From 8622c1b8db27c4ab56f5ea5a63a9cd3dcccafa18 Mon Sep 17 00:00:00 2001 From: Julien Moutinho Date: Sat, 1 Jul 2023 19:11:34 +0200 Subject: [PATCH] support and require aeson >= 2.0 --- System/Metrics/Json.hs | 24 +++++++++++++----------- ekg-json.cabal | 6 +++--- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/System/Metrics/Json.hs b/System/Metrics/Json.hs index 1c58ca5..09a416d 100644 --- a/System/Metrics/Json.hs +++ b/System/Metrics/Json.hs @@ -17,8 +17,10 @@ module System.Metrics.Json ) where import Data.Aeson ((.=)) +import qualified Data.Aeson.Key as AK +import qualified Data.Aeson.KeyMap as AKM import qualified Data.Aeson.Types as A -import qualified Data.HashMap.Strict as M +import qualified Data.HashMap.Strict as HM import Data.Int (Int64) import qualified Data.Text as T import qualified System.Metrics as Metrics @@ -50,22 +52,22 @@ sampleToJson :: Metrics.Sample -> A.Value sampleToJson metrics = buildOne metrics $ A.emptyObject where - buildOne :: M.HashMap T.Text Metrics.Value -> A.Value -> A.Value - buildOne m o = M.foldlWithKey' build o m + buildOne :: HM.HashMap T.Text Metrics.Value -> A.Value -> A.Value + buildOne m o = HM.foldlWithKey' build o m build :: A.Value -> T.Text -> Metrics.Value -> A.Value - build m name val = go m (T.splitOn "." name) val + build m name val = go m (AK.fromText <$> T.splitOn "." name) val - go :: A.Value -> [T.Text] -> Metrics.Value -> A.Value - go (A.Object m) [str] val = A.Object $ M.insert str metric m + go :: A.Value -> [A.Key] -> Metrics.Value -> A.Value + go (A.Object m) [str] val = A.Object $ AKM.insert str metric m where metric = valueToJson val - go (A.Object m) (str:rest) val = case M.lookup str m of - Nothing -> A.Object $ M.insert str (go A.emptyObject rest val) m - Just m' -> A.Object $ M.insert str (go m' rest val) m + go (A.Object m) (str:rest) val = case AKM.lookup str m of + Nothing -> A.Object $ AKM.insert str (go A.emptyObject rest val) m + Just m' -> A.Object $ AKM.insert str (go m' rest val) m go v _ _ = typeMismatch "Object" v sampleFromJson :: A.Value -> A.Parser Metrics.Sample -sampleFromJson v = M.fromList <$> go [] v +sampleFromJson v = HM.fromList <$> go [] v where go :: [T.Text] -> A.Value -> A.Parser [(T.Text, Metrics.Value)] go prefix (A.Object o) = do mtype <- o A..:? "type" @@ -75,7 +77,7 @@ sampleFromJson v = M.fromList <$> go [] v metricsVal <- valueFromJson ty val return [(T.intercalate "." prefix, metricsVal)] Nothing -> concat - <$> traverse (\(k, v) -> go (prefix++[k]) v) (M.toList o) + <$> traverse (\(k, v) -> go (prefix++[AK.toText k]) v) (AKM.toList o) go _ _ = fail "shouldn't happen" typeMismatch :: String -- ^ The expected type diff --git a/ekg-json.cabal b/ekg-json.cabal index d48f3c8..fffe463 100644 --- a/ekg-json.cabal +++ b/ekg-json.cabal @@ -24,10 +24,10 @@ library exposed-modules: System.Metrics.Json build-depends: - aeson >=0.4 && < 1.6, - base >= 4.6 && < 4.16, + aeson >=2.0 && < 3.0, + base >= 4.6 && < 4.18, ekg-core >= 0.1 && < 0.2, - text < 1.3, + text < 1.3 || >= 2.0 && < 2.1, unordered-containers < 0.3 default-language: Haskell2010 -- 2.40.1