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

Only log incorrect k8s buttons definitions #1413

Merged
merged 2 commits into from
Mar 12, 2024
Merged

Conversation

mszostok
Copy link
Contributor

@mszostok mszostok commented Mar 11, 2024

Description

Changes proposed in this pull request:

  • Only log incorrect k8s buttons definitions
  • Agent without debug enabled, shows k8s plugin errors too.

Testing

You can see the unit-test, additionally I tested that e2e:

  • when Agent uses text logger:
    ERRO[2024-03-11T18:17:30+01:00] ERRO[2024-03-11T18:17:30+01:00] Failed to convert extra buttons assigned to "error" event. Those buttons will be omitted. Issues:  logger=stderr plugin=botkube/kubernetes
    ERRO[2024-03-11T18:17:30+01:00] 3 errors occurred:                            logger=stderr plugin=botkube/kubernetes
    ERRO[2024-03-11T18:17:30+01:00] 	* invalid extraButtons[1].commandTpl: template: Ask AI v2:1:11: executing "Ask AI v2" at <.Event.Namespace>: can't evaluate field Event in type event.Event  logger=stderr plugin=botkube/kubernetes
    ERRO[2024-03-11T18:17:30+01:00] 	* invalid extraButtons[2]: displayName cannot be empty  logger=stderr plugin=botkube/kubernetes
    ERRO[2024-03-11T18:17:30+01:00] 	* invalid extraButtons[3]: displayName cannot be empty, unknown trigger.type["fatal"]  component="Message Builder"  logger=stderr plugin=botkube/kubernetes
    
  • when agent uses json logger:
    {"level":"error","logger":"stderr","msg":"\u001b[31mERRO\u001b[0m[2024-03-11T18:37:36+01:00] Failed to convert extra buttons assigned to \"error\" event. Those buttons will be omitted. Issues:","plugin":"botkube/kubernetes","time":"2024-03-11T18:37:36+01:00"}
    {"level":"error","logger":"stderr","msg":"3 errors occurred:","plugin":"botkube/kubernetes","time":"2024-03-11T18:37:36+01:00"}
    {"level":"error","logger":"stderr","msg":"\t* invalid extraButtons[1].commandTpl: template: Ask AI v2:1:11: executing \"Ask AI v2\" at \u003c.Event.Namespace\u003e: can't evaluate field Event in type event.Event","plugin":"botkube/kubernetes","time":"2024-03-11T18:37:36+01:00"}
    {"level":"error","logger":"stderr","msg":"\t* invalid extraButtons[2]: displayName cannot be empty","plugin":"botkube/kubernetes","time":"2024-03-11T18:37:36+01:00"}
    {"level":"error","logger":"stderr","msg":"\t* invalid extraButtons[3]: displayName cannot be empty, unknown trigger.type[\"fatal\"]  \u001b[31mcomponent\u001b[0m=\"Message Builder\"","plugin":"botkube/kubernetes","time":"2024-03-11T18:37:36+01:00"}
  1. Checkout PR

  2. Build plugin: PLUGIN_TARGETS="kubernetes" make build-plugins-single

  3. Start server: make serve-local-plugins

  4. Start Botkube Agent with such configuration:

    Config

    communications:
      default-group:
        socketSlack:
          enabled: true
          channels:
            default:
              name: hakuna-matata
              bindings:
                sources:
                  - k8s-ai-support-err-events
                executors: []
          appToken: "xapp-1-"
          botToken: "xoxb-"
    
    sources:
      'k8s-ai-support-err-events':
        displayName: "K8s AI-powered errors"
        botkube/kubernetes:
          enabled: true
          context:
            defaultNamespace: "default"
            rbac:
              group:
                type: Static
                static:
                  values: [ "botkube-plugins-default" ]
          config:
            # -- Define extra buttons to be displayed beside notification message.
            extraButtons:
              - enabled: true
                trigger:
                  type: [ "ERROR" ]
                button:
                  displayName: "Ask AI"
                  commandTpl: "ai --resource={{ .Namespace }}/{{ .Kind | lower }}/{{ .Name }} --error={{ .Reason }} --bk-cmd-header='AI assistance'"
              - enabled: true
                trigger:
                  type: [ "error" ]
                button:
                  displayName: "Ask AI v2"
                  commandTpl: "ai {{.Event.Namespace}} this one is wrong"
    
              - enabled: true
                trigger:
                  type: [ "error" ]
                button:
                  commandTpl: "ai {{.Event.Namespace}} this one is wrong"
    
              - enabled: true
                trigger:
                  type: [ "fatal" ]
                button:
                  commandTpl: "ai {{.Event.Namespace}} this one is wrong"
    
            namespaces:
              include:
                - ".*"
            event:
              types:
                - error
            resources:
              - type: v1/pods
    
    plugins:
      cacheDir: "/tmp/plugins"
      repositories:
        botkube:
          url: http://localhost:3010/botkube.yaml
    
    settings:
      log:
        level: "info"
        formatter: text
      kubeconfig: "your kubeconfig path"
      clusterName: "labs"
      upgradeNotifier: false
    
    analytics:
      disable: true

You should still get Pods error, if you will try the same on main, it won't get you a notification.

Related issue(s)

Fix #1407

@mszostok mszostok added the bug Something isn't working label Mar 11, 2024
@mszostok mszostok marked this pull request as ready for review March 11, 2024 17:36
@mszostok mszostok requested review from PrasadG193 and a team as code owners March 11, 2024 17:36
@mszostok mszostok requested a review from vaijab March 11, 2024 17:36
Copy link
Collaborator

@vaijab vaijab left a comment

Choose a reason for hiding this comment

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

Nice one!

@mszostok mszostok enabled auto-merge (squash) March 12, 2024 09:22
@mszostok mszostok merged commit c2b90f4 into kubeshop:main Mar 12, 2024
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

K8s source doesn't send alerts when the extra buttons cannot be rendered
2 participants