-
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
[8.x] [Infra][ObsUX] Hosts & Container Logs only overview (#202992) #204984
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
...ility_solution/infra/public/components/asset_details/hooks/use_chart_series_color.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* 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 { useEuiTheme } from '@elastic/eui'; | ||
import { renderHook } from '@testing-library/react'; | ||
import { useChartSeriesColor } from './use_chart_series_color'; | ||
|
||
describe('useChartSeriesColor', () => { | ||
let seriesDefaultColor: string; | ||
|
||
beforeEach(() => { | ||
const { result } = renderHook(() => useEuiTheme()); | ||
|
||
// Don't try to test a hardcoded value, just use what is provided by EUI. | ||
// If in the future this value changes, the tests won't break. | ||
seriesDefaultColor = result.current.euiTheme.colors.lightestShade; | ||
}); | ||
|
||
it('returns a default color value if given no input', () => { | ||
const { result } = renderHook(() => useChartSeriesColor()); | ||
|
||
expect(result.current).not.toBe(''); | ||
expect(result.current).toBe(seriesDefaultColor); | ||
}); | ||
|
||
it('returns a default color value if given an empty string', () => { | ||
const { result } = renderHook(() => useChartSeriesColor('')); | ||
|
||
expect(result.current).not.toBe(''); | ||
expect(result.current).toBe(seriesDefaultColor); | ||
}); | ||
|
||
it('returns the provided color input', () => { | ||
const { result } = renderHook(() => useChartSeriesColor('#fff')); | ||
|
||
expect(result.current).not.toBe(seriesDefaultColor); | ||
expect(result.current).toBe('#fff'); | ||
}); | ||
}); |
21 changes: 21 additions & 0 deletions
21
...ervability_solution/infra/public/components/asset_details/hooks/use_chart_series_color.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
* 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 { useEuiTheme } from '@elastic/eui'; | ||
|
||
/** | ||
* Provides either the input color, or yields the default EUI theme | ||
* color for use as the KPI chart series color. | ||
* @param seriesColor A user-defined color value | ||
* @returns Either the input `seriesColor` or the default color from EUI | ||
*/ | ||
export const useChartSeriesColor = (seriesColor?: string): string => { | ||
const { euiTheme } = useEuiTheme(); | ||
|
||
// Prevent empty string being used as a valid color | ||
return seriesColor || euiTheme.colors.lightestShade; | ||
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. Same as above |
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
...gins/observability_solution/infra/public/components/asset_details/hooks/use_log_charts.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* 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 { i18n } from '@kbn/i18n'; | ||
import { useMemo } from 'react'; | ||
import { LensConfig } from '@kbn/lens-embeddable-utils/config_builder'; | ||
import { useChartSeriesColor } from './use_chart_series_color'; | ||
|
||
const LOG_RATE = i18n.translate('xpack.infra.assetDetails.charts.logRate', { | ||
defaultMessage: 'Log Rate', | ||
}); | ||
|
||
const LOG_ERROR_RATE = i18n.translate('xpack.infra.assetDetails.charts.logErrorRate', { | ||
defaultMessage: 'Log Error Rate', | ||
}); | ||
|
||
const logRateMetric: LensConfig & { id: string } = { | ||
id: 'logMetric', | ||
chartType: 'metric', | ||
title: LOG_RATE, | ||
label: LOG_RATE, | ||
trendLine: true, | ||
value: 'count()', | ||
format: 'number', | ||
decimals: 1, | ||
normalizeByUnit: 's', | ||
}; | ||
|
||
const logErrorRateMetric: LensConfig & { id: string } = { | ||
id: 'logErrorMetric', | ||
chartType: 'metric', | ||
title: LOG_ERROR_RATE, | ||
label: LOG_ERROR_RATE, | ||
trendLine: true, | ||
value: | ||
'count(kql=\'log.level: "error" OR log.level: "ERROR" OR error.log.level: "error" OR error.log.level: "ERROR"\')', | ||
format: 'number', | ||
decimals: 1, | ||
normalizeByUnit: 's', | ||
}; | ||
|
||
export const useLogsCharts = ({ | ||
dataViewId, | ||
seriesColor, | ||
}: { | ||
dataViewId?: string; | ||
seriesColor?: string; | ||
}) => { | ||
seriesColor = useChartSeriesColor(seriesColor); | ||
|
||
return useMemo(() => { | ||
const dataset = dataViewId && { | ||
dataset: { | ||
index: dataViewId, | ||
}, | ||
}; | ||
|
||
return { | ||
charts: [ | ||
{ | ||
...logRateMetric, | ||
...dataset, | ||
seriesColor, | ||
}, | ||
{ | ||
...logErrorRateMetric, | ||
...dataset, | ||
seriesColor, | ||
}, | ||
], | ||
}; | ||
}, [dataViewId, seriesColor]); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
...ugins/observability_solution/infra/public/components/asset_details/tabs/overview/logs.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* 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, { useMemo } from 'react'; | ||
import type { DataView } from '@kbn/data-views-plugin/public'; | ||
import type { TimeRange } from '@kbn/es-query'; | ||
import { EuiFlexGroup, EuiFlexItem } from '@elastic/eui'; | ||
import { | ||
findInventoryFields, | ||
type InventoryItemType, | ||
} from '@kbn/metrics-data-access-plugin/common'; | ||
import { buildCombinedAssetFilter } from '../../../../utils/filters/build'; | ||
import { useSearchSessionContext } from '../../../../hooks/use_search_session'; | ||
import { useLogsCharts } from '../../hooks/use_log_charts'; | ||
import { Kpi } from '../../components/kpis/kpi'; | ||
|
||
interface Props { | ||
dataView?: DataView; | ||
assetId: string; | ||
assetType: InventoryItemType; | ||
dateRange: TimeRange; | ||
} | ||
|
||
export const LogsContent = ({ assetId, assetType, dataView, dateRange }: Props) => { | ||
const { searchSessionId } = useSearchSessionContext(); | ||
|
||
const filters = useMemo(() => { | ||
return [ | ||
buildCombinedAssetFilter({ | ||
field: findInventoryFields(assetType).id, | ||
values: [assetId], | ||
dataView, | ||
}), | ||
]; | ||
}, [dataView, assetId, assetType]); | ||
|
||
const { charts } = useLogsCharts({ | ||
dataViewId: dataView?.id, | ||
}); | ||
|
||
return ( | ||
<EuiFlexGroup direction="row" gutterSize="s" data-test-subj="infraAssetDetailsLogsGrid"> | ||
{charts.map((chartProps, index) => ( | ||
<EuiFlexItem key={index}> | ||
<Kpi | ||
{...chartProps} | ||
dateRange={dateRange} | ||
filters={filters} | ||
searchSessionId={searchSessionId} | ||
/> | ||
</EuiFlexItem> | ||
))} | ||
</EuiFlexGroup> | ||
); | ||
}; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 had to change the variable being used here from backgroundLightText to lightestShade as the new semantic tokens aren't in 8.x (was mistaken about them being in 8.x)