Skip to content

Commit 9933897

Browse files
committed
Add support of generic_task metric type.
Fixes GoogleCloudPlatform#117
1 parent 8167a6d commit 9933897

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

exporter/metric/constants.go

+3
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,14 @@ const (
5252
K8SKeyPodName = "k8s.pod.name"
5353
K8SKeyDeploymentName = "k8s.deployment.name"
5454

55+
TaskID = "task_id"
56+
5557
// Monitored Resources types
5658
K8SContainer = "k8s_container"
5759
K8SNode = "k8s_node"
5860
K8SPod = "k8s_pod"
5961
K8SCluster = "k8s_cluster"
6062
GCEInstance = "gce_instance"
6163
AWSEC2Instance = "aws_ec2_instance"
64+
GenericTask = "generic_task"
6265
)

exporter/metric/metric.go

+14
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,15 @@ var awsResourceMap = map[string]string{
115115
"aws_account": CloudKeyAccountID,
116116
}
117117

118+
// For generic_task, assume there's no further transformation required. Still
119+
// provide a map here to check the existence of the required labels.
120+
var genericTaskMap = map[string]string{
121+
"task_id": "task_id",
122+
"location": "location",
123+
"namespace": "namespace",
124+
"job": "job",
125+
}
126+
118127
// newMetricExporter returns an exporter that uploads OTel metric data to Google Cloud Monitoring.
119128
func newMetricExporter(o *options) (*metricExporter, error) {
120129
if strings.TrimSpace(o.ProjectID) == "" {
@@ -335,6 +344,7 @@ func subdivideGCPTypes(labelMap map[string]string) (string, map[string]string) {
335344
_, hasNamespaceName := labelMap[K8SKeyNamespaceName]
336345
_, hasPodName := labelMap[K8SKeyPodName]
337346
_, hasContainerName := labelMap[ContainerKeyName]
347+
_, hasTaskID := labelMap[TaskID]
338348

339349
if hasLocation && hasClusterName && hasNamespaceName && hasPodName && hasContainerName {
340350
return K8SContainer, k8sContainerMap
@@ -354,6 +364,10 @@ func subdivideGCPTypes(labelMap map[string]string) (string, map[string]string) {
354364
return K8SCluster, k8sClusterMap
355365
}
356366

367+
if hasTaskID {
368+
return GenericTask, genericTaskMap
369+
}
370+
357371
return GCEInstance, gceResourceMap
358372
}
359373

0 commit comments

Comments
 (0)