Skip to content

Commit

Permalink
delete meter_helper
Browse files Browse the repository at this point in the history
Signed-off-by: Nikita Skrynnik <nikita.skrynnik@xored.com>
  • Loading branch information
NikitaSkrynnik committed Dec 30, 2021
1 parent d5cd9f9 commit 711ab40
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 81 deletions.
30 changes: 23 additions & 7 deletions pkg/networkservice/common/metrics/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,28 @@ package metrics

import (
"context"
"strconv"

"github.com/golang/protobuf/ptypes/empty"
"github.com/networkservicemesh/api/pkg/api/networkservice"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/metric/global"

"github.com/networkservicemesh/sdk/pkg/networkservice/core/next"
"github.com/networkservicemesh/sdk/pkg/tools/opentelemetry/meterhelper"
"github.com/networkservicemesh/sdk/pkg/tools/opentelemetry"
)

type metricServer struct {
helpers map[string]meterhelper.MeterHelper
recorderMap map[string]metric.Int64Histogram
meter metric.Meter
}

// NewServer returns a new metric server chain element
func NewServer() networkservice.NetworkServiceServer {
return &metricServer{
helpers: make(map[string]meterhelper.MeterHelper),
recorderMap: make(map[string]metric.Int64Histogram),
meter: global.Meter(opentelemetry.InstrumentationName),
}
}

Expand Down Expand Up @@ -64,11 +70,21 @@ func (t *metricServer) writeMetrics(ctx context.Context, path *networkservice.Pa
if pathSegment.Metrics == nil {
continue
}
_, ok := t.helpers[pathSegment.Id]
if !ok {
t.helpers[pathSegment.Id] = meterhelper.NewMeterHelper(pathSegment.Name, path.GetPathSegments()[0].Id)

for metricName, metricValue := range pathSegment.Metrics {
/* Works with integers only */
recVal, err := strconv.ParseInt(metricValue, 10, 64)
if err != nil {
continue
}
_, ok := t.recorderMap[metricName]
if !ok {
t.recorderMap[metricName] = metric.Must(t.meter).NewInt64Histogram(
pathSegment.Name + "_" + metricName,
)
}
t.recorderMap[metricName].Record(ctx, recVal, attribute.String("connection", path.GetPathSegments()[0].Id))
}
t.helpers[pathSegment.Id].WriteMetrics(ctx, pathSegment.Metrics)
}
}
}
74 changes: 0 additions & 74 deletions pkg/tools/opentelemetry/meterhelper/meter_helper.go

This file was deleted.

0 comments on commit 711ab40

Please sign in to comment.