Skip to content

Commit

Permalink
signalfxexporter: update labels -> attributes (#4603)
Browse files Browse the repository at this point in the history
Following the changes in core to OTLP 0.9.0 to move away from `Labels` and on to `Attributes`

**Link to tracking Issue:** Part of open-telemetry/opentelemetry-collector#3535
  • Loading branch information
alrex committed Aug 12, 2021
1 parent cb28068 commit 6f74449
Show file tree
Hide file tree
Showing 5 changed files with 145 additions and 137 deletions.
24 changes: 12 additions & 12 deletions exporter/signalfxexporter/exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ func TestConsumeMetrics(t *testing.T) {
m.SetName("test_gauge")
m.SetDataType(pdata.MetricDataTypeGauge)
dp := m.Gauge().DataPoints().AppendEmpty()
dp.LabelsMap().InitFromMap(map[string]string{
"k0": "v0",
"k1": "v1",
dp.Attributes().InitFromMap(map[string]pdata.AttributeValue{
"k0": pdata.NewAttributeValueString("v0"),
"k1": pdata.NewAttributeValueString("v1"),
})
dp.SetDoubleVal(123)

Expand Down Expand Up @@ -260,9 +260,9 @@ func TestConsumeMetricsWithAccessTokenPassthrough(t *testing.T) {
m.SetDataType(pdata.MetricDataTypeGauge)

dp := m.Gauge().DataPoints().AppendEmpty()
dp.LabelsMap().InitFromMap(map[string]string{
"k0": "v0",
"k1": "v1",
dp.Attributes().InitFromMap(map[string]pdata.AttributeValue{
"k0": pdata.NewAttributeValueString("v0"),
"k1": pdata.NewAttributeValueString("v1"),
})
dp.SetDoubleVal(123)
return out
Expand Down Expand Up @@ -325,9 +325,9 @@ func TestConsumeMetricsWithAccessTokenPassthrough(t *testing.T) {
m.SetName("test_gauge")
m.SetDataType(pdata.MetricDataTypeGauge)
dp := m.Gauge().DataPoints().AppendEmpty()
dp.LabelsMap().InitFromMap(map[string]string{
"k0": "v0",
"k1": "v1",
dp.Attributes().InitFromMap(map[string]pdata.AttributeValue{
"k0": pdata.NewAttributeValueString("v0"),
"k1": pdata.NewAttributeValueString("v1"),
})
dp.SetDoubleVal(123)

Expand Down Expand Up @@ -708,9 +708,9 @@ func generateLargeDPBatch() pdata.Metrics {

dp := m.Gauge().DataPoints().AppendEmpty()
dp.SetTimestamp(pdata.TimestampFromTime(ts))
dp.LabelsMap().InitFromMap(map[string]string{
"k0": "v0",
"k1": "v1",
dp.Attributes().InitFromMap(map[string]pdata.AttributeValue{
"k0": pdata.NewAttributeValueString("v0"),
"k1": pdata.NewAttributeValueString("v1"),
})
dp.SetIntVal(int64(i))
}
Expand Down
192 changes: 96 additions & 96 deletions exporter/signalfxexporter/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,20 +310,20 @@ func testMetricsData() pdata.ResourceMetrics {
m1.SetUnit("bytes")
m1.SetDataType(pdata.MetricDataTypeGauge)
dp11 := m1.Gauge().DataPoints().AppendEmpty()
dp11.LabelsMap().InitFromMap(map[string]string{
"state": "used",
"host": "host0",
"kubernetes_node": "node0",
"kubernetes_cluster": "cluster0",
dp11.Attributes().InitFromMap(map[string]pdata.AttributeValue{
"state": pdata.NewAttributeValueString("used"),
"host": pdata.NewAttributeValueString("host0"),
"kubernetes_node": pdata.NewAttributeValueString("node0"),
"kubernetes_cluster": pdata.NewAttributeValueString("cluster0"),
}).Sort()
dp11.SetTimestamp(pdata.TimestampFromTime(time.Unix(1596000000, 0)))
dp11.SetIntVal(4e9)
dp12 := m1.Gauge().DataPoints().AppendEmpty()
dp12.LabelsMap().InitFromMap(map[string]string{
"state": "free",
"host": "host0",
"kubernetes_node": "node0",
"kubernetes_cluster": "cluster0",
dp12.Attributes().InitFromMap(map[string]pdata.AttributeValue{
"state": pdata.NewAttributeValueString("free"),
"host": pdata.NewAttributeValueString("host0"),
"kubernetes_node": pdata.NewAttributeValueString("node0"),
"kubernetes_cluster": pdata.NewAttributeValueString("cluster0"),
}).Sort()
dp12.SetTimestamp(pdata.TimestampFromTime(time.Unix(1596000000, 0)))
dp12.SetIntVal(6e9)
Expand All @@ -335,34 +335,34 @@ func testMetricsData() pdata.ResourceMetrics {
m2.Sum().SetIsMonotonic(true)
m2.Sum().SetAggregationTemporality(pdata.AggregationTemporalityCumulative)
dp21 := m2.Sum().DataPoints().AppendEmpty()
dp21.LabelsMap().InitFromMap(map[string]string{
"host": "host0",
"direction": "read",
"device": "sda1",
dp21.Attributes().InitFromMap(map[string]pdata.AttributeValue{
"host": pdata.NewAttributeValueString("host0"),
"direction": pdata.NewAttributeValueString("read"),
"device": pdata.NewAttributeValueString("sda1"),
}).Sort()
dp21.SetTimestamp(pdata.TimestampFromTime(time.Unix(1596000000, 0)))
dp21.SetIntVal(1e9)
dp22 := m2.Sum().DataPoints().AppendEmpty()
dp22.LabelsMap().InitFromMap(map[string]string{
"host": "host0",
"direction": "read",
"device": "sda2",
dp22.Attributes().InitFromMap(map[string]pdata.AttributeValue{
"host": pdata.NewAttributeValueString("host0"),
"direction": pdata.NewAttributeValueString("read"),
"device": pdata.NewAttributeValueString("sda2"),
}).Sort()
dp22.SetTimestamp(pdata.TimestampFromTime(time.Unix(1596000000, 0)))
dp22.SetIntVal(2e9)
dp23 := m2.Sum().DataPoints().AppendEmpty()
dp23.LabelsMap().InitFromMap(map[string]string{
"host": "host0",
"direction": "write",
"device": "sda1",
dp23.Attributes().InitFromMap(map[string]pdata.AttributeValue{
"host": pdata.NewAttributeValueString("host0"),
"direction": pdata.NewAttributeValueString("write"),
"device": pdata.NewAttributeValueString("sda1"),
}).Sort()
dp23.SetTimestamp(pdata.TimestampFromTime(time.Unix(1596000000, 0)))
dp23.SetIntVal(3e9)
dp24 := m2.Sum().DataPoints().AppendEmpty()
dp24.LabelsMap().InitFromMap(map[string]string{
"host": "host0",
"direction": "write",
"device": "sda2",
dp24.Attributes().InitFromMap(map[string]pdata.AttributeValue{
"host": pdata.NewAttributeValueString("host0"),
"direction": pdata.NewAttributeValueString("write"),
"device": pdata.NewAttributeValueString("sda2"),
}).Sort()
dp24.SetTimestamp(pdata.TimestampFromTime(time.Unix(1596000000, 0)))
dp24.SetIntVal(8e9)
Expand All @@ -375,34 +375,34 @@ func testMetricsData() pdata.ResourceMetrics {
m3.Sum().SetIsMonotonic(true)
m3.Sum().SetAggregationTemporality(pdata.AggregationTemporalityCumulative)
dp31 := m3.Sum().DataPoints().AppendEmpty()
dp31.LabelsMap().InitFromMap(map[string]string{
"host": "host0",
"direction": "read",
"device": "sda1",
dp31.Attributes().InitFromMap(map[string]pdata.AttributeValue{
"host": pdata.NewAttributeValueString("host0"),
"direction": pdata.NewAttributeValueString("read"),
"device": pdata.NewAttributeValueString("sda1"),
}).Sort()
dp31.SetTimestamp(pdata.TimestampFromTime(time.Unix(1596000000, 0)))
dp31.SetIntVal(4e3)
dp32 := m3.Sum().DataPoints().AppendEmpty()
dp32.LabelsMap().InitFromMap(map[string]string{
"host": "host0",
"direction": "read",
"device": "sda2",
dp32.Attributes().InitFromMap(map[string]pdata.AttributeValue{
"host": pdata.NewAttributeValueString("host0"),
"direction": pdata.NewAttributeValueString("read"),
"device": pdata.NewAttributeValueString("sda2"),
}).Sort()
dp32.SetTimestamp(pdata.TimestampFromTime(time.Unix(1596000000, 0)))
dp32.SetIntVal(6e3)
dp33 := m3.Sum().DataPoints().AppendEmpty()
dp33.LabelsMap().InitFromMap(map[string]string{
"host": "host0",
"direction": "write",
"device": "sda1",
dp33.Attributes().InitFromMap(map[string]pdata.AttributeValue{
"host": pdata.NewAttributeValueString("host0"),
"direction": pdata.NewAttributeValueString("write"),
"device": pdata.NewAttributeValueString("sda1"),
}).Sort()
dp33.SetTimestamp(pdata.TimestampFromTime(time.Unix(1596000000, 0)))
dp33.SetIntVal(1e3)
dp34 := m3.Sum().DataPoints().AppendEmpty()
dp34.LabelsMap().InitFromMap(map[string]string{
"host": "host0",
"direction": "write",
"device": "sda2",
dp34.Attributes().InitFromMap(map[string]pdata.AttributeValue{
"host": pdata.NewAttributeValueString("host0"),
"direction": pdata.NewAttributeValueString("write"),
"device": pdata.NewAttributeValueString("sda2"),
}).Sort()
dp34.SetTimestamp(pdata.TimestampFromTime(time.Unix(1596000000, 0)))
dp34.SetIntVal(5e3)
Expand All @@ -415,34 +415,34 @@ func testMetricsData() pdata.ResourceMetrics {
m4.Sum().SetIsMonotonic(true)
m4.Sum().SetAggregationTemporality(pdata.AggregationTemporalityCumulative)
dp41 := m4.Sum().DataPoints().AppendEmpty()
dp41.LabelsMap().InitFromMap(map[string]string{
"device": "sda1",
"direction": "read",
"host": "host0",
dp41.Attributes().InitFromMap(map[string]pdata.AttributeValue{
"device": pdata.NewAttributeValueString("sda1"),
"direction": pdata.NewAttributeValueString("read"),
"host": pdata.NewAttributeValueString("host0"),
}).Sort()
dp41.SetTimestamp(pdata.TimestampFromTime(time.Unix(1596000060, 0)))
dp41.SetIntVal(6e3)
dp42 := m4.Sum().DataPoints().AppendEmpty()
dp42.LabelsMap().InitFromMap(map[string]string{
"device": "sda2",
"direction": "read",
"host": "host0",
dp42.Attributes().InitFromMap(map[string]pdata.AttributeValue{
"device": pdata.NewAttributeValueString("sda2"),
"direction": pdata.NewAttributeValueString("read"),
"host": pdata.NewAttributeValueString("host0"),
}).Sort()
dp42.SetTimestamp(pdata.TimestampFromTime(time.Unix(1596000060, 0)))
dp42.SetIntVal(8e3)
dp43 := m4.Sum().DataPoints().AppendEmpty()
dp43.LabelsMap().InitFromMap(map[string]string{
"device": "sda1",
"direction": "write",
"host": "host0",
dp43.Attributes().InitFromMap(map[string]pdata.AttributeValue{
"device": pdata.NewAttributeValueString("sda1"),
"direction": pdata.NewAttributeValueString("write"),
"host": pdata.NewAttributeValueString("host0"),
}).Sort()
dp43.SetTimestamp(pdata.TimestampFromTime(time.Unix(1596000060, 0)))
dp43.SetIntVal(3e3)
dp44 := m4.Sum().DataPoints().AppendEmpty()
dp44.LabelsMap().InitFromMap(map[string]string{
"device": "sda2",
"direction": "write",
"host": "host0",
dp44.Attributes().InitFromMap(map[string]pdata.AttributeValue{
"device": pdata.NewAttributeValueString("sda2"),
"direction": pdata.NewAttributeValueString("write"),
"host": pdata.NewAttributeValueString("host0"),
}).Sort()
dp44.SetTimestamp(pdata.TimestampFromTime(time.Unix(1596000060, 0)))
dp44.SetIntVal(7e3)
Expand All @@ -453,22 +453,22 @@ func testMetricsData() pdata.ResourceMetrics {
m5.SetUnit("bytes")
m5.SetDataType(pdata.MetricDataTypeGauge)
dp51 := m5.Gauge().DataPoints().AppendEmpty()
dp51.LabelsMap().InitFromMap(map[string]string{
"direction": "receive",
"device": "eth0",
"host": "host0",
"kubernetes_node": "node0",
"kubernetes_cluster": "cluster0",
dp51.Attributes().InitFromMap(map[string]pdata.AttributeValue{
"direction": pdata.NewAttributeValueString("receive"),
"device": pdata.NewAttributeValueString("eth0"),
"host": pdata.NewAttributeValueString("host0"),
"kubernetes_node": pdata.NewAttributeValueString("node0"),
"kubernetes_cluster": pdata.NewAttributeValueString("cluster0"),
}).Sort()
dp51.SetTimestamp(pdata.TimestampFromTime(time.Unix(1596000000, 0)))
dp51.SetIntVal(4e9)
dp52 := m5.Gauge().DataPoints().AppendEmpty()
dp52.LabelsMap().InitFromMap(map[string]string{
"direction": "transmit",
"device": "eth0",
"host": "host0",
"kubernetes_node": "node0",
"kubernetes_cluster": "cluster0",
dp52.Attributes().InitFromMap(map[string]pdata.AttributeValue{
"direction": pdata.NewAttributeValueString("transmit"),
"device": pdata.NewAttributeValueString("eth0"),
"host": pdata.NewAttributeValueString("host0"),
"kubernetes_node": pdata.NewAttributeValueString("node0"),
"kubernetes_cluster": pdata.NewAttributeValueString("cluster0"),
}).Sort()
dp52.SetTimestamp(pdata.TimestampFromTime(time.Unix(1596000000, 0)))
dp52.SetIntVal(6e9)
Expand All @@ -478,22 +478,22 @@ func testMetricsData() pdata.ResourceMetrics {
m6.SetDescription("The number of packets transferred")
m6.SetDataType(pdata.MetricDataTypeGauge)
dp61 := m6.Gauge().DataPoints().AppendEmpty()
dp61.LabelsMap().InitFromMap(map[string]string{
"direction": "receive",
"device": "eth0",
"host": "host0",
"kubernetes_node": "node0",
"kubernetes_cluster": "cluster0",
dp61.Attributes().InitFromMap(map[string]pdata.AttributeValue{
"direction": pdata.NewAttributeValueString("receive"),
"device": pdata.NewAttributeValueString("eth0"),
"host": pdata.NewAttributeValueString("host0"),
"kubernetes_node": pdata.NewAttributeValueString("node0"),
"kubernetes_cluster": pdata.NewAttributeValueString("cluster0"),
}).Sort()
dp61.SetTimestamp(pdata.TimestampFromTime(time.Unix(1596000000, 0)))
dp61.SetIntVal(200)
dp62 := m6.Gauge().DataPoints().AppendEmpty()
dp62.LabelsMap().InitFromMap(map[string]string{
"direction": "receive",
"device": "eth1",
"host": "host0",
"kubernetes_node": "node0",
"kubernetes_cluster": "cluster0",
dp62.Attributes().InitFromMap(map[string]pdata.AttributeValue{
"direction": pdata.NewAttributeValueString("receive"),
"device": pdata.NewAttributeValueString("eth1"),
"host": pdata.NewAttributeValueString("host0"),
"kubernetes_node": pdata.NewAttributeValueString("node0"),
"kubernetes_cluster": pdata.NewAttributeValueString("cluster0"),
}).Sort()
dp62.SetTimestamp(pdata.TimestampFromTime(time.Unix(1596000000, 0)))
dp62.SetIntVal(150)
Expand All @@ -503,10 +503,10 @@ func testMetricsData() pdata.ResourceMetrics {
m7.SetUnit("bytes")
m7.SetDataType(pdata.MetricDataTypeGauge)
dp71 := m7.Gauge().DataPoints().AppendEmpty()
dp71.LabelsMap().InitFromMap(map[string]string{
"host": "host0",
"kubernetes_node": "node0",
"kubernetes_cluster": "cluster0",
dp71.Attributes().InitFromMap(map[string]pdata.AttributeValue{
"host": pdata.NewAttributeValueString("host0"),
"kubernetes_node": pdata.NewAttributeValueString("node0"),
"kubernetes_cluster": pdata.NewAttributeValueString("cluster0"),
}).Sort()
dp71.SetTimestamp(pdata.TimestampFromTime(time.Unix(1596000000, 0)))
dp71.SetIntVal(1000)
Expand All @@ -515,10 +515,10 @@ func testMetricsData() pdata.ResourceMetrics {
m8.SetName("container.memory.page_faults")
m8.SetDataType(pdata.MetricDataTypeGauge)
dp81 := m8.Gauge().DataPoints().AppendEmpty()
dp81.LabelsMap().InitFromMap(map[string]string{
"host": "host0",
"kubernetes_node": "node0",
"kubernetes_cluster": "cluster0",
dp81.Attributes().InitFromMap(map[string]pdata.AttributeValue{
"host": pdata.NewAttributeValueString("host0"),
"kubernetes_node": pdata.NewAttributeValueString("node0"),
"kubernetes_cluster": pdata.NewAttributeValueString("cluster0"),
}).Sort()
dp81.SetTimestamp(pdata.TimestampFromTime(time.Unix(1596000000, 0)))
dp81.SetIntVal(1000)
Expand All @@ -527,10 +527,10 @@ func testMetricsData() pdata.ResourceMetrics {
m9.SetName("container.memory.major_page_faults")
m9.SetDataType(pdata.MetricDataTypeGauge)
dp91 := m9.Gauge().DataPoints().AppendEmpty()
dp91.LabelsMap().InitFromMap(map[string]string{
"host": "host0",
"kubernetes_node": "node0",
"kubernetes_cluster": "cluster0",
dp91.Attributes().InitFromMap(map[string]pdata.AttributeValue{
"host": pdata.NewAttributeValueString("host0"),
"kubernetes_node": pdata.NewAttributeValueString("node0"),
"kubernetes_cluster": pdata.NewAttributeValueString("cluster0"),
}).Sort()
dp91.SetTimestamp(pdata.TimestampFromTime(time.Unix(1596000000, 0)))
dp91.SetIntVal(1000)
Expand Down Expand Up @@ -678,13 +678,13 @@ func getResourceMetrics(metrics []map[string]string) pdata.ResourceMetrics {
m.SetDataType(pdata.MetricDataTypeSum)
dp := m.Sum().DataPoints().AppendEmpty()
dp.SetIntVal(0)
labelsMap := dp.LabelsMap()
attributesMap := dp.Attributes()
for k, v := range mp {
if v == "" {
m.SetName(k)
continue
}
labelsMap.Insert(k, v)
attributesMap.InsertString(k, v)
}
}
return rms
Expand Down
Loading

0 comments on commit 6f74449

Please sign in to comment.