Skip to content

Commit 3cc0d37

Browse files
authored
SignalFx exporter: Fix producing cloud unique ID dimension (#966)
This change fixes creation of cloud unique ID based on attributes from resource detection processor
1 parent 4ca3574 commit 3cc0d37

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

exporter/signalfxexporter/translation/converter.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ var (
7575

7676
// infinity bound dimension value is used on all histograms.
7777
infinityBoundSFxDimValue = float64ToDimValue(math.Inf(1))
78+
79+
// TODO: expose the constants somewhere in the project and share with resource detector processor
80+
cloudProviderAWS = "aws"
81+
cloudProviderGCP = "gcp"
7882
)
7983

8084
// MetricsConverter converts MetricsData to sfxpb DataPoints. It holds an optional
@@ -420,8 +424,7 @@ func appendResourceAttributesToDimensions(dims []*sfxpb.Dimension, resourceAttr
420424
filter := func(k string) bool { return true }
421425

422426
switch provider {
423-
// TODO: Should these be defined as constants in resourcedetector module that we import or somewhere else?
424-
case "ec2":
427+
case cloudProviderAWS:
425428
if instanceID == "" || region == "" || accountID == "" {
426429
break
427430
}
@@ -435,7 +438,7 @@ func appendResourceAttributesToDimensions(dims []*sfxpb.Dimension, resourceAttr
435438
Key: "AWSUniqueId",
436439
Value: fmt.Sprintf("%s_%s_%s", instanceID, region, accountID),
437440
})
438-
case "gce":
441+
case cloudProviderGCP:
439442
if accountID == "" || instanceID == "" {
440443
break
441444
}

exporter/signalfxexporter/translation/converter_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ func Test_MetricDataToSignalFxV2(t *testing.T) {
192192
Labels: map[string]string{
193193
"k/r0": "vr0",
194194
"k/r1": "vr1",
195-
"cloud.provider": "ec2",
195+
"cloud.provider": cloudProviderAWS,
196196
"cloud.account.id": "efgh",
197197
"cloud.region": "us-east",
198198
},
@@ -209,7 +209,7 @@ func Test_MetricDataToSignalFxV2(t *testing.T) {
209209
tsMSecs,
210210
&sfxMetricTypeGauge,
211211
append([]string{"cloud_account_id", "cloud_provider", "cloud_region", "k_r0", "k_r1"}, keys...),
212-
append([]string{"efgh", "ec2", "us-east", "vr0", "vr1"}, values...),
212+
append([]string{"efgh", cloudProviderAWS, "us-east", "vr0", "vr1"}, values...),
213213
doubleVal),
214214
},
215215
},
@@ -222,7 +222,7 @@ func Test_MetricDataToSignalFxV2(t *testing.T) {
222222
Labels: map[string]string{
223223
"k/r0": "vr0",
224224
"k/r1": "vr1",
225-
"cloud.provider": "ec2",
225+
"cloud.provider": cloudProviderAWS,
226226
"cloud.account.id": "efgh",
227227
"cloud.region": "us-east",
228228
"host.id": "abcd",
@@ -245,15 +245,15 @@ func Test_MetricDataToSignalFxV2(t *testing.T) {
245245
},
246246
},
247247
{
248-
name: "with_resources_cloud_gce_dim_partial",
248+
name: "with_resources_cloud_gcp_dim_partial",
249249
metricsDataFn: func() []consumerdata.MetricsData {
250250
return []consumerdata.MetricsData{
251251
{
252252
Resource: &resourcepb.Resource{
253253
Labels: map[string]string{
254254
"k/r0": "vr0",
255255
"k/r1": "vr1",
256-
"cloud.provider": "gce",
256+
"cloud.provider": cloudProviderGCP,
257257
"host.id": "abcd",
258258
},
259259
},
@@ -269,7 +269,7 @@ func Test_MetricDataToSignalFxV2(t *testing.T) {
269269
tsMSecs,
270270
&sfxMetricTypeGauge,
271271
append([]string{"cloud_provider", "host_id", "k_r0", "k_r1"}, keys...),
272-
append([]string{"gce", "abcd", "vr0", "vr1"}, values...),
272+
append([]string{cloudProviderGCP, "abcd", "vr0", "vr1"}, values...),
273273
doubleVal),
274274
},
275275
},
@@ -282,7 +282,7 @@ func Test_MetricDataToSignalFxV2(t *testing.T) {
282282
Labels: map[string]string{
283283
"k/r0": "vr0",
284284
"k/r1": "vr1",
285-
"cloud.provider": "gce",
285+
"cloud.provider": cloudProviderGCP,
286286
"cloud.account.id": "efgh",
287287
"host.id": "abcd",
288288
},

0 commit comments

Comments
 (0)