Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cabal.project.freeze
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ constraints: any.Cabal ==3.14.1.0,
any.ghc-platform ==0.1.0.0,
any.ghc-prim ==0.12.0,
any.ghci ==9.10.3,
any.gitrev ==1.3.1,
any.gridtables ==0.1.1.0,
any.haddock-library ==1.11.0,
any.half ==0.3.3,
Expand Down
1 change: 1 addition & 0 deletions flora.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ library
effectful-plugin,
envparse,
filepath,
gitrev,
heptapod ^>=1.1.0.0,
hsec-core,
http-api-data,
Expand Down
1 change: 1 addition & 0 deletions src/core/Flora/Environment/Env.hs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ data FloraEnv = FloraEnv

data AppMetrics = AppMetrics
{ packageImportCounter :: P.Vector P.Label1 P.Counter
, gitRevision :: P.Vector P.Label1 P.Gauge
}

data BlobStoreImpl = BlobStoreFS FilePath | BlobStorePure
Expand Down
20 changes: 19 additions & 1 deletion src/core/Flora/Monitoring.hs
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
{-# LANGUAGE TemplateHaskell #-}

module Flora.Monitoring
( increaseCounter
, increasePackageImportCounter
, registerMetrics
, increaseCounterBy
, increasePackageImportCounterBy
, setGitHash
) where

import Control.Monad (replicateM_)
import Data.Text
import Development.GitRev (gitHash)
import Effectful
import Effectful.Prometheus
import Prometheus
Expand All @@ -24,8 +28,22 @@ registerMetrics = do
{ metricName = "flora_imported_packages_total"
, metricHelp = "Packages imported and their index"
}
let gitHashMetric =
P.vector "git_revision" $
P.gauge
P.Info
{ metricName = "git_revision"
, metricHelp = "Git revision"
}
packageImportCounter <- P.register packageImportCount
pure $ AppMetrics packageImportCounter
gitHashText <- P.register gitHashMetric
pure $ AppMetrics packageImportCounter gitHashText

setGitHash
:: Metrics AppMetrics :> es
=> Eff es ()
setGitHash =
setLabelledGauge gitRevision $(gitHash) 1.0

increaseCounterBy
:: Metrics AppMetrics :> es
Expand Down
13 changes: 8 additions & 5 deletions src/web/FloraWeb/Server.hs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ import Flora.Environment.Env
import Flora.Logging qualified as Logging
import Flora.Model.BlobStore.API
import Flora.Monad
import Flora.Monitoring (setGitHash)
import Flora.Tracing qualified as Tracing
import FloraJobs.Runner
import FloraJobs.Types (JobsRunnerEnv (..))
Expand Down Expand Up @@ -125,11 +126,13 @@ runFlora = do
liftIO $ do
forM_ env.mltp.eventlogSocket Socket.start
when (isJust env.mltp.eventlogSocket) (blueMessage "🔥 Sending live events to socket")
liftIO $ when env.mltp.prometheusEnabled $ do
blueMessage $ "🔥 Exposing Prometheus metrics at " <> baseURL <> "/metrics"
void $ P.register P.ghcMetrics
when (System.os == "linux") $ void $ P.register P.procMetrics
void $ P.register (P.counter (P.Info "flora_imported_packages_total" "The number of imported packages"))
when env.mltp.prometheusEnabled $ do
liftIO $ blueMessage $ "🔥 Exposing Prometheus metrics at " <> baseURL <> "/metrics"
runPrometheusMetrics env.metrics $ do
void $ P.register P.ghcMetrics
when (System.os == "linux") $ void $ P.register P.procMetrics
setGitHash

liftIO $ when env.mltp.zipkinEnabled (blueMessage "🖊️ Connecting to Zipkin endpoint")
liftIO $ when (env.environment == Development) (blueMessage "🔁 Live reloading enabled")
let withLogger = Logging.makeLogger env.mltp.logger
Expand Down
Loading