Skip to content

Commit

Permalink
fix: include metadata in dimensions
Browse files Browse the repository at this point in the history
  • Loading branch information
leonyork committed Dec 20, 2022
1 parent 653b510 commit 2c37d3a
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/kelseyhightower/envconfig v1.4.0
github.com/sirupsen/logrus v1.9.0
github.com/stretchr/testify v1.8.1
go.k6.io/k6 v0.40.0
go.k6.io/k6 v0.42.0
)

require (
Expand Down
11 changes: 11 additions & 0 deletions output.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,17 @@ func (o *Output) createRecords(samples []metrics.Sample) []types.Record {
})
}

for tagKey, tagValue := range sample.Metadata {
if len(strings.TrimSpace(tagValue)) == 0 {
continue
}

dimensions = append(dimensions, types.Dimension{
Name: aws.String(tagKey),
Value: aws.String(tagValue),
})
}

records = append(records, types.Record{
Dimensions: dimensions,
MeasureName: aws.String(sample.Metric.Name),
Expand Down
20 changes: 20 additions & 0 deletions output_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,10 @@ func TestCreateRecords(t *testing.T) {
},
Time: time.UnixMicro(int64(0)),
Value: float64(1),
Metadata: map[string]string{
"md1.1": "mdval1.1",
"md2.1": "mdval2.1",
},
},
{
TimeSeries: metrics.TimeSeries{
Expand All @@ -245,6 +249,10 @@ func TestCreateRecords(t *testing.T) {
},
Time: time.UnixMicro(int64(1)),
Value: float64(2.2),
Metadata: map[string]string{
"empty": "",
"md2.2": "mdval2.2",
},
},
}

Expand All @@ -259,6 +267,14 @@ func TestCreateRecords(t *testing.T) {
Name: aws.String("key2.1"),
Value: aws.String("val2.1"),
},
{
Name: aws.String("md1.1"),
Value: aws.String("mdval1.1"),
},
{
Name: aws.String("md2.1"),
Value: aws.String("mdval2.1"),
},
},
MeasureName: aws.String("test_metric1"),
MeasureValue: aws.String("1.000000"),
Expand All @@ -272,6 +288,10 @@ func TestCreateRecords(t *testing.T) {
Name: aws.String("key2.2"),
Value: aws.String("val2.2"),
},
{
Name: aws.String("md2.2"),
Value: aws.String("mdval2.2"),
},
},
MeasureName: aws.String("test_metric2"),
MeasureValue: aws.String("2.200000"),
Expand Down

0 comments on commit 2c37d3a

Please sign in to comment.