Skip to content

Commit

Permalink
[Usage Counters] Enhancements to the APIs (#187665)
Browse files Browse the repository at this point in the history
## Summary

Part of #186530
Follow-up of #187064 

The goal of this PR is to provide the necessary means to allow
implementing the [Counting
views](https://docs.google.com/document/d/1W77qoweixcjrq0sEKh_LjIk3j33Xyy9umod9mG9BlOM/edit)
part of the _Dashboards++_ initiative.
We do this by extending the capabilities of the _usage counters_ APIs:
* We support custom retention periods. Currently data is only kept in SO
indices for 5 days. Having 90 days worth of counting was required for
Dashboards++.
* We expose a Search API that will allow retrieving persisted counters.

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
  • Loading branch information
gsoldevila and kibanamachine authored Aug 5, 2024
1 parent 99ba4d8 commit d9c1f97
Show file tree
Hide file tree
Showing 57 changed files with 1,907 additions and 713 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ describe('getSearchDsl', () => {
mappings,
opts.type,
opts.sortField,
opts.sortOrder
opts.sortOrder,
opts.pit
);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export function getSearchDsl(
hasNoReferenceOperator,
kueryNode,
}),
...getSortingParams(mappings, type, sortField, sortOrder),
...getSortingParams(mappings, type, sortField, sortOrder, pit),
...(pit ? getPitParams(pit) : {}),
search_after: searchAfter,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,4 +238,12 @@ describe('searchDsl/getSortParams', () => {
});
});
});

describe('pit, no sortField', () => {
it('defaults to natural storage order sorting', () => {
expect(getSortingParams(MAPPINGS, 'saved', undefined, undefined, { id: 'abc123' })).toEqual({
sort: ['_shard_doc'],
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
* Side Public License, v 1.
*/

import * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import Boom from '@hapi/boom';
import type { SortOrder, SortCombinations } from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import type { SavedObjectsPitParams } from '@kbn/core-saved-objects-api-server/src/apis';
import { getProperty, type IndexMapping } from '@kbn/core-saved-objects-base-server-internal';

const TOP_LEVEL_FIELDS = ['_id', '_score'];
Expand All @@ -16,10 +17,15 @@ export function getSortingParams(
mappings: IndexMapping,
type: string | string[],
sortField?: string,
sortOrder?: estypes.SortOrder
): { sort?: estypes.SortCombinations[] } {
sortOrder?: SortOrder,
pit?: SavedObjectsPitParams
): { sort?: SortCombinations[] } {
if (!sortField) {
return {};
// if we are performing a PIT search, we must sort by some criteria
// in order to get the 'sort' property for each of the results.
// Defaulting to '_shard_doc' tells ES to sort by the natural stored order,
// giving the best performance
return pit ? { sort: ['_shard_doc'] } : {};
}

const types = Array.isArray(type) ? type : [type];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
*/

export const getUsageCollection = () => ({
domainId: 'abc123',
incrementCounter: jest.fn(),
});

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,5 @@ export { registerCoreUsageCollector } from './core';
export { registerLocalizationUsageCollector } from './localization';
export { registerConfigUsageCollector } from './config_usage';
export { registerUiCountersUsageCollector } from './ui_counters';
export {
registerUsageCountersRollups,
registerUsageCountersUsageCollector,
} from './usage_counters';
export { registerUsageCountersUsageCollector } from './usage_counters';
export { registerEventLoopDelaysCollector } from './event_loop_delays';
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,3 @@
*/

export { registerUsageCountersUsageCollector } from './register_usage_counters_collector';
export { registerUsageCountersRollups } from './rollups';
Loading

0 comments on commit d9c1f97

Please sign in to comment.