Skip to content

Commit

Permalink
fix(Targets): Target list fails to populate if WebSocket connection i…
Browse files Browse the repository at this point in the history
…s not established (cryostatio#1276)

Co-authored-by: Andrew Azores <[email protected]>
  • Loading branch information
aali309 and andrewazores authored Jun 11, 2024
1 parent 875e7ac commit d143a8b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
34 changes: 19 additions & 15 deletions src/app/Shared/Services/Api.service.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -66,11 +77,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<boolean>(1);
private readonly archiveEnabled = new BehaviorSubject<boolean>(true);
private readonly cryostatVersionSubject = new ReplaySubject<string>(1);
private readonly grafanaDatasourceUrlSubject = new ReplaySubject<string>(1);
private readonly grafanaDashboardUrlSubject = new ReplaySubject<string>(1);
Expand All @@ -80,20 +90,14 @@ export class ApiService {
private readonly notifications: NotificationService,
private readonly login: LoginService,
) {
// show recording archives when recordings available
this.login
.getSessionState()
this.doGet('recordings')
.pipe(
concatMap((sessionState) => (sessionState === SessionState.USER_SESSION ? this.doGet('recordings') : EMPTY)),
)
.subscribe({
next: () => {
this.archiveEnabled.next(true);
},
error: () => {
catchError(() => {
this.archiveEnabled.next(false);
},
});
return EMPTY;
}),
)
.subscribe();

const getDatasourceURL: Observable<GrafanaDatasourceUrlGetResponse> = fromFetch(
`${this.login.authority}/api/v1/grafana_datasource_url`,
Expand Down
14 changes: 5 additions & 9 deletions src/app/Shared/Services/Targets.service.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<Target[]> = new BehaviorSubject<Target[]>([]);
Expand All @@ -33,12 +32,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) {
Expand Down

0 comments on commit d143a8b

Please sign in to comment.