Skip to content
This repository has been archived by the owner on Jun 6, 2024. It is now read-only.

Commit

Permalink
[alert-manager] move pai-bearer-token config field under alert-manager (
Browse files Browse the repository at this point in the history
  • Loading branch information
suiguoxin authored Feb 28, 2021
1 parent ba3aa5b commit 59146fa
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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: [email protected]
# smtp-host: smtp.office365.com
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: [email protected]
# smtp-host: smtp.office365.com
Expand Down
2 changes: 1 addition & 1 deletion docs/manual/cluster-admin/how-to-use-alert-system.md
Original file line number Diff line number Diff line change
Expand Up @@ -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: [email protected]
smtp-host: smtp.office365.com
Expand Down
2 changes: 1 addition & 1 deletion docs_zh_CN/manual/cluster-admin/how-to-use-alert-system.md
Original file line number Diff line number Diff line change
Expand Up @@ -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: [email protected]
smtp-host: smtp.office365.com
Expand Down
2 changes: 1 addition & 1 deletion examples/cluster-configuration/services-configuration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: [email protected]
# smtp-host: smtp.office365.com
Expand Down
4 changes: 2 additions & 2 deletions src/alert-manager/config/alert-manager.md
Original file line number Diff line number Diff line change
Expand Up @@ -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: [email protected]
smtp-host: smtp.office365.com
Expand Down Expand Up @@ -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
Expand All @@ -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: [email protected]
smtp-host: smtp.office365.com
Expand Down
9 changes: 7 additions & 2 deletions src/alert-manager/config/alert_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,22 +99,22 @@ 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"]) %}
{% for tag in receiver["actions"]["tag-jobs"]["tags"] %}
- 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 %}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 59146fa

Please sign in to comment.