Skip to content

Commit

Permalink
automatically map faas.name and faas.instance to prometheus job and i…
Browse files Browse the repository at this point in the history
…nstance (#695)
  • Loading branch information
dashpole authored Aug 7, 2023
1 parent ce6e82d commit b087585
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ var promTargetKeys = map[string][]string{
locationLabel: {locationLabel, semconv.AttributeCloudAvailabilityZone, semconv.AttributeCloudRegion},
clusterLabel: {clusterLabel, semconv.AttributeK8SClusterName},
namespaceLabel: {namespaceLabel, semconv.AttributeK8SNamespaceName},
jobLabel: {semconv.AttributeServiceName},
jobLabel: {jobLabel, semconv.AttributeFaaSName, semconv.AttributeServiceName},
serviceNamespaceLabel: {semconv.AttributeServiceNamespace},
instanceLabel: {semconv.AttributeServiceInstanceID},
instanceLabel: {instanceLabel, semconv.AttributeFaaSInstance, semconv.AttributeServiceInstanceID},
}

func MapToPrometheusTarget(res pcommon.Resource) *monitoredrespb.MonitoredResource {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,25 @@ func TestMapToPrometheusTarget(t *testing.T) {
},
},
},
{
desc: "Attributes from cloud run",
resourceLabels: map[string]string{
"cloud.region": "us-central1",
"service.name": "service:unknown",
"faas.name": "my-cloud-run-service",
"faas.instance": "1234759430923053489543203",
},
expected: &monitoredrespb.MonitoredResource{
Type: "prometheus_target",
Labels: map[string]string{
"location": "us-central1",
"cluster": "",
"namespace": "",
"job": "my-cloud-run-service",
"instance": "1234759430923053489543203",
},
},
},
} {
t.Run(tc.desc, func(t *testing.T) {
r := pcommon.NewResource()
Expand Down

0 comments on commit b087585

Please sign in to comment.