10000 Add BUILD_OS to Telemetry (#5968) · nginx/kubernetes-ingress@4f4152c · GitHub
[go: up one dir, main page]

Skip to content

Commit 4f4152c

Browse files
authored
Add BUILD_OS to Telemetry (#5968)
1 parent 61bb53e commit 4f4152c

File tree

10 files changed

+84
-1
lines changed

10 files changed

+84
-1
lines changed

build/Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,8 @@ ARG IC_VERSION
546546
ARG TARGETPLATFORM
547547
ARG NAP_MODULES=none
548548

549+
ENV BUILD_OS=${BUILD_OS}
550+
549551
RUN --mount=type=bind,target=/tmp \
550552
--mount=type=bind,from=nginx-files,src=common.sh,target=/usr/local/bin/common.sh \
551553
--mount=type=bind,from=nginx-files,src=patch-os.sh,target=/usr/local/bin/patch-os.sh \

cmd/nginx-ingress/main.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ func main() {
6464
parseFlags()
6565
parsedFlags := os.Args[1:]
6666

67+
buildOS := os.Getenv("BUILD_OS")
68+
6769
config, kubeClient := createConfigAndKubeClient()
6870

6971
kubernetesVersionInfo(kubeClient)
@@ -230,6 +232,7 @@ func main() {
230232
WatchNamespaceLabel: *watchNamespaceLabel,
231233
EnableTelemetryReporting: *enableTelemetryReporting,
232234
TelemetryReportingEndpoint: telemetryEndpoint,
235+
BuildOS: buildOS,
233236
NICVersion: version,
234237
DynamicWeightChangesReload: *enableDynamicWeightChangesReload,
235238
InstallationFlags: parsedFlags,

docs/content/overview/product-telemetry.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ These are the data points collected and reported by NGINX Ingress Controller:
5757
- **AppProtectVersion** The AppProtect version
5858
- **IsPlus** Represents whether NGINX is Plus or OSS
5959
- **InstallationFlags** List of command line arguments configured for NGINX Ingress Controller
60+
- **BuildOS** The base operating system image in which NGINX Ingress Controller is running on.
6061

6162
---
6263

internal/k8s/controller.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ type NewLoadBalancerControllerInput struct {
216216
WatchNamespaceLabel string
217217
EnableTelemetryReporting bool
218218
TelemetryReportingEndpoint string
219+
BuildOS string
219220
NICVersion string
220221
DynamicWeightChangesReload bool
221222
InstallationFlags []string
@@ -371,6 +372,7 @@ func NewLoadBalancerController(input NewLoadBalancerControllerInput) *LoadBalanc
371372
K8sClientReader: input.KubeClient,
372373
Version: input.NICVersion,
373374
AppProtectVersion: input.AppProtectVersion,
375+
BuildOS: input.BuildOS,
374376
InstallationFlags: input.InstallationFlags,
375377
GlobalConfiguration: lbc.watchGlobalConfiguration,
376378
Configurator: lbc.configurator,

internal/telemetry/cluster.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,11 @@ func (c *Collector) ServiceCounts() (map[string]int, error) {
231231
return serviceCounts, nil
232232
}
233233

234+
// BuildOS returns a string which is the base operating system image tha NIC is running in.
235+
func (c *Collector) BuildOS() string {
236+
return c.Config.BuildOS
237+
}
238+
234239
// lookupPlatform takes a string representing a K8s PlatformID
235240
// retrieved from a cluster node and returns a string
236241
// representing the platform name.

internal/telemetry/collector.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ type CollectorConfig struct {
7575
// AppProtectVersion represents the version of App Protect.
7676
AppProtectVersion string
7777

78+
// BuildOS represents the base operating system image
79+
BuildOS string
80+
7881
// IsPlus represents whether NGINX is Plus or OSS
7982
IsPlus bool
8083

@@ -154,6 +157,7 @@ func (c *Collector) Collect(ctx context.Context) {
154157
AppProtectVersion: report.AppProtectVersion,
155158
IsPlus: report.IsPlus,
156159
InstallationFlags: report.InstallationFlags,
160+
BuildOS: report.BuildOS,
157161
},
158162
}
159163

@@ -203,6 +207,7 @@ type Report struct {
203207
AppProtectVersion string
204208
IsPlus bool
205209
InstallationFlags []string
210+
BuildOS string
206211
}
207212

208213
// BuildReport takes context, collects telemetry data and builds the report.
@@ -334,5 +339,6 @@ func (c *Collector) BuildReport(ctx context.Context) (Report, error) {
334339
AppProtectVersion: appProtectVersion,
335340
IsPlus: isPlus,
336341
InstallationFlags: installationFlags,
342+
BuildOS: c.BuildOS(),
337343
}, err
338344
}

internal/telemetry/collector_test.go

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,6 +1129,65 @@ func TestCollectInstallationFlags(t *testing.T) {
11291129
}
11301130
}
11311131

1132+
func TestCollectBuildOS(t *testing.T) {
1133+
t.Parallel()
1134+
1135+
testCases := []struct {
1136+
name string
1137+
buildOS string
1138+
wantOS string
1139+
}{
1140+
{
1141+
name: "debian plus image",
1142+
buildOS: "debian-plus",
1143+
wantOS: "debian-plus",
1144+
},
1145+
{
1146+
name: "ubi-9 plus app protect image",
1147+
buildOS: "ubi-9-plus-nap",
1148+
wantOS: "ubi-9-plus-nap",
1149+
},
1150+
{
1151+
name: "alpine oss image",
1152+
buildOS: "alpine",
1153+
wantOS: "alpine",
1154+
},
1155+
{
1156+
name: "self built image",
1157+
buildOS: "",
1158+
wantOS: "",
1159+
},
1160+
}
1161+
1162+
for _, tc := range testCases {
1163+
t.Run(tc.name, func(t *testing.T) {
1164+
buf := &bytes.Buffer{}
1165+
exp := &telemetry.StdoutExporter{Endpoint: buf}
1166+
1167+
configurator := newConfiguratorWithIngress(t)
1168+
1169+
cfg := telemetry.CollectorConfig{
1170+
Configurator: configurator,
1171+
K8sClientReader: newTestClientset(node1, kubeNS),
1172+
Version: telemetryNICData.ProjectVersion,
1173+
BuildOS: tc.buildOS,
1174+
}
1175+
1176+
c, err := telemetry.NewCollector(cfg, telemetry.WithExporter(exp))
1177+
if err != nil {
1178+
t.Fatal(err)
1179+
}
1180+
c.Collect(context.Background())
1181+
1182+
buildOS := c.BuildOS()
1183+
1184+
if tc.wantOS != buildOS {
1185+
t.Errorf("want: %s, got: %s", tc.wantOS, buildOS)
1186+
}
1187+
})
1188+
}
1189+
}
1190+
11321191
func TestCountVirtualServersOnCustomResourceEnabled(t *testing.T) {
11331192
t.Parallel()
11341193

internal/telemetry/data.avdl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
@namespace("ingress.nginx.com") protocol NICProductTelemetry {
2-
/** Data is the product telemetry data of NGINX Ingress Controller. */
32
@df_datatype("nic-product-telemetry") record Data {
43
/** The field that identifies what type of data this is. */
54
string dataType;
@@ -115,5 +114,8 @@ It is the UID of the `kube-system` Namespace. */
115114
/** InstallationFlags is the list of command line arguments configured for NGINX Ingress Controller */
116115
union {null, array<string>} InstallationFlags = null;
117116

117+
/** BuildOS returns the base buildOS image */
118+
string? BuildOS = null;
119+
118120
}
119121
}

internal/telemetry/exporter.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,4 +119,6 @@ type NICResourceCounts struct {
119119
IsPlus bool
120120
// InstallationFlags is the list of command line arguments configured for NGINX Ingress Controller
121121
InstallationFlags []string
122+
// BuildOS represents the base operating system image
123+
BuildOS string
122124
}

internal/telemetry/nicresourcecounts_attributes_generated.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ func (d *NICResourceCounts) Attributes() []attribute.KeyValue {
4040
attrs = append(attrs, attribute.String("AppProtectVersion", d.AppProtectVersion))
4141
attrs = append(attrs, attribute.Bool("IsPlus", d.IsPlus))
4242
attrs = append(attrs, attribute.StringSlice("InstallationFlags", d.InstallationFlags))
43+
attrs = append(attrs, attribute.String("BuildOS", d.BuildOS))
4344

4445
return attrs
4546
}

0 commit comments

Comments
 (0)
0