Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

METRON-2302: [UI] Change the default polling interval for Alerts UI to longer time #1547

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ import { Spy } from 'jasmine-core';
import { DialogService } from 'app/service/dialog.service';
import { RestError } from 'app/model/rest-error';
import { DialogType } from 'app/model/dialog-type';
import { RefreshInterval } from 'app/alerts/configure-rows/configure-rows-enums';

const DEFAULT_POLLING_INTERVAL = RefreshInterval.TEN_MIN;

class QueryBuilderFake {
private _filter = '';
Expand Down Expand Up @@ -447,13 +450,13 @@ describe('AutoPollingService', () => {
it('should persist polling state on start', () => {
spyOn(localStorage, 'setItem');
autoPollingService.start();
expect(localStorage.setItem).toHaveBeenCalledWith('autoPolling', '{"isActive":true,"refreshInterval":10}');
expect(localStorage.setItem).toHaveBeenCalledWith('autoPolling', `{"isActive":true,"refreshInterval":${DEFAULT_POLLING_INTERVAL}}`);
});

it('should persist polling state on stop', () => {
spyOn(localStorage, 'setItem');
autoPollingService.stop();
expect(localStorage.setItem).toHaveBeenCalledWith('autoPolling', '{"isActive":false,"refreshInterval":10}');
expect(localStorage.setItem).toHaveBeenCalledWith('autoPolling', `{"isActive":false,"refreshInterval":${DEFAULT_POLLING_INTERVAL}}`);
});

it('should persist polling state on interval change', () => {
Expand All @@ -464,7 +467,7 @@ describe('AutoPollingService', () => {

it('should restore polling state on construction', () => {
const queryBuilderFake = TestBed.get(QueryBuilder);
const dialogServiceFake = TestBed.get(QueryBuilder);
const dialogServiceFake = TestBed.get(DialogService);

spyOn(localStorage, 'getItem').and.returnValue('{"isActive":true,"refreshInterval":443}');

Expand All @@ -477,7 +480,7 @@ describe('AutoPollingService', () => {

it('should start polling on construction when persisted isActive==true', fakeAsync(() => {
const queryBuilderFake = TestBed.get(QueryBuilder);
const dialogServiceFake = TestBed.get(QueryBuilder);
const dialogServiceFake = TestBed.get(DialogService);

spyOn(searchServiceFake, 'search').and.callThrough();
spyOn(localStorage, 'getItem').and.returnValue('{"isActive":true,"refreshInterval":10}');
Expand All @@ -486,18 +489,18 @@ describe('AutoPollingService', () => {

expect(searchServiceFake.search).toHaveBeenCalledTimes(1);

tick(getIntervalInMS());
tick(localAutoPollingSvc.getInterval() * 1000);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may want to consider normalizing your abstraction for the tick calculations, i.e. you're using a nice function getIntervalInMS() in some places, but removed it here bc you're using a localAutoPollingSvc rather than the global autoPollingService. Not a blocker, but something to consider if you're inclined.

expect(searchServiceFake.search).toHaveBeenCalledTimes(2);

tick(getIntervalInMS());
tick(localAutoPollingSvc.getInterval() * 1000);
expect(searchServiceFake.search).toHaveBeenCalledTimes(3);

localAutoPollingSvc.stop();
}));

it('should start polling on construction with the persisted interval', fakeAsync(() => {
const queryBuilderFake = TestBed.get(QueryBuilder);
const dialogServiceFake = TestBed.get(QueryBuilder);
const dialogServiceFake = TestBed.get(DialogService);

spyOn(searchServiceFake, 'search').and.callThrough();
spyOn(localStorage, 'getItem').and.returnValue('{"isActive":true,"refreshInterval":4}');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { POLLING_DEFAULT_STATE } from 'app/utils/constants';
import { RestError } from 'app/model/rest-error';
import { DialogType } from 'app/shared/metron-dialog/metron-dialog.component';
import { DialogService } from 'app/service/dialog.service';
import { RefreshInterval } from '../../configure-rows/configure-rows-enums';

interface AutoPollingStateModel {
isActive: boolean,
Expand All @@ -36,7 +37,7 @@ export class AutoPollingService {
data = new Subject<SearchResponse>();

private isCongestion = false;
private refreshInterval = 10;
private refreshInterval = RefreshInterval.TEN_MIN;
private isPollingActive = POLLING_DEFAULT_STATE;
private isPending = false;
private isPollingSuppressed = false;
Expand Down