From 6228355d3eec286ccf7cc6f80049060832ae85ec Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Tue, 11 Jun 2024 10:38:08 -0400 Subject: [PATCH 1/6] fix --- src/app/Shared/Services/Login.service.tsx | 2 +- .../Shared/Services/NotificationChannel.service.tsx | 13 ++++--------- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/src/app/Shared/Services/Login.service.tsx b/src/app/Shared/Services/Login.service.tsx index 23fd5bf4c..6f044df56 100644 --- a/src/app/Shared/Services/Login.service.tsx +++ b/src/app/Shared/Services/Login.service.tsx @@ -27,7 +27,6 @@ export class LoginService { constructor(private readonly settings: SettingsService) { this.authority = process.env.CRYOSTAT_AUTHORITY || '.'; - this.sessionState.next(SessionState.CREATING_USER_SESSION); fromFetch(`${this.authority}/api/v2.1/auth`, { credentials: 'include', @@ -47,6 +46,7 @@ export class LoginService { ) .subscribe((v) => { this.username.next(v?.data?.result?.username ?? ''); + this.sessionState.next(SessionState.USER_SESSION); }); } diff --git a/src/app/Shared/Services/NotificationChannel.service.tsx b/src/app/Shared/Services/NotificationChannel.service.tsx index ffcd71785..3bc395ca0 100644 --- a/src/app/Shared/Services/NotificationChannel.service.tsx +++ b/src/app/Shared/Services/NotificationChannel.service.tsx @@ -65,13 +65,11 @@ export class NotificationChannel { }); }); - combineLatest([this.login.getSessionState(), timer(0, 5000)]) + combineLatest([this.login.getSessionState(), this._ready, timer(0, 5000)]) .pipe(distinctUntilChanged(_.isEqual)) .subscribe({ - next: (parts: string[]) => { - const sessionState = parseInt(parts[0]); - - if (sessionState !== SessionState.CREATING_USER_SESSION) { + next: ([sessionState, readyState]) => { + if (sessionState === SessionState.NO_USER_SESSION || readyState.ready) { return; } @@ -86,10 +84,7 @@ export class NotificationChannel { url: url.toString(), protocol: '', openObserver: { - next: () => { - this._ready.next({ ready: true }); - this.login.setSessionState(SessionState.USER_SESSION); - }, + next: () => this._ready.next({ ready: true }), }, closeObserver: { next: (evt) => { From afa0ffc9adc60e40a6d2edda154bc65f5eafea8c Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Tue, 11 Jun 2024 10:44:35 -0400 Subject: [PATCH 2/6] fix 2 --- src/app/Shared/Services/Login.service.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/Shared/Services/Login.service.tsx b/src/app/Shared/Services/Login.service.tsx index 6f044df56..f338e0191 100644 --- a/src/app/Shared/Services/Login.service.tsx +++ b/src/app/Shared/Services/Login.service.tsx @@ -22,7 +22,7 @@ import type { SettingsService } from './Settings.service'; export class LoginService { private readonly logout = new ReplaySubject(1); private readonly username = new ReplaySubject(1); - private readonly sessionState = new ReplaySubject(1); + private readonly sessionState = new ReplaySubject(SessionState.CREATING_USER_SESSION); readonly authority: string; constructor(private readonly settings: SettingsService) { From 7ea77fd758faf4a6b414287b86bcb8d145876d8e Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Tue, 11 Jun 2024 14:09:12 -0400 Subject: [PATCH 3/6] resolve issues --- src/app/Shared/Services/Api.service.tsx | 20 +++++++------------ src/app/Shared/Services/Login.service.tsx | 4 ++-- .../Services/NotificationChannel.service.tsx | 13 ++++++++---- src/app/Shared/Services/Targets.service.tsx | 9 +++------ 4 files changed, 21 insertions(+), 25 deletions(-) diff --git a/src/app/Shared/Services/Api.service.tsx b/src/app/Shared/Services/Api.service.tsx index d216b9745..3a567e7f7 100644 --- a/src/app/Shared/Services/Api.service.tsx +++ b/src/app/Shared/Services/Api.service.tsx @@ -81,19 +81,13 @@ export class ApiService { private readonly login: LoginService, ) { // show recording archives when recordings available - this.login - .getSessionState() - .pipe( - concatMap((sessionState) => (sessionState === SessionState.USER_SESSION ? this.doGet('recordings') : EMPTY)), - ) - .subscribe({ - next: () => { - this.archiveEnabled.next(true); - }, - error: () => { - this.archiveEnabled.next(false); - }, - }); + this.doGet('recordings').pipe( + tap(() => this.archiveEnabled.next(true)), + catchError(() => { + this.archiveEnabled.next(false); + return EMPTY; + }) + ).subscribe(); const getDatasourceURL: Observable = fromFetch( `${this.login.authority}/api/v1/grafana_datasource_url`, diff --git a/src/app/Shared/Services/Login.service.tsx b/src/app/Shared/Services/Login.service.tsx index f338e0191..23fd5bf4c 100644 --- a/src/app/Shared/Services/Login.service.tsx +++ b/src/app/Shared/Services/Login.service.tsx @@ -22,11 +22,12 @@ import type { SettingsService } from './Settings.service'; export class LoginService { private readonly logout = new ReplaySubject(1); private readonly username = new ReplaySubject(1); - private readonly sessionState = new ReplaySubject(SessionState.CREATING_USER_SESSION); + private readonly sessionState = new ReplaySubject(1); readonly authority: string; constructor(private readonly settings: SettingsService) { this.authority = process.env.CRYOSTAT_AUTHORITY || '.'; + this.sessionState.next(SessionState.CREATING_USER_SESSION); fromFetch(`${this.authority}/api/v2.1/auth`, { credentials: 'include', @@ -46,7 +47,6 @@ export class LoginService { ) .subscribe((v) => { this.username.next(v?.data?.result?.username ?? ''); - this.sessionState.next(SessionState.USER_SESSION); }); } diff --git a/src/app/Shared/Services/NotificationChannel.service.tsx b/src/app/Shared/Services/NotificationChannel.service.tsx index 3bc395ca0..ffcd71785 100644 --- a/src/app/Shared/Services/NotificationChannel.service.tsx +++ b/src/app/Shared/Services/NotificationChannel.service.tsx @@ -65,11 +65,13 @@ export class NotificationChannel { }); }); - combineLatest([this.login.getSessionState(), this._ready, timer(0, 5000)]) + combineLatest([this.login.getSessionState(), timer(0, 5000)]) .pipe(distinctUntilChanged(_.isEqual)) .subscribe({ - next: ([sessionState, readyState]) => { - if (sessionState === SessionState.NO_USER_SESSION || readyState.ready) { + next: (parts: string[]) => { + const sessionState = parseInt(parts[0]); + + if (sessionState !== SessionState.CREATING_USER_SESSION) { return; } @@ -84,7 +86,10 @@ export class NotificationChannel { url: url.toString(), protocol: '', openObserver: { - next: () => this._ready.next({ ready: true }), + next: () => { + this._ready.next({ ready: true }); + this.login.setSessionState(SessionState.USER_SESSION); + }, }, closeObserver: { next: (evt) => { diff --git a/src/app/Shared/Services/Targets.service.tsx b/src/app/Shared/Services/Targets.service.tsx index e5134319d..45eb5f76f 100644 --- a/src/app/Shared/Services/Targets.service.tsx +++ b/src/app/Shared/Services/Targets.service.tsx @@ -33,12 +33,9 @@ export class TargetsService { login: LoginService, notificationChannel: NotificationChannel, ) { - login - .getSessionState() - .pipe(concatMap((sessionState) => (sessionState === SessionState.USER_SESSION ? this.queryForTargets() : EMPTY))) - .subscribe(() => { - // just trigger a startup query - }); + // just trigger a startup query + this.queryForTargets().subscribe(); + notificationChannel.messages(NotificationCategory.TargetJvmDiscovery).subscribe((v) => { const evt: TargetDiscoveryEvent = v.message.event; switch (evt.kind) { From db5ff4dfd59d09636507b3c4bda3a467303c49b6 Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Tue, 11 Jun 2024 14:15:13 -0400 Subject: [PATCH 4/6] yarn format:apply --- src/app/Shared/Services/Api.service.tsx | 16 +++++++++------- src/app/Shared/Services/Targets.service.tsx | 4 ++-- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/app/Shared/Services/Api.service.tsx b/src/app/Shared/Services/Api.service.tsx index 3a567e7f7..045763bf9 100644 --- a/src/app/Shared/Services/Api.service.tsx +++ b/src/app/Shared/Services/Api.service.tsx @@ -81,13 +81,15 @@ export class ApiService { private readonly login: LoginService, ) { // show recording archives when recordings available - this.doGet('recordings').pipe( - tap(() => this.archiveEnabled.next(true)), - catchError(() => { - this.archiveEnabled.next(false); - return EMPTY; - }) - ).subscribe(); + this.doGet('recordings') + .pipe( + tap(() => this.archiveEnabled.next(true)), + catchError(() => { + this.archiveEnabled.next(false); + return EMPTY; + }), + ) + .subscribe(); const getDatasourceURL: Observable = fromFetch( `${this.login.authority}/api/v1/grafana_datasource_url`, diff --git a/src/app/Shared/Services/Targets.service.tsx b/src/app/Shared/Services/Targets.service.tsx index 45eb5f76f..18c85c6e2 100644 --- a/src/app/Shared/Services/Targets.service.tsx +++ b/src/app/Shared/Services/Targets.service.tsx @@ -33,9 +33,9 @@ export class TargetsService { login: LoginService, notificationChannel: NotificationChannel, ) { - // just trigger a startup query + // just trigger a startup query this.queryForTargets().subscribe(); - + notificationChannel.messages(NotificationCategory.TargetJvmDiscovery).subscribe((v) => { const evt: TargetDiscoveryEvent = v.message.event; switch (evt.kind) { From 5d283c1643e584494f2e7350150444fd6469f696 Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Tue, 11 Jun 2024 14:46:14 -0400 Subject: [PATCH 5/6] resolve issues2 --- src/app/Shared/Services/Api.service.tsx | 5 +---- src/app/Shared/Services/Targets.service.tsx | 5 ++--- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/src/app/Shared/Services/Api.service.tsx b/src/app/Shared/Services/Api.service.tsx index 045763bf9..199f0939a 100644 --- a/src/app/Shared/Services/Api.service.tsx +++ b/src/app/Shared/Services/Api.service.tsx @@ -66,11 +66,10 @@ import { import { isHttpError, includesTarget, isHttpOk, isXMLHttpError } from './api.utils'; import { LoginService } from './Login.service'; import { NotificationService } from './Notifications.service'; -import { SessionState } from './service.types'; import { TargetService } from './Target.service'; export class ApiService { - private readonly archiveEnabled = new ReplaySubject(1); + private readonly archiveEnabled = new ReplaySubject(true); private readonly cryostatVersionSubject = new ReplaySubject(1); private readonly grafanaDatasourceUrlSubject = new ReplaySubject(1); private readonly grafanaDashboardUrlSubject = new ReplaySubject(1); @@ -80,10 +79,8 @@ export class ApiService { private readonly notifications: NotificationService, private readonly login: LoginService, ) { - // show recording archives when recordings available this.doGet('recordings') .pipe( - tap(() => this.archiveEnabled.next(true)), catchError(() => { this.archiveEnabled.next(false); return EMPTY; diff --git a/src/app/Shared/Services/Targets.service.tsx b/src/app/Shared/Services/Targets.service.tsx index 18c85c6e2..516d2f99f 100644 --- a/src/app/Shared/Services/Targets.service.tsx +++ b/src/app/Shared/Services/Targets.service.tsx @@ -15,14 +15,13 @@ */ import _ from 'lodash'; -import { Observable, BehaviorSubject, of, EMPTY } from 'rxjs'; -import { catchError, concatMap, first, map, tap } from 'rxjs/operators'; +import { Observable, BehaviorSubject, of } from 'rxjs'; +import { catchError, first, map, tap } from 'rxjs/operators'; import { ApiService } from './Api.service'; import { Target, NotificationCategory, TargetDiscoveryEvent } from './api.types'; import { LoginService } from './Login.service'; import { NotificationChannel } from './NotificationChannel.service'; import { NotificationService } from './Notifications.service'; -import { SessionState } from './service.types'; export class TargetsService { private readonly _targets$: BehaviorSubject = new BehaviorSubject([]); From 5b21d14a140c29a3f2743b00627008f711baa9da Mon Sep 17 00:00:00 2001 From: Andrew Azores Date: Tue, 11 Jun 2024 15:08:51 -0400 Subject: [PATCH 6/6] behaviorsubject --- src/app/Shared/Services/Api.service.tsx | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/app/Shared/Services/Api.service.tsx b/src/app/Shared/Services/Api.service.tsx index 199f0939a..c62f10c0d 100644 --- a/src/app/Shared/Services/Api.service.tsx +++ b/src/app/Shared/Services/Api.service.tsx @@ -17,7 +17,18 @@ import { LayoutTemplate, SerialLayoutTemplate } from '@app/Dashboard/types'; import { createBlobURL } from '@app/utils/utils'; import { ValidatedOptions } from '@patternfly/react-core'; -import { EMPTY, forkJoin, from, Observable, ObservableInput, of, ReplaySubject, shareReplay, throwError } from 'rxjs'; +import { + BehaviorSubject, + EMPTY, + forkJoin, + from, + Observable, + ObservableInput, + of, + ReplaySubject, + shareReplay, + throwError, +} from 'rxjs'; import { fromFetch } from 'rxjs/fetch'; import { catchError, concatMap, filter, first, map, mergeMap, tap } from 'rxjs/operators'; import { @@ -69,7 +80,7 @@ import { NotificationService } from './Notifications.service'; import { TargetService } from './Target.service'; export class ApiService { - private readonly archiveEnabled = new ReplaySubject(true); + private readonly archiveEnabled = new BehaviorSubject(true); private readonly cryostatVersionSubject = new ReplaySubject(1); private readonly grafanaDatasourceUrlSubject = new ReplaySubject(1); private readonly grafanaDashboardUrlSubject = new ReplaySubject(1);