Skip to content

Commit

Permalink
Add image source to telemetry data (#1600)
Browse files Browse the repository at this point in the history
* Add image source

* Move env var to join the others
  • Loading branch information
ciarams87 authored Feb 21, 2024
1 parent 92081af commit 6a11016
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions build/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions cmd/gateway/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -203,6 +208,7 @@ func createStaticModeCommand() *cobra.Command {
TelemetryReportPeriod: period,
Version: version,
ExperimentalFeatures: gwExperimentalFeatures,
ImageSource: imageSource,
}

if err := static.StartManager(conf); err != nil {
Expand Down
2 changes: 2 additions & 0 deletions internal/mode/static/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions internal/mode/static/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 5 additions & 1 deletion internal/mode/static/telemetry/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ type ProjectMetadata struct {
type Data struct {
ProjectMetadata ProjectMetadata
ClusterID string
NodeCount int
ImageSource string
NGFResourceCounts NGFResourceCounts
NodeCount int
NGFReplicaCount int
}

Expand All @@ -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.
Expand Down Expand Up @@ -115,6 +118,7 @@ func (c DataCollectorImpl) Collect(ctx context.Context) (Data, error) {
},
NGFReplicaCount: ngfReplicaCount,
ClusterID: clusterID,
ImageSource: c.cfg.ImageSource,
}

return data, nil
Expand Down
2 changes: 2 additions & 0 deletions internal/mode/static/telemetry/collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ var _ = Describe("Collector", Ordered, func() {
NGFResourceCounts: telemetry.NGFResourceCounts{},
NGFReplicaCount: 1,
ClusterID: string(kubeNamespace.GetUID()),
ImageSource: "local",
}

k8sClientReader = &eventsfakes.FakeReader{}
Expand All @@ -138,6 +139,7 @@ var _ = Describe("Collector", Ordered, func() {
ConfigurationGetter: fakeConfigurationGetter,
Version: version,
PodNSName: podNSName,
ImageSource: "local",
})

baseGetCalls = createGetCallsFunc(ngfPod, ngfReplicaSet, kubeNamespace)
Expand Down

0 comments on commit 6a11016

Please sign in to comment.