Skip to content

Commit

Permalink
Support location_label config in GCP Metrics Metricset (#41626)
Browse files Browse the repository at this point in the history
* Support of servicelabel config

* Update the label

* update location_label

* Add metricbeat and gcp.yml.disabled

* Update changelog

* update gcp asciidoc

* adress review comments
  • Loading branch information
ishleenk17 authored Dec 2, 2024
1 parent 1660894 commit 3144d38
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,7 @@ https://github.com/elastic/beats/compare/v8.8.1\...main[Check the HEAD diff]
- Bump aerospike-client-go to version v7.7.1 and add support for basic auth in Aerospike module {pull}41233[41233]
- Only watch metadata for ReplicaSets in metricbeat k8s module {pull}41289[41289]
- Add support for region/zone for Vertex AI service in GCP module {pull}41551[41551]
- Add support for location label as an optional configuration parameter in GCP metrics metricset. {issue}41550[41550] {pull}41626[41626]

*Metricbeat*

Expand Down
1 change: 1 addition & 0 deletions metricbeat/docs/modules/gcp.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ metricbeat.modules:
credentials_file_path: "your JSON credentials file path"
exclude_labels: false
period: 1m
location_label: "resource.labels.zone"
metrics:
- aligner: ALIGN_NONE
service: compute
Expand Down
1 change: 1 addition & 0 deletions x-pack/metricbeat/metricbeat.reference.yml
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,7 @@ metricbeat.modules:
credentials_file_path: "your JSON credentials file path"
exclude_labels: false
period: 1m
location_label: "resource.labels.zone"
metrics:
- aligner: ALIGN_NONE
service: compute
Expand Down
1 change: 1 addition & 0 deletions x-pack/metricbeat/module/gcp/_meta/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
credentials_file_path: "your JSON credentials file path"
exclude_labels: false
period: 1m
location_label: "resource.labels.zone"
metrics:
- aligner: ALIGN_NONE
service: compute
Expand Down
27 changes: 27 additions & 0 deletions x-pack/metricbeat/module/gcp/metrics/_meta/docs.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ services under "Google Cloud metrics", but does not work for other services
(`kubernetes` aka GKE for example).
This option allow to override the default and specify an arbitrary metric prefix.

* *location_label*: Use this option to specify the resource label that identifies the location (such as zone or region) for a Google Cloud service when filtering metrics. For example, labels like `resource.label.location` or `resource.label.zone` are used by Google Cloud to represent the region or zone of a resource. This is an optional configuration for the user.

[float]
=== Example Configuration
* `metrics` metricset is enabled to collect metrics from all zones under
Expand Down Expand Up @@ -134,3 +136,28 @@ metric prefix, as for GKE metrics the required prefix is `kubernetes.io/`
metric_types:
- "container/cpu/core_usage_time"
----

* `metrics` metricset is enabled to collect metrics from region
`us-east4` in `elastic-observability` project. The metric, number of replicas of the prediction model is
collected from a new GCP service `aiplatform`. Since its a new service which is not supported by
default in this metricset, the user provides the servicelabel (resource.label.location), for which
user wants to filter the incoming data

+
[source,yaml]
----
- module: gcp
metricsets:
- metrics
project_id: "elastic-observability"
credentials_json: "your JSON credentials"
exclude_labels: false
period: 1m
location_label: "resource.label.location" # This is an optional configuration
regions:
- us-east4
metrics:
- service: aiplatform
metric_types:
- "prediction/online/replicas"
----
12 changes: 11 additions & 1 deletion x-pack/metricbeat/module/gcp/metrics/metrics_requester.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ func (r *metricsRequester) getFilterForMetric(serviceName, m string) string {
// NOTE: some GCP services are global, not regional or zonal. To these services we don't need
// to apply any additional filters.
if locationsConfigsAvailable && !isAGlobalService(serviceName) {
serviceLabel := getServiceLabelFor(serviceName)
serviceLabel := r.getServiceLabel(serviceName)
f = r.buildLocationFilter(serviceLabel, f)
}

Expand All @@ -261,6 +261,16 @@ func (r *metricsRequester) getFilterForMetric(serviceName, m string) string {
return f
}

// getServiceLabel determines the service label to be used for the given service name. If a custom
// location label is configured, it will be used. Otherwise, the default service label for the
// given service name will be returned.
func (r *metricsRequester) getServiceLabel(serviceName string) string {
if r.config.LocationLabel != "" {
return r.config.LocationLabel
}
return getServiceLabelFor(serviceName)
}

// Returns a GCP TimeInterval based on the ingestDelay and samplePeriod from ListMetricDescriptor
func getTimeIntervalAligner(ingestDelay time.Duration, samplePeriod time.Duration, collectionPeriod *durationpb.Duration, inputAligner string) (*monitoringpb.TimeInterval, string) {
var startTime, endTime, currentTime time.Time
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,13 @@ func TestGetFilterForMetric(t *testing.T) {
metricsRequester{config: config{Region: "foobar", Regions: []string{"foo", "bar"}}, logger: logger},
"metric.type=\"dummy\" AND resource.labels.zone = starts_with(\"foobar\")",
},
{
"aiplatform service with configured region and zone",
"aiplatform",
"",
metricsRequester{config: config{Region: "foo", Zone: "bar", LocationLabel: "resource.label.location"}, logger: logger},
"metric.type=\"dummy\" AND resource.label.location = starts_with(\"foo\")",
},
}

for _, c := range cases {
Expand Down
1 change: 1 addition & 0 deletions x-pack/metricbeat/module/gcp/metrics/metricset.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ type config struct {
Zone string `config:"zone"`
Region string `config:"region"`
Regions []string `config:"regions"`
LocationLabel string `config:"location_label"`
ProjectID string `config:"project_id" validate:"required"`
ExcludeLabels bool `config:"exclude_labels"`
CredentialsFilePath string `config:"credentials_file_path"`
Expand Down
1 change: 1 addition & 0 deletions x-pack/metricbeat/modules.d/gcp.yml.disabled
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
credentials_file_path: "your JSON credentials file path"
exclude_labels: false
period: 1m
location_label: "resource.labels.zone"
metrics:
- aligner: ALIGN_NONE
service: compute
Expand Down

0 comments on commit 3144d38

Please sign in to comment.