-
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
[RAC] Link inventory alerts to the right inventory view #113553
Changes from all commits
f792832
556ca4e
c1d0cf3
269f813
e744466
638999b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { parse } from 'query-string'; | ||
import { Redirect, RouteComponentProps } from 'react-router-dom'; | ||
|
||
// FIXME what would be the right way to build this query string? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we cannot find a good way in this PR we can address this later. If I recall correctly Kibana provides a service already to create good URLs? Maybe it's worth leaving this as is and wait until that service is used in Metrics to update this code There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You would need to use the
As for the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm more concerned about what happens if/when the parameters in the URL change. It feels I'm duplicating things here and it's just a matter of time until it gets changed somewhere else and this breaks. Is there something in metrics to generate valid URLs? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mmm, apparently the I think moving forward it's better to leave the code as it is now (revisiting how the query string is constructed). What do you think @simianhacker? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds good. |
||
const QUERY_STRING_TEMPLATE = | ||
"?waffleFilter=(expression:'',kind:kuery)&waffleTime=(currentTime:{timestamp},isAutoReloading:!f)&waffleOptions=(accountId:'',autoBounds:!t,boundsOverride:(max:1,min:0),customMetrics:!({customMetric}),customOptions:!(),groupBy:!(),legend:(palette:cool,reverseColors:!f,steps:10),metric:{metric},nodeType:{nodeType},region:'',sort:(by:name,direction:desc),timelineOpen:!f,view:map)"; | ||
|
||
export const RedirectToInventory: React.FC<RouteComponentProps> = ({ location }) => { | ||
const parsedQueryString = parseQueryString(location.search); | ||
|
||
const inventoryQueryString = QUERY_STRING_TEMPLATE.replace( | ||
/{(\w+)}/g, | ||
(_, key) => parsedQueryString[key] || '' | ||
); | ||
|
||
return <Redirect to={'/inventory' + inventoryQueryString} />; | ||
}; | ||
|
||
function parseQueryString(search: string): Record<string, string> { | ||
if (search.length === 0) { | ||
return {}; | ||
} | ||
|
||
const obj = parse(search.substring(1)); | ||
|
||
// Force all values into string. If they are empty don't create the keys | ||
for (const key in obj) { | ||
if (Object.hasOwnProperty.call(obj, key)) { | ||
if (!obj[key]) { | ||
delete obj[key]; | ||
} | ||
if (Array.isArray(obj.key)) { | ||
obj[key] = obj[key]![0]; | ||
} | ||
} | ||
} | ||
|
||
return obj as Record<string, string>; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,8 @@ | |
* 2.0. | ||
*/ | ||
|
||
import { schema } from '@kbn/config-schema'; | ||
import { schema, Type } from '@kbn/config-schema'; | ||
import { Unit } from '@elastic/datemath'; | ||
import { i18n } from '@kbn/i18n'; | ||
import { PluginSetupContract } from '../../../../../alerting/server'; | ||
import { | ||
|
@@ -26,21 +27,32 @@ import { | |
metricActionVariableDescription, | ||
thresholdActionVariableDescription, | ||
} from '../common/messages'; | ||
import { | ||
SnapshotMetricTypeKeys, | ||
SnapshotMetricType, | ||
InventoryItemType, | ||
} from '../../../../common/inventory_models/types'; | ||
import { | ||
SNAPSHOT_CUSTOM_AGGREGATIONS, | ||
SnapshotCustomAggregation, | ||
} from '../../../../common/http_api/snapshot_api'; | ||
|
||
const condition = schema.object({ | ||
threshold: schema.arrayOf(schema.number()), | ||
comparator: oneOfLiterals(Object.values(Comparator)), | ||
timeUnit: schema.string(), | ||
comparator: oneOfLiterals(Object.values(Comparator)) as Type<Comparator>, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All these type assertions are necessary to make the kibana schema play nicely with the io-ts generated types. |
||
timeUnit: schema.string() as Type<Unit>, | ||
timeSize: schema.number(), | ||
metric: schema.string(), | ||
metric: oneOfLiterals(Object.keys(SnapshotMetricTypeKeys)) as Type<SnapshotMetricType>, | ||
warningThreshold: schema.maybe(schema.arrayOf(schema.number())), | ||
warningComparator: schema.maybe(oneOfLiterals(Object.values(Comparator))), | ||
warningComparator: schema.maybe(oneOfLiterals(Object.values(Comparator))) as Type< | ||
Comparator | undefined | ||
>, | ||
customMetric: schema.maybe( | ||
schema.object({ | ||
type: schema.literal('custom'), | ||
id: schema.string(), | ||
field: schema.string(), | ||
aggregation: schema.string(), | ||
aggregation: oneOfLiterals(SNAPSHOT_CUSTOM_AGGREGATIONS) as Type<SnapshotCustomAggregation>, | ||
label: schema.maybe(schema.string()), | ||
}) | ||
), | ||
|
@@ -59,7 +71,7 @@ export async function registerMetricInventoryThresholdAlertType( | |
params: schema.object( | ||
{ | ||
criteria: schema.arrayOf(condition), | ||
nodeType: schema.string(), | ||
nodeType: schema.string() as Type<InventoryItemType>, | ||
filterQuery: schema.maybe( | ||
schema.string({ validate: validateIsStringElasticsearchJSONFilter }) | ||
), | ||
|
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.
We should probably use
getUrlForApp
here as well.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 is not used within a React context so calling
useKibana
is not possible. I'm looking how easy is to inject the kibana services and it's not that straightforward.The link is correctly prefixed when used (the
prepend()
call in the linked code), so I wonder if that's good 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.
shakes fist at sky "Damn you hooks!"