-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
add(observation): db pool flushes observation #4668
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,51 @@ | ||||||
| {-# LANGUAGE DataKinds #-} | ||||||
| {-# LANGUAGE MonadComprehensions #-} | ||||||
| {-# LANGUAGE NamedFieldPuns #-} | ||||||
| module Observation.SchemaCacheSpec where | ||||||
|
|
||||||
| import Network.Wai (Application) | ||||||
| import ObsHelper | ||||||
| import qualified PostgREST.AppState as AppState | ||||||
| import PostgREST.Config (configDbSchemas) | ||||||
| import PostgREST.Observation | ||||||
| import Protolude | ||||||
| import Test.Hspec (SpecWith, describe, it) | ||||||
| import Test.Hspec.Wai (getState) | ||||||
|
|
||||||
| spec :: SpecWith (SpecState, Application) | ||||||
| spec = describe "Server started with metrics enabled" $ do | ||||||
|
|
||||||
| it "Should emit PoolFlushed, SchemaCacheQueriedObs and SchemaCacheLoadedObs when schema cache is reloaded" $ do | ||||||
| SpecState{specAppState = appState, specObsChan} <- getState | ||||||
| let waitFor = waitForObs specObsChan | ||||||
|
|
||||||
| liftIO $ do | ||||||
| AppState.schemaCacheLoader appState | ||||||
|
|
||||||
| waitFor (1 * sec) "PoolFlushed" $ \x -> [ o | o@PoolFlushed <- pure x ] | ||||||
| waitFor (1 * sec) "SchemaCacheQueriedObs" $ \x -> [ o | o@SchemaCacheQueriedObs{} <- pure x ] | ||||||
| waitFor (1 * sec) "SchemaCacheLoadedObs" $ \x -> [ o | o@SchemaCacheLoadedObs{} <- pure x ] | ||||||
|
|
||||||
|
|
||||||
| it "Should flush pool multiple times when schema reloading retries" $ do | ||||||
| SpecState{specAppState = appState, specObsChan} <- getState | ||||||
| let waitFor = waitForObs specObsChan | ||||||
|
|
||||||
| liftIO $ do | ||||||
| AppState.getConfig appState >>= \cfg -> do | ||||||
| AppState.putConfig appState $ cfg { configDbSchemas = pure "bad_schema" } | ||||||
| AppState.schemaCacheLoader appState | ||||||
|
|
||||||
| waitFor (1 * sec) "PoolFlushed 1" $ \x -> [ o | o@PoolFlushed <- pure x ] | ||||||
| waitFor (1 * sec) "SchemaCacheErrorObs" $ \x -> [ o | o@SchemaCacheErrorObs{} <- pure x ] | ||||||
|
|
||||||
| -- Restore configuration | ||||||
| AppState.putConfig appState cfg | ||||||
|
|
||||||
| -- Wait for 2 seconds so that retry can happen | ||||||
| waitFor (2 * sec) "PoolFlushed 2" $ \x -> [ o | o@PoolFlushed <- pure x ] | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Curious, what does the
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The text in quotes is just description and used for easier tracking the exact spot of failure in case we miss a specific observation. So in this case it is just to make sure that it is easy to identify which specific
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, so the I might have misunderstood the function, I was thinking the postgrest/test/observability/ObsHelper.hs Lines 194 to 195 in 0e820b9
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes.
Constructor names and
Upon failure, without Constructor names are used to produce output with all observations that were produced until failure (so that it is easier to diagnose the test failures), along the lines of: Looking at this and the test code above, you know one "PoolFlushed" was received ( |
||||||
| waitFor (1 * sec) "SchemaCacheQueriedObs" $ \x -> [ o | o@SchemaCacheQueriedObs{} <- pure x ] | ||||||
| waitFor (1 * sec) "SchemaCacheLoadedObs" $ \x -> [ o | o@SchemaCacheLoadedObs{} <- pure x ] | ||||||
|
|
||||||
| where | ||||||
| sec = 1000000 | ||||||
Uh oh!
There was an error while loading. Please reload this page.