You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/docs/concepts/internals.md
+25-3Lines changed: 25 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,9 +4,7 @@ This document details information about how Compass interfaces with elasticsearc
4
4
5
5
## Index Setup
6
6
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:
10
8
11
9
```javascript
12
10
// PUT http://${ES_HOST}/{index}
@@ -28,6 +26,30 @@ The indices are also configured with a camel case tokenizer, to support proper l
28
26
}
29
27
```
30
28
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
+
CREATEUSER "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"GRANTSELECT, 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
+
31
53
## Search
32
54
33
55
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.
@@ -317,6 +317,8 @@ API for querying documents. 'text' is fuzzy matched against all the available da
317
317
| text | query | text to search for (fuzzy) | No | string |
318
318
| 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 |
319
319
| 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 |
320
322
321
323
##### Responses
322
324
@@ -1097,6 +1099,111 @@ Get all assets starred by a user
1097
1099
1098
1100
## default
1099
1101
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 |
| 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
+
1100
1207
### /v1beta1/search
1101
1208
1102
1209
#### GET
@@ -1115,6 +1222,8 @@ API for querying documents. 'text' is fuzzy matched against all the available da
1115
1222
| text | query | text to search for (fuzzy) | No | string |
1116
1223
| 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 |
1117
1224
| 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 |
1118
1227
1119
1228
##### Responses
1120
1229
@@ -1535,6 +1644,21 @@ Request to be sent to create a discussion
1535
1644
| ---- | ---- | ----------- | -------- |
1536
1645
| id | string || No |
1537
1646
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
+
1538
1662
#### CreateTagAssetRequest
1539
1663
1540
1664
Request to be sent to create a tag
@@ -1708,6 +1832,12 @@ Request to be sent to create a tag's template
1708
1832
| ---- | ---- | ----------- | -------- |
1709
1833
| data |[[v1beta1.Asset](#v1beta1asset)]|| No |
1710
1834
1835
+
#### GetNamespaceResponse
1836
+
1837
+
| Name | Type | Description | Required |
1838
+
| ---- | ---- | ----------- | -------- |
1839
+
| namespace |[Namespace](#namespace)|| No |
1840
+
1711
1841
#### GetTagByAssetAndTemplateResponse
1712
1842
1713
1843
| Name | Type | Description | Required |
@@ -1742,6 +1872,21 @@ Request to be sent to create a tag's template
1742
1872
| type | string || No |
1743
1873
| urn | string || No |
1744
1874
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
+
1745
1890
#### NodeAttributes
1746
1891
1747
1892
| Name | Type | Description | Required |
@@ -1851,6 +1996,12 @@ Request to be sent to create a tag's template
0 commit comments