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

[RAC] Populate Observability alerts table with data from alerts indices #96692

Merged
merged 29 commits into from
Apr 15, 2021

Conversation

dgieselaar
Copy link
Member

@dgieselaar dgieselaar commented Apr 9, 2021

Closes #96566, #96624, #96531, #96563.

Changes to the rule registry:

  • The rule registry now has a public plugin as well. It doesn’t do much other than creating a client-side root rule registry, and exposing it in its setup contract.
  • The scopedRuleRegistryClient now expects rule uuids to be passed into it, rather than fetching it by itself. I ran into issues with using a scoped saved objects client, and I couldn’t figure out how to get access to the alertsClient inside a rule executor, only in the context of a request. That means that the scopedRuleRegistryClient in a rule executor can also only read data from that rule. That is something that should be fixed at some point, to enable alerts on alerts.
  • The rule registry now attempts to update template and index mappings on startup. This is to make it easier for now to make changes to the mappings. We probably need a different strategy once it’s no longer experimental.
  • The scopedRuleRegistryClient now also has a getDynamicIndexPattern() that is used for the search bar. Probably autocompletion needs to be moved to the server entirely, because non-superusers will likely not have access to the alerts indices by default.

Observability/APM changes:

  • The APM rules now also store evaluation data (value & threshold).
  • A top alerts API endpoint is added in the Observability plugin.
  • Some code was moved and/or copied from the APM folder to allow the Observability plugin to use it.
  • The APM rule types now implement a format() function that takes an alert, and returns a reason/link that is used in the alerts table and flyout.

@dgieselaar dgieselaar added Team:APM All issues that need APM UI Team support release_note:skip Skip the PR/issue when compiling release notes v7.13.0 Theme: rac label obsolete labels Apr 9, 2021
Comment on lines 54 to 70
const alertsDynamicIndexPatternRoute = createObservabilityServerRoute({
endpoint: 'GET /api/observability/rules/alerts/dynamic_index_pattern',
options: {
tags: [],
},
handler: async ({ ruleRegistry, context }) => {
const ruleRegistryClient = ruleRegistry.createScopedRuleRegistryClient({
context,
});

if (!ruleRegistryClient) {
throw Boom.failedDependency();
}

return ruleRegistryClient.getDynamicIndexPattern();
},
});
Copy link
Contributor

@shahzad31 shahzad31 Apr 12, 2021

Choose a reason for hiding this comment

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

you can use data.indexPatterns.getFieldsForWildcard on client, i don't think it make sense to create a separate route for it.

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 call is done with the internal user. I assume that's not possible in the browser?

Copy link
Contributor

Choose a reason for hiding this comment

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

you are right, but will it make a different in this case? AFAIK, you can't assign individual permissions to index patterns. Kibana permissions are weird as far as data goes, they are useful for limiting UI features though.

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'm not sure what you mean with "assign individual permissions to index patterns"?

Copy link
Contributor

@smith smith left a comment

Choose a reason for hiding this comment

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

This looks good as-is.

We're going to need to do something about the bundle size. The rule registry plugin has extraPublicDirs: common so anything exported from common gets loaded on every page load. We might have to limit what's in common. Not sure where the APM increase is coming from. Haven't looked.

I suppose some increase in bundle size is acceptable since we're adding new features.

import { ObservabilityRuleRegistry } from '../plugin';

const createRuleRegistryMock = () => ({
registerType: jest.fn(),
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we're trying to use these in stories, where there is no jest global.

logger: Logger;
params: TParams;
}): Promise<ESSearchResponse<unknown, TParams>> {
// logger.debug(JSON.stringify(params, null, 2));
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove this?

const response = await scopedClusterClient.asCurrentUser.search({
...params,
ignore_unavailable: true,
});

// logger.debug(JSON.stringify(response.body, null, 2));
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove this?

@@ -149,6 +150,10 @@ export function registerTransactionDurationAlertType({
? { [SERVICE_ENVIRONMENT]: environmentParsed.esFieldValue }
: {}),
[TRANSACTION_TYPE]: alertParams.transactionType,
[PROCESSOR_EVENT]: ProcessorEvent.transaction,
'kibana.observability.evaluation.value': transactionDuration,
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we have constants for these?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I do miss the constants from APM. But I'll put this one on the TODO list, I need to look at how the mappings/types are generated anyway.

@dgieselaar dgieselaar marked this pull request as ready for review April 14, 2021 15:08
@dgieselaar dgieselaar requested review from a team as code owners April 14, 2021 15:08
@elasticmachine
Copy link
Contributor

Pinging @elastic/apm-ui (Team:apm)

@dgieselaar dgieselaar requested a review from spong April 14, 2021 15:08
@dgieselaar
Copy link
Member Author

@elastic/kibana-operations I've created #97128 to look at the bundle size.

@@ -61,6 +61,7 @@ pageLoadAssetSize:
remoteClusters: 51327
reporting: 183418
rollup: 97204
ruleRegistry: 107971
Copy link
Member

Choose a reason for hiding this comment

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

Can start this with 100kb? It looks like it should still pass the limits check.

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 thing 👍

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
apm 1573 1574 +1
observability 314 334 +20
ruleRegistry - 17 +17
total +38

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
apm 4.2MB 4.1MB -54.5KB
observability 416.8KB 441.8KB +25.1KB
total -29.5KB

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
apm 22.2KB 53.5KB +31.3KB
observability 35.1KB 39.0KB +3.9KB
ruleRegistry - 90.8KB +90.8KB
total +126.0KB

History

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

@shahzad31
Copy link
Contributor

It more than doubles page load bundles for apm and i have seen the since RAC initiative , observability plugin page load bundle is also increasing bit by bit in each PR.

I worked hard on reducing at least these two bundles :D

can we please put an extra effort to make sure this can be avoided? Will really appreciate that.

@dgieselaar
Copy link
Member Author

@shahzad31 #97128.

}

return asBytes;
};
Copy link
Member

Choose a reason for hiding this comment

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

I don't see this file as deleted. So it was just copied over from APM?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah :(

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 tried copying one over, but they're all somehow connected, so ended up copying the whole folder and assuming we will start using those from APM in the near future).

@@ -28,7 +28,7 @@ type InferResponseType<TReturn> = Exclude<TReturn, undefined> extends Promise<in
: unknown;

export function useFetcher<TReturn>(
Copy link
Member

Choose a reason for hiding this comment

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

Should we delete the useFetcher hook in APM to avoid the two drifting apart again?

Copy link
Member Author

Choose a reason for hiding this comment

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

Preferably yes! But it's kind of hard to share public code right now. Hoping we can tackle that later.

Copy link
Member

@sorenlouv sorenlouv left a comment

Choose a reason for hiding this comment

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

Wow, huuuge PR! But overall lgtm.

@dgieselaar
Copy link
Member Author

dgieselaar commented Apr 15, 2021

@shahzad31 @jbudz I've opened up a PR that hopefully reduces the page load bundle size somewhat again. I think the rule registry plugin is down to 10k and the APM one is down again as well (though it's still a small increase). #97251

Copy link
Member

@spong spong left a comment

Choose a reason for hiding this comment

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

Rule registry changes LGTM! 👍

@dgieselaar dgieselaar merged commit 5bb9eec into elastic:master Apr 15, 2021
@dgieselaar dgieselaar deleted the observability-rule-apis branch April 15, 2021 16:25
dgieselaar added a commit to dgieselaar/kibana that referenced this pull request Apr 18, 2021
…es (elastic#96692)

* Set up Observability rule APIs

* Populate alerts table with data from API

* Move field map types/utils to common

* Format reason/link in alert type

* Format reason/link in alert type

* Fix issues with tsconfigs

* Storybook cleanup for example alerts

* Use `MemoryRouter` in the stories and `useHistory` in the component to get the history
* Replace examples with ones from "real" data
* Use `() => {}` instead of `jest.fn()` in mock registry data

* Store/display evaluations, add active/recovered badge

* Some more story fixes

* Decode rule data with type from owning registry

* Use transaction type/environment in link to app

* Fix type issues

* Fix API tests

* Undo changes in task_runner.ts

* Remove Mutable<> wrappers for field map

* Remove logger.debug calls in alerting es client

* Add API test for recovery of alerts

* Revert changes to src/core/server/http/router

* Use type imports where possible

* Update limits

* Set limit to 100kb

Co-authored-by: Nathan L Smith <[email protected]>
dgieselaar added a commit that referenced this pull request Apr 18, 2021
…es (#96692) (#97399)

* Set up Observability rule APIs

* Populate alerts table with data from API

* Move field map types/utils to common

* Format reason/link in alert type

* Format reason/link in alert type

* Fix issues with tsconfigs

* Storybook cleanup for example alerts

* Use `MemoryRouter` in the stories and `useHistory` in the component to get the history
* Replace examples with ones from "real" data
* Use `() => {}` instead of `jest.fn()` in mock registry data

* Store/display evaluations, add active/recovered badge

* Some more story fixes

* Decode rule data with type from owning registry

* Use transaction type/environment in link to app

* Fix type issues

* Fix API tests

* Undo changes in task_runner.ts

* Remove Mutable<> wrappers for field map

* Remove logger.debug calls in alerting es client

* Add API test for recovery of alerts

* Revert changes to src/core/server/http/router

* Use type imports where possible

* Update limits

* Set limit to 100kb

Co-authored-by: Nathan L Smith <[email protected]>

Co-authored-by: Nathan L Smith <[email protected]>
@@ -61,6 +61,7 @@ pageLoadAssetSize:
remoteClusters: 51327
reporting: 183418
rollup: 97204
ruleRegistry: 100000
Copy link
Contributor

Choose a reason for hiding this comment

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

I know this is a bit late, but shouldn't this be near 0 since there's no actual UI yet?

Copy link
Contributor

Choose a reason for hiding this comment

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

There isn't any UI, but there is the rule registry setup/and start methods and the RuleRegistry class is exported. The bundle includes some io/fp-ts utils and the ECS field mapping, which takes up most of the space.

Copy link
Member Author

Choose a reason for hiding this comment

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

It's down to 10kb now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release_note:skip Skip the PR/issue when compiling release notes Team:APM All issues that need APM UI Team support Theme: rac label obsolete v7.13.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Populate observability alerts table with alert data
9 participants