Repository navigation
Expand file tree
/
Copy pathtraces.go
More file actions
62 lines (52 loc) · 1.67 KB
/
Copy pathtraces.go
File metadata and controls
62 lines (52 loc) · 1.67 KB
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
// Copyright (c) Last9, Inc.
// All rights reserved.
package k8sprocessor
import (
"context"
"log"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/consumer"
"go.opentelemetry.io/collector/pdata/ptrace"
k8shelper "github.com/last9/gpu-telemetry/k8shelper"
)
type k8sInfoTraces struct {
next consumer.Traces
K8sProcessorBase
}
func newK8sInfoTraces(next consumer.Traces, cfg component.Config) *k8sInfoTraces {
return &k8sInfoTraces{
next: next,
K8sProcessorBase: NewK8sProcessorBase(cfg),
}
}
func (kt *k8sInfoTraces) processTraces(ctx context.Context, traces ptrace.Traces) (ptrace.Traces, error) {
gpu2k8s, err := k8shelper.GetGPU2K8s(kt.Config)
if err != nil {
log.Println("k8sprocessor: error getting GPU-to-K8s mapping:", err)
gpu2k8s = make(map[string]k8shelper.K8sMetadata)
}
cloudZone, cloudRegion := extractCloudInfo(gpu2k8s)
resourceSpansSlice := traces.ResourceSpans()
for i := 0; i < resourceSpansSlice.Len(); i++ {
kt.AddCloudAttrs(resourceSpansSlice.At(i).Resource().Attributes(), cloudZone, cloudRegion)
// Resource-level aggregation: attach all pod names on this node
kt.AddK8sMetadataSlice(
resourceSpansSlice.At(i).Resource().Attributes(),
k8shelper.GetGPUData(gpu2k8s),
)
scopeSpansSlice := resourceSpansSlice.At(i).ScopeSpans()
for j := 0; j < scopeSpansSlice.Len(); j++ {
spansSlice := scopeSpansSlice.At(j).Spans()
for k := 0; k < spansSlice.Len(); k++ {
span := spansSlice.At(k)
gpuVal, hasGPU := span.Attributes().Get(gpuIndex)
if hasGPU {
if meta, ok := gpu2k8s[gpuVal.Str()]; ok {
kt.AddK8sMetadata(span.Attributes(), meta)
}
}
}
}
}
return traces, nil
}