---
grafana_services:
  grafana:
    container_name: grafana
    group: grafana
    enabled: true
    image: "{{ grafana_image_full }}"
    volumes: "{{ grafana_default_volumes + grafana_extra_volumes }}"
    dimensions: "{{ grafana_dimensions }}"
    haproxy:
      grafana_server:
        enabled: "{{ enable_grafana }}"
        mode: "http"
        external: false
        port: "{{ grafana_server_port }}"
        listen_port: "{{ grafana_server_listen_port }}"
      grafana_server_external:
        enabled: "{{ enable_grafana_external | bool }}"
        mode: "http"
        external: true
        external_fqdn: "{{ grafana_external_fqdn }}"
        port: "{{ grafana_server_public_port }}"
        listen_port: "{{ grafana_server_listen_port }}"

####################
# Database
####################
grafana_database_name: "grafana"
grafana_database_user: "{% if use_preconfigured_databases | bool and use_common_mariadb_user | bool %}{{ database_user }}{% else %}grafana{% endif %}"
grafana_database_address: "{{ database_address | put_address_in_context('url') }}:{{ database_port }}"

####################
# Database sharding
####################
grafana_database_shard_root_user: "{% if enable_proxysql | bool %}root_shard_{{ grafana_database_shard_id }}{% else %}{{ database_user }}{% endif %}"
grafana_database_shard_id: "{{ mariadb_default_database_shard_id | int }}"
grafana_database_shard:
  users:
    - user: "{{ grafana_database_user }}"
      password: "{{ grafana_database_password }}"
  rules:
    - schema: "{{ grafana_database_name }}"
      shard_id: "{{ grafana_database_shard_id }}"


####################
# Datasource
####################
grafana_data_sources:
  influxdb:
    enabled: "{{ enable_influxdb | bool }}"
    data:
      isDefault: yes
      database: "telegraf"
      name: "telegraf"
      type: "influxdb"
      url: "{{ influxdb_internal_endpoint }}"
      access: "proxy"
      basicAuth: false
  opensearch:
    enabled: "{{ enable_opensearch | bool }}"
    data:
      name: "opensearch"
      type: "grafana-opensearch-datasource"
      access: "proxy"
      url: "{{ opensearch_internal_endpoint }}"
      jsonData:
        flavor: "OpenSearch"
        database: "{{ opensearch_log_index_prefix }}-*"
        version: "2.11.1"
        timeField: "@timestamp"
        logLevelField: "log_level"

##########
# Grafana
##########
grafana_image: "{{ docker_registry ~ '/' if docker_registry else '' }}{{ docker_namespace }}/grafana"
grafana_tag: "{{ openstack_tag }}"
grafana_image_full: "{{ grafana_image }}:{{ grafana_tag }}"
grafana_admin_username: "admin"

grafana_dimensions: "{{ default_container_dimensions }}"
grafana_default_volumes:
  - "{{ node_config_directory }}/grafana/:{{ container_config_directory }}/:ro"
  - "/etc/localtime:/etc/localtime:ro"
  - "{{ '/etc/timezone:/etc/timezone:ro' if ansible_facts.os_family == 'Debian' else '' }}"
  - "kolla_logs:/var/log/kolla/"
grafana_extra_volumes: "{{ default_extra_volumes }}"

grafana_start_first_node_delay: 10
grafana_start_first_node_retries: 12

# TODO(dawudm): make this True in the D release
grafana_remove_old_volume: false

############
# Prometheus
############
grafana_prometheus_url: "{{ internal_protocol }}://{{ kolla_internal_fqdn | put_address_in_context('url') }}:{{ prometheus_port }}"
