Skip to content

Commit

Permalink
Define metrics using Prometheus.unsafeRegister instead of having th…
Browse files Browse the repository at this point in the history
…e metrics-core wrapper (#4085)

* catchErrors middleware: Always record metrics

Instead of relying on `Metrics`, use top-level metric registered using
`unsafeRegister`.

* Use `unsafeRegister` for metrics instead of bunch of IORef HashMaps

* federator: Enable GC metrics
  • Loading branch information
akshaymankar authored Jun 17, 2024
1 parent 36b2406 commit c2bb1a2
Show file tree
Hide file tree
Showing 68 changed files with 576 additions and 680 deletions.
1 change: 1 addition & 0 deletions changelog.d/5-internal/federator-metrics
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
federator: Add metrics for garbage collections and unexpected errors that were caught
1 change: 1 addition & 0 deletions changelog.d/5-internal/metrics-core
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
metrics-core: Delete `Data.Metrics` in favour of defining metrics closer to where they are being emitted
8 changes: 0 additions & 8 deletions libs/metrics-core/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,23 @@
# dependencies are added or removed.
{ mkDerivation
, base
, containers
, gitignoreSource
, hashable
, immortal
, imports
, lib
, prometheus-client
, text
, time
, unordered-containers
}:
mkDerivation {
pname = "metrics-core";
version = "0.3.2";
src = gitignoreSource ./.;
libraryHaskellDepends = [
base
containers
hashable
immortal
imports
prometheus-client
text
time
unordered-containers
];
description = "Metrics core";
license = lib.licenses.agpl3Only;
Expand Down
7 changes: 1 addition & 6 deletions libs/metrics-core/metrics-core.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ build-type: Simple

library
exposed-modules:
Data.Metrics
Data.Metrics.AWS
Data.Metrics.GC

Expand Down Expand Up @@ -66,14 +65,10 @@ library
-Wredundant-constraints -Wunused-packages

build-depends:
base >=4.9
, containers
, hashable >=1.2
base >=4.9
, immortal
, imports
, prometheus-client
, text >=0.11
, time
, unordered-containers >=0.2

default-language: GHC2021
295 changes: 0 additions & 295 deletions libs/metrics-core/src/Data/Metrics.hs

This file was deleted.

18 changes: 14 additions & 4 deletions libs/metrics-core/src/Data/Metrics/AWS.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,24 @@

module Data.Metrics.AWS (gaugeTokenRemaing) where

import Data.Metrics (Metrics, gaugeSet, path)
import Data.Time
import Imports
import Prometheus qualified as Prom

gaugeTokenRemaing :: Metrics -> Maybe NominalDiffTime -> IO ()
gaugeTokenRemaing m mbRemaining = do
gaugeTokenRemaing :: Maybe NominalDiffTime -> IO ()
gaugeTokenRemaing mbRemaining = do
let t = toSeconds (fromMaybe 0 mbRemaining)
gaugeSet t (path "aws_auth.token_secs_remaining") m
Prom.setGauge awsAuthTokenSecsRemaining t
where
toSeconds :: NominalDiffTime -> Double
toSeconds = fromRational . toRational

{-# NOINLINE awsAuthTokenSecsRemaining #-}
awsAuthTokenSecsRemaining :: Prom.Gauge
awsAuthTokenSecsRemaining =
Prom.unsafeRegister $
Prom.gauge
Prom.Info
{ Prom.metricName = "aws_auth.token_secs_remaining",
Prom.metricHelp = "Number of seconds left before AWS Auth expires"
}
Loading

0 comments on commit c2bb1a2

Please sign in to comment.