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

[Uptime] Migrate to TypeScript project references #90510

Merged
Show file tree
Hide file tree
Changes from 6 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
40 changes: 25 additions & 15 deletions x-pack/plugins/uptime/common/constants/alerts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,33 @@

import { ActionGroup } from '../../../alerts/common';

export type MonitorStatusActionGroup = ActionGroup<'xpack.uptime.alerts.actionGroups.monitorStatus'>;
export type TLSActionGroup = ActionGroup<'xpack.uptime.alerts.actionGroups.tls'>;
export type DurationAnomalyActionGroup = ActionGroup<'xpack.uptime.alerts.actionGroups.durationAnomaly'>;

export const MONITOR_STATUS: MonitorStatusActionGroup = {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The compiler seemed to want these exported individually in the way we were referencing them.

id: 'xpack.uptime.alerts.actionGroups.monitorStatus',
name: 'Uptime Down Monitor',
};

export const TLS: TLSActionGroup = {
id: 'xpack.uptime.alerts.actionGroups.tls',
name: 'Uptime TLS Alert',
};

export const DURATION_ANOMALY: DurationAnomalyActionGroup = {
id: 'xpack.uptime.alerts.actionGroups.durationAnomaly',
name: 'Uptime Duration Anomaly',
};

export const ACTION_GROUP_DEFINITIONS: {
MONITOR_STATUS: ActionGroup<'xpack.uptime.alerts.actionGroups.monitorStatus'>;
TLS: ActionGroup<'xpack.uptime.alerts.actionGroups.tls'>;
DURATION_ANOMALY: ActionGroup<'xpack.uptime.alerts.actionGroups.durationAnomaly'>;
MONITOR_STATUS: MonitorStatusActionGroup;
TLS: TLSActionGroup;
DURATION_ANOMALY: DurationAnomalyActionGroup;
} = {
MONITOR_STATUS: {
id: 'xpack.uptime.alerts.actionGroups.monitorStatus',
name: 'Uptime Down Monitor',
},
TLS: {
id: 'xpack.uptime.alerts.actionGroups.tls',
name: 'Uptime TLS Alert',
},
DURATION_ANOMALY: {
id: 'xpack.uptime.alerts.actionGroups.durationAnomaly',
name: 'Uptime Duration Anomaly',
},
MONITOR_STATUS,
TLS,
DURATION_ANOMALY,
};

export const CLIENT_ALERT_TYPES = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
* 2.0.
*/

import { EuiPanel, EuiFlexGroup, EuiFlexItem, EuiText } from '@elastic/eui';
import { EuiPanel, EuiFlexGroup, EuiFlexItem, EuiText, EuiPanelProps } from '@elastic/eui';
import { rgba } from 'polished';
import { euiStyled } from '../../../../../../../../../src/plugins/kibana_react/common';
import { FunctionComponent } from 'react';
import { StyledComponent } from 'styled-components';
import { euiStyled, EuiTheme } from '../../../../../../../../../src/plugins/kibana_react/common';
import { FIXED_AXIS_HEIGHT } from './constants';

interface WaterfallChartOuterContainerProps {
Expand Down Expand Up @@ -40,7 +42,10 @@ export const WaterfallChartFixedTopContainer = euiStyled.div`
border-bottom: ${(props) => `1px solid ${props.theme.eui.euiColorLightShade}`};
`;

export const WaterfallChartFixedTopContainerSidebarCover = euiStyled(EuiPanel)`
export const WaterfallChartFixedTopContainerSidebarCover: StyledComponent<
FunctionComponent<EuiPanelProps>,
EuiTheme
> = euiStyled(EuiPanel)`
height: 100%;
border-radius: 0 !important;
border: none;
Expand All @@ -60,7 +65,10 @@ export const WaterfallChartSidebarContainer = euiStyled.div<WaterfallChartSideba
overflow-y: hidden;
`;

export const WaterfallChartSidebarContainerInnerPanel = euiStyled(EuiPanel)`
export const WaterfallChartSidebarContainerInnerPanel: StyledComponent<
FunctionComponent<EuiPanelProps>,
EuiTheme
> = euiStyled(EuiPanel)`
border: 0;
height: 100%;
`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { IntegrationGroup } from './integration_group';
import { MonitorSummary } from '../../../../../../common/runtime_types';
import { toggleIntegrationsPopover, PopoverState } from '../../../../../state/actions';

interface ActionsPopoverProps {
export interface ActionsPopoverProps {
summary: MonitorSummary;
popoverState: PopoverState | null;
togglePopoverIsVisible: typeof toggleIntegrationsPopover;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,25 @@
},
"state": {
"agent": null,
"checks": ,
Copy link
Contributor Author

@justinkambic justinkambic Feb 5, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A little concerning that this didn't cause anything to break (until now).

"checks": [
{
"agent": { "id": "8f9a37fb-573a-4fdc-9895-440a5b39c250", "__typename": "Agent" },
"container": null,
"kubernetes": null,
"monitor": {
"ip": "127.0.0.1",
"name": "localhost",
"status": "up",
"__typename": "CheckMonitor"
},
"observer": {
"geo": { "name": null, "location": null, "__typename": "CheckGeo" },
"__typename": "CheckObserver"
},
"timestamp": "1570538246143",
"__typename": "Check"
}
],
"geo": null,
"observer": {
"geo": { "name": [], "location": null, "__typename": "StateGeo" },
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/uptime/public/state/alerts/alerts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export const deleteAnomalyAlertAction = createAsyncAction<{ alertId: string }, a
'DELETE ANOMALY ALERT'
);

interface AlertState {
export interface AlertState {
connectors: AsyncInitState<ActionConnector[]>;
newAlert: AsyncInitState<Alert<UptimeAlertTypeParams>>;
alerts: AsyncInitState<AlertsResult>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const getCertificatesAction = createAsyncAction<GetCertsParams, CertResul
'GET_CERTIFICATES'
);

interface CertificatesState {
export interface CertificatesState {
certs: AsyncInitState<CertResult>;
}

Expand Down
7 changes: 7 additions & 0 deletions x-pack/plugins/uptime/public/state/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ import { rootReducer } from './reducers';

export type AppState = ReturnType<typeof rootReducer>;

type ComposeType = typeof compose;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was copied from another plugin's solution for providing a global type for redux devtools.

andrewvc marked this conversation as resolved.
Show resolved Hide resolved
declare global {
interface Window {
__REDUX_DEVTOOLS_EXTENSION_COMPOSE__: ComposeType;
}
}

const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i would prefer to use this here, this package is already part of kibana, so it would be easier to use.

import { composeWithDevTools } from 'redux-devtools-extension';
export const store = createStore(rootReducer, composeWithDevTools(applyMiddleware(sagaMW)));

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏


const sagaMW = createSagaMiddleware();
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/uptime/public/state/reducers/journey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export interface JourneyState {
error?: Error;
}

interface JourneyKVP {
export interface JourneyKVP {
[checkGroup: string]: JourneyState;
}

Expand Down
3 changes: 1 addition & 2 deletions x-pack/plugins/uptime/server/lib/alerts/duration_anomaly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import moment from 'moment';
import { schema } from '@kbn/config-schema';
import { ActionGroupIdsOf } from '../../../../alerts/common';
import { updateState } from './common';
import { ACTION_GROUP_DEFINITIONS } from '../../../common/constants/alerts';
import { DURATION_ANOMALY } from '../../../common/constants/alerts';
import { commonStateTranslations, durationAnomalyTranslations } from './translations';
import { AnomaliesTableRecord } from '../../../../ml/common/types/anomalies';
import { getSeverityType } from '../../../../ml/common/util/anomaly_utils';
Expand All @@ -21,7 +21,6 @@ import { getMLJobId } from '../../../common/lib';
import { getLatestMonitor } from '../requests/get_latest_monitor';
import { uptimeAlertWrapper } from './uptime_alert_wrapper';

const { DURATION_ANOMALY } = ACTION_GROUP_DEFINITIONS;
export type ActionGroupIds = ActionGroupIdsOf<typeof DURATION_ANOMALY>;

export const getAnomalySummary = (anomaly: AnomaliesTableRecord, monitorInfo: Ping) => {
Expand Down
3 changes: 1 addition & 2 deletions x-pack/plugins/uptime/server/lib/alerts/status_check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
Ping,
GetMonitorAvailabilityParams,
} from '../../../common/runtime_types';
import { ACTION_GROUP_DEFINITIONS } from '../../../common/constants/alerts';
import { MONITOR_STATUS } from '../../../common/constants/alerts';
import { updateState } from './common';
import { commonMonitorStateI18, commonStateTranslations, DOWN_LABEL } from './translations';
import { stringifyKueries, combineFiltersAndUserSearch } from '../../../common/lib';
Expand All @@ -29,7 +29,6 @@ import { MonitorStatusTranslations } from '../../../common/translations';
import { getUptimeIndexPattern, IndexPatternTitleAndFields } from '../requests/get_index_pattern';
import { UMServerLibs, UptimeESClient } from '../lib';

const { MONITOR_STATUS } = ACTION_GROUP_DEFINITIONS;
export type ActionGroupIds = ActionGroupIdsOf<typeof MONITOR_STATUS>;

const getMonIdByLoc = (monitorId: string, location: string) => {
Expand Down
3 changes: 1 addition & 2 deletions x-pack/plugins/uptime/server/lib/alerts/tls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,14 @@ import moment from 'moment';
import { schema } from '@kbn/config-schema';
import { UptimeAlertTypeFactory } from './types';
import { updateState } from './common';
import { ACTION_GROUP_DEFINITIONS } from '../../../common/constants/alerts';
import { TLS } from '../../../common/constants/alerts';
import { DYNAMIC_SETTINGS_DEFAULTS } from '../../../common/constants';
import { Cert, CertResult } from '../../../common/runtime_types';
import { commonStateTranslations, tlsTranslations } from './translations';
import { DEFAULT_FROM, DEFAULT_TO } from '../../rest_api/certs/certs';
import { uptimeAlertWrapper } from './uptime_alert_wrapper';
import { ActionGroupIdsOf } from '../../../../alerts/common';

const { TLS } = ACTION_GROUP_DEFINITIONS;
export type ActionGroupIds = ActionGroupIdsOf<typeof TLS>;

const DEFAULT_SIZE = 20;
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/uptime/server/lib/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export interface UMServerLibs extends UMDomainLibs {
framework: UMBackendFrameworkAdapter;
}

interface CountResponse {
export interface CountResponse {
body: {
count: number;
_shards: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import { UMElasticsearchQueryFn } from '../adapters/framework';
import { SyntheticsJourneyApiResponse } from '../../../common/runtime_types';

interface GetJourneyDetails {
export interface GetJourneyDetails {
checkGroup: string;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import { UMElasticsearchQueryFn } from '../adapters/framework';
import { Ping } from '../../../common/runtime_types';

interface GetJourneyStepsParams {
export interface GetJourneyStepsParams {
checkGroups: string[];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import { UMElasticsearchQueryFn } from '../adapters/framework';
import { Ping } from '../../../common/runtime_types/ping';

interface GetJourneyScreenshotParams {
export interface GetJourneyScreenshotParams {
checkGroup: string;
stepIndex: number;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import { UMElasticsearchQueryFn } from '../adapters/framework';
import { Ping } from '../../../common/runtime_types';

interface GetJourneyStepsParams {
export interface GetJourneyStepsParams {
andrewvc marked this conversation as resolved.
Show resolved Hide resolved
checkGroup: string;
syntheticEventTypes?: string | string[];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import { UMElasticsearchQueryFn } from '../adapters/framework';
import { NetworkEvent } from '../../../common/runtime_types';

interface GetNetworkEventsParams {
export interface GetNetworkEventsParams {
checkGroup: string;
stepIndex: string;
}
Expand Down
15 changes: 11 additions & 4 deletions x-pack/plugins/uptime/server/lib/requests/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
* 2.0.
*/

// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { ElasticsearchClientMock } from 'src/core/server/elasticsearch/client/mocks';
import {
elasticsearchServiceMock,
savedObjectsClientMock,
} from '../../../../../../src/core/server/mocks';

// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { ElasticsearchClientMock } from '../../../../../../src/core/server/elasticsearch/client/mocks';
import { createUptimeESClient } from '../lib';
import { createUptimeESClient, UptimeESClient } from '../lib';

export interface MultiPageCriteria<K, T> {
after_key?: K;
Expand Down Expand Up @@ -60,7 +60,14 @@ export const setupMockEsCompositeQuery = <K, C, I>(
return esMock;
};

export const getUptimeESMockClient = (esClientMock?: ElasticsearchClientMock) => {
interface UptimeEsMockClient {
esClient: ElasticsearchClientMock;
uptimeEsClient: UptimeESClient;
}

export const getUptimeESMockClient = (
esClientMock?: ElasticsearchClientMock
): UptimeEsMockClient => {
const esClient = elasticsearchServiceMock.createElasticsearchClient();

const savedObjectsClient = savedObjectsClientMock.create();
Expand Down
24 changes: 24 additions & 0 deletions x-pack/plugins/uptime/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"extends": "../../../tsconfig.base.json",
"compilerOptions": {
"composite": true,
"outDir": "./target/types",
"emitDeclarationOnly": true,
"declaration": true,
"declarationMap": true
},
"include": [
"common/**/*",
"public/**/*",
"server/**/*",
"../../../typings/**/*",
"public/**/*.json",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The glob syntax above appeared to ignore JSON files.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since there are just two json files, maybe it doesn't make sense to use wildcard pattern

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, we can make it more specific. The drawback will be when someone adds a dependency in the future this will need to be updated each time.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"public/**/*.json",
"server/lib/requests/__fixtures__/monitor_charts_mock.json"

"server/**/*.json"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"server/**/*.json"
"server/lib/requests/__fixtures__/monitor_charts_mock.json"

],
"references": [
{ "path": "../alerts/tsconfig.json" },
{ "path": "../ml/tsconfig.json" },
{ "path": "../triggers_actions_ui/tsconfig.json" },
{ "path": "../observability/tsconfig.json" }
]
}
3 changes: 2 additions & 1 deletion x-pack/test/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
{ "path": "../plugins/upgrade_assistant/tsconfig.json" },
{ "path": "../plugins/watcher/tsconfig.json" },
{ "path": "../plugins/runtime_fields/tsconfig.json" },
{ "path": "../plugins/index_management/tsconfig.json" }
{ "path": "../plugins/index_management/tsconfig.json" },
{ "path": "../plugins/uptime/tsconfig.json" }
]
}
4 changes: 3 additions & 1 deletion x-pack/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"plugins/index_management/**/*",
"plugins/grokdebugger/**/*",
"plugins/upgrade_assistant/**/*",
"plugins/uptime/**/*",
"test/**/*"
],
"compilerOptions": {
Expand Down Expand Up @@ -143,6 +144,7 @@
{ "path": "./plugins/upgrade_assistant/tsconfig.json" },
{ "path": "./plugins/runtime_fields/tsconfig.json" },
{ "path": "./plugins/index_management/tsconfig.json" },
{ "path": "./plugins/watcher/tsconfig.json" }
{ "path": "./plugins/watcher/tsconfig.json" },
{ "path": "./plugins/uptime/tsconfig.json" }
]
}
3 changes: 2 additions & 1 deletion x-pack/tsconfig.refs.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
{ "path": "./plugins/upgrade_assistant/tsconfig.json" },
{ "path": "./plugins/runtime_fields/tsconfig.json" },
{ "path": "./plugins/index_management/tsconfig.json" },
{ "path": "./plugins/watcher/tsconfig.json" }
{ "path": "./plugins/watcher/tsconfig.json" },
{ "path": "./plugins/uptime/tsconfig.json" }
]
}