With Davis CoPilot for Workflows, you can automate problem summarization and ask Davis CoPilot to suggest remediation steps that can be sent to your email.
With this guide:
This guide is written for:
To help teams manage observability costs more effectively, this use case demonstrates how to automate the identification and optimization of expensive Dynatrace Query Language (DQL) executions.
A simple workflow, scheduled to run once daily, detects the top 20 most costly queries from the past 24 hours. By integrating Davis CoPilot into this workflow, each query is automatically analyzed for optimization opportunities.
Davis CoPilot provides tailored recommendations to reduce query costs and sends these insights directly to the respective query authors via email. This helps you to proactively control costs and improve query efficiency without manual intervention.
To use Davis CoPilot in Workflows, ensure that you have:
ALLOW davis-copilot:conversations:execute;) permission.Select + Add task.
In the search field, enter DQL query, or select Execute DQL Query from the list of the Workflow actions.
Rename the task to dql_query.
In the DQL query field, add the following query:
fetch dt.system.query_executions, from:now() - 24h| filter status == "SUCCEEDED"| summarize executionCount = count(), sum = sum(scanned_bytes.on_demand), user = collectDistinct(user.email), app = collectDistinct(client.application_context), by: {query_string}| sort sum desc| limit 20
In the Prompt field, enter the following prompt:
I've supplied you with result of a DQL Grail query. This result has information about top 20 expensive executed by users in last 24 hours.Create a json array with the following info:- query: that is the original query that is given in the result- email: email of the user who executed the query- improvement: tell me the reasons why query is expensive and how can user improve it- context: any relevant context where the query is executed and so onMake sure that there is no other text beside the json array and no backticks or anything
In the Additional context field, enter the following:
{{result('dql_query').records}}
Enable Auto-trim.
Set Document retrieval to Dynatrace.
Rename the task to davis_copilot.
Select + Add task.
In the search field, enter Send email, or select Send email from the list of the Workflow actions. For more information about the Email workflow actions, see Email Connector.
Enter the workflow task name.
Configure the fields:
In Configure email > Recipients, set the To field to {{_.list.email}}. This is the email of the user.
In the Content, Subject field, enter the following text: Expensive query executed.
Set the Message field to the following:
Hi {{_.list.email}},You've executed an expensive query that could be optimized to reduce costs. Below are the details to help you improve it:---### Query Details:- **Original Query**:`{{_.list.query}}`- **Suggested Improvements**:{{_.list.improvement}}- **Context**:{{_.list.context}}---Taking these steps can help improve performance and reduce expenses.Thanks,Your Admin
Go to the Options tab and configure the fields as following:
list in the Item variable name field and enter {{result('davis_copilot').text}} in the List field.Select Deploy to deploy the workflow.
Select Run to test the workflow.