diff --git a/cmd/botkube-agent/main.go b/cmd/botkube-agent/main.go index 54ec1f68d..c3d5a045e 100644 --- a/cmd/botkube-agent/main.go +++ b/cmd/botkube-agent/main.go @@ -381,7 +381,12 @@ func run(ctx context.Context) (err error) { ) errGroup.Go(func() error { defer analytics.ReportPanicIfOccurs(logger, analyticsReporter) - return upgradeChecker.Run(ctx) + err := upgradeChecker.Run(ctx) + if err != nil { + // we ignore error to make sure that upgrade checker does not stop the agent + logger.WithError(err).Errorf("Failed to notify about upgrade") + } + return nil }) } diff --git a/go.mod b/go.mod index 6aa70e928..bfa264b66 100644 --- a/go.mod +++ b/go.mod @@ -65,7 +65,7 @@ require ( google.golang.org/protobuf v1.31.0 gopkg.in/yaml.v3 v3.0.1 gotest.tools/v3 v3.5.1 - helm.sh/helm/v3 v3.14.1 + helm.sh/helm/v3 v3.14.2 k8s.io/api v0.29.0 k8s.io/apimachinery v0.29.0 k8s.io/cli-runtime v0.29.0 diff --git a/go.sum b/go.sum index 21a6c0539..c87407904 100644 --- a/go.sum +++ b/go.sum @@ -1832,8 +1832,8 @@ gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gotest.tools/v3 v3.5.1 h1:EENdUnS3pdur5nybKYIh2Vfgc8IUNBjxDPSjtiJcOzU= gotest.tools/v3 v3.5.1/go.mod h1:isy3WKz7GK6uNw/sbHzfKBLvlvXwUyV06n6brMxxopU= grpc.go4.org v0.0.0-20170609214715-11d0a25b4919/go.mod h1:77eQGdRu53HpSqPFJFmuJdjuHRquDANNeA4x7B8WQ9o= -helm.sh/helm/v3 v3.14.1 h1:4AwRLx+wfzlPtvrsbDmWP5PUokGmf9/nAmEdk21vae8= -helm.sh/helm/v3 v3.14.1/go.mod h1:2itvvDv2WSZXTllknfQo6j7u3VVgMAvm8POCDgYH424= +helm.sh/helm/v3 v3.14.2 h1:V71fv+NGZv0icBlr+in1MJXuUIHCiPG1hW9gEBISTIA= +helm.sh/helm/v3 v3.14.2/go.mod h1:2itvvDv2WSZXTllknfQo6j7u3VVgMAvm8POCDgYH424= honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/internal/analytics/segment_reporter.go b/internal/analytics/segment_reporter.go index b2e4f9137..82852153e 100644 --- a/internal/analytics/segment_reporter.go +++ b/internal/analytics/segment_reporter.go @@ -14,6 +14,7 @@ import ( "github.com/kubeshop/botkube/internal/analytics/batched" "github.com/kubeshop/botkube/pkg/config" + "github.com/kubeshop/botkube/pkg/maputil" "github.com/kubeshop/botkube/pkg/plugin" "github.com/kubeshop/botkube/pkg/ptr" "github.com/kubeshop/botkube/pkg/version" @@ -116,11 +117,15 @@ func (r *SegmentReporter) ReportBotEnabled(platform config.CommPlatformIntegrati // ReportPluginsEnabled reports plugins enabled. func (r *SegmentReporter) ReportPluginsEnabled(executors map[string]config.Executors, sources map[string]config.Sources) error { pluginsConfig := make(map[string]interface{}) - for _, values := range executors { - r.generatePluginsReport(pluginsConfig, values.Plugins, plugin.TypeExecutor) + + executorKeys := maputil.SortKeys(executors) + for i, key := range executorKeys { + r.generatePluginsReport(i, pluginsConfig, executors[key].Plugins, plugin.TypeExecutor) } - for _, values := range sources { - r.generatePluginsReport(pluginsConfig, values.Plugins, plugin.TypeSource) + + sourceKeys := maputil.SortKeys(sources) + for i, key := range sourceKeys { + r.generatePluginsReport(i, pluginsConfig, sources[key].Plugins, plugin.TypeSource) } return r.reportEvent("Plugin enabled", pluginsConfig) } @@ -353,12 +358,18 @@ func (r *SegmentReporter) getNodeCount(ctx context.Context, k8sCli kubernetes.In return workerNodesCount, controlPlaneNodesCount, nil } -func (r *SegmentReporter) generatePluginsReport(pluginsConfig map[string]interface{}, plugins config.Plugins, pluginType plugin.Type) { +func (r *SegmentReporter) generatePluginsReport(cfgGroupIdx int, pluginsConfig map[string]interface{}, plugins config.Plugins, pluginType plugin.Type) { for name, pluginValue := range plugins { if !pluginValue.Enabled { continue } - pluginsConfig[name] = pluginReport{ + + key := name + if _, exists := pluginsConfig[name]; exists { + key = fmt.Sprintf("%s-%d", name, cfgGroupIdx) + } + + pluginsConfig[key] = pluginReport{ Name: name, Type: pluginType, RBAC: r.getAnonymizedRBAC(pluginValue.Context.RBAC), @@ -367,6 +378,10 @@ func (r *SegmentReporter) generatePluginsReport(pluginsConfig map[string]interfa } func (r *SegmentReporter) getAnonymizedRBAC(rbac *config.PolicyRule) *config.PolicyRule { + if rbac == nil { + return nil + } + rbac.Group.Prefix = r.anonymizedValue(rbac.Group.Prefix) for key, name := range rbac.Group.Static.Values { rbac.Group.Static.Values[key] = r.anonymizedValue(name) diff --git a/internal/analytics/segment_reporter_test.go b/internal/analytics/segment_reporter_test.go index c76726b54..0a8ff9321 100644 --- a/internal/analytics/segment_reporter_test.go +++ b/internal/analytics/segment_reporter_test.go @@ -215,6 +215,18 @@ func TestSegmentReporter_ReportPluginsEnabled(t *testing.T) { }, }, }, + "botkube/kubectl_2": { + DisplayName: "kubectl", + Plugins: map[string]config.Plugin{ + "botkube/kubectl": { + Enabled: true, + Config: "{}", + Context: config.PluginContext{ + RBAC: nil, + }, + }, + }, + }, }, map[string]config.Sources{ "botkube/kubernetes_22yy2": { DisplayName: "k8s", @@ -270,6 +282,18 @@ func TestSegmentReporter_ReportPluginsEnabled(t *testing.T) { }, }, }, + "botkube/kubernetes_2": { + DisplayName: "kubernetes", + Plugins: map[string]config.Plugin{ + "botkube/kubernetes": { + Enabled: true, + Config: "{}", + Context: config.PluginContext{ + RBAC: nil, + }, + }, + }, + }, }) require.NoError(t, err) diff --git a/internal/analytics/testdata/TestSegmentReporter_ReportPluginsEnabled.json b/internal/analytics/testdata/TestSegmentReporter_ReportPluginsEnabled.json index 78625c2b2..4dac81551 100644 --- a/internal/analytics/testdata/TestSegmentReporter_ReportPluginsEnabled.json +++ b/internal/analytics/testdata/TestSegmentReporter_ReportPluginsEnabled.json @@ -30,6 +30,11 @@ } }, "botkube/kubectl": { + "Name": "botkube/kubectl", + "Type": "executor", + "RBAC": null + }, + "botkube/kubectl-2": { "Name": "botkube/kubectl", "Type": "executor", "RBAC": { @@ -50,6 +55,11 @@ } }, "botkube/kubernetes": { + "Name": "botkube/kubernetes", + "Type": "source", + "RBAC": null + }, + "botkube/kubernetes-2": { "Name": "botkube/kubernetes", "Type": "source", "RBAC": { diff --git a/test/e2e/bots_test.go b/test/e2e/bots_test.go index af9766ea2..5a68473b7 100644 --- a/test/e2e/bots_test.go +++ b/test/e2e/bots_test.go @@ -1256,10 +1256,10 @@ func runBotTest(t *testing.T, command := "list executors" expectedBody := codeBlock(heredoc.Doc(` - EXECUTOR ENABLED ALIASES RESTARTS STATUS LAST_RESTART - botkube/echo@v0.0.0-latest true e 0/1 Running - botkube/kubectl true k, kc 0/1 Running - botkubeCloud/helm true 0/1 Running`)) + EXECUTOR ENABLED ALIASES RESTARTS STATUS LAST_RESTART + botkube/echo true e 0/1 Running + botkube/kubectl true k, kc 0/1 Running + botkubeCloud/helm true 0/1 Running`)) if botDriver.Type() == commplatform.DiscordBot { // Cloud plugins are not tested on Discord