forked from elastic/beats
-
Notifications
You must be signed in to change notification settings - Fork 0
/
metadata_test.go
79 lines (72 loc) · 2.08 KB
/
metadata_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// 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"
"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"
monitoring "google.golang.org/genproto/googleapis/monitoring/v3"
)
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)
}