Skip to content

Commit 0a04c07

Browse files
kushsharmaravisuhag
authored andcommitted
docs: add namespace in cli and api specs
Signed-off-by: Kush Sharma <[email protected]>
1 parent 87f5ca9 commit 0a04c07

File tree

3 files changed

+213
-10
lines changed

3 files changed

+213
-10
lines changed

docs/docs/concepts/internals.md

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ This document details information about how Compass interfaces with elasticsearc
44

55
## Index Setup
66

7-
There is a migration command in compass to setup all storages. Once the migration is executed, all types are being created (if does not exist). When a type is created, an index is created in elasticsearch by it's name. All created indices are aliased to the `universe` index, which is used to run the search when all types need to be searched, or when `filter[type]` is not specifed in the Search API.
8-
9-
The indices are also configured with a camel case tokenizer, to support proper lexing of some resources that use camel case in their nomenclature \(protobuf names for instance\). Given below is a sample of the index settings that are used:
7+
There is a migration command in compass to setup all storages. The indices are configured with a camel case tokenizer, to support proper lexing of some resources that use camel case in their nomenclature \(protobuf names for instance\). Given below is a sample of the index settings that are used:
108

119
```javascript
1210
// PUT http://${ES_HOST}/{index}
@@ -28,6 +26,30 @@ The indices are also configured with a camel case tokenizer, to support proper l
2826
}
2927
```
3028

29+
One shared index is created for all services and tenants but each request(read/write) is routed to a unique shard for each tenant. Compass categorize tenants into two tires, `shared` and `dedicated`. For shared tenants, all the requests will be routed by namespace id over a single shard in an index. For dedicated tenants, each tenant will have its own index. Note, a single index will have N number of `types` same as the number of `Services` supported in Compass. This design will ensure, all the document insert/query requests are only confined to a single shard(in case of shared) or a single index(in case of dedicated).
30+
Details on why we did this is available at [issue #208](https://github.com/odpf/compass/issues/208).
31+
32+
## Postgres
33+
34+
To enforce multi-tenant restrictions at the database level, [Row Level Security](https://www.postgresql.org/docs/current/ddl-rowsecurity.html) is used. RLS requires Postgres users used for application database connection not to be a table owner or a superuser else all RLS are bypassed by default. That means a Postgres user that is migrating the application and a user that is used to serve the app should both be different.
35+
36+
To create a postgres user
37+
```sql
38+
CREATE USER "compass_user" WITH PASSWORD 'compass';
39+
GRANT CONNECT ON DATABASE "compass" TO "compass_user";
40+
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO "compass_user";
41+
GRANT ALL ON ALL SEQUENCES IN SCHEMA public TO "compass_user";
42+
GRANT ALL ON ALL FUNCTIONS IN SCHEMA public TO "compass_user";
43+
44+
ALTER DEFAULT PRIVILEGES IN SCHEMA "public" GRANT SELECT, INSERT, UPDATE, DELETE, REFERENCES
45+
ON TABLES TO "compass_user";
46+
ALTER DEFAULT PRIVILEGES IN SCHEMA "public" GRANT USAGE ON SEQUENCES TO "compass_user";
47+
ALTER DEFAULT PRIVILEGES IN SCHEMA "public" GRANT EXECUTE ON FUNCTIONS TO "compass_user";
48+
```
49+
50+
A middleware for grpc looks for `x-namespace-id` header to extract tenant id if not found falls back to `default` namespace.
51+
Same could be passed in a `jwt token` of Authentication Bearer with `namespace_id` as a claim.
52+
3153
## Search
3254

3355
We use elasticsearch's `multi_match` search for running our queries. Depending on whether there are additional filter's specified during search, we augment the query with a custom script query that filter's the result set.

docs/docs/reference/api.md

Lines changed: 153 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
# API
1+
# Compass
22
Documentation of our Compass API with gRPC and gRPC-Gateway.
33

4-
## Version: 0.2.1
4+
## Version: 0.3.0
55

66
**License:** [Apache License 2.0](https://github.com/odpf/compass/blob/main/LICENSE)
77

@@ -317,6 +317,8 @@ API for querying documents. 'text' is fuzzy matched against all the available da
317317
| text | query | text to search for (fuzzy) | No | string |
318318
| rankby | query | descendingly sort based on a numeric field in the asset. the nested field is written with period separated field name. eg, "rankby[data.profile.usage_count]" | No | string |
319319
| size | query | number of results to return | No | long |
320+
| include_fields | query | | No | [ string ] |
321+
| offset | query | offset parameter defines the offset from the first result you want to fetch | No | long |
320322

321323
##### Responses
322324

@@ -1097,6 +1099,111 @@ Get all assets starred by a user
10971099

10981100
## default
10991101

1102+
### /v1beta1/namespaces
1103+
1104+
#### GET
1105+
##### Summary
1106+
1107+
List namespace
1108+
1109+
##### Description
1110+
1111+
List all created namespaces
1112+
1113+
##### Responses
1114+
1115+
| Code | Description | Schema |
1116+
| ---- | ----------- | ------ |
1117+
| 200 | A successful response. | [ListNamespacesResponse](#listnamespacesresponse) |
1118+
| 400 | Returned when the data that user input is wrong. | [Status](#status) |
1119+
| 404 | Returned when the resource does not exist. | [Status](#status) |
1120+
| 409 | Returned when the resource already exist. | [Status](#status) |
1121+
| 500 | Returned when theres is something wrong on the server side. | [Status](#status) |
1122+
| default | An unexpected error response. | [Status](#status) |
1123+
1124+
#### POST
1125+
##### Summary
1126+
1127+
Create a namespace
1128+
1129+
##### Description
1130+
1131+
Create a new namespace, throws error if already exists
1132+
1133+
##### Parameters
1134+
1135+
| Name | Located in | Description | Required | Schema |
1136+
| ---- | ---------- | ----------- | -------- | ------ |
1137+
| body | body | | Yes | [CreateNamespaceRequest](#createnamespacerequest) |
1138+
1139+
##### Responses
1140+
1141+
| Code | Description | Schema |
1142+
| ---- | ----------- | ------ |
1143+
| 200 | A successful response. | [CreateNamespaceResponse](#createnamespaceresponse) |
1144+
| 400 | Returned when the data that user input is wrong. | [Status](#status) |
1145+
| 404 | Returned when the resource does not exist. | [Status](#status) |
1146+
| 409 | Returned when the resource already exist. | [Status](#status) |
1147+
| 500 | Returned when theres is something wrong on the server side. | [Status](#status) |
1148+
| default | An unexpected error response. | [Status](#status) |
1149+
1150+
### /v1beta1/namespaces/{urn}
1151+
1152+
#### GET
1153+
##### Summary
1154+
1155+
Get namespace
1156+
1157+
##### Description
1158+
1159+
Fetch a namespace details, throws error if doesn't exists. Use id or name as urn.
1160+
1161+
##### Parameters
1162+
1163+
| Name | Located in | Description | Required | Schema |
1164+
| ---- | ---------- | ----------- | -------- | ------ |
1165+
| urn | path | set either id or name | Yes | string |
1166+
1167+
##### Responses
1168+
1169+
| Code | Description | Schema |
1170+
| ---- | ----------- | ------ |
1171+
| 200 | A successful response. | [GetNamespaceResponse](#getnamespaceresponse) |
1172+
| 400 | Returned when the data that user input is wrong. | [Status](#status) |
1173+
| 404 | Returned when the resource does not exist. | [Status](#status) |
1174+
| 409 | Returned when the resource already exist. | [Status](#status) |
1175+
| 500 | Returned when theres is something wrong on the server side. | [Status](#status) |
1176+
| default | An unexpected error response. | [Status](#status) |
1177+
1178+
#### PUT
1179+
##### Summary
1180+
1181+
Update namespace
1182+
1183+
##### Description
1184+
1185+
Update an existing namespace, throws error if doesn't exists. Use id or name as urn.
1186+
1187+
##### Parameters
1188+
1189+
| Name | Located in | Description | Required | Schema |
1190+
| ---- | ---------- | ----------- | -------- | ------ |
1191+
| urn | path | set either id or name | Yes | string |
1192+
| body | body | | Yes | { **"metadata"**: object, **"state"**: string } |
1193+
1194+
##### Responses
1195+
1196+
| Code | Description | Schema |
1197+
| ---- | ----------- | ------ |
1198+
| 200 | A successful response. | [UpdateNamespaceResponse](#updatenamespaceresponse) |
1199+
| 400 | Returned when the data that user input is wrong. | [Status](#status) |
1200+
| 404 | Returned when the resource does not exist. | [Status](#status) |
1201+
| 409 | Returned when the resource already exist. | [Status](#status) |
1202+
| 500 | Returned when theres is something wrong on the server side. | [Status](#status) |
1203+
| default | An unexpected error response. | [Status](#status) |
1204+
1205+
## default
1206+
11001207
### /v1beta1/search
11011208

11021209
#### GET
@@ -1115,6 +1222,8 @@ API for querying documents. 'text' is fuzzy matched against all the available da
11151222
| text | query | text to search for (fuzzy) | No | string |
11161223
| rankby | query | descendingly sort based on a numeric field in the asset. the nested field is written with period separated field name. eg, "rankby[data.profile.usage_count]" | No | string |
11171224
| size | query | number of results to return | No | long |
1225+
| include_fields | query | | No | [ string ] |
1226+
| offset | query | offset parameter defines the offset from the first result you want to fetch | No | long |
11181227

11191228
##### Responses
11201229

@@ -1535,6 +1644,21 @@ Request to be sent to create a discussion
15351644
| ---- | ---- | ----------- | -------- |
15361645
| id | string | | No |
15371646

1647+
#### CreateNamespaceRequest
1648+
1649+
| Name | Type | Description | Required |
1650+
| ---- | ---- | ----------- | -------- |
1651+
| id | string | optional, if not specified will be auto generated | No |
1652+
| metadata | object | key value pairs as metadata for the namespace | No |
1653+
| name | string | | No |
1654+
| state | string | | No |
1655+
1656+
#### CreateNamespaceResponse
1657+
1658+
| Name | Type | Description | Required |
1659+
| ---- | ---- | ----------- | -------- |
1660+
| id | string | | No |
1661+
15381662
#### CreateTagAssetRequest
15391663

15401664
Request to be sent to create a tag
@@ -1708,6 +1832,12 @@ Request to be sent to create a tag's template
17081832
| ---- | ---- | ----------- | -------- |
17091833
| data | [ [v1beta1.Asset](#v1beta1asset) ] | | No |
17101834

1835+
#### GetNamespaceResponse
1836+
1837+
| Name | Type | Description | Required |
1838+
| ---- | ---- | ----------- | -------- |
1839+
| namespace | [Namespace](#namespace) | | No |
1840+
17111841
#### GetTagByAssetAndTemplateResponse
17121842

17131843
| Name | Type | Description | Required |
@@ -1742,6 +1872,21 @@ Request to be sent to create a tag's template
17421872
| type | string | | No |
17431873
| urn | string | | No |
17441874

1875+
#### ListNamespacesResponse
1876+
1877+
| Name | Type | Description | Required |
1878+
| ---- | ---- | ----------- | -------- |
1879+
| namespaces | [ [Namespace](#namespace) ] | | No |
1880+
1881+
#### Namespace
1882+
1883+
| Name | Type | Description | Required |
1884+
| ---- | ---- | ----------- | -------- |
1885+
| id | string | | No |
1886+
| metadata | object | key value pairs as metadata for the namespace | No |
1887+
| name | string | | No |
1888+
| state | string | | No |
1889+
17451890
#### NodeAttributes
17461891

17471892
| Name | Type | Description | Required |
@@ -1851,6 +1996,12 @@ Request to be sent to create a tag's template
18511996
| ---- | ---- | ----------- | -------- |
18521997
| UpdateCommentResponse | object | | |
18531998

1999+
#### UpdateNamespaceResponse
2000+
2001+
| Name | Type | Description | Required |
2002+
| ---- | ---- | ----------- | -------- |
2003+
| UpdateNamespaceResponse | object | | |
2004+
18542005
#### UpdateTagAssetResponse
18552006

18562007
| Name | Type | Description | Required |

docs/docs/reference/cli.md

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,25 +133,55 @@ view discussion for the given ID
133133
134134
observe the lineage of metadata
135135
136+
## `compass namespace`
137+
138+
Manage namespaces
139+
140+
### `compass namespace create [flags]`
141+
142+
create a new namespace
143+
144+
```
145+
-n, --name string namespace unique name
146+
-s, --state string is namespace shared with existing tenants or a dedicated one (default "shared")
147+
````
148+
149+
### `compass namespace list [flags]`
150+
151+
lists all namespaces
152+
153+
```
154+
-o, --out -o json flag to control output viewing, for json -o json (default "table")
155+
````
156+
157+
### `compass namespace view <id>`
158+
159+
view namespace for the given uuid or name
160+
136161
## `compass search <text> [flags]`
137162
138163
query the metadata available
139164
140165
```
141-
-f, --filter string --filter=field_key1:val1,key2:val2,key3:val3 gives exact match for values
142-
-q, --query string --query=--filter=field_key1:val1 supports fuzzy search
143-
-r, --rankby string --rankby=<numeric_field>
144-
-s, --size uint32 --size=10 maximum size of response query
166+
-f, --filter string --filter=field_key1:val1,key2:val2,key3:val3 gives exact match for values
167+
-n, --namespace string namespace id or name (default "00000000-0000-0000-0000-000000000000")
168+
-q, --query string --query=--filter=field_key1:val1 supports fuzzy search
169+
-r, --rankby string --rankby=<numeric_field>
170+
-s, --size uint32 --size=10 maximum size of response query
145171
````
146172
147173
## `compass server <command>`
148174
149175
Run compass server
150176
151-
### `compass server migrate`
177+
### `compass server migrate [flags]`
152178
153179
Run storage migration
154180
181+
```
182+
--down rollback migration one step
183+
````
184+
155185
### `compass server start`
156186

157187
Start server on default port 8080

0 commit comments

Comments
 (0)