Skip to content

Commit

Permalink
[data views editor] Disable loading rollups when rollups are disabled (
Browse files Browse the repository at this point in the history
…#184765)

## Summary

Previously we were checking the `/api/rollup/indices` endpoint when the
data view editor was loaded. If rollups were disabled, it would
harmlessly handle a 404 error. Still, people justifiably wonder whether
something is wrong.

This PR skips checking the endpoint as one would expect. A unit test has
been added. I also manually verified the behavior is as expected.

Follow up to #162674

---------

Co-authored-by: Lukas Olson <[email protected]>
  • Loading branch information
mattkime and lukasolson authored Jun 5, 2024
1 parent 9560481 commit 1772203
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* 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 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import { DataViewEditorService } from './data_view_editor_service';
import { HttpSetup } from '@kbn/core/public';
import { DataViewsServicePublic } from '@kbn/data-views-plugin/public';

describe('DataViewEditorService', () => {
it('should check for rollup indices when rolls are enabled', () => {
const get = jest.fn();
const http = { get } as unknown as HttpSetup;
new DataViewEditorService({
services: {
http,
dataViews: {
getIdsWithTitle: jest.fn().mockResolvedValue([]),
getRollupsEnabled: jest.fn().mockReturnValue(true),
} as unknown as DataViewsServicePublic,
},
initialValues: {},
});

expect(get).toHaveBeenCalledTimes(1);
expect(get.mock.calls[0][0]).toEqual('/api/rollup/indices');
});
it('should skip check for rollup indices when rollups are disabled', () => {
const http = { get: jest.fn() } as unknown as HttpSetup;
new DataViewEditorService({
services: {
http,
dataViews: {
getIdsWithTitle: jest.fn().mockResolvedValue([]),
getRollupsEnabled: jest.fn().mockReturnValue(false),
} as unknown as DataViewsServicePublic,
},
initialValues: {},
});

expect(http.get).toHaveBeenCalledTimes(0);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,9 @@ export class DataViewEditorService {
};

private getRollupIndexCaps = async () => {
if (this.dataViews.getRollupsEnabled() === false) {
return {};
}
let rollupIndicesCaps: RollupIndicesCapsResponse = {};
try {
rollupIndicesCaps = await this.http.get<RollupIndicesCapsResponse>('/api/rollup/indices');
Expand Down

0 comments on commit 1772203

Please sign in to comment.