mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-16 09:51:59 +03:00
2eab6a89aa
These must have gotten messed up during a refactor. As a consequence almost all samples received so far fall into the single erroneous 0 to 1K seconds (originally supposed to be 1ms?) bucket. I also re-thought what the numbers should be, but these are still arbitrary and might want adjusting in the future.
52 lines
2.4 KiB
Haskell
52 lines
2.4 KiB
Haskell
{-# LANGUAGE DuplicateRecordFields #-}
|
|
module Hasura.Server.TelemetrySpec (spec) where
|
|
|
|
import Hasura.Prelude
|
|
|
|
import qualified Data.Aeson as A
|
|
import Hasura.Server.Telemetry.Counters
|
|
import Test.Hspec
|
|
|
|
spec :: Spec
|
|
spec = do
|
|
telemetryCountersTests
|
|
|
|
-- NOTE: this test is effectful/stateful; if we need to we can implement an
|
|
-- operation to clear metric store.
|
|
telemetryCountersTests :: Spec
|
|
telemetryCountersTests = do
|
|
describe "request timing counters" $ do
|
|
it "is at first empty" $ do
|
|
fmap serviceTimingMetrics dumpServiceTimingMetrics `shouldReturn` []
|
|
|
|
-- excercise accumulating and buckets:
|
|
let expected =
|
|
-- NOTE: ordering is arbitrary here (and hence fragile)
|
|
[ServiceTimingMetric {
|
|
dimensions = RequestDimensions Miss Mutation Local HTTP
|
|
, bucket = RunningTimeBucket {bucketGreaterThan = 0.050}
|
|
, metrics = RequestTimingsCount {telemTimeIO = 2, telemTimeTot = 1.050, telemCount = 2}},
|
|
ServiceTimingMetric {
|
|
dimensions = RequestDimensions Hit Mutation Local HTTP
|
|
, bucket = RunningTimeBucket {bucketGreaterThan = 0}
|
|
, metrics = RequestTimingsCount {telemTimeIO = 2, telemTimeTot = 0.001, telemCount = 2}},
|
|
ServiceTimingMetric {
|
|
dimensions = RequestDimensions Hit Query Remote WebSocket
|
|
, bucket = RunningTimeBucket {bucketGreaterThan = 1.000}
|
|
, metrics = RequestTimingsCount {telemTimeIO = 1, telemTimeTot = 5.000, telemCount = 1}}]
|
|
|
|
it "accumulates as expected" $ do
|
|
-- bucket 0sec - 1ms:
|
|
recordTimingMetric (RequestDimensions Hit Mutation Local HTTP) (RequestTimings 1 0.0001)
|
|
recordTimingMetric (RequestDimensions Hit Mutation Local HTTP) (RequestTimings 1 0.0009)
|
|
-- bucket 50ms - 1 sec:
|
|
recordTimingMetric (RequestDimensions Miss Mutation Local HTTP) (RequestTimings 1 0.0510)
|
|
recordTimingMetric (RequestDimensions Miss Mutation Local HTTP) (RequestTimings 1 0.9990)
|
|
-- bucket 1 sec - 1 hour:
|
|
recordTimingMetric (RequestDimensions Hit Query Remote WebSocket) (RequestTimings 1 5.0000)
|
|
fmap serviceTimingMetrics dumpServiceTimingMetrics `shouldReturn` expected
|
|
|
|
it "serializes and deserializes properly" $ do
|
|
fmap (fmap serviceTimingMetrics . A.eitherDecode . A.encode) dumpServiceTimingMetrics
|
|
`shouldReturn` Right expected
|