Skip to content

Commit

Permalink
Merge pull request #142 from idealista/develop
Browse files Browse the repository at this point in the history
Release 2.5.0
  • Loading branch information
miguel-chacon authored Sep 9, 2019
2 parents 7f96e0a + 6b25521 commit c0f4c8a
Show file tree
Hide file tree
Showing 19 changed files with 337 additions and 9 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ This project adheres to [Semantic Versioning](http://semver.org/) and [Keep a ch

## [Unreleased](https://github.com/idealista/prom2teams/tree/develop)

## [2.5.0](https://github.com/idealista/prom2teams/tree/2.5.0)
[Full Changelog](https://github.com/idealista/prom2teams/compare/2.4.0...2.5.0)
## Added
- *[#109](https://github.com/idealista/prom2teams/issues/109) Add Helm chart* @Aaron-ML
## Fixed
- *[#139](https://github.com/idealista/prom2teams/issues/139) Add route for favicon* @miguel-chacon
- *Missing internal errors in flask exporter metrics* @miguel-chacon
## Changed
- *Minor improve Dockerfile* @miguel-chacon

## [2.4.0](https://github.com/idealista/prom2teams/tree/2.4.0)
[Full Changelog](https://github.com/idealista/prom2teams/compare/2.3.3...2.4.0)
## Added
Expand Down
3 changes: 1 addition & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ LABEL maintainer="[email protected]"

EXPOSE 8089

RUN apk add gcc libc-dev linux-headers --update-cache \
&& rm -rf /var/cache/apk/*
RUN apk add gcc libc-dev linux-headers --no-cache

WORKDIR /opt/prom2teams

Expand Down
48 changes: 48 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,54 @@ Prom2teams uses Flask and, to have the service monitored, we use @rycus66's [Pro
- Use the `--enablemetrics` or `-m` flag when launching prom2teams.
- Set the environment variable `PROM2TEAMS_PROMETHEUS_METRICS=true`.

### Helm chart

#### Installing the Chart

To install the chart with the release name `my-release` run:

```bash
$ helm install --name my-release /location/of/prom2teams_ROOT/helm
```

After a few seconds, Prom2Teams should be running.

> **Tip**: List all releases using `helm list`, a release is a name used to track a specific deployment
#### Uninstalling the Chart

To uninstall/delete the `my-release` deployment:

```bash
$ helm delete my-release
```
> **Tip**: Use helm delete --purge my-release to completely remove the release from Helm internal storage
The command removes all the Kubernetes components associated with the chart and deletes the release.

#### Configuration

The following table lists the configurable parameters of the Prom2teams chart and their default values.

| Parameter | Description | Default
| --- | --- | ---
| `image.repository` | The image repository to pull from | `idealista/prom2teams`
| `image.tag` | The image tag to pull | `2.4.0`
| `image.pullPolicy` | The image pull policy | `IfNotPresent`
| `resources.requests.cpu` | CPU requested for being run in a node | `100m`
| `resources.requests.memory` | Memory requested for being run in a node | `128Mi`
| `resources.limits.cpu` | CPU limit | `200m`
| `resources.limits.memory` | Memory limit | `200Mi`
| `service.type` | Service Map (NodePort/ClusterIP) | `ClusterIP`
| `service.port` | Service Port | `8089`
| `prom2teams.host` | IP to bind to | `0.0.0.0`
| `prom2teams.port` | Port to bind to | `8089`
| `prom2teams.connector` | Connector URL | `<empty>`
| `prom2teams.group_alerts_by` | Group_alerts_by field | `<empty>`
| `prom2teams.loglevel` | Loglevel | `INFO`
| `prom2teams.templatepath` | Custom Template path (files/teams.j2) | `/opt/prom2teams/helmconfig/teams.j2`
| `prom2teams.config` | Config (specific to Helm) | `/opt/prom2teams/helmconfig/config.ini`

### Docker image

Every new Prom2teams release, a new Docker image is built in our [Dockerhub](https://hub.docker.com/r/idealista/prom2teams). We strongly recommend you to use the images with the version tag, though it will be possible to use them without it.
Expand Down
22 changes: 22 additions & 0 deletions helm/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
5 changes: 5 additions & 0 deletions helm/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apiVersion: v1
appVersion: "1.0"
description: A Helm chart for Prom2Teams
name: prom2teams
version: 0.1.0
43 changes: 43 additions & 0 deletions helm/files/teams.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{%- set
theme_colors = {
'resolved' : '2DC72D',
'critical' : '8C1A1A',
'severe' : '8C1A1A',
'warning' : 'FF9A0B',
'unknown' : 'CCCCCC'
}
-%}

{
"@type": "MessageCard",
"@context": "http://schema.org/extensions",
"themeColor": "{% if status=='resolved' %} {{ theme_colors.resolved }} {% else %} {{ theme_colors[msg_text.severity] }} {% endif %}",
"summary": "{% if status=='resolved' %}(Resolved) {% endif %}{{ msg_text.summary }}",
"title": "{{ msg_text.name }} {% if status=='resolved' %}(Resolved) {% elif status=='unknown' %} (status unknown) {% endif %}",
"sections": [{
"activityTitle": "{{ msg_text.message }}",
"facts": [{% if msg_text.name %}{
"name": "Alarm",
"value": "{{ msg_text.name }}"
},{% endif %}{% if msg_text.instance %}{
"name": "In host",
"value": "{{ msg_text.instance }}"
},{% endif %}{% if msg_text.severity %}{
"name": "Severity",
"value": "{{ msg_text.severity }}"
},{% endif %}{% if msg_text.runbook_url %}{
"name": "Runbook",
"value": "{{ msg_text.runbook_url }}"
},{% endif %}{% if msg_text.description %}{
"name": "Description",
"value": "{{ msg_text.description }}"
},{% endif %}{
"name": "Status",
"value": "{{ msg_text.status }}"
}{% if msg_text.extra_labels %}{% for key in msg_text.extra_labels %},{
"name": "{{ key }}",
"value": "{{ msg_text.extra_labels[key] }}"
}{% endfor %}{% endif %}],
"markdown": true
}]
}
2 changes: 2 additions & 0 deletions helm/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Prom2Teams has been installed. Check its status by running:
kubectl --namespace {{ .Release.Namespace }} get pods -l "release={{ .Release.Name }}"
45 changes: 45 additions & 0 deletions helm/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{{/* vim: set filetype=mustache: */}}
{{/*
Expand the name of the chart.
*/}}
{{- define "prom2teams.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "prom2teams.fullname" -}}
{{- if .Values.fullnameOverride -}}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- $name := default .Chart.Name .Values.nameOverride -}}
{{- if contains $name .Release.Name -}}
{{- .Release.Name | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{- end -}}
{{- end -}}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "prom2teams.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Common labels
*/}}
{{- define "prom2teams.labels" -}}
app.kubernetes.io/name: {{ include "prom2teams.name" . }}
helm.sh/chart: {{ include "prom2teams.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end -}}
22 changes: 22 additions & 0 deletions helm/templates/configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: prom2teams-config
labels:
app.kubernetes.io/managed-by: {{ .Release.Service }}
app.kubernetes.io/instance: {{ .Release.Name }}
data:
config.ini: |-
[HTTP Server]
Host: {{ .Values.prom2teams.ip }}
Port: {{ .Values.prom2teams.port }}
[Microsoft Teams]
Connector: {{ .Values.prom2teams.connector }}
[Group Alerts]
Field: {{ .Values.prom2teams.group_alerts_by }}
[Log]
Level: {{ .Values.prom2teams.loglevel }}
[Template]
Path: {{ .Values.prom2teams.templatepath }}
#config.ini: {{ .Files.Get "files/config.ini" | quote }}
teams.j2: {{ .Files.Get "files/teams.j2" | quote }}
54 changes: 54 additions & 0 deletions helm/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "prom2teams.fullname" . }}
labels:
{{ include "prom2teams.labels" . | indent 4 }}
spec:
replicas: {{ .Values.replicaCount }}
selector:
matchLabels:
app.kubernetes.io/name: {{ include "prom2teams.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
template:
metadata:
labels:
app.kubernetes.io/name: {{ include "prom2teams.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
volumes:
- name: config
configMap:
name: prom2teams-config
containers:
- name: {{ .Chart.Name }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
ports:
- name: http
containerPort: 8089
protocol: TCP
volumeMounts:
- name: config
mountPath: /opt/prom2teams/helmconfig/
env:
- name: APP_CONFIG_FILE
value: {{ .Values.prom2teams.config }}
resources:
{{- toYaml .Values.resources | nindent 12 }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
16 changes: 16 additions & 0 deletions helm/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
apiVersion: v1
kind: Service
metadata:
name: {{ include "prom2teams.fullname" . }}
labels:
{{ include "prom2teams.labels" . | indent 4 }}
spec:
type: {{ .Values.service.type }}
ports:
- port: {{ .Values.service.port }}
targetPort: 8089
protocol: TCP
name: http
selector:
app.kubernetes.io/name: {{ include "prom2teams.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
16 changes: 16 additions & 0 deletions helm/templates/tests/test-connection.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
apiVersion: v1
kind: Pod
metadata:
name: "{{ include "prom2teams.fullname" . }}-test-connection"
labels:
{{ include "prom2teams.labels" . | indent 4 }}
annotations:
"helm.sh/hook": test-success
"helm.sh/hook-delete-policy": test-success,test-failure
spec:
containers:
- name: wget
image: busybox
command: ['wget']
args: ['{{ include "prom2teams.fullname" . }}:{{ .Values.service.port }}']
restartPolicy: Never
29 changes: 29 additions & 0 deletions helm/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Default values for prom2teams.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.

image:
repository: idealista/prom2teams
tag: 2.4.0
pullPolicy: IfNotPresent

resources:
requests:
cpu: 100m
memory: 128Mi
limits:
cpu: 200m
memory: 200Mi

service:
type: ClusterIP
port: 8089

prom2teams:
host: 0.0.0.0
port: 8089
connector:
group_alerts_by:
loglevel: INFO
templatepath: /opt/prom2teams/helmconfig/teams.j2
config: /opt/prom2teams/helmconfig/config.ini
17 changes: 16 additions & 1 deletion prom2teams/app/api.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import logging.config
import os

from flask import Flask, Blueprint
from flask import Flask, Blueprint, send_from_directory

from prom2teams.app.configuration import config_app, setup_logging
from .versions.v1 import api_v1
Expand All @@ -13,6 +14,19 @@
app = Flask(__name__)



@app.route('/favicon.ico')
def favicon():
return send_from_directory(os.path.join(app.root_path, 'static'),
'favicon.ico', mimetype='image/vnd.microsoft.icon')

def error_handler(e):
msg = 'An unhandled exception occurred. {}'.format(e)
log.exception(msg)
return str(e), e.code



def register_api(application, api, namespace, blueprint):
api.init_app(blueprint)
api.add_namespace(namespace)
Expand All @@ -27,6 +41,7 @@ def init_app(application):
blueprint_v2 = Blueprint('api_v2', __name__, url_prefix=application.config['API_V2_URL_PREFIX'])
register_api(application, api_v1, ns_v1, blueprint_v1)
register_api(application, api_v2, ns_v2, blueprint_v2)
application.register_error_handler(500, error_handler)


init_app(app)
Expand Down
2 changes: 1 addition & 1 deletion prom2teams/app/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def config_app(application):
application.config['TEMPLATE_PATH'] = command_line_args.templatepath
if command_line_args.groupalertsby:
application.config['GROUP_ALERTS_BY'] = command_line_args.groupalertsby
if (command_line_args.enablemetrics or os.environ.get('PROM2TEAMS_PROMETHEUS_METRICS',False)):
if command_line_args.enablemetrics or os.environ.get('PROM2TEAMS_PROMETHEUS_METRICS', False):
from prometheus_flask_exporter import PrometheusMetrics
metrics = PrometheusMetrics(application)

Expand Down
Loading

0 comments on commit c0f4c8a

Please sign in to comment.