Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Vladislav Byrgazov committed May 17, 2024
1 parent a0cb64a commit 9dd704c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
12 changes: 6 additions & 6 deletions pkg/networkservice/common/metrics/metadata.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (c) 2022 Cisco and/or its affiliates.
// Copyright (c) 2023 Nordix Foundation.
// Copyright (c) 2024 Cisco and/or its affiliates.
//
// Copyright (c) 2022-2024 Cisco and/or its affiliates.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand Down Expand Up @@ -29,12 +29,12 @@ import (

type keyType struct{}

type dataType struct {
type metricsData struct {
counter map[string]metric.Int64Counter
previous *sync.Map
previous sync.Map
}

func loadOrStore(ctx context.Context, metrics dataType) (value dataType, ok bool) {
func loadOrStore(ctx context.Context, metrics *metricsData) (value *metricsData, ok bool) {
rawValue, ok := metadata.Map(ctx, false).LoadOrStore(keyType{}, metrics)
return rawValue.(dataType), ok
return rawValue.(*metricsData), ok
}
11 changes: 4 additions & 7 deletions pkg/networkservice/common/metrics/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,12 @@ package metrics
import (
"context"
"fmt"
"strconv"
"sync"

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

"github.com/networkservicemesh/sdk/pkg/networkservice/core/next"
"github.com/networkservicemesh/sdk/pkg/tools/opentelemetry"
Expand Down Expand Up @@ -79,11 +77,10 @@ func (t *metricServer) writeMetrics(ctx context.Context, path *networkservice.Pa
continue
}

k := dataType{
counter: make(map[string]metric.Int64Counter),
previous: new(sync.Map),
k := metricsData{
counter: make(map[string]metric.Int64Counter),
}
metrics, _ := loadOrStore(ctx, k)
metrics, _ := loadOrStore(ctx, &k)
for metricName, metricValue := range pathSegment.Metrics {
/* Works with integers only */
recVal, err := strconv.ParseInt(metricValue, 10, 64)
Expand Down

0 comments on commit 9dd704c

Please sign in to comment.