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 basic StatusService #60335

Merged
merged 8 commits into from
Apr 8, 2020
Merged

Add basic StatusService #60335

merged 8 commits into from
Apr 8, 2020

Conversation

joshdover
Copy link
Contributor

@joshdover joshdover commented Mar 16, 2020

Summary

Related to #41983
Follows the spec outlined in RFC-0010.

This implements the basics of the StatusService + exposes the core status of the Elasticsearch and SavedObject services. These values are not currently being read by anything in the system yet, but will be in a future change.

Checklist

Delete any items that are not applicable to this PR.

For maintainers

@joshdover joshdover force-pushed the np/core-status branch 2 times, most recently from 8d567b7 to ed6c080 Compare March 20, 2020 00:36
@joshdover joshdover added Feature:New Platform 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.8.0 labels Mar 23, 2020
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-platform (Team:Platform)

@joshdover joshdover marked this pull request as ready for review March 23, 2020 21:42
@joshdover joshdover requested a review from a team as a code owner March 23, 2020 21:42
src/core/server/elasticsearch/status.ts Outdated Show resolved Hide resolved
src/core/server/elasticsearch/status.test.ts Outdated Show resolved Hide resolved
src/core/server/saved_objects/status.ts Outdated Show resolved Hide resolved
src/core/server/server.ts Outdated Show resolved Hide resolved
src/core/server/status/status_service.mock.ts Outdated Show resolved Hide resolved
src/core/server/status/types.ts Outdated Show resolved Hide resolved
src/core/server/status/types.ts Outdated Show resolved Hide resolved
src/core/server/status/types.ts Outdated Show resolved Hide resolved
src/core/server/status/types.ts Show resolved Hide resolved
src/core/server/saved_objects/status.ts Outdated Show resolved Hide resolved
src/core/server/saved_objects/status.ts Show resolved Hide resolved
src/core/server/status/types.ts Outdated Show resolved Hide resolved
src/core/server/saved_objects/status.ts Outdated Show resolved Hide resolved
src/core/server/elasticsearch/status.ts Show resolved Hide resolved
src/core/server/elasticsearch/status.ts Outdated Show resolved Hide resolved
src/core/server/elasticsearch/status.test.ts Outdated Show resolved Hide resolved
expect(statusUpdates.map(({ level, summary }) => ({ level, summary }))).toMatchInlineSnapshot(`
Array [
Object {
"level": 2,
Copy link
Contributor

Choose a reason for hiding this comment

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

That demonstrates why we should use string enum https://www.typescriptlang.org/docs/handbook/enums.html#string-enums or a union of strings.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I think the sorting property that I liked from a regular integer enum can be expressed as a utility. String readability is probably more important. 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually on second thought, I think we're more often concerned with comparisons than we are with the string output (which is really only needed in the API outputs).

If we move to string enums, we would probably want to include a utility like this:

export const statusComparator = {
  gt: (a: ServiceStatusLevel, b: ServiceStatusLevel): boolean => compareFn(a, b) === 1,
  gte: (a: ServiceStatusLevel, b: ServiceStatusLevel): boolean => compareFn(a, b) >= 0,
  lt: (a: ServiceStatusLevel, b: ServiceStatusLevel): boolean => compareFn(a, b) === -1,
  lte: (a: ServiceStatusLevel, b: ServiceStatusLevel): boolean => compareFn(a, b) <= -1,
  eq: (a: ServiceStatusLevel, b: ServiceStatusLevel): boolean => compareFn(a, b) === 0,
  compareFn,
};

However, I think this will be far less discoverable. Since doing comparisons like esStatus >= unavailable may be very common, I don't think this is an improvement. WDYT?

Copy link
Contributor

@mshustov mshustov Mar 31, 2020

Choose a reason for hiding this comment

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

However, I think this will be far less discoverable. Since doing comparisons like esStatus >= unavailable may be very common, I don't think this is an improvement. WDYT?

Optional: We can define each level as an object or a class instance with a valueOf method to make them comparable.

const available = {
  toString() {
    return 'available';
  },
  valueOf() {
    return 0;
  },
};

const degraded = {
  toString() {
    return 'degraded';
  },
  valueOf() {
    return 1;
  },
};
const levels = {
  available,
  degraded,
};

console.log(levels.available === levels.available);
console.log(levels.available > levels.degraded);
console.log(levels.available === levels.degraded);
console.log(levels.available < levels.degraded);

but the current implementation is ok for me

Copy link
Contributor

Choose a reason for hiding this comment

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

const available = {
  toString() {
    return 'available';
  },
  valueOf() {
    return 0;
  },
};

Would love to have java enum class implementation in TS. that would really solves this kind of issues in a graceful way...

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 idea, switched to this pattern. It doesn't work for array sorting, but I'm less concerned about that being a common use case.

src/core/server/status/types.ts Outdated Show resolved Hide resolved
src/core/server/saved_objects/status.ts Outdated Show resolved Hide resolved
src/core/server/saved_objects/status.ts Outdated Show resolved Hide resolved
src/core/server/saved_objects/status.ts Outdated Show resolved Hide resolved
src/core/server/status/status_service.mock.ts Outdated Show resolved Hide resolved
@joshdover
Copy link
Contributor Author

Updated addressing all comments. The only thing that I think needs discussion is whether we should use integer enums or a string enum.

I prefer the integer enum since it allows for easy comparison between status levels, which is very convenient. As I outlined here we could provide utilities to make this easier with string enums, however I worry that it won't be as easily discoverable.

src/core/server/elasticsearch/status.ts Outdated Show resolved Hide resolved
Comment on lines 126 to 129
if (this.migrationResult === undefined || rerun) {
this.status$.next({ status: 'running' });
this.migrationResult = this.runMigrationsInternal();
}
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 mixed about the fact to re-emit running status in case of runMigrations({ rerun: true}). OTOH, this should only be used for FTR tests, so I guess that's alright.

Copy link
Contributor

@rudolf rudolf left a comment

Choose a reason for hiding this comment

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

Happy for this to be merge if we've removed the double replay

Comment on lines 55 to 56
distinctUntilChanged(isDeepStrictEqual),
shareReplay(1)
Copy link
Contributor

Choose a reason for hiding this comment

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

We do another distinctUntilChanged and shareReplay in setupCoreStatus so we can remove 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.

Maybe the shareReplay could be removed but I think we could still produce duplicate statuses since the summary rollup may or may not be the same value.

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

History

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

@joshdover joshdover merged commit f84773f into elastic:master Apr 8, 2020
@joshdover joshdover deleted the np/core-status branch April 8, 2020 19:16
joshdover added a commit to joshdover/kibana that referenced this pull request Apr 8, 2020
jloleysens added a commit to jloleysens/kibana that referenced this pull request Apr 9, 2020
…chore/put-all-xjson-together

* 'master' of github.com:elastic/kibana: (35 commits)
  [SIEM] [Detection Engine] Fixes bug when notification doesn't… (elastic#63013)
  [SIEM][Detection Engine] Fix rule notification critical bugs
  Add Error Exception Type Column (elastic#59596)
  [APM] Agent remote configuration: changes in Java property descriptions (elastic#62282)
  [Alerting] Displays warning when a permanent encryption key is missing and hides alerting UI appropriately (elastic#62772)
  FTR: add chromium-based Edge browser support (elastic#61684)
  [Ingest] Data source configuration validation UI (elastic#61180)
  restore empty_kibana after saved objects test (elastic#62951)
  Index pattern management plugin - src/legacy/core_plugins/management => new platform plugin (elastic#62594)
  Add basic StatusService (elastic#60335)
  [kbn/optimizer] link to kibanaReact/kibanaUtils plugins (elastic#62720)
  [APM] Service map - fixes layout issues for maps with no rum services (elastic#62887)
  Exclude disabled datasources and streams from agent config (elastic#62869)
  [Alerting] Fix validation support for nested IErrorObjects (elastic#62833)
  [Metrics UI] Invalidate non-count alerts which have no metrics (elastic#62837)
  Add --filter option to API docs script (elastic#62888)
  [Maps] fix attribution overflow with exit full screen button (elastic#62699)
  [Uptime]Alerting UI text in case filter is selected (elastic#62570)
  [Maps] Show create filter button for top-term tooltip property (elastic#62461)
  skip flaky suite (elastic#59030)
  ...

# Conflicts:
#	src/plugins/es_ui_shared/public/index.ts
gmmorris added a commit to gmmorris/kibana that referenced this pull request Apr 9, 2020
* master: (40 commits)
  [ML] Functional transform tests - stabilize source selection (elastic#63087)
  add embed flag to saved object url as well (elastic#62926)
  [SIEM] [Detection Engine] Fixes bug when notification doesn't… (elastic#63013)
  [SIEM][Detection Engine] Fix rule notification critical bugs
  Add Error Exception Type Column (elastic#59596)
  [APM] Agent remote configuration: changes in Java property descriptions (elastic#62282)
  [Alerting] Displays warning when a permanent encryption key is missing and hides alerting UI appropriately (elastic#62772)
  FTR: add chromium-based Edge browser support (elastic#61684)
  [Ingest] Data source configuration validation UI (elastic#61180)
  restore empty_kibana after saved objects test (elastic#62951)
  Index pattern management plugin - src/legacy/core_plugins/management => new platform plugin (elastic#62594)
  Add basic StatusService (elastic#60335)
  [kbn/optimizer] link to kibanaReact/kibanaUtils plugins (elastic#62720)
  [APM] Service map - fixes layout issues for maps with no rum services (elastic#62887)
  Exclude disabled datasources and streams from agent config (elastic#62869)
  [Alerting] Fix validation support for nested IErrorObjects (elastic#62833)
  [Metrics UI] Invalidate non-count alerts which have no metrics (elastic#62837)
  Add --filter option to API docs script (elastic#62888)
  [Maps] fix attribution overflow with exit full screen button (elastic#62699)
  [Uptime]Alerting UI text in case filter is selected (elastic#62570)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:New Platform 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.8.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants