Skip to content

Commit

Permalink
[Uptime] [User Experience] Prefix internal apis with /internal (#117852
Browse files Browse the repository at this point in the history
…) (#118380)

* [Uptime] prefix internal APIs with /internal [relates to #116334]

* [Uptime] move hard-coded URL paths to rest_api constants [relates to #116334]

* [Uptime] use API_URLS from constants in API integration tests [relates to #116334]

* [Uptime] Remove unnecessary filters route test

* [Uptime] prefix internal RUM routes with /internal and /ux [relates to #116334]

* [User Experience] update API docs for prefixed internal UX APIs
  • Loading branch information
lucasfcosta authored Nov 11, 2021
1 parent 178fff2 commit 1b1e803
Show file tree
Hide file tree
Showing 41 changed files with 748 additions and 261 deletions.
554 changes: 476 additions & 78 deletions api_docs/apm.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export function Metrics() {
(callApmApi) => {
if (uxQuery) {
return callApmApi({
endpoint: 'GET /api/apm/rum/client-metrics',
endpoint: 'GET /internal/apm/ux/client-metrics',
params: {
query: {
...uxQuery,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export function JSErrors() {
(callApmApi) => {
if (start && end && serviceName) {
return callApmApi({
endpoint: 'GET /api/apm/rum-client/js-errors',
endpoint: 'GET /internal/apm/ux/js-errors',
params: {
query: {
start,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export function PageLoadDistribution() {
(callApmApi) => {
if (start && end && serviceName) {
return callApmApi({
endpoint: 'GET /api/apm/rum-client/page-load-distribution',
endpoint: 'GET /internal/apm/ux/page-load-distribution',
params: {
query: {
start,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const useBreakdowns = ({ percentileRange, field, value }: Props) => {
(callApmApi) => {
if (start && end && field && value) {
return callApmApi({
endpoint: 'GET /api/apm/rum-client/page-load-distribution/breakdown',
endpoint: 'GET /internal/apm/ux/page-load-distribution/breakdown',
params: {
query: {
start,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export function PageViewsTrend() {
(callApmApi) => {
if (start && end && serviceName) {
return callApmApi({
endpoint: 'GET /api/apm/rum-client/page-view-trends',
endpoint: 'GET /internal/apm/ux/page-view-trends',
params: {
query: {
start,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export function WebApplicationSelect() {
(callApmApi) => {
if (start && end) {
return callApmApi({
endpoint: 'GET /api/apm/rum-client/services',
endpoint: 'GET /internal/apm/ux/services',
params: {
query: {
start,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const useUrlSearch = ({ popoverIsOpen, query }: Props) => {
(callApmApi) => {
if (uxQuery && popoverIsOpen) {
return callApmApi({
endpoint: 'GET /api/apm/rum-client/url-search',
endpoint: 'GET /internal/apm/ux/url-search',
params: {
query: {
...uxQuery,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export function KeyUXMetrics({ data, loading }: Props) {
(callApmApi) => {
if (uxQuery) {
return callApmApi({
endpoint: 'GET /api/apm/rum-client/long-task-metrics',
endpoint: 'GET /internal/apm/ux/long-task-metrics',
params: {
query: {
...uxQuery,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export function UXMetrics() {
(callApmApi) => {
if (uxQuery) {
return callApmApi({
endpoint: 'GET /api/apm/rum-client/web-core-vitals',
endpoint: 'GET /internal/apm/ux/web-core-vitals',
params: {
query: uxQuery,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export function VisitorBreakdown() {

if (start && end && serviceName) {
return callApmApi({
endpoint: 'GET /api/apm/rum-client/visitor-breakdown',
endpoint: 'GET /internal/apm/ux/visitor-breakdown',
params: {
query: {
start,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const fetchUxOverviewDate = async ({
serviceName,
}: FetchDataParams): Promise<UxFetchDataResponse> => {
const data = await callApmApi({
endpoint: 'GET /api/apm/rum-client/web-core-vitals',
endpoint: 'GET /internal/apm/ux/web-core-vitals',
signal: null,
params: {
query: {
Expand Down
20 changes: 10 additions & 10 deletions x-pack/plugins/apm/server/routes/rum_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const uxQueryRt = t.intersection([
]);

const rumClientMetricsRoute = createApmServerRoute({
endpoint: 'GET /api/apm/rum/client-metrics',
endpoint: 'GET /internal/apm/ux/client-metrics',
params: t.type({
query: uxQueryRt,
}),
Expand All @@ -88,7 +88,7 @@ const rumClientMetricsRoute = createApmServerRoute({
});

const rumPageLoadDistributionRoute = createApmServerRoute({
endpoint: 'GET /api/apm/rum-client/page-load-distribution',
endpoint: 'GET /internal/apm/ux/page-load-distribution',
params: t.type({
query: t.intersection([uxQueryRt, percentileRangeRt]),
}),
Expand All @@ -114,7 +114,7 @@ const rumPageLoadDistributionRoute = createApmServerRoute({
});

const rumPageLoadDistBreakdownRoute = createApmServerRoute({
endpoint: 'GET /api/apm/rum-client/page-load-distribution/breakdown',
endpoint: 'GET /internal/apm/ux/page-load-distribution/breakdown',
params: t.type({
query: t.intersection([
uxQueryRt,
Expand Down Expand Up @@ -145,7 +145,7 @@ const rumPageLoadDistBreakdownRoute = createApmServerRoute({
});

const rumPageViewsTrendRoute = createApmServerRoute({
endpoint: 'GET /api/apm/rum-client/page-view-trends',
endpoint: 'GET /internal/apm/ux/page-view-trends',
params: t.type({
query: t.intersection([uxQueryRt, t.partial({ breakdowns: t.string })]),
}),
Expand All @@ -168,7 +168,7 @@ const rumPageViewsTrendRoute = createApmServerRoute({
});

const rumServicesRoute = createApmServerRoute({
endpoint: 'GET /api/apm/rum-client/services',
endpoint: 'GET /internal/apm/ux/services',
params: t.type({
query: t.intersection([uiFiltersRt, rangeRt]),
}),
Expand All @@ -184,7 +184,7 @@ const rumServicesRoute = createApmServerRoute({
});

const rumVisitorsBreakdownRoute = createApmServerRoute({
endpoint: 'GET /api/apm/rum-client/visitor-breakdown',
endpoint: 'GET /internal/apm/ux/visitor-breakdown',
params: t.type({
query: uxQueryRt,
}),
Expand All @@ -206,7 +206,7 @@ const rumVisitorsBreakdownRoute = createApmServerRoute({
});

const rumWebCoreVitals = createApmServerRoute({
endpoint: 'GET /api/apm/rum-client/web-core-vitals',
endpoint: 'GET /internal/apm/ux/web-core-vitals',
params: t.type({
query: uxQueryRt,
}),
Expand All @@ -229,7 +229,7 @@ const rumWebCoreVitals = createApmServerRoute({
});

const rumLongTaskMetrics = createApmServerRoute({
endpoint: 'GET /api/apm/rum-client/long-task-metrics',
endpoint: 'GET /internal/apm/ux/long-task-metrics',
params: t.type({
query: uxQueryRt,
}),
Expand All @@ -252,7 +252,7 @@ const rumLongTaskMetrics = createApmServerRoute({
});

const rumUrlSearch = createApmServerRoute({
endpoint: 'GET /api/apm/rum-client/url-search',
endpoint: 'GET /internal/apm/ux/url-search',
params: t.type({
query: uxQueryRt,
}),
Expand All @@ -275,7 +275,7 @@ const rumUrlSearch = createApmServerRoute({
});

const rumJSErrors = createApmServerRoute({
endpoint: 'GET /api/apm/rum-client/js-errors',
endpoint: 'GET /internal/apm/ux/js-errors',
params: t.type({
query: t.intersection([
uiFiltersRt,
Expand Down
27 changes: 17 additions & 10 deletions x-pack/plugins/uptime/common/constants/rest_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,23 @@
*/

export enum API_URLS {
INDEX_STATUS = '/api/uptime/index_status',
MONITOR_LIST = `/api/uptime/monitor/list`,
MONITOR_LOCATIONS = `/api/uptime/monitor/locations`,
MONITOR_DURATION = `/api/uptime/monitor/duration`,
MONITOR_DETAILS = `/api/uptime/monitor/details`,
MONITOR_STATUS = `/api/uptime/monitor/status`,
PINGS = '/api/uptime/pings',
PING_HISTOGRAM = `/api/uptime/ping/histogram`,
SNAPSHOT_COUNT = `/api/uptime/snapshot/count`,
LOG_PAGE_VIEW = `/api/uptime/log_page_view`,
DYNAMIC_SETTINGS = `/internal/uptime/dynamic_settings`,
INDEX_STATUS = '/internal/uptime/index_status',
MONITOR_LIST = `/internal/uptime/monitor/list`,
MONITOR_LOCATIONS = `/internal/uptime/monitor/locations`,
MONITOR_DURATION = `/internal/uptime/monitor/duration`,
MONITOR_DETAILS = `/internal/uptime/monitor/details`,
MONITOR_STATUS = `/internal/uptime/monitor/status`,
NETWORK_EVENTS = `/internal/uptime/network_events`,
PINGS = '/internal/uptime/pings',
PING_HISTOGRAM = `/internal/uptime/ping/histogram`,
SNAPSHOT_COUNT = `/internal/uptime/snapshot/count`,
SYNTHETICS_SUCCESSFUL_STEP = `/internal/uptime/synthetics/step/success`,
JOURNEY_CREATE = `/internal/uptime/journey/{checkGroup}`,
JOURNEY_FAILED_STEPS = `/internal/uptime/journeys/failed_steps`,
JOURNEY_SCREENSHOT = `/internal/uptime/journey/screenshot/{checkGroup}/{stepIndex}`,
JOURNEY_SCREENSHOT_BLOCKS = `/internal/uptime/journey/screenshot/block`,
LOG_PAGE_VIEW = `/internal/uptime/log_page_view`,

ML_MODULE_JOBS = `/api/ml/modules/jobs_exist/`,
ML_SETUP_MODULE = '/api/ml/modules/setup/',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const PingTimestamp = ({ label, checkGroup, initialStepNo = 1 }: Props) =

const { basePath } = useContext(UptimeSettingsContext);

const imgPath = `${basePath}/api/uptime/journey/screenshot/${checkGroup}/${stepNumber}`;
const imgPath = `${basePath}/internal/uptime/journey/screenshot/${checkGroup}/${stepNumber}`;

const intersection = useIntersection(intersectionRef, {
root: null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export const StepScreenshotDisplay: FC<StepScreenshotDisplayProps> = ({
}
}, [hasIntersected, isIntersecting, setHasIntersected]);

const imgSrc = basePath + `/api/uptime/journey/screenshot/${checkGroup}/${stepIndex}`;
const imgSrc = basePath + `/internal/uptime/journey/screenshot/${checkGroup}/${stepIndex}`;

// When loading a legacy screenshot, set `url` to full-size screenshot path.
// Otherwise, we first need to composite the image.
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/uptime/public/state/api/dynamic_settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ import {
DynamicSettingsSaveType,
} from '../../../common/runtime_types';
import { apiService } from './utils';
import { API_URLS } from '../../../common/constants';

const apiPath = '/api/uptime/dynamic_settings';
const apiPath = API_URLS.DYNAMIC_SETTINGS;

interface SaveApiRequest {
settings: DynamicSettings;
Expand Down
13 changes: 5 additions & 8 deletions x-pack/plugins/uptime/public/state/api/journey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,17 @@ import {
SyntheticsJourneyApiResponse,
SyntheticsJourneyApiResponseType,
} from '../../../common/runtime_types/ping/synthetics';
import { API_URLS } from '../../../common/constants';

export async function fetchScreenshotBlockSet(params: string[]): Promise<ScreenshotBlockDoc[]> {
return apiService.post('/api/uptime/journey/screenshot/block', { hashes: params });
return apiService.post(API_URLS.JOURNEY_SCREENSHOT_BLOCKS, { hashes: params });
}

export async function fetchJourneySteps(
params: FetchJourneyStepsParams
): Promise<SyntheticsJourneyApiResponse> {
return apiService.get(
`/api/uptime/journey/${params.checkGroup}`,
`/internal/uptime/journey/${params.checkGroup}`,
{ syntheticEventTypes: params.syntheticEventTypes },
SyntheticsJourneyApiResponseType
);
Expand All @@ -38,11 +39,7 @@ export async function fetchJourneysFailedSteps({
}: {
checkGroups: string[];
}): Promise<FailedStepsApiResponse> {
return apiService.get(
`/api/uptime/journeys/failed_steps`,
{ checkGroups },
FailedStepsApiResponseType
);
return apiService.get(API_URLS.JOURNEY_FAILED_STEPS, { checkGroups }, FailedStepsApiResponseType);
}

export async function fetchLastSuccessfulStep({
Expand All @@ -57,7 +54,7 @@ export async function fetchLastSuccessfulStep({
location?: string;
}): Promise<JourneyStep> {
return await apiService.get(
`/api/uptime/synthetics/step/success/`,
API_URLS.SYNTHETICS_SUCCESSFUL_STEP,
{
monitorId,
timestamp,
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/uptime/public/state/api/network_events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ import {
SyntheticsNetworkEventsApiResponse,
SyntheticsNetworkEventsApiResponseType,
} from '../../../common/runtime_types';
import { API_URLS } from '../../../common/constants';

export async function fetchNetworkEvents(
params: FetchNetworkEventsParams
): Promise<SyntheticsNetworkEventsApiResponse> {
return (await apiService.get(
`/api/uptime/network_events`,
API_URLS.NETWORK_EVENTS,
{
checkGroup: params.checkGroup,
stepIndex: params.stepIndex,
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/uptime/public/state/api/snapshot.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import { HttpFetchError } from 'src/core/public';
import { fetchSnapshotCount } from './snapshot';
import { apiService } from './utils';
import { API_URLS } from '../../../common/constants';

describe('snapshot API', () => {
let fetchMock: jest.SpyInstance<Partial<unknown>>;
Expand Down Expand Up @@ -36,7 +37,7 @@ describe('snapshot API', () => {
});
expect(fetchMock).toHaveBeenCalledWith({
asResponse: false,
path: '/api/uptime/snapshot/count',
path: API_URLS.SNAPSHOT_COUNT,
query: {
dateRangeEnd: 'now',
dateRangeStart: 'now-15m',
Expand Down
5 changes: 3 additions & 2 deletions x-pack/plugins/uptime/server/rest_api/dynamic_settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ import {
VALUE_MUST_BE_GREATER_THAN_ZERO,
VALUE_MUST_BE_AN_INTEGER,
} from '../../common/translations';
import { API_URLS } from '../../common/constants';

export const createGetDynamicSettingsRoute: UMRestApiRouteFactory = (libs: UMServerLibs) => ({
method: 'GET',
path: '/api/uptime/dynamic_settings',
path: API_URLS.DYNAMIC_SETTINGS,
validate: false,
handler: async ({ savedObjectsClient }): Promise<any> => {
return savedObjectsAdapter.getUptimeDynamicSettings(savedObjectsClient);
Expand Down Expand Up @@ -47,7 +48,7 @@ export const validateCertsValues = (

export const createPostDynamicSettingsRoute: UMRestApiRouteFactory = (libs: UMServerLibs) => ({
method: 'POST',
path: '/api/uptime/dynamic_settings',
path: API_URLS.DYNAMIC_SETTINGS,
validate: {
body: schema.object({
heartbeatIndices: schema.string(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
import { schema } from '@kbn/config-schema';
import { UMServerLibs } from '../../lib/lib';
import { UMRestApiRouteFactory } from '../types';
import { API_URLS } from '../../../common/constants';

export const createNetworkEventsRoute: UMRestApiRouteFactory = (libs: UMServerLibs) => ({
method: 'GET',
path: '/api/uptime/network_events',
path: API_URLS.NETWORK_EVENTS,
validate: {
query: schema.object({
checkGroup: schema.string(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ import { isRight } from 'fp-ts/lib/Either';
import { schema } from '@kbn/config-schema';
import { UMServerLibs } from '../../lib/lib';
import { UMRestApiRouteFactory } from '../types';
import { API_URLS } from '../../../common/constants';

function isStringArray(data: unknown): data is string[] {
return isRight(t.array(t.string).decode(data));
}

export const createJourneyScreenshotBlocksRoute: UMRestApiRouteFactory = (libs: UMServerLibs) => ({
method: 'POST',
path: '/api/uptime/journey/screenshot/block',
path: API_URLS.JOURNEY_SCREENSHOT_BLOCKS,
validate: {
body: schema.object({
hashes: schema.arrayOf(schema.string()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { isRefResult, isFullScreenshot } from '../../../common/runtime_types/pin
import { UMServerLibs } from '../../lib/lib';
import { ScreenshotReturnTypesUnion } from '../../lib/requests/get_journey_screenshot';
import { UMRestApiRouteFactory } from '../types';
import { API_URLS } from '../../../common/constants';

function getSharedHeaders(stepName: string, totalSteps: number) {
return {
Expand All @@ -21,7 +22,7 @@ function getSharedHeaders(stepName: string, totalSteps: number) {

export const createJourneyScreenshotRoute: UMRestApiRouteFactory = (libs: UMServerLibs) => ({
method: 'GET',
path: '/api/uptime/journey/screenshot/{checkGroup}/{stepIndex}',
path: API_URLS.JOURNEY_SCREENSHOT,
validate: {
params: schema.object({
checkGroup: schema.string(),
Expand Down
Loading

0 comments on commit 1b1e803

Please sign in to comment.