Skip to content
Open
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 internal/controller/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package controller
import (
"context"
"fmt"
"os"
"time"

"github.com/go-logr/logr"
Expand Down Expand Up @@ -290,6 +291,7 @@ func StartManager(cfg config.Config) error {
Name: cfg.GatewayPodConfig.Name,
},
ImageSource: cfg.ImageSource,
BuildOS: os.Getenv("BUILD_OS"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we'll still need the check you had before and like in ImageSource where BUILD_OS could be something else besides ubi or it could be empty.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

			imageSource := os.Getenv("BUILD_AGENT")
			if imageSource != "gha" && imageSource != "local" {
				imageSource = "unknown"
			}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sjberman pointed out in here that we should just be able to access it directly.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, os.Getenv("BUILD_OS") should be directly accessible in this file (probably even just in the collector file), but we'll still need to check the value of it. Since it could be empty and we don't want to pass that empty value in and would rather pass in something like "unknown" or "alpine"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah fair point. I'll update that too.

Flags: cfg.Flags,
NginxOneConsoleConnection: cfg.NginxOneConsoleTelemetryConfig.DataplaneKeySecretName != "",
})
Expand Down
7 changes: 6 additions & 1 deletion internal/controller/telemetry/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type ConfigurationGetter interface {
// Data is telemetry data.
//
//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
type Data struct {
type Data struct { //nolint //required to skip golangci-lint-full fieldalignment
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do you need nolint here?

// ImageSource tells whether the image was built by GitHub or locally (values are 'gha', 'local', or 'unknown')
ImageSource string
tel.Data // embedding is required by the generator.
Expand All @@ -66,6 +66,8 @@ type Data struct {
ControlPlanePodCount int64
// NginxOneConnectionEnabled is a boolean that indicates whether the connection to the Nginx One Console is enabled.
NginxOneConnectionEnabled bool
// BuildOS is the OS the NGF and NGINX binary was built on.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically this just checks the OS of NGF right? Do we know the expected functionality if somebody builds NGF with ubi but then tries to use NGINX in the other os?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, I'm not really sure how that would work, or if it even can. I guess nothing really stops anyone from mixing them

BuildOS string
}

// NGFResourceCounts stores the counts of all relevant resources that NGF processes and generates configuration from.
Expand Down Expand Up @@ -121,6 +123,8 @@ type DataCollectorConfig struct {
Version string
// ImageSource is the source of the NGF image.
ImageSource string
// BuildOS is the OS the NGF and NGINX binary was built on.
BuildOS string
// Flags contains the command-line NGF flag keys and values.
Flags config.Flags
// NginxOneConsoleConnection is a boolean that indicates whether the connection to the Nginx One Console is enabled.
Expand Down Expand Up @@ -187,6 +191,7 @@ func (c DataCollectorImpl) Collect(ctx context.Context) (Data, error) {
},
NGFResourceCounts: graphResourceCount,
ImageSource: c.cfg.ImageSource,
BuildOS: c.cfg.BuildOS,
FlagNames: c.cfg.Flags.Names,
FlagValues: c.cfg.Flags.Values,
SnippetsFiltersDirectives: snippetsFiltersDirectives,
Expand Down
2 changes: 2 additions & 0 deletions internal/controller/telemetry/collector_test.go
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll need to add the field to the "Normal Case"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, what is "normal case"?

Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ var _ = Describe("Collector", Ordered, func() {
NGFResourceCounts: telemetry.NGFResourceCounts{},
ControlPlanePodCount: 1,
ImageSource: "local",
BuildOS: "ubi",
FlagNames: flags.Names,
FlagValues: flags.Values,
SnippetsFiltersDirectives: []string{},
Expand All @@ -193,6 +194,7 @@ var _ = Describe("Collector", Ordered, func() {
Version: version,
PodNSName: podNSName,
ImageSource: "local",
BuildOS: "ubi",
Flags: flags,
NginxOneConsoleConnection: true,
})
Expand Down
3 changes: 3 additions & 0 deletions internal/controller/telemetry/data.avdl
Original file line number Diff line number Diff line change
Expand Up @@ -114,5 +114,8 @@ attached at the Gateway level. */
/** NginxOneConnectionEnabled is a boolean that indicates whether the connection to the Nginx One Console is enabled. */
boolean? NginxOneConnectionEnabled = null;

/** BuildOS is the OS the NGF and NGINX binary was built on. */
string? BuildOS = null;

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func (d *Data) Attributes() []attribute.KeyValue {
attrs = append(attrs, attribute.Int64("NginxPodCount", d.NginxPodCount))
attrs = append(attrs, attribute.Int64("ControlPlanePodCount", d.ControlPlanePodCount))
attrs = append(attrs, attribute.Bool("NginxOneConnectionEnabled", d.NginxOneConnectionEnabled))
attrs = append(attrs, attribute.String("BuildOS", d.BuildOS))

return attrs
}
Expand Down
2 changes: 2 additions & 0 deletions internal/controller/telemetry/data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ func TestDataAttributes(t *testing.T) {
attribute.Int64("NginxPodCount", 3),
attribute.Int64("ControlPlanePodCount", 3),
attribute.Bool("NginxOneConnectionEnabled", true),
attribute.String("BuildOS", ""),
}

result := data.Attributes()
Expand Down Expand Up @@ -132,6 +133,7 @@ func TestDataAttributesWithEmptyData(t *testing.T) {
attribute.Int64("NginxPodCount", 0),
attribute.Int64("ControlPlanePodCount", 0),
attribute.Bool("NginxOneConnectionEnabled", false),
attribute.String("BuildOS", ""),
}

result := data.Attributes()
Expand Down
1 change: 1 addition & 0 deletions tests/suite/telemetry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ var _ = Describe("Telemetry test with OTel collector", Label("telemetry"), func(
"NginxPodCount: Int(0)",
"ControlPlanePodCount: Int(1)",
"NginxOneConnectionEnabled: Bool(false)",
"BuildOS:",
},
)
})
Expand Down
Loading