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

Test fix: ensure we don't accidentally generate two identical histograms #113322

Merged
merged 3 commits into from
Sep 23, 2024

Conversation

smalyshev
Copy link
Contributor

Fixes #113264

@smalyshev smalyshev marked this pull request as ready for review September 21, 2024 00:23
@smalyshev smalyshev requested review from quux00 and javanna September 21, 2024 00:23
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-search-foundations (Team:Search Foundations)

@elasticsearchmachine elasticsearchmachine added the Team:Search Foundations Meta label for the Search Foundations team in Elasticsearch label Sep 21, 2024
Copy link
Contributor

@andreidan andreidan left a comment

Choose a reason for hiding this comment

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

Thanks for working on this Stas.

Left a suggestion to potentially improve the reliability of the solution.

@@ -33,7 +33,7 @@ public class CCSTelemetrySnapshotTests extends AbstractWireSerializingTestCase<C

private LongMetricValue randomLongMetricValue() {
LongMetric v = new LongMetric();
for (int i = 0; i < randomIntBetween(1, 10); i++) {
for (int i = 0; i < randomIntBetween(5, 10); i++) {
Copy link
Contributor

@andreidan andreidan Sep 23, 2024

Choose a reason for hiding this comment

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

It's not immediately obvious what issue we're looking to fix and how this change fixes it.

Can you please expand in the PR description the observed problem?

I suspect the problematic usage of this random long method lies in mutateInstance ? (based on the linked issue) If this is correct I think we should use randomValueOtherThan() to make sure mutateInstance generates a value that's different than the input.

edit: linking an example from other tests https://github.com/elastic/elasticsearch/blob/main/server/src/test/java/org/elasticsearch/cluster/metadata/DataStreamTests.java#L133

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The problem seems to be that if it chooses to have one value, the histogram sometimes ends up the same as the previous one. The problem here is that I can't just generate a long different from previous long, for two reasons: 1) I do not know what the previous long has been (I only have a histogram) and 2) even if I did, a histogram can put two different values into the same bucket, thus producing the same histogram. Making it always generate more than one value significantly reduces a chance for randomly generating two identical histograms.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@andreidan I changed the code to use randomValueOtherThan

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry if I'm misunderstanding the problem, but wouldn't we get different histograms if we radomize away from the current value?
e.g.

            case 3:
                took = randomValueOtherThan(took, () -> randomLongMetricValue());
                break;
            case 4:
                tookMrtTrue = randomValueOtherThan(tookMrtTrue, () -> randomLongMetricValue());
                break;
            case 5:
                tookMrtFalse = randomValueOtherThan(tookMrtFalse, () -> randomLongMetricValue());
                break;

I believe the current proposed solution only changes the window of flakiness (arguably making it less probable to occur, but does not eliminate it i.e. the creation of test instance my get 5 values in a histogram and the mutation might also get 5)

@smalyshev smalyshev changed the title Test fix: looks like using one value is not random enough Test fix: ensure we don't accidentally generate two identical histograms Sep 23, 2024
Copy link
Contributor

@andreidan andreidan 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 for fixing this Stas

@smalyshev
Copy link
Contributor Author

@elasticmachine update branch

@smalyshev smalyshev merged commit 756f18e into elastic:main Sep 23, 2024
15 checks passed
@smalyshev smalyshev deleted the bug/113264 branch September 23, 2024 19:21
@elasticsearchmachine
Copy link
Collaborator

💚 Backport successful

Status Branch Result
8.x

smalyshev added a commit to smalyshev/elasticsearch that referenced this pull request Sep 23, 2024
…ams (elastic#113322)

* Test fix: looks like using one value is not random enough
elasticsearchmachine pushed a commit that referenced this pull request Sep 23, 2024
…ams (#113322) (#113415)

* Test fix: looks like using one value is not random enough
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>non-issue :Search Foundations/CCS Team:Search Foundations Meta label for the Search Foundations team in Elasticsearch >test Issues or PRs that are addressing/adding tests v8.16.0 v9.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[CI] CCSTelemetrySnapshotTests.testEqualsAndHashcode
4 participants