Skip to content

Commit

Permalink
Migrate status & stats APIs to KP + remove legacy status lib (#76054)
Browse files Browse the repository at this point in the history
* Complete migration of legacy status API

* PR comments

* Remove optional auth on stats endpoint

* Regen docs

* PR comments

* PR nits

* Set ReplaySubject buffer to 1

* Fix exclude_usage logic

Co-authored-by: pgayvallet <[email protected]>
  • Loading branch information
joshdover and pgayvallet authored Sep 17, 2020
1 parent e3f3d5f commit cbf2844
Show file tree
Hide file tree
Showing 65 changed files with 1,414 additions and 2,462 deletions.
3 changes: 2 additions & 1 deletion .i18nrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@
"visTypeXy": "src/plugins/vis_type_xy",
"visualizations": "src/plugins/visualizations",
"visualize": "src/plugins/visualize",
"apmOss": "src/plugins/apm_oss"
"apmOss": "src/plugins/apm_oss",
"usageCollection": "src/plugins/usage_collection"
},
"exclude": [
"src/legacy/ui/ui_render/ui_render_mixin.js"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export interface CoreSetup<TPluginsStart extends object = object, TStart = unkno
| [getStartServices](./kibana-plugin-core-server.coresetup.getstartservices.md) | <code>StartServicesAccessor&lt;TPluginsStart, TStart&gt;</code> | [StartServicesAccessor](./kibana-plugin-core-server.startservicesaccessor.md) |
| [http](./kibana-plugin-core-server.coresetup.http.md) | <code>HttpServiceSetup &amp; {</code><br/><code> resources: HttpResources;</code><br/><code> }</code> | [HttpServiceSetup](./kibana-plugin-core-server.httpservicesetup.md) |
| [logging](./kibana-plugin-core-server.coresetup.logging.md) | <code>LoggingServiceSetup</code> | [LoggingServiceSetup](./kibana-plugin-core-server.loggingservicesetup.md) |
| [metrics](./kibana-plugin-core-server.coresetup.metrics.md) | <code>MetricsServiceSetup</code> | [MetricsServiceSetup](./kibana-plugin-core-server.metricsservicesetup.md) |
| [savedObjects](./kibana-plugin-core-server.coresetup.savedobjects.md) | <code>SavedObjectsServiceSetup</code> | [SavedObjectsServiceSetup](./kibana-plugin-core-server.savedobjectsservicesetup.md) |
| [status](./kibana-plugin-core-server.coresetup.status.md) | <code>StatusServiceSetup</code> | [StatusServiceSetup](./kibana-plugin-core-server.statusservicesetup.md) |
| [uiSettings](./kibana-plugin-core-server.coresetup.uisettings.md) | <code>UiSettingsServiceSetup</code> | [UiSettingsServiceSetup](./kibana-plugin-core-server.uisettingsservicesetup.md) |
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-core-server](./kibana-plugin-core-server.md) &gt; [CoreSetup](./kibana-plugin-core-server.coresetup.md) &gt; [metrics](./kibana-plugin-core-server.coresetup.metrics.md)

## CoreSetup.metrics property

[MetricsServiceSetup](./kibana-plugin-core-server.metricsservicesetup.md)

<b>Signature:</b>

```typescript
metrics: MetricsServiceSetup;
```
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export interface CoreStart
| [capabilities](./kibana-plugin-core-server.corestart.capabilities.md) | <code>CapabilitiesStart</code> | [CapabilitiesStart](./kibana-plugin-core-server.capabilitiesstart.md) |
| [elasticsearch](./kibana-plugin-core-server.corestart.elasticsearch.md) | <code>ElasticsearchServiceStart</code> | [ElasticsearchServiceStart](./kibana-plugin-core-server.elasticsearchservicestart.md) |
| [http](./kibana-plugin-core-server.corestart.http.md) | <code>HttpServiceStart</code> | [HttpServiceStart](./kibana-plugin-core-server.httpservicestart.md) |
| [metrics](./kibana-plugin-core-server.corestart.metrics.md) | <code>MetricsServiceStart</code> | |
| [metrics](./kibana-plugin-core-server.corestart.metrics.md) | <code>MetricsServiceStart</code> | [MetricsServiceStart](./kibana-plugin-core-server.metricsservicestart.md) |
| [savedObjects](./kibana-plugin-core-server.corestart.savedobjects.md) | <code>SavedObjectsServiceStart</code> | [SavedObjectsServiceStart](./kibana-plugin-core-server.savedobjectsservicestart.md) |
| [uiSettings](./kibana-plugin-core-server.corestart.uisettings.md) | <code>UiSettingsServiceStart</code> | [UiSettingsServiceStart](./kibana-plugin-core-server.uisettingsservicestart.md) |

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

## CoreStart.metrics property

[MetricsServiceStart](./kibana-plugin-core-server.metricsservicestart.md)

<b>Signature:</b>

Expand Down
1 change: 1 addition & 0 deletions docs/development/core/server/kibana-plugin-core-server.md
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ The plugin integrates with the core system via lifecycle events: `setup`<!-- -->
| [LegacyElasticsearchClientConfig](./kibana-plugin-core-server.legacyelasticsearchclientconfig.md) | |
| [LifecycleResponseFactory](./kibana-plugin-core-server.lifecycleresponsefactory.md) | Creates an object containing redirection or error response with error details, HTTP headers, and other data transmitted to the client. |
| [LoggerConfigType](./kibana-plugin-core-server.loggerconfigtype.md) | |
| [MetricsServiceStart](./kibana-plugin-core-server.metricsservicestart.md) | APIs to retrieves metrics gathered and exposed by the core platform. |
| [MIGRATION\_ASSISTANCE\_INDEX\_ACTION](./kibana-plugin-core-server.migration_assistance_index_action.md) | |
| [MIGRATION\_DEPRECATION\_LEVEL](./kibana-plugin-core-server.migration_deprecation_level.md) | |
| [MutatingOperationRefreshSetting](./kibana-plugin-core-server.mutatingoperationrefreshsetting.md) | Elasticsearch Refresh setting for mutating operation |
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-core-server](./kibana-plugin-core-server.md) &gt; [MetricsServiceStart](./kibana-plugin-core-server.metricsservicestart.md)

## MetricsServiceStart type

APIs to retrieves metrics gathered and exposed by the core platform.

<b>Signature:</b>

```typescript
export declare type MetricsServiceStart = MetricsServiceSetup;
```
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,22 @@ ServiceStatusLevels: Readonly<{
available: Readonly<{
toString: () => "available";
valueOf: () => 0;
toJSON: () => "available";
}>;
degraded: Readonly<{
toString: () => "degraded";
valueOf: () => 1;
toJSON: () => "degraded";
}>;
unavailable: Readonly<{
toString: () => "unavailable";
valueOf: () => 2;
toJSON: () => "unavailable";
}>;
critical: Readonly<{
toString: () => "critical";
valueOf: () => 3;
toJSON: () => "critical";
}>;
}>
```
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-core-server](./kibana-plugin-core-server.md) &gt; [StatusServiceSetup](./kibana-plugin-core-server.statusservicesetup.md) &gt; [isStatusPageAnonymous](./kibana-plugin-core-server.statusservicesetup.isstatuspageanonymous.md)

## StatusServiceSetup.isStatusPageAnonymous property

Whether or not the status HTTP APIs are available to unauthenticated users when an authentication provider is present.

<b>Signature:</b>

```typescript
isStatusPageAnonymous: () => boolean;
```
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ core.status.set(
| [core$](./kibana-plugin-core-server.statusservicesetup.core_.md) | <code>Observable&lt;CoreStatus&gt;</code> | Current status for all Core services. |
| [dependencies$](./kibana-plugin-core-server.statusservicesetup.dependencies_.md) | <code>Observable&lt;Record&lt;string, ServiceStatus&gt;&gt;</code> | Current status for all plugins this plugin depends on. Each key of the <code>Record</code> is a plugin id. |
| [derivedStatus$](./kibana-plugin-core-server.statusservicesetup.derivedstatus_.md) | <code>Observable&lt;ServiceStatus&gt;</code> | The status of this plugin as derived from its dependencies. |
| [isStatusPageAnonymous](./kibana-plugin-core-server.statusservicesetup.isstatuspageanonymous.md) | <code>() =&gt; boolean</code> | Whether or not the status HTTP APIs are available to unauthenticated users when an authentication provider is present. |
| [overall$](./kibana-plugin-core-server.statusservicesetup.overall_.md) | <code>Observable&lt;ServiceStatus&gt;</code> | Overall system status for all of Kibana. |

## Methods
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export function mapNodesVersionCompatibility(
kibanaVersion: string,
ignoreVersionMismatch: boolean
): NodesVersionCompatibility {
if (Object.keys(nodesInfo.nodes).length === 0) {
if (Object.keys(nodesInfo.nodes ?? {}).length === 0) {
return {
isCompatible: false,
message: 'Unable to retrieve version information from Elasticsearch nodes.',
Expand Down
5 changes: 4 additions & 1 deletion src/core/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ import {
SavedObjectsServiceStart,
} from './saved_objects';
import { CapabilitiesSetup, CapabilitiesStart } from './capabilities';
import { MetricsServiceStart } from './metrics';
import { MetricsServiceSetup, MetricsServiceStart } from './metrics';
import { StatusServiceSetup } from './status';
import { Auditor, AuditTrailSetup, AuditTrailStart } from './audit_trail';
import { AppenderConfigType, appendersSchema, LoggingServiceSetup } from './logging';
Expand Down Expand Up @@ -320,6 +320,7 @@ export {
OpsServerMetrics,
OpsProcessMetrics,
MetricsServiceSetup,
MetricsServiceStart,
} from './metrics';

export { DEFAULT_APP_CATEGORIES } from '../utils';
Expand Down Expand Up @@ -414,6 +415,8 @@ export interface CoreSetup<TPluginsStart extends object = object, TStart = unkno
};
/** {@link LoggingServiceSetup} */
logging: LoggingServiceSetup;
/** {@link MetricsServiceSetup} */
metrics: MetricsServiceSetup;
/** {@link SavedObjectsServiceSetup} */
savedObjects: SavedObjectsServiceSetup;
/** {@link StatusServiceSetup} */
Expand Down
3 changes: 2 additions & 1 deletion src/core/server/internal_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import {
} from './saved_objects';
import { InternalUiSettingsServiceSetup, InternalUiSettingsServiceStart } from './ui_settings';
import { InternalEnvironmentServiceSetup } from './environment';
import { InternalMetricsServiceStart } from './metrics';
import { InternalMetricsServiceSetup, InternalMetricsServiceStart } from './metrics';
import { InternalRenderingServiceSetup } from './rendering';
import { InternalHttpResourcesSetup } from './http_resources';
import { InternalStatusServiceSetup } from './status';
Expand All @@ -54,6 +54,7 @@ export interface InternalCoreSetup {
httpResources: InternalHttpResourcesSetup;
auditTrail: AuditTrailSetup;
logging: InternalLoggingServiceSetup;
metrics: InternalMetricsServiceSetup;
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/core/server/legacy/legacy_service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import { coreMock } from '../mocks';
import { statusServiceMock } from '../status/status_service.mock';
import { auditTrailServiceMock } from '../audit_trail/audit_trail_service.mock';
import { loggingServiceMock } from '../logging/logging_service.mock';
import { metricsServiceMock } from '../metrics/metrics_service.mock';

const MockKbnServer: jest.Mock<KbnServer> = KbnServer as any;

Expand Down Expand Up @@ -99,6 +100,7 @@ beforeEach(() => {
status: statusServiceMock.createInternalSetupContract(),
auditTrail: auditTrailServiceMock.createSetupContract(),
logging: loggingServiceMock.createInternalSetupContract(),
metrics: metricsServiceMock.createInternalSetupContract(),
},
plugins: { 'plugin-id': 'plugin-value' },
uiPlugins: {
Expand Down
5 changes: 5 additions & 0 deletions src/core/server/legacy/legacy_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,13 +302,18 @@ export class LegacyService implements CoreService {
logging: {
configure: (config$) => setupDeps.core.logging.configure([], config$),
},
metrics: {
collectionInterval: setupDeps.core.metrics.collectionInterval,
getOpsMetrics$: setupDeps.core.metrics.getOpsMetrics$,
},
savedObjects: {
setClientFactoryProvider: setupDeps.core.savedObjects.setClientFactoryProvider,
addClientWrapper: setupDeps.core.savedObjects.addClientWrapper,
registerType: setupDeps.core.savedObjects.registerType,
getImportExportObjectLimit: setupDeps.core.savedObjects.getImportExportObjectLimit,
},
status: {
isStatusPageAnonymous: setupDeps.core.status.isStatusPageAnonymous,
core$: setupDeps.core.status.core$,
overall$: setupDeps.core.status.overall$,
set: () => {
Expand Down
4 changes: 2 additions & 2 deletions src/core/server/metrics/metrics_service.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ type MetricsServiceContract = PublicMethodsOf<MetricsService>;

const createMock = () => {
const mocked: jest.Mocked<MetricsServiceContract> = {
setup: jest.fn().mockReturnValue(createInternalSetupContractMock()),
start: jest.fn().mockReturnValue(createInternalStartContractMock()),
setup: jest.fn().mockReturnValue(createSetupContractMock()),
start: jest.fn().mockReturnValue(createStartContractMock()),
stop: jest.fn(),
};
return mocked;
Expand Down
5 changes: 4 additions & 1 deletion src/core/server/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export { typeRegistryMock as savedObjectsTypeRegistryMock } from './saved_object
export { uiSettingsServiceMock } from './ui_settings/ui_settings_service.mock';
export { metricsServiceMock } from './metrics/metrics_service.mock';
export { renderingMock } from './rendering/rendering_service.mock';
export { statusServiceMock } from './status/status_service.mock';
export { contextServiceMock } from './context/context_service.mock';

export function pluginInitializerContextConfigMock<T>(config: T) {
Expand Down Expand Up @@ -138,6 +139,7 @@ function createCoreSetupMock({
uiSettings: uiSettingsMock,
auditTrail: auditTrailServiceMock.createSetupContract(),
logging: loggingServiceMock.createSetupContract(),
metrics: metricsServiceMock.createSetupContract(),
getStartServices: jest
.fn<Promise<[ReturnType<typeof createCoreStartMock>, object, any]>, []>()
.mockResolvedValue([createCoreStartMock(), pluginStartDeps, pluginStartContract]),
Expand Down Expand Up @@ -174,6 +176,7 @@ function createInternalCoreSetupMock() {
uiSettings: uiSettingsServiceMock.createSetupContract(),
auditTrail: auditTrailServiceMock.createSetupContract(),
logging: loggingServiceMock.createInternalSetupContract(),
metrics: metricsServiceMock.createInternalSetupContract(),
};
return setupDeps;
}
Expand All @@ -183,7 +186,7 @@ function createInternalCoreStartMock() {
capabilities: capabilitiesServiceMock.createStartContract(),
elasticsearch: elasticsearchServiceMock.createInternalStart(),
http: httpServiceMock.createInternalStartContract(),
metrics: metricsServiceMock.createStartContract(),
metrics: metricsServiceMock.createInternalStartContract(),
savedObjects: savedObjectsServiceMock.createInternalStartContract(),
uiSettings: uiSettingsServiceMock.createStartContract(),
auditTrail: auditTrailServiceMock.createStartContract(),
Expand Down
5 changes: 5 additions & 0 deletions src/core/server/plugins/plugin_context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@ export function createPluginSetupContext<TPlugin, TPluginDependencies>(
logging: {
configure: (config$) => deps.logging.configure(['plugins', plugin.name], config$),
},
metrics: {
collectionInterval: deps.metrics.collectionInterval,
getOpsMetrics$: deps.metrics.getOpsMetrics$,
},
savedObjects: {
setClientFactoryProvider: deps.savedObjects.setClientFactoryProvider,
addClientWrapper: deps.savedObjects.addClientWrapper,
Expand All @@ -191,6 +195,7 @@ export function createPluginSetupContext<TPlugin, TPluginDependencies>(
set: deps.status.plugins.set.bind(null, plugin.name),
dependencies$: deps.status.plugins.getDependenciesStatus$(plugin.name),
derivedStatus$: deps.status.plugins.getDerivedStatus$(plugin.name),
isStatusPageAnonymous: deps.status.isStatusPageAnonymous,
},
uiSettings: {
register: deps.uiSettings.register,
Expand Down
13 changes: 10 additions & 3 deletions src/core/server/server.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,8 @@ export interface CoreSetup<TPluginsStart extends object = object, TStart = unkno
// (undocumented)
logging: LoggingServiceSetup;
// (undocumented)
metrics: MetricsServiceSetup;
// (undocumented)
savedObjects: SavedObjectsServiceSetup;
// (undocumented)
status: StatusServiceSetup;
Expand All @@ -433,9 +435,6 @@ export interface CoreStart {
elasticsearch: ElasticsearchServiceStart;
// (undocumented)
http: HttpServiceStart;
// Warning: (ae-forgotten-export) The symbol "MetricsServiceStart" needs to be exported by the entry point index.d.ts
// Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "kibana" does not have an export "MetricsServiceStart"
//
// (undocumented)
metrics: MetricsServiceStart;
// (undocumented)
Expand Down Expand Up @@ -1431,6 +1430,9 @@ export interface MetricsServiceSetup {
getOpsMetrics$: () => Observable<OpsMetrics>;
}

// @public
export type MetricsServiceStart = MetricsServiceSetup;

// @public @deprecated (undocumented)
export type MIGRATION_ASSISTANCE_INDEX_ACTION = 'upgrade' | 'reindex';

Expand Down Expand Up @@ -2589,18 +2591,22 @@ export const ServiceStatusLevels: Readonly<{
available: Readonly<{
toString: () => "available";
valueOf: () => 0;
toJSON: () => "available";
}>;
degraded: Readonly<{
toString: () => "degraded";
valueOf: () => 1;
toJSON: () => "degraded";
}>;
unavailable: Readonly<{
toString: () => "unavailable";
valueOf: () => 2;
toJSON: () => "unavailable";
}>;
critical: Readonly<{
toString: () => "critical";
valueOf: () => 3;
toJSON: () => "critical";
}>;
}>;

Expand Down Expand Up @@ -2676,6 +2682,7 @@ export interface StatusServiceSetup {
dependencies$: Observable<Record<string, ServiceStatus>>;
// Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "kibana" does not have an export "StatusSetup"
derivedStatus$: Observable<ServiceStatus>;
isStatusPageAnonymous: () => boolean;
overall$: Observable<ServiceStatus>;
set(status$: Observable<ServiceStatus>): void;
}
Expand Down
6 changes: 5 additions & 1 deletion src/core/server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,15 @@ export class Server {
savedObjects: savedObjectsSetup,
});

await this.metrics.setup({ http: httpSetup });
const metricsSetup = await this.metrics.setup({ http: httpSetup });

const statusSetup = await this.status.setup({
elasticsearch: elasticsearchServiceSetup,
pluginDependencies: pluginTree.asNames,
savedObjects: savedObjectsSetup,
environment: environmentSetup,
http: httpSetup,
metrics: metricsSetup,
});

const renderingSetup = await this.rendering.setup({
Expand Down Expand Up @@ -189,6 +192,7 @@ export class Server {
httpResources: httpResourcesSetup,
auditTrail: auditTrailSetup,
logging: loggingSetup,
metrics: metricsSetup,
};

const pluginsSetup = await this.plugins.setup(coreSetup);
Expand Down
Loading

0 comments on commit cbf2844

Please sign in to comment.