-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cherry-pick #18757 to 7.x: [Metricbeat] Fix getting compute instance …
…metadata with partial zone/region config (#18839) * [Metricbeat] Fix getting compute instance metadata with partial zone/region config (#18757) * use zone for getting instance metadata (cherry picked from commit f4c65f3) * update changelog
- Loading branch information
1 parent
408423d
commit 8928a7d
Showing
4 changed files
with
100 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
x-pack/metricbeat/module/googlecloud/stackdriver/compute/metadata_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
// or more contributor license agreements. Licensed under the Elastic License; | ||
// you may not use this file except in compliance with the Elastic License. | ||
|
||
package compute | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/golang/protobuf/ptypes/timestamp" | ||
"github.com/stretchr/testify/assert" | ||
"google.golang.org/genproto/googleapis/api/metric" | ||
"google.golang.org/genproto/googleapis/api/monitoredres" | ||
"google.golang.org/genproto/googleapis/monitoring/v3" | ||
|
||
"github.com/elastic/beats/v7/libbeat/common" | ||
) | ||
|
||
var fake = &monitoring.TimeSeries{ | ||
Resource: &monitoredres.MonitoredResource{ | ||
Type: "gce_instance", | ||
Labels: map[string]string{ | ||
"instance_id": "4624337448093162893", | ||
"project_id": "elastic-metricbeat", | ||
"zone": "us-central1-a", | ||
}, | ||
}, | ||
Metadata: &monitoredres.MonitoredResourceMetadata{ | ||
UserLabels: map[string]string{ | ||
"user": "label", | ||
}, | ||
}, | ||
Metric: &metric.Metric{ | ||
Labels: map[string]string{ | ||
"instance_name": "instance-1", | ||
}, | ||
Type: "compute.googleapis.com/instance/cpu/usage_time", | ||
}, | ||
MetricKind: metric.MetricDescriptor_GAUGE, | ||
ValueType: metric.MetricDescriptor_DOUBLE, | ||
Points: []*monitoring.Point{{ | ||
Value: &monitoring.TypedValue{ | ||
Value: &monitoring.TypedValue_DoubleValue{DoubleValue: 0.0041224284852319215}, | ||
}, | ||
Interval: &monitoring.TimeInterval{ | ||
StartTime: ×tamp.Timestamp{ | ||
Seconds: 1569932700, | ||
}, | ||
EndTime: ×tamp.Timestamp{ | ||
Seconds: 1569932700, | ||
}, | ||
}, | ||
}, { | ||
Value: &monitoring.TypedValue{ | ||
Value: &monitoring.TypedValue_DoubleValue{DoubleValue: 0.004205757571772513}, | ||
}, | ||
Interval: &monitoring.TimeInterval{ | ||
StartTime: ×tamp.Timestamp{ | ||
Seconds: 1569932640, | ||
}, | ||
EndTime: ×tamp.Timestamp{ | ||
Seconds: 1569932640, | ||
}, | ||
}, | ||
}}, | ||
} | ||
|
||
var m = &metadataCollector{ | ||
projectID: "projectID", | ||
instanceCache: common.NewCache(30*time.Second, 13), | ||
} | ||
|
||
func TestInstanceID(t *testing.T) { | ||
instanceID := m.instanceID(fake) | ||
assert.Equal(t, "4624337448093162893", instanceID) | ||
} | ||
|
||
func TestInstanceZone(t *testing.T) { | ||
zone := m.instanceZone(fake) | ||
assert.Equal(t, "us-central1-a", zone) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters