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

[Telemetry] Report Kibana distro in local collectors + Usage Collectors in TS #55859

Merged
merged 6 commits into from
Feb 5, 2020

Conversation

afharo
Copy link
Member

@afharo afharo commented Jan 24, 2020

Summary

  • Add the missing os.distros and os.distroReleases to the local collectors in Kibana
  • Add typings to the .js files in the usage_collector plugins (move them to .ts).

Fixes https://github.com/elastic/telemetry/issues/210

Checklist

Use strikethroughs to remove checklist items you don't feel are applicable to this PR.

For maintainers

@afharo afharo added v8.0.0 release_note:skip Skip the PR/issue when compiling release notes v7.7.0 Team:Pulse labels Jan 24, 2020
@afharo afharo requested a review from a team as a code owner January 24, 2020 16:28
@elasticmachine
Copy link
Contributor

Pinging @elastic/pulse (Team:Pulse)

@afharo afharo force-pushed the telemetry/os-distro branch from 82df60e to 578defe Compare January 24, 2020 16:44
@afharo
Copy link
Member Author

afharo commented Jan 27, 2020

@elasticmachine merge upstream

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.

Honestly i'm not a fan of heavily using generics in types. The consumer of collectors (collector set) does not care about collector types since we are looping over all of them and calling their methods, so adding generic types will not be useful it only adds extra steps.

+1 for converting to TS though.

export interface CollectorOptions<T = unknown, U = T> {
type: string;
init?: Function;
fetch: (callCluster: CallCluster) => Promise<T> | T;
Copy link
Member

Choose a reason for hiding this comment

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

I believe callCluster should be optional

  fetch: (callCluster?: CallCluster) => Promise<T> | T;

There is no need to pass generic T at the interface level. We do not need the fetch return type when registering the collector. It could be scoped to fetch or simply the use of ..) => unknown is enough.

Copy link
Member Author

Choose a reason for hiding this comment

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

I believe callCluster should be optional

If we do it optional, every fetch will need to check if callCluster is not undefined before using it, but from the CollectorSet we are always providing it (and we should be enforced to provide it).

Declaring your fetch method without any argument if not using the callCluster parameter is still fine for TS (and even encouraged by eslint). A quick TS-safe example I just tested below:

  usageCollection.makeUsageCollector({
    type: KIBANA_REPORTING_TYPE,
    isReady,
    fetch: () => ({ count: 1 }),
  });

There is no need to pass generic T at the interface level. We do not need the fetch return type when registering the collector. It could be scoped to fetch or simply the use of ..) => unknown is enough.

The reason for being at the interface level is so formatForBulkUpload infers the type from the output of fetch. And it also will fail to compile if formatForBulkUpload is assuming an input different to the output of fetch.

An example is x-pack/legacy/plugins/reporting/server/usage/reporting_usage_collector.ts. You can see there is no need to specify the types when calling makeUsageCollector as it infers it automagically from the methods definitions.


const defaultFormatterForBulkUpload = result => ({ type, payload: result });
this._formatForBulkUpload = formatForBulkUpload || defaultFormatterForBulkUpload;
if (typeof isReady === 'function') {
Copy link
Member

Choose a reason for hiding this comment

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

Lets keep this typeof check. In case someone sets isReady to true the collectorSet will not throw when attempting to execute something other than a function.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure! I was relying on TS to ensure users will only provide a function here, but I'll add the safety check just in case anyone does it in a .js or as any cast

...acc,
[`${key}s`]: [{ [key]: value, count: 1 }],
};
}, {});
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure i understand the difference between the previous code and the current one?

Copy link
Member Author

Choose a reason for hiding this comment

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

The previous code was only mapping os.platforms[].platform and os.platformReleases[].platformRelease.

Now we are copying every element in kibanaStats.os (also including distro and distroRelease), but following the convention of os[keyName + "s"] = [ { [keyName]: value, count: 1 } ] (os[KEY_IN_PLURAL] = Array<{ [KEY]: string, count: number }>).

I can try changing it to something more strict and map the 2 new missing fields (distro and distroRelease), but that will result in the next time we add something to the os payload, we'll face this same issue again.

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

History

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

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.

LGTM thanks for the clarifications

Copy link
Contributor

@TinaHeiligers TinaHeiligers left a comment

Choose a reason for hiding this comment

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

LGTM

@afharo afharo merged commit 2bb4673 into elastic:master Feb 5, 2020
@afharo afharo deleted the telemetry/os-distro branch February 5, 2020 14:08
afharo added a commit to afharo/kibana that referenced this pull request Feb 5, 2020
…rs in TS (elastic#55859)

* [Telemetry] Report Kibana distro in local collectors + Usage Collectors in TS

* Ensure isReady is a function

* Move CollectorSet tests to TS + Jest

* Fix test

Co-authored-by: Elastic Machine <[email protected]>
afharo added a commit that referenced this pull request Feb 5, 2020
…rs in TS (#55859) (#56849)

* [Telemetry] Report Kibana distro in local collectors + Usage Collectors in TS

* Ensure isReady is a function

* Move CollectorSet tests to TS + Jest

* Fix test

Co-authored-by: Elastic Machine <[email protected]>

Co-authored-by: Elastic Machine <[email protected]>
afharo added a commit that referenced this pull request Feb 17, 2020
* [Telemetry] Refactor to TS Monitoring telemetry_collection files

* [Telemetry] Fetch side documents generated by monitoring to build up the Kibana plugins stats

* Update x-pack/legacy/plugins/monitoring/server/telemetry_collection/get_beats_stats.ts

Co-Authored-By: Ahmad Bamieh <[email protected]>

* Fix import in test file

* Move mocha tests to Jest + TS

* Fix extended telemetry in functional tests

* Fix types

* [Telemetry] Fix bug in usage_collector wrong function override

* Revert integration tests (change not needed)

Co-authored-by: Ahmad Bamieh <[email protected]>
Co-authored-by: Elastic Machine <[email protected]>
afharo added a commit to afharo/kibana that referenced this pull request Feb 17, 2020
* [Telemetry] Refactor to TS Monitoring telemetry_collection files

* [Telemetry] Fetch side documents generated by monitoring to build up the Kibana plugins stats

* Update x-pack/legacy/plugins/monitoring/server/telemetry_collection/get_beats_stats.ts

Co-Authored-By: Ahmad Bamieh <[email protected]>

* Fix import in test file

* Move mocha tests to Jest + TS

* Fix extended telemetry in functional tests

* Fix types

* [Telemetry] Fix bug in usage_collector wrong function override

* Revert integration tests (change not needed)

Co-authored-by: Ahmad Bamieh <[email protected]>
Co-authored-by: Elastic Machine <[email protected]>
afharo added a commit that referenced this pull request Feb 17, 2020
* [Telemetry] Refactor to TS Monitoring telemetry_collection files

* [Telemetry] Fetch side documents generated by monitoring to build up the Kibana plugins stats

* Update x-pack/legacy/plugins/monitoring/server/telemetry_collection/get_beats_stats.ts

Co-Authored-By: Ahmad Bamieh <[email protected]>

* Fix import in test file

* Move mocha tests to Jest + TS

* Fix extended telemetry in functional tests

* Fix types

* [Telemetry] Fix bug in usage_collector wrong function override

* Revert integration tests (change not needed)

Co-authored-by: Ahmad Bamieh <[email protected]>
Co-authored-by: Elastic Machine <[email protected]>

Co-authored-by: Ahmad Bamieh <[email protected]>
Co-authored-by: Elastic Machine <[email protected]>
@lukeelmers lukeelmers added Feature:Telemetry Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc labels Oct 1, 2021
@elasticmachine
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.7.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants