Skip to content

Commit 73c60fb

Browse files
committed
Move ProxySettingsPolicies count out of NGFResourceCounts
1 parent 623c471 commit 73c60fb

File tree

7 files changed

+62
-48
lines changed

7 files changed

+62
-48
lines changed

internal/controller/telemetry/collector.go

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ type Data struct { //nolint //required to skip golangci-lint-full fieldalignment
7171
InferencePoolCount int64
7272
// BuildOS is the base operating system the control plane was built on (e.g. alpine, ubi).
7373
BuildOS string
74+
// GatewayAttachedProxySettingsPolicyCount is the number of relevant ProxySettingsPolicies
75+
// attached at the Gateway level.
76+
GatewayAttachedProxySettingsPolicyCount int64
77+
// RouteAttachedProxySettingsPolicyCount is the number of relevant ProxySettingsPolicies
78+
// attached at the Route level.
79+
RouteAttachedProxySettingsPolicyCount int64
7480
}
7581

7682
// NGFResourceCounts stores the counts of all relevant resources that NGF processes and generates configuration from.
@@ -110,12 +116,6 @@ type NGFResourceCounts struct {
110116
UpstreamSettingsPolicyCount int64
111117
// GatewayAttachedNpCount is the total number of NginxProxy resources that are attached to a Gateway.
112118
GatewayAttachedNpCount int64
113-
// GatewayAttachedProxySettingsPolicyCount is the number of relevant ProxySettingsPolicies
114-
// attached at the Gateway level.
115-
GatewayAttachedProxySettingsPolicyCount int64
116-
// RouteAttachedProxySettingsPolicyCount is the number of relevant ProxySettingsPolicies
117-
// attached at the Route level.
118-
RouteAttachedProxySettingsPolicyCount int64
119119
}
120120

121121
func (rc *NGFResourceCounts) CountPolicies(g *graph.Graph) {
@@ -137,21 +137,32 @@ func (rc *NGFResourceCounts) CountPolicies(g *graph.Graph) {
137137
rc.ObservabilityPolicyCount++
138138
case kinds.UpstreamSettingsPolicy:
139139
rc.UpstreamSettingsPolicyCount++
140-
case kinds.ProxySettingsPolicy:
140+
}
141+
}
142+
}
143+
144+
func CountProxySettingsPolicies(g *graph.Graph) (int64, int64) {
145+
gatewayAttachedProxySettingsPolicyCount := int64(0)
146+
routeAttachedProxySettingsPolicyCount := int64(0)
147+
148+
for policyKey, policy := range g.NGFPolicies {
149+
if policyKey.GVK.Kind == kinds.ProxySettingsPolicy {
141150
if len(policy.TargetRefs) == 0 {
142151
continue
143152
}
144153

145154
for _, tr := range policy.TargetRefs {
146155
switch tr.Kind {
147156
case kinds.Gateway:
148-
rc.GatewayAttachedProxySettingsPolicyCount++
157+
gatewayAttachedProxySettingsPolicyCount++
149158
case kinds.HTTPRoute, kinds.GRPCRoute:
150-
rc.RouteAttachedProxySettingsPolicyCount++
159+
routeAttachedProxySettingsPolicyCount++
151160
}
152161
}
153162
}
154163
}
164+
165+
return gatewayAttachedProxySettingsPolicyCount, routeAttachedProxySettingsPolicyCount
155166
}
156167

157168
// DataCollectorConfig holds configuration parameters for DataCollectorImpl.
@@ -228,6 +239,7 @@ func (c DataCollectorImpl) Collect(ctx context.Context) (Data, error) {
228239
buildOs = "alpine"
229240
}
230241
inferencePoolCount := int64(len(g.ReferencedInferencePools))
242+
gatewayAttachedProxySettingsPolicyCount, routeAttachedProxySettingsPolicyCount := CountProxySettingsPolicies(g)
231243

232244
data := Data{
233245
Data: tel.Data{
@@ -240,17 +252,19 @@ func (c DataCollectorImpl) Collect(ctx context.Context) (Data, error) {
240252
InstallationID: deploymentID,
241253
ClusterNodeCount: int64(clusterInfo.NodeCount),
242254
},
243-
NGFResourceCounts: graphResourceCount,
244-
ImageSource: c.cfg.ImageSource,
245-
BuildOS: buildOs,
246-
FlagNames: c.cfg.Flags.Names,
247-
FlagValues: c.cfg.Flags.Values,
248-
SnippetsFiltersDirectives: snippetsFiltersDirectives,
249-
SnippetsFiltersDirectivesCount: snippetsFiltersDirectivesCount,
250-
NginxPodCount: nginxPodCount,
251-
ControlPlanePodCount: int64(replicaCount),
252-
NginxOneConnectionEnabled: c.cfg.NginxOneConsoleConnection,
253-
InferencePoolCount: inferencePoolCount,
255+
NGFResourceCounts: graphResourceCount,
256+
ImageSource: c.cfg.ImageSource,
257+
BuildOS: buildOs,
258+
FlagNames: c.cfg.Flags.Names,
259+
FlagValues: c.cfg.Flags.Values,
260+
SnippetsFiltersDirectives: snippetsFiltersDirectives,
261+
SnippetsFiltersDirectivesCount: snippetsFiltersDirectivesCount,
262+
NginxPodCount: nginxPodCount,
263+
ControlPlanePodCount: int64(replicaCount),
264+
NginxOneConnectionEnabled: c.cfg.NginxOneConsoleConnection,
265+
InferencePoolCount: inferencePoolCount,
266+
GatewayAttachedProxySettingsPolicyCount: gatewayAttachedProxySettingsPolicyCount,
267+
RouteAttachedProxySettingsPolicyCount: routeAttachedProxySettingsPolicyCount,
254268
}
255269

256270
return data, nil

internal/controller/telemetry/collector_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -510,8 +510,6 @@ var _ = Describe("Collector", Ordered, func() {
510510
SnippetsFilterCount: 3,
511511
UpstreamSettingsPolicyCount: 1,
512512
GatewayAttachedNpCount: 2,
513-
GatewayAttachedProxySettingsPolicyCount: 2,
514-
RouteAttachedProxySettingsPolicyCount: 4,
515513
}
516514
expData.ClusterVersion = "1.29.2"
517515
expData.ClusterPlatform = "kind"
@@ -547,6 +545,8 @@ var _ = Describe("Collector", Ordered, func() {
547545
expData.BuildOS = "alpine"
548546

549547
expData.InferencePoolCount = 3
548+
expData.GatewayAttachedProxySettingsPolicyCount = 2
549+
expData.RouteAttachedProxySettingsPolicyCount = 4
550550

551551
data, err := dataCollector.Collect(ctx)
552552
Expect(err).ToNot(HaveOccurred())
@@ -828,11 +828,11 @@ var _ = Describe("Collector", Ordered, func() {
828828
UpstreamSettingsPolicyCount: 1,
829829
GatewayAttachedNpCount: 1,
830830
BackendTLSPolicyCount: 1,
831-
GatewayAttachedProxySettingsPolicyCount: 2,
832-
RouteAttachedProxySettingsPolicyCount: 3,
833831
}
834832
expData.NginxPodCount = 1
835833
expData.InferencePoolCount = 1
834+
expData.GatewayAttachedProxySettingsPolicyCount = 2
835+
expData.RouteAttachedProxySettingsPolicyCount = 3
836836

837837
data, err := dataCollector.Collect(ctx)
838838

internal/controller/telemetry/data.avdl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,6 @@ attached at the Gateway level. */
105105
/** GatewayAttachedNpCount is the total number of NginxProxy resources that are attached to a Gateway. */
106106
long? GatewayAttachedNpCount = null;
107107

108-
/** GatewayAttachedProxySettingsPolicyCount is the number of relevant ProxySettingsPolicies
109-
attached at the Gateway level. */
110-
long? GatewayAttachedProxySettingsPolicyCount = null;
111-
112-
/** RouteAttachedProxySettingsPolicyCount is the number of relevant ProxySettingsPolicies
113-
attached at the Route level. */
114-
long? RouteAttachedProxySettingsPolicyCount = null;
115-
116108
/** NginxPodCount is the total number of Nginx data plane Pods. */
117109
long? NginxPodCount = null;
118110

@@ -128,5 +120,13 @@ attached at the Route level. */
128120
/** BuildOS is the base operating system the control plane was built on (e.g. alpine, ubi). */
129121
string? BuildOS = null;
130122

123+
/** GatewayAttachedProxySettingsPolicyCount is the number of relevant ProxySettingsPolicies
124+
attached at the Gateway level. */
125+
long? GatewayAttachedProxySettingsPolicyCount = null;
126+
127+
/** RouteAttachedProxySettingsPolicyCount is the number of relevant ProxySettingsPolicies
128+
attached at the Route level. */
129+
long? RouteAttachedProxySettingsPolicyCount = null;
130+
131131
}
132132
}

internal/controller/telemetry/data_attributes_generated.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ func (d *Data) Attributes() []attribute.KeyValue {
2525
attrs = append(attrs, attribute.Bool("NginxOneConnectionEnabled", d.NginxOneConnectionEnabled))
2626
attrs = append(attrs, attribute.Int64("InferencePoolCount", d.InferencePoolCount))
2727
attrs = append(attrs, attribute.String("BuildOS", d.BuildOS))
28+
attrs = append(attrs, attribute.Int64("GatewayAttachedProxySettingsPolicyCount", d.GatewayAttachedProxySettingsPolicyCount))
29+
attrs = append(attrs, attribute.Int64("RouteAttachedProxySettingsPolicyCount", d.RouteAttachedProxySettingsPolicyCount))
2830

2931
return attrs
3032
}

internal/controller/telemetry/data_test.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,15 @@ func TestDataAttributes(t *testing.T) {
4141
SnippetsFilterCount: 13,
4242
UpstreamSettingsPolicyCount: 14,
4343
GatewayAttachedNpCount: 15,
44-
GatewayAttachedProxySettingsPolicyCount: 17,
45-
RouteAttachedProxySettingsPolicyCount: 18,
4644
},
47-
SnippetsFiltersDirectives: []string{"main-three-count", "http-two-count", "server-one-count"},
48-
SnippetsFiltersDirectivesCount: []int64{3, 2, 1},
49-
NginxPodCount: 3,
50-
ControlPlanePodCount: 3,
51-
NginxOneConnectionEnabled: true,
52-
InferencePoolCount: 16,
45+
SnippetsFiltersDirectives: []string{"main-three-count", "http-two-count", "server-one-count"},
46+
SnippetsFiltersDirectivesCount: []int64{3, 2, 1},
47+
NginxPodCount: 3,
48+
ControlPlanePodCount: 3,
49+
NginxOneConnectionEnabled: true,
50+
InferencePoolCount: 16,
51+
GatewayAttachedProxySettingsPolicyCount: 17,
52+
RouteAttachedProxySettingsPolicyCount: 18,
5353
}
5454

5555
expected := []attribute.KeyValue{
@@ -86,13 +86,13 @@ func TestDataAttributes(t *testing.T) {
8686
attribute.Int64("SnippetsFilterCount", 13),
8787
attribute.Int64("UpstreamSettingsPolicyCount", 14),
8888
attribute.Int64("GatewayAttachedNpCount", 15),
89-
attribute.Int64("GatewayAttachedProxySettingsPolicyCount", 17),
90-
attribute.Int64("RouteAttachedProxySettingsPolicyCount", 18),
9189
attribute.Int64("NginxPodCount", 3),
9290
attribute.Int64("ControlPlanePodCount", 3),
9391
attribute.Bool("NginxOneConnectionEnabled", true),
9492
attribute.Int64("InferencePoolCount", 16),
9593
attribute.String("BuildOS", ""),
94+
attribute.Int64("GatewayAttachedProxySettingsPolicyCount", 17),
95+
attribute.Int64("RouteAttachedProxySettingsPolicyCount", 18),
9696
}
9797

9898
result := data.Attributes()
@@ -136,13 +136,13 @@ func TestDataAttributesWithEmptyData(t *testing.T) {
136136
attribute.Int64("SnippetsFilterCount", 0),
137137
attribute.Int64("UpstreamSettingsPolicyCount", 0),
138138
attribute.Int64("GatewayAttachedNpCount", 0),
139-
attribute.Int64("GatewayAttachedProxySettingsPolicyCount", 0),
140-
attribute.Int64("RouteAttachedProxySettingsPolicyCount", 0),
141139
attribute.Int64("NginxPodCount", 0),
142140
attribute.Int64("ControlPlanePodCount", 0),
143141
attribute.Bool("NginxOneConnectionEnabled", false),
144142
attribute.Int64("InferencePoolCount", 0),
145143
attribute.String("BuildOS", ""),
144+
attribute.Int64("GatewayAttachedProxySettingsPolicyCount", 0),
145+
attribute.Int64("RouteAttachedProxySettingsPolicyCount", 0),
146146
}
147147

148148
result := data.Attributes()

internal/controller/telemetry/ngfresourcecounts_attributes_generated.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ func (d *NGFResourceCounts) Attributes() []attribute.KeyValue {
2828
attrs = append(attrs, attribute.Int64("SnippetsFilterCount", d.SnippetsFilterCount))
2929
attrs = append(attrs, attribute.Int64("UpstreamSettingsPolicyCount", d.UpstreamSettingsPolicyCount))
3030
attrs = append(attrs, attribute.Int64("GatewayAttachedNpCount", d.GatewayAttachedNpCount))
31-
attrs = append(attrs, attribute.Int64("GatewayAttachedProxySettingsPolicyCount", d.GatewayAttachedProxySettingsPolicyCount))
32-
attrs = append(attrs, attribute.Int64("RouteAttachedProxySettingsPolicyCount", d.RouteAttachedProxySettingsPolicyCount))
3331

3432
return attrs
3533
}

tests/suite/telemetry_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,13 @@ var _ = Describe("Telemetry test with OTel collector", Label("telemetry"), func(
9393
"SnippetsFilterCount: Int(0)",
9494
"UpstreamSettingsPolicyCount: Int(0)",
9595
"GatewayAttachedNpCount: Int(0)",
96-
"GatewayAttachedProxySettingsPolicyCount: Int(0)",
97-
"RouteAttachedProxySettingsPolicyCount: Int(0)",
9896
"NginxPodCount: Int(0)",
9997
"ControlPlanePodCount: Int(1)",
10098
"NginxOneConnectionEnabled: Bool(false)",
10199
"InferencePoolCount: Int(0)",
102100
"BuildOS:",
101+
"GatewayAttachedProxySettingsPolicyCount: Int(0)",
102+
"RouteAttachedProxySettingsPolicyCount: Int(0)",
103103
},
104104
)
105105
})

0 commit comments

Comments
 (0)