This article describes the Snuba query language (SnQL).
A series of
- 1 minute Quick use of The latest version of Docker Sentry-CLI – create version
- Quick use of Docker start Sentry-CLI – 30 seconds start Source Maps
- Sentry For React
- Sentry For Vue
- Sentry-CLI usage details
- Sentry Web Performance Monitoring – Web Vitals
- Sentry Web performance monitoring – Metrics
- Sentry Web Performance Monitoring – Trends
- Sentry Web Front-end Monitoring – Best Practices (Official Tutorial)
- Sentry Backend Monitoring – Best Practices (Official Tutorial)
- Sentry Monitor – Discover Big data query analysis engine
- Sentry Monitoring – Dashboards Large screen for visualizing data
- Sentry Monitor – Environments Distinguishes event data from different deployment Environments
- Sentry monitoring – Security Policy Reports Security policies
- Sentry monitoring – Search Indicates the actual Search
- Sentry monitoring – Alerts Indicates an alarm
- Sentry Monitor – Distributed Tracing
- Sentry Monitoring – Distributed Tracing 101 for Full-stack Developers
- Sentry Monitoring – Snuba Data Mid platform Architecture introduction (Kafka+Clickhouse)
- Sentry – Snuba Data Model
- Sentry Monitoring – Snuba Data Mid-Platform Architecture (Introduction to Query Processing)
- Sentry official JavaScript SDK introduction and debugging guide
- Sentry Monitoring – Snuba Data Mid-platform architecture (writing and testing Snuba queries)
Here is the SnQL query structure:
MATCH simple | join | subquery
SELECT [expressions] | [aggregations BY expressions]
ARRAY JOIN [column]
WHERE condition [[AND | OR] condition]*
HAVING condition [[AND | OR] condition]*
ORDER BY expressions ASC|DESC [, expressions ASC|DESC]*
LIMIT expression BY n
LIMIT n
OFFSET n
GRANULARITY n
TOTALS boolean
Copy the code
These queries are sent as strings to the /:dataset/ SNQL endpoint, encoded as a JSON body in the following format:
{
"query": "<query>"."dataset": "<dataset>"."consistent": bool,
"turbo": bool,
"debug": bool,
}
Copy the code
The dataset is implied by the URL used by the query. In the JSON body, all fields except Query are optional.
MATCH
Our data model is represented by an entity graph. This clause identifies the pattern for the Subgraphs we are querying. Three types of MATCH clauses are currently supported:
Simple:
MATCH (<entity> [SAMPLE n])
This is equivalent to all of our current queries. This is querying data from a single entity (event, transaction, and so on). You can add an optional sample to the query by adding it along with the entity.
For example: MATCH (events)
Subquery:
MATCH { <query> }
Another full SQL query can be inside curly braces. Anything in the SELECT/BY clause of the subquery will be exposed in the external query using the specified alias.
Such as:
MATCH {
MATCH (transactions)
SELECT avg(duration) AS avg_d BY transaction
}
SELECT max(avg_d)
Copy the code
The Join () :
MATCH (<alias>: <entity> [SAMPLE n]) -[<join>]-> (<alias>: <entity> [SAMPLE n])
A join represents a subgraph, which is a subgraph containing multiple relationships between different nodes. 1.. between nodes is currently supported. N, n.. 1 and 1.. 1. Directed relation.
For a JOIN, each entity must have an alias, which is a unique string. Sampling can also be applied to any entity in a Join.
is the string specified in the Entity in Snuba and is shorthand for a set of join conditions. You can have multiple join clauses, separated by commas.
Such as:
MATCH
(e: events) -[grouped]-> (g: groupedmessage),
(e: events) -[assigned]-> (a: groupassignee)
SELECT count(a)AS tot BY e.project_id, g.id
WHERE a.user_id = "somebody"
Copy the code
Join types (left/inner) and join keys are part of the data model, not the query. They are hard-coded in entity code. This is because no entity can securely connect to any other entity in the distributed version of the underlying database.
The tuple provided by the match clause to the WHERE clause looks exactly the same as the tuple generated by the traditional join clause:
[{"e.project_id": 1."g.id": 10}
{"e.project_id": 1."g.id": 11}
{"e.project_id": 2."g.id": 20}... ]Copy the code
SELECT .. BY
This clause specifies which results should be returned in the output. If aggregation exists, everything in the BY clause is treated as a grouping key. If we wanted to aggregate the entire result set, we could do it without the BY clause, but in that case only the aggregate could be contained in the SELECT. Even if there is a BY clause, an empty SELECT clause is invalid.
An expression in a SELECT clause can be a column, an arithmetic, a function, or any combination of the three. If the query is a JOIN, then each column must have a qualified alias that matches one of the entity aliases in the MATCH clause.
WHERE
This is the filter for queries (such as WHERE in SQL) that occur before aggregation.
The condition is an infix expression of the form LHS OP RHS*, where LHS and RHS are literals or expressions. OP refers to a specific operator to compare two values. The operators are =,! =, <, <=, >, >=, IN, NOT IN, LIKE, NOT LIKE, IS NULL, IS NOT NULL. Note that RHS IS optional when operators such as IS NULL are used.
Conditions can be combined using the Boolean keyword AND OR OR. They can also be grouped using ().
HAVING
Works like the WHERE clause, but it applies after the aggregation declared in the SELECT clause. So we can apply conditions here to the result of the aggregate function.
ORDER BY
Specifies an expression that sorts the result set.
LIMIT BY/LIMIT/OFFSET
Self-explanatory, they take integers and set the corresponding values in the Clickhouse query. If the query does not specify limit or offset, they default to 1000 and 0, respectively.
GRANULARITY
An integer that represents the granularity of grouping time-based results.
TOTALS
If set to True, the response from Snuba will have a “total” key with total totals for all selected rows.
SAMPLE
If the node in the MATCH clause does not provide the sampling rate, you can specify it here. In this case, Snuba assigns sample Right to one of the nodes in the query. Sample can be a floating point number between 0 and 1 that represents the percentage of rows to be sampled.
Or it can be an integer greater than 1, representing the number of rows to sample.