Skip to content

Commit dcdf9ee

Browse files
committed
Adds Workflows GraphQL examples and docs
1 parent f5b3aaf commit dcdf9ee

File tree

1 file changed

+152
-24
lines changed

1 file changed

+152
-24
lines changed

src/content/docs/workflows/observability/metrics-analytics.mdx

Lines changed: 152 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -38,31 +38,159 @@ Workflows GraphQL datasets require an `accountTag` filter with your Cloudflare a
3838

3939
### Examples
4040

41-
To query the sum of `readQueries`, `writeQueries` for a given `$databaseId`, grouping by `databaseId` and `date`:
41+
To query the count (number of workflow invocations) and sum of `wallTime` for a given `$workflowName` between `$datetimeStart` and `$datetimeEnd`, grouping by `date`:
4242

4343
```graphql
44-
query {
45-
viewer {
46-
accounts(filter: { accountTag: $accountId }) {
47-
d1AnalyticsAdaptiveGroups(
48-
limit: 10000
49-
filter: {
50-
date_geq: $startDate
51-
date_leq: $endDate
52-
databaseId: $databaseId
53-
}
54-
orderBy: [date_DESC]
55-
) {
56-
sum {
57-
readQueries
58-
writeQueries
59-
}
60-
dimensions {
61-
date
62-
databaseId
63-
}
64-
}
65-
}
66-
}
44+
{
45+
viewer {
46+
accounts(filter: { accountTag: $accountTag }) {
47+
wallTime: workflowsAdaptiveGroups(
48+
limit: 10000
49+
filter: {
50+
datetimeHour_geq: $datetimeStart,
51+
datetimeHour_leq: $datetimeEnd,
52+
workflowName: $workflowName
53+
}
54+
orderBy: [count_DESC]
55+
) {
56+
count
57+
sum {
58+
wallTime
59+
}
60+
dimensions {
61+
date: datetimeHour
62+
}
63+
}
64+
}
65+
}
6766
}
6867
```
68+
69+
Here we are doing the same for `wallTime`, `instanceRuns` and `stepCount` in the same query:
70+
71+
```graphql
72+
{
73+
viewer {
74+
accounts(filter: { accountTag: $accountTag }) {
75+
instanceRuns: workflowsAdaptiveGroups(
76+
limit: 10000
77+
filter: {
78+
datetimeHour_geq: $datetimeStart
79+
datetimeHour_leq: $datetimeEnd
80+
workflowName: $workflowName
81+
eventType: "WORKFLOW_START"
82+
}
83+
orderBy: [count_DESC]
84+
) {
85+
count
86+
dimensions {
87+
date: datetimeHour
88+
}
89+
}
90+
stepCount: workflowsAdaptiveGroups(
91+
limit: 10000
92+
filter: {
93+
datetimeHour_geq: $datetimeStart
94+
datetimeHour_leq: $datetimeEnd
95+
workflowName: $workflowName
96+
eventType: "STEP_START"
97+
}
98+
orderBy: [count_DESC]
99+
) {
100+
count
101+
dimensions {
102+
date: datetimeHour
103+
}
104+
}
105+
wallTime: workflowsAdaptiveGroups(
106+
limit: 10000
107+
filter: {
108+
datetimeHour_geq: $datetimeStart
109+
datetimeHour_leq: $datetimeEnd
110+
workflowName: $workflowName
111+
}
112+
orderBy: [count_DESC]
113+
) {
114+
count
115+
sum {
116+
wallTime
117+
}
118+
dimensions {
119+
date: datetimeHour
120+
}
121+
}
122+
}
123+
}
124+
}
125+
```
126+
127+
Here lets query `workflowsAdaptive` for raw data about `$instanceId` between `$datetimeStart` and `$datetimeEnd`:
128+
129+
```
130+
{
131+
viewer {
132+
accounts(filter: { accountTag: $accountTag }) {
133+
workflowsAdaptive(
134+
limit: 100
135+
filter: {
136+
datetime_geq: $datetimeStart
137+
datetime_leq: $datetimeEnd
138+
instanceId: $instanceId
139+
}
140+
orderBy: [datetime_ASC]
141+
) {
142+
datetime
143+
eventType
144+
workflowName
145+
instanceId
146+
stepName
147+
stepCount
148+
wallTime
149+
}
150+
}
151+
}
152+
}
153+
```
154+
155+
#### GraphQL query variables
156+
157+
Example values for the query variables:
158+
159+
```json
160+
{
161+
"accountTag": "fedfa729a5b0ecfd623bca1f9000f0a22",
162+
"datetimeStart": "2024-10-20T00:00:00Z",
163+
"datetimeEnd": "2024-10-29T00:00:00Z",
164+
"workflowName": "shoppingCart",
165+
"instanceId": "ecc48200-11c4-22a3-b05f-88a3c1c1db81"
166+
}
167+
```
168+
169+
As said above, you can use [introspection](/analytics/graphql-api/features/discovery/introspection/) with your favorite GraphQL client to discover the available fields and types of the Workflows datasets, but here are some of our `workflowsAdaptiveGroups` dimensions:
170+
171+
* date - The date when trigger was triggered
172+
* datetimeFifteenMinutes - The date and time truncated to fifteen minutes
173+
* datetimeFiveMinutes - The date and time truncated to five minutes
174+
* datetimeHour - The date and time truncated to the hour
175+
* datetimeMinute - The date and time truncated to the minute
176+
* eventType - Event type
177+
* instanceId - Instance Id
178+
* stepCount - Step number
179+
* stepName - Step name
180+
* workflowName - Workflow Name
181+
182+
And here's a list of `eventType`s you can filter on:
183+
184+
* WORKFLOW_QUEUED
185+
* ORKFLOW_START
186+
* WORKFLOW_SUCCESS
187+
* WORKFLOW_FAILURE
188+
* WORKFLOW_TERMINATED
189+
* STEP_START
190+
* STEP_SUCCESS
191+
* STEP_FAILURE
192+
* SLEEP_START
193+
* SLEEP_COMPLETE
194+
* ATTEMPT_START
195+
* ATTEMPT_SUCCESS
196+
* ATTEMPT_FAILURE

0 commit comments

Comments
 (0)