Skip to content

Commit 4103612

Browse files
committed
Add BuilOS to telemetry
1 parent cb31ea4 commit 4103612

File tree

7 files changed

+81
-0
lines changed

7 files changed

+81
-0
lines changed

cmd/gateway/commands.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,11 @@ func createControllerCommand() *cobra.Command {
209209
imageSource = "unknown"
210210
}
211211

212+
buildOs := os.Getenv("BUILD_OS")
213+
if buildOs == "" {
214+
buildOs = "alpine"
215+
}
216+
212217
period, err := time.ParseDuration(telemetryReportPeriod)
213218
if err != nil {
214219
return fmt.Errorf("error parsing telemetry report period: %w", err)
@@ -271,6 +276,7 @@ func createControllerCommand() *cobra.Command {
271276
Plus: plus,
272277
ExperimentalFeatures: gwExperimentalFeatures,
273278
ImageSource: imageSource,
279+
BuildOS: buildOs,
274280
Flags: config.Flags{
275281
Names: flagKeys,
276282
Values: flagValues,

internal/controller/config/config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ type Config struct {
2626
GatewayClassName string
2727
// ImageSource is the source of the NGINX Gateway image.
2828
ImageSource string
29+
// BuildOS is the OS the NGF and NGINX binary was built on.
30+
BuildOS string
2931
// GatewayCtlrName is the name of this controller.
3032
GatewayCtlrName string
3133
// UsageReportConfig specifies the NGINX Plus usage reporting configuration.

internal/controller/manager.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ func StartManager(cfg config.Config) error {
290290
Name: cfg.GatewayPodConfig.Name,
291291
},
292292
ImageSource: cfg.ImageSource,
293+
BuildOS: cfg.BuildOS,
293294
Flags: cfg.Flags,
294295
NginxOneConsoleConnection: cfg.NginxOneConsoleTelemetryConfig.DataplaneKeySecretName != "",
295296
})

internal/controller/telemetry/collector.go

Lines changed: 10 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+
// BuildOS is the OS the NGF and NGINX binary was built on.
70+
BuildOS string
6971
}
7072

7173
// NGFResourceCounts stores the counts of all relevant resources that NGF processes and generates configuration from.
@@ -121,6 +123,8 @@ type DataCollectorConfig struct {
121123
Version string
122124
// ImageSource is the source of the NGF image.
123125
ImageSource string
126+
// BuildOS is the OS the NGF and NGINX binary was built on.
127+
BuildOS string
124128
// Flags contains the command-line NGF flag keys and values.
125129
Flags config.Flags
126130
// NginxOneConsoleConnection is a boolean that indicates whether the connection to the Nginx One Console is enabled.
@@ -174,6 +178,11 @@ func (c DataCollectorImpl) Collect(ctx context.Context) (Data, error) {
174178

175179
nginxPodCount := getNginxPodCount(g, clusterInfo.NodeCount)
176180

181+
buildOS := c.cfg.BuildOS
182+
if buildOS == "" {
183+
buildOS = "alpine"
184+
}
185+
177186
data := Data{
178187
Data: tel.Data{
179188
ProjectName: "NGF",
@@ -187,6 +196,7 @@ func (c DataCollectorImpl) Collect(ctx context.Context) (Data, error) {
187196
},
188197
NGFResourceCounts: graphResourceCount,
189198
ImageSource: c.cfg.ImageSource,
199+
BuildOS: buildOS,
190200
FlagNames: c.cfg.Flags.Names,
191201
FlagValues: c.cfg.Flags.Values,
192202
SnippetsFiltersDirectives: snippetsFiltersDirectives,

internal/controller/telemetry/collector_test.go

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,64 @@ func createGetCallsFunc(objects ...client.Object) getCallsFunc {
7272
}
7373

7474
var _ = Describe("Collector", Ordered, func() {
75+
76+
Describe("BuildOS field", func() {
77+
var (
78+
k8sClientReader *kubernetesfakes.FakeReader
79+
fakeGraphGetter *telemetryfakes.FakeGraphGetter
80+
fakeConfigurationGetter *telemetryfakes.FakeConfigurationGetter
81+
version string
82+
podNSName types.NamespacedName
83+
flags config.Flags
84+
)
85+
86+
BeforeEach(func() {
87+
version = "1.1"
88+
k8sClientReader = &kubernetesfakes.FakeReader{}
89+
fakeGraphGetter = &telemetryfakes.FakeGraphGetter{}
90+
fakeConfigurationGetter = &telemetryfakes.FakeConfigurationGetter{}
91+
podNSName = types.NamespacedName{Namespace: "nginx-gateway", Name: "ngf-pod"}
92+
flags = config.Flags{}
93+
fakeGraphGetter.GetLatestGraphReturns(&graph.Graph{})
94+
fakeConfigurationGetter.GetLatestConfigurationReturns(nil)
95+
})
96+
97+
It("sets BuildOS to 'alpine' when config.BuildOS is empty", func(ctx SpecContext) {
98+
dataCollector := telemetry.NewDataCollectorImpl(telemetry.DataCollectorConfig{
99+
K8sClientReader: k8sClientReader,
100+
GraphGetter: fakeGraphGetter,
101+
ConfigurationGetter: fakeConfigurationGetter,
102+
Version: version,
103+
PodNSName: podNSName,
104+
ImageSource: "local",
105+
Flags: flags,
106+
NginxOneConsoleConnection: true,
107+
BuildOS: "",
108+
})
109+
110+
data, err := dataCollector.Collect(ctx)
111+
Expect(err).ToNot(HaveOccurred())
112+
Expect(data.BuildOS).To(Equal("alpine"))
113+
})
114+
115+
It("sets BuildOS to 'ubi' when config.BuildOS is 'ubi'", func(ctx SpecContext) {
116+
dataCollector := telemetry.NewDataCollectorImpl(telemetry.DataCollectorConfig{
117+
K8sClientReader: k8sClientReader,
118+
GraphGetter: fakeGraphGetter,
119+
ConfigurationGetter: fakeConfigurationGetter,
120+
Version: version,
121+
PodNSName: podNSName,
122+
ImageSource: "local",
123+
Flags: flags,
124+
NginxOneConsoleConnection: true,
125+
BuildOS: "ubi",
126+
})
127+
128+
data, err := dataCollector.Collect(ctx)
129+
Expect(err).ToNot(HaveOccurred())
130+
Expect(data.BuildOS).To(Equal("ubi"))
131+
})
132+
})
75133
var (
76134
k8sClientReader *kubernetesfakes.FakeReader
77135
fakeGraphGetter *telemetryfakes.FakeGraphGetter
@@ -195,6 +253,7 @@ var _ = Describe("Collector", Ordered, func() {
195253
ImageSource: "local",
196254
Flags: flags,
197255
NginxOneConsoleConnection: true,
256+
BuildOS: "",
198257
})
199258

200259
baseGetCalls = createGetCallsFunc(ngfPod, ngfReplicaSet, kubeNamespace)

internal/controller/telemetry/data.avdl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,5 +114,7 @@ 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+
/** BuildOS is a string that indicates the base operating statem that both NGF and NGINX were built on. */
118+
string? BuildOS = null;
117119
}
118120
}

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+
"BuildOS:",
99100
},
100101
)
101102
})

0 commit comments

Comments
 (0)