|
| 1 | +# 1. My First Asset |
| 2 | + |
| 3 | +Before starting the tour, make sure you have a running Compass instance. You can refer this [installation guide](../installation). |
| 4 | + |
| 5 | +## 1.1 Introduction |
| 6 | + |
| 7 | +In Compass, we call every metadata that you input as an [Asset](../concepts/asset). All your tables, dashboards, topics, jobs are an example of assets. |
| 8 | + |
| 9 | +In this section, we will help you to build your first Asset and hopefully it will give your clear idea about what an Asset is in Compass. |
| 10 | + |
| 11 | +## 1.2 Hello, ~~World~~ Asset! |
| 12 | + |
| 13 | +Let's imagine we have a `postgres` instance that we keep referring to as our `main-postgres`. Inside it there is a database called `my-database` that has plenty of tables. One of the tables is named `orders`, and below is how you represent that `table` as an Compass' Asset. |
| 14 | + |
| 15 | +```json |
| 16 | +{ |
| 17 | + "urn": "main-postgres:my-database.orders", |
| 18 | + "type": "table", |
| 19 | + "service": "postgres", |
| 20 | + "name": "orders", |
| 21 | + "data": { |
| 22 | + "database": "my-database", |
| 23 | + "namespace": "main-postgres" |
| 24 | + } |
| 25 | +} |
| 26 | +``` |
| 27 | + |
| 28 | +- **urn** is a unique name you assign to an asset. You need to make sure you don't have a duplicate urns across all of your assets because Compass treats `urn` as an identifier of your asset. For this example, we use the following format to make sure our urn is unique, `{NAMESPACE}:{DB_NAME}.{TABLE_NAME}`. (more info about URN generation can be found [here](../guides/urn-generation)) |
| 29 | + |
| 30 | +- **type** is your Asset's type. The value for type has to be recognizable by Compass. More info about Asset's Type can be found [here](../concepts/type). |
| 31 | + |
| 32 | +- **service** can be seen as the source of your asset. `service` can be anything, in this case since our `orders` table resides in `postgres`, we can just put `postgres` as the service. |
| 33 | + |
| 34 | +- **name** is the name of your asset, it does not have to be unique. We don't need to worry to get mixed up if there are other tables with the same name, `urn` will be the main identifier for your asset, that is why we need to make it unique across all of your assets. |
| 35 | + |
| 36 | +- **data** can hold your asset's extra details if there is any. In the example, we use it to store information of the **database name** and the **alias/namespace** that we use when referring the postgres instance. |
| 37 | + |
| 38 | +## 1.3 Sending your first asset to Compass |
| 39 | + |
| 40 | +Here is the asset that we built on previous section. |
| 41 | + |
| 42 | +```json |
| 43 | +{ |
| 44 | + "urn": "main-postgres:my-database.orders", |
| 45 | + "type": "table", |
| 46 | + "service": "postgres", |
| 47 | + "name": "orders", |
| 48 | + "data": { |
| 49 | + "database": "my-database", |
| 50 | + "namespace": "main-postgres" |
| 51 | + } |
| 52 | +} |
| 53 | +``` |
| 54 | +Let's send this into Compass so that it would be discoverable. |
| 55 | + |
| 56 | +As of now, Compass supports ingesting assets via `gRPC` and `http`. In this example, we will use `http` to send your first asset to Compass. |
| 57 | +Compass exposes an API `[PATCH] /v1beta1/assets` to upload your asset. |
| 58 | + |
| 59 | +```bash |
| 60 | +curl --location --request PATCH 'http://localhost:8080/v1beta1/assets' \ |
| 61 | +--header 'Content-Type: application/json' \ |
| 62 | +--header 'Compass-User-UUID: john.doe@example.com' \ |
| 63 | +--data-raw '{ |
| 64 | + "asset": { |
| 65 | + "urn": "main-postgres:my-database.orders", |
| 66 | + "type": "table", |
| 67 | + "service": "postgres", |
| 68 | + "name": "orders", |
| 69 | + "data": { |
| 70 | + "database": "my-database", |
| 71 | + "namespace": "main-postgres" |
| 72 | + } |
| 73 | + } |
| 74 | +}' |
| 75 | +``` |
| 76 | + |
| 77 | +There are a few things to notice here: |
| 78 | +1. The HTTP method used is `PATCH`. This is because Compass does not have a dedicated `Create` API, it uses a single API to `Patch / Create` an asset instead. So when updating or patching your asset, you can use the same API. |
| 79 | + |
| 80 | +2. Compass requires `Compass-User-UUID` header to be in the request. More information about the identity header can be found [here](../concepts/user). To simplify this tour, let's just use `john.doe@example.com`. |
| 81 | + |
| 82 | +3. When sending our asset to Compass, we need to put our asset object inside an `asset` field as shown in the sample curl above. |
| 83 | + |
| 84 | +On a success insertion, your will receive below response: |
| 85 | + |
| 86 | +```json |
| 87 | +{ "id": "cebeb793-8933-434c-b38f-beb6dbad91a5" } |
| 88 | +``` |
| 89 | + |
| 90 | +**id** is an identifier of your asset. Unlike `urn` which is provided by you, `id` is auto generated by Compass if there was no asset found with the given URN. |
| 91 | + |
| 92 | +## Conclusion |
| 93 | + |
| 94 | +Now that you have successfully ingested your asset to Compass, we can now search and find it via Compass. |
| 95 | + |
| 96 | +In the next section, we will see how Compass can help you in searching and discovering your assets. |
0 commit comments