Skip to content

ES|QL PromQL: implicit type coercion for counter/gauge - #149985

Merged
felixbarny merged 7 commits into
mainfrom
promql-implicit-type-coercion
May 29, 2026
Merged

felixbarny merged 7 commits into
mainfrom
promql-implicit-type-coercion

Conversation

@felixbarny

@felixbarny felixbarny commented May 27, 2026 •

Copy link
Copy Markdown
Member

During PromQL translation, counter-required functions wrap plain numerics with to_counter(), and gauge-only functions wrap counter metrics with to_gauge().

A single PROMQL_IMPLICIT_TYPE_COERCION capability gates the behaviour. Tests cover rate/increase/irate and avg_over_time on counter, gauge, and plain numeric inputs.

Note

Depends on #149713 (TO_GAUGE / ::gauge) being merged first.

closes #140035

@felixbarny felixbarny changed the title promql implicit type coercion ES|QL PromQL: implicit type coercion for counter/gauge May 27, 2026
@elasticsearchmachine

Copy link
Copy Markdown
Collaborator

@felixbarny please enable the option "Allow edits and access to secrets by maintainers" on your PR. For more information, see the documentation.

@elasticsearchmachine elasticsearchmachine added needs:triage Requires assignment of a team area label external-contributor Pull request authored by a developer outside the Elasticsearch team labels May 27, 2026
@elasticsearchmachine elasticsearchmachine added Team:StorageEngine and removed needs:triage Requires assignment of a team area label labels May 27, 2026
@elasticsearchmachine

Copy link
Copy Markdown
Collaborator

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

@felixbarny
felixbarny requested review from kkrik-es and sidosera May 27, 2026 13:57
@felixbarny
felixbarny force-pushed the gauge-converter-function branch from 90a5a63 to 2ea462e Compare May 28, 2026 06:48
@felixbarny
felixbarny requested a review from a team as a code owner May 28, 2026 06:48
@felixbarny
felixbarny force-pushed the promql-implicit-type-coercion branch from 0aa43c2 to 7de4659 Compare May 28, 2026 06:49
@felixbarny
felixbarny force-pushed the gauge-converter-function branch from 2ea462e to 2c32582 Compare May 28, 2026 06:49
@felixbarny
felixbarny force-pushed the promql-implicit-type-coercion branch 5 times, most recently from 0679183 to 6be8154 Compare May 28, 2026 08:34
@felixbarny
felixbarny force-pushed the gauge-converter-function branch from 51ee70a to d6c57c3 Compare May 28, 2026 17:29
@felixbarny
felixbarny force-pushed the promql-implicit-type-coercion branch from 903d490 to 6be8154 Compare May 29, 2026 05:37
@felixbarny
felixbarny force-pushed the gauge-converter-function branch from d6c57c3 to 7c86fa6 Compare May 29, 2026 05:37
@felixbarny
felixbarny force-pushed the promql-implicit-type-coercion branch 2 times, most recently from aa2a367 to 5e9bc0a Compare May 29, 2026 06:13
@felixbarny
felixbarny force-pushed the gauge-converter-function branch from 7c86fa6 to 4822230 Compare May 29, 2026 06:14
@felixbarny
felixbarny force-pushed the promql-implicit-type-coercion branch from 5e9bc0a to 0e2ddb4 Compare May 29, 2026 06:15
@felixbarny
felixbarny force-pushed the gauge-converter-function branch from 4822230 to a3f1c2c Compare May 29, 2026 06:34
@felixbarny
felixbarny force-pushed the promql-implicit-type-coercion branch 3 times, most recently from 3cc771c to 286b4c6 Compare May 29, 2026 08:44
@kkrik-es

Copy link
Copy Markdown
Member

@stratoula fyi. this means that promql allows running rate on gauges - I don't think we should be using these in auto-complete, but I wonder if you have validation for promql queries that needs to be updated.

Base automatically changed from gauge-converter-function to main May 29, 2026 10:03
@elasticsearchmachine

Copy link
Copy Markdown
Collaborator

Hi @felixbarny, I've created a changelog YAML for you.

@github-actions

github-actions Bot commented May 29, 2026 •

Copy link
Copy Markdown
Contributor

🔍 Preview links for changed docs

⏳ Building and deploying preview... View progress

This comment will be updated with preview links when the build is complete.

@github-actions

Copy link
Copy Markdown
Contributor

✅ Elastic Docs Style Checker (Vale)

No issues found on modified lines!


The Vale linter checks documentation changes against the Elastic Docs style guide. To use Vale locally or report issues, refer to Elastic style guide for Vale.

@github-actions

Copy link
Copy Markdown
Contributor

ℹ️ Important: Docs version tagging

👋 Thanks for updating the docs! Just a friendly reminder that our docs are now cumulative. This means all 9.x versions are documented on the same page and published off of the main branch, instead of creating separate pages for each minor version.

We use applies_to tags to mark version-specific features and changes.

Expand for a quick overview

When to use applies_to tags:

✅ At the page level to indicate which products/deployments the content applies to (mandatory)
✅ When features change state (e.g. preview, ga) in a specific version
✅ When availability differs across deployments and environments

What NOT to do:

❌ Don't remove or replace information that applies to an older version
❌ Don't add new information that applies to a specific version without an applies_to tag
❌ Don't forget that applies_to tags can be used at the page, section, and inline level

🤔 Need help?

felixbarny and others added 5 commits May 29, 2026 12:11
PromQL accepts any numeric range vector, but ES|QL distinguishes
counter from gauge types. During translation, counter-required
functions wrap plain numerics with to_counter(), and gauge-only
functions wrap counter metrics with to_gauge().

A single PROMQL_IMPLICIT_TYPE_COERCION capability gates the
behaviour. Tests cover rate/increase/irate and avg_over_time on
counter, gauge, and plain numeric inputs.
Fix compile error after counter/gauge validation moved to translation.
Expected results were copied from ES|QL bucket tests; update them
to match PromQL step timestamp alignment.
@felixbarny
felixbarny force-pushed the promql-implicit-type-coercion branch from cc5be60 to d40913c Compare May 29, 2026 10:12
@stratoula

Copy link
Copy Markdown

@stratoula fyi. this means that promql allows running rate on gauges - I don't think we should be using these in auto-complete, but I wonder if you have validation for promql queries that needs to be updated.

No we dont have such a strong validation. We are relying on the definitions you are sending us

const rateDefinition: PromQLFunctionDefinition = {
  type: PromQLFunctionDefinitionTypes.WITHIN_SERIES,
  name: 'rate',
  description: i18n.translate('kbn-esql-language.promql.definitions.rate', {
    defaultMessage:
      'Calculates the per-second average rate of increase of the time series in the range vector.',
  }),
  preview: true,
  signatures: [
    {
      params: [
        {
          name: 'v',
          type: 'range_vector',
          optional: false,
          description: 'Range vector input.',
        },
      ],
      returnType: 'instant_vector',
    },
  ],
  locationsAvailable: [Location.PROMQL],
  examples: ['rate(http_requests_total[5m])'],
};

and it is a bit vague so we are ok

@elasticsearchmachine

Copy link
Copy Markdown
Collaborator

Hi @felixbarny, I've updated the changelog YAML for you.

@felixbarny
felixbarny disabled auto-merge May 29, 2026 13:37
@felixbarny
felixbarny enabled auto-merge (squash) May 29, 2026 13:37
@felixbarny
felixbarny merged commit f8f64ac into main May 29, 2026
37 checks passed
@felixbarny
felixbarny deleted the promql-implicit-type-coercion branch May 29, 2026 15:00
szybia added a commit to szybia/elasticsearch that referenced this pull request May 29, 2026
* upstream/main:
  In file watching tests, add 2s to guarantee a timestamp change (elastic#149937)
  Add query filter to more query types (elastic#150127)
  [DOCS] Fix setting error and edit reindex-indices.md (elastic#150139)
  Rename ResumeBulkByScrollRequest to ResumeBulkByPaginatedSearchRequest (elastic#150210)
  Fail search shards in resharding disruption tests (elastic#150124)
  Tests: Fix ShardSearchPhaseAPMMetricsTests (elastic#150200)
  ES|QL PromQL: implicit type coercion for counter/gauge (elastic#149985)
  Fix OTelMetricsBufferingIT: explicitly produce multiple delta batches (elastic#150136)
  [Test] Fix testActionStats off-by-one on powers of two (elastic#150218)
  Escape BUILDKITE_PARALLEL_JOB in batch dispatch (elastic#150223)
  Handle patterns that require resource on every project (elastic#149980)
  Mute org.elasticsearch.xpack.inference.external.http.sender.RequestExecutorServiceTests testChangingCapacity_DoesNotRejectsOverflowTasks_BecauseOfQueueFull elastic#150226
  Add timestamp accumulator for cache quota tracking (elastic#149890)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

>enhancement external-contributor Pull request authored by a developer outside the Elasticsearch team :StorageEngine/PromQL PromQL support for Elastic Team:StorageEngine v9.5.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PromQL: support any functions regardless of the metric type

5 participants