Правила тестирования AlertManager FAILED: yaml: unmarshal errors: строка 1: группы полей не найдены в типе main.unitTestFile

пожалуйста, помогите, я получил сообщение об ошибке при тестировании диспетчера предупреждений ниже

 promtool check rules /etc/prometheus/alert.rules.yml
 Checking /etc/prometheus/alert.rules.yml
 SUCCESS: 3 rules found

 promtool test rules /etc/prometheus/alert.rules.yml
 Unit Testing:  /etc/prometheus/alert.rules.yml
 FAILED:
 yaml: unmarshal errors:
 line 1: field groups not found in type main.unitTestFile

моя alert.rules конфигурация, как показано ниже:

      cat /etc/prometheus/alert.rules.yml
      groups:
      - alert: MemoryFree10%
        expr: node_exporter:node_memory_free:memory_used_percents >= 90
        for: 5m
        labels:
          severity: critical
        annotations:
          summary: "Instance {{ $labels.instance }} hight memory usage"
          description: "{{ $labels.instance }} has more than 90% of its memory used."
      - alert: DiskSpace10%Free
        expr: node_exporter:node_filesystem_free:fs_used_percents >= 90
        labels:
          severity: moderate
        annotations:
          summary: "Instance {{ $labels.instance }} is low on disk space"
          description: "{{ $labels.instance }} has only {{ $value }}% free."
      - alert: ExporterDown
        expr: up == 0
        for: 5m
        labels:
          severity: warning
        annotations:
          summary: "Exporter down (instance {{ $labels.instance }})"
          description: "Prometheus exporter down\n  VALUE = {{ $value }}\n  LABELS: {{ $labels }}"

Есть ли какие-то отсутствующие или неправильные правила оповещения о файлах?

пожалуйста помоги?

Спасибо


person Fajar Hadiyanto    schedule 22.09.2019    source источник


Ответы (3)


Вы запускаете модульный тест для файла правил предупреждений. Вы должны сначала написать тестовый файл, а затем запустить модульный тест для тестового файла с помощью promtool test rules test.yml.

Вот демонстрация из https://prometheus.io/docs/prometheus/latest/configuration/unit_testing_rules/

alerts.yml

# This is the rules file.

groups:
- name: example
  rules:

  - alert: InstanceDown
    expr: up == 0
    for: 5m
    labels:
        severity: page
    annotations:
        summary: "Instance {{ $labels.instance }} down"
        description: "{{ $labels.instance }} of job {{ $labels.job }} has been down for more than 5 minutes."

  - alert: AnotherInstanceDown
    expr: up == 0
    for: 10m
    labels:
        severity: page
    annotations:
        summary: "Instance {{ $labels.instance }} down"
        description: "{{ $labels.instance }} of job {{ $labels.job }} has been down for more than 5 minutes."

test.yml

# This is the main input for unit testing.
# Only this file is passed as command line argument.

rule_files:
    - alerts.yml

evaluation_interval: 1m

tests:
    # Test 1.
    - interval: 1m
      # Series data.
      input_series:
          - series: 'up{job="prometheus", instance="localhost:9090"}'
            values: '0 0 0 0 0 0 0 0 0 0 0 0 0 0 0'
          - series: 'up{job="node_exporter", instance="localhost:9100"}'
            values: '1+0x6 0 0 0 0 0 0 0 0' # 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0
          - series: 'go_goroutines{job="prometheus", instance="localhost:9090"}'
            values: '10+10x2 30+20x5' # 10 20 30 30 50 70 90 110 130
          - series: 'go_goroutines{job="node_exporter", instance="localhost:9100"}'
            values: '10+10x7 10+30x4' # 10 20 30 40 50 60 70 80 10 40 70 100 130

      # Unit test for alerting rules.
      alert_rule_test:
          # Unit test 1.
          - eval_time: 10m
            alertname: InstanceDown
            exp_alerts:
                # Alert 1.
                - exp_labels:
                      severity: page
                      instance: localhost:9090
                      job: prometheus
                  exp_annotations:
                      summary: "Instance localhost:9090 down"
                      description: "localhost:9090 of job prometheus has been down for more than 5 minutes."
      # Unit tests for promql expressions.
      promql_expr_test:
          # Unit test 1.
          - expr: go_goroutines > 5
            eval_time: 4m
            exp_samples:
                # Sample 1.
                - labels: 'go_goroutines{job="prometheus",instance="localhost:9090"}'
                  value: 50
                # Sample 2.
                - labels: 'go_goroutines{job="node_exporter",instance="localhost:9100"}'
                  value: 50

Затем вы можете запустить promtool test rules test.yml, вы получите результат вроде

Unit Testing:  test.yml
  SUCCESS
person Hongbo Miao    schedule 29.03.2021

При проверке синтаксиса с помощью promtool для файла конфигурации вы должны использовать ./promtool check config prometheus.yml. Этот prometheus.yml является родительским файлом, который будет вызывать файл правил prometheus prometheus_rules.yml. Поэтому при проверке синтаксиса с помощью promtool для файла правил вы должны использовать ./promtool check rules prometheus_rules.yml.

person MeowRude    schedule 08.06.2021

В вашей конфигурации отсутствуют правила.

    groups:
    - name: alert.rules
      rules:
      - alert: HighRequestLatency
      .....

https://prometheus.io/docs/prometheus/latest/configuration/alerting_rules/ < / а>

person Amjad Hussain Syed    schedule 22.09.2019
comment
‹Pre› привет Амджад, спасибо за ответ. но я уже тестирую с использованием правил все еще группы ошибок: - name: alertting.rules rules: - alert: ExporterDown expr: up == 0 для: 5m label: severity: warning annotations: summary: Exporter down (instance {{$ labels. instance}}) правила тестирования promtool /etc/prometheus/alert.rules.yml Модульное тестирование: /etc/prometheus/alert.rules.yml НЕ ВЫПОЛНЕНО: yaml: unmarshal errors: строка 1: группы полей не найдены в типе main.unitTestFile ‹ / pre › - person Fajar Hadiyanto; 22.09.2019
comment
Я добавил ваш полный yml-файл и запустил promtool, и все прошло успешно, вы уверены, что ваш yaml правильный или отформатирован? `` `группы: - name: rules rules: - alert: MemoryFree10% expr: node_exporter: node_memory_free: memory_used_percents› = 90 для: 5 миллионов меток: серьезность: критические аннотации: сводка: экземпляр {{$ labels.instance}} высокое использование памяти description: {{$ labels.instance}} использует более 90% своей памяти. `` '' - person Amjad Hussain Syed; 22.09.2019
comment
эхмм странно, я пытаюсь всегда ошибка FAILED: yaml: unmarshal errors: строка 1: группы полей не найдены в типе main.unitTestFile - person Fajar Hadiyanto; 22.09.2019
comment
Не могли бы вы выразить это вкратце? - person Michael Doubez; 23.09.2019
comment
извините @MichaelDoubez, что означает суть? - person Fajar Hadiyanto; 23.09.2019