Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions cmd/gateway/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,11 @@ func createControllerCommand() *cobra.Command {
imageSource = "unknown"
}

buildOs := os.Getenv("BUILD_OS")
if buildOs == "" {
buildOs = "alpine"
}

period, err := time.ParseDuration(telemetryReportPeriod)
if err != nil {
return fmt.Errorf("error parsing telemetry report period: %w", err)
Expand Down Expand Up @@ -271,6 +276,7 @@ func createControllerCommand() *cobra.Command {
Plus: plus,
ExperimentalFeatures: gwExperimentalFeatures,
ImageSource: imageSource,
BuildOS: buildOs,
Flags: config.Flags{
Names: flagKeys,
Values: flagValues,
Expand Down
2 changes: 2 additions & 0 deletions internal/controller/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ type Config struct {
GatewayClassName string
// ImageSource is the source of the NGINX Gateway image.
ImageSource string
// BuildOS is the OS the NGF and NGINX binary was built on.
BuildOS string
// GatewayCtlrName is the name of this controller.
GatewayCtlrName string
// UsageReportConfig specifies the NGINX Plus usage reporting configuration.
Expand Down
1 change: 1 addition & 0 deletions internal/controller/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ func StartManager(cfg config.Config) error {
Name: cfg.GatewayPodConfig.Name,
},
ImageSource: cfg.ImageSource,
BuildOS: cfg.BuildOS,
Flags: cfg.Flags,
NginxOneConsoleConnection: cfg.NginxOneConsoleTelemetryConfig.DataplaneKeySecretName != "",
})
Expand Down
10 changes: 10 additions & 0 deletions internal/controller/telemetry/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
// Data is telemetry data.
//
//go:generate go run -tags generator github.com/nginx/telemetry-exporter/cmd/generator -type=Data -scheme -scheme-protocol=NGFProductTelemetry -scheme-df-datatype=ngf-product-telemetry
type Data struct {

Check failure on line 43 in internal/controller/telemetry/collector.go

View workflow job for this annotation

GitHub Actions / Go Lint (.)

fieldalignment: struct with 392 pointer bytes could be 232 (govet)
// ImageSource tells whether the image was built by GitHub or locally (values are 'gha', 'local', or 'unknown')
ImageSource string
tel.Data // embedding is required by the generator.
Expand All @@ -66,6 +66,8 @@
ControlPlanePodCount int64
// NginxOneConnectionEnabled is a boolean that indicates whether the connection to the Nginx One Console is enabled.
NginxOneConnectionEnabled bool
// BuildOS is the OS the NGF and NGINX binary was built on.
BuildOS string
}

// NGFResourceCounts stores the counts of all relevant resources that NGF processes and generates configuration from.
Expand Down Expand Up @@ -121,6 +123,8 @@
Version string
// ImageSource is the source of the NGF image.
ImageSource string
// BuildOS is the OS the NGF and NGINX binary was built on.
BuildOS string
// Flags contains the command-line NGF flag keys and values.
Flags config.Flags
// NginxOneConsoleConnection is a boolean that indicates whether the connection to the Nginx One Console is enabled.
Expand Down Expand Up @@ -174,6 +178,11 @@

nginxPodCount := getNginxPodCount(g, clusterInfo.NodeCount)

buildOS := c.cfg.BuildOS
if buildOS == "" {
buildOS = "alpine"
}
Comment on lines +182 to +184
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need this since we have the check in commands.go. So like how we don't add an additional check for ImageSource I think we can follow suite.


data := Data{
Data: tel.Data{
ProjectName: "NGF",
Expand All @@ -187,6 +196,7 @@
},
NGFResourceCounts: graphResourceCount,
ImageSource: c.cfg.ImageSource,
BuildOS: buildOS,
FlagNames: c.cfg.Flags.Names,
FlagValues: c.cfg.Flags.Values,
SnippetsFiltersDirectives: snippetsFiltersDirectives,
Expand Down
59 changes: 59 additions & 0 deletions internal/controller/telemetry/collector_test.go
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll need to add the field to the "Normal Case"

Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,64 @@
}

var _ = Describe("Collector", Ordered, func() {

Check failure on line 75 in internal/controller/telemetry/collector_test.go

View workflow job for this annotation

GitHub Actions / Go Lint (.)

File is not properly formatted (gofumpt)
Describe("BuildOS field", func() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really think a new Describe block is needed once you add the field in the normal case. Similar to how we don't have a separate Describe block for ImageSource, but if you insist on keeping it, we should move to down towards the other Describe blocks (probably end of file). Currently this is in a weird place.

var (
k8sClientReader *kubernetesfakes.FakeReader
fakeGraphGetter *telemetryfakes.FakeGraphGetter
fakeConfigurationGetter *telemetryfakes.FakeConfigurationGetter
version string
podNSName types.NamespacedName
flags config.Flags
)

BeforeEach(func() {
version = "1.1"
k8sClientReader = &kubernetesfakes.FakeReader{}
fakeGraphGetter = &telemetryfakes.FakeGraphGetter{}
fakeConfigurationGetter = &telemetryfakes.FakeConfigurationGetter{}
podNSName = types.NamespacedName{Namespace: "nginx-gateway", Name: "ngf-pod"}
flags = config.Flags{}
fakeGraphGetter.GetLatestGraphReturns(&graph.Graph{})
fakeConfigurationGetter.GetLatestConfigurationReturns(nil)
})

It("sets BuildOS to 'alpine' when config.BuildOS is empty", func(ctx SpecContext) {
dataCollector := telemetry.NewDataCollectorImpl(telemetry.DataCollectorConfig{
K8sClientReader: k8sClientReader,
GraphGetter: fakeGraphGetter,
ConfigurationGetter: fakeConfigurationGetter,
Version: version,
PodNSName: podNSName,
ImageSource: "local",
Flags: flags,
NginxOneConsoleConnection: true,
BuildOS: "",
})

data, err := dataCollector.Collect(ctx)
Expect(err).ToNot(HaveOccurred())
Expect(data.BuildOS).To(Equal("alpine"))
})

It("sets BuildOS to 'ubi' when config.BuildOS is 'ubi'", func(ctx SpecContext) {
dataCollector := telemetry.NewDataCollectorImpl(telemetry.DataCollectorConfig{
K8sClientReader: k8sClientReader,
GraphGetter: fakeGraphGetter,
ConfigurationGetter: fakeConfigurationGetter,
Version: version,
PodNSName: podNSName,
ImageSource: "local",
Flags: flags,
NginxOneConsoleConnection: true,
BuildOS: "ubi",
})

data, err := dataCollector.Collect(ctx)
Expect(err).ToNot(HaveOccurred())
Expect(data.BuildOS).To(Equal("ubi"))
})
})
var (
k8sClientReader *kubernetesfakes.FakeReader
fakeGraphGetter *telemetryfakes.FakeGraphGetter
Expand Down Expand Up @@ -195,6 +253,7 @@
ImageSource: "local",
Flags: flags,
NginxOneConsoleConnection: true,
BuildOS: "",
})

baseGetCalls = createGetCallsFunc(ngfPod, ngfReplicaSet, kubeNamespace)
Expand Down
3 changes: 3 additions & 0 deletions internal/controller/telemetry/data.avdl
Original file line number Diff line number Diff line change
Expand Up @@ -114,5 +114,8 @@ attached at the Gateway level. */
/** NginxOneConnectionEnabled is a boolean that indicates whether the connection to the Nginx One Console is enabled. */
boolean? NginxOneConnectionEnabled = null;

/** BuildOS is the OS the NGF and NGINX binary was built on. */
string? BuildOS = null;

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func (d *Data) Attributes() []attribute.KeyValue {
attrs = append(attrs, attribute.Int64("NginxPodCount", d.NginxPodCount))
attrs = append(attrs, attribute.Int64("ControlPlanePodCount", d.ControlPlanePodCount))
attrs = append(attrs, attribute.Bool("NginxOneConnectionEnabled", d.NginxOneConnectionEnabled))
attrs = append(attrs, attribute.String("BuildOS", d.BuildOS))

return attrs
}
Expand Down
1 change: 1 addition & 0 deletions tests/suite/telemetry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ var _ = Describe("Telemetry test with OTel collector", Label("telemetry"), func(
"NginxPodCount: Int(0)",
"ControlPlanePodCount: Int(1)",
"NginxOneConnectionEnabled: Bool(false)",
"BuildOS:",
},
)
})
Expand Down
Loading