Skip to content

Commit 6a11016

Browse files
authored
Add image source to telemetry data (#1600)
* Add image source * Move env var to join the others
1 parent 92081af commit 6a11016

File tree

7 files changed

+19
-2
lines changed

7 files changed

+19
-2
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ build-images-with-plus: build-ngf-image build-nginx-plus-image ## Build the NGF
4545

4646
.PHONY: build-ngf-image
4747
build-ngf-image: check-for-docker build ## Build the NGF docker image
48-
docker build --platform linux/$(GOARCH) --target $(strip $(TARGET)) -f build/Dockerfile -t $(strip $(PREFIX)):$(strip $(TAG)) .
48+
docker build --platform linux/$(GOARCH) --build-arg BUILD_AGENT=$(BUILD_AGENT) --target $(strip $(TARGET)) -f build/Dockerfile -t $(strip $(PREFIX)):$(strip $(TAG)) .
4949

5050
.PHONY: build-nginx-image
5151
build-nginx-image: check-for-docker ## Build the custom nginx image

build/Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ RUN setcap 'cap_kill=+ep' /usr/bin/gateway
2727

2828
FROM scratch as common
2929
USER 102:1001
30+
ARG BUILD_AGENT
31+
ENV BUILD_AGENT=${BUILD_AGENT}
3032
ENTRYPOINT [ "/usr/bin/gateway" ]
3133

3234
FROM common as container

cmd/gateway/commands.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,11 @@ func createStaticModeCommand() *cobra.Command {
146146
return errors.New("POD_NAME environment variable must be set")
147147
}
148148

149+
imageSource := os.Getenv("BUILD_AGENT")
150+
if imageSource != "gha" && imageSource != "local" {
151+
imageSource = "unknown"
152+
}
153+
149154
period, err := time.ParseDuration(telemetryReportPeriod)
150155
if err != nil {
151156
return fmt.Errorf("error parsing telemetry report period: %w", err)
@@ -203,6 +208,7 @@ func createStaticModeCommand() *cobra.Command {
203208
TelemetryReportPeriod: period,
204209
Version: version,
205210
ExperimentalFeatures: gwExperimentalFeatures,
211+
ImageSource: imageSource,
206212
}
207213

208214
if err := static.StartManager(conf); err != nil {

internal/mode/static/config/config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import (
1111
type Config struct {
1212
// Version is the running NGF version.
1313
Version string
14+
// ImageSource is the source of the NGINX Gateway image.
15+
ImageSource string
1416
// AtomicLevel is an atomically changeable, dynamic logging level.
1517
AtomicLevel zap.AtomicLevel
1618
// GatewayNsName is the namespaced name of a Gateway resource that the Gateway will use.

internal/mode/static/manager.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ func StartManager(cfg config.Config) error {
251251
Namespace: cfg.GatewayPodConfig.Namespace,
252252
Name: cfg.GatewayPodConfig.Name,
253253
},
254+
ImageSource: cfg.ImageSource,
254255
})
255256
if err = mgr.Add(createTelemetryJob(cfg, dataCollector, nginxChecker.getReadyCh())); err != nil {
256257
return fmt.Errorf("cannot register telemetry job: %w", err)

internal/mode/static/telemetry/collector.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,9 @@ type ProjectMetadata struct {
5151
type Data struct {
5252
ProjectMetadata ProjectMetadata
5353
ClusterID string
54-
NodeCount int
54+
ImageSource string
5555
NGFResourceCounts NGFResourceCounts
56+
NodeCount int
5657
NGFReplicaCount int
5758
}
5859

@@ -68,6 +69,8 @@ type DataCollectorConfig struct {
6869
Version string
6970
// PodNSName is the NamespacedName of the NGF Pod.
7071
PodNSName types.NamespacedName
72+
// ImageSource is the source of the NGF image.
73+
ImageSource string
7174
}
7275

7376
// DataCollectorImpl is am implementation of DataCollector.
@@ -115,6 +118,7 @@ func (c DataCollectorImpl) Collect(ctx context.Context) (Data, error) {
115118
},
116119
NGFReplicaCount: ngfReplicaCount,
117120
ClusterID: clusterID,
121+
ImageSource: c.cfg.ImageSource,
118122
}
119123

120124
return data, nil

internal/mode/static/telemetry/collector_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ var _ = Describe("Collector", Ordered, func() {
123123
NGFResourceCounts: telemetry.NGFResourceCounts{},
124124
NGFReplicaCount: 1,
125125
ClusterID: string(kubeNamespace.GetUID()),
126+
ImageSource: "local",
126127
}
127128

128129
k8sClientReader = &eventsfakes.FakeReader{}
@@ -138,6 +139,7 @@ var _ = Describe("Collector", Ordered, func() {
138139
ConfigurationGetter: fakeConfigurationGetter,
139140
Version: version,
140141
PodNSName: podNSName,
142+
ImageSource: "local",
141143
})
142144

143145
baseGetCalls = createGetCallsFunc(ngfPod, ngfReplicaSet, kubeNamespace)

0 commit comments

Comments
 (0)