mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
[Uptime Monitor Management] Update error conditions for location fetch (#124111)
This commit is contained in:
parent
06389d7b90
commit
a810fe6bc2
6 changed files with 27 additions and 12 deletions
|
@ -55,6 +55,6 @@ describe('useExpViewTimeRange', function () {
|
|||
wrapper: Wrapper,
|
||||
});
|
||||
|
||||
expect(result.current).toEqual({ loading, error });
|
||||
expect(result.current).toEqual({ loading, error, locations: [] });
|
||||
});
|
||||
});
|
||||
|
|
|
@ -15,6 +15,7 @@ export function useLocations() {
|
|||
const {
|
||||
error: { serviceLocations: serviceLocationsError },
|
||||
loading: { serviceLocations: serviceLocationsLoading },
|
||||
locations,
|
||||
} = useSelector(monitorManagementListSelector);
|
||||
|
||||
useEffect(() => {
|
||||
|
@ -22,6 +23,7 @@ export function useLocations() {
|
|||
}, [dispatch]);
|
||||
|
||||
return {
|
||||
locations,
|
||||
error: serviceLocationsError,
|
||||
loading: serviceLocationsLoading,
|
||||
};
|
||||
|
|
|
@ -19,13 +19,13 @@ export const AddMonitorPage: React.FC = () => {
|
|||
useTrackPageview({ app: 'uptime', path: 'add-monitor' });
|
||||
useTrackPageview({ app: 'uptime', path: 'add-monitor', delay: 15000 });
|
||||
|
||||
const { error, loading } = useLocations();
|
||||
const { error, loading, locations } = useLocations();
|
||||
|
||||
useMonitorManagementBreadcrumbs({ isAddMonitor: true });
|
||||
|
||||
return (
|
||||
<Loader
|
||||
error={Boolean(error)}
|
||||
error={Boolean(error) || (locations && locations.length === 0)}
|
||||
loading={loading}
|
||||
loadingTitle={LOADING_LABEL}
|
||||
errorTitle={ERROR_HEADING_LABEL}
|
||||
|
|
|
@ -10,7 +10,6 @@ import { forkJoin, from as rxjsFrom, Observable, of } from 'rxjs';
|
|||
import { catchError, tap } from 'rxjs/operators';
|
||||
import * as https from 'https';
|
||||
import { SslConfig } from '@kbn/server-http-tools';
|
||||
import { getServiceLocations } from './get_service_locations';
|
||||
import { Logger } from '../../../../../../src/core/server';
|
||||
import { MonitorFields, ServiceLocations } from '../../../common/runtime_types';
|
||||
import { convertToDataStreamFormat } from './formatters/convert_to_data_stream';
|
||||
|
@ -31,14 +30,14 @@ export class ServiceAPIClient {
|
|||
private readonly username?: string;
|
||||
private readonly devUrl?: string;
|
||||
private readonly authorization: string;
|
||||
private locations: ServiceLocations;
|
||||
public locations: ServiceLocations;
|
||||
private logger: Logger;
|
||||
private readonly config: ServiceConfig;
|
||||
private readonly kibanaVersion: string;
|
||||
|
||||
constructor(logger: Logger, config: ServiceConfig, kibanaVersion: string) {
|
||||
this.config = config;
|
||||
const { username, password, manifestUrl, devUrl } = config;
|
||||
const { username, password, devUrl } = config;
|
||||
this.username = username;
|
||||
this.devUrl = devUrl;
|
||||
this.kibanaVersion = kibanaVersion;
|
||||
|
@ -51,10 +50,6 @@ export class ServiceAPIClient {
|
|||
|
||||
this.logger = logger;
|
||||
this.locations = [];
|
||||
|
||||
getServiceLocations({ manifestUrl }).then((result) => {
|
||||
this.locations = result.locations;
|
||||
});
|
||||
}
|
||||
|
||||
getHttpsAgent() {
|
||||
|
|
|
@ -26,9 +26,11 @@ import { formatMonitorConfig } from './formatters/format_configs';
|
|||
import {
|
||||
ConfigKey,
|
||||
MonitorFields,
|
||||
ServiceLocations,
|
||||
SyntheticsMonitor,
|
||||
SyntheticsMonitorWithId,
|
||||
} from '../../../common/runtime_types';
|
||||
import { getServiceLocations } from './get_service_locations';
|
||||
|
||||
const SYNTHETICS_SERVICE_SYNC_MONITORS_TASK_TYPE =
|
||||
'UPTIME:SyntheticsService:Sync-Saved-Monitor-Objects';
|
||||
|
@ -45,6 +47,8 @@ export class SyntheticsService {
|
|||
|
||||
private apiKey: SyntheticsServiceApiKey | undefined;
|
||||
|
||||
public locations: ServiceLocations;
|
||||
|
||||
constructor(logger: Logger, server: UptimeServerSetup, config: ServiceConfig) {
|
||||
this.logger = logger;
|
||||
this.server = server;
|
||||
|
@ -53,6 +57,8 @@ export class SyntheticsService {
|
|||
this.apiClient = new ServiceAPIClient(logger, this.config, this.server.kibanaVersion);
|
||||
|
||||
this.esHosts = getEsHosts({ config: this.config, cloud: server.cloud });
|
||||
|
||||
this.locations = [];
|
||||
}
|
||||
|
||||
public init() {
|
||||
|
@ -98,6 +104,13 @@ export class SyntheticsService {
|
|||
async run() {
|
||||
const { state } = taskInstance;
|
||||
|
||||
const { manifestUrl } = service.config;
|
||||
|
||||
getServiceLocations({ manifestUrl }).then((result) => {
|
||||
service.locations = result.locations;
|
||||
service.apiClient.locations = result.locations;
|
||||
});
|
||||
|
||||
await service.pushConfigs();
|
||||
|
||||
return { state };
|
||||
|
|
|
@ -13,6 +13,11 @@ export const getServiceLocationsRoute: UMRestApiRouteFactory = () => ({
|
|||
method: 'GET',
|
||||
path: API_URLS.SERVICE_LOCATIONS,
|
||||
validate: {},
|
||||
handler: async ({ server }): Promise<any> =>
|
||||
getServiceLocations({ manifestUrl: server.config.service!.manifestUrl! }),
|
||||
handler: async ({ server }): Promise<any> => {
|
||||
if (server.syntheticsService.locations.length > 0) {
|
||||
return { locations: server.syntheticsService.locations };
|
||||
}
|
||||
|
||||
return getServiceLocations({ manifestUrl: server.config.service!.manifestUrl! });
|
||||
},
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue