-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Conversation
Pinging @elastic/pulse (Team:Pulse) |
82df60e
to
578defe
Compare
@elasticmachine merge upstream |
There was a problem hiding this 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; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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') { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 }], | ||
}; | ||
}, {}); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
💚 Build SucceededHistory
To update your PR or re-run it, just comment with: |
There was a problem hiding this 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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
…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]>
…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]>
* [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]>
* [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]>
* [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]>
Pinging @elastic/kibana-core (Team:Core) |
Summary
os.distros
andos.distroReleases
to the local collectors in Kibana.js
files in the usage_collector plugins (move them to.ts
).Fixes https://github.com/elastic/telemetry/issues/210
Checklist
Use
strikethroughsto remove checklist items you don't feel are applicable to this PR.[ ] This was checked for cross-browser compatibility, including a check against IE11[ ] Any text added follows EUI's writing guidelines, uses sentence case text and includes i18n support[ ] Documentation was added for features that require explanation or tutorials[ ] This was checked for keyboard-only and screenreader accessibilityFor maintainers