github.com/thanos-io/thanos@v0.32.5/mixin/alerts/absent.libsonnet (about)

     1  local capitalize(str) = std.asciiUpper(std.substr(str, 0, 1)) + std.asciiLower(std.substr(str, 1, std.length(str)));
     2  local titlize(str) = std.join('', std.map(capitalize, std.split(str, '_')));
     3  
     4  local components = ['query', 'receive', 'rule', 'compact', 'store', 'bucket-replicate', 'sidecar'];
     5  {
     6    local thanos = self,
     7  
     8    // We build alerts for the presence of all these jobs.
     9    jobs:: {
    10      ['Thanos%s' % titlize(component)]: thanos[component].selector
    11      for component in std.objectFieldsAll(thanos)
    12      if component != 'jobs' && std.type(thanos[component]) == 'object' && std.member(components, component)
    13    },
    14  
    15    prometheusAlerts+:: {
    16      local location = if std.length(std.objectFields(thanos.targetGroups)) > 0 then ' from %s' % std.join('/', ['{{$labels.%s}}' % level for level in std.objectFields(thanos.targetGroups)]) else '',
    17      groups+: [
    18        {
    19          name: 'thanos-component-absent',
    20          rules: [
    21            {
    22              alert: '%sIsDown' % name,
    23              expr: |||
    24                absent(up{%s} == 1)
    25              ||| % thanos.jobs[name],
    26              'for': '5m',
    27              labels: {
    28                severity: 'critical',
    29              },
    30              annotations: {
    31                description: '%s has disappeared%s. Prometheus target for the component cannot be discovered.' % [name, location],
    32                summary: 'Thanos component has disappeared%s.' % location,
    33              },
    34            }
    35            for name in std.objectFields(thanos.jobs)
    36          ],
    37        },
    38      ],
    39    },
    40  }