Skip to content

Conversation

@kkrik-es
Copy link
Contributor

Fixes #135441
Fixes #133449

@kkrik-es kkrik-es self-assigned this Sep 25, 2025
@kkrik-es kkrik-es added >non-issue Team:StorageEngine :StorageEngine/ES|QL Timeseries / metrics / logsdb capabilities in ES|QL labels Sep 25, 2025
@kkrik-es kkrik-es marked this pull request as ready for review September 25, 2025 19:21
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-storage-engine (Team:StorageEngine)

@kkrik-es
Copy link
Contributor Author

TelemetryIt has coverage for the TS command already. @luigidellaquila please let me know if it needs further modifications. Thanks!

Copy link
Contributor

@luigidellaquila luigidellaquila left a comment

Choose a reason for hiding this comment

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

Thanks @kkrik-es

I left two comments, my main concern is that we are tracking FROM commands that don't really exist in the query. For some cases the fix could be easy, but for others it could require some refactoring.

Happy to chat about it off-line, if it can help

public void testTimeSeriesAggregate() {
assumeTrue("TS required", EsqlCapabilities.Cap.TS_COMMAND_V0.isEnabled());
Counters c = esql("""
TS metrics
Copy link
Contributor

@luigidellaquila luigidellaquila Sep 26, 2025

Choose a reason for hiding this comment

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

Does it also work for a query without stats?
Eg. will this return ts:1, keep:1, from:0?

TS metrics | KEEP @timestamp

I didn't test it, but if I remember well it gets planned as a normal FROM, so I expect it to return from:1, ts:0

Could you please add a test and verify?

If it's how I suspect, a fix could be problematic, as after analysis we lose the information we stored in the UnresolvedRelation to distinguish the two situations.

cc @astefan this is another case that would require the refactoring we discussed some time ago, ie. move the stats calculation to parse time, and unify it with APM telemetry

Copy link
Contributor

@luigidellaquila luigidellaquila Sep 26, 2025

Choose a reason for hiding this comment

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

Actually, an easy fix could be to rely on indexMode in EsRelation, ie.

FROM(x -> x instanceof EsRelation r && r.indexMode() != IndexMode.TIME_SERIES),
TS(x -> x instanceof EsRelation r && r.indexMode() == IndexMode.TIME_SERIES),

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No that's not accurate, FROM is also applicable to time-series indices. In general, TS makes sense when combined with STATS, otherwise it doesn't offer much and it's actually more restrictive than it should. In that respect, I think it's ok if we don't track TS metrics | KEEP @timestamp as TS but rather as FROM.

Copy link
Contributor

@luigidellaquila luigidellaquila Sep 26, 2025

Choose a reason for hiding this comment

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

Looking at the code, I see UnresolvedRelation is built with IndexMode.STANDARD from FROM and with IndexMode.TIME_SERIES for TS

Then we build the EsRelation starting from the UnresolvedRelation, using the same index mode.

At optimization time things can change, but here we are still at verification phase, so we should have the original information.

Am I missing something?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hm actually you're right, this seems to work! @dnhatn to double-check it too.

Copy link
Contributor

@luigidellaquila luigidellaquila left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

Copy link
Member

@dnhatn dnhatn left a comment

Choose a reason for hiding this comment

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

LGTM, thanks Kostas!

@elasticsearchmachine elasticsearchmachine added the serverless-linked Added by automation, don't add manually label Sep 27, 2025
@kkrik-es kkrik-es merged commit 7e05113 into elastic:main Sep 27, 2025
34 of 35 checks passed
@kkrik-es kkrik-es deleted the tsdb/ts-telemetry branch September 29, 2025 05:45
szybia added a commit to szybia/elasticsearch that referenced this pull request Sep 29, 2025
* upstream/main: (22 commits)
  Fix InternalCategorizationAggregationTests.testReduceRandom (elastic#135533)
  [DOCS] GeoIP processor: add clarification about using a reverse proxy endpoint (elastic#135534)
  Move `ProjectRoutingInfo` and related classes (elastic#135586)
  Refactor IndexAbstractionResolver (elastic#135587)
  Simplify returnLocalAll handling in ES|QL (elastic#135353)
  Reapply "Add an option to return early from an allocate call"  (elastic#135589)
  Mute org.elasticsearch.xpack.esql.qa.single_node.GenerativeIT test elastic#134407
  Mute org.elasticsearch.xpack.esql.heap_attack.HeapAttackIT testAggTooManyMvLongs elastic#135585
  Mute org.elasticsearch.multiproject.test.XpackWithMultipleProjectsClientYamlTestSuiteIT test {yaml=esql/60_usage/Basic ESQL usage output (telemetry) snapshot version} elastic#135579
  Mute org.elasticsearch.search.ccs.KnnVectorQueryBuilderCrossClusterSearchIT testKnnQueryWithCcsMinimizeRoundTripsFalse elastic#135573
  Mute org.elasticsearch.xpack.esql.inference.textembedding.TextEmbeddingOperatorTests testSimpleCircuitBreaking elastic#135569
  Add telemetry for `TS` command (elastic#135471)
  Mute org.elasticsearch.cluster.routing.allocation.decider.RestoreInProgressAllocationDeciderTests testCanAllocatePrimaryExistingInRestoreInProgress elastic#135566
  allocation: clarify RestoreInProgressAllocationDecider failure message (elastic#132307)
  [ES|QL] Register AggregateMetricDoubleLiteral (elastic#135054)
  Validate Logstash pipeline ID when creating. (elastic#135378)
  Migrate transport versions 8841050 through 8841041 (elastic#135555)
  Mute org.elasticsearch.search.ccs.SparseVectorQueryBuilderCrossClusterSearchIT testSparseVectorQueryWithCcsMinimizeRoundTripsFalse elastic#135559
  Mute org.elasticsearch.action.admin.cluster.stats.SearchUsageStatsTests testToXContent elastic#135558
  Testing indices query cache memory stats (elastic#135298)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

>non-issue serverless-linked Added by automation, don't add manually :StorageEngine/ES|QL Timeseries / metrics / logsdb capabilities in ES|QL Team:StorageEngine v9.2.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add telemetry for TS command [CI] XPackRestIT test {p0=esql/60_usage/Basic ESQL usage output (telemetry) non-snapshot version} failing

4 participants