Skip to content

Commit

Permalink
Merge branch 'master' into kibana-page-template-as-1
Browse files Browse the repository at this point in the history
  • Loading branch information
Constance committed Jun 21, 2021
2 parents 1fc987e + 79b0949 commit eea67d6
Show file tree
Hide file tree
Showing 81 changed files with 803 additions and 713 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) &gt; [AggConfigs](./kibana-plugin-plugins-data-public.aggconfigs.md) &gt; [getResolvedTimeRange](./kibana-plugin-plugins-data-public.aggconfigs.getresolvedtimerange.md)

## AggConfigs.getResolvedTimeRange() method

Returns the current time range as moment instance (date math will get resolved using the current "now" value or system time if not set)

<b>Signature:</b>

```typescript
getResolvedTimeRange(): import("../..").TimeRangeBounds | undefined;
```
<b>Returns:</b>

`import("../..").TimeRangeBounds | undefined`

Current time range as resolved date.

Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export declare class AggConfigs
| [getAll()](./kibana-plugin-plugins-data-public.aggconfigs.getall.md) | | |
| [getRequestAggById(id)](./kibana-plugin-plugins-data-public.aggconfigs.getrequestaggbyid.md) | | |
| [getRequestAggs()](./kibana-plugin-plugins-data-public.aggconfigs.getrequestaggs.md) | | |
| [getResolvedTimeRange()](./kibana-plugin-plugins-data-public.aggconfigs.getresolvedtimerange.md) | | Returns the current time range as moment instance (date math will get resolved using the current "now" value or system time if not set) |
| [getResponseAggById(id)](./kibana-plugin-plugins-data-public.aggconfigs.getresponseaggbyid.md) | | Find a response agg by it's id. This may be an agg in the aggConfigs, or one created specifically for a response value |
| [getResponseAggs()](./kibana-plugin-plugins-data-public.aggconfigs.getresponseaggs.md) | | Gets the AggConfigs (and possibly ResponseAggConfigs) that represent the values that will be produced when all aggs are run.<!-- -->With multi-value metric aggs it is possible for a single agg request to result in multiple agg values, which is why the length of a vis' responseValuesAggs may be different than the vis' aggs {<!-- -->array\[AggConfig\]<!-- -->} |
| [getSearchSourceTimeFilter(forceNow)](./kibana-plugin-plugins-data-public.aggconfigs.getsearchsourcetimefilter.md) | | |
Expand Down
14 changes: 6 additions & 8 deletions src/core/server/core_usage_data/core_usage_data_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,12 @@ export class CoreUsageDataService implements CoreService<CoreUsageDataSetup, Cor
const stats = body[0];
return {
alias: kibanaOrTaskManagerIndex(index, this.kibanaConfig!.index),
// @ts-expect-error @elastic/elasticsearch declares it 'docs.count' as optional
docsCount: parseInt(stats['docs.count'], 10),
// @ts-expect-error @elastic/elasticsearch declares it 'docs.deleted' as optional
docsDeleted: parseInt(stats['docs.deleted'], 10),
// @ts-expect-error @elastic/elasticsearch declares it 'store.size' as string | number
storeSizeBytes: parseInt(stats['store.size'], 10),
// @ts-expect-error @elastic/elasticsearch declares it 'pri.store.size' as string | number
primaryStoreSizeBytes: parseInt(stats['pri.store.size'], 10),
docsCount: stats['docs.count'] ? parseInt(stats['docs.count'], 10) : 0,
docsDeleted: stats['docs.deleted'] ? parseInt(stats['docs.deleted'], 10) : 0,
storeSizeBytes: stats['store.size'] ? parseInt(stats['store.size'], 10) : 0,
primaryStoreSizeBytes: stats['pri.store.size']
? parseInt(stats['pri.store.size'], 10)
: 0,
};
});
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,12 +187,8 @@ async function migrateSourceToDest(context: Context) {
await Index.write(
client,
dest.indexName,
await migrateRawDocs(
serializer,
documentMigrator.migrateAndConvert,
// @ts-expect-error @elastic/elasticsearch `Hit._id` may be a string | number in ES, but we always expect strings in the SO index.
docs
)
// @ts-expect-error @elastic/elasticsearch _source is optional
await migrateRawDocs(serializer, documentMigrator.migrateAndConvert, docs)
);
}
}
4 changes: 2 additions & 2 deletions src/core/server/saved_objects/service/lib/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -897,10 +897,10 @@ export class SavedObjectsRepository {
total: body.hits.total,
saved_objects: body.hits.hits.map(
(hit: estypes.SearchHit<SavedObjectsRawDocSource>): SavedObjectsFindResult => ({
// @ts-expect-error @elastic/elasticsearch declared Id as string | number
// @ts-expect-error @elastic/elasticsearch _source is optional
...this._rawToSavedObject(hit),
score: hit._score!,
// @ts-expect-error @elastic/elasticsearch declared sort as string | number
// @ts-expect-error @elastic/elasticsearch _source is optional
sort: hit.sort,
})
),
Expand Down
2 changes: 2 additions & 0 deletions src/core/types/elasticsearch/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,9 @@ export type AggregateOf<
{
key: string;
from?: number;
from_as_string?: string;
to?: number;
to_as_string?: string;
doc_count: number;
},
TAggregationContainer extends { range: { ranges: Array<infer TRangeType> } }
Expand Down
5 changes: 2 additions & 3 deletions src/plugins/data/common/search/aggs/agg_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,8 @@ export class AggConfig {
} else if (!this.aggConfigs.timeRange) {
return;
}
return moment.duration(
moment(this.aggConfigs.timeRange.to).diff(this.aggConfigs.timeRange.from)
);
const resolvedBounds = this.aggConfigs.getResolvedTimeRange()!;
return moment.duration(moment(resolvedBounds.max).diff(resolvedBounds.min));
}
return parsedTimeShift;
}
Expand Down
15 changes: 14 additions & 1 deletion src/plugins/data/common/search/aggs/agg_configs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { IAggType } from './agg_type';
import { AggTypesRegistryStart } from './agg_types_registry';
import { AggGroupNames } from './agg_groups';
import { IndexPattern } from '../../index_patterns/index_patterns/index_pattern';
import { TimeRange, getTime, isRangeFilter } from '../../../common';
import { TimeRange, getTime, isRangeFilter, calculateBounds } from '../../../common';
import { IBucketAggConfig } from './buckets';
import { insertTimeShiftSplit, mergeTimeShifts } from './utils/time_splits';

Expand Down Expand Up @@ -127,6 +127,19 @@ export class AggConfigs {
this.aggs.forEach(updateAggTimeRange);
}

/**
* Returns the current time range as moment instance (date math will get resolved using the current "now" value or system time if not set)
* @returns Current time range as resolved date.
*/
getResolvedTimeRange() {
return (
this.timeRange &&
calculateBounds(this.timeRange, {
forceNow: this.forceNow,
})
);
}

// clone method will reuse existing AggConfig in the list (will not create new instances)
clone({ enabledOnly = true } = {}) {
const filterAggs = (agg: AggConfig) => {
Expand Down
1 change: 1 addition & 0 deletions src/plugins/data/public/public.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ export class AggConfigs {
getRequestAggById(id: string): AggConfig | undefined;
// (undocumented)
getRequestAggs(): AggConfig[];
getResolvedTimeRange(): import("../..").TimeRangeBounds | undefined;
getResponseAggById(id: string): AggConfig | undefined;
getResponseAggs(): AggConfig[];
// (undocumented)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ export async function getSavedObjectsCounts(
},
};
const { body } = await esClient.search(savedObjectCountSearchParams);
// @ts-expect-error @elastic/elasticsearch Aggregate does not include `buckets`
// @ts-expect-error declare type for aggregations explicitly
return body.aggregations?.types?.buckets || [];
}
18 changes: 7 additions & 11 deletions src/plugins/security_oss/server/check_cluster_data.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,19 @@ describe('checkClusterForUserData', () => {
it('returns false if data only exists in system indices', async () => {
const esClient = elasticsearchServiceMock.createElasticsearchClient();
esClient.cat.indices.mockResolvedValue(
// @ts-expect-error @elastic/elasticsearch ES types don't support array response format
elasticsearchServiceMock.createApiResponse({
body: [
{
index: '.kibana',
'docs.count': 500,
'docs.count': '500',
},
{
index: 'kibana_sample_ecommerce_data',
'docs.count': 20,
'docs.count': '20',
},
{
index: '.somethingElse',
'docs.count': 20,
'docs.count': '20',
},
],
})
Expand All @@ -56,16 +55,15 @@ describe('checkClusterForUserData', () => {
it('returns true if data exists in non-system indices', async () => {
const esClient = elasticsearchServiceMock.createElasticsearchClient();
esClient.cat.indices.mockResolvedValue(
// @ts-expect-error @elastic/elasticsearch ES types don't support array response format
elasticsearchServiceMock.createApiResponse({
body: [
{
index: '.kibana',
'docs.count': 500,
'docs.count': '500',
},
{
index: 'some_real_index',
'docs.count': 20,
'docs.count': '20',
},
],
})
Expand All @@ -87,23 +85,21 @@ describe('checkClusterForUserData', () => {
)
.mockRejectedValueOnce(new Error('something terrible happened'))
.mockResolvedValueOnce(
// @ts-expect-error @elastic/elasticsearch ES types don't support array response format
elasticsearchServiceMock.createApiResponse({
body: [
{
index: '.kibana',
'docs.count': 500,
'docs.count': '500',
},
],
})
)
.mockResolvedValueOnce(
// @ts-expect-error @elastic/elasticsearch ES types don't support array response format
elasticsearchServiceMock.createApiResponse({
body: [
{
index: 'some_real_index',
'docs.count': 20,
'docs.count': '20',
},
],
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,21 @@ export default function ({
expect(getCell(result, 0, 2)).to.be(4618);
});

it('shifts multiple metrics with relative time range and previous', async () => {
const expression = `
kibana_context timeRange={timerange from='${timeRange.from}' to='now'}
| esaggs index={indexPatternLoad id='logstash-*'}
aggs={aggCount id="1" enabled=true schema="metric"}
aggs={aggCount id="2" enabled=true schema="metric" timeShift="previous"}
`;
const result = await expectExpression(
'esaggs_shift_multi_metric_previous',
expression
).getResponse();
expect(getCell(result, 0, 0)).to.be(9247);
expect(getCell(result, 0, 1)).to.be(4763);
});

it('shifts single percentile', async () => {
const expression = `
kibana_context timeRange={timerange from='${timeRange.from}' to='${timeRange.to}'}
Expand Down Expand Up @@ -137,7 +152,7 @@ export default function ({
customMetric={aggAvg id="3"
field="bytes"
enabled=true
schema="metric"
schema="metric"
}
enabled=true
schema="metric"
Expand All @@ -154,7 +169,7 @@ export default function ({
customMetric={aggAvg id="5"
field="bytes"
enabled=true
schema="metric"
schema="metric"
}
enabled=true
schema="metric"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export function DetailView({ errorGroup, urlParams }: Props) {
const status = error.http?.response?.status_code;

return (
<EuiPanel>
<EuiPanel hasBorder={true}>
<HeaderContainer>
<EuiTitle size="s">
<h3>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,13 @@ export function ErrorGroupDetails({

return (
<>
<EuiSpacer size={'s'} />

<ErrorGroupHeader groupId={groupId} isUnhandled={isUnhandled} />

<EuiPanel>
<EuiSpacer size={'m'} />

<EuiPanel hasBorder={true}>
{showDetails && (
<Titles>
<EuiText>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export function ErrorGroupOverview({ serviceName }: ErrorGroupOverviewProps) {
return (
<EuiFlexGroup direction="column" gutterSize="s">
<EuiFlexItem>
<EuiPanel>
<EuiPanel hasBorder={true}>
<ErrorDistribution
distribution={errorDistributionData}
title={i18n.translate(
Expand All @@ -85,7 +85,7 @@ export function ErrorGroupOverview({ serviceName }: ErrorGroupOverviewProps) {
</EuiFlexItem>

<EuiFlexItem>
<EuiPanel>
<EuiPanel hasBorder={true}>
<EuiTitle size="xs">
<h3>
{i18n.translate(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,6 @@ export interface Props {
* Current autoplay interval
*/
autoplayInterval: number;
/**
* Enables autoplay
*/
enableAutoplay: (autoplay: boolean) => void;
/**
* Sets autoplay interval
*/
Expand All @@ -110,7 +106,6 @@ export const ViewMenu: FunctionComponent<Props> = ({
setRefreshInterval,
autoplayEnabled,
autoplayInterval,
enableAutoplay,
setAutoplayInterval,
}) => {
const setRefresh = (val: number) => setRefreshInterval(val);
Expand Down Expand Up @@ -259,6 +254,5 @@ ViewMenu.propTypes = {
setRefreshInterval: PropTypes.func.isRequired,
autoplayEnabled: PropTypes.bool.isRequired,
autoplayInterval: PropTypes.number.isRequired,
enableAutoplay: PropTypes.func.isRequired,
setAutoplayInterval: PropTypes.func.isRequired,
};
Loading

0 comments on commit eea67d6

Please sign in to comment.