Skip to content
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

Add Granular Ingress Counts to Telemetry #5608

Merged
merged 23 commits into from
May 28, 2024
Merged
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
203ff59
Add Installation Flags to Telemetry - all comparison tests break need…
AlexFenlon May 17, 2024
a3b4966
Add tests for installation flags - dont work at the moment
AlexFenlon May 20, 2024
a455218
Merge remote-tracking branch 'refs/remotes/origin/main' into feat/tel…
AlexFenlon May 20, 2024
7cc10b9
Add catch for tests
AlexFenlon May 20, 2024
50b9014
Merge remote-tracking branch 'refs/remotes/origin/main' into feat/tel…
AlexFenlon May 20, 2024
3104ab4
Remove non working test
AlexFenlon May 20, 2024
ae501e1
Merge branch 'main' into feat/telemetry-flags
AlexFenlon May 20, 2024
8acff3b
Add tests and use lbc instead of os.args
AlexFenlon May 20, 2024
147e35e
Merge remote-tracking branch 'refs/remotes/origin/main' into feat/tel…
AlexFenlon May 21, 2024
8f3dc7f
Add tests, refactor and get os.Args at main
AlexFenlon May 21, 2024
ad3dad7
Merge branch 'main' into feat/telemetry-flags
jjngx May 21, 2024
3d3851c
Merge branch 'main' into feat/telemetry-flags
jjngx May 21, 2024
7d205e7
Merge branch 'main' into feat/telemetry-flags
jjngx May 21, 2024
12069aa
Fix Doc change from PR and associated changes
AlexFenlon May 22, 2024
7f4501d
Update docs/content/overview/product-telemetry.md
AlexFenlon May 22, 2024
26bde6c
Add Granular Ingress Counts to Telemetry
AlexFenlon May 22, 2024
a2ae400
Merge remote-tracking branch 'refs/remotes/origin/main' into feat/tel…
AlexFenlon May 22, 2024
df0c079
Fix doc and comment.
AlexFenlon May 23, 2024
2416458
Fix data.avdl
AlexFenlon May 23, 2024
bbfc1db
Merge branch 'main' into feat/telemetry-granular-ingress-counts
AlexFenlon May 23, 2024
c163cf5
Merge branch 'main' into feat/telemetry-granular-ingress-counts
AlexFenlon May 23, 2024
e49e8ba
Merge branch 'main' into feat/telemetry-granular-ingress-counts
AlexFenlon May 27, 2024
c8bbe0f
Merge branch 'main' into feat/telemetry-granular-ingress-counts
AlexFenlon May 28, 2024
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
Prev Previous commit
Next Next commit
Add tests, refactor and get os.Args at main
AlexFenlon committed May 21, 2024
commit 8f3dc7fbec3e69f55069ae6154adcfc4701af090
4 changes: 2 additions & 2 deletions cmd/nginx-ingress/main.go
Original file line number Diff line number Diff line change
@@ -2,7 +2,6 @@ package main

import (
"context"
"flag"
"fmt"
"net"
"net/http"
@@ -60,6 +59,7 @@ func main() {
fmt.Printf("NGINX Ingress Controller Version=%v Commit=%v Date=%v DirtyState=%v Arch=%v/%v Go=%v\n", version, commitHash, commitTime, dirtyBuild, runtime.GOOS, runtime.GOARCH, runtime.Version())

parseFlags()
parsedFlags := os.Args[1:]

config, kubeClient := createConfigAndKubeClient()

@@ -218,7 +218,7 @@ func main() {
TelemetryReportingEndpoint: telemetryEndpoint,
NICVersion: version,
DynamicWeightChangesReload: *enableDynamicWeightChangesReload,
InstallationFlags: flag.Args(),
InstallationFlags: parsedFlags,
}

lbc := k8s.NewLoadBalancerController(lbcInput)
14 changes: 1 addition & 13 deletions internal/telemetry/cluster.go
Original file line number Diff line number Diff line change
@@ -3,7 +3,6 @@ package telemetry
import (
"context"
"errors"
"flag"
"fmt"
"strings"

@@ -205,18 +204,7 @@ func (c *Collector) IsPlusEnabled() bool {

// InstallationFlags returns the list of all set flags
func (c *Collector) InstallationFlags() []string {
flags := c.Config.InstallationFlags
flag.Visit(func(f *flag.Flag) {
switch {
case strings.Contains(f.Name, "test."):
flags = []string{""}
case f.Value.String() == "":
flags = append(flags, f.Name)
default:
flags = append(flags, fmt.Sprintf("%s=%s", f.Name, f.Value.String()))
}
})
return flags
return c.Config.InstallationFlags
}

// lookupPlatform takes a string representing a K8s PlatformID
23 changes: 23 additions & 0 deletions internal/telemetry/cluster_test.go
Original file line number Diff line number Diff line change
@@ -4,6 +4,8 @@ import (
"context"
"testing"

"github.com/google/go-cmp/cmp"

"github.com/nginxinc/kubernetes-ingress/internal/telemetry"
appsV1 "k8s.io/api/apps/v1"
apiCoreV1 "k8s.io/api/core/v1"
@@ -436,6 +438,27 @@ func TestInstallationIDFailsOnMissingDaemonSet(t *testing.T) {
}
}

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

c, err := telemetry.NewCollector(
telemetry.CollectorConfig{
InstallationFlags: []string{
"-nginx-plus=true",
},
},
)
if err != nil {
t.Fatal(err)
}

got := c.InstallationFlags()
want := []string{"-nginx-plus=true"}
if !cmp.Equal(want, got) {
t.Error(cmp.Diff(want, got))
}
}

// newTestCollectorForClusterWithNodes returns a telemetry collector configured
// to simulate collecting data on a cluser with provided nodes.
func newTestCollectorForClusterWithNodes(t *testing.T, nodes ...runtime.Object) *telemetry.Collector {
113 changes: 24 additions & 89 deletions internal/telemetry/collector_test.go
Original file line number Diff line number Diff line change
@@ -906,11 +906,11 @@ func TestCollectInstallationFlags(t *testing.T) {
name: "multiple flags",
setFlags: []string{
"nginx-plus=true",
"^\\QTestCollectInstallationFlags\\E$",
"-v=3",
},
wantFlags: []string{
"nginx-plus=true",
"^\\QTestCollectInstallationFlags\\E$",
"-v=3",
},
},
{
@@ -940,99 +940,34 @@ func TestCollectInstallationFlags(t *testing.T) {
}
c.Collect(context.Background())

flags := c.InstallationFlags()

for _, wantFlag := range tc.wantFlags {
found := false
for _, flag := range flags {
if flag == wantFlag {
found = true
break
}
}
if !found {
t.Errorf("expected flag %s not found in %v", wantFlag, flags)
}
telData := tel.Data{
ProjectName: telemetryNICData.ProjectName,
ProjectVersion: telemetryNICData.ProjectVersion,
ProjectArchitecture: telemetryNICData.ProjectArchitecture,
ClusterNodeCount: 1,
ClusterID: telemetryNICData.ClusterID,
ClusterVersion: telemetryNICData.ClusterVersion,
ClusterPlatform: "other",
}
})
}
}

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

testCases := []struct {
name string
setFlags []string
wantFlags []string
}{
{
name: "wrong flag",
setFlags: []string{
"-test.v",
},
wantFlags: []string{
"-nginx-plus7",
},
},
{
name: "wrong flag 2",
setFlags: []string{
"-test.v",
},
wantFlags: []string{
"-test",
},
},
{
name: "multiple wrong flags",
wantFlags: []string{
"-test.v123",
"^\\CollectionFlags\\$",
},
},
{
name: "nil flags",
setFlags: []string{
"-test.v",
},
wantFlags: nil,
},
}

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,
InstallationFlags: tc.setFlags,
nicResourceCounts := telemetry.NICResourceCounts{
VirtualServers: 0,
VirtualServerRoutes: 0,
TransportServers: 0,
Ingresses: 0,
InstallationFlags: tc.wantFlags,
}

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

flags := c.InstallationFlags()

for _, wantFlag := range tc.wantFlags {
found := false
for _, flag := range flags {
if flag == wantFlag {
found = true
break
}
}
if found {
t.Errorf("expected flag %s not found in %v", wantFlag, flags)
}
want := fmt.Sprintf("%+v", &td)

got := buf.String()
if !cmp.Equal(want, got) {
t.Error(cmp.Diff(got, want))
}
})
}