diff --git a/internal/controller/telemetry/collector.go b/internal/controller/telemetry/collector.go index e06da3f0b8..0c33c8c2f6 100644 --- a/internal/controller/telemetry/collector.go +++ b/internal/controller/telemetry/collector.go @@ -4,6 +4,7 @@ import ( "context" "errors" "fmt" + "os" "runtime" "sort" "strings" @@ -40,7 +41,7 @@ type ConfigurationGetter interface { // 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 { +type Data struct { //nolint //required to skip golangci-lint-full fieldalignment // 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. @@ -66,6 +67,8 @@ type Data struct { ControlPlanePodCount int64 // NginxOneConnectionEnabled is a boolean that indicates whether the connection to the Nginx One Console is enabled. NginxOneConnectionEnabled bool + // BuildOS is the base operating system the control plane was built on (e.g. alpine, ubi). + BuildOS string } // NGFResourceCounts stores the counts of all relevant resources that NGF processes and generates configuration from. @@ -121,6 +124,8 @@ type DataCollectorConfig struct { Version string // ImageSource is the source of the NGF image. ImageSource string + // BuildOS is the base operating system the control plane was built on (e.g. alpine, ubi). + 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. @@ -174,6 +179,11 @@ func (c DataCollectorImpl) Collect(ctx context.Context) (Data, error) { nginxPodCount := getNginxPodCount(g, clusterInfo.NodeCount) + buildOs := os.Getenv("BUILD_OS") + if buildOs == "" { + buildOs = "alpine" + } + data := Data{ Data: tel.Data{ ProjectName: "NGF", @@ -187,6 +197,7 @@ func (c DataCollectorImpl) Collect(ctx context.Context) (Data, error) { }, NGFResourceCounts: graphResourceCount, ImageSource: c.cfg.ImageSource, + BuildOS: buildOs, FlagNames: c.cfg.Flags.Names, FlagValues: c.cfg.Flags.Values, SnippetsFiltersDirectives: snippetsFiltersDirectives, diff --git a/internal/controller/telemetry/collector_test.go b/internal/controller/telemetry/collector_test.go index 8c749fdfbe..b73f236863 100644 --- a/internal/controller/telemetry/collector_test.go +++ b/internal/controller/telemetry/collector_test.go @@ -172,6 +172,7 @@ var _ = Describe("Collector", Ordered, func() { NGFResourceCounts: telemetry.NGFResourceCounts{}, ControlPlanePodCount: 1, ImageSource: "local", + BuildOS: "alpine", FlagNames: flags.Names, FlagValues: flags.Values, SnippetsFiltersDirectives: []string{}, @@ -193,6 +194,7 @@ var _ = Describe("Collector", Ordered, func() { Version: version, PodNSName: podNSName, ImageSource: "local", + BuildOS: "alpine", Flags: flags, NginxOneConsoleConnection: true, }) @@ -519,6 +521,7 @@ var _ = Describe("Collector", Ordered, func() { expData.NginxPodCount = int64(8) expData.ControlPlanePodCount = int64(2) expData.NginxOneConnectionEnabled = true + expData.BuildOS = "alpine" data, err := dataCollector.Collect(ctx) Expect(err).ToNot(HaveOccurred()) diff --git a/internal/controller/telemetry/data.avdl b/internal/controller/telemetry/data.avdl index c19881315a..a131d91bc4 100644 --- a/internal/controller/telemetry/data.avdl +++ b/internal/controller/telemetry/data.avdl @@ -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 base operating system the control plane was built on (e.g. alpine, ubi). */ + string? BuildOS = null; + } } diff --git a/internal/controller/telemetry/data_attributes_generated.go b/internal/controller/telemetry/data_attributes_generated.go index 3b8b3dcf3f..3423c902c9 100644 --- a/internal/controller/telemetry/data_attributes_generated.go +++ b/internal/controller/telemetry/data_attributes_generated.go @@ -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 } diff --git a/internal/controller/telemetry/data_test.go b/internal/controller/telemetry/data_test.go index 49c8e3543c..03b36f9a2b 100644 --- a/internal/controller/telemetry/data_test.go +++ b/internal/controller/telemetry/data_test.go @@ -86,6 +86,7 @@ func TestDataAttributes(t *testing.T) { attribute.Int64("NginxPodCount", 3), attribute.Int64("ControlPlanePodCount", 3), attribute.Bool("NginxOneConnectionEnabled", true), + attribute.String("BuildOS", ""), } result := data.Attributes() @@ -132,6 +133,7 @@ func TestDataAttributesWithEmptyData(t *testing.T) { attribute.Int64("NginxPodCount", 0), attribute.Int64("ControlPlanePodCount", 0), attribute.Bool("NginxOneConnectionEnabled", false), + attribute.String("BuildOS", ""), } result := data.Attributes() diff --git a/tests/suite/telemetry_test.go b/tests/suite/telemetry_test.go index 2ad0c0b3a0..bc57c1ca1e 100644 --- a/tests/suite/telemetry_test.go +++ b/tests/suite/telemetry_test.go @@ -96,6 +96,7 @@ var _ = Describe("Telemetry test with OTel collector", Label("telemetry"), func( "NginxPodCount: Int(0)", "ControlPlanePodCount: Int(1)", "NginxOneConnectionEnabled: Bool(false)", + "BuildOS:", }, ) })