From 59146fa6facc7f8477fc1f425b8b426713212774 Mon Sep 17 00:00:00 2001 From: Guoxin Date: Sun, 28 Feb 2021 20:17:25 +0800 Subject: [PATCH] [alert-manager] move pai-bearer-token config field under alert-manager (#5324) --- .../quick-start/services-configuration.yaml.template | 2 +- .../quick-start/services-configuration.yaml.template | 2 +- docs/manual/cluster-admin/how-to-use-alert-system.md | 2 +- .../manual/cluster-admin/how-to-use-alert-system.md | 2 +- .../cluster-configuration/services-configuration.yaml | 2 +- src/alert-manager/config/alert-manager.md | 4 ++-- src/alert-manager/config/alert_manager.py | 9 +++++++-- .../deploy/alert-manager-configmap.yaml.template | 6 +++--- .../deploy/alert-manager-cronjob.yaml.template | 2 +- 9 files changed, 18 insertions(+), 13 deletions(-) diff --git a/contrib/kubespray/quick-start/services-configuration.yaml.template b/contrib/kubespray/quick-start/services-configuration.yaml.template index af53e1c478..9d6d98ee7f 100644 --- a/contrib/kubespray/quick-start/services-configuration.yaml.template +++ b/contrib/kubespray/quick-start/services-configuration.yaml.template @@ -213,10 +213,10 @@ authentication: # if you want to enable alert-handler actions, uncomment following lines and fill the right values. # alert-manager: # port: 9093 # optional, do not modify this if you do not want to change the port alert-manager is listening on +# pai-bearer-token: 'your-application-token-for-pai-rest-server' # alert-handler: # alert-handler will only be enabled when this field is not empty # port: 9095 # optional, do not modify this if you do not want to change the port alert-handler is listening on # log-level: "info" # optional -# pai-bearer-token: 'your-application-token-for-pai-rest-server' # email-configs: # email-notification will only be enabled when this field is not empty # admin-receiver: addr-of-admin-receiver@example.com # smtp-host: smtp.office365.com diff --git a/deployment/quick-start/services-configuration.yaml.template b/deployment/quick-start/services-configuration.yaml.template index e0fa1264f8..6b067a2a81 100644 --- a/deployment/quick-start/services-configuration.yaml.template +++ b/deployment/quick-start/services-configuration.yaml.template @@ -73,10 +73,10 @@ rest-server: # if you want to enable alert-handler actions, uncomment following lines and fill the right values. # alert-manager: # port: 9093 # optional, do not modify this if you do not want to change the port alert-manager is listening on +# pai-bearer-token: 'your-application-token-for-pai-rest-server' # alert-handler: # alert-handler will only be enabled when this field is not empty # port: 9095 # optional, do not modify this if you do not want to change the port alert-handler is listening on # log-level: "info" # optional -# pai-bearer-token: 'your-application-token-for-pai-rest-server' # email-configs: # email-notification will only be enabled when this field is not empty # admin-receiver: addr-of-admin-receiver@example.com # smtp-host: smtp.office365.com diff --git a/docs/manual/cluster-admin/how-to-use-alert-system.md b/docs/manual/cluster-admin/how-to-use-alert-system.md index 209772f995..b5b09323ba 100644 --- a/docs/manual/cluster-admin/how-to-use-alert-system.md +++ b/docs/manual/cluster-admin/how-to-use-alert-system.md @@ -77,9 +77,9 @@ The alert actions and the matching rules are realized in the `alert-manager` ser ```yaml alert-manager: port: 9093 # optional, do not change this if you do not want to change the port alert-manager is listening on + pai-bearer-token: 'your-application-token-for-pai-rest-server' alert-handler: port: 9095 # optional, do not change this if you do not want to change the port alert-handler is listening on - pai-bearer-token: 'your-application-token-for-pai-rest-server' email-configs: # email-notification will only be enabled when this field is not empty admin-receiver: addr-of-admin-receiver@example.com smtp-host: smtp.office365.com diff --git a/docs_zh_CN/manual/cluster-admin/how-to-use-alert-system.md b/docs_zh_CN/manual/cluster-admin/how-to-use-alert-system.md index 33d6301613..ddac284d45 100644 --- a/docs_zh_CN/manual/cluster-admin/how-to-use-alert-system.md +++ b/docs_zh_CN/manual/cluster-admin/how-to-use-alert-system.md @@ -74,9 +74,9 @@ prometheus: ```yaml alert-manager: port: 9093 + pai-bearer-token: 'your-application-token-for-pai-rest-server' alert-handler: port: 9095 - pai-bearer-token: 'your-application-token-for-pai-rest-server' email-configs: admin-receiver: addr-of-admin-receiver@example.com smtp-host: smtp.office365.com diff --git a/examples/cluster-configuration/services-configuration.yaml b/examples/cluster-configuration/services-configuration.yaml index f8794af177..66ace0af3c 100644 --- a/examples/cluster-configuration/services-configuration.yaml +++ b/examples/cluster-configuration/services-configuration.yaml @@ -106,10 +106,10 @@ rest-server: # if you want to enable alert-handler actions, uncomment following lines and fill the right values. # alert-manager: # port: 9093 # optional, do not modify this if you do not want to change the port alert-manager is listening on +# pai-bearer-token: 'your-application-token-for-pai-rest-server' # alert-handler: # alert-handler will only be enabled when this field is not empty # port: 9095 # optional, do not modify this if you do not want to change the port alert-handler is listening on # log-level: "info" # optional -# pai-bearer-token: 'your-application-token-for-pai-rest-server' # email-configs: # email-notification will only be enabled when this field is not empty # admin-receiver: addr-of-admin-receiver@example.com # smtp-host: smtp.office365.com diff --git a/src/alert-manager/config/alert-manager.md b/src/alert-manager/config/alert-manager.md index 56c5b3c670..39f2c69ab2 100644 --- a/src/alert-manager/config/alert-manager.md +++ b/src/alert-manager/config/alert-manager.md @@ -17,9 +17,9 @@ you should configure `alert-manager` in your `service-configuration.yaml` like f ``` yaml alert-manager: port: 9093 # optional, do not change this if you do not want to change the port alert-manager is listening on + pai-bearer-token: 'your-application-token-for-pai-rest-server' alert-handler: # alert-handler will only be enabled when this field is not empty port: 9095 # optional, do not change this if you do not want to change the port alert-handler is listening on - pai-bearer-token: 'your-application-token-for-pai-rest-server' email-configs: # email-notification will only be enabled when this field is not empty admin-receiver: addr-of-admin-receiver@example.com smtp-host: smtp.office365.com @@ -54,6 +54,7 @@ After parsing, if you properly configured `email-configs` and `pai-bearer-token` ``` yaml alert-manager: port: 9093 + pai-bearer-token: 'your-application-token-for-pai-rest-server' actions-available: - webportal-notification - cordon-nodes @@ -65,7 +66,6 @@ alert-manager: log-level: info port: 9095 configured: True - pai-bearer-token: 'your-application-token-for-pai-rest-server' email-configs: # email-notification will only be enabled when this field is not empty admin-receiver: addr-of-admin-receiver@example.com smtp-host: smtp.office365.com diff --git a/src/alert-manager/config/alert_manager.py b/src/alert-manager/config/alert_manager.py index 86de832be2..6b33c15435 100644 --- a/src/alert-manager/config/alert_manager.py +++ b/src/alert-manager/config/alert_manager.py @@ -64,8 +64,12 @@ def run(self): result["alert-handler"]["email-configs"]["templates"] = self.get_email_templates() # check if `pai-bearer-token` is properly configured - if result.get("alert-handler") is not None and \ + if result.get("pai-bearer-token") is not None: + token_configured = True + # legacy: to be compatible with pai version <= v1.5 + elif result.get("alert-handler") is not None and \ result["alert-handler"].get("pai-bearer-token") is not None: + result["pai-bearer-token"] = result["alert-handler"]["pai-bearer-token"] token_configured = True else: token_configured = False @@ -83,7 +87,8 @@ def run(self): result["alert-handler"]["configured"] = False if result.get("cluster-utilization") is not None and \ - result["cluster-utilization"].get("schedule") is not None: + result["cluster-utilization"].get("schedule") is not None and \ + token_configured: result["cluster-utilization"]["configured"] = True else: result["cluster-utilization"]["configured"] = False diff --git a/src/alert-manager/deploy/alert-manager-configmap.yaml.template b/src/alert-manager/deploy/alert-manager-configmap.yaml.template index 63320548b1..0169673ba5 100644 --- a/src/alert-manager/deploy/alert-manager-configmap.yaml.template +++ b/src/alert-manager/deploy/alert-manager-configmap.yaml.template @@ -99,14 +99,14 @@ data: - url: 'http://localhost:{{ cluster_cfg["alert-manager"]["alert-handler"]["port"] }}/alert-handler/send-email-to-user/?template={{ template }}' send_resolved: false http_config: - bearer_token: {{ cluster_cfg["alert-manager"]["alert-handler"]["pai-bearer-token"] }} + bearer_token: {{ cluster_cfg["alert-manager"]["pai-bearer-token"] }} {% endif %} {% if (receiver["actions"]["stop-jobs"] is defined) and ('stop-jobs' in cluster_cfg["alert-manager"]["actions-available"]) %} - url: 'http://localhost:{{ cluster_cfg["alert-manager"]["alert-handler"]["port"] }}/alert-handler/stop-jobs' send_resolved: false http_config: - bearer_token: {{ cluster_cfg["alert-manager"]["alert-handler"]["pai-bearer-token"] }} + bearer_token: {{ cluster_cfg["alert-manager"]["pai-bearer-token"] }} {% endif %} {% if (receiver["actions"]["tag-jobs"] is defined) and ('tag-jobs' in cluster_cfg["alert-manager"]["actions-available"]) %} @@ -114,7 +114,7 @@ data: - url: 'http://localhost:{{ cluster_cfg["alert-manager"]["alert-handler"]["port"] }}/alert-handler/tag-jobs/{{ tag }}' send_resolved: false http_config: - bearer_token: {{ cluster_cfg["alert-manager"]["alert-handler"]["pai-bearer-token"] }} + bearer_token: {{ cluster_cfg["alert-manager"]["pai-bearer-token"] }} {% endfor %} {% endif %} diff --git a/src/alert-manager/deploy/alert-manager-cronjob.yaml.template b/src/alert-manager/deploy/alert-manager-cronjob.yaml.template index 3eafea1594..dfce1709a5 100644 --- a/src/alert-manager/deploy/alert-manager-cronjob.yaml.template +++ b/src/alert-manager/deploy/alert-manager-cronjob.yaml.template @@ -38,7 +38,7 @@ spec: value: "{{ cluster_cfg['pylon']['uri']}}" {%- endif %} - name: PAI_BEARER_TOKEN - value: {{ cluster_cfg["alert-manager"]["alert-handler"]["pai-bearer-token"] }} + value: {{ cluster_cfg["alert-manager"]["pai-bearer-token"] }} - name: PROMETHEUS_SCRAPE_INTERVAL value: "{{ cluster_cfg["prometheus"]["scrape_interval"] }}" imagePullSecrets: