-
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
[APM] Improve router types #83620
[APM] Improve router types #83620
Conversation
Pinging @elastic/apm-ui (Team:apm) |
Pinging @elastic/uptime (Team:uptime) |
// this is similar to t.intersection, but does a deep merge | ||
// instead of a shallow merge | ||
|
||
export function merge<A extends t.Mixed, B extends t.Mixed>( |
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.
Should it be called deepMerge
then?
Btw. I'm surprised this doesn't already exist in the shared typescript utils.
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.
it's merge
because it uses lodash.merge
. I figured deepMerge
would be overkill.
@@ -24,8 +24,7 @@ import { APIReturnType } from '../../services/rest/createCallApmApi'; | |||
import { units } from '../../style/variables'; | |||
|
|||
export type AnomalyDetectionApiResponse = APIReturnType< | |||
'/api/apm/settings/anomaly-detection', | |||
'GET' | |||
'GET /api/apm/settings/anomaly-detection' |
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.
Reads much nicer 👍
@@ -60,7 +59,7 @@ export function AnomalyDetectionSetupLink() { | |||
export function MissingJobsAlert({ environment }: { environment?: string }) { | |||
const { data = DEFAULT_DATA, status } = useFetcher( | |||
(callApmApi) => | |||
callApmApi({ pathname: `/api/apm/settings/anomaly-detection` }), | |||
callApmApi({ endpoint: `GET /api/apm/settings/anomaly-detection` }), |
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.
feels controversial. I like it!
|
||
const path = (params.path || {}) as Record<string, any>; | ||
const [method, pathname] = endpoint.split(' '); |
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.
This will cause problems if the endpoint contains spaces. Something that's theoretically possible but widely frowned upon (for good reasons).
I don't think we need to handle this - just wanted to point it out so I can link to this conversation when this causes a production incident 5 years from now :D
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 have enough faith in humanity to assume that no one will ever try to register an endpoint with spaces 😅
]), | ||
}), | ||
}, | ||
export const dynamicIndexPatternRoute = createRoute({ |
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.
Shouldn't we be passing processorEvent
along to getDynamicIndexPattern
? If not, will you remove processorEvent
from getDynamicIndexPattern
and getPatternIndices
?
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.
Probably also remove it from here
processorEvent?: ProcessorEvent; |
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've put it back, we were not using it but looks like it was a bug I introduced in 429805d. Previously, we were using query.processorEvent
in setup_request
, but we moved it out of setup_request
into its own function, which required the query param to be passed explicitly, but looked like that never happened.
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.
Nice improvement, thanks!
@@ -53,7 +53,7 @@ export function ClientMetrics() { | |||
(callApmApi) => { | |||
if (uxQuery) { | |||
return callApmApi({ | |||
pathname: '/api/apm/rum/client-metrics', | |||
endpoint: 'GET /api/apm/rum/client-metrics', |
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 am yet to take a look at that apm client contract you have created, will these types continue to work once we move ux code out of apm?
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.
You would have to create your own pseudo-router (create_ux_api
) and client (callUxApi
), but that was already the case, nothing in this PR changes what you need to do I think.
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 !!
💚 Build SucceededMetrics [docs]Async chunks
Distributable file count
History
To update your PR or re-run it, just comment with: |
* [APM] Improve router types * Pass processorEvent param to useDynamicIndexPattern
… into add-logs-to-node-details * 'add-logs-to-node-details' of github.com:phillipb/kibana: (87 commits) [Maps] Add 'crossed' & 'exited' events to tracking alert (elastic#82463) Updating code-owners to use new core/app-services team names (elastic#83731) Add Managed label to data streams and a view switch for the table (elastic#83049) [Maps] Add query bar inputs to geo threshold alerts tracked points & boundaries (elastic#80871) fix(NA): search examples kibana version declaration (elastic#83182) Fixed console error, which appears when saving changes in Edit Alert flyout (elastic#83610) [Alerting] Add `alert.updatedAt` field to represent date of last user edit (elastic#83578) Not resetting server log level if level is defined (elastic#83651) disable incremenetal build for legacy tsconfig.json (elastic#82986) [Workplace Search] Migrate SourceLogic from ent-search (elastic#83593) [Workplace Search] Port Box changes from ent-search (elastic#83675) [APM] Improve router types (elastic#83620) Bump flat to v4.1.1 (elastic#83647) Bump y18n@5 to v5.0.5 (elastic#83644) Bump jsonpointer to v4.1.0 (elastic#83641) Bump is-my-json-valid to v2.20.5 (elastic#83642) [Telemetry] Move Monitoring collection strategy to a collector (elastic#82638) Update typescript eslint to v4.8 (elastic#83520) [ML] Persist URL state for Anomaly detection jobs using metric function (elastic#83507) [ML] Performance improvements to annotations editing in Single Metric Viewer & buttons placement (elastic#83216) ...
* [APM] Improve router types * Pass processorEvent param to useDynamicIndexPattern
Main changes:
params
runtime type, instead of a plain object with a runtime type for each ofpath
,query
andbody
. This makes our types a little easier to maintain (as we can just use much ofio-ts
its tooling) and more composable.pathname
andmethod
intoendpoint
. Previously, if we registered two HTTP methods for the samepathname
, TypeScript would either fail to resolve the route params or merge them together regardless of which one was being used. For an example, see/api/apm/settings/custom_links
, where (according to TypeScript) you can leave out bothbody
andquery
, or specify both, even though one and only one is required on both the GET and the POST route.