Skip to content

Add image source to telemetry data #1600

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 21, 2024
Merged
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
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