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

tempo-cli: add support for /api/v2/traces endpoint #4127

Merged
merged 9 commits into from
Sep 27, 2024

Conversation

electron0zero
Copy link
Member

@electron0zero electron0zero commented Sep 26, 2024

What this PR does:
Use /api/v2/traces by default to query trace by id and get partial traces for bigger traces, also add --v1 flag in tempo-cli query api trace-id command to query /api/traces endpoint.

see #3941 for more details on /api/v2/traces.

example usage: tempo-cli query api trace-id http://tempo:3200 fd9b20c52c74f67de6a69279bfba3936 --v1 > trace.json

there is a change in default behaviour and you need to use --v1 if you are on a older version of tempo that doesn't support /api/v2/traces or want to use /api/traces, because of that, this change is marked as BREAKING CHANGE


This PR also includes a small change in the way we Marshal the trace.

encoding/json package can't handle +Inf, -Inf, NaN values and will fail to Marshal the response from tracebyid endpoints if response has keys with values of +Inf, -Inf or NaN.

gogo/protobuf/jsonpb package correctly handles these values so use that to Marshal and print the response to stdout

Checklist

  • Tests updated
  • Documentation added
  • CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX]

@electron0zero electron0zero changed the title tempo-cli: add support for traces api V2 tempo-cli: add support for /api/v2/traces endpoint Sep 26, 2024
@electron0zero electron0zero marked this pull request as ready for review September 26, 2024 13:31
@@ -94,7 +94,7 @@ func main() {
ctx := kong.Parse(&cli,
kong.UsageOnError(),
kong.ConfigureHelp(kong.HelpOptions{
// Compact: true,
Compact: true,
Copy link
Member Author

Choose a reason for hiding this comment

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

no idea why this was commented out, so enabled it again.

I personally find the Compact form easy to read and parse out at a glance.

here is the difference in the help output.

with Compact: true

Usage: tempo-cli-arm64 <command>

Flags:
  -h, --help                  Show context-sensitive help.
  -c, --config-file=STRING    Path to tempo config file

Commands:
  list block                     List information about a block
  list blocks                    List information about all blocks in a bucket
  list compaction-summary        List summary of data by compaction level
  list cache-summary             List summary of bloom sizes per day per
                                 compaction level
  list index                     List information about a block index
  list column                    List values in a given column
  analyse block                  Analyse block in a bucket
  analyse blocks                 Analyse blocks in a bucket
  view index                     View contents of block index
  view schema                    View parquet schema
  gen index                      Generate index for a block
  gen bloom                      Generate bloom for a block
  query api trace-id             query Tempo by trace ID
  query api search-tags          query Tempo search tags
  query api search-tag-values    query Tempo search tag values
  query api search               query Tempo search
  query api metrics              query Tempo metrics query range
  query trace-id                 query for a traceid directly from backend
                                 blocks
  query trace-summary            query summary for a traceid directly from
                                 backend blocks
  query search                   search for a traceid directly from backend
                                 blocks
  rewrite-blocks drop-trace      rewrite blocks with a given trace id redacted
  parquet convert-2-to-3         convert an existing vParquet2 file to vParquet3
                                 block
  parquet convert-3-to-4         convert an existing vParquet3 file to vParquet4
                                 block
  migrate tenant                 migrate tenant between two backends
  migrate overrides-config       migrate overrides config

Run "tempo-cli-arm64 <command> --help" for more information on a command.

without Compact: true

Usage: tempo-cli-arm64 <command>

Flags:
  -h, --help                  Show context-sensitive help.
  -c, --config-file=STRING    Path to tempo config file

Commands:
  list block <tenant-id> <block-id>
    List information about a block

  list blocks <tenant-id>
    List information about all blocks in a bucket

  list compaction-summary <tenant-id>
    List summary of data by compaction level

  list cache-summary <tenant-id>
    List summary of bloom sizes per day per compaction level

  list index <tenant-id> <block-id>
    List information about a block index

  list column <tenant-id> <block-id> <column>
    List values in a given column

  analyse block <tenant-id> <block-id>
    Analyse block in a bucket

  analyse blocks <tenant-id>
    Analyse blocks in a bucket

  view index <tenant-id> <block-id>
    View contents of block index

  view schema <tenant-id> <block-id>
    View parquet schema

  gen index <tenant-id> <block-id>
    Generate index for a block

  gen bloom <tenant-id> <block-id> <bloom-fp> <bloom-shard-size>
    Generate bloom for a block

  query api trace-id <api-endpoint> <trace-id>
    query Tempo by trace ID

  query api search-tags <host-port> [<start> [<end>]]
    query Tempo search tags

  query api search-tag-values <host-port> <tag> [<start> [<end>]]
    query Tempo search tag values

  query api search <host-port> [<trace-ql> [<start> [<end>]]]
    query Tempo search

  query api metrics <host-port> [<trace-ql> [<start> [<end>]]]
    query Tempo metrics query range

  query trace-id <trace-id> <tenant-id>
    query for a traceid directly from backend blocks

  query trace-summary <trace-id> <tenant-id>
    query summary for a traceid directly from backend blocks

  query search <name> <value> <start> <end> <tenant-id>
    search for a traceid directly from backend blocks

  rewrite-blocks drop-trace <trace-id> <tenant-id>
    rewrite blocks with a given trace id redacted

  parquet convert-2-to-3 <in> [<out> [<dedicated-columns> ...]]
    convert an existing vParquet2 file to vParquet3 block

  parquet convert-3-to-4 <in> [<out> [<dedicated-columns> ...]]
    convert an existing vParquet3 file to vParquet4 block

  migrate tenant --source-config-file=STRING <source-tenant-id> <dest-tenant-id>
    migrate tenant between two backends

  migrate overrides-config <config-file>
    migrate overrides config

Run "tempo-cli-arm64 <command> --help" for more information on a command.

@joe-elliott
Copy link
Member

Should we just make v2 default? and require a flag to use v1? We could list it as a breaking change if we feel it needs to be.

@electron0zero
Copy link
Member Author

Should we just make v2 default? and require a flag to use v1? We could list it as a breaking change if we feel it needs to be.

we can yes, I left --v2 under a flag assuming not everyone is running latest tempo with /api/v2/traces so it might break the CLI for them but these users can still use the older version of tempo-cli and if they upgarde they can use --v1 flag

will flip the flag to be --v1 and make --v2 default and mark it as breaking change.

@electron0zero
Copy link
Member Author

Should we just make v2 default? and require a flag to use v1? We could list it as a breaking change if we feel it needs to be.

updated, @joe-elliott v1 is behind flag, and v2 is now default.

'encoding/json' package can't handle +Inf, -Inf, NaN values and will
fail to Marshal the response from tracebyid endpoints if response has keys with
values of +Inf, -Inf or NaN.

gogo/protobuf/jsonpb package correctly handles these values so use that to
Marshal and print the response to stdout
@electron0zero electron0zero merged commit efb69a6 into grafana:main Sep 27, 2024
17 checks passed
@electron0zero electron0zero deleted the tempo-cli_v2 branch September 27, 2024 15:52
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