File tree Expand file tree Collapse file tree 5 files changed +28
-6
lines changed
Expand file tree Collapse file tree 5 files changed +28
-6
lines changed Original file line number Diff line number Diff line change @@ -190,6 +190,7 @@ constraints: any.Cabal ==3.14.1.0,
190190 any.ghc-platform ==0.1.0.0,
191191 any.ghc-prim ==0.12.0,
192192 any.ghci ==9.10.3,
193+ any.gitrev ==1.3.1,
193194 any.gridtables ==0.1.1.0,
194195 any.haddock-library ==1.11.0,
195196 any.half ==0.3.3,
Original file line number Diff line number Diff line change @@ -191,6 +191,7 @@ library
191191 effectful-plugin,
192192 envparse,
193193 filepath,
194+ gitrev,
194195 heptapod ^>= 1.1.0.0 ,
195196 hsec-core,
196197 http-api-data,
Original file line number Diff line number Diff line change @@ -37,6 +37,7 @@ data FloraEnv = FloraEnv
3737
3838data AppMetrics = AppMetrics
3939 { packageImportCounter :: P. Vector P. Label1 P. Counter
40+ , gitRevision :: P. Vector P. Label1 P. Gauge
4041 }
4142
4243data BlobStoreImpl = BlobStoreFS FilePath | BlobStorePure
Original file line number Diff line number Diff line change 1+ {-# LANGUAGE TemplateHaskell #-}
12module Flora.Monitoring
23 ( increaseCounter
34 , increasePackageImportCounter
45 , registerMetrics
56 , increaseCounterBy
67 , increasePackageImportCounterBy
8+ , setGitHash
79 ) where
810
911import Control.Monad (replicateM_ )
@@ -12,6 +14,7 @@ import Effectful
1214import Effectful.Prometheus
1315import Prometheus
1416import Prometheus qualified as P
17+ import Development.GitRev (gitHash )
1518
1619import Flora.Environment.Env
1720
@@ -24,8 +27,21 @@ registerMetrics = do
2427 { metricName = " flora_imported_packages_total"
2528 , metricHelp = " Packages imported and their index"
2629 }
30+ let gitHashMetric =
31+ P. vector " git_revision" $
32+ P. gauge
33+ P. Info
34+ { metricName = " git_revision"
35+ , metricHelp = " Git revision"
36+ }
2737 packageImportCounter <- P. register packageImportCount
28- pure $ AppMetrics packageImportCounter
38+ gitHashText <- P. register gitHashMetric
39+ pure $ AppMetrics packageImportCounter gitHashText
40+
41+ setGitHash :: Metrics AppMetrics :> es
42+ => Eff es ()
43+ setGitHash =
44+ setLabelledGauge gitRevision $ (gitHash) 1.0
2945
3046increaseCounterBy
3147 :: Metrics AppMetrics :> es
Original file line number Diff line number Diff line change @@ -70,6 +70,7 @@ import System.Info qualified as System
7070
7171import Flora.Environment (getFloraEnv )
7272import Flora.Environment.Config (DeploymentEnv (.. ))
73+ import Flora.Monitoring (setGitHash )
7374import Flora.Environment.Env
7475 ( BlobStoreImpl (.. )
7576 , FeatureEnv (.. )
@@ -125,11 +126,13 @@ runFlora = do
125126 liftIO $ do
126127 forM_ env. mltp. eventlogSocket Socket. start
127128 when (isJust env. mltp. eventlogSocket) (blueMessage " 🔥 Sending live events to socket" )
128- liftIO $ when env. mltp. prometheusEnabled $ do
129- blueMessage $ " 🔥 Exposing Prometheus metrics at " <> baseURL <> " /metrics"
130- void $ P. register P. ghcMetrics
131- when (System. os == " linux" ) $ void $ P. register P. procMetrics
132- void $ P. register (P. counter (P. Info " flora_imported_packages_total" " The number of imported packages" ))
129+ when env. mltp. prometheusEnabled $ do
130+ liftIO $ blueMessage $ " 🔥 Exposing Prometheus metrics at " <> baseURL <> " /metrics"
131+ runPrometheusMetrics env. metrics $ do
132+ void $ P. register P. ghcMetrics
133+ when (System. os == " linux" ) $ void $ P. register P. procMetrics
134+ setGitHash
135+
133136 liftIO $ when env. mltp. zipkinEnabled (blueMessage " 🖊️ Connecting to Zipkin endpoint" )
134137 liftIO $ when (env. environment == Development ) (blueMessage " 🔁 Live reloading enabled" )
135138 let withLogger = Logging. makeLogger env. mltp. logger
You can’t perform that action at this time.
0 commit comments