Skip to content

Commit 94da7a0

Browse files
Oxyjunthomasgauvin
andauthored
[KV] Adding new info on metric/analytics API (#16328)
* Converting existing PR for new chapters on KV. * Replacing tab with two spaces to conform schema. * Replacing tabs with spaces to conform to schema. * Trying a different way of specifying KV.yaml file. * Removing layout: changelog syntax. * thomasgauvin: update changelog to include status for dashboard * Redundant change to the branch to test PR update. * Update src/content/changelogs/kv.yaml * Apply suggestions from code review --------- Co-authored-by: Thomas Gauvin <[email protected]> Co-authored-by: Thomas Gauvin <[email protected]>
1 parent 3f74612 commit 94da7a0

File tree

4 files changed

+201
-0
lines changed

4 files changed

+201
-0
lines changed

src/content/changelogs/kv.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
link: "/kv/platform/changelog/"
3+
productName: Workers KV
4+
productLink: "/kv/"
5+
productArea: Developer platform
6+
productAreaLink: /workers/platform/changelog/platform/
7+
entries:
8+
9+
- publish_date: "2024-08-08"
10+
title: New KV Analytics API
11+
description: |-
12+
13+
Workers KV now has a new [metrics dashboard](/kv/observability/metrics-analytics/#view-metrics-in-the-dashboard) and [analytics API](/kv/observability/metrics-analytics/#query-via-the-graphql-api) that leverages the [GraphQL Analytics API](/analytics/graphql-api/) used by many other Cloudflare products. The new analytics API provides per-account and per-namespace metrics for both operations and storage, including latency metrics for read and write operations to Workers KV.
14+
15+
The legacy Workers KV [analytics REST API](/api/operations/workers-kv-request-analytics-query-request-analytics) will be turned off as of January 31st, 2025.
16+
Developers using this API will receive a series of email notifications prior to the shutdown of the legacy API.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
pcx_content_type: navigation
3+
title: Observability
4+
sidebar:
5+
order: 5
6+
7+
---
8+
9+
import { DirectoryListing } from "~/components"
10+
11+
<DirectoryListing />
Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
---
2+
pcx_content_type: concept
3+
title: Metrics and analytics
4+
sidebar:
5+
order: 10
6+
7+
---
8+
9+
KV exposes analytics that allow you to inspect requests and storage across all namespaces in your account.
10+
11+
The metrics displayed in the [Cloudflare dashboard](https://dash.cloudflare.com/) charts are queried from Cloudflare’s [GraphQL Analytics API](/analytics/graphql-api/). You can access the metrics [programmatically](#query-via-the-graphql-api) via GraphQL or HTTP client.
12+
13+
## Metrics
14+
15+
KV currently exposes the below metrics:
16+
17+
| Dataset | GraphQL Dataset Name | Description |
18+
| ----------------------- | --------------------------- | ------------------------------------------------------------- |
19+
| Operations | `kvOperationsAdaptiveGroups`| This dataset consists of the operations made to your KV namespaces. |
20+
| Storage | `kvStorageAdaptiveGroups` | This dataset consists of the storage details of your KV namespaces. |
21+
22+
Metrics can be queried (and are retained) for the past 31 days.
23+
24+
## View metrics in the dashboard
25+
26+
Per-namespace analytics for KV are available in the Cloudflare dashboard. To view current and historical metrics for a database:
27+
28+
1. Log in to the [Cloudflare dashboard](https://dash.cloudflare.com) and select your account.
29+
2. Go to [**Workers & Pages** > **KV**](https://dash.cloudflare.com/?to=/:account/workers/kv/namespaces).
30+
3. Select an existing namespace.
31+
4. Select the **Metrics** tab.
32+
33+
You can optionally select a time window to query. This defaults to the last 24 hours.
34+
35+
## Query via the GraphQL API
36+
37+
You can programmatically query analytics for your KV namespaces via the [GraphQL Analytics API](/analytics/graphql-api/). This API queries the same datasets as the Cloudflare dashboard, and supports GraphQL [introspection](/analytics/graphql-api/features/discovery/introspection/).
38+
39+
To get started using the [GraphQL Analytics API](/analytics/graphql-api/), follow the documentation to setup [Authentication for the GraphQL Analytics API](/analytics/graphql-api/getting-started/authentication/).
40+
41+
To use the GraphQL API to retrieve KV's datasets, you must provide the `accountTag` filter with your Cloudflare Account ID. The GraphQL datasets for KV include:
42+
43+
- `kvOperationsAdaptiveGroups`
44+
- `kvStorageAdaptiveGroups`
45+
46+
### Examples
47+
48+
The following are common GraphQL queries that you can use to retrieve information about KV analytics. These queries make use of variables `$accountTag`, `$date_geq`, `$date_leq`, and `$namespaceId`, which should be set as GraphQL variables or replaced in line. These variables should look similar to these:
49+
50+
```json
51+
{
52+
"accountTag":"<YOUR_ACCOUNT_ID>",
53+
"namespaceId": "<YOUR_KV_NAMESPACE_ID>",
54+
"date_geq": "2024-07-15",
55+
"date_leq": "2024-07-30"
56+
}
57+
```
58+
59+
#### Operations
60+
61+
To query the sum of read, write, delete, and list operations for a given `namespaceId` and for a given date range (`date_geq` and `date_leq`), grouped by `date` and `actionType`:
62+
63+
```graphql
64+
query {
65+
viewer {
66+
accounts(filter: { accountTag: $accountTag }) {
67+
kvOperationsAdaptiveGroups(
68+
filter: { namespaceId: $namespaceId, date_geq: $date_geq, date_leq: $date_leq }
69+
limit: 10000
70+
orderBy: [date_DESC]
71+
) {
72+
sum {
73+
requests
74+
}
75+
dimensions {
76+
date
77+
actionType
78+
}
79+
}
80+
}
81+
}
82+
}
83+
```
84+
85+
86+
To query the distribution of the latency for read operations for a given `namespaceId` within a given date range (`date_geq`, `date_leq`):
87+
88+
```graphql
89+
query {
90+
viewer {
91+
accounts(filter: { accountTag: $accountTag }) {
92+
kvOperationsAdaptiveGroups(
93+
filter: { namespaceId: $namespaceId, date_geq: $date_geq, date_leq: $date_leq, actionType: "read" }
94+
limit: 10000
95+
) {
96+
sum {
97+
requests
98+
}
99+
dimensions {
100+
actionType
101+
}
102+
quantiles {
103+
latencyMsP25
104+
latencyMsP50
105+
latencyMsP75
106+
latencyMsP90
107+
latencyMsP99
108+
latencyMsP999
109+
}
110+
}
111+
}
112+
}
113+
}
114+
```
115+
116+
To query your account-wide read, write, delete, and list operations across all KV namespaces:
117+
118+
```graphql
119+
query {
120+
viewer {
121+
accounts(filter: { accountTag: $accountTag }) {
122+
kvOperationsAdaptiveGroups(filter: { date_geq: $date_geq, date_leq: $date_leq }, limit: 10000) {
123+
sum {
124+
requests
125+
}
126+
dimensions {
127+
actionType
128+
}
129+
}
130+
}
131+
}
132+
}
133+
```
134+
135+
#### Storage
136+
137+
To query the storage details (`keyCount` and `byteCount`) of a KV namespace for every day of a given date range:
138+
139+
```graphql
140+
query Viewer {
141+
viewer {
142+
accounts(filter: { accountTag: $accountTag }) {
143+
kvStorageAdaptiveGroups(
144+
filter: { date_geq: $date_geq, date_leq: $date_leq, namespaceId: $namespaceId }
145+
limit: 10000
146+
orderBy: [date_DESC]
147+
) {
148+
max {
149+
keyCount
150+
byteCount
151+
}
152+
dimensions {
153+
date
154+
}
155+
}
156+
}
157+
}
158+
}
159+
```
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
pcx_content_type: changelog
3+
title: Changelog
4+
sidebar:
5+
order: 8
6+
changelog_file_name:
7+
- kv
8+
9+
---
10+
11+
import { ProductChangelog } from "~/components"
12+
13+
{/* Actual content lives in /data/changelogs/kv.yaml. Update the file there for new entries to appear here. For more details, refer to https://developers.cloudflare.com/style-guide/documentation-content-strategy/content-types/changelog/#yaml-file */}
14+
15+
<ProductChangelog />

0 commit comments

Comments
 (0)