Skip to content

Commit

Permalink
[FLORA-214] Implement tracing with zipkin (#564)
Browse files Browse the repository at this point in the history
  • Loading branch information
tchoutri authored Jul 23, 2024
1 parent 212e4e8 commit 54f2923
Show file tree
Hide file tree
Showing 13 changed files with 376 additions and 214 deletions.
1 change: 0 additions & 1 deletion app/cli/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,6 @@ importIndex path repository = do
importPackageTarball
:: ( Log :> es
, BlobStoreAPI :> es
, Time :> es
, IOE :> es
, DB :> es
)
Expand Down
8 changes: 8 additions & 0 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ package warp
package zlib
flags: -pkg-config

source-repository-package
type: git
location: https://github.com/scrive/tracing
tag: e49720d
subdir:
.
./tracing-effectful

source-repository-package
type: git
location: https://github.com/haskell-cryptography/libsodium-bindings
Expand Down
2 changes: 2 additions & 0 deletions changelog.d/564
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
synopsis: Implement tracing with zipkin
prs: #564
4 changes: 4 additions & 0 deletions flora.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ library
Flora.Publish
Flora.QRCode
Flora.Search
Flora.Tracing
JSON
Log.Backend.File
Lucid.Orphans
Expand Down Expand Up @@ -194,6 +195,7 @@ library
, text
, text-display
, time
, tracing
, unliftio
, utf8-string
, uuid
Expand Down Expand Up @@ -334,6 +336,8 @@ library flora-web
, text-display
, time
, torsor
, tracing
, tracing-effectful
, uuid
, vector
, vector-algorithms
Expand Down
3 changes: 1 addition & 2 deletions src/core/Flora/Model/BlobIndex/Update.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import Data.Text.Display (display)
import Effectful (Eff, type (:>))
import Effectful.Log (Log)
import Effectful.PostgreSQL.Transact.Effect (DB, dbtToEff)
import Effectful.Time (Time)
import Log qualified

import Database.PostgreSQL.Entity (Entity, _insert)
Expand All @@ -31,7 +30,7 @@ import Flora.Model.Release.Types (Release (..), ReleaseId (..))
import Flora.Model.Release.Update qualified as Update

insertTar
:: (Log :> es, DB :> es, BlobStoreAPI :> es, Time :> es)
:: (Log :> es, DB :> es, BlobStoreAPI :> es)
=> PackageName
-> Version
-> LazyByteString
Expand Down
4 changes: 1 addition & 3 deletions src/core/Flora/Publish.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ import Control.Monad
import Data.Text.Display
import Data.Text.IO qualified as T
import Effectful
import Effectful.Log
import Effectful.PostgreSQL.Transact.Effect
import Effectful.Time

import Flora.Import.Categories.Tuning
import Flora.Import.Categories.Tuning qualified as Tuning
Expand All @@ -25,7 +23,7 @@ import Flora.Model.Requirement (Requirement)
-}

publishPackage
:: (DB :> es, Log :> es, Time :> es, IOE :> es)
:: (DB :> es, IOE :> es)
=> [Requirement]
-> [PackageComponent]
-> Release
Expand Down
25 changes: 25 additions & 0 deletions src/core/Flora/Tracing.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module Flora.Tracing where

import Data.Text (Text)
import Data.Text qualified as Text
import Monitor.Tracing.Zipkin (Zipkin)
import Monitor.Tracing.Zipkin qualified as ZPK

newZipkin
:: Text
-- ^ Zipkin server URL
-> Text
-- ^ Flora instance identifier
-> IO Zipkin
newZipkin serverURL serviceName = do
let settings =
ZPK.defaultSettings
{ ZPK.settingsEndpoint =
Just $
ZPK.defaultEndpoint
{ ZPK.endpointService = Just serviceName
}
, ZPK.settingsHostname = Just $ Text.unpack serverURL
, ZPK.settingsPublishPeriod = 1
}
ZPK.new settings
1 change: 0 additions & 1 deletion src/jobs-worker/FloraJobs/Runner.hs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ makeReadme pay@ReadmeJobPayload{..} =

fetchTarball
:: ( IOE :> es
, Time :> es
, DB :> es
, Reader JobsRunnerEnv :> es
, Log :> es
Expand Down
17 changes: 11 additions & 6 deletions src/web/FloraWeb/API/Server/Packages.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ import Data.Maybe (fromMaybe)
import Data.Vector qualified as Vector
import Distribution.Version (Version)
import Effectful (Eff, (:>))
import Servant hiding ((:>))

import Effectful.Error.Static (Error)
import Effectful.Log (Log)
import Effectful.PostgreSQL.Transact.Effect (DB)
import Effectful.Time (Time)
import Effectful.Trace
import Servant hiding ((:>))

import Flora.Model.Component.Query qualified as Query
import Flora.Model.Package.Types
import Flora.Model.Release.Query qualified as Query
Expand All @@ -35,7 +34,10 @@ withPackageServer namespace packageName =
}

getPackageHandler
:: (Time :> es, Log :> es, DB :> es, Error ServerError :> es)
:: ( DB :> es
, Error ServerError :> es
, Trace :> es
)
=> Namespace
-> PackageName
-> (Eff es) (PackageDTO 0)
Expand All @@ -56,7 +58,10 @@ getPackageHandler namespace packageName = do
pure $ toPackageDTO package release components

getVersionedPackageHandler
:: (Time :> es, Log :> es, DB :> es, Error ServerError :> es)
:: ( DB :> es
, Error ServerError :> es
, Trace :> es
)
=> Namespace
-> PackageName
-> Version
Expand Down
16 changes: 10 additions & 6 deletions src/web/FloraWeb/Common/Guards.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ module FloraWeb.Common.Guards where
import Data.Text (Text)
import Distribution.Types.Version (Version)
import Effectful
import Effectful.Log (Log)
import Effectful.PostgreSQL.Transact.Effect
import Effectful.Time (Time)
import Effectful.Trace
import FloraWeb.Pages.Templates
import Log qualified
import Monitor.Tracing qualified as Tracing
import Optics.Core
import Servant (respond)
import Servant.API.UVerb
Expand All @@ -27,14 +27,16 @@ import FloraWeb.Session (Session)
import FloraWeb.Types (FloraEff)

guardThatPackageExists
:: (DB :> es, Log :> es, Time :> es)
:: (DB :> es, Trace :> es)
=> Namespace
-> PackageName
-> (Namespace -> PackageName -> Eff es Package)
-- ^ Action to run if the package does not exist
-> Eff es Package
guardThatPackageExists namespace packageName action = do
result <- Query.getPackageByNamespaceAndName namespace packageName
result <-
Tracing.childSpan "Query.getPackageByNamespaceAndName " $
Query.getPackageByNamespaceAndName namespace packageName
case result of
Nothing -> action namespace packageName
Just package ->
Expand All @@ -43,14 +45,16 @@ guardThatPackageExists namespace packageName action = do
UnknownPackage -> action namespace packageName

guardThatReleaseExists
:: DB :> es
:: (DB :> es, Trace :> es)
=> PackageId
-> Version
-> (Version -> Eff es Release)
-- ^ Action to run if the package does not exist
-> Eff es Release
guardThatReleaseExists packageId version action = do
result <- Query.getReleaseByVersion packageId version
result <-
Tracing.childSpan "Query.getReleaseByVersion" $
Query.getReleaseByVersion packageId version
case result of
Just release -> pure release
Nothing -> action version
Expand Down
Loading

0 comments on commit 54f2923

Please sign in to comment.