server: add code field to warning object in metadata API responses

PR-URL: https://github.com/hasura/graphql-engine-mono/pull/8601
GitOrigin-RevId: 7034c0a04b87c44731680917aa3946084b705959
This commit is contained in:
paritosh-08 2023-04-06 08:08:03 +05:30 committed by hasura-bot
parent 3cef692dd7
commit 774075a709
7 changed files with 34 additions and 14 deletions

View File

@ -213,6 +213,7 @@ HTTP/1.1 200 OK
"inconsistent_objects": [], "inconsistent_objects": [],
"warnings: [ "warnings: [
{ {
"code": "illegal-event-trigger-name",
"message": "The event trigger with name \"weird]name]\" may not work as expected, hasura suggests to use only alphanumeric, underscore and hyphens in an event trigger name", "message": "The event trigger with name \"weird]name]\" may not work as expected, hasura suggests to use only alphanumeric, underscore and hyphens in an event trigger name",
"type": "event_trigger", "type": "event_trigger",
"name": "event_trigger weird]name] in table hasura.authors in source mssql" "name": "event_trigger weird]name] in table hasura.authors in source mssql"
@ -232,6 +233,7 @@ HTTP/1.1 400 Bad Request
"error": "failed due to metadata warnings", "error": "failed due to metadata warnings",
"internal": [ "internal": [
{ {
"code": "illegal-event-trigger-name",
"message": "The event trigger with name \"weird]name]\" may not work as expected, hasura suggests to use only alphanumeric, underscore and hyphens in an event trigger name", "message": "The event trigger with name \"weird]name]\" may not work as expected, hasura suggests to use only alphanumeric, underscore and hyphens in an event trigger name",
"name": "event_trigger weird]name] in table hasura.authors in source mssql", "name": "event_trigger weird]name] in table hasura.authors in source mssql",
"type": "event_trigger" "type": "event_trigger"

View File

@ -120,7 +120,8 @@ tests = do
is_consistent: true is_consistent: true
inconsistent_objects: [] inconsistent_objects: []
warnings: warnings:
- message: >- - code: source-cleanup-failed
message: >-
Could not cleanup the source '"postgres"' while dropping it from the graphql-engine as it is Could not cleanup the source '"postgres"' while dropping it from the graphql-engine as it is
inconsistent. Please consider cleaning the resources created by the graphql engine, refer inconsistent. Please consider cleaning the resources created by the graphql engine, refer
https://hasura.io/docs/latest/graphql/core/event-triggers/remove-event-triggers/#clean-footprints-manually https://hasura.io/docs/latest/graphql/core/event-triggers/remove-event-triggers/#clean-footprints-manually

View File

@ -45,7 +45,8 @@ tests = do
code: metadata-warnings code: metadata-warnings
error: failed due to metadata warnings error: failed due to metadata warnings
internal: internal:
- message: The event trigger with name "weird$name" may not work as expected, hasura suggests to use only alphanumeric, underscore and hyphens in an event trigger name - code: illegal-event-trigger-name
message: The event trigger with name "weird$name" may not work as expected, hasura suggests to use only alphanumeric, underscore and hyphens in an event trigger name
name: event_trigger weird$name in table hasura.table1 in source postgres name: event_trigger weird$name in table hasura.table1 in source postgres
type: event_trigger type: event_trigger
path: $.args path: $.args
@ -60,7 +61,8 @@ tests = do
is_consistent: true is_consistent: true
inconsistent_objects: [] inconsistent_objects: []
warnings: warnings:
- message: The event trigger with name "weird$name" may not work as expected, hasura suggests to use only alphanumeric, underscore and hyphens in an event trigger name - code: illegal-event-trigger-name
message: The event trigger with name "weird$name" may not work as expected, hasura suggests to use only alphanumeric, underscore and hyphens in an event trigger name
name: event_trigger weird$name in table hasura.table1 in source postgres name: event_trigger weird$name in table hasura.table1 in source postgres
type: event_trigger type: event_trigger
|] |]

View File

@ -77,7 +77,8 @@ tests = describe "weird trigger names are allowed" do
[yaml| [yaml|
message: success message: success
warnings: warnings:
- message: >- - code: illegal-event-trigger-name
message: >-
The event trigger with name "weird]name]" may not work as expected, The event trigger with name "weird]name]" may not work as expected,
hasura suggests to use only alphanumeric, underscore and hyphens in hasura suggests to use only alphanumeric, underscore and hyphens in
an event trigger name an event trigger name

View File

@ -58,7 +58,7 @@ compareTimeLimitWith userTimeLimitMaybe = do
-- warning message if the user time limit API limit is greater than the cloud time limit API limit -- warning message if the user time limit API limit is greater than the cloud time limit API limit
warningMessage :: MaxTime -> MaxTime -> MetadataWarning warningMessage :: MaxTime -> MaxTime -> MetadataWarning
warningMessage userTimeLimit cloudTimeLimit = warningMessage userTimeLimit cloudTimeLimit =
MetadataWarning (MOSource defaultSource) $ MetadataWarning WCTimeLimitExceededSystemLimit (MOSource defaultSource) $
"the configured time limit: " "the configured time limit: "
<> tshow (seconds $ unMaxTime userTimeLimit) <> tshow (seconds $ unMaxTime userTimeLimit)
<> " exceeds the project time limit: " <> " exceeds the project time limit: "

View File

@ -114,7 +114,7 @@ postDropSourceHookHelper oldSchemaCache sourceName sourceMetadataBackend = do
<> " Please consider cleaning the resources created by the graphql engine," <> " Please consider cleaning the resources created by the graphql engine,"
<> " refer https://hasura.io/docs/latest/graphql/core/event-triggers/remove-event-triggers/#clean-footprints-manually" <> " refer https://hasura.io/docs/latest/graphql/core/event-triggers/remove-event-triggers/#clean-footprints-manually"
HL.unLogger logger $ MetadataLog HL.LevelWarn message J.Null HL.unLogger logger $ MetadataLog HL.LevelWarn message J.Null
warn $ MetadataWarning (MOSource sourceName) message warn $ MetadataWarning WCSourceCleanupFailed (MOSource sourceName) message
Just sourceInfo -> runPostDropSourceHook defaultSource sourceInfo Just sourceInfo -> runPostDropSourceHook defaultSource sourceInfo
runClearMetadata :: runClearMetadata ::
@ -327,7 +327,7 @@ runReplaceMetadataV2' ReplaceMetadataV2 {..} = do
mkEventTriggerObjID tableName triggerName = MOSourceObjId source $ AB.mkAnyBackend $ SMOTableObj @b tableName $ MTOTrigger triggerName mkEventTriggerObjID tableName triggerName = MOSourceObjId source $ AB.mkAnyBackend $ SMOTableObj @b tableName $ MTOTrigger triggerName
mkIllegalEventTriggerNameWarning (tableName, triggerName) = mkIllegalEventTriggerNameWarning (tableName, triggerName) =
-- TODO: capture the path as well -- TODO: capture the path as well
MetadataWarning (mkEventTriggerObjID tableName triggerName) $ MetadataWarning WCIllegalEventTriggerName (mkEventTriggerObjID tableName triggerName) $
"The event trigger with name " "The event trigger with name "
<> dquote (triggerNameToTxt triggerName) <> dquote (triggerNameToTxt triggerName)
<> " may not work as expected, hasura suggests to use only alphanumeric, underscore and hyphens in an event trigger name" <> " may not work as expected, hasura suggests to use only alphanumeric, underscore and hyphens in an event trigger name"
@ -485,7 +485,7 @@ runReplaceMetadataV2' ReplaceMetadataV2 {..} = do
<> " Please refer https://hasura.io/docs/latest/graphql/core/event-triggers/remove-event-triggers/#clean-up-event-trigger-footprints-manually " <> " Please refer https://hasura.io/docs/latest/graphql/core/event-triggers/remove-event-triggers/#clean-up-event-trigger-footprints-manually "
<> " to delete the sql triggers from the database manually." <> " to delete the sql triggers from the database manually."
<> " For more details, please refer https://hasura.io/docs/latest/graphql/core/event-triggers/index.html " <> " For more details, please refer https://hasura.io/docs/latest/graphql/core/event-triggers/index.html "
warn $ MetadataWarning sourceObjID message warn $ MetadataWarning WCSourceCleanupFailed sourceObjID message
logger $ MetadataLog HL.LevelWarn message J.Null logger $ MetadataLog HL.LevelWarn message J.Null
Just sourceConfig -> do Just sourceConfig -> do
for_ droppedEventTriggers $ for_ droppedEventTriggers $
@ -496,7 +496,7 @@ runReplaceMetadataV2' ReplaceMetadataV2 {..} = do
case tableNameMaybe of case tableNameMaybe of
Nothing -> do Nothing -> do
let message = sqlTriggerError triggerName let message = sqlTriggerError triggerName
warn $ MetadataWarning sourceObjID message warn $ MetadataWarning WCSourceCleanupFailed sourceObjID message
logger $ MetadataLog HL.LevelWarn message J.Null logger $ MetadataLog HL.LevelWarn message J.Null
Just tableName -> Just tableName ->
dropTriggerAndArchiveEvents @b sourceConfig triggerName tableName dropTriggerAndArchiveEvents @b sourceConfig triggerName tableName
@ -504,7 +504,7 @@ runReplaceMetadataV2' ReplaceMetadataV2 {..} = do
case OMap.lookup retainedNewTriggerName oldTriggersMap of case OMap.lookup retainedNewTriggerName oldTriggersMap of
Nothing -> do Nothing -> do
let message = sqlTriggerError retainedNewTriggerName let message = sqlTriggerError retainedNewTriggerName
warn $ MetadataWarning sourceObjID message warn $ MetadataWarning WCSourceCleanupFailed sourceObjID message
logger $ MetadataLog HL.LevelWarn message J.Null logger $ MetadataLog HL.LevelWarn message J.Null
Just oldTriggerConf -> do Just oldTriggerConf -> do
let newTriggerOps = etcDefinition retainedNewTriggerConf let newTriggerOps = etcDefinition retainedNewTriggerConf
@ -519,7 +519,7 @@ runReplaceMetadataV2' ReplaceMetadataV2 {..} = do
case tableNameMaybe of case tableNameMaybe of
Nothing -> do Nothing -> do
let message = sqlTriggerError retainedNewTriggerName let message = sqlTriggerError retainedNewTriggerName
warn $ MetadataWarning sourceObjID message warn $ MetadataWarning WCSourceCleanupFailed sourceObjID message
logger $ MetadataLog HL.LevelWarn message J.Null logger $ MetadataLog HL.LevelWarn message J.Null
Just tableName -> Just tableName ->
dropDanglingSQLTrigger @b sourceConfig retainedNewTriggerName tableName (HS.fromList $ catMaybes droppedOps) dropDanglingSQLTrigger @b sourceConfig retainedNewTriggerName tableName (HS.fromList $ catMaybes droppedOps)

View File

@ -21,6 +21,7 @@ module Hasura.RQL.DDL.Warnings
runMetadataWarnings, runMetadataWarnings,
mkSuccessResponseWithWarnings, mkSuccessResponseWithWarnings,
successMsgWithWarnings, successMsgWithWarnings,
WarningCode (..),
) )
where where
@ -74,18 +75,31 @@ instance ToJSON AllowWarnings where
toBool AllowWarnings = True toBool AllowWarnings = True
toBool NoAllowWarnings = False toBool NoAllowWarnings = False
data WarningCode
= WCSourceCleanupFailed
| WCIllegalEventTriggerName
| WCTimeLimitExceededSystemLimit
deriving (Eq, Ord)
instance ToJSON WarningCode where
toJSON WCIllegalEventTriggerName = "illegal-event-trigger-name"
toJSON WCTimeLimitExceededSystemLimit = "time-limit-exceeded-system-limit"
toJSON WCSourceCleanupFailed = "source-cleanup-failed"
data MetadataWarning = MetadataWarning data MetadataWarning = MetadataWarning
{ _mwMetadataObj :: MetadataObjId, { _mwCode :: WarningCode,
_mwMetadataObj :: MetadataObjId,
_mwMessage :: Text _mwMessage :: Text
} }
deriving (Eq, Ord) deriving (Eq, Ord)
instance ToJSON MetadataWarning where instance ToJSON MetadataWarning where
toJSON (MetadataWarning mObj msg) = toJSON (MetadataWarning code mObj msg) =
Aeson.object Aeson.object
[ "message" .= msg, [ "message" .= msg,
"type" .= moiTypeName mObj, "type" .= moiTypeName mObj,
"name" .= moiName mObj "name" .= moiName mObj,
"code" .= code
] ]
type MetadataWarnings = Seq MetadataWarning type MetadataWarnings = Seq MetadataWarning