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

[Usage collection] Collect non-default kibana configs #97368

Merged
merged 17 commits into from Apr 20, 2021

Conversation

Bamieh
Copy link
Member

@Bamieh Bamieh commented Apr 16, 2021

Config Usage Collector

The config usage collector reports non-default kibana configs.

All non-default configs except booleans and numbers will be reported as [redacted] unless otherwise specified via config.exposeToUsage in the plugin config descriptor.

import { schema, TypeOf } from '@kbn/config-schema';
import { PluginConfigDescriptor } from 'src/core/server';

export const configSchema = schema.object({
  usageCounters: schema.object({
    enabled: schema.boolean({ defaultValue: true }),
    retryCount: schema.number({ defaultValue: 1 }),
    bufferDuration: schema.duration({ defaultValue: '5s' }),
  }),
  uiCounters: schema.object({
    enabled: schema.boolean({ defaultValue: true }),
    debug: schema.boolean({ defaultValue: schema.contextRef('dev') }),
  }),
  maximumWaitTimeForAllCollectorsInS: schema.number({
    defaultValue: DEFAULT_MAXIMUM_WAIT_TIME_FOR_ALL_COLLECTORS_IN_S,
  }),
});

export const config: PluginConfigDescriptor<ConfigType> = {
  schema: configSchema,
  exposeToUsage: {
    uiCounters: true,
    usageCounters: {
      bufferDuration: true,
    },
    maximumWaitTimeForAllCollectorsInS: false,
  },
};

In the above example setting uiCounters: true in the exposeToUsage property marks all configs under the path uiCounters as safe. The collector will send the actual non-default config value when setting an exact config or its parent path to true.

Settings the config path or its parent path to false will explicitly mark this config as unsafe. The collector will send [redacted] for non-default configs when setting an exact config or its parent path to false.

Example output of the collector

{
  "kibana_config_usage": {
    "xpack.apm.serviceMapTraceIdBucketSize": 30,
    "elasticsearch.username": "[redacted]",
    "elasticsearch.password": "[redacted]",
    "plugins.paths": "[redacted]",
    "server.port": 5603,
    "server.basePath": "[redacted]",
    "server.rewriteBasePath": true,
    "logging.json": false,
    "usageCollection.uiCounters.debug": true
  }
}

@Bamieh Bamieh added auto-backport Deprecated: Automatically backport this PR after it's merged release_note:skip Skip the PR/issue when compiling release notes Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc Team:KibanaTelemetry v7.13.0 v8.0.0 labels Apr 16, 2021
@Bamieh Bamieh requested a review from afharo April 16, 2021 11:33
@Bamieh Bamieh marked this pull request as ready for review April 16, 2021 16:22
@Bamieh Bamieh requested a review from a team as a code owner April 16, 2021 16:22
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-core (Team:Core)

@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-telemetry (Team:KibanaTelemetry)

@Bamieh
Copy link
Member Author

Bamieh commented Apr 16, 2021

@elasticmachine merge upstream

@Bamieh
Copy link
Member Author

Bamieh commented Apr 16, 2021

@elasticmachine merge upstream

@Bamieh
Copy link
Member Author

Bamieh commented Apr 18, 2021

@elasticmachine merge upstream

Copy link
Member

@afharo afharo left a comment

Choose a reason for hiding this comment

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

Overall, it looks great! Good job @Bamieh! I just added some NITs and 2 potential issues we might want to look at before merging this PR:

  • startsWith check
  • array of objects

Copy link
Contributor

@pgayvallet pgayvallet left a comment

Choose a reason for hiding this comment

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

Overall looking great.

A few remarks and questions

Comment on lines -5 to +7
"exclude": []
"exclude": [
"src/plugins/kibana_usage_collection/server/collectors/config_usage/register_config_usage_collector.ts"
]
Copy link
Contributor

Choose a reason for hiding this comment

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

Why was that necessary?

Copy link
Member Author

@Bamieh Bamieh Apr 20, 2021

Choose a reason for hiding this comment

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

I've opened a follow up issue here: #97599.

TLDR;

Explicitly typing every config in the schema is not practical. We'll be experimenting with flattened_type ES type and runtime fields to query this collector. Both are not yet supported by the collection schema types.

If we had to explicitly specify every kibana config in the schema we'd need to improve our telemetry tooling to automatically do this for devs. Although flattened_type seems promising enough for this use case.

src/core/server/index.ts Show resolved Hide resolved
Comment on lines +113 to +115
public getExposedPluginConfigsToUsage() {
return this.pluginConfigUsageDescriptors;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Why can't this be added to the internal setup contract instead of creating a new method?

Copy link
Member Author

Choose a reason for hiding this comment

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

this function is called in the start function before plugins.start is called. I can expose it from setup but then i'd have to pass it from setup to start via this inside server.

src/core/server/core_usage_data/core_usage_data_service.ts Outdated Show resolved Hide resolved
src/core/server/core_usage_data/core_usage_data_service.ts Outdated Show resolved Hide resolved
Comment on lines 287 to 289
if (typeof isSafe === 'boolean') {
return { explicitlyMarked: true, isSafe };
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm wondering (if I understood the model correctly): with TS support, can this condition actually be false?

Copy link
Member Author

@Bamieh Bamieh Apr 20, 2021

Choose a reason for hiding this comment

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

Correct TS should not allow this case to happen since we only allow boolean leafs. We cannot rely on TS type safety alone since devs can always // @ts-ignore. This would also guard from unexpected changes to the type by mistake in the future (along with tests).

src/core/server/core_usage_data/core_usage_data_service.ts Outdated Show resolved Hide resolved
Comment on lines 561 to 562
// @ts-expect-error
service.getMarkedAsSafe = mockGetMarkedAsSafe;
Copy link
Contributor

Choose a reason for hiding this comment

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

Optional: I think CoreUsageDataService.getMarkedAsSafe can be made static, right? If so, we could extract it to allow proper module mocking.

@Bamieh Bamieh requested a review from a team as a code owner April 20, 2021 10:23
Copy link
Contributor

@pgayvallet pgayvallet 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
Member

@afharo afharo left a comment

Choose a reason for hiding this comment

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

LGTM! Thank you for this, @Bamieh!

Comment on lines 129 to 132
merge(
get(fullSchema, 'properties.stack_stats.properties.kibana.properties.plugins'),
telemetrySchema.plugins
);
Copy link
Member

Choose a reason for hiding this comment

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

🧡

@Bamieh Bamieh enabled auto-merge (squash) April 20, 2021 14:09
@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Unknown metric groups

API count

id before after diff
core 2174 2176 +2

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@Bamieh Bamieh merged commit 0f45381 into elastic:master Apr 20, 2021
@Bamieh Bamieh deleted the usage_collection/changed_config branch April 20, 2021 15:03
kibanamachine added a commit to kibanamachine/kibana that referenced this pull request Apr 20, 2021
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
@kibanamachine
Copy link
Contributor

💚 Backport successful

Status Branch Result
7.x

This backport PR will be merged automatically after passing CI.

kibanamachine added a commit that referenced this pull request Apr 20, 2021
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>

Co-authored-by: Ahmad Bamieh <ahmadbamieh@gmail.com>
madirey pushed a commit to madirey/kibana that referenced this pull request May 11, 2021
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-backport Deprecated: Automatically backport this PR after it's merged Feature:Telemetry release_note:skip Skip the PR/issue when compiling release notes Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc v7.13.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants