feat: add opencensus tracing and metrics support

This commit is contained in:
Vikram Rangnekar
2020-05-23 11:43:57 -04:00
parent b64daaf034
commit 01ad9b71ba
19 changed files with 408 additions and 64 deletions

View File

@ -216,27 +216,23 @@ func addRoles(c *Config, qc *qcode.Compiler) error {
}
func addRole(qc *qcode.Compiler, r Role, t RoleTable) error {
blocked := struct {
readOnly bool
query bool
insert bool
update bool
delete bool
}{true, true, true, true, true}
ro := true // read-only
if r.Name == "anon" {
blocked.query = false
} else {
blocked.readOnly = false
blocked.query = false
blocked.insert = false
blocked.update = false
blocked.delete = false
if r.Name != "anon" {
ro = false
}
if t.ReadOnly != nil {
blocked.readOnly = *t.ReadOnly
ro = *t.ReadOnly
}
blocked := struct {
query bool
insert bool
update bool
delete bool
}{false, ro, ro, ro}
if t.Query.Block != nil {
blocked.query = *t.Query.Block
}
@ -279,11 +275,10 @@ func addRole(qc *qcode.Compiler, r Role, t RoleTable) error {
}
return qc.AddRole(r.Name, t.Name, qcode.TRConfig{
ReadOnly: blocked.readOnly,
Query: query,
Insert: insert,
Update: update,
Delete: del,
Query: query,
Insert: insert,
Update: update,
Delete: del,
})
}

View File

@ -17,7 +17,6 @@ import (
)
func TestCockroachDB(t *testing.T) {
dir, err := ioutil.TempDir("", "temp-cockraochdb-")
if err != nil {
log.Fatal(err)
@ -33,6 +32,7 @@ func TestCockroachDB(t *testing.T) {
err = cmd.Start()
if err != nil {
t.Skip("is CockroachDB installed?: " + err.Error())
return
}
fmt.Println("started temporary cockroach db")

View File

@ -55,13 +55,15 @@ func TestSuperGraph(t *testing.T, db *sql.DB, before func(t *testing.T)) {
config.AllowListFile = "./allow.list"
config.RolesQuery = `SELECT * FROM users WHERE id = $user_id`
blockFalse := false
config.Roles = []core.Role{
core.Role{
Name: "anon",
Tables: []core.RoleTable{
core.RoleTable{Name: "users", Query: core.Query{Limit: 100}},
core.RoleTable{Name: "product", Query: core.Query{Limit: 100}},
core.RoleTable{Name: "line_item", Query: core.Query{Limit: 100}},
core.RoleTable{Name: "users", ReadOnly: &blockFalse, Query: core.Query{Limit: 100}},
core.RoleTable{Name: "product", ReadOnly: &blockFalse, Query: core.Query{Limit: 100}},
core.RoleTable{Name: "line_item", ReadOnly: &blockFalse, Query: core.Query{Limit: 100}},
},
},
}

View File

@ -15,13 +15,13 @@ func TestCockroachDB(t *testing.T) {
url, found := os.LookupEnv("SG_POSTGRESQL_TEST_URL")
if !found {
t.Skip("set the SG_POSTGRESQL_TEST_URL env variable if you want to run integration tests against a PostgreSQL database")
} else {
db, err := sql.Open("pgx", url)
require.NoError(t, err)
integration_tests.DropSchema(t, db)
integration_tests.SetupSchema(t, db)
integration_tests.TestSuperGraph(t, db, func(t *testing.T) {
})
}
db, err := sql.Open("pgx", url)
require.NoError(t, err)
integration_tests.DropSchema(t, db)
integration_tests.SetupSchema(t, db)
integration_tests.TestSuperGraph(t, db, func(t *testing.T) {
})
}

View File

@ -40,11 +40,10 @@ type DeleteConfig struct {
}
type TRConfig struct {
ReadOnly bool
Query QueryConfig
Insert InsertConfig
Update UpdateConfig
Delete DeleteConfig
Query QueryConfig
Insert InsertConfig
Update UpdateConfig
Delete DeleteConfig
}
type trval struct {

View File

@ -207,7 +207,7 @@ func NewFilter() *Exp {
func (com *Compiler) AddRole(role, table string, trc TRConfig) error {
var err error
trv := &trval{readOnly: trc.ReadOnly}
trv := &trval{}
// query config
trv.query.fil, trv.query.filNU, err = compileFilter(trc.Query.Filters)
@ -341,17 +341,17 @@ func (com *Compiler) compileQuery(qc *QCode, op *Operation, role string) error {
}
case QTInsert:
if trv.insert.block || trv.readOnly {
if trv.insert.block {
return fmt.Errorf("insert blocked: %s", field.Name)
}
case QTUpdate:
if trv.update.block || trv.readOnly {
if trv.update.block {
return fmt.Errorf("update blocked: %s", field.Name)
}
case QTDelete:
if trv.delete.block || trv.readOnly {
if trv.delete.block {
return fmt.Errorf("delete blocked: %s", field.Name)
}
}