-
Notifications
You must be signed in to change notification settings - Fork 478
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Work around high cardinality metrics from otelcol receivers
Fixes #4764
- Loading branch information
1 parent
0be02ad
commit a1fc6a6
Showing
2 changed files
with
58 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package views | ||
|
||
import ( | ||
semconv "go.opentelemetry.io/collector/semconv/v1.13.0" | ||
"go.opentelemetry.io/otel/attribute" | ||
"go.opentelemetry.io/otel/sdk/instrumentation" | ||
"go.opentelemetry.io/otel/sdk/metric" | ||
) | ||
|
||
var ( | ||
grpcScope = "go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc" | ||
// grpcUnacceptableKeyValues is a list of high cardinality grpc attributes that should be filtered out. | ||
grpcUnacceptableKeyValues = []attribute.KeyValue{ | ||
attribute.String(semconv.AttributeNetSockPeerAddr, ""), | ||
attribute.String(semconv.AttributeNetSockPeerPort, ""), | ||
attribute.String(semconv.AttributeNetSockPeerName, ""), | ||
} | ||
|
||
httpScope = "go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp" | ||
// httpUnacceptableKeyValues is a list of high cardinality http attributes that should be filtered out. | ||
httpUnacceptableKeyValues = []attribute.KeyValue{ | ||
attribute.String(semconv.AttributeNetHostName, ""), | ||
attribute.String(semconv.AttributeNetHostPort, ""), | ||
attribute.String(semconv.AttributeNetSockPeerPort, ""), | ||
attribute.String(semconv.AttributeNetSockPeerAddr, ""), | ||
attribute.String(semconv.AttributeHTTPClientIP, ""), | ||
} | ||
) | ||
|
||
func cardinalityFilter(kvs ...attribute.KeyValue) attribute.Filter { | ||
filter := attribute.NewSet(kvs...) | ||
return func(kv attribute.KeyValue) bool { | ||
return !filter.HasValue(kv.Key) | ||
} | ||
} | ||
|
||
// DropHighCardinalityServerAttributes drops certain high cardinality attributes from grpc/http server metrics | ||
// | ||
// This is a hopefully temporary fix to this upstream issue https://github.com/open-telemetry/opentelemetry-go-contrib/issues/3765 | ||
func DropHighCardinalityServerAttributes() []metric.View { | ||
var views []metric.View | ||
|
||
views = append(views, metric.NewView( | ||
metric.Instrument{Scope: instrumentation.Scope{Name: grpcScope}}, | ||
metric.Stream{AttributeFilter: cardinalityFilter(grpcUnacceptableKeyValues...)})) | ||
|
||
views = append(views, metric.NewView( | ||
metric.Instrument{Scope: instrumentation.Scope{Name: httpScope}}, | ||
metric.Stream{AttributeFilter: cardinalityFilter(httpUnacceptableKeyValues...)}, | ||
)) | ||
|
||
return views | ||
} |
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