-
Notifications
You must be signed in to change notification settings - Fork 4.9k
/
identity.go
32 lines (26 loc) · 1.04 KB
/
identity.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
// 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 (
"context"
"errors"
"github.com/elastic/beats/v7/x-pack/metricbeat/module/gcp"
)
// ID returns a generated ID for a Compute resource based on its labels, projectID, zone, timestamp and instance ID
// It's purpose is to group metrics that share that ID (the ones on the same instance, basically)
func (s *metadataCollector) ID(ctx context.Context, in *gcp.MetadataCollectorInputData) (string, error) {
metadata, err := s.Metadata(ctx, in.TimeSeries)
if err != nil {
return "", err
}
metadata.ECS.Update(metadata.Labels)
if in.Timestamp != nil {
metadata.ECS.Put("timestamp", in.Timestamp)
} else if in.Point != nil {
metadata.ECS.Put("timestamp", in.Point.Interval.EndTime)
} else {
return "", errors.New("no timestamp information found")
}
return metadata.ECS.String(), nil
}