You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@metron.apache.org by sa...@apache.org on 2019/11/05 01:31:26 UTC

[metron] branch master updated: METRON-2290 [UI] Delaying first auto polling request on app start (tiborm via sardell) closes apache/metron#1534

This is an automated email from the ASF dual-hosted git repository.

sardell pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/metron.git


The following commit(s) were added to refs/heads/master by this push:
     new fb3986e  METRON-2290 [UI] Delaying first auto polling request on app start (tiborm via sardell) closes apache/metron#1534
fb3986e is described below

commit fb3986e3ec6c39838fec2cf96020d84dd2ff86bc
Author: tiborm <ti...@gmail.com>
AuthorDate: Mon Nov 4 19:30:41 2019 -0600

    METRON-2290 [UI] Delaying first auto polling request on app start (tiborm via sardell) closes apache/metron#1534
---
 .../src/app/alerts/alerts-list/alerts-list.component.ts      |  1 +
 .../alerts-list/auto-polling/auto-polling.service.spec.ts    | 12 ++++++++++--
 .../alerts/alerts-list/auto-polling/auto-polling.service.ts  |  9 +++++----
 3 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/metron-interface/metron-alerts/src/app/alerts/alerts-list/alerts-list.component.ts b/metron-interface/metron-alerts/src/app/alerts/alerts-list/alerts-list.component.ts
index b27083a..1bb7a04 100755
--- a/metron-interface/metron-alerts/src/app/alerts/alerts-list/alerts-list.component.ts
+++ b/metron-interface/metron-alerts/src/app/alerts/alerts-list/alerts-list.component.ts
@@ -190,6 +190,7 @@ export class AlertsListComponent implements OnInit, OnDestroy {
         this.clusterMetaDataService.getDefaultColumns()
     ).subscribe((response: any) => {
       this.prepareData(response[0], response[1]);
+      this.setSearchRequestSize();
       this.refreshAlertData(resetPaginationForSearch);
     });
   }
diff --git a/metron-interface/metron-alerts/src/app/alerts/alerts-list/auto-polling/auto-polling.service.spec.ts b/metron-interface/metron-alerts/src/app/alerts/alerts-list/auto-polling/auto-polling.service.spec.ts
index d13eab1..029d0e4 100644
--- a/metron-interface/metron-alerts/src/app/alerts/alerts-list/auto-polling/auto-polling.service.spec.ts
+++ b/metron-interface/metron-alerts/src/app/alerts/alerts-list/auto-polling/auto-polling.service.spec.ts
@@ -465,7 +465,7 @@ describe('AutoPollingService', () => {
       expect(localStorage.setItem).toHaveBeenCalledWith('autoPolling', '{"isActive":false,"refreshInterval":4}');
     });
 
-    it('should restore polling state on construction', () => {
+    it('should restore polling state on construction with a delay', fakeAsync(() => {
       const queryBuilderFake = TestBed.get(QueryBuilder);
       const dialogServiceFake = TestBed.get(DialogService);
 
@@ -473,10 +473,14 @@ describe('AutoPollingService', () => {
 
       const localAutoPollingSvc = new AutoPollingService(searchServiceFake, queryBuilderFake, dialogServiceFake);
 
+      tick(localAutoPollingSvc.AUTO_START_DELAY);
+
       expect(localStorage.getItem).toHaveBeenCalledWith('autoPolling');
       expect(localAutoPollingSvc.getIsPollingActive()).toBe(true);
       expect(localAutoPollingSvc.getInterval()).toBe(443);
-    });
+
+      localAutoPollingSvc.stop();
+    }));
 
     it('should start polling on construction when persisted isActive==true', fakeAsync(() => {
       const queryBuilderFake = TestBed.get(QueryBuilder);
@@ -487,6 +491,8 @@ describe('AutoPollingService', () => {
 
       const localAutoPollingSvc = new AutoPollingService(searchServiceFake, queryBuilderFake, dialogServiceFake);
 
+      tick(localAutoPollingSvc.AUTO_START_DELAY);
+
       expect(searchServiceFake.search).toHaveBeenCalledTimes(1);
 
       tick(localAutoPollingSvc.getInterval() * 1000);
@@ -507,6 +513,8 @@ describe('AutoPollingService', () => {
 
       const localAutoPollingSvc = new AutoPollingService(searchServiceFake, queryBuilderFake, dialogServiceFake);
 
+      tick(localAutoPollingSvc.AUTO_START_DELAY);
+
       expect(searchServiceFake.search).toHaveBeenCalledTimes(1);
 
       tick(4000);
diff --git a/metron-interface/metron-alerts/src/app/alerts/alerts-list/auto-polling/auto-polling.service.ts b/metron-interface/metron-alerts/src/app/alerts/alerts-list/auto-polling/auto-polling.service.ts
index 4f6cdba..23cd572 100755
--- a/metron-interface/metron-alerts/src/app/alerts/alerts-list/auto-polling/auto-polling.service.ts
+++ b/metron-interface/metron-alerts/src/app/alerts/alerts-list/auto-polling/auto-polling.service.ts
@@ -16,7 +16,7 @@
  * limitations under the License.
  */
 import { Injectable } from '@angular/core';
-import { Subscription, Subject, Observable, interval, onErrorResumeNext } from 'rxjs';
+import { Subscription, Subject, Observable, interval, onErrorResumeNext, timer } from 'rxjs';
 import { SearchService } from 'app/service/search.service';
 import { QueryBuilder } from '../query-builder';
 import { SearchResponse } from 'app/model/search-response';
@@ -34,8 +34,6 @@ interface AutoPollingStateModel {
 
 @Injectable()
 export class AutoPollingService {
-  data = new Subject<SearchResponse>();
-
   private isCongestion = false;
   private refreshInterval = RefreshInterval.TEN_MIN;
   private isPollingActive = POLLING_DEFAULT_STATE;
@@ -43,6 +41,9 @@ export class AutoPollingService {
   private isPollingSuppressed = false;
   private pollingIntervalSubs: Subscription;
 
+  readonly AUTO_START_DELAY = 500;
+  data = new Subject<SearchResponse>();
+
   public readonly AUTO_POLLING_STORAGE_KEY = 'autoPolling';
 
   constructor(private searchService: SearchService,
@@ -117,7 +118,7 @@ export class AutoPollingService {
       this.refreshInterval = persistedState.refreshInterval;
 
       if (persistedState.isActive) {
-        this.start();
+        timer(this.AUTO_START_DELAY).subscribe(this.start.bind(this));
       }
     }
   }