Skip to content

Commit

Permalink
cli: add support for health_check metadata object in sources
Browse files Browse the repository at this point in the history
PR-URL: hasura/graphql-engine-mono#5287
GitOrigin-RevId: be7e1d19b9875cf05a52a9894cf2bda58b209733
  • Loading branch information
m-Bilal authored and hasura-bot committed Aug 3, 2022
1 parent a1fc55e commit 48a0a34
Show file tree
Hide file tree
Showing 6 changed files with 282 additions and 4 deletions.
1 change: 1 addition & 0 deletions cli/internal/metadataobject/sources/sources.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type SourceWithNormalFields struct {
Configuration yaml.Node `yaml:"configuration"`
QueryTags yaml.Node `yaml:"query_tags,omitempty"`
Customization yaml.Node `yaml:"customization,omitempty"`
HealthCheck yaml.Node `yaml:"health_check,omitempty"`
}
type Source struct {
SourceWithNormalFields `yaml:",inline"`
Expand Down
10 changes: 7 additions & 3 deletions cli/internal/metadataobject/sources/sources_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package sources

import (
"bytes"
"encoding/json"
"io/ioutil"
"testing"

Expand Down Expand Up @@ -51,13 +53,15 @@ func TestSourceConfig_Build(t *testing.T) {
assert.NoError(t, err)
jsonbs, err := goyaml.YAMLToJSON(gotbs)
assert.NoError(t, err)

var pretty_jsonbs bytes.Buffer
err = json.Indent(&pretty_jsonbs, jsonbs, "", " ")
assert.NoError(t, err)
// uncomment following lines to update golden file
// assert.NoError(t, ioutil.WriteFile(tt.wantGolden, jsonbs, os.ModePerm))
// assert.NoError(t, ioutil.WriteFile(tt.wantGolden, pretty_jsonbs.Bytes(), os.ModePerm))

wantbs, err := ioutil.ReadFile(tt.wantGolden)
assert.NoError(t, err)
assert.Equal(t, string(wantbs), string(jsonbs))
assert.Equal(t, string(wantbs), pretty_jsonbs.String())
}
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@
suffix: null
prefix: null
namespace: mynamespace
health_check:
interval: 10
retries: 3
test:
sql: SELECT 1
timeout: 5
tables: !include "s1/tables/tables.yaml"
functions: !include "s1/functions/functions.yaml"
- name: s2
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,254 @@
{"sources": [{"name": "s1", "kind": "postgres", "configuration": {"connection_info": {"database_url": {"from_env": "HASURA_GRAPHQL_DATABASE_URL"}, "isolation_level": "read-committed", "pool_settings": {"idle_timeout": 180, "max_connections": 50, "retries": 1}, "use_prepared_statements": true}}, "query_tags": {"disabled": false, "format": "standard"}, "customization": {"type_names": null, "root_fields": {"suffix": null, "prefix": null, "namespace": "mynamespace"}}, "tables": [{"table": {"name": "t1", "schema": "public"}}, {"table": {"name": "t2", "schema": "public"}}], "functions": [{"function": {"name": "get_t1", "schema": "public"}}, {"function": {"name": "get_t2", "schema": "public"}}]}, {"name": "s2", "kind": "postgres", "configuration": {"connection_info": {"database_url": {"from_env": "HASURA_GRAPHQL_DATABASE_URL"}, "isolation_level": "read-committed", "pool_settings": {"idle_timeout": 180, "max_connections": 50, "retries": 1}, "use_prepared_statements": true}}, "tables": [{"table": {"name": "t1", "schema": "public"}}, {"table": {"name": "t2", "schema": "public"}}], "functions": [{"function": {"name": "get_t1", "schema": "public"}}, {"function": {"name": "get_t2", "schema": "public"}}]}, {"name": "s 3", "kind": "postgres", "configuration": {"connection_info": {"database_url": {"from_env": "HASURA_GRAPHQL_DATABASE_URL"}, "isolation_level": "read-committed", "pool_settings": {"idle_timeout": 180, "max_connections": 50, "retries": 1}, "use_prepared_statements": true}}, "tables": [{"table": {"name": "t1", "schema": "public"}}, {"table": {"name": "t2", "schema": "public"}}], "functions": [{"function": {"name": "get_t1", "schema": "public"}}, {"function": {"name": "get_t2", "schema": "public"}}]}, {"name": "s 4", "kind": "postgres", "configuration": {"connection_info": {"database_url": {"from_env": "HASURA_GRAPHQL_DATABASE_URL"}, "isolation_level": "read-committed", "pool_settings": {"idle_timeout": 180, "max_connections": 50, "retries": 1}, "use_prepared_statements": true}}, "tables": [{"table": {"name": "t1", "schema": "public"}}, {"table": {"name": "t2", "schema": "public"}}], "functions": [{"function": {"name": "get_t1", "schema": "public"}}, {"function": {"name": "get_t2", "schema": "public"}}]}, {"name": "s 5", "kind": "postgres", "configuration": {"connection_info": {"database_url": {"from_env": "HASURA_GRAPHQL_DATABASE_URL"}, "isolation_level": "read-committed", "pool_settings": {"idle_timeout": 180, "max_connections": 50, "retries": 1}, "use_prepared_statements": true}}, "tables": [{"table": {"name": "t1", "schema": "public"}}, {"table": {"name": "t2", "schema": "public"}}], "functions": [{"function": {"name": "get_t1", "schema": "public"}}, {"function": {"name": "get_t2", "schema": "public"}}]}]}
{
"sources": [
{
"name": "s1",
"kind": "postgres",
"configuration": {
"connection_info": {
"database_url": {
"from_env": "HASURA_GRAPHQL_DATABASE_URL"
},
"isolation_level": "read-committed",
"pool_settings": {
"idle_timeout": 180,
"max_connections": 50,
"retries": 1
},
"use_prepared_statements": true
}
},
"query_tags": {
"disabled": false,
"format": "standard"
},
"customization": {
"type_names": null,
"root_fields": {
"suffix": null,
"prefix": null,
"namespace": "mynamespace"
}
},
"health_check": {
"interval": 10,
"retries": 3,
"test": {
"sql": "SELECT 1"
},
"timeout": 5
},
"tables": [
{
"table": {
"name": "t1",
"schema": "public"
}
},
{
"table": {
"name": "t2",
"schema": "public"
}
}
],
"functions": [
{
"function": {
"name": "get_t1",
"schema": "public"
}
},
{
"function": {
"name": "get_t2",
"schema": "public"
}
}
]
},
{
"name": "s2",
"kind": "postgres",
"configuration": {
"connection_info": {
"database_url": {
"from_env": "HASURA_GRAPHQL_DATABASE_URL"
},
"isolation_level": "read-committed",
"pool_settings": {
"idle_timeout": 180,
"max_connections": 50,
"retries": 1
},
"use_prepared_statements": true
}
},
"tables": [
{
"table": {
"name": "t1",
"schema": "public"
}
},
{
"table": {
"name": "t2",
"schema": "public"
}
}
],
"functions": [
{
"function": {
"name": "get_t1",
"schema": "public"
}
},
{
"function": {
"name": "get_t2",
"schema": "public"
}
}
]
},
{
"name": "s 3",
"kind": "postgres",
"configuration": {
"connection_info": {
"database_url": {
"from_env": "HASURA_GRAPHQL_DATABASE_URL"
},
"isolation_level": "read-committed",
"pool_settings": {
"idle_timeout": 180,
"max_connections": 50,
"retries": 1
},
"use_prepared_statements": true
}
},
"tables": [
{
"table": {
"name": "t1",
"schema": "public"
}
},
{
"table": {
"name": "t2",
"schema": "public"
}
}
],
"functions": [
{
"function": {
"name": "get_t1",
"schema": "public"
}
},
{
"function": {
"name": "get_t2",
"schema": "public"
}
}
]
},
{
"name": "s 4",
"kind": "postgres",
"configuration": {
"connection_info": {
"database_url": {
"from_env": "HASURA_GRAPHQL_DATABASE_URL"
},
"isolation_level": "read-committed",
"pool_settings": {
"idle_timeout": 180,
"max_connections": 50,
"retries": 1
},
"use_prepared_statements": true
}
},
"tables": [
{
"table": {
"name": "t1",
"schema": "public"
}
},
{
"table": {
"name": "t2",
"schema": "public"
}
}
],
"functions": [
{
"function": {
"name": "get_t1",
"schema": "public"
}
},
{
"function": {
"name": "get_t2",
"schema": "public"
}
}
]
},
{
"name": "s 5",
"kind": "postgres",
"configuration": {
"connection_info": {
"database_url": {
"from_env": "HASURA_GRAPHQL_DATABASE_URL"
},
"isolation_level": "read-committed",
"pool_settings": {
"idle_timeout": 180,
"max_connections": 50,
"retries": 1
},
"use_prepared_statements": true
}
},
"tables": [
{
"table": {
"name": "t1",
"schema": "public"
}
},
{
"table": {
"name": "t2",
"schema": "public"
}
}
],
"functions": [
{
"function": {
"name": "get_t1",
"schema": "public"
}
},
{
"function": {
"name": "get_t2",
"schema": "public"
}
}
]
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,14 @@
"prefix": null,
"namespace": "mynamespace"
}
},
"health_check": {
"interval": 10,
"retries": 3,
"test": {
"sql": "SELECT 1"
},
"timeout": 5
}
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@
suffix: null
prefix: null
namespace: mynamespace
health_check:
interval: 10
retries: 3
test:
sql: SELECT 1
timeout: 5
tables: "!include default/tables/tables.yaml"
functions: "!include default/functions/functions.yaml"
- name: bg
Expand Down

0 comments on commit 48a0a34

Please sign in to comment.