{-# LANGUAGE OverloadedStrings #-}

-- | The names of the instruments arbiter registers.
module Arbiter.Otel.MetricNames
  ( MetricName (..)
  , metricName
  , arbiterMetricNames
  ) where

import Data.Text (Text)

-- | Every instrument the library registers. A job's @kind@ attribute is absent when its
-- label is not declared.
data MetricName
  = -- Worker lifecycle

    -- | Counter, no unit. Attributes: @queue@, @kind@.
    JobsClaimed
  | -- | Counter, no unit. Attributes: @queue@, @outcome@ (success, dlq, cancelled, unavailable), @kind@.
    JobsProcessed
  | -- | Counter, no unit. Attributes: @queue@, @kind@.
    JobsRetried
  | -- | Counter, no unit. Attributes: @queue@, @policy_kind@, @policy@.
    AdmissionAdmitted
  | -- | Counter, no unit. Attributes: @op@.
    MaintenanceRows
  | -- | Histogram, @s@. Attributes: @queue@, @outcome@ (success, failure), @kind@.
    HandlerDuration
  | -- Queue depth

    -- | Gauge, @{job}@. Attributes: @queue@, @status@ (ready, blocked, in_flight, scheduled, backoff, throttled, suspended, cancelled, exhausted).
    QueueDepth
  | -- | Gauge, @{job}@. Attributes: @queue@, @kind@.
    QueueDepthByKind
  | -- | Gauge, @s@. Attributes: @queue@.
    QueueOldestReadyAge
  | -- | Gauge, @s@. Attributes: @queue@.
    QueueOldestInFlightAge
  | -- | Gauge, @{worker}@. Attributes: @queue@, @state@ (active, paused).
    Workers
  | -- Admission

    -- | Gauge, @{key}@. Attributes: @policy_kind@, @policy@.
    AdmissionKeys
  | -- | Gauge, @{admission}@, in concurrency slots or rate-limit tokens. Attributes: @policy_kind@, @policy@.
    AdmissionLimit
  | -- | Gauge, @{job}@. Attributes: @policy@.
    AdmissionInFlight
  | -- | Gauge, @{job}@. Attributes: @policy@.
    AdmissionBusiestKey
  | -- | Gauge, @{token}@. Attributes: @policy@, @stat@ (min, avg).
    AdmissionTokens
  | -- Postgres health

    -- | Gauge, @{tuple}@. Attributes: @table@.
    PgTableDeadTuples
  | -- | Gauge, @{tuple}@. Attributes: @table@.
    PgTableLiveTuples
  | -- | Gauge, @s@. Attributes: @table@.
    PgTableVacuumAge
  | -- | Gauge, @By@. Attributes: @table@.
    PgTableSize
  | -- | Counter, @{scan}@. Attributes: @table@, @path@ (seq, index).
    PgTableScans
  | -- | Counter, @{block}@. Attributes: @table@, @source@ (hit, disk).
    PgTableBlocks
  | -- | Gauge, @{transaction}@. Attributes: @table@.
    PgTableXidAge
  | -- | Gauge, @{connection}@. Attributes: @state@ (active, idle, idle_in_transaction, idle_in_transaction_aborted, blocked, other).
    PgDbConnections
  | -- | Gauge, @{backend}@. No attributes.
    PgDbBackends
  | -- | Gauge, @s@. No attributes.
    PgDbOldestTransactionAge
  | -- | Gauge, @s@. No attributes.
    PgDbOldestQueryAge
  | -- | Gauge, @1@, 1 when reachable and 0 when not. No attributes.
    DbReachable
  | -- | Gauge, @s@. No attributes.
    GaugesAge
  deriving stock (MetricName
MetricName -> MetricName -> Bounded MetricName
forall a. a -> a -> Bounded a
$cminBound :: MetricName
minBound :: MetricName
$cmaxBound :: MetricName
maxBound :: MetricName
Bounded, Int -> MetricName
MetricName -> Int
MetricName -> [MetricName]
MetricName -> MetricName
MetricName -> MetricName -> [MetricName]
MetricName -> MetricName -> MetricName -> [MetricName]
(MetricName -> MetricName)
-> (MetricName -> MetricName)
-> (Int -> MetricName)
-> (MetricName -> Int)
-> (MetricName -> [MetricName])
-> (MetricName -> MetricName -> [MetricName])
-> (MetricName -> MetricName -> [MetricName])
-> (MetricName -> MetricName -> MetricName -> [MetricName])
-> Enum MetricName
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
$csucc :: MetricName -> MetricName
succ :: MetricName -> MetricName
$cpred :: MetricName -> MetricName
pred :: MetricName -> MetricName
$ctoEnum :: Int -> MetricName
toEnum :: Int -> MetricName
$cfromEnum :: MetricName -> Int
fromEnum :: MetricName -> Int
$cenumFrom :: MetricName -> [MetricName]
enumFrom :: MetricName -> [MetricName]
$cenumFromThen :: MetricName -> MetricName -> [MetricName]
enumFromThen :: MetricName -> MetricName -> [MetricName]
$cenumFromTo :: MetricName -> MetricName -> [MetricName]
enumFromTo :: MetricName -> MetricName -> [MetricName]
$cenumFromThenTo :: MetricName -> MetricName -> MetricName -> [MetricName]
enumFromThenTo :: MetricName -> MetricName -> MetricName -> [MetricName]
Enum, MetricName -> MetricName -> Bool
(MetricName -> MetricName -> Bool)
-> (MetricName -> MetricName -> Bool) -> Eq MetricName
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: MetricName -> MetricName -> Bool
== :: MetricName -> MetricName -> Bool
$c/= :: MetricName -> MetricName -> Bool
/= :: MetricName -> MetricName -> Bool
Eq, Int -> MetricName -> ShowS
[MetricName] -> ShowS
MetricName -> String
(Int -> MetricName -> ShowS)
-> (MetricName -> String)
-> ([MetricName] -> ShowS)
-> Show MetricName
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> MetricName -> ShowS
showsPrec :: Int -> MetricName -> ShowS
$cshow :: MetricName -> String
show :: MetricName -> String
$cshowList :: [MetricName] -> ShowS
showList :: [MetricName] -> ShowS
Show)

-- | The exported name of a metric.
metricName :: MetricName -> Text
metricName :: MetricName -> Text
metricName = \case
  MetricName
JobsClaimed -> Text
"arbiter.jobs.claimed"
  MetricName
JobsProcessed -> Text
"arbiter.jobs.processed"
  MetricName
JobsRetried -> Text
"arbiter.jobs.retried"
  MetricName
AdmissionAdmitted -> Text
"arbiter.admission.admitted"
  MetricName
MaintenanceRows -> Text
"arbiter.maintenance.rows"
  MetricName
HandlerDuration -> Text
"arbiter.jobs.handler.duration"
  MetricName
QueueDepth -> Text
"arbiter.queue.depth"
  MetricName
QueueDepthByKind -> Text
"arbiter.queue.depth_by_kind"
  MetricName
QueueOldestReadyAge -> Text
"arbiter.queue.oldest_ready_age"
  MetricName
QueueOldestInFlightAge -> Text
"arbiter.queue.oldest_in_flight_age"
  MetricName
Workers -> Text
"arbiter.workers"
  MetricName
AdmissionKeys -> Text
"arbiter.admission.keys"
  MetricName
AdmissionLimit -> Text
"arbiter.admission.limit"
  MetricName
AdmissionInFlight -> Text
"arbiter.admission.in_flight"
  MetricName
AdmissionBusiestKey -> Text
"arbiter.admission.busiest_key"
  MetricName
AdmissionTokens -> Text
"arbiter.admission.tokens"
  MetricName
PgTableDeadTuples -> Text
"arbiter.pg.table.dead_tuples"
  MetricName
PgTableLiveTuples -> Text
"arbiter.pg.table.live_tuples"
  MetricName
PgTableVacuumAge -> Text
"arbiter.pg.table.vacuum_age"
  MetricName
PgTableSize -> Text
"arbiter.pg.table.size"
  MetricName
PgTableScans -> Text
"arbiter.pg.table.scans"
  MetricName
PgTableBlocks -> Text
"arbiter.pg.table.blocks"
  MetricName
PgTableXidAge -> Text
"arbiter.pg.table.xid_age"
  MetricName
PgDbConnections -> Text
"arbiter.pg.database.connections"
  MetricName
PgDbBackends -> Text
"arbiter.pg.database.backends"
  MetricName
PgDbOldestTransactionAge -> Text
"arbiter.pg.database.oldest_transaction_age"
  MetricName
PgDbOldestQueryAge -> Text
"arbiter.pg.database.oldest_query_age"
  MetricName
DbReachable -> Text
"arbiter.pg.database.reachable"
  MetricName
GaugesAge -> Text
"arbiter.gauges.age"

-- | Every metric name arbiter exports.
arbiterMetricNames :: [Text]
arbiterMetricNames :: [Text]
arbiterMetricNames = (MetricName -> Text) -> [MetricName] -> [Text]
forall a b. (a -> b) -> [a] -> [b]
map MetricName -> Text
metricName [MetricName
forall a. Bounded a => a
minBound .. MetricName
forall a. Bounded a => a
maxBound]