Skip to content

promtool unittests fail with rate() & time() #4817

@sbueringer

Description

@sbueringer

Bug Report

What did you do?

I executed promtool in a dir with the following 2 files:

promtool test rules *.test.yaml

github.rules

groups:
- name: thanos-compact
  rules:
  - alert: ThanosCompactBucketOperationsFailed
    expr: rate(thanos_objstore_bucket_operation_failures_total{app="thanos-compact"}[5m]) > 0.01
    labels:
      severity: warning
      tenant: "{{$labels.tenant}}"
    annotations:
      summary: Thanos Compact bucket operations are failing
      impact: Long term storage queries will be slower and Minio fills up
      action: Check {{ $labels.kubernetes_pod_name }} pod logs in {{ $labels.kubernetes_namespace}} namespace
  - alert: ThanosCompactNotRunIn24Hours
    expr: (time() - max(thanos_objstore_bucket_last_successful_upload_time{app="thanos-compact"}) ) /60/60 > 24
    labels:
      severity: warning
      tenant: "{{$labels.tenant}}"
    annotations:
      summary: Thanos Compaction has not been run in 24 hours
      impact: Long term storage queries will be slower and Minio fills up
      action: Check {{ $labels.kubernetes_pod_name }} pod logs in {{ $labels.kubernetes_namespace}} namespace

github.rules.test.yaml


rule_files:
- github.rules

tests:

- interval: 1m
  input_series:
  - series: 'thanos_objstore_bucket_operation_failures_total{app="thanos-compact",tenant="i13as",kubernetes_namespace="monitoring",kubernetes_pod_name="thanos-compact-0"}'
    values: '0+0x10 1+1x5'
  - series: 'thanos_objstore_bucket_last_successful_upload_time{app="thanos-compact",tenant="i13as",kubernetes_namespace="monitoring",kubernetes_pod_name="thanos-compact-0"}'
    values: '1531152794+0x20'

  alert_rule_test:
  - alertname: ThanosCompactBucketOperationsFailed
    eval_time: 11m
    exp_alerts:
      - exp_labels:
          severity: warning
          tenant: i13as
          app: thanos-compact
          kubernetes_namespace: monitoring
          kubernetes_pod_name: thanos-compact-0
        exp_annotations:
          action: "Check thanos-compact-0 pod logs in monitoring namespace"
          impact: "Long term storage queries will be slower and Minio fills up"
          summary: "Thanos Compact bucket operations are failing"
  - alertname: ThanosCompactNotRunIn24Hours
    eval_time: 10m
    exp_alerts:
      - exp_labels:
          severity: warning
          tenant: i13as
          app: thanos-compact
          kubernetes_namespace: monitoring
          kubernetes_pod_name: thanos-compact-0
        exp_annotations:
          action: "Check thanos-compact-0 pod logs in monitoring namespace"
          impact: "Long term storage queries will be slower and Minio fills up"
          summary: "Thanos Compact bucket operations are failing"

What did you expect to see?

I expected the unit test to succeed.

What did you see instead? Under which circumstances?

The unit test failed.

Environment

Linux Fedora with promtool 2.5.0-rc2

  • Logs:
Unit Testing:  github.rules.test.yaml
  FAILED:
    alertname:ThanosCompactNotRunIn24Hours, time:10m0s, 
        exp:"[Labels:{alertname=\"ThanosCompactNotRunIn24Hours\", app=\"thanos-compact\", kubernetes_namespace=\"monitoring\", kubernetes_pod_name=\"thanos-compact-0\", severity=\"warning\", tenant=\"i13as\"} Annotations:{action=\"Check thanos-compact-0 pod logs in monitoring namespace\", impact=\"Long term storage queries will be slower and Minio fills up\", summary=\"Thanos Compact bucket operations are failing\"}]", 
        got:"[]"
    alertname:ThanosCompactBucketOperationsFailed, time:11m0s, 
        exp:"[Labels:{alertname=\"ThanosCompactBucketOperationsFailed\", app=\"thanos-compact\", kubernetes_namespace=\"monitoring\", kubernetes_pod_name=\"thanos-compact-0\", severity=\"warning\", tenant=\"i13as\"} Annotations:{action=\"Check thanos-compact-0 pod logs in monitoring namespace\", impact=\"Long term storage queries will be slower and Minio fills up\", summary=\"Thanos Compact bucket operations are failing\"}]", 
        got:"[]"

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions