|
1 | | -# cortextool |
| 1 | +# Cortex Tools |
2 | 2 |
|
3 | | -This tool is designed to interact with the various user facing APIs provided by Cortex, as well as, interact with various backend storage components containing Cortex data. |
| 3 | +This repo contains tools used for interacting with [Cortex](https://github.com/cortexproject/cortex). |
4 | 4 |
|
5 | | -## Config Commands |
| 5 | +* [cortextool](#cortextool): Interacts with user-facing Cortex APIs and backend storage components |
| 6 | +* [chunktool](#chunktool): Interacts with chunks stored and indexed in Cortex storage backends. |
| 7 | +* [logtool](#logtool): Tool which parses Cortex query-frontend logs and formats them for easy analysis. |
| 8 | + |
| 9 | +## cortextool |
| 10 | + |
| 11 | +This tool is designed to interact with the various user-facing APIs provided by Cortex, as well as, interact with various backend storage components containing Cortex data. |
| 12 | + |
| 13 | +### Config Commands |
6 | 14 |
|
7 | 15 | Config commands interact with the Cortex api and read/create/update/delete user configs from Cortex. Specifically a users alertmanager and rule configs can be composed and updated using these commands. |
8 | 16 |
|
9 | | -### Configuration |
| 17 | +#### Configuration |
10 | 18 |
|
11 | 19 | | Env Variables | Flag | Description | |
12 | 20 | | ----------------- | --------- | ------------------------------------------------------------------------------------------------------------- | |
13 | 21 | | CORTEX_ADDRESS | `address` | Addess of the API of the desired Cortex cluster. | |
14 | 22 | | CORTEX_API_KEY | `key` | In cases where the Cortex API is set behind a basic auth gateway, an key can be set as a basic auth password. | |
15 | 23 | | CORTEX_TENANT_ID | `id` | The tenant ID of the Cortex instance to interact with. | |
16 | 24 |
|
17 | | -### Alertmanager |
| 25 | +#### Alertmanager |
18 | 26 |
|
19 | 27 | The following commands are used by users to interact with their Cortex alertmanager configuration, as well as their alert template files. |
20 | 28 |
|
21 | | -#### Alertmanager Get |
| 29 | +##### Alertmanager Get |
22 | 30 |
|
23 | 31 | cortextool alertmanager get |
24 | 32 |
|
25 | | -#### Alertmanager Load |
| 33 | +##### Alertmanager Load |
26 | 34 |
|
27 | 35 | cortextool alertmanager load ./example_alertmanager_config.yaml |
28 | 36 |
|
29 | | -### Rules |
| 37 | +#### Rules |
30 | 38 |
|
31 | 39 | The following commands are used by users to interact with their Cortex ruler configuration. They can load prometheus rule files, as well as interact with individual rule groups. |
32 | 40 |
|
33 | | -#### Rules List |
| 41 | +##### Rules List |
34 | 42 |
|
35 | 43 | This command will retrieve all of the rule groups stored in the specified Cortex instance and print each one by rule group name and namespace to the terminal. |
36 | 44 |
|
37 | 45 | cortextool rules list |
38 | 46 |
|
39 | | -#### Rules Print |
| 47 | +##### Rules Print |
40 | 48 |
|
41 | 49 | This command will retrieve all of the rule groups stored in the specified Cortex instance and print them to the terminal. |
42 | 50 |
|
43 | 51 | cortextool rules print |
44 | 52 |
|
45 | | -#### Rules Get |
| 53 | +##### Rules Get |
46 | 54 |
|
47 | 55 | This command will retrieve the specified rule group from Cortex and print it to the terminal. |
48 | 56 |
|
49 | 57 | cortextool rules get example_namespace example_rule_group |
50 | 58 |
|
51 | | -#### Rules Delete |
| 59 | +##### Rules Delete |
52 | 60 |
|
53 | 61 | This command will retrieve the specified rule group from Cortex and print it to the terminal. |
54 | 62 |
|
55 | 63 | cortextool rules delete example_namespace example_rule_group |
56 | 64 |
|
57 | | -#### Rules Load |
| 65 | +##### Rules Load |
58 | 66 |
|
59 | 67 | This command will load each rule group in the specified files and load them into Cortex. If a rule already exists in Cortex it will be overwritten if a diff is found. |
60 | 68 |
|
@@ -82,21 +90,58 @@ At the end of the run, the command tells you whenever the operation was a succes |
82 | 90 |
|
83 | 91 | It is important to note that a modification can be a PromQL expression lint or a label add to your aggregation. |
84 | 92 |
|
85 | | -# chunktool |
| 93 | +## chunktool |
86 | 94 |
|
87 | 95 | This repo also contains the `chunktool`. A client meant to interact with chunks stored and indexed in cortex backends. |
88 | 96 |
|
89 | | -### Chunk Delete |
| 97 | +##### Chunk Delete |
90 | 98 |
|
91 | 99 | The delete command currently cleans all index entries pointing to chunks in the specified index. Only bigtable and the v10 schema are currently fully supported. This will not delete the entire index entry, only the corresponding chunk entries within the index row. |
92 | 100 |
|
93 | | -### Chunk Migrate |
| 101 | +##### Chunk Migrate |
94 | 102 |
|
95 | 103 | The migrate command helps with migrating chunks across cortex clusters. It also takes care of setting right index in the new cluster as per the specified schema config. |
96 | 104 |
|
97 | 105 | As of now it only supports `Bigtable` or `GCS` as a source to read chunks from for migration while for writing it supports all the storages that Cortex supports. |
98 | 106 | More details about it [here](./pkg/chunk/migrate/README.md) |
99 | 107 |
|
100 | | -## License |
| 108 | +## logtool |
| 109 | + |
| 110 | +A CLI tool to parse Cortex query-frontend logs and formats them for easy analysis. |
| 111 | + |
| 112 | +``` |
| 113 | +Options: |
| 114 | + -dur duration |
| 115 | + only show queries which took longer than this duration, e.g. -dur 10s |
| 116 | + -query |
| 117 | + show the query |
| 118 | + -utc |
| 119 | + show timestamp in UTC time |
| 120 | +``` |
| 121 | + |
| 122 | +Feed logs into it using [`logcli`](https://github.com/grafana/loki/blob/master/docs/getting-started/logcli.md) from Loki, [`kubectl`](https://kubernetes.io/docs/reference/kubectl/overview/) for Kubernetes, `cat` from a file, or any other way to get raw logs: |
| 123 | + |
| 124 | +Loki `logcli` example: |
| 125 | +``` |
| 126 | +$ logcli query '{cluster="us-central1", name="query-frontend", namespace="dev"}' --limit=5000 --since=3h --forward -o raw | ./logtool -dur 5s |
| 127 | +https://logs-dev-ops-tools1.grafana.net/loki/api/v1/query_range?direction=FORWARD&end=1591119479093405000&limit=5000&query=%7Bcluster%3D%22us-central1%22%2C+name%3D%22query-frontend%22%2C+namespace%3D%22dev%22%7D&start=1591108679093405000 |
| 128 | +Common labels: {cluster="us-central1", container_name="query-frontend", job="dev/query-frontend", level="debug", name="query-frontend", namespace="dev", pod_template_hash="7cd4bf469d", stream="stderr"} |
| 129 | +
|
| 130 | +Timestamp TraceID Length Duration Status Path |
| 131 | +2020-06-02 10:38:40.34205349 -0400 EDT 1f2533b40f7711d3 12h0m0s 21.92465802s (200) /api/prom/api/v1/query_range |
| 132 | +2020-06-02 10:40:25.171649132 -0400 EDT 2ac59421db0000d8 168h0m0s 16.378698276s (200) /api/prom/api/v1/query_range |
| 133 | +2020-06-02 10:40:29.698167258 -0400 EDT 3fd088d900160ba8 168h0m0s 20.912864541s (200) /api/prom/api/v1/query_range |
| 134 | +``` |
| 135 | + |
| 136 | +``` |
| 137 | +$ cat query-frontend-logs.log | ./logtool -dur 5s |
| 138 | +Timestamp TraceID Length Duration Status Path |
| 139 | +2020-05-26 13:51:15.0577354 -0400 EDT 76b9939fd5c78b8f 6h0m0s 10.249149614s (200) /api/prom/api/v1/query_range |
| 140 | +2020-05-26 13:52:15.771988849 -0400 EDT 2e7473ab10160630 10h33m0s 7.472855362s (200) /api/prom/api/v1/query_range |
| 141 | +2020-05-26 13:53:46.712563497 -0400 EDT 761f3221dcdd85de 10h33m0s 11.874296689s (200) /api/prom/api/v1/query_range |
| 142 | +``` |
| 143 | + |
| 144 | + |
| 145 | +### License |
101 | 146 |
|
102 | 147 | Licensed Apache 2.0, see [LICENSE](LICENSE). |
0 commit comments