Skip to content

Commit

Permalink
cluster_zone and grafana annotations custom tags
Browse files Browse the repository at this point in the history
  • Loading branch information
arikalon1 committed Oct 26, 2021
1 parent 7313375 commit c4e91fd
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
3 changes: 3 additions & 0 deletions helm/robusta/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ global_config:
{{- end }}
{{- end }}
cluster_name: {{ required "A valid .Values.clusterName entry is required!" .Values.clusterName }}
{{- if .Values.clusterZone }}
cluster_zone: {{ .Values.clusterZone }}
{{- end }}
active_playbooks:
{{ toYaml .Values.playbooks | indent 2 }}
{{ end }}
1 change: 1 addition & 0 deletions helm/robusta/values.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# global parameters
clusterName: ""
clusterZone: ""

# slack integration params
slackApiKey: ""
Expand Down
14 changes: 11 additions & 3 deletions playbooks/grafana_enrichment.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@
from robusta.api import *


class Params(BaseModel):
class GrafanaAnnotationsParams(BaseModel):
grafana_url: str = None
grafana_api_key: SecretStr
grafana_dashboard_uid: str
cluster_name: str
cluster_zone: str = None
custom_tags: List[str] = None


@on_deployment_update
def add_deployment_lines_to_grafana(event: DeploymentEvent, action_params: Params):
def add_deployment_lines_to_grafana(event: DeploymentEvent, action_params: GrafanaAnnotationsParams):
"""
Add annotations to grafana whenever a new application version is deployed so that you can easily see changes in performance.
"""
Expand All @@ -31,9 +33,15 @@ def add_deployment_lines_to_grafana(event: DeploymentEvent, action_params: Param
grafana = Grafana(
action_params.grafana_api_key.get_secret_value(), action_params.grafana_url
)
tags = [event.obj.metadata.name, event.obj.metadata.namespace, action_params.cluster_name]
if action_params.cluster_zone:
tags.append(action_params.cluster_zone)
if action_params.custom_tags:
tags.extend(action_params.custom_tags)

grafana.add_line_to_dashboard(
action_params.grafana_dashboard_uid, msg,
tags=[event.obj.metadata.name, event.obj.metadata.namespace, action_params.cluster_name]
tags=tags
)


Expand Down

0 comments on commit c4e91fd

Please sign in to comment.