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

Add analytics plugin usage stats to _xpack/usage #54911

Merged
merged 8 commits into from
Apr 13, 2020

Conversation

imotov
Copy link
Contributor

@imotov imotov commented Apr 7, 2020

Adds analytics plugin usage stats to _xpack/usage. It looks like the usage
didn't report the actual usage in the previous versions. So, while it looks
like it is reported in 7.7, the numbers are always 0. Because code between 7.7
and 7.x/master is significantly different, I can open a separate PR for 7.7 if
we want to fix it there.

Closes #54847

Adds analytics plugin usage stats to _xpack/usage.

Closes elastic#54847
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-analytics-geo (:Analytics/Aggregations)

@@ -137,7 +137,7 @@ public AnalyticsPlugin() { }
ResourceWatcherService resourceWatcherService, ScriptService scriptService, NamedXContentRegistry xContentRegistry,
Environment environment, NodeEnvironment nodeEnvironment, NamedWriteableRegistry namedWriteableRegistry,
IndexNameExpressionResolver indexNameExpressionResolver) {
return singletonList(new AnalyticsUsage());
Copy link
Member

Choose a reason for hiding this comment

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

Ouch.

@@ -9,53 +9,35 @@
import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.common.xcontent.ContextParser;
import org.elasticsearch.xpack.core.analytics.action.AnalyticsStatsAction;
import org.elasticsearch.xpack.core.watcher.common.stats.Counters;
Copy link
Member

Choose a reason for hiding this comment

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

I feel like we might be better off using an EnumMap<AnalyticsStatsAction.Item, AtomicLong> than this string based thing. Serialization would have to be a bit more explicit, but I don't mind that too much.

Copy link
Member

Choose a reason for hiding this comment

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

On the other hand, Counters is nice from a BWC perspective. Maybe just move it out of the watcher package in a follow up change? Maybe drop the enum entirely and just us a string?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have replaced Counters with Enum-based Counters, which for now resides in the analytics package, but we can move it to a more generic package if we decide to start using them for other areas.

@imotov
Copy link
Contributor Author

imotov commented Apr 8, 2020

@polyfractal @nik9000 I implemented some changes. I would love to hear what you think about it.

@imotov imotov requested a review from nik9000 April 8, 2020 21:34
vals[i] = val;
}
}
counters = new AtomicLongArray(vals);
Copy link
Member

Choose a reason for hiding this comment

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

So, like, we have to add enum entries to the end and they'll come through as 0 if they aren't set. Right?

Copy link
Member

Choose a reason for hiding this comment

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

I think it is worth adding comments about that, both to the enum class and to this one.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is basically to handle the situation when an older node have less stat categories or a newer node has more stats categories. I added a comment to the enum but I agree I should duplicate it here.

Copy link
Contributor

Choose a reason for hiding this comment

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

👍

counters.inc(TestV1.A, 1);
counters.inc(TestV1.B, 2);
counters.inc(TestV1.C, 3);
EnumCounters<TestV2> newCounters = serialize(counters, in -> new EnumCounters<>(in, TestV2.class));
Copy link
Member

Choose a reason for hiding this comment

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

Nice trick!

@imotov
Copy link
Contributor Author

imotov commented Apr 10, 2020

@polyfractal @nik9000 I have added comments that @nik9000 has requested.

Copy link
Member

@nik9000 nik9000 left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@polyfractal polyfractal left a comment

Choose a reason for hiding this comment

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

Left a few minor comments and a serialization question, but otherwise LGTM! Thanks for fixing <3

super(XPackUsageFeatureAction.ANALYTICS.name(), transportService, clusterService,
threadPool, actionFilters, indexNameExpressionResolver);
this.licenseState = licenseState;
this.client = client;
}

@Override
protected void masterOperation(Task task, XPackUsageRequest request, ClusterState state,
ActionListener<XPackUsageFeatureResponse> listener) {
boolean available = licenseState.isDataScienceAllowed();
Copy link
Contributor

Choose a reason for hiding this comment

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

Oof, just noticed "DataScience"... we should probably change that at some point 😓 Not for this PR though :)

vals[i] = val;
}
}
counters = new AtomicLongArray(vals);
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

ttestUsage = 0;
counters = new EnumCounters<>(Item.class);
if (in.getVersion().onOrAfter(Version.V_7_7_0)) {
counters.inc(Item.BOXPLOT, in.readLong());
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this should be a readVLong() instead of readLong()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch!

@@ -33,6 +33,17 @@ private AnalyticsStatsAction() {
super(NAME, Response::new);
}

/**
* Items to track. Serialized by ordinals. Append only, don't remove or change order of items in this list.
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 have a test somewhere that enforces this? E.g. enums that extend writeable directly can implement AbstractWriteableEnumTestCase. Not the same situation here, but having something conceptually similar to testValidOrdinals() would be nice. Just verifies that BOXPLOT == 0, etc etc

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed we need a bwc test for usage. Right now it is completely broken so it didn't make sense to have it. But as soon as I back port this I will open a PR for bwc test for usage.

@imotov imotov merged commit e593f3e into elastic:master Apr 13, 2020
imotov added a commit to imotov/elasticsearch that referenced this pull request Apr 14, 2020
Adds analytics plugin usage stats to _xpack/usage.

Closes elastic#54847
imotov added a commit that referenced this pull request Apr 14, 2020
Adds analytics plugin usage stats to _xpack/usage.

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

Successfully merging this pull request may close these issues.

Add analytics plugin usage stats to _xpack/usage
5 participants