diff --git a/Makefile b/Makefile index cac2bf24e0..87303395e1 100644 --- a/Makefile +++ b/Makefile @@ -45,7 +45,7 @@ build-images-with-plus: build-ngf-image build-nginx-plus-image ## Build the NGF .PHONY: build-ngf-image build-ngf-image: check-for-docker build ## Build the NGF docker image - docker build --platform linux/$(GOARCH) --target $(strip $(TARGET)) -f build/Dockerfile -t $(strip $(PREFIX)):$(strip $(TAG)) . + docker build --platform linux/$(GOARCH) --build-arg BUILD_AGENT=$(BUILD_AGENT) --target $(strip $(TARGET)) -f build/Dockerfile -t $(strip $(PREFIX)):$(strip $(TAG)) . .PHONY: build-nginx-image build-nginx-image: check-for-docker ## Build the custom nginx image diff --git a/build/Dockerfile b/build/Dockerfile index 24026ba3b0..4411500348 100644 --- a/build/Dockerfile +++ b/build/Dockerfile @@ -27,6 +27,8 @@ RUN setcap 'cap_kill=+ep' /usr/bin/gateway FROM scratch as common USER 102:1001 +ARG BUILD_AGENT +ENV BUILD_AGENT=${BUILD_AGENT} ENTRYPOINT [ "/usr/bin/gateway" ] FROM common as container diff --git a/cmd/gateway/commands.go b/cmd/gateway/commands.go index 3cd42ca3a1..e721e697a7 100644 --- a/cmd/gateway/commands.go +++ b/cmd/gateway/commands.go @@ -146,6 +146,11 @@ func createStaticModeCommand() *cobra.Command { return errors.New("POD_NAME environment variable must be set") } + imageSource := os.Getenv("BUILD_AGENT") + if imageSource != "gha" && imageSource != "local" { + imageSource = "unknown" + } + period, err := time.ParseDuration(telemetryReportPeriod) if err != nil { return fmt.Errorf("error parsing telemetry report period: %w", err) @@ -203,6 +208,7 @@ func createStaticModeCommand() *cobra.Command { TelemetryReportPeriod: period, Version: version, ExperimentalFeatures: gwExperimentalFeatures, + ImageSource: imageSource, } if err := static.StartManager(conf); err != nil { diff --git a/internal/mode/static/config/config.go b/internal/mode/static/config/config.go index 5ab8c811b4..3a21055fdf 100644 --- a/internal/mode/static/config/config.go +++ b/internal/mode/static/config/config.go @@ -11,6 +11,8 @@ import ( type Config struct { // Version is the running NGF version. Version string + // ImageSource is the source of the NGINX Gateway image. + ImageSource string // AtomicLevel is an atomically changeable, dynamic logging level. AtomicLevel zap.AtomicLevel // GatewayNsName is the namespaced name of a Gateway resource that the Gateway will use. diff --git a/internal/mode/static/manager.go b/internal/mode/static/manager.go index 99f97b8ebf..2652b72d73 100644 --- a/internal/mode/static/manager.go +++ b/internal/mode/static/manager.go @@ -251,6 +251,7 @@ func StartManager(cfg config.Config) error { Namespace: cfg.GatewayPodConfig.Namespace, Name: cfg.GatewayPodConfig.Name, }, + ImageSource: cfg.ImageSource, }) if err = mgr.Add(createTelemetryJob(cfg, dataCollector, nginxChecker.getReadyCh())); err != nil { return fmt.Errorf("cannot register telemetry job: %w", err) diff --git a/internal/mode/static/telemetry/collector.go b/internal/mode/static/telemetry/collector.go index e7dc692a7b..8bc4fdeb2c 100644 --- a/internal/mode/static/telemetry/collector.go +++ b/internal/mode/static/telemetry/collector.go @@ -51,8 +51,9 @@ type ProjectMetadata struct { type Data struct { ProjectMetadata ProjectMetadata ClusterID string - NodeCount int + ImageSource string NGFResourceCounts NGFResourceCounts + NodeCount int NGFReplicaCount int } @@ -68,6 +69,8 @@ type DataCollectorConfig struct { Version string // PodNSName is the NamespacedName of the NGF Pod. PodNSName types.NamespacedName + // ImageSource is the source of the NGF image. + ImageSource string } // DataCollectorImpl is am implementation of DataCollector. @@ -115,6 +118,7 @@ func (c DataCollectorImpl) Collect(ctx context.Context) (Data, error) { }, NGFReplicaCount: ngfReplicaCount, ClusterID: clusterID, + ImageSource: c.cfg.ImageSource, } return data, nil diff --git a/internal/mode/static/telemetry/collector_test.go b/internal/mode/static/telemetry/collector_test.go index 8b9827c90a..3fe8287b02 100644 --- a/internal/mode/static/telemetry/collector_test.go +++ b/internal/mode/static/telemetry/collector_test.go @@ -123,6 +123,7 @@ var _ = Describe("Collector", Ordered, func() { NGFResourceCounts: telemetry.NGFResourceCounts{}, NGFReplicaCount: 1, ClusterID: string(kubeNamespace.GetUID()), + ImageSource: "local", } k8sClientReader = &eventsfakes.FakeReader{} @@ -138,6 +139,7 @@ var _ = Describe("Collector", Ordered, func() { ConfigurationGetter: fakeConfigurationGetter, Version: version, PodNSName: podNSName, + ImageSource: "local", }) baseGetCalls = createGetCallsFunc(ngfPod, ngfReplicaSet, kubeNamespace)