-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Update protobuf to v1.26.0 needed for opentelemetry Signed-off-by: Artem Glazychev <artem.glazychev@xored.com> * Add opentelemetry support Signed-off-by: Artem Glazychev <artem.glazychev@xored.com> * fixes Signed-off-by: Nikita Skrynnik <nikita.skrynnik@xored.com> * update dependencies Signed-off-by: Nikita Skrynnik <nikita.skrynnik@xored.com> * fixes due to version update Signed-off-by: Nikita Skrynnik <nikita.skrynnik@xored.com> * add jaeger exporter Signed-off-by: Nikita Skrynnik <nikita.skrynnik@xored.com> * goleaks disappeared somewhere Signed-off-by: Nikita Skrynnik <nikita.skrynnik@xored.com> * minor fixes for jaeger Signed-off-by: Nikita Skrynnik <nikita.skrynnik@xored.com> * add zipkin exporter Signed-off-by: Nikita Skrynnik <nikita.skrynnik@xored.com> * go leaks related to transfer of the spans Signed-off-by: Nikita Skrynnik <nikita.skrynnik@xored.com> * add opentelemetry collector support Signed-off-by: Nikita Skrynnik <nikita.skrynnik@xored.com> * add metrics support Signed-off-by: Nikita Skrynnik <nikita.skrynnik@xored.com> * add metrics test Signed-off-by: Nikita Skrynnik <nikita.skrynnik@xored.com> * add README.md file Signed-off-by: Nikita Skrynnik <nikita.skrynnik@xored.com> * fixes after cherry-pick Signed-off-by: Nikita Skrynnik <nikita.skrynnik@xored.com> * more fixes Signed-off-by: Nikita Skrynnik <nikita.skrynnik@xored.com> * run go mod tidy Signed-off-by: Nikita Skrynnik <nikita.skrynnik@xored.com> * lint fixes Signed-off-by: Nikita Skrynnik <nikita.skrynnik@xored.com> * revert test and updatepath files Signed-off-by: Nikita.Skrynnik <nikita.nstu@gmail.com> * revert refresh/client.go file Signed-off-by: Nikita Skrynnik <nikita.skrynnik@xored.com> * delete meter_helper Signed-off-by: Nikita Skrynnik <nikita.skrynnik@xored.com> * fill empty event names + delete instrumentationname Signed-off-by: Nikita Skrynnik <nikita.skrynnik@xored.com> * Revert "revert refresh/client.go file" This reverts commit d5cd9f9. Signed-off-by: Nikita Skrynnik <nikita.skrynnik@xored.com> * remove opentracing Signed-off-by: Nikita Skrynnik <nikita.skrynnik@xored.com> * fix linter issue Signed-off-by: Nikita Skrynnik <nikita.skrynnik@xored.com> * change TELEMETRY env value Signed-off-by: Nikita Skrynnik <nikita.skrynnik@xored.com> Co-authored-by: Artem Glazychev <artem.glazychev@xored.com> Co-authored-by: Nikita.Skrynnik <nikita.nstu@gmail.com>
- Loading branch information
1 parent
fe9702d
commit b112919
Showing
47 changed files
with
828 additions
and
321 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
// Copyright (c) 2021-2022 Doc.ai and/or its affiliates. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at: | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
// Package metrics provides a chain element that sends metrics to collector | ||
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" | ||
) | ||
|
||
type metricServer struct { | ||
recorderMap map[string]metric.Int64Histogram | ||
meter metric.Meter | ||
} | ||
|
||
// NewServer returns a new metric server chain element | ||
func NewServer() networkservice.NetworkServiceServer { | ||
return &metricServer{ | ||
recorderMap: make(map[string]metric.Int64Histogram), | ||
meter: global.Meter(""), | ||
} | ||
} | ||
|
||
func (t *metricServer) Request(ctx context.Context, request *networkservice.NetworkServiceRequest) (*networkservice.Connection, error) { | ||
conn, err := next.Server(ctx).Request(ctx, request) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
t.writeMetrics(ctx, conn.GetPath()) | ||
return conn, nil | ||
} | ||
|
||
func (t *metricServer) Close(ctx context.Context, conn *networkservice.Connection) (*empty.Empty, error) { | ||
_, err := next.Server(ctx).Close(ctx, conn) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
t.writeMetrics(ctx, conn.GetPath()) | ||
return &empty.Empty{}, nil | ||
} | ||
|
||
func (t *metricServer) writeMetrics(ctx context.Context, path *networkservice.Path) { | ||
if path != nil { | ||
for _, pathSegment := range path.GetPathSegments() { | ||
if pathSegment.Metrics == nil { | ||
continue | ||
} | ||
|
||
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)) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.