Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow retrieving query traces over HTTP #4243

Merged
merged 7 commits into from
Dec 21, 2022
Merged

Allow retrieving query traces over HTTP #4243

merged 7 commits into from
Dec 21, 2022

Conversation

lutter
Copy link
Collaborator

@lutter lutter commented Dec 14, 2022

With these changes, if the request header X-GraphTraceQuery is set to the right value, the response to a GraphQL query will include a trace of the SQL queries that were run to generate the GraphQL response. That trace looks like

{
  "data": { .. },
  "trace": {
    "query": "<GraphQL query>",
    "query_id": "e89d81e9ce262e07-d019a5d7d56a8920",
    "block": 10096796,
    "elapsed_ms": 6,
    "pairs": {
      "query": "/* controller='filter',application='sgd44',route='e89d81e9ce262e07-d019a5d7d56a8920',action='10096796' */\tselect 'Pair' as entity, to_jsonb(c.*) as data from (select  * \t  from \"sgd44\".\"pair\" c\t where c.block_range @> $1\t\t order by \"id\", block_range\t limit 2) c -- binds: [10096796]",
      "elapsed_ms": 0,
      "entity_count": 2,
      "token0": {
        "query": "<SQL query>",
        "elapsed_ms": 0,
        "entity_count": 2
      },
      "token1": {
        "query": "<SQL query>",
        "elapsed_ms": 0,
        "entity_count": 2
      }
    },
    "tokens": {
      "query": "<SQL query>",
      "elapsed_ms": 0,
      "entity_count": 2
    }
  }
}

Since generating traces can be expensive, the right value for X-GraphTraceQuery is configurable through the environment variable GRAPH_GRAPHQL_TRACE_TOKEN; only if the header contains that token will a trace be generated.

This PR also simplifies the usage of graphman query: it is no longer necessary to set GRAPH_LOG_QUERY_TIMING when running it to get the query output and trace from the command line. The JSON that graphman query generates as a trace is the same as is returned for HTTP queries, and much more readable than it was before.

Copy link
Collaborator

@leoyvens leoyvens left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! I didn't know we had these traces

@lutter lutter merged commit 4ca9399 into master Dec 21, 2022
@lutter lutter deleted the lutter/timing branch December 21, 2022 21:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants