Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Metricbeat] Remove checking region/zone and service name from googlecloud #18398

Merged
merged 4 commits into from
May 11, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions metricbeat/docs/modules/googlecloud.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,22 @@ metricbeat.modules:
credentials_file_path: "your JSON credentials file path"
exclude_labels: false
period: 5m

- module: googlecloud
metricsets:
- stackdriver
project_id: "your project id"
credentials_file_path: "your JSON credentials file path"
exclude_labels: false
period: 1m
service: compute
metrics:
- aligner: ALIGN_NONE
metric_types:
- "compute.googleapis.com/instance/cpu/reserved_cores"
- "compute.googleapis.com/instance/cpu/usage_time"
- "compute.googleapis.com/instance/cpu/utilization"
- "compute.googleapis.com/instance/uptime"
----

[float]
Expand Down
16 changes: 16 additions & 0 deletions x-pack/metricbeat/metricbeat.reference.yml
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,22 @@ metricbeat.modules:
exclude_labels: false
period: 5m

- module: googlecloud
metricsets:
- stackdriver
project_id: "your project id"
credentials_file_path: "your JSON credentials file path"
exclude_labels: false
period: 1m
service: compute
metrics:
- aligner: ALIGN_NONE
metric_types:
- "compute.googleapis.com/instance/cpu/reserved_cores"
- "compute.googleapis.com/instance/cpu/usage_time"
- "compute.googleapis.com/instance/cpu/utilization"
- "compute.googleapis.com/instance/uptime"

#------------------------------- Graphite Module -------------------------------
- module: graphite
metricsets: ["server"]
Expand Down
16 changes: 16 additions & 0 deletions x-pack/metricbeat/module/googlecloud/_meta/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,19 @@
credentials_file_path: "your JSON credentials file path"
exclude_labels: false
period: 5m

- module: googlecloud
metricsets:
- stackdriver
project_id: "your project id"
credentials_file_path: "your JSON credentials file path"
exclude_labels: false
period: 1m
service: compute
metrics:
- aligner: ALIGN_NONE
metric_types:
- "compute.googleapis.com/instance/cpu/reserved_cores"
- "compute.googleapis.com/instance/cpu/usage_time"
- "compute.googleapis.com/instance/cpu/utilization"
- "compute.googleapis.com/instance/uptime"
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
package stackdriver

import (
"github.com/pkg/errors"

"github.com/elastic/beats/v7/x-pack/metricbeat/module/googlecloud"
"github.com/elastic/beats/v7/x-pack/metricbeat/module/googlecloud/stackdriver/compute"
)
Expand All @@ -17,9 +15,7 @@ func NewMetadataServiceForConfig(c config) (googlecloud.MetadataService, error)
switch c.ServiceName {
case googlecloud.ServiceCompute:
return compute.NewMetadataService(c.ProjectID, c.Zone, c.Region, c.opt...)
case googlecloud.ServicePubsub, googlecloud.ServiceLoadBalancing, googlecloud.ServiceStorage:
return nil, nil
default:
return nil, errors.Errorf("service '%s' not supported", c.ServiceName)
return nil, nil
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ var serviceRegexp = regexp.MustCompile(`^(?P<service>[a-z]+)\.googleapis.com.*`)
// if they have a region specified.
func (r *stackdriverMetricsRequester) getFilterForMetric(m string) (f string) {
f = fmt.Sprintf(`metric.type="%s"`, m)
if r.config.Zone == "" && r.config.Region == "" {
return
}

service := serviceRegexp.ReplaceAllString(m, "${service}")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ func TestGetFilterForMetric(t *testing.T) {
stackdriverMetricsRequester{config: config{Zone: "us-west1-*"}, logger: logger},
"metric.type=\"compute.googleapis.com/instance/uptime\" AND resource.labels.zone = starts_with(\"us-west1-\")",
},
{
"compute service with no region/zone in config",
"compute.googleapis.com/firewall/dropped_bytes_count",
stackdriverMetricsRequester{config: config{}},
"metric.type=\"compute.googleapis.com/firewall/dropped_bytes_count\"",
},
}

for _, c := range cases {
Expand Down
23 changes: 8 additions & 15 deletions x-pack/metricbeat/module/googlecloud/stackdriver/metricset.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,19 +188,6 @@ func validatePeriodForGCP(d time.Duration) (err error) {
return nil
}

// Validate googlecloud module config
func (c *config) Validate() error {
// storage metricset does not require region or zone config parameter.
if c.ServiceName == "storage" {
return nil
}

if c.Region == "" && c.Zone == "" {
return errors.New("region and zone in Google Cloud config file cannot both be empty")
}
return nil
}

// Validate stackdriver related config
func (mc *stackDriverConfig) Validate() error {
gcpAlignerNames := make([]string, 0)
Expand Down Expand Up @@ -234,10 +221,16 @@ func metricDescriptor(ctx context.Context, client *monitoring.MetricClient, proj
return metricsWithMeta, errors.Errorf("Could not make ListMetricDescriptors request: %s: %v", mt, err)
}

metricsWithMeta[mt] = metricMeta{
meta := metricMeta{
samplePeriod: time.Duration(out.Metadata.SamplePeriod.Seconds) * time.Second,
ingestDelay: time.Duration(out.Metadata.IngestDelay.Seconds) * time.Second,
ingestDelay: 0 * time.Second,
}

if out.Metadata.IngestDelay != nil {
kaiyan-sheng marked this conversation as resolved.
Show resolved Hide resolved
meta.ingestDelay = time.Duration(out.Metadata.IngestDelay.Seconds) * time.Second
}

metricsWithMeta[mt] = meta
}
}

Expand Down
16 changes: 16 additions & 0 deletions x-pack/metricbeat/modules.d/googlecloud.yml.disabled
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,19 @@
credentials_file_path: "your JSON credentials file path"
exclude_labels: false
period: 5m

- module: googlecloud
metricsets:
- stackdriver
project_id: "your project id"
credentials_file_path: "your JSON credentials file path"
exclude_labels: false
period: 1m
service: compute
metrics:
- aligner: ALIGN_NONE
metric_types:
- "compute.googleapis.com/instance/cpu/reserved_cores"
- "compute.googleapis.com/instance/cpu/usage_time"
- "compute.googleapis.com/instance/cpu/utilization"
- "compute.googleapis.com/instance/uptime"