Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Targets): Target list fails to populate if WebSocket connection is not established #1276

Merged
merged 6 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)))
andrewazores marked this conversation as resolved.
Show resolved Hide resolved
.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
Loading