Skip to content

Commit

Permalink
Group metrics randomly for one EMF event with a 50% probability
Browse files Browse the repository at this point in the history
  • Loading branch information
mxiamxia committed Jun 10, 2024
1 parent 21a87ff commit 1b24933
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions exporter/awsemfexporter/grouped_metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ package awsemfexporter // import "github.com/open-telemetry/opentelemetry-collec

import (
"encoding/json"
"math/rand"
"strings"
"time"

"go.opentelemetry.io/collector/pdata/pmetric"
"go.uber.org/zap"
Expand Down Expand Up @@ -77,6 +79,16 @@ func addToGroupedMetric(
}
}

// add metric name as label attribute so it will not be grouped with other metrics in 50% chance
if addMetricNameInGroupKey(dp.name) {
labels["metric.name"] = dp.name
config.logger.Warn(
"Add MetricName attribute as group key",
zap.String("Name", dp.name),
zap.Any("Labels", labels),
)
}

metric := &metricInfo{
value: dp.value,
unit: translateUnit(pmd, descriptor),
Expand Down Expand Up @@ -112,6 +124,22 @@ func addToGroupedMetric(
return nil
}

// addMetricNameInGroupKey returns true or false with equal probability.
func addMetricNameInGroupKey(metricName string) bool {
validMetrics := map[string]bool{
"Latency": true,
"Fault": true,
"Error": true,
}

if validMetrics[metricName] {
rand.Seed(time.Now().UnixNano())
return rand.Intn(2) == 0
}

return false
}

type kubernetesObj struct {
ContainerName string `json:"container_name,omitempty"`
Docker *internalDockerObj `json:"docker,omitempty"`
Expand Down

0 comments on commit 1b24933

Please sign in to comment.