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

feat(telemetry): include gw discovery and konnect sync in reports #3588

Merged
merged 1 commit into from
Feb 22, 2023
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 CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ Adding a new version? You'll need three changes:
[#3563](https://github.com/Kong/kubernetes-ingress-controller/pull/3563)
- Added `GRPCRoute` controller and implemented basic `GRPCRoute` functionality.
[#3537](https://github.com/Kong/kubernetes-ingress-controller/pull/3537)
- Included Konnect sync and Gateway Service discovery features in telemetry reports.
[#3588](https://github.com/Kong/kubernetes-ingress-controller/pull/3588)

### Fixed

Expand Down
11 changes: 7 additions & 4 deletions internal/manager/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,11 +229,14 @@ func Run(ctx context.Context, c *Config, diagnostic util.ConfigDumpDiagnostic, d
stopAnonymousReports, err := telemetry.SetupAnonymousReports(
ctx,
kubeconfig,
c.PublishService,
metadata.Release,
len(c.WatchNamespaces) == 0,
featureGates,
clientsManager,
telemetry.ReportValues{
PublishServiceNN: c.PublishService,
FeatureGates: featureGates,
MeshDetection: len(c.WatchNamespaces) == 0,
KonnectSyncEnabled: c.Konnect.ConfigSynchronizationEnabled,
GatewayServiceDiscoveryEnabled: c.KongAdminSvc.String() != "",
},
)
if err != nil {
setupLog.Error(err, "failed setting up anonymous reports")
Expand Down
38 changes: 24 additions & 14 deletions internal/manager/telemetry/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,16 @@ const (

type Payload = types.ProviderReport

type ReportValues struct {
FeatureGates map[string]bool
MeshDetection bool
PublishServiceNN apitypes.NamespacedName
KonnectSyncEnabled bool
GatewayServiceDiscoveryEnabled bool
}

// CreateManager creates telemetry manager using the provided rest.Config.
func CreateManager(
restConfig *rest.Config,
fixedPayload Payload,
featureGates map[string]bool,
meshDetection bool,
publishServiceNN apitypes.NamespacedName,
) (telemetry.Manager, error) {
func CreateManager(restConfig *rest.Config, fixedPayload Payload, rv ReportValues) (telemetry.Manager, error) {
logger := logrusr.New(logrus.New())

k, err := kubernetes.NewForConfig(restConfig)
Expand All @@ -52,7 +54,7 @@ func CreateManager(
}
dyn := dynamic.New(k.Discovery().RESTClient())

m, err := createManager(k, dyn, cl, fixedPayload, featureGates, meshDetection, publishServiceNN,
m, err := createManager(k, dyn, cl, fixedPayload, rv,
telemetry.OptManagerPeriod(telemetryPeriod),
telemetry.OptManagerLogger(logger),
)
Expand All @@ -78,9 +80,7 @@ func createManager(
dyn dynamic.Interface,
cl client.Client,
fixedPayload Payload,
featureGates map[string]bool,
meshDetection bool,
publishServiceNN apitypes.NamespacedName,
rv ReportValues,
opts ...telemetry.OptManager,
) (telemetry.Manager, error) {
m, err := telemetry.NewManager(
Expand Down Expand Up @@ -112,15 +112,15 @@ func createManager(

// Add mesh detect workflow
{
if meshDetection {
if rv.MeshDetection {
podNN, err := util.GetPodNN()
if err != nil {
// Don't fail, just don't include mesh detection workflow.
// We could probably add conditions around this, so that only the
// part responsible for detecting the mesh that current pod is running
// gets disabled.
} else {
w, err := telemetry.NewMeshDetectWorkflow(cl, podNN, publishServiceNN)
w, err := telemetry.NewMeshDetectWorkflow(cl, podNN, rv.PublishServiceNN)
if err != nil {
return nil, fmt.Errorf("failed to create mesh detect workflow: %w", err)
}
Expand All @@ -145,7 +145,17 @@ func createManager(
w.AddProvider(p)
}
{
p, err := provider.NewFixedValueProvider("feature-gates", featureGatesToTelemetryPayload(featureGates))
p, err := provider.NewFixedValueProvider("feature-gates", featureGatesToTelemetryPayload(rv.FeatureGates))
if err != nil {
return nil, fmt.Errorf("failed to create fixed value provider: %w", err)
}
w.AddProvider(p)
}
{
p, err := provider.NewFixedValueProvider("feature-flags", types.ProviderReport{
"feature-konnect-sync": rv.KonnectSyncEnabled,
"feature-gateway-service-discovery": rv.GatewayServiceDiscoveryEnabled,
})
if err != nil {
return nil, fmt.Errorf("failed to create fixed value provider: %w", err)
}
Expand Down
16 changes: 14 additions & 2 deletions internal/manager/telemetry/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ func TestCreateManager(t *testing.T) {
"knative": false,
}
ctx = context.Background()
meshDetection = true
publishService = apitypes.NamespacedName{
Namespace: "kong",
Name: "kong-proxy",
Expand Down Expand Up @@ -83,7 +82,18 @@ func TestCreateManager(t *testing.T) {
Platform: "linux/amd64",
}

mgr, err := createManager(k8sclient, dyn, ctrlClient, payload, featureGates, meshDetection, publishService,
mgr, err := createManager(
k8sclient,
dyn,
ctrlClient,
payload,
ReportValues{
FeatureGates: featureGates,
MeshDetection: true,
PublishServiceNN: publishService,
KonnectSyncEnabled: true,
GatewayServiceDiscoveryEnabled: true,
},
telemetry.OptManagerPeriod(time.Hour),
telemetry.OptManagerLogger(logr.Discard()),
)
Expand All @@ -107,8 +117,10 @@ func TestCreateManager(t *testing.T) {
"<14>"+
"signal=test-signal;"+
"db=off;"+
"feature-gateway-service-discovery=true;"+
"feature-gateway=true;"+
"feature-knative=false;"+
"feature-konnect-sync=true;"+
"hn=%s;"+
"kv=3.1.1;"+
"uptime=0;"+
Expand Down
12 changes: 4 additions & 8 deletions internal/manager/telemetry/reports.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"

"github.com/google/uuid"
apitypes "k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/rest"

"github.com/kong/kubernetes-ingress-controller/v2/internal/dataplane"
Expand All @@ -19,11 +18,8 @@ import (
func SetupAnonymousReports(
ctx context.Context,
kubeCfg *rest.Config,
publishService apitypes.NamespacedName,
kicVersion string,
meshDetection bool,
featureGates map[string]bool,
clientsProvider dataplane.AdminAPIClientsProvider,
rv ReportValues,
) (func(), error) {
// if anonymous reports are enabled this helps provide Kong with insights about usage of the ingress controller
// which is non-sensitive and predominantly informs us of the controller and cluster versions in use.
Expand All @@ -35,10 +31,10 @@ func SetupAnonymousReports(
// That's fine because we allow for now only 1 set of version and db setting
// throughout all Kong instances that 1 KIC instance configures.
//
// When we change that and decide to allow heterogenous Kong instances to be
// When we change that and decide to allow heterogeneous Kong instances to be
// configured by 1 KIC instance then this will have to change.
//
// https://github.com/Kong/kubernetes-ingress-controller/issues/3362
// https://github.com/Kong/kubernetes-ingress-controller/issues/3589
root, err := clientsProvider.GatewayClients()[0].AdminAPIClient().Root(ctx)
if err != nil {
return nil, fmt.Errorf("failed to get Kong root config data: %w", err)
Expand All @@ -65,7 +61,7 @@ func SetupAnonymousReports(
"id": uuid.NewString(), // universal unique identifier for this system
}

tMgr, err := CreateManager(kubeCfg, fixedPayload, featureGates, meshDetection, publishService)
tMgr, err := CreateManager(kubeCfg, fixedPayload, rv)
if err != nil {
return nil, fmt.Errorf("failed to create anonymous reports manager: %w", err)
}
Expand Down
1 change: 1 addition & 0 deletions internal/manager/utils/kongconfig/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func ValidateRoots(roots []Root, skipCACerts bool) (string, kong.Version, error)
return "", kong.Version{}, fmt.Errorf("failed to validate kong Roots: %w", err)
}

// To be dropped as a part of https://github.com/Kong/kubernetes-ingress-controller/issues/3590.
uniqs := lo.UniqBy(roots, getRootKeyFunc(skipCACerts))
if len(uniqs) != 1 {
return "", kong.Version{},
Expand Down
117 changes: 0 additions & 117 deletions internal/manager/utils/reports.go

This file was deleted.