Skip to content

Commit 2a4c8d7

Browse files
authored
Collect InferencePoolCount in telemetry (#4008)
Proposed changes Problem: Want to collect number of referenced InferencePools in cluster. Solution: Collect the count of referenced InferencePools. Testing: Unit tests and manually verified collection via debug logs.
1 parent 75998ba commit 2a4c8d7

File tree

6 files changed

+24
-0
lines changed

6 files changed

+24
-0
lines changed

internal/controller/telemetry/collector.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ type Data struct {
6666
ControlPlanePodCount int64
6767
// NginxOneConnectionEnabled is a boolean that indicates whether the connection to the Nginx One Console is enabled.
6868
NginxOneConnectionEnabled bool
69+
// InferencePoolCount is the number of InferencePools that are referenced by at least one Route.
70+
InferencePoolCount int64
6971
}
7072

7173
// NGFResourceCounts stores the counts of all relevant resources that NGF processes and generates configuration from.
@@ -174,6 +176,8 @@ func (c DataCollectorImpl) Collect(ctx context.Context) (Data, error) {
174176

175177
nginxPodCount := getNginxPodCount(g, clusterInfo.NodeCount)
176178

179+
inferencePoolCount := int64(len(g.ReferencedInferencePools))
180+
177181
data := Data{
178182
Data: tel.Data{
179183
ProjectName: "NGF",
@@ -194,6 +198,7 @@ func (c DataCollectorImpl) Collect(ctx context.Context) (Data, error) {
194198
NginxPodCount: nginxPodCount,
195199
ControlPlanePodCount: int64(replicaCount),
196200
NginxOneConnectionEnabled: c.cfg.NginxOneConsoleConnection,
201+
InferencePoolCount: inferencePoolCount,
197202
}
198203

199204
return data, nil

internal/controller/telemetry/collector_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,11 @@ var _ = Describe("Collector", Ordered, func() {
417417
},
418418
},
419419
},
420+
ReferencedInferencePools: map[types.NamespacedName]*graph.ReferencedInferencePool{
421+
{Namespace: "test", Name: "inferencePool-1"}: {},
422+
{Namespace: "test", Name: "inferencePool-2"}: {},
423+
{Namespace: "test", Name: "inferencePool-3"}: {},
424+
},
420425
}
421426

422427
configs := []*dataplane.Configuration{
@@ -520,6 +525,8 @@ var _ = Describe("Collector", Ordered, func() {
520525
expData.ControlPlanePodCount = int64(2)
521526
expData.NginxOneConnectionEnabled = true
522527

528+
expData.InferencePoolCount = 3
529+
523530
data, err := dataCollector.Collect(ctx)
524531
Expect(err).ToNot(HaveOccurred())
525532

@@ -700,6 +707,9 @@ var _ = Describe("Collector", Ordered, func() {
700707
BackendTLSPolicies: map[types.NamespacedName]*graph.BackendTLSPolicy{
701708
{Namespace: "test", Name: "BackendTLSPolicy-1"}: {},
702709
},
710+
ReferencedInferencePools: map[types.NamespacedName]*graph.ReferencedInferencePool{
711+
{Namespace: "test", Name: "inferencePool-1"}: {},
712+
},
703713
}
704714

705715
config1 = []*dataplane.Configuration{
@@ -783,6 +793,7 @@ var _ = Describe("Collector", Ordered, func() {
783793
BackendTLSPolicyCount: 1,
784794
}
785795
expData.NginxPodCount = 1
796+
expData.InferencePoolCount = 1
786797

787798
data, err := dataCollector.Collect(ctx)
788799

internal/controller/telemetry/data.avdl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,5 +114,8 @@ attached at the Gateway level. */
114114
/** NginxOneConnectionEnabled is a boolean that indicates whether the connection to the Nginx One Console is enabled. */
115115
boolean? NginxOneConnectionEnabled = null;
116116

117+
/** InferencePoolCount is the number of InferencePools that are referenced by at least one Route. */
118+
long? InferencePoolCount = null;
119+
117120
}
118121
}

internal/controller/telemetry/data_attributes_generated.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ func (d *Data) Attributes() []attribute.KeyValue {
2323
attrs = append(attrs, attribute.Int64("NginxPodCount", d.NginxPodCount))
2424
attrs = append(attrs, attribute.Int64("ControlPlanePodCount", d.ControlPlanePodCount))
2525
attrs = append(attrs, attribute.Bool("NginxOneConnectionEnabled", d.NginxOneConnectionEnabled))
26+
attrs = append(attrs, attribute.Int64("InferencePoolCount", d.InferencePoolCount))
2627

2728
return attrs
2829
}

internal/controller/telemetry/data_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ func TestDataAttributes(t *testing.T) {
4747
NginxPodCount: 3,
4848
ControlPlanePodCount: 3,
4949
NginxOneConnectionEnabled: true,
50+
InferencePoolCount: 16,
5051
}
5152

5253
expected := []attribute.KeyValue{
@@ -86,6 +87,7 @@ func TestDataAttributes(t *testing.T) {
8687
attribute.Int64("NginxPodCount", 3),
8788
attribute.Int64("ControlPlanePodCount", 3),
8889
attribute.Bool("NginxOneConnectionEnabled", true),
90+
attribute.Int64("InferencePoolCount", 16),
8991
}
9092

9193
result := data.Attributes()
@@ -132,6 +134,7 @@ func TestDataAttributesWithEmptyData(t *testing.T) {
132134
attribute.Int64("NginxPodCount", 0),
133135
attribute.Int64("ControlPlanePodCount", 0),
134136
attribute.Bool("NginxOneConnectionEnabled", false),
137+
attribute.Int64("InferencePoolCount", 0),
135138
}
136139

137140
result := data.Attributes()

tests/suite/telemetry_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ var _ = Describe("Telemetry test with OTel collector", Label("telemetry"), func(
9696
"NginxPodCount: Int(0)",
9797
"ControlPlanePodCount: Int(1)",
9898
"NginxOneConnectionEnabled: Bool(false)",
99+
"InferencePoolCount: Int(0)",
99100
},
100101
)
101102
})

0 commit comments

Comments
 (0)