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

Write metrics tags only once to Elasticsearch #21

Merged
merged 1 commit into from
Jan 9, 2024
Merged
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
51 changes: 23 additions & 28 deletions pkg/esoutput/esoutput.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ type elasticMetricEntry struct {
MetricName string
MetricType string
Value float64
MetricTags map[string]string
SampleTags map[string]string
Tags map[string]string
Time time.Time
}

Expand Down Expand Up @@ -183,33 +182,29 @@ func (o *Output) flush() {
samples := samplesContainer.GetSamples()

for _, sample := range samples {
for _, entry := range sample.GetSamples() {
mappedEntry := elasticMetricEntry{
MetricName: entry.Metric.Name,
MetricType: entry.Metric.Type.String(),
Value: entry.Value,
MetricTags: entry.GetTags().Map(),
SampleTags: sample.GetTags().Map(),
Time: sample.Time,
}
data, err := json.Marshal(mappedEntry)
if err != nil {
o.logger.Fatalf("Cannot encode document: %s, %s", err, mappedEntry)
}
var item = esutil.BulkIndexerItem{
Action: "index",
Body: bytes.NewReader(data),
OnFailure: o.blkItemErrHandler,
}
err = o.bulkIndexer.Add(
context.Background(),
item,
)
if err != nil {
log.Fatalf("Unexpected error: %s", err)
}
mappedEntry := elasticMetricEntry{
MetricName: sample.Metric.Name,
MetricType: sample.Metric.Type.String(),
Value: sample.Value,
Tags: sample.GetTags().Map(),
Time: sample.Time,
}
data, err := json.Marshal(mappedEntry)
if err != nil {
o.logger.Fatalf("Cannot encode document: %s, %s", err, mappedEntry)
}
var item = esutil.BulkIndexerItem{
Action: "index",
Body: bytes.NewReader(data),
OnFailure: o.blkItemErrHandler,
}
err = o.bulkIndexer.Add(
context.Background(),
item,
)
if err != nil {
log.Fatalf("Unexpected error: %s", err)
}

}
}
}