Skip to content

Commit

Permalink
prometheus: add instance name to namespace label
Browse files Browse the repository at this point in the history
This change adds the VM instance name to the `namespace` label so
aggregation by namespace is more human readable.

Signed-off-by: Ridwan Sharif <[email protected]>
  • Loading branch information
ridwanmsharif committed Jan 11, 2024
1 parent f8e2ffb commit 30e880f
Show file tree
Hide file tree
Showing 59 changed files with 64 additions and 63 deletions.
2 changes: 1 addition & 1 deletion apps/otlp.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (ReceiverOTLP) gmpResourceProcessors(ctx context.Context) []otel.Component
// location = cloud.availability_zone
stmt(`attributes["location"]`, `resource.attributes["cloud.availability_zone"]`, "gcp_compute_engine"),
// namespace = host.id
stmt(`attributes["namespace"]`, `resource.attributes["host.id"]`, "gcp_compute_engine"),
stmt(`attributes["namespace"]`, `Concat([resource.attributes["host.id"], resource.attributes["host.name"]], "/")`, "gcp_compute_engine"),
// cluster = "__gce__"
stmt(`attributes["cluster"]`, `"__gce__"`, "gcp_compute_engine"),
// instance_name = host.name
Expand Down
3 changes: 2 additions & 1 deletion confgenerator/resourcedetector/gce_detector.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package resourcedetector

import (
"fmt"
"strings"

"github.com/prometheus/prometheus/util/strutil"
Expand Down Expand Up @@ -172,7 +173,7 @@ func (r GCEResource) PrometheusStyleMetadata() map[string]string {

// Set the location, namespace and cluster labels.
metaLabels["location"] = r.Zone
metaLabels["namespace"] = r.InstanceID
metaLabels["namespace"] = fmt.Sprintf("%s/%s", r.InstanceID, r.InstanceName)
metaLabels["cluster"] = "__gce__"

// Set some curated labels.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ processors:
- context: datapoint
statements:
- set(attributes["location"], resource.attributes["cloud.availability_zone"]) where resource.attributes["cloud.availability_zone"] != nil and resource.attributes["cloud.platform"] == "gcp_compute_engine"
- set(attributes["namespace"], resource.attributes["host.id"]) where resource.attributes["host.id"] != nil and resource.attributes["cloud.platform"] == "gcp_compute_engine"
- set(attributes["namespace"], Concat([resource.attributes["host.id"], resource.attributes["host.name"]], "/")) where Concat([resource.attributes["host.id"], resource.attributes["host.name"]], "/") != nil and resource.attributes["cloud.platform"] == "gcp_compute_engine"
- set(attributes["cluster"], "__gce__") where "__gce__" != nil and resource.attributes["cloud.platform"] == "gcp_compute_engine"
- set(attributes["instance_name"], resource.attributes["host.name"]) where resource.attributes["host.name"] != nil and resource.attributes["cloud.platform"] == "gcp_compute_engine"
- set(attributes["machine_type"], resource.attributes["host.type"]) where resource.attributes["host.type"] != nil and resource.attributes["cloud.platform"] == "gcp_compute_engine"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ processors:
- context: datapoint
statements:
- set(attributes["location"], resource.attributes["cloud.availability_zone"]) where resource.attributes["cloud.availability_zone"] != nil and resource.attributes["cloud.platform"] == "gcp_compute_engine"
- set(attributes["namespace"], resource.attributes["host.id"]) where resource.attributes["host.id"] != nil and resource.attributes["cloud.platform"] == "gcp_compute_engine"
- set(attributes["namespace"], Concat([resource.attributes["host.id"], resource.attributes["host.name"]], "/")) where Concat([resource.attributes["host.id"], resource.attributes["host.name"]], "/") != nil and resource.attributes["cloud.platform"] == "gcp_compute_engine"
- set(attributes["cluster"], "__gce__") where "__gce__" != nil and resource.attributes["cloud.platform"] == "gcp_compute_engine"
- set(attributes["instance_name"], resource.attributes["host.name"]) where resource.attributes["host.name"] != nil and resource.attributes["cloud.platform"] == "gcp_compute_engine"
- set(attributes["machine_type"], resource.attributes["host.type"]) where resource.attributes["host.type"] != nil and resource.attributes["cloud.platform"] == "gcp_compute_engine"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ processors:
- context: datapoint
statements:
- set(attributes["location"], resource.attributes["cloud.availability_zone"]) where resource.attributes["cloud.availability_zone"] != nil and resource.attributes["cloud.platform"] == "gcp_compute_engine"
- set(attributes["namespace"], resource.attributes["host.id"]) where resource.attributes["host.id"] != nil and resource.attributes["cloud.platform"] == "gcp_compute_engine"
- set(attributes["namespace"], Concat([resource.attributes["host.id"], resource.attributes["host.name"]], "/")) where Concat([resource.attributes["host.id"], resource.attributes["host.name"]], "/") != nil and resource.attributes["cloud.platform"] == "gcp_compute_engine"
- set(attributes["cluster"], "__gce__") where "__gce__" != nil and resource.attributes["cloud.platform"] == "gcp_compute_engine"
- set(attributes["instance_name"], resource.attributes["host.name"]) where resource.attributes["host.name"] != nil and resource.attributes["cloud.platform"] == "gcp_compute_engine"
- set(attributes["machine_type"], resource.attributes["host.type"]) where resource.attributes["host.type"] != nil and resource.attributes["cloud.platform"] == "gcp_compute_engine"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ processors:
- context: datapoint
statements:
- set(attributes["location"], resource.attributes["cloud.availability_zone"]) where resource.attributes["cloud.availability_zone"] != nil and resource.attributes["cloud.platform"] == "gcp_compute_engine"
- set(attributes["namespace"], resource.attributes["host.id"]) where resource.attributes["host.id"] != nil and resource.attributes["cloud.platform"] == "gcp_compute_engine"
- set(attributes["namespace"], Concat([resource.attributes["host.id"], resource.attributes["host.name"]], "/")) where Concat([resource.attributes["host.id"], resource.attributes["host.name"]], "/") != nil and resource.attributes["cloud.platform"] == "gcp_compute_engine"
- set(attributes["cluster"], "__gce__") where "__gce__" != nil and resource.attributes["cloud.platform"] == "gcp_compute_engine"
- set(attributes["instance_name"], resource.attributes["host.name"]) where resource.attributes["host.name"] != nil and resource.attributes["cloud.platform"] == "gcp_compute_engine"
- set(attributes["machine_type"], resource.attributes["host.type"]) where resource.attributes["host.type"] != nil and resource.attributes["cloud.platform"] == "gcp_compute_engine"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ processors:
- context: datapoint
statements:
- set(attributes["location"], resource.attributes["cloud.availability_zone"]) where resource.attributes["cloud.availability_zone"] != nil and resource.attributes["cloud.platform"] == "gcp_compute_engine"
- set(attributes["namespace"], resource.attributes["host.id"]) where resource.attributes["host.id"] != nil and resource.attributes["cloud.platform"] == "gcp_compute_engine"
- set(attributes["namespace"], Concat([resource.attributes["host.id"], resource.attributes["host.name"]], "/")) where Concat([resource.attributes["host.id"], resource.attributes["host.name"]], "/") != nil and resource.attributes["cloud.platform"] == "gcp_compute_engine"
- set(attributes["cluster"], "__gce__") where "__gce__" != nil and resource.attributes["cloud.platform"] == "gcp_compute_engine"
- set(attributes["instance_name"], resource.attributes["host.name"]) where resource.attributes["host.name"] != nil and resource.attributes["cloud.platform"] == "gcp_compute_engine"
- set(attributes["machine_type"], resource.attributes["host.type"]) where resource.attributes["host.type"] != nil and resource.attributes["cloud.platform"] == "gcp_compute_engine"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ processors:
- context: datapoint
statements:
- set(attributes["location"], resource.attributes["cloud.availability_zone"]) where resource.attributes["cloud.availability_zone"] != nil and resource.attributes["cloud.platform"] == "gcp_compute_engine"
- set(attributes["namespace"], resource.attributes["host.id"]) where resource.attributes["host.id"] != nil and resource.attributes["cloud.platform"] == "gcp_compute_engine"
- set(attributes["namespace"], Concat([resource.attributes["host.id"], resource.attributes["host.name"]], "/")) where Concat([resource.attributes["host.id"], resource.attributes["host.name"]], "/") != nil and resource.attributes["cloud.platform"] == "gcp_compute_engine"
- set(attributes["cluster"], "__gce__") where "__gce__" != nil and resource.attributes["cloud.platform"] == "gcp_compute_engine"
- set(attributes["instance_name"], resource.attributes["host.name"]) where resource.attributes["host.name"] != nil and resource.attributes["cloud.platform"] == "gcp_compute_engine"
- set(attributes["machine_type"], resource.attributes["host.type"]) where resource.attributes["host.type"] != nil and resource.attributes["cloud.platform"] == "gcp_compute_engine"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ processors:
- context: datapoint
statements:
- set(attributes["location"], resource.attributes["cloud.availability_zone"]) where resource.attributes["cloud.availability_zone"] != nil and resource.attributes["cloud.platform"] == "gcp_compute_engine"
- set(attributes["namespace"], resource.attributes["host.id"]) where resource.attributes["host.id"] != nil and resource.attributes["cloud.platform"] == "gcp_compute_engine"
- set(attributes["namespace"], Concat([resource.attributes["host.id"], resource.attributes["host.name"]], "/")) where Concat([resource.attributes["host.id"], resource.attributes["host.name"]], "/") != nil and resource.attributes["cloud.platform"] == "gcp_compute_engine"
- set(attributes["cluster"], "__gce__") where "__gce__" != nil and resource.attributes["cloud.platform"] == "gcp_compute_engine"
- set(attributes["instance_name"], resource.attributes["host.name"]) where resource.attributes["host.name"] != nil and resource.attributes["cloud.platform"] == "gcp_compute_engine"
- set(attributes["machine_type"], resource.attributes["host.type"]) where resource.attributes["host.type"] != nil and resource.attributes["cloud.platform"] == "gcp_compute_engine"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ processors:
- context: datapoint
statements:
- set(attributes["location"], resource.attributes["cloud.availability_zone"]) where resource.attributes["cloud.availability_zone"] != nil and resource.attributes["cloud.platform"] == "gcp_compute_engine"
- set(attributes["namespace"], resource.attributes["host.id"]) where resource.attributes["host.id"] != nil and resource.attributes["cloud.platform"] == "gcp_compute_engine"
- set(attributes["namespace"], Concat([resource.attributes["host.id"], resource.attributes["host.name"]], "/")) where Concat([resource.attributes["host.id"], resource.attributes["host.name"]], "/") != nil and resource.attributes["cloud.platform"] == "gcp_compute_engine"
- set(attributes["cluster"], "__gce__") where "__gce__" != nil and resource.attributes["cloud.platform"] == "gcp_compute_engine"
- set(attributes["instance_name"], resource.attributes["host.name"]) where resource.attributes["host.name"] != nil and resource.attributes["cloud.platform"] == "gcp_compute_engine"
- set(attributes["machine_type"], resource.attributes["host.type"]) where resource.attributes["host.type"] != nil and resource.attributes["cloud.platform"] == "gcp_compute_engine"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ processors:
- context: datapoint
statements:
- set(attributes["location"], resource.attributes["cloud.availability_zone"]) where resource.attributes["cloud.availability_zone"] != nil and resource.attributes["cloud.platform"] == "gcp_compute_engine"
- set(attributes["namespace"], resource.attributes["host.id"]) where resource.attributes["host.id"] != nil and resource.attributes["cloud.platform"] == "gcp_compute_engine"
- set(attributes["namespace"], Concat([resource.attributes["host.id"], resource.attributes["host.name"]], "/")) where Concat([resource.attributes["host.id"], resource.attributes["host.name"]], "/") != nil and resource.attributes["cloud.platform"] == "gcp_compute_engine"
- set(attributes["cluster"], "__gce__") where "__gce__" != nil and resource.attributes["cloud.platform"] == "gcp_compute_engine"
- set(attributes["instance_name"], resource.attributes["host.name"]) where resource.attributes["host.name"] != nil and resource.attributes["cloud.platform"] == "gcp_compute_engine"
- set(attributes["machine_type"], resource.attributes["host.type"]) where resource.attributes["host.type"] != nil and resource.attributes["cloud.platform"] == "gcp_compute_engine"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ processors:
- context: datapoint
statements:
- set(attributes["location"], resource.attributes["cloud.availability_zone"]) where resource.attributes["cloud.availability_zone"] != nil and resource.attributes["cloud.platform"] == "gcp_compute_engine"
- set(attributes["namespace"], resource.attributes["host.id"]) where resource.attributes["host.id"] != nil and resource.attributes["cloud.platform"] == "gcp_compute_engine"
- set(attributes["namespace"], Concat([resource.attributes["host.id"], resource.attributes["host.name"]], "/")) where Concat([resource.attributes["host.id"], resource.attributes["host.name"]], "/") != nil and resource.attributes["cloud.platform"] == "gcp_compute_engine"
- set(attributes["cluster"], "__gce__") where "__gce__" != nil and resource.attributes["cloud.platform"] == "gcp_compute_engine"
- set(attributes["instance_name"], resource.attributes["host.name"]) where resource.attributes["host.name"] != nil and resource.attributes["cloud.platform"] == "gcp_compute_engine"
- set(attributes["machine_type"], resource.attributes["host.type"]) where resource.attributes["host.type"] != nil and resource.attributes["cloud.platform"] == "gcp_compute_engine"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ processors:
- context: datapoint
statements:
- set(attributes["location"], resource.attributes["cloud.availability_zone"]) where resource.attributes["cloud.availability_zone"] != nil and resource.attributes["cloud.platform"] == "gcp_compute_engine"
- set(attributes["namespace"], resource.attributes["host.id"]) where resource.attributes["host.id"] != nil and resource.attributes["cloud.platform"] == "gcp_compute_engine"
- set(attributes["namespace"], Concat([resource.attributes["host.id"], resource.attributes["host.name"]], "/")) where Concat([resource.attributes["host.id"], resource.attributes["host.name"]], "/") != nil and resource.attributes["cloud.platform"] == "gcp_compute_engine"
- set(attributes["cluster"], "__gce__") where "__gce__" != nil and resource.attributes["cloud.platform"] == "gcp_compute_engine"
- set(attributes["instance_name"], resource.attributes["host.name"]) where resource.attributes["host.name"] != nil and resource.attributes["cloud.platform"] == "gcp_compute_engine"
- set(attributes["machine_type"], resource.attributes["host.type"]) where resource.attributes["host.type"] != nil and resource.attributes["cloud.platform"] == "gcp_compute_engine"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ processors:
- context: datapoint
statements:
- set(attributes["location"], resource.attributes["cloud.availability_zone"]) where resource.attributes["cloud.availability_zone"] != nil and resource.attributes["cloud.platform"] == "gcp_compute_engine"
- set(attributes["namespace"], resource.attributes["host.id"]) where resource.attributes["host.id"] != nil and resource.attributes["cloud.platform"] == "gcp_compute_engine"
- set(attributes["namespace"], Concat([resource.attributes["host.id"], resource.attributes["host.name"]], "/")) where Concat([resource.attributes["host.id"], resource.attributes["host.name"]], "/") != nil and resource.attributes["cloud.platform"] == "gcp_compute_engine"
- set(attributes["cluster"], "__gce__") where "__gce__" != nil and resource.attributes["cloud.platform"] == "gcp_compute_engine"
- set(attributes["instance_name"], resource.attributes["host.name"]) where resource.attributes["host.name"] != nil and resource.attributes["cloud.platform"] == "gcp_compute_engine"
- set(attributes["machine_type"], resource.attributes["host.type"]) where resource.attributes["host.type"] != nil and resource.attributes["cloud.platform"] == "gcp_compute_engine"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ processors:
- context: datapoint
statements:
- set(attributes["location"], resource.attributes["cloud.availability_zone"]) where resource.attributes["cloud.availability_zone"] != nil and resource.attributes["cloud.platform"] == "gcp_compute_engine"
- set(attributes["namespace"], resource.attributes["host.id"]) where resource.attributes["host.id"] != nil and resource.attributes["cloud.platform"] == "gcp_compute_engine"
- set(attributes["namespace"], Concat([resource.attributes["host.id"], resource.attributes["host.name"]], "/")) where Concat([resource.attributes["host.id"], resource.attributes["host.name"]], "/") != nil and resource.attributes["cloud.platform"] == "gcp_compute_engine"
- set(attributes["cluster"], "__gce__") where "__gce__" != nil and resource.attributes["cloud.platform"] == "gcp_compute_engine"
- set(attributes["instance_name"], resource.attributes["host.name"]) where resource.attributes["host.name"] != nil and resource.attributes["cloud.platform"] == "gcp_compute_engine"
- set(attributes["machine_type"], resource.attributes["host.type"]) where resource.attributes["host.type"] != nil and resource.attributes["cloud.platform"] == "gcp_compute_engine"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ processors:
- context: datapoint
statements:
- set(attributes["location"], resource.attributes["cloud.availability_zone"]) where resource.attributes["cloud.availability_zone"] != nil and resource.attributes["cloud.platform"] == "gcp_compute_engine"
- set(attributes["namespace"], resource.attributes["host.id"]) where resource.attributes["host.id"] != nil and resource.attributes["cloud.platform"] == "gcp_compute_engine"
- set(attributes["namespace"], Concat([resource.attributes["host.id"], resource.attributes["host.name"]], "/")) where Concat([resource.attributes["host.id"], resource.attributes["host.name"]], "/") != nil and resource.attributes["cloud.platform"] == "gcp_compute_engine"
- set(attributes["cluster"], "__gce__") where "__gce__" != nil and resource.attributes["cloud.platform"] == "gcp_compute_engine"
- set(attributes["instance_name"], resource.attributes["host.name"]) where resource.attributes["host.name"] != nil and resource.attributes["cloud.platform"] == "gcp_compute_engine"
- set(attributes["machine_type"], resource.attributes["host.type"]) where resource.attributes["host.type"] != nil and resource.attributes["cloud.platform"] == "gcp_compute_engine"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ processors:
- context: datapoint
statements:
- set(attributes["location"], resource.attributes["cloud.availability_zone"]) where resource.attributes["cloud.availability_zone"] != nil and resource.attributes["cloud.platform"] == "gcp_compute_engine"
- set(attributes["namespace"], resource.attributes["host.id"]) where resource.attributes["host.id"] != nil and resource.attributes["cloud.platform"] == "gcp_compute_engine"
- set(attributes["namespace"], Concat([resource.attributes["host.id"], resource.attributes["host.name"]], "/")) where Concat([resource.attributes["host.id"], resource.attributes["host.name"]], "/") != nil and resource.attributes["cloud.platform"] == "gcp_compute_engine"
- set(attributes["cluster"], "__gce__") where "__gce__" != nil and resource.attributes["cloud.platform"] == "gcp_compute_engine"
- set(attributes["instance_name"], resource.attributes["host.name"]) where resource.attributes["host.name"] != nil and resource.attributes["cloud.platform"] == "gcp_compute_engine"
- set(attributes["machine_type"], resource.attributes["host.type"]) where resource.attributes["host.type"] != nil and resource.attributes["cloud.platform"] == "gcp_compute_engine"
Expand Down
Loading

0 comments on commit 30e880f

Please sign in to comment.