Skip to content

Conversation

@gmarouli
Copy link
Contributor

@gmarouli gmarouli commented Oct 22, 2025

Following #136813, we expose to ILM the new sampling method config in the downsampling API. This will allow users to configure the sampling method in their downsample action of their ILM policies. For example:

PUT _ilm/policy/datastream_policy
{
  "policy": {
    "phases": {
      "hot": {
        "actions": {
          "rollover": {
            "max_docs": 1
          },
          "downsample": {
  	          "fixed_interval": "1h",
  	          "force_merge_index": false,
                  "sampling_method": "aggregate"
  	  }
        }
      }
    }
  }
}

@github-actions
Copy link
Contributor

github-actions bot commented Oct 22, 2025

🔍 Preview links for changed docs

@github-actions
Copy link
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?

@gmarouli gmarouli added >enhancement :Data Management/ILM+SLM Index and Snapshot lifecycle management :StorageEngine/Downsampling Downsampling (replacement for rollups) - Turn fine-grained time-based data into coarser-grained data labels Oct 22, 2025
@elasticsearchmachine elasticsearchmachine added Team:Data Management Meta label for data/management team Team:StorageEngine and removed needs:triage Requires assignment of a team area label labels Oct 22, 2025
@elasticsearchmachine
Copy link
Collaborator

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

@elasticsearchmachine
Copy link
Collaborator

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

@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-data-management (Team:Data Management)

@gmarouli gmarouli requested a review from nielsbauman October 22, 2025 15:45
Copy link
Contributor

@nielsbauman nielsbauman left a comment

Choose a reason for hiding this comment

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

Thanks a lot for working on this, Mary! Looking good to me, I just have a few pretty minor comments.

Who would have thought that a new functionality would require fewer changes in ILM than in DLM 😄

Comment on lines +26 to +28
`sampling_method` {applies_to}`stack: ga 9.3`
: (Optional, string) The sampling method that will be used to sample metrics; there are two methods available `aggregate` and
the `last_value`. Defaults to `aggregate`.
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we link to a page that explains the difference between the two methods? Or do we not have such a page yet?

Copy link
Contributor Author

@gmarouli gmarouli Oct 29, 2025

Choose a reason for hiding this comment

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

We do not have a page about this yet. But this is a very good point and I will keep a note about that.

Comment on lines 331 to 336
return switch (between(0, 2)) {
case 0 -> null;
case 1 -> DownsampleConfig.SamplingMethod.AGGREGATE;
case 2 -> DownsampleConfig.SamplingMethod.LAST_VALUE;
default -> throw new IllegalArgumentException("Unknown randomisation branch");
};
Copy link
Contributor

Choose a reason for hiding this comment

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

Small optional nit:

Suggested change
return switch (between(0, 2)) {
case 0 -> null;
case 1 -> DownsampleConfig.SamplingMethod.AGGREGATE;
case 2 -> DownsampleConfig.SamplingMethod.LAST_VALUE;
default -> throw new IllegalArgumentException("Unknown randomisation branch");
};
return randomBoolean() ? null : randomFrom(DownsampleConfig.SamplingMethod.values());

Copy link
Contributor Author

@gmarouli gmarouli Oct 29, 2025

Choose a reason for hiding this comment

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

I used to have it like this but it favours null, I will change it though to something fair that still picks up the values dynamically. Nice that you challenged it.

I am considering something along the lines of:

static DownsampleConfig.SamplingMethod randomSamplingMethod() {
        if (between(0, DownsampleConfig.SamplingMethod.values().length) == 0) {
            return null;
        } else {
            return randomFrom(DownsampleConfig.SamplingMethod.values());
        }
    }

@gmarouli
Copy link
Contributor Author

Who would have thought that a new functionality would require fewer changes in ILM than in DLM 😄

Hahah, actually, if we did the same in DLM just adding it to the each round, it required almost nothing. But the users would need to pay the price. So, I still think DLM wins, it's just unfortunate that we did not see this when we were first coming up with the configuration.

@gmarouli gmarouli requested a review from nielsbauman October 29, 2025 10:24
assertEquals(policy, settings.get(LifecycleSettings.LIFECYCLE_NAME_SETTING.getKey()));
}, 120, TimeUnit.SECONDS);

// update the policy to now contain the downsample action in cold, whilst not existing in warm anymore (this will have our already
// downsampled index attempt to go through the downsample action again when in cold)

// Sometimes the sampling method might be different; this step should not fail considering that the index is already downsampled.
Copy link
Contributor

Choose a reason for hiding this comment

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

I understand this comment, but I think it might be hard to understand without the context of this PR.

Also, wouldn't it be valuable to have a similar test that explicitly changes the sampling method between the two phases? Now we sometimes implicitly do that through the default value (which is what your comment hints at), but I feel like that's an important edge case that is worth explicitly verifying. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes you are right, initially, I thought the sampling method should not matter, but as you say it's good to check that the test case captures this. I changed it to always change the sampling method

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks. I think we should also update this comment as Sometimes is no longer correct, right?

@gmarouli gmarouli requested a review from nielsbauman October 31, 2025 10:43
Copy link
Contributor

@nielsbauman nielsbauman 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 a lot for the work and the iterations :)

@gmarouli
Copy link
Contributor Author

Thanks for the review @nielsbauman . Very helpful!

@gmarouli gmarouli merged commit c9dcc3b into elastic:main Oct 31, 2025
34 checks passed
@gmarouli gmarouli deleted the downsampling/add-new-sampling-method-ilm branch October 31, 2025 11:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

:Data Management/ILM+SLM Index and Snapshot lifecycle management >enhancement :StorageEngine/Downsampling Downsampling (replacement for rollups) - Turn fine-grained time-based data into coarser-grained data Team:Data Management Meta label for data/management team Team:StorageEngine v9.3.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants