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

Block requests to ui_metric API if telemetry is disabled #35268

Merged
merged 12 commits into from
Apr 25, 2019

Conversation

cjcenizal
Copy link
Contributor

@cjcenizal cjcenizal commented Apr 17, 2019

Fixes #34387

We need to prevent requests to the ui_metric API from being sent if telemetry is disabled; otherwise users might assume we're still gathering telemetry. This change adds an interceptor to the $http service which blocks the request, and also introduces some hackery to ensure all requests to the API go through $http and that blocked requests don't bubble up warnings to the console.

To test:

  1. With telemetry enabled, visit the Management > Remote Clusters app. You should see a request be sent to api/ui_metric.
  2. Disable telemetry, and repeat. You should no longer see the request being sent.

I've also tested this by creating a build of Kibana and checking that the ui_metric requests were and were not being set with/without telemetry, just to verify that X-Pack was still consuming the OSS code as expected.

NOTE: A bug currently prevents users from toggling telemetry under Advanced Settings, so you may need to test this by clearing out and restarting your cluster. The bug will be fixed by #35250.

This PR also throws an error if the user calls trackUiMetric with an app name or metric type that contains a colon. I expect people to test new metrics by performing an action and verifying it in the /stats output, at which point they'll see this error.

image

image

@cjcenizal cjcenizal added Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc non-issue Indicates to automation that a pull request should not appear in the release notes Feature:Telemetry v8.0.0 v7.2.0 labels Apr 17, 2019
@cjcenizal cjcenizal requested a review from a team as a code owner April 17, 2019 23:20
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-platform

- Export track helper method from ui_metric app.
- Remove createUiMetricUri helper.
const currentSignature = response.headers('kbn-xpack-sig');
const cachedSignature = xpackInfoSignature.get();
// If another interceptor has rejected a request, then headers will be undefined.
if (response.headers) {

This comment was marked as outdated.

@@ -65,7 +65,9 @@ module.config(($httpProvider) => {

function interceptorFactory(responseHandler) {
return function interceptor(response) {
if (!isUnauthenticated && !isSystemApiRequest(response.config) && sessionTimeout !== null) {
// If another interceptor has rejected a request, then config will be undefined.
const isSystemRequest = response.config ? isSystemApiRequest(response.config) : false;

This comment was marked as outdated.

@elasticmachine
Copy link
Contributor

💔 Build Failed

@cjcenizal
Copy link
Contributor Author

CC @tylersmalley as I believe this is the first instance of statically importing OSS code into production X-Pack code, as enabled by #32722.

@elasticmachine
Copy link
Contributor

💔 Build Failed

});

module.config(($httpProvider) => {
$httpProvider.interceptors.push(($q) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are we using an interceptor to accomplish this? Would it be possible to just not make the calls when telemetry is disabled instead of trying to block them?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Haha, yes! I implemented the interceptor solution before creating the common track method, so completely overlooked the obvious. I'll update the code to just perform the check there.

…rceptors.

- Add support for an array of metric types.
- Update README.
@cjcenizal
Copy link
Contributor Author

Thanks @kobelb, I've applied your suggestion.

@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Copy link
Contributor

@sebelga sebelga left a comment

Choose a reason for hiding this comment

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

LGTM! I am still not convinced about spreading the code across folders but it's ok 😊
I was wondering if we shouldn't create all new plugins with the new platform architecture and create a shim until the migration is done?

@cjcenizal
Copy link
Contributor Author

Thanks, Seb! I'm handing this off to @Bamieh, who is on the Platform team, so I'll let him decide how to handle integration with the NP.

Copy link
Member

@Bamieh Bamieh left a comment

Choose a reason for hiding this comment

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

Looks good! LGTM

to worry about exceeding the 1000-field soft limit in Elasticsearch.

// TODO: Clarify that colons are NOT allowed in metric names or app types possibly reject request in trackUiMetric; disallow commas too?
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 this todo is no longer needed as you have already addressed it on line 37

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@cjcenizal cjcenizal merged commit c55b0af into elastic:master Apr 25, 2019
@cjcenizal cjcenizal deleted the uim/disable-when-opted-out branch April 25, 2019 22:08
cjcenizal added a commit to cjcenizal/kibana that referenced this pull request Apr 25, 2019
* Block requests to ui_metric API if telemetry is disabled
- Export trackUiMetric helper method from ui_metric app.
- Remove createUiMetricUri helper.
- Add support for an array of metric types.
- Update README.
* Throw error if trackUiMetric is called with a string containing a colon.
cjcenizal added a commit that referenced this pull request Apr 25, 2019
…5629)

* Block requests to ui_metric API if telemetry is disabled
- Export trackUiMetric helper method from ui_metric app.
- Remove createUiMetricUri helper.
- Add support for an array of metric types.
- Update README.
* Throw error if trackUiMetric is called with a string containing a colon.
lizozom pushed a commit to lizozom/kibana that referenced this pull request Apr 29, 2019
* Block requests to ui_metric API if telemetry is disabled
- Export trackUiMetric helper method from ui_metric app.
- Remove createUiMetricUri helper.
- Add support for an array of metric types.
- Update README.
* Throw error if trackUiMetric is called with a string containing a colon.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Telemetry non-issue Indicates to automation that a pull request should not appear in the release notes Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc v7.2.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Disable ui_metric gathering if telemetry is not opted-in or if X-Pack isn't present
5 participants