mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-15 01:12:56 +03:00
[server] allow feature flags to be overwritten by env vars
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/7659 Co-authored-by: Gil Mizrahi <8547573+soupi@users.noreply.github.com> GitOrigin-RevId: 2a64ff09118aa0b5cbf494c45e4b178de366236b
This commit is contained in:
parent
0680550fd7
commit
ab9c56b343
@ -19,24 +19,27 @@ import Test.Hspec (SpecWith, describe, it)
|
||||
-- We currently don't need the table to exist in order to set up a custom SQL
|
||||
-- stanza.
|
||||
|
||||
featureFlagForNativeQuery :: String
|
||||
featureFlagForNativeQuery = "HASURA_FF_NATIVE_QUERY_INTERFACE"
|
||||
|
||||
spec :: SpecWith GlobalTestEnvironment
|
||||
spec =
|
||||
Fixture.run
|
||||
( NE.fromList
|
||||
[ (Fixture.fixture $ Fixture.Backend Postgres.backendTypeMetadata)
|
||||
{ Fixture.setupTeardown = \(testEnv, _) ->
|
||||
[ Postgres.setupTablesAction [] testEnv
|
||||
],
|
||||
Fixture.customOptions =
|
||||
Just $
|
||||
Fixture.defaultOptions
|
||||
{ Fixture.skipTests =
|
||||
Just "Disabled until we can dynamically switch on Native Access with a command line option in NDAT-452"
|
||||
}
|
||||
}
|
||||
]
|
||||
)
|
||||
tests
|
||||
Fixture.hgeWithEnv [(featureFlagForNativeQuery, "True")] $
|
||||
Fixture.run
|
||||
( NE.fromList
|
||||
[ (Fixture.fixture $ Fixture.Backend Postgres.backendTypeMetadata)
|
||||
{ Fixture.setupTeardown = \(testEnv, _) ->
|
||||
[ Postgres.setupTablesAction [] testEnv
|
||||
],
|
||||
Fixture.customOptions =
|
||||
Just $
|
||||
Fixture.defaultOptions
|
||||
{ Fixture.skipTests = Just "Skipped until we merge the implementation"
|
||||
}
|
||||
}
|
||||
]
|
||||
)
|
||||
tests
|
||||
|
||||
-- ** Setup and teardown
|
||||
|
||||
|
@ -326,7 +326,7 @@ runApp serveOptions = do
|
||||
liftIO $ createServerMetrics $ EKG.subset ServerSubset store
|
||||
pure (EKG.subset EKG.emptyOf store, serverMetrics)
|
||||
prometheusMetrics <- makeDummyPrometheusMetrics
|
||||
runManagedT (App.initialiseServerCtx env globalCtx serveOptions Nothing serverMetrics prometheusMetrics sampleAlways FeatureFlag.defaultValueIO) $ \serverCtx@ServerCtx {..} ->
|
||||
runManagedT (App.initialiseServerCtx env globalCtx serveOptions Nothing serverMetrics prometheusMetrics sampleAlways (FeatureFlag.checkFeatureFlag env)) $ \serverCtx@ServerCtx {..} ->
|
||||
do
|
||||
let Loggers _ _ pgLogger = scLoggers
|
||||
flip App.runPGMetadataStorageAppT (scMetadataDbPool, pgLogger)
|
||||
@ -340,7 +340,7 @@ runApp serveOptions = do
|
||||
initTime
|
||||
Nothing
|
||||
ekgStore
|
||||
FeatureFlag.defaultValueIO
|
||||
(FeatureFlag.checkFeatureFlag env)
|
||||
|
||||
-- | Used only for 'runApp' above.
|
||||
data TestMetricsSpec name metricType tags
|
||||
|
@ -69,7 +69,7 @@ runApp env (HGEOptions rci metadataDbUrl hgeCmd) = do
|
||||
-- It'd be nice if we didn't have to call runManagedT twice here, but
|
||||
-- there is a data dependency problem since the call to runPGMetadataStorageApp
|
||||
-- below depends on serverCtx.
|
||||
runManagedT (initialiseServerCtx env globalCtx serveOptions Nothing serverMetrics prometheusMetrics sampleAlways FeatureFlag.defaultValueIO) $ \serverCtx@ServerCtx {..} -> do
|
||||
runManagedT (initialiseServerCtx env globalCtx serveOptions Nothing serverMetrics prometheusMetrics sampleAlways (FeatureFlag.checkFeatureFlag env)) $ \serverCtx@ServerCtx {..} -> do
|
||||
-- Catches the SIGTERM signal and initiates a graceful shutdown.
|
||||
-- Graceful shutdown for regular HTTP requests is already implemented in
|
||||
-- Warp, and is triggered by invoking the 'closeSocket' callback.
|
||||
@ -87,7 +87,7 @@ runApp env (HGEOptions rci metadataDbUrl hgeCmd) = do
|
||||
GC.ourIdleGC logger (seconds 0.3) (seconds 10) (seconds 60)
|
||||
|
||||
flip runPGMetadataStorageAppT (scMetadataDbPool, pgLogger) . lowerManagedT $ do
|
||||
runHGEServer (const $ pure ()) env serveOptions serverCtx initTime Nothing ekgStore FeatureFlag.defaultValueIO
|
||||
runHGEServer (const $ pure ()) env serveOptions serverCtx initTime Nothing ekgStore (FeatureFlag.checkFeatureFlag env)
|
||||
HCExport -> do
|
||||
GlobalCtx {..} <- initGlobalCtx env metadataDbUrl rci
|
||||
res <- runTxWithMinimalPool _gcMetadataDbConnInfo fetchMetadataFromCatalog
|
||||
|
@ -120,7 +120,7 @@ import Hasura.Server.API.Query (requiresAdmin)
|
||||
import Hasura.Server.App
|
||||
import Hasura.Server.Auth
|
||||
import Hasura.Server.CheckUpdates (checkForUpdates)
|
||||
import Hasura.Server.Init
|
||||
import Hasura.Server.Init hiding (checkFeatureFlag)
|
||||
import Hasura.Server.Limits
|
||||
import Hasura.Server.Logging
|
||||
import Hasura.Server.Metrics (ServerMetrics (..))
|
||||
|
@ -82,7 +82,7 @@ import Hasura.Server.API.V2Query qualified as V2Q
|
||||
import Hasura.Server.Auth (AuthMode (..), UserAuthentication (..))
|
||||
import Hasura.Server.Compression
|
||||
import Hasura.Server.Cors
|
||||
import Hasura.Server.Init
|
||||
import Hasura.Server.Init hiding (checkFeatureFlag)
|
||||
import Hasura.Server.Limits
|
||||
import Hasura.Server.Logging
|
||||
import Hasura.Server.Metrics (ServerMetrics)
|
||||
|
@ -3,7 +3,7 @@
|
||||
-- | Feature Flags are /temporary/ toggles.
|
||||
module Hasura.Server.Init.FeatureFlag
|
||||
( FeatureFlag (..),
|
||||
defaultValueIO,
|
||||
checkFeatureFlag,
|
||||
Identifier (..),
|
||||
FeatureFlags (..),
|
||||
featureFlags,
|
||||
@ -14,6 +14,7 @@ where
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
import Data.Aeson (FromJSON, ToJSON)
|
||||
import Data.Environment qualified as Env
|
||||
import Data.HashMap.Strict qualified as HashMap
|
||||
import Hasura.Prelude
|
||||
|
||||
@ -27,14 +28,19 @@ newtype Identifier = Identifier {getIdentifier :: Text}
|
||||
data FeatureFlag = FeatureFlag
|
||||
{ ffIdentifier :: Identifier,
|
||||
ffDefaultValue :: Bool,
|
||||
ffDescription :: Text
|
||||
ffDescription :: Text,
|
||||
ffEnvVar :: String
|
||||
}
|
||||
deriving stock (Eq, Generic)
|
||||
deriving anyclass (Hashable, FromJSON, ToJSON)
|
||||
|
||||
-- | We hardcode all feature flags to their default value in OSS.
|
||||
defaultValueIO :: FeatureFlag -> IO Bool
|
||||
defaultValueIO = pure . ffDefaultValue
|
||||
-- | In OSS we look for a environment variable or fall back to the default
|
||||
-- value
|
||||
checkFeatureFlag :: Env.Environment -> FeatureFlag -> IO Bool
|
||||
checkFeatureFlag env (FeatureFlag {ffEnvVar = envVar, ffDefaultValue = defaultValue}) =
|
||||
case Env.lookupEnv env envVar of
|
||||
Just found -> pure $ fromMaybe defaultValue (readMaybe found)
|
||||
Nothing -> pure $ defaultValue
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
@ -55,7 +61,8 @@ testFlag =
|
||||
FeatureFlag
|
||||
{ ffIdentifier = Identifier "test-flag",
|
||||
ffDefaultValue = False,
|
||||
ffDescription = "Testing feature flag integration"
|
||||
ffDescription = "Testing feature flag integration",
|
||||
ffEnvVar = "HASURA_FF_TEST_FLAG"
|
||||
}
|
||||
|
||||
nativeQueryInterface :: FeatureFlag
|
||||
@ -63,5 +70,6 @@ nativeQueryInterface =
|
||||
FeatureFlag
|
||||
{ ffIdentifier = Identifier "native-query-interface",
|
||||
ffDefaultValue = False,
|
||||
ffDescription = "Expose custom views, permissions and advanced SQL functionality via custom queries"
|
||||
ffDescription = "Expose custom views, permissions and advanced SQL functionality via custom queries",
|
||||
ffEnvVar = "HASURA_FF_NATIVE_QUERY_INTERFACE"
|
||||
}
|
||||
|
@ -89,7 +89,7 @@ main = do
|
||||
readOnlyMode
|
||||
Nothing -- We are not testing the naming convention here, so defaulting to hasura-default
|
||||
emptyMetadataDefaults
|
||||
FF.defaultValueIO
|
||||
(FF.checkFeatureFlag mempty)
|
||||
cacheBuildParams = CacheBuildParams httpManager (mkPgSourceResolver print) mkMSSQLSourceResolver serverConfigCtx
|
||||
pgLogger = print
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user