git.iko.soy/typeable/bloodhound
on master help sign in
WIP node stats API
976143cMichael Xavier
src/Database/Bloodhound/Client.hs+19
@@ -79,6 +79,7 @@ module Database.Bloodhound.Client
79 , restoreSnapshot
79 , restoreSnapshot
80 -- ** Nodes
80 -- ** Nodes
81 , getNodesInfo
81 , getNodesInfo
82+ , getNodesStats
82 -- ** Request Utilities
83 -- ** Request Utilities
83 , encodeBulkOperations
84 , encodeBulkOperations
84 , encodeBulkOperation
85 , encodeBulkOperation
@@ -475,6 +476,24 @@ getNodesInfo sel = parseEsResponse =<< get =<< url
475 selToSeg (NodeByHost (Server s)) = s
476 selToSeg (NodeByHost (Server s)) = s
476 selToSeg (NodeByAttribute (NodeAttrName a) v) = a <> ":" <> v
477 selToSeg (NodeByAttribute (NodeAttrName a) v) = a <> ":" <> v
477
478
479+getNodesStats
480+ :: ( MonadBH m
481+ , MonadThrow m
482+ )
483+ => NodeSelection
484+ -> m (Either EsError NodesStats)
485+getNodesStats sel = parseEsResponse =<< get =<< url
486+ where
487+ url = joinPath ["_nodes", selectionSeg, "stats"]
488+ selectionSeg = case sel of
489+ LocalNode -> "_local"
490+ NodeList (l :| ls) -> T.intercalate "," (selToSeg <$> (l:ls))
491+ AllNodes -> "_all"
492+ selToSeg (NodeByName (NodeName n)) = n
493+ selToSeg (NodeByFullNodeId (FullNodeId i)) = i
494+ selToSeg (NodeByHost (Server s)) = s
495+ selToSeg (NodeByAttribute (NodeAttrName a) v) = a <> ":" <> v
496+
478-- | 'createIndex' will create an index given a 'Server', 'IndexSettings', and an 'IndexName'.
497-- | 'createIndex' will create an index given a 'Server', 'IndexSettings', and an 'IndexName'.
479--
498--
480-- >>> response <- runBH' $ createIndex defaultIndexSettings (IndexName "didimakeanindex")
499-- >>> response <- runBH' $ createIndex defaultIndexSettings (IndexName "didimakeanindex")
src/Database/Bloodhound/Types.hs+122
@@ -258,6 +258,18 @@ module Database.Bloodhound.Types
258 , NodeName(..)
258 , NodeName(..)
259 , ClusterName(..)
259 , ClusterName(..)
260 , NodesInfo(..)
260 , NodesInfo(..)
261+ , NodesStats(..)
262+ , NodeStats(..)
263+ , NodeBreakerStats(..)
264+ , NodeHTTPStats(..)
265+ , NodeTransportStats(..)
266+ , NodeFSStats(..)
267+ , NodeNetworkStats(..)
268+ , NodeThreadPoolsStats(..)
269+ , NodeJVMStats(..)
270+ , NodeProcessStats(..)
271+ , NodeOSStats(..)
272+ , NodeIndicesStats(..)
261 , EsAddress(..)
273 , EsAddress(..)
262 , PluginName(..)
274 , PluginName(..)
263 , NodeInfo(..)
275 , NodeInfo(..)
@@ -3841,6 +3853,58 @@ data NodesInfo = NodesInfo {
3841 , nodesClusterName :: ClusterName
3853 , nodesClusterName :: ClusterName
3842 } deriving (Eq, Show, Generic, Typeable)
3854 } deriving (Eq, Show, Generic, Typeable)
3843
3855
3856+data NodesStats = NodesStats {
3857+ nodesStats :: [NodeStats]
3858+ , nodesStatsClusterName :: ClusterName
3859+ } deriving (Eq, Show, Generic, Typeable)
3860+
3861+data NodeStats = NodeStats {
3862+ nodeStatsName :: NodeName
3863+ , nodeStatsFullId :: FullNodeId
3864+ , nodeStatsParentBreaker :: NodeBreakerStats
3865+ , nodeStatsRequestBreaker :: NodeBreakerStats
3866+ , nodeStatsFieldDataBreaker :: NodeBreakerStats
3867+ , nodeStatsHTTP :: NodeHTTPStats
3868+ , nodeStatsTransport :: NodeTransportStats
3869+ , nodeStatsFS :: NodeFSStats
3870+ , nodeStatsNetwork :: NodeNetworkStats
3871+ , nodeStatsThreadPool :: NodeThreadPoolsStats
3872+ , nodeStatsJVM :: NodeJVMStats
3873+ , nodeStatsProcess :: NodeProcessStats
3874+ , nodeStatsOS :: NodeOSStats
3875+ , nodeStatsIndices :: NodeIndicesStats
3876+ } deriving (Eq, Show, Generic, Typeable)
3877+
3878+data NodeBreakerStats = NodeBreakerStats
3879+ deriving (Eq, Show, Generic, Typeable)
3880+
3881+data NodeHTTPStats = NodeHTTPStats
3882+ deriving (Eq, Show, Generic, Typeable)
3883+
3884+data NodeTransportStats = NodeTransportStats
3885+ deriving (Eq, Show, Generic, Typeable)
3886+
3887+data NodeFSStats = NodeFSStats
3888+ deriving (Eq, Show, Generic, Typeable)
3889+
3890+data NodeNetworkStats = NodeNetworkStats
3891+ deriving (Eq, Show, Generic, Typeable)
3892+
3893+data NodeThreadPoolsStats = NodeThreadPoolsStats
3894+ deriving (Eq, Show, Generic, Typeable)
3895+
3896+data NodeJVMStats = NodeJVMStats
3897+ deriving (Eq, Show, Generic, Typeable)
3898+
3899+data NodeProcessStats = NodeProcessStats
3900+ deriving (Eq, Show, Generic, Typeable)
3901+
3902+data NodeOSStats = NodeOSStats
3903+ deriving (Eq, Show, Generic, Typeable)
3904+
3905+data NodeIndicesStats = NodeIndicesStats
3906+ deriving (Eq, Show, Generic, Typeable)
3907+
3844-- | A quirky address format used throughout ElasticSearch. An example
3908-- | A quirky address format used throughout ElasticSearch. An example
3845-- would be inet[/1.1.1.1:9200]. inet may be a placeholder for a
3909-- would be inet[/1.1.1.1:9200]. inet may be a placeholder for a
3846-- <https://en.wikipedia.org/wiki/Fully_qualified_domain_name FQDN>.
3910-- <https://en.wikipedia.org/wiki/Fully_qualified_domain_name FQDN>.
@@ -4360,6 +4424,64 @@ instance FromJSON NodesInfo where
4360 cn <- o .: "cluster_name"
4424 cn <- o .: "cluster_name"
4361 return (NodesInfo infos cn)
4425 return (NodesInfo infos cn)
4362
4426
4427+instance FromJSON NodesStats where
4428+ parseJSON = withObject "NodesStats" parse
4429+ where
4430+ parse o = do
4431+ nodes <- o .: "nodes"
4432+ stats <- forM (HM.toList nodes) $ \(fullNID, v) -> do
4433+ node <- parseJSON v
4434+ parseNodeStats (FullNodeId fullNID) node
4435+ cn <- o .: "cluster_name"
4436+ return (NodesStats stats cn)
4437+
4438+instance FromJSON NodeBreakerStats where
4439+ parseJSON _ = pure NodeBreakerStats
4440+
4441+instance FromJSON NodeHTTPStats where
4442+ parseJSON _ = pure NodeHTTPStats
4443+
4444+instance FromJSON NodeTransportStats where
4445+ parseJSON _ = pure NodeTransportStats
4446+
4447+instance FromJSON NodeFSStats where
4448+ parseJSON _ = pure NodeFSStats
4449+
4450+instance FromJSON NodeNetworkStats where
4451+ parseJSON _ = pure NodeNetworkStats
4452+
4453+instance FromJSON NodeThreadPoolsStats where
4454+ parseJSON _ = pure NodeThreadPoolsStats
4455+
4456+instance FromJSON NodeJVMStats where
4457+ parseJSON _ = pure NodeJVMStats
4458+
4459+instance FromJSON NodeProcessStats where
4460+ parseJSON _ = pure NodeProcessStats
4461+
4462+instance FromJSON NodeOSStats where
4463+ parseJSON _ = pure NodeOSStats
4464+
4465+instance FromJSON NodeIndicesStats where
4466+ parseJSON _ = pure NodeIndicesStats
4467+
4468+parseNodeStats :: FullNodeId -> Object -> Parser NodeStats
4469+parseNodeStats fnid o = do
4470+ breakers <- o .: "breakers"
4471+ NodeStats <$> o .: "name"
4472+ <*> pure fnid
4473+ <*> breakers .: "parent"
4474+ <*> breakers .: "request"
4475+ <*> breakers .: "fielddata"
4476+ <*> o .: "http"
4477+ <*> o .: "transport"
4478+ <*> o .: "fs"
4479+ <*> o .: "network"
4480+ <*> o .: "thread_pool"
4481+ <*> o .: "jvm"
4482+ <*> o .: "process"
4483+ <*> o .: "os"
4484+ <*> o .: "indices"
4363
4485
4364parseNodeInfo :: FullNodeId -> Object -> Parser NodeInfo
4486parseNodeInfo :: FullNodeId -> Object -> Parser NodeInfo
4365parseNodeInfo nid o =
4487parseNodeInfo nid o =
tests/tests.hs+10
@@ -1575,6 +1575,16 @@ main = hspec $ do
1575 Right NodesInfo {..} -> length nodesInfo `shouldBe` 1
1575 Right NodesInfo {..} -> length nodesInfo `shouldBe` 1
1576 Left e -> expectationFailure ("Expected NodesInfo but got " <> show e)
1576 Left e -> expectationFailure ("Expected NodesInfo but got " <> show e)
1577
1577
1578+ describe "getNodesStats" $ do
1579+ it "fetches the responding node when LocalNode is used" $ withTestEnv $ do
1580+ res <- getNodesStats LocalNode
1581+ liftIO $ case res of
1582+ -- This is really just a smoke test for response
1583+ -- parsing. Node stats is so variable, there's not much I can
1584+ -- assert here.
1585+ Right NodesStats {..} -> length nodesStats `shouldBe` 1
1586+ Left e -> expectationFailure ("Expected NodesStats but got " <> show e)
1587+
1578 describe "Enum DocVersion" $ do
1588 describe "Enum DocVersion" $ do
1579 it "follows the laws of Enum, Bounded" $ do
1589 it "follows the laws of Enum, Bounded" $ do
1580 evaluate (succ maxBound :: DocVersion) `shouldThrow` anyErrorCall
1590 evaluate (succ maxBound :: DocVersion) `shouldThrow` anyErrorCall