servant-prometheus 1.1.0 → 1.2.0
raw patch · 6 files changed
+34/−36 lines, 6 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Prometheus.Servant.Internal: instance forall k sub (a :: k). Prometheus.Servant.Internal.HasEndpoint sub => Prometheus.Servant.Internal.HasEndpoint (Servant.API.Experimental.Auth.AuthProtect a Servant.API.Sub.:> sub)
Files
- CHANGELOG.md +6/−0
- README.md +13/−5
- bench/Main.hs +1/−1
- lib/Prometheus/Servant/Internal.hs +7/−0
- servant-prometheus.cabal +5/−28
- test/Prometheus/ServantSpec.hs +2/−2
CHANGELOG.md view
@@ -1,6 +1,12 @@ Unreleased ========== ++1.2.0+=======++- Add an `HasEndpoint` instance for `AuthProtect`+ 1.1.0 =======
README.md view
@@ -1,20 +1,21 @@ # servant-prometheus [](https://github.com/worm2fed/servant-prometheus/actions/workflows/ci.yml)-[][https://hackage.haskell.org/package/servant-prometheus]+[](https://hackage.haskell.org/package/servant-prometheus) # Servant Performance Counters -This package lets you track performance counters for each of your Servant endpoints using Prometheus.+This package lets you track performance counters for each of your Servant endpoints using [Prometheus](https://prometheus.io/). # Usage -Servant-Prometheus knows how to handle all official Servant combinators out of the box.+`servant-prometheus` knows how to handle all official Servant combinators out of the box. ## Instrumenting your API-To use Servant-Prometheus, you'll need to wrap your WAI application with the Servant-Prometheus middleware. -```+To use `servant-prometheus`, you'll need to wrap your WAI application with the provided middleware.++```haskell import Network.Wai.Handler.Warp import Prometheus.Servant @@ -27,7 +28,14 @@ run 8080 app ``` +## Custom metrics++Note, that in example above `defaultMetrics` used, which actually provided as an example and good starting point.+If you want to use your custom metrics (eg you want another labels), you'll need to define an implementation for `Metrics mLatencyLabel mActiveLabel` data.+That's not hard, just copy-paste and tweak accordingly to your needs.+ ## Runtime overhead+ Instrumenting your API introduces a non-zero runtime overhead, on the order of 200 - 600 µsec depending upon your machine. It's a good idea to run the benchmarks on your intended production platform to get an idea of how large the overhead will be. You'll need to have `wrk` installed to run the benchmarks. In general, the runtime overhead should be effectively negligible if your handlers are issuing network requests, such as to databases. If you have handlers that are small, CPU-only, and requested frequently, you will see a performance hit from `servant-prometheus`.
bench/Main.hs view
@@ -10,7 +10,7 @@ , JSON , Proxy (..) , serve- , type (:>)+ , (:>) ) import System.Process (callCommand)
lib/Prometheus/Servant/Internal.hs view
@@ -175,6 +175,13 @@ where method = reflectMethod (Proxy :: Proxy method) +#if MIN_VERSION_servant(0,5,0)+instance HasEndpoint (sub :: Type) => HasEndpoint (AuthProtect a :> sub) where+ getEndpoint _ = getEndpoint (Proxy :: Proxy sub)++ enumerateEndpoints _ = enumerateEndpoints (Proxy :: Proxy sub)+#endif+ #if MIN_VERSION_servant(0,17,0) instance ReflectMethod method => HasEndpoint (NoContentVerb method) where getEndpoint _ req = case pathInfo req of
servant-prometheus.cabal view
@@ -5,7 +5,7 @@ -- see: https://github.com/sol/hpack name: servant-prometheus-version: 1.1.0+version: 1.2.0 synopsis: Helpers for using prometheus with servant description: Please see the README on GitHub at <https://github.com/worm2fed/servant-prometheus#readme> category: Servant, Web, System@@ -19,6 +19,7 @@ tested-with: GHC == 9.2.8 , GHC == 9.4.7+ , GHC == 9.4.8 extra-source-files: README.md LICENSE@@ -40,19 +41,11 @@ hs-source-dirs: lib default-extensions:- BangPatterns DataKinds DeriveAnyClass- DeriveGeneric DerivingStrategies- FlexibleContexts- FlexibleInstances- ImportQualifiedPost OverloadedStrings- PolyKinds RecordWildCards- ScopedTypeVariables- TypeOperators UndecidableInstances ghc-options: -Weverything -Wno-missing-exported-signatures -Wno-missing-import-lists -Wno-missed-specialisations -Wno-all-missed-specialisations -Wno-unsafe -Wno-safe -Wno-inferred-safe-imports -Wno-missing-safe-haskell-mode -Wno-missing-local-signatures -Wno-monomorphism-restriction -Wno-prepositive-qualified-module -Wno-missing-kind-signatures -Wno-implicit-prelude build-depends:@@ -65,7 +58,7 @@ , servant >=0.14 && <0.20 , text >=1.2.5 && <2.1 , wai >=3.2.3 && <3.3- default-language: Haskell2010+ default-language: GHC2021 test-suite spec type: exitcode-stdio-1.0@@ -78,19 +71,11 @@ hs-source-dirs: test default-extensions:- BangPatterns DataKinds DeriveAnyClass- DeriveGeneric DerivingStrategies- FlexibleContexts- FlexibleInstances- ImportQualifiedPost OverloadedStrings- PolyKinds RecordWildCards- ScopedTypeVariables- TypeOperators UndecidableInstances ghc-options: -Weverything -Wno-missing-exported-signatures -Wno-missing-import-lists -Wno-missed-specialisations -Wno-all-missed-specialisations -Wno-unsafe -Wno-safe -Wno-inferred-safe-imports -Wno-missing-safe-haskell-mode -Wno-missing-local-signatures -Wno-monomorphism-restriction -Wno-prepositive-qualified-module -Wno-missing-kind-signatures -Wno-implicit-prelude -Wno-missing-export-lists -threaded "-with-rtsopts=-N -A64m -AL256m" build-tool-depends:@@ -110,7 +95,7 @@ , text , wai , warp >=3.2.4 && <3.4- default-language: Haskell2010+ default-language: GHC2021 benchmark bench type: exitcode-stdio-1.0@@ -122,19 +107,11 @@ hs-source-dirs: bench default-extensions:- BangPatterns DataKinds DeriveAnyClass- DeriveGeneric DerivingStrategies- FlexibleContexts- FlexibleInstances- ImportQualifiedPost OverloadedStrings- PolyKinds RecordWildCards- ScopedTypeVariables- TypeOperators UndecidableInstances ghc-options: -Weverything -Wno-missing-exported-signatures -Wno-missing-import-lists -Wno-missed-specialisations -Wno-all-missed-specialisations -Wno-unsafe -Wno-safe -Wno-inferred-safe-imports -Wno-missing-safe-haskell-mode -Wno-missing-local-signatures -Wno-monomorphism-restriction -Wno-prepositive-qualified-module -Wno-missing-kind-signatures -Wno-implicit-prelude -threaded "-with-rtsopts=-N -A64m -AL256m" build-depends:@@ -145,4 +122,4 @@ , text , wai , warp- default-language: Haskell2010+ default-language: GHC2021
test/Prometheus/ServantSpec.hs view
@@ -21,8 +21,8 @@ , ReqBody , Server , serve- , type (:<|>) (..)- , type (:>)+ , (:<|>) (..)+ , (:>) ) import Servant.Client ( BaseUrl (..)