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

Prometheus source plugin #942

Merged
merged 13 commits into from
Jan 19, 2023

Conversation

huseyinbabal
Copy link
Contributor

@huseyinbabal huseyinbabal commented Jan 16, 2023

Description

Changes proposed in this pull request:

  • prometheus source plugin is added.

Test

Checkout branch

gh pr checkout 942

Build plugins

make build-plugins

Generate plugin index

PLUGIN_DOWNLOAD_URL_BASE_PATH=http://localhost:8080/dist make gen-plugins-index

Run local plugin repository

npx serve --listen 8080

Install Prometheus stack in k8s

helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo update
helm install prom prometheus-community/kube-prometheus-stack

Export prometheus endpoint

kubectl port-forward prometheus-botkube-kube-prometheus-st-prometheus-0 9090

Prepare botkube config

## /tmp/botkubecfg.yaml
communications:
  'default-group':
    # Settings for Slack
    socketSlack:
      enabled: true
      appToken: "xapp...."
      botToken: "xoxb..."
      notification:
        type: "long" # TODO: Change to `short` during testing
      channels:
        'default':
          name: botkube-demo
          bindings:
            sources:
              - plugin-based

settings:
  clusterName: gke-playground
  configWatcher: true
  lifecycleServer:
    deployment:
      name: botkube
      namespace: botkube
    port: "2113"

configWatcher:
  enabled: false
  initialSyncTimeout: 0

sources:
  'plugin-based':
    botkube/prometheus:
      enabled: true
      config:
        url: http://localhost:9090
        ignoreOldAlerts: false
        alertStates: ["pending"]

plugins:
  repositories:
    botkube:
      url: http://localhost:8080/plugins-index.yaml

Run botkube

export BOTKUBE_CONFIG_PATHS="./helm/botkube/values.yaml,/tmp/botkubecfg.yaml"
export BOTKUBE_SETTINGS_KUBECONFIG="/path/to/.kube/config"

go run cmd/botkube/main.go

Deploy problematic nginx

kubectl run nginx --image nginx:1.23_err -n default

Related issue(s)

#849

@huseyinbabal huseyinbabal marked this pull request as ready for review January 17, 2023 16:09
@huseyinbabal huseyinbabal requested review from a team and PrasadG193 as code owners January 17, 2023 16:09
@mszostok mszostok self-assigned this Jan 17, 2023
@mszostok mszostok added the enhancement New feature or request label Jan 17, 2023
internal/source/prometheus/client.go Outdated Show resolved Hide resolved
internal/source/prometheus/client.go Outdated Show resolved Hide resolved
internal/source/prometheus/client.go Outdated Show resolved Hide resolved
internal/source/prometheus/client.go Outdated Show resolved Hide resolved
internal/source/prometheus/config.go Show resolved Hide resolved
internal/source/prometheus/source.go Show resolved Hide resolved
internal/source/prometheus/source.go Outdated Show resolved Hide resolved
internal/source/prometheus/source.go Outdated Show resolved Hide resolved
internal/source/prometheus/source.go Outdated Show resolved Hide resolved
internal/source/prometheus/source.go Outdated Show resolved Hide resolved
@huseyinbabal
Copy link
Contributor Author

@mszostok addressed all of your suggestions except this one, let me know what you think about that. Thanks :)

Copy link
Contributor

@mszostok mszostok left a comment

Choose a reason for hiding this comment

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

LGTM 🚀

return api.JSONSchema{
Value: heredoc.Docf(`{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "botkube/prometheus",
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
"title": "botkube/prometheus",
"title": "Prometheus",

the repository name can be change in different part of the configuration, so I would not put that here.

log := loggerx.New(loggerx.Config{
Level: config.Log.Level,
})
prometheus, err := p.getPrometheusClient(config.URL)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit

we can move it to Stream method, same as you did with MergeConfigs, so you will return an error there

	prometheus, err := p.getPrometheusClient(config.URL)
	if err != nil {
		return source.StreamOutput{}, fmt.Errorf("while creating Prometheus client: %w", err)
	}

or move that into for loop, and just do the log.Errorf only, so client creation will be "retried" in case of error.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok I kept it in consumeAlerts function, and removed mutex

@huseyinbabal huseyinbabal merged commit b950d81 into kubeshop:main Jan 19, 2023
@huseyinbabal huseyinbabal deleted the prometheus-plugin-poc branch January 19, 2023 11:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants