server: add active_livequeries, active_streaming_subscriptions EKG metrics

PR-URL: https://github.com/hasura/graphql-engine-mono/pull/5627
GitOrigin-RevId: 3f010dbe29f78ba9e79f545acc26a6a56e0b5d28
This commit is contained in:
Naveen Naidu 2022-08-25 21:20:39 +05:30 committed by hasura-bot
parent 0bdfd3ae39
commit a4c06deba3
2 changed files with 21 additions and 1 deletions

View File

@ -205,6 +205,7 @@ addLiveQuery
liftIO $ EKG.Gauge.inc $ smActiveSubscriptions serverMetrics
liftIO $ Prometheus.Gauge.inc $ pmActiveSubscriptions prometheusMetrics
liftIO $ EKG.Gauge.inc $ smActiveLiveQueries serverMetrics
pure $ SubscriberDetails handlerId cohortKey subscriberId
where
@ -294,6 +295,7 @@ addStreamSubscriptionQuery
liftIO $ EKG.Gauge.inc $ smActiveSubscriptions serverMetrics
liftIO $ Prometheus.Gauge.inc $ pmActiveSubscriptions prometheusMetrics
liftIO $ EKG.Gauge.inc $ smActiveStreamingSubscriptions serverMetrics
pure $ SubscriberDetails handlerId (cohortKey, cohortCursorTVar) subscriberId
where
@ -332,6 +334,7 @@ removeLiveQuery logger serverMetrics prometheusMetrics lqState lqId@(SubscriberD
sequence_ mbCleanupIO
liftIO $ EKG.Gauge.dec $ smActiveSubscriptions serverMetrics
liftIO $ Prometheus.Gauge.dec $ pmActiveSubscriptions prometheusMetrics
liftIO $ EKG.Gauge.dec $ smActiveLiveQueries serverMetrics
where
lqMap = _ssLiveQueryMap lqState
@ -390,6 +393,7 @@ removeStreamingQuery logger serverMetrics prometheusMetrics subscriptionState (S
sequence_ mbCleanupIO
liftIO $ EKG.Gauge.dec $ smActiveSubscriptions serverMetrics
liftIO $ Prometheus.Gauge.dec $ pmActiveSubscriptions prometheusMetrics
liftIO $ EKG.Gauge.dec $ smActiveStreamingSubscriptions serverMetrics
where
streamQMap = _ssStreamQueryMap subscriptionState

View File

@ -67,6 +67,18 @@ data
"schema_cache_metadata_resource_version"
'GaugeType
()
-- | Current number active live queries
ActiveLiveQueries ::
ServerMetricsSpec
"active_livequeries"
'GaugeType
()
-- | Current number of streaming subscriptions
ActiveStreaming ::
ServerMetricsSpec
"active_streaming_subscriptions"
'GaugeType
()
-- | Mutable references for the server metrics. See `ServerMetricsSpec` for a
-- description of each metric.
@ -77,7 +89,9 @@ data ServerMetrics = ServerMetrics
smNumEventsFetchedPerBatch :: !Distribution,
smNumEventHTTPWorkers :: !Gauge,
smEventQueueTime :: !Distribution,
smSchemaCacheMetadataResourceVersion :: !Gauge
smSchemaCacheMetadataResourceVersion :: !Gauge,
smActiveLiveQueries :: !Gauge,
smActiveStreamingSubscriptions :: !Gauge
}
createServerMetrics :: Store ServerMetricsSpec -> IO ServerMetrics
@ -89,4 +103,6 @@ createServerMetrics store = do
smNumEventHTTPWorkers <- createGauge NumEventHTTPWorkers () store
smEventQueueTime <- createDistribution EventQueueTime () store
smSchemaCacheMetadataResourceVersion <- createGauge SchemaCacheMetadataResourceVersion () store
smActiveLiveQueries <- createGauge ActiveLiveQueries () store
smActiveStreamingSubscriptions <- createGauge ActiveStreaming () store
pure ServerMetrics {..}