Skip to content
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: 2 additions & 0 deletions build/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,8 @@ ARG IC_VERSION
ARG TARGETPLATFORM
ARG NAP_MODULES=none

ENV BUILD_OS=${BUILD_OS}

RUN --mount=type=bind,target=/tmp \
--mount=type=bind,from=nginx-files,src=common.sh,target=/usr/local/bin/common.sh \
--mount=type=bind,from=nginx-files,src=patch-os.sh,target=/usr/local/bin/patch-os.sh \
Expand Down
3 changes: 3 additions & 0 deletions cmd/nginx-ingress/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ func main() {
parseFlags()
parsedFlags := os.Args[1:]

buildOS := os.Getenv("BUILD_OS")

config, kubeClient := createConfigAndKubeClient()

kubernetesVersionInfo(kubeClient)
Expand Down Expand Up @@ -230,6 +232,7 @@ func main() {
WatchNamespaceLabel: *watchNamespaceLabel,
EnableTelemetryReporting: *enableTelemetryReporting,
TelemetryReportingEndpoint: telemetryEndpoint,
BuildOS: buildOS,
NICVersion: version,
DynamicWeightChangesReload: *enableDynamicWeightChangesReload,
InstallationFlags: parsedFlags,
Expand Down
1 change: 1 addition & 0 deletions docs/content/overview/product-telemetry.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ These are the data points collected and reported by NGINX Ingress Controller:
- **AppProtectVersion** The AppProtect version
- **IsPlus** Represents whether NGINX is Plus or OSS
- **InstallationFlags** List of command line arguments configured for NGINX Ingress Controller
- **BuildOS** The base operating system image in which NGINX Ingress Controller is running on.

---

Expand Down
2 changes: 2 additions & 0 deletions internal/k8s/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ type NewLoadBalancerControllerInput struct {
WatchNamespaceLabel string
EnableTelemetryReporting bool
TelemetryReportingEndpoint string
BuildOS string
NICVersion string
DynamicWeightChangesReload bool
InstallationFlags []string
Expand Down Expand Up @@ -371,6 +372,7 @@ func NewLoadBalancerController(input NewLoadBalancerControllerInput) *LoadBalanc
K8sClientReader: input.KubeClient,
Version: input.NICVersion,
AppProtectVersion: input.AppProtectVersion,
BuildOS: input.BuildOS,
InstallationFlags: input.InstallationFlags,
GlobalConfiguration: lbc.watchGlobalConfiguration,
Configurator: lbc.configurator,
Expand Down
5 changes: 5 additions & 0 deletions internal/telemetry/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,11 @@ func (c *Collector) ServiceCounts() (map[string]int, error) {
return serviceCounts, nil
}

// BuildOS returns a string which is the base operating system image tha NIC is running in.
func (c *Collector) BuildOS() string {
return c.Config.BuildOS
}

// lookupPlatform takes a string representing a K8s PlatformID
// retrieved from a cluster node and returns a string
// representing the platform name.
Expand Down
6 changes: 6 additions & 0 deletions internal/telemetry/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ type CollectorConfig struct {
// AppProtectVersion represents the version of App Protect.
AppProtectVersion string

// BuildOS represents the base operating system image
BuildOS string

// IsPlus represents whether NGINX is Plus or OSS
IsPlus bool

Expand Down Expand Up @@ -154,6 +157,7 @@ func (c *Collector) Collect(ctx context.Context) {
AppProtectVersion: report.AppProtectVersion,
IsPlus: report.IsPlus,
InstallationFlags: report.InstallationFlags,
BuildOS: report.BuildOS,
},
}

Expand Down Expand Up @@ -203,6 +207,7 @@ type Report struct {
AppProtectVersion string
IsPlus bool
InstallationFlags []string
BuildOS string
}

// BuildReport takes context, collects telemetry data and builds the report.
Expand Down Expand Up @@ -334,5 +339,6 @@ func (c *Collector) BuildReport(ctx context.Context) (Report, error) {
AppProtectVersion: appProtectVersion,
IsPlus: isPlus,
InstallationFlags: installationFlags,
BuildOS: c.BuildOS(),
}, err
}
59 changes: 59 additions & 0 deletions internal/telemetry/collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1129,6 +1129,65 @@ func TestCollectInstallationFlags(t *testing.T) {
}
}

func TestCollectBuildOS(t *testing.T) {
t.Parallel()

testCases := []struct {
name string
buildOS string
wantOS string
}{
{
name: "debian plus image",
buildOS: "debian-plus",
wantOS: "debian-plus",
},
{
name: "ubi-9 plus app protect image",
buildOS: "ubi-9-plus-nap",
wantOS: "ubi-9-plus-nap",
},
{
name: "alpine oss image",
buildOS: "alpine",
wantOS: "alpine",
},
{
name: "self built image",
buildOS: "",
wantOS: "",
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
buf := &bytes.Buffer{}
exp := &telemetry.StdoutExporter{Endpoint: buf}

configurator := newConfiguratorWithIngress(t)

cfg := telemetry.CollectorConfig{
Configurator: configurator,
K8sClientReader: newTestClientset(node1, kubeNS),
Version: telemetryNICData.ProjectVersion,
BuildOS: tc.buildOS,
}

c, err := telemetry.NewCollector(cfg, telemetry.WithExporter(exp))
if err != nil {
t.Fatal(err)
}
c.Collect(context.Background())

buildOS := c.BuildOS()

if tc.wantOS != buildOS {
t.Errorf("want: %s, got: %s", tc.wantOS, buildOS)
}
})
}
}

func TestCountVirtualServersOnCustomResourceEnabled(t *testing.T) {
t.Parallel()

Expand Down
4 changes: 3 additions & 1 deletion internal/telemetry/data.avdl
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
@namespace("ingress.nginx.com") protocol NICProductTelemetry {
/** Data is the product telemetry data of NGINX Ingress Controller. */
@df_datatype("nic-product-telemetry") record Data {
/** The field that identifies what type of data this is. */
string dataType;
Expand Down Expand Up @@ -115,5 +114,8 @@ It is the UID of the `kube-system` Namespace. */
/** InstallationFlags is the list of command line arguments configured for NGINX Ingress Controller */
union {null, array<string>} InstallationFlags = null;

/** BuildOS returns the base buildOS image */
string? BuildOS = null;

}
}
2 changes: 2 additions & 0 deletions internal/telemetry/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,6 @@ type NICResourceCounts struct {
IsPlus bool
// InstallationFlags is the list of command line arguments configured for NGINX Ingress Controller
InstallationFlags []string
// BuildOS represents the base operating system image
BuildOS string
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func (d *NICResourceCounts) Attributes() []attribute.KeyValue {
attrs = append(attrs, attribute.String("AppProtectVersion", d.AppProtectVersion))
attrs = append(attrs, attribute.Bool("IsPlus", d.IsPlus))
attrs = append(attrs, attribute.StringSlice("InstallationFlags", d.InstallationFlags))
attrs = append(attrs, attribute.String("BuildOS", d.BuildOS))

return attrs
}
Expand Down