Skip to content

Commit

Permalink
Check for nil filters
Browse files Browse the repository at this point in the history
  • Loading branch information
Achooo committed Jul 25, 2023
1 parent c8c8faa commit 5a1f5c2
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions agent/hcp/telemetry/otel_sink.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func (o *OTELSink) IncrCounter(key []string, val float32) {
func (o *OTELSink) SetGaugeWithLabels(key []string, val float32, labels []gometrics.Label) {
k := o.flattenKey(key)

if !o.cfgProvider.GetFilters().MatchString(k) {
if !o.allowedMetric(k) {
return
}

Expand Down Expand Up @@ -160,7 +160,7 @@ func (o *OTELSink) SetGaugeWithLabels(key []string, val float32, labels []gometr
func (o *OTELSink) AddSampleWithLabels(key []string, val float32, labels []gometrics.Label) {
k := o.flattenKey(key)

if !o.cfgProvider.GetFilters().MatchString(k) {
if !o.allowedMetric(k) {
return
}

Expand All @@ -186,7 +186,7 @@ func (o *OTELSink) AddSampleWithLabels(key []string, val float32, labels []gomet
func (o *OTELSink) IncrCounterWithLabels(key []string, val float32, labels []gometrics.Label) {
k := o.flattenKey(key)

if !o.cfgProvider.GetFilters().MatchString(k) {
if !o.allowedMetric(k) {
return
}

Expand Down Expand Up @@ -222,6 +222,15 @@ func (o *OTELSink) flattenKey(parts []string) string {
return buf.String()
}

// filter checks the filter allowlist, if it exists, to verify if this metric should be recorded.
func (o *OTELSink) allowedMetric(key string) bool {
if o.cfgProvider.GetFilters() != nil {
return o.cfgProvider.GetFilters().MatchString(key)
}

return true
}

// labelsToAttributes converts go metrics and provider labels into OTEL format []attributes.KeyValue
func (o *OTELSink) labelsToAttributes(goMetricsLabels []gometrics.Label) []attribute.KeyValue {
providerLabels := o.cfgProvider.GetLabels()
Expand Down

0 comments on commit 5a1f5c2

Please sign in to comment.