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(vm-alert): add notifier config support #572

Closed
wants to merge 6 commits into from

Conversation

hakuno
Copy link

@hakuno hakuno commented Jul 6, 2023

Notifier also supports configuration via file specified with flag -notifier.config.

But, no way to do that in current Helm chart.

So, how could I place discover notifiers?

*** EDIT ***

I see it can be better with config and configPath.

  • config: we can set the config with a map like the alert rules;
  • configPath: or we can set a file path from a volume mount if desired.

Scenarios

Scenario 1 with server.notifier.config

helm template --dry-run --validate . -f custom-config.yaml
server:
  notifier:
    config:
      dns_sd_configs:
        - names:
            - alertmanager-headless.ns.svc.cluster.local
          type: 'A'
          port: 9093
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: release-name-victoria-metrics-alert-server-notifier-config
  namespace: prometheus
  labels:
    app: server
    app.kubernetes.io/name: victoria-metrics-alert
    app.kubernetes.io/instance: release-name
    helm.sh/chart: victoria-metrics-alert-0.6.4
    app.kubernetes.io/managed-by: Helm
data:
  notifier.yaml: |
    dns_sd_configs:
    - names:
      - alertmanager-headless.ns.svc.cluster.local
      port: 9093
      type: A

---
    ...
    spec:
      containers:
        - name: victoria-metrics-alert-server
          image: "victoriametrics/vmalert:v1.91.3"
          args:
            - -rule=/config/alert-rules.yaml
            - -datasource.url=http://localhost
            - -notifier.config=/config/notifier.yaml
            - -remoteRead.url=
            - -remoteWrite.url=
            - -envflag.enable=true
            - -envflag.prefix=VM_
            - -loggerFormat=json
          volumeMounts:
            - name: alerts-config
              mountPath: /config
      volumes:
        - name: alerts-config
          projected:
            sources:
              - configMap:
                  name: release-name-victoria-metrics-alert-server-alert-rules-config
              - configMap:
                  name: release-name-victoria-metrics-alert-server-notifier-config

Scenario #2 with server.notifier.configPath

helm template --dry-run --validate . -f custom-configpath.yaml
server:
  notifier:
    configPath: "/custom-path/random.yaml"
---
    ...
    spec:
      containers:
        - name: victoria-metrics-alert-server
          image: "victoriametrics/vmalert:v1.91.3"
          args:
            - -rule=/config/alert-rules.yaml
            - -datasource.url=http://localhost
            - -notifier.config=/custom-path/random.yaml
            - -remoteRead.url=
            - -remoteWrite.url=
            - -envflag.enable=true
            - -envflag.prefix=VM_
            - -loggerFormat=json

Please, check it out.

@hakuno
Copy link
Author

hakuno commented Jul 6, 2023

Also relates to #468

@hakuno
Copy link
Author

hakuno commented Jul 6, 2023

The Alertmanager in HA mode has a headless service. So the DNS discover could account that. Is it?

dns_sd_configs:
  - names:
      - alertmanager-headless.ns.svc.cluster.local
    type: 'A'
    port: 9093

@hagen1778 hagen1778 requested review from Amper and Haleygo July 6, 2023 09:40
Haleygo
Haleygo previously approved these changes Jul 10, 2023
Copy link
Contributor

@Haleygo Haleygo left a comment

Choose a reason for hiding this comment

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

Thanks!
/LGTM
cc @f41gh7

@hakuno
Copy link
Author

hakuno commented Jul 11, 2023

@Haleygo I made a big improvement. Please, can you review again? I see it can be better. I'll update the PR description.

@@ -119,7 +119,8 @@ server:
token: ""
# -- Token Auth file with Bearer token. You can use one of token or tokenFile
tokenFile: ""
config: ""
config: {}
configPath: ""
Copy link
Contributor

Choose a reason for hiding this comment

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

I assume the configPath will use configmap mostly, maybe we can change it to "configMap", use cm when specified or create cm when config is using, and mount it like "alerts-config" here.

# vmalert alert rules configuration configuration:
# use existing configmap if specified
# otherwise .config values will be used
configMap: ""
config:
alerts:

{{- define "vmalert.server.configname" -}}
{{- if .Values.server.configMap -}}
{{- .Values.server.configMap -}}
{{- else -}}
{{- include "vmalert.server.fullname" . -}}-alert-rules-config
{{- end -}}
{{- end -}}

volumes:
- name: alerts-config
configMap:
name: {{ include "vmalert.server.configname" . }}

WDYT?

Copy link
Author

Choose a reason for hiding this comment

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

@Haleygo Okay. Also I added support for secret.

| server.notifier | object | `{"alertmanager":{"basicAuth":{"password":"","username":""},"bearer":{"token":"","tokenFile":""},"url":""},"config":""}` | Notifier to use for alerts. Multiple notifiers can be enabled by using `notifiers` section |
| server.notifier.config | object | `""` | Path to configuration file for notifiers |
| server.notifier | object | `{"alertmanager":{"basicAuth":{"password":"","username":""},"bearer":{"token":"","tokenFile":""},"url":""},"config":{},"configPath":""}` | Notifier to use for alerts. Multiple notifiers can be enabled by using `notifiers` section |
| server.notifier.config | object | `{}` | Path to configuration file for notifiers |
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you update the comment here?

Copy link
Author

Choose a reason for hiding this comment

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

Changed. Please, give a look at.

@hakuno
Copy link
Author

hakuno commented Jul 11, 2023

I made changes. Now it can support 3 ways:

  1. Set the config on values;
  2. Set a config map (with custom key name if desired);
  3. Set a secret (with custom key name if desired);

The default values are:

...
notifier:
    config: {}
    configMap: ""
    configMapKey: "notifier.yaml"
    existingSecret: ""
    existingSecretKey: "notifier.yaml"

The existingSecret has precedence over configMap; the configMap has precedence over config; the config has precedence over url list.

@hakuno hakuno requested a review from Haleygo July 11, 2023 18:23
@Haleygo
Copy link
Contributor

Haleygo commented Jul 12, 2023

I made changes. Now it can support 3 ways:

  1. Set the config on values;
  2. Set a config map (with custom key name if desired);
  3. Set a secret (with custom key name if desired);

The default values are:

...
notifier:
    config: {}
    configMap: ""
    configMapKey: "notifier.yaml"
    existingSecret: ""
    existingSecretKey: "notifier.yaml"

The existingSecret has precedence over configMap; the configMap has precedence over config; the config has precedence over url list.

Oh, so there will be secret using cases. But adding another two secret fileds and the precedences looks overdone to me, maybe we should just come back to the simple configpath and let user mount file however they like.
Any suggestion here) @f41gh7 @Amper

@hakuno
Copy link
Author

hakuno commented Jul 12, 2023 via email

@f41gh7
Copy link
Collaborator

f41gh7 commented Jul 13, 2023

I made changes. Now it can support 3 ways:

  1. Set the config on values;
  2. Set a config map (with custom key name if desired);
  3. Set a secret (with custom key name if desired);

The default values are:

...
notifier:
    config: {}
    configMap: ""
    configMapKey: "notifier.yaml"
    existingSecret: ""
    existingSecretKey: "notifier.yaml"

The existingSecret has precedence over configMap; the configMap has precedence over config; the config has precedence over url list.

Oh, so there will be secret using cases. But adding another two secret fileds and the precedences looks overdone to me, maybe we should just come back to the simple configpath and let user mount file however they like. Any suggestion here) @f41gh7 @Amper

Agreed, I can propose a simple solution:
allow adding configuration only from external secret.

Such secret can be defined at values or externally

# values.yaml
# -- Add extra specs dynamically to this chart
extraObjects:
- kind: Secret
  metadata:
     name: notifier-configuration
  stringData:
    notifier_config.yaml |
     some-config

usage

server:
  notifier:
     config:
       secretName: notifier-configuration
       secretKey: notifier_config.yaml

Note, notifier config could be used with notifiers defined at server.notifiers[] section.

@hakuno
Copy link
Author

hakuno commented Jul 13, 2023

Note, notifier config could be used with notifiers defined at server.notifiers[] section.

@f41gh7 The docs don't explain it.

The docs show that urls can be appended to notifier.url.

So, also does config support? Like below

-notifier.config=/config/first.yaml,/config/second.yaml,/config/third.yaml

or

-notifier.config=/config/first.yaml,/config/notifier.yaml
-notifier.config=/config/first.yaml,/config/other_notifier.yaml

Please, let me know.

@Haleygo
Copy link
Contributor

Haleygo commented Jul 18, 2023

Note, notifier config could be used with notifiers defined at server.notifiers[] section.

I suppose @f41gh7 means that what we do here for .server.notifier should also be available for .server.notifiers
https://github.com/VictoriaMetrics/helm-charts/blob/master/charts/victoria-metrics-alert/values.yaml#L136-146

So, also does config support? Like below
-notifier.config=/config/first.yaml,/config/second.yaml,/config/third.yaml

No, notifier.config is only support one file.

@tenmozes
Copy link
Collaborator

@Haleygo @zekker6 could you plaese take a look and accept(or not) this PR, if this requires any follow up please cover it, thank you

@hakuno
Copy link
Author

hakuno commented Oct 18, 2023

Hey, friends!
I've noticed it got extraObjects already. I'm unable to look at notifier.config right now... So I'll close this.

Thanks in advance!

@hakuno hakuno closed this Oct 18, 2023
@Haleygo
Copy link
Contributor

Haleygo commented Nov 24, 2023

I've noticed it got extraObjects already.

Yeah, thanks for the work!
Now, users who want to use -notifier.config can use extraVolumes mount configmap or secret.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants