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

Commit

Permalink
support external url in alerting email (#1955)
Browse files Browse the repository at this point in the history
  • Loading branch information
xudifsd authored Jan 8, 2019
1 parent 597b88d commit 9bfdbb9
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 10 deletions.
4 changes: 4 additions & 0 deletions src/alert-manager/config/alert-manager.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ alert-manager:
port: 9093 # this is optional, you should not write this if you do not want to change the port alert-manager is listening on
```
In addition, if you deployed pai behind firewall, you should configure alert-manager with `use-pylon: True`, to make url from alert email public available.

#### Generated Configuration <a name="G_Config"></a>

After parsing, if you configured the alert-manager the model will be like:
Expand All @@ -37,6 +39,7 @@ alert-manager:
configured: True
host: master_ip
url: "http://master_ip:9093"
use-pylon: False
```

if you didn't configured alert-manager, it will be like:
Expand All @@ -46,4 +49,5 @@ alert-manager:
configured: False
host: master_ip
url: "http://master_ip:9093"
use-pylon: False
```
1 change: 1 addition & 0 deletions src/alert-manager/config/alert-manager.yaml
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
port: 9093
use-pylon: False
10 changes: 9 additions & 1 deletion src/alert-manager/deploy/alert-manager.yaml.template
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

{% if cluster_cfg["alert-manager"]["configured"] %}

{% if cluster_cfg["alert-manager"]["use-pylon"] %}
{% set external_url = cluster_cfg["pylon"]["uri"] %}
{% else %}
{% set external_url = cluster_cfg["alert-manager"]["url"] %}
{% endif %}

apiVersion: apps/v1
kind: Deployment
metadata:
Expand All @@ -38,7 +45,8 @@ spec:
args:
- '--config.file=/etc/alertmanager/config.yml'
- '--storage.path=/alertmanager'
- '--web.external-url={{ cluster_cfg["alert-manager"]["url"] }}'
- '--web.external-url={{ external_url }}/alert-manager/'
- '--web.route-prefix=alert-manager'
ports:
- name: alertmanager
containerPort: {{ cluster_cfg["alert-manager"]["port"] }}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name":"PM",
"type":"prometheus",
"url":"{{ cluster_cfg['prometheus']['url'] }}",
"url":"{{ cluster_cfg['prometheus']['url'] }}/prometheus",
"access":"direct",
"basicAuth":false,
"isDefault":true
Expand Down
3 changes: 2 additions & 1 deletion src/prometheus/deploy/prometheus-configmap.yaml.template
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ data:
{% if has_alert_manager %}
alerting:
alertmanagers:
- static_configs:
- path_prefix: alert-manager
static_configs:
- targets:
- {{ cluster_cfg["alert-manager"]["host"] }}:{{ alert_manager_port }}
{% endif %}
10 changes: 8 additions & 2 deletions src/prometheus/deploy/prometheus-deployment.yaml.template
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,14 @@
# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

{% set prometheus_url = cluster_cfg["prometheus"]["url"] %}
{% set prometheus_port = cluster_cfg["prometheus"]["port"] %}

{% if cluster_cfg["alert-manager"]["use-pylon"] %}
{% set external_url = cluster_cfg["pylon"]["uri"] %}
{% else %}
{% set external_url = cluster_cfg["prometheus"]["url"] %}
{% endif %}

apiVersion: apps/v1
kind: Deployment
metadata:
Expand Down Expand Up @@ -47,7 +52,8 @@ spec:
args:
- '--config.file=/etc/prometheus/prometheus.yml'
- '--web.listen-address=0.0.0.0:{{prometheus_port}}'
- '--web.external-url={{prometheus_url}}'
- '--web.external-url={{ external_url }}/prometheus/'
- '--web.route-prefix=prometheus'
ports:
- name: web
containerPort: {{prometheus_port}}
Expand Down
3 changes: 2 additions & 1 deletion src/pylon/config/pylon.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def validation_post(self, cluster_object_model):
('kubernetes', 'api-servers-url'),
('hadoop-name-node', 'master-ip'),
('prometheus', 'url'),
('alert-manager', 'url'),
('kubernetes', 'dashboard-host'),
('hadoop-resource-manager', 'master-ip'),
('grafana', 'url'),
Expand All @@ -59,4 +60,4 @@ def validation_post(self, cluster_object_model):
if service not in cluster_object_model or config not in cluster_object_model[service]:
return False, '{0}.{1} is required'.format(service, config)

return True, None
return True, None
2 changes: 2 additions & 0 deletions src/pylon/deploy/pylon.yaml.template
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ spec:
{% endif %}
- name: PROMETHEUS_URI
value: {{ cluster_cfg['prometheus']['url'] }}
- name: ALERT_MANGER_URI
value: {{ cluster_cfg['alert-manager']['url'] }}
- name: K8S_DASHBOARD_URI
value: http://{{ cluster_cfg['kubernetes']['dashboard-host'] }}:9090
- name: YARN_WEB_PORTAL_URI
Expand Down
13 changes: 9 additions & 4 deletions src/pylon/src/nginx.conf.template
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,13 @@ http {
}

# Prometheus API server.
location ~ ^/prometheus/api(.*)$ {
proxy_pass {{PROMETHEUS_URI}}/api$1$is_args$args;
location ~ ^/prometheus(.*)$ {
proxy_pass {{PROMETHEUS_URI}}/prometheus$1$is_args$args;
}

# alert-manager server.
location ~ ^/alert-manager(.*)$ {
proxy_pass {{ALERT_MANGER_URI}}/alert-manager$1$is_args$args;
}

#
Expand Down Expand Up @@ -264,7 +269,7 @@ http {
'<base href="/" />'
'<base href="$scheme://$http_host/grafana/" />';
sub_filter
'{{PROMETHEUS_URI}}'
'{{PROMETHEUS_URI}}/prometheus'
'$scheme://$http_host/prometheus';
sub_filter
'{{GRAFANA_URI}}'
Expand Down Expand Up @@ -298,7 +303,7 @@ http {
'{{K8S_API_SERVER_URI}}'
'/kubernetes';
sub_filter
'{{PROMETHEUS_URI}}'
'{{PROMETHEUS_URI}}/prometheus'
'/prometheus';
sub_filter
'{{YARN_WEB_PORTAL_URI}}'
Expand Down

0 comments on commit 9bfdbb9

Please sign in to comment.