Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Group metrics randomly for one EMF event with a 50% probability #217

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading