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

Fix wrong search stats groups in indices API #8950

Closed
wants to merge 4 commits into from

Conversation

alexksikes
Copy link
Contributor

This provides a fix to issue #7644. A new Stats object must be created, and not a reference to the retrieved stats, before we can add stats to it. Otherwise, we would keep on adding to the same object on subsequent calls to IndicesStatsResponse#getPrimaries() or IndicesStatsResponse#getTotal().

@@ -60,6 +60,10 @@ public Stats(long queryCount, long queryTimeInMillis, long queryCurrent, long fe
this.fetchCurrent = fetchCurrent;
}

public Stats(Stats stats) {
Copy link
Member

Choose a reason for hiding this comment

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

if this new constructor is only used in the same class we can reduce its visibility perhaps?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe it could be used outside of the class at some point, so might be better to leave constructors public in general.

Copy link
Member

Choose a reason for hiding this comment

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

I am not sure why...I wouldn't leave public if not needed. Actually I am even thinking that we could remove this constructor and just do new Stats(stats.queryCount etc.) directly, which would address my other comment too

@javanna
Copy link
Member

javanna commented Dec 15, 2014

Hey @alexksikes thanks for looking into this. Could you add some description to the PR that explains why this happens? I am also not clear yet on whether this would cause problems on the REST layer only or also on the transport layer (when the api is called through java api), maybe we can clarify that too.

@s1monw
Copy link
Contributor

s1monw commented Dec 15, 2014

this is a good fix, I agree with @javanna that we shoud have a better comment why this happens?

I also want a real unittest for this instead of a REST test. These REST test have a massive overhead and this one can be easily tested in a unittest

@@ -60,6 +60,10 @@ public Stats(long queryCount, long queryTimeInMillis, long queryCurrent, long fe
this.fetchCurrent = fetchCurrent;
}

public Stats(Stats stats) {
this.add(stats);
Copy link
Member

Choose a reason for hiding this comment

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

wondering if this should call this(stats.queryCount, etc.), since the addition is not required given that we are creating a new object

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 vars are all set to zero so it would do the same thing.

Copy link
Member

Choose a reason for hiding this comment

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

I know the result is the same, but we are not adding to something existing, we are creating a new object. The addition is not needed and I think it would make the code cleaner if we called the other constructor.

@javanna
Copy link
Member

javanna commented Dec 15, 2014

The fix looks good, I left a couple of small comments, also I would add some unit tests for this, so that we won't need the REST test. Maybe also test group stats in the existing stats integration test.

@alexksikes
Copy link
Contributor Author

Thanks for the comments, I've added a unit test to show where the problem is exactly. I suppose I can remove the REST test?

@s1monw
Copy link
Contributor

s1monw commented Dec 15, 2014

yeah please remove the REST test

checkStats(groupStats1.get("group1"), 3);
}

private void checkStats(Stats stats, long equalTo) {
Copy link
Member

Choose a reason for hiding this comment

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

can we rename to assertStats?

@javanna
Copy link
Member

javanna commented Dec 16, 2014

Left a few comments

@javanna
Copy link
Member

javanna commented Dec 16, 2014

LGTM

alexksikes added a commit that referenced this pull request Dec 16, 2014
This provides a fix to issue #7644. A new Stats object must be created, and
not a reference to the retrieved stats, before we can add stats to it.
Otherwise, we would keep on adding to the same object on subsequent calls to
IndicesStatsResponse#getPrimaries() or IndicesStatsResponse#getTotal().

Closes #7644 and #8950
@alexksikes alexksikes closed this Dec 16, 2014
@alexksikes alexksikes deleted the fix/search-stats-groups branch December 16, 2014 14:03
alexksikes added a commit that referenced this pull request Dec 16, 2014
This provides a fix to issue #7644. A new Stats object must be created, and
not a reference to the retrieved stats, before we can add stats to it.
Otherwise, we would keep on adding to the same object on subsequent calls to
IndicesStatsResponse#getPrimaries() or IndicesStatsResponse#getTotal().

Closes #7644 and #8950
alexksikes added a commit that referenced this pull request Jan 5, 2015
This provides a fix to issue #7644. A new Stats object must be created, and
not a reference to the retrieved stats, before we can add stats to it.
Otherwise, we would keep on adding to the same object on subsequent calls to
IndicesStatsResponse#getPrimaries() or IndicesStatsResponse#getTotal().

Closes #7644 and #8950
@clintongormley clintongormley added the :Data Management/Stats Statistics tracking and retrieval APIs label Mar 19, 2015
@clintongormley clintongormley changed the title Indices API: Fix wrong search stats groups Fix wrong search stats groups in indices API Jun 8, 2015
mute pushed a commit to mute/elasticsearch that referenced this pull request Jul 29, 2015
This provides a fix to issue elastic#7644. A new Stats object must be created, and
not a reference to the retrieved stats, before we can add stats to it.
Otherwise, we would keep on adding to the same object on subsequent calls to
IndicesStatsResponse#getPrimaries() or IndicesStatsResponse#getTotal().

Closes elastic#7644 and elastic#8950
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants