Skip to content

Commit de28e5f

Browse files
authored
OpenShift Support: Product Telemetry (#4038)
1 parent 3dd0bed commit de28e5f

File tree

8 files changed

+23
-1
lines changed

8 files changed

+23
-1
lines changed

build/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ COPY --from=ca-certs-provider --link /etc/ssl/certs/ca-certificates.crt /etc/ssl
1717
USER 101:1001
1818
ARG BUILD_AGENT
1919
ENV BUILD_AGENT=${BUILD_AGENT}
20+
ENV BUILD_OS=alpine
2021
ENTRYPOINT [ "/usr/bin/gateway" ]
2122

2223
FROM common AS container

build/ubi/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ COPY --from=ca-certs-provider --link /etc/ssl/certs/ca-certificates.crt /etc/ssl
1717
USER 101:1001
1818
ARG BUILD_AGENT
1919
ENV BUILD_AGENT=${BUILD_AGENT}
20+
ENV BUILD_OS=ubi
2021

2122
LABEL name="F5 NGINX Gateway Fabric NGINX Plus" \
2223
maintainer="[email protected]" \

internal/controller/telemetry/collector.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"errors"
66
"fmt"
7+
"os"
78
"runtime"
89
"sort"
910
"strings"
@@ -40,7 +41,7 @@ type ConfigurationGetter interface {
4041
// Data is telemetry data.
4142
//
4243
//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
43-
type Data struct {
44+
type Data struct { //nolint //required to skip golangci-lint-full fieldalignment
4445
// ImageSource tells whether the image was built by GitHub or locally (values are 'gha', 'local', or 'unknown')
4546
ImageSource string
4647
tel.Data // embedding is required by the generator.
@@ -68,6 +69,8 @@ type Data struct {
6869
NginxOneConnectionEnabled bool
6970
// InferencePoolCount is the number of InferencePools that are referenced by at least one Route.
7071
InferencePoolCount int64
72+
// BuildOS is the base operating system the control plane was built on (e.g. alpine, ubi).
73+
BuildOS string
7174
}
7275

7376
// NGFResourceCounts stores the counts of all relevant resources that NGF processes and generates configuration from.
@@ -123,6 +126,8 @@ type DataCollectorConfig struct {
123126
Version string
124127
// ImageSource is the source of the NGF image.
125128
ImageSource string
129+
// BuildOS is the base operating system the control plane was built on (e.g. alpine, ubi).
130+
BuildOS string
126131
// Flags contains the command-line NGF flag keys and values.
127132
Flags config.Flags
128133
// NginxOneConsoleConnection is a boolean that indicates whether the connection to the Nginx One Console is enabled.
@@ -176,6 +181,10 @@ func (c DataCollectorImpl) Collect(ctx context.Context) (Data, error) {
176181

177182
nginxPodCount := getNginxPodCount(g, clusterInfo.NodeCount)
178183

184+
buildOs := os.Getenv("BUILD_OS")
185+
if buildOs == "" {
186+
buildOs = "alpine"
187+
}
179188
inferencePoolCount := int64(len(g.ReferencedInferencePools))
180189

181190
data := Data{
@@ -191,6 +200,7 @@ func (c DataCollectorImpl) Collect(ctx context.Context) (Data, error) {
191200
},
192201
NGFResourceCounts: graphResourceCount,
193202
ImageSource: c.cfg.ImageSource,
203+
BuildOS: buildOs,
194204
FlagNames: c.cfg.Flags.Names,
195205
FlagValues: c.cfg.Flags.Values,
196206
SnippetsFiltersDirectives: snippetsFiltersDirectives,

internal/controller/telemetry/collector_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ var _ = Describe("Collector", Ordered, func() {
172172
NGFResourceCounts: telemetry.NGFResourceCounts{},
173173
ControlPlanePodCount: 1,
174174
ImageSource: "local",
175+
BuildOS: "alpine",
175176
FlagNames: flags.Names,
176177
FlagValues: flags.Values,
177178
SnippetsFiltersDirectives: []string{},
@@ -193,6 +194,7 @@ var _ = Describe("Collector", Ordered, func() {
193194
Version: version,
194195
PodNSName: podNSName,
195196
ImageSource: "local",
197+
BuildOS: "alpine",
196198
Flags: flags,
197199
NginxOneConsoleConnection: true,
198200
})
@@ -524,6 +526,7 @@ var _ = Describe("Collector", Ordered, func() {
524526
expData.NginxPodCount = int64(8)
525527
expData.ControlPlanePodCount = int64(2)
526528
expData.NginxOneConnectionEnabled = true
529+
expData.BuildOS = "alpine"
527530

528531
expData.InferencePoolCount = 3
529532

internal/controller/telemetry/data.avdl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,5 +117,8 @@ attached at the Gateway level. */
117117
/** InferencePoolCount is the number of InferencePools that are referenced by at least one Route. */
118118
long? InferencePoolCount = null;
119119

120+
/** BuildOS is the base operating system the control plane was built on (e.g. alpine, ubi). */
121+
string? BuildOS = null;
122+
120123
}
121124
}

internal/controller/telemetry/data_attributes_generated.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ func (d *Data) Attributes() []attribute.KeyValue {
2424
attrs = append(attrs, attribute.Int64("ControlPlanePodCount", d.ControlPlanePodCount))
2525
attrs = append(attrs, attribute.Bool("NginxOneConnectionEnabled", d.NginxOneConnectionEnabled))
2626
attrs = append(attrs, attribute.Int64("InferencePoolCount", d.InferencePoolCount))
27+
attrs = append(attrs, attribute.String("BuildOS", d.BuildOS))
2728

2829
return attrs
2930
}

internal/controller/telemetry/data_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ func TestDataAttributes(t *testing.T) {
8888
attribute.Int64("ControlPlanePodCount", 3),
8989
attribute.Bool("NginxOneConnectionEnabled", true),
9090
attribute.Int64("InferencePoolCount", 16),
91+
attribute.String("BuildOS", ""),
9192
}
9293

9394
result := data.Attributes()
@@ -135,6 +136,7 @@ func TestDataAttributesWithEmptyData(t *testing.T) {
135136
attribute.Int64("ControlPlanePodCount", 0),
136137
attribute.Bool("NginxOneConnectionEnabled", false),
137138
attribute.Int64("InferencePoolCount", 0),
139+
attribute.String("BuildOS", ""),
138140
}
139141

140142
result := data.Attributes()

tests/suite/telemetry_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ var _ = Describe("Telemetry test with OTel collector", Label("telemetry"), func(
9797
"ControlPlanePodCount: Int(1)",
9898
"NginxOneConnectionEnabled: Bool(false)",
9999
"InferencePoolCount: Int(0)",
100+
"BuildOS:",
100101
},
101102
)
102103
})

0 commit comments

Comments
 (0)