chore(gomod): update otel to 1.0.0 (#2414)

This commit is contained in:
Silvan
2021-09-23 12:50:17 +02:00
committed by GitHub
parent a17a6263b4
commit 30153cff39
7 changed files with 66 additions and 65 deletions

View File

@@ -6,6 +6,7 @@ import (
"github.com/caos/logging"
sentryhttp "github.com/getsentry/sentry-go/http"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/metric"
"google.golang.org/grpc"
@@ -185,9 +186,9 @@ func (a *API) registerSpoolerDivCounters() {
metrics.SpoolerDivCounterDescription,
func(ctx context.Context, result metric.Int64ObserverResult) {
for _, view := range views {
labels := map[string]interface{}{
metrics.Database: view.Database,
metrics.ViewName: view.ViewName,
labels := map[string]attribute.Value{
metrics.Database: attribute.StringValue(view.Database),
metrics.ViewName: attribute.StringValue(view.ViewName),
}
result.Observe(
a.admin.GetSpoolerDiv(view.Database, view.ViewName),

View File

@@ -5,6 +5,7 @@ import (
"strings"
"github.com/grpc-ecosystem/grpc-gateway/runtime"
"go.opentelemetry.io/otel/attribute"
"google.golang.org/grpc"
"google.golang.org/grpc/status"
@@ -54,8 +55,8 @@ func RegisterMetrics(ctx context.Context, req interface{}, info *grpc.UnaryServe
}
func RegisterGrpcRequestCounter(ctx context.Context, info *grpc.UnaryServerInfo) {
var labels = map[string]interface{}{
GrpcMethod: info.FullMethod,
var labels = map[string]attribute.Value{
GrpcMethod: attribute.StringValue(info.FullMethod),
}
metrics.RegisterCounter(GrpcRequestCounter, GrpcRequestCounterDescription)
metrics.AddCount(ctx, GrpcRequestCounter, 1, labels)
@@ -68,9 +69,9 @@ func RegisterGrpcTotalRequestCounter(ctx context.Context) {
func RegisterGrpcRequestCodeCounter(ctx context.Context, info *grpc.UnaryServerInfo, err error) {
statusCode := status.Code(err)
var labels = map[string]interface{}{
GrpcMethod: info.FullMethod,
ReturnCode: runtime.HTTPStatusFromCode(statusCode),
var labels = map[string]attribute.Value{
GrpcMethod: attribute.StringValue(info.FullMethod),
ReturnCode: attribute.IntValue(runtime.HTTPStatusFromCode(statusCode)),
}
metrics.RegisterCounter(GrpcStatusCodeCounter, GrpcStatusCodeCounterDescription)
metrics.AddCount(ctx, GrpcStatusCodeCounter, 1, labels)

View File

@@ -3,6 +3,8 @@ package metrics
import (
"net/http"
"strings"
"go.opentelemetry.io/otel/attribute"
)
const (
@@ -93,9 +95,9 @@ func (h *Handler) containsMetricsMethod(method MetricType) bool {
}
func RegisterRequestCounter(r *http.Request) {
var labels = map[string]interface{}{
URI: strings.Split(r.RequestURI, "?")[0],
Method: r.Method,
var labels = map[string]attribute.Value{
URI: attribute.StringValue(strings.Split(r.RequestURI, "?")[0]),
Method: attribute.StringValue(r.Method),
}
RegisterCounter(RequestCounter, RequestCountDescription)
AddCount(r.Context(), RequestCounter, 1, labels)
@@ -107,10 +109,10 @@ func RegisterTotalRequestCounter(r *http.Request) {
}
func RegisterRequestCodeCounter(recorder *StatusRecorder, r *http.Request) {
var labels = map[string]interface{}{
URI: strings.Split(r.RequestURI, "?")[0],
Method: r.Method,
ReturnCode: recorder.Status,
var labels = map[string]attribute.Value{
URI: attribute.StringValue(strings.Split(r.RequestURI, "?")[0]),
Method: attribute.StringValue(r.Method),
ReturnCode: attribute.IntValue(recorder.Status),
}
RegisterCounter(ReturnCodeCounter, ReturnCodeCounterDescription)
AddCount(r.Context(), ReturnCodeCounter, 1, labels)

View File

@@ -4,6 +4,7 @@ import (
"context"
"net/http"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/metric"
)
@@ -20,7 +21,7 @@ type Metrics interface {
GetExporter() http.Handler
GetMetricsProvider() metric.MeterProvider
RegisterCounter(name, description string) error
AddCount(ctx context.Context, name string, value int64, labels map[string]interface{}) error
AddCount(ctx context.Context, name string, value int64, labels map[string]attribute.Value) error
RegisterUpDownSumObserver(name, description string, callbackFunc metric.Int64ObserverFunc) error
RegisterValueObserver(name, description string, callbackFunc metric.Int64ObserverFunc) error
}
@@ -52,7 +53,7 @@ func RegisterCounter(name, description string) error {
return M.RegisterCounter(name, description)
}
func AddCount(ctx context.Context, name string, value int64, labels map[string]interface{}) error {
func AddCount(ctx context.Context, name string, value int64, labels map[string]attribute.Value) error {
if M == nil {
return nil
}

View File

@@ -5,7 +5,7 @@ import (
"net/http"
"sync"
label "go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/exporters/prometheus"
"go.opentelemetry.io/otel/metric"
export "go.opentelemetry.io/otel/sdk/export/metric"
@@ -62,7 +62,7 @@ func (m *Metrics) RegisterCounter(name, description string) error {
return nil
}
func (m *Metrics) AddCount(ctx context.Context, name string, value int64, labels map[string]interface{}) error {
func (m *Metrics) AddCount(ctx context.Context, name string, value int64, labels map[string]attribute.Value) error {
counter, exists := m.Counters.Load(name)
if !exists {
return caos_errs.ThrowNotFound(nil, "METER-4u8fs", "Errors.Metrics.Counter.NotFound")
@@ -93,13 +93,16 @@ func (m *Metrics) RegisterValueObserver(name, description string, callbackFunc m
return nil
}
func MapToKeyValue(labels map[string]interface{}) []label.KeyValue {
func MapToKeyValue(labels map[string]attribute.Value) []attribute.KeyValue {
if labels == nil {
return nil
}
keyValues := make([]label.KeyValue, 0, len(labels))
keyValues := make([]attribute.KeyValue, 0, len(labels))
for key, value := range labels {
keyValues = append(keyValues, label.Any(key, value))
keyValues = append(keyValues, attribute.KeyValue{
Key: attribute.Key(key),
Value: value,
})
}
return keyValues
}