Skip to content

Commit

Permalink
Remove OS data for now, test for SO usage data
Browse files Browse the repository at this point in the history
  • Loading branch information
rudolf committed Oct 4, 2020
1 parent 949e6a5 commit 062280e
Show file tree
Hide file tree
Showing 17 changed files with 384 additions and 57 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<!-- 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; [CoreConfigUsageData](./kibana-plugin-core-server.coreconfigusagedata.md) &gt; [elasticsearch](./kibana-plugin-core-server.coreconfigusagedata.elasticsearch.md)

## CoreConfigUsageData.elasticsearch property

<b>Signature:</b>

```typescript
elasticsearch: {
sniffOnStart: boolean;
sniffIntervalMs?: number;
sniffOnConnectionFault: boolean;
numberOfHostsConfigured: number;
requestHeadersWhitelistConfigured: boolean;
customHeadersConfigured: boolean;
shardTimeoutMs: number;
requestTimeoutMs: number;
pingTimeoutMs: number;
logQueries: boolean;
ssl: {
verificationMode: 'none' | 'certificate' | 'full';
certificateAuthoritiesConfigured: boolean;
certificateConfigured: boolean;
keyConfigured: boolean;
keystoreConfigured: boolean;
truststoreConfigured: boolean;
alwaysPresentCertificate: boolean;
};
apiVersion: string;
healthCheckDelayMs: number;
};
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<!-- 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; [CoreConfigUsageData](./kibana-plugin-core-server.coreconfigusagedata.md) &gt; [http](./kibana-plugin-core-server.coreconfigusagedata.http.md)

## CoreConfigUsageData.http property

<b>Signature:</b>

```typescript
http: {
basePathConfigured: boolean;
maxPayloadInBytes: number;
rewriteBasePath: boolean;
keepaliveTimeout: number;
socketTimeout: number;
compression: {
enabled: boolean;
referrerWhitelistConfigured: boolean;
};
xsrf: {
disableProtection: boolean;
whitelistConfigured: boolean;
};
requestId: {
allowFromAnyIp: boolean;
ipAllowlistConfigured: boolean;
};
ssl: {
certificateAuthoritiesConfigured: boolean;
certificateConfigured: boolean;
cipherSuites: string[];
keyConfigured: boolean;
keystoreConfigured: boolean;
truststoreConfigured: boolean;
redirectHttpFromPortConfigured: boolean;
supportedProtocols: string[];
clientAuthentication: 'none' | 'optional' | 'required';
};
};
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!-- 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; [CoreConfigUsageData](./kibana-plugin-core-server.coreconfigusagedata.md) &gt; [logging](./kibana-plugin-core-server.coreconfigusagedata.logging.md)

## CoreConfigUsageData.logging property

<b>Signature:</b>

```typescript
logging: {
appendersTypesUsed: string[];
loggersConfiguredCount: number;
};
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!-- 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; [CoreConfigUsageData](./kibana-plugin-core-server.coreconfigusagedata.md)

## CoreConfigUsageData interface

Usage data on this cluster's configuration of Core features

<b>Signature:</b>

```typescript
export interface CoreConfigUsageData
```

## Properties

| Property | Type | Description |
| --- | --- | --- |
| [elasticsearch](./kibana-plugin-core-server.coreconfigusagedata.elasticsearch.md) | <code>{</code><br/><code> sniffOnStart: boolean;</code><br/><code> sniffIntervalMs?: number;</code><br/><code> sniffOnConnectionFault: boolean;</code><br/><code> numberOfHostsConfigured: number;</code><br/><code> requestHeadersWhitelistConfigured: boolean;</code><br/><code> customHeadersConfigured: boolean;</code><br/><code> shardTimeoutMs: number;</code><br/><code> requestTimeoutMs: number;</code><br/><code> pingTimeoutMs: number;</code><br/><code> logQueries: boolean;</code><br/><code> ssl: {</code><br/><code> verificationMode: 'none' &#124; 'certificate' &#124; 'full';</code><br/><code> certificateAuthoritiesConfigured: boolean;</code><br/><code> certificateConfigured: boolean;</code><br/><code> keyConfigured: boolean;</code><br/><code> keystoreConfigured: boolean;</code><br/><code> truststoreConfigured: boolean;</code><br/><code> alwaysPresentCertificate: boolean;</code><br/><code> };</code><br/><code> apiVersion: string;</code><br/><code> healthCheckDelayMs: number;</code><br/><code> }</code> | |
| [http](./kibana-plugin-core-server.coreconfigusagedata.http.md) | <code>{</code><br/><code> basePathConfigured: boolean;</code><br/><code> maxPayloadInBytes: number;</code><br/><code> rewriteBasePath: boolean;</code><br/><code> keepaliveTimeout: number;</code><br/><code> socketTimeout: number;</code><br/><code> compression: {</code><br/><code> enabled: boolean;</code><br/><code> referrerWhitelistConfigured: boolean;</code><br/><code> };</code><br/><code> xsrf: {</code><br/><code> disableProtection: boolean;</code><br/><code> whitelistConfigured: boolean;</code><br/><code> };</code><br/><code> requestId: {</code><br/><code> allowFromAnyIp: boolean;</code><br/><code> ipAllowlistConfigured: boolean;</code><br/><code> };</code><br/><code> ssl: {</code><br/><code> certificateAuthoritiesConfigured: boolean;</code><br/><code> certificateConfigured: boolean;</code><br/><code> cipherSuites: string[];</code><br/><code> keyConfigured: boolean;</code><br/><code> keystoreConfigured: boolean;</code><br/><code> truststoreConfigured: boolean;</code><br/><code> redirectHttpFromPortConfigured: boolean;</code><br/><code> supportedProtocols: string[];</code><br/><code> clientAuthentication: 'none' &#124; 'optional' &#124; 'required';</code><br/><code> };</code><br/><code> }</code> | |
| [logging](./kibana-plugin-core-server.coreconfigusagedata.logging.md) | <code>{</code><br/><code> appendersTypesUsed: string[];</code><br/><code> loggersConfiguredCount: number;</code><br/><code> }</code> | |
| [savedObjects](./kibana-plugin-core-server.coreconfigusagedata.savedobjects.md) | <code>{</code><br/><code> maxImportPayloadBytes: number;</code><br/><code> maxImportExportSizeBytes: number;</code><br/><code> }</code> | |

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!-- 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; [CoreConfigUsageData](./kibana-plugin-core-server.coreconfigusagedata.md) &gt; [savedObjects](./kibana-plugin-core-server.coreconfigusagedata.savedobjects.md)

## CoreConfigUsageData.savedObjects property

<b>Signature:</b>

```typescript
savedObjects: {
maxImportPayloadBytes: number;
maxImportExportSizeBytes: number;
};
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!-- 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; [CoreEnvironmentUsageData](./kibana-plugin-core-server.coreenvironmentusagedata.md)

## CoreEnvironmentUsageData interface

Usage data on this Kibana node's runtime environment.

<b>Signature:</b>

```typescript
export interface CoreEnvironmentUsageData
```

## Properties

| Property | Type | Description |
| --- | --- | --- |
| [memory](./kibana-plugin-core-server.coreenvironmentusagedata.memory.md) | <code>{</code><br/><code> heapTotalBytes: number;</code><br/><code> heapUsedBytes: number;</code><br/><code> heapSizeLimit: number;</code><br/><code> }</code> | |

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!-- 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; [CoreEnvironmentUsageData](./kibana-plugin-core-server.coreenvironmentusagedata.md) &gt; [memory](./kibana-plugin-core-server.coreenvironmentusagedata.memory.md)

## CoreEnvironmentUsageData.memory property

<b>Signature:</b>

```typescript
memory: {
heapTotalBytes: number;
heapUsedBytes: number;
heapSizeLimit: number;
};
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!-- 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; [CoreServicesUsageData](./kibana-plugin-core-server.coreservicesusagedata.md)

## CoreServicesUsageData interface

Usage data from Core services

<b>Signature:</b>

```typescript
export interface CoreServicesUsageData
```

## Properties

| Property | Type | Description |
| --- | --- | --- |
| [savedObjects](./kibana-plugin-core-server.coreservicesusagedata.savedobjects.md) | <code>{</code><br/><code> indices: {</code><br/><code> alias: string;</code><br/><code> docsCount: number;</code><br/><code> docsDeleted: number;</code><br/><code> storeSizeBytes: number;</code><br/><code> primaryStoreSizeBytes: number;</code><br/><code> }[];</code><br/><code> }</code> | |

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!-- 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; [CoreServicesUsageData](./kibana-plugin-core-server.coreservicesusagedata.md) &gt; [savedObjects](./kibana-plugin-core-server.coreservicesusagedata.savedobjects.md)

## CoreServicesUsageData.savedObjects property

<b>Signature:</b>

```typescript
savedObjects: {
indices: {
alias: string;
docsCount: number;
docsDeleted: number;
storeSizeBytes: number;
primaryStoreSizeBytes: number;
}[];
};
```
3 changes: 3 additions & 0 deletions docs/development/core/server/kibana-plugin-core-server.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ The plugin integrates with the core system via lifecycle events: `setup`<!-- -->
| [CapabilitiesSetup](./kibana-plugin-core-server.capabilitiessetup.md) | APIs to manage the [Capabilities](./kibana-plugin-core-server.capabilities.md) that will be used by the application.<!-- -->Plugins relying on capabilities to toggle some of their features should register them during the setup phase using the <code>registerProvider</code> method.<!-- -->Plugins having the responsibility to restrict capabilities depending on a given context should register their capabilities switcher using the <code>registerSwitcher</code> method.<!-- -->Refers to the methods documentation for complete description and examples. |
| [CapabilitiesStart](./kibana-plugin-core-server.capabilitiesstart.md) | APIs to access the application [Capabilities](./kibana-plugin-core-server.capabilities.md)<!-- -->. |
| [ContextSetup](./kibana-plugin-core-server.contextsetup.md) | An object that handles registration of context providers and configuring handlers with context. |
| [CoreConfigUsageData](./kibana-plugin-core-server.coreconfigusagedata.md) | Usage data on this cluster's configuration of Core features |
| [CoreEnvironmentUsageData](./kibana-plugin-core-server.coreenvironmentusagedata.md) | Usage data on this Kibana node's runtime environment. |
| [CoreServicesUsageData](./kibana-plugin-core-server.coreservicesusagedata.md) | Usage data from Core services |
| [CoreSetup](./kibana-plugin-core-server.coresetup.md) | Context passed to the plugins <code>setup</code> method. |
| [CoreStart](./kibana-plugin-core-server.corestart.md) | Context passed to the plugins <code>start</code> method. |
| [CoreStatus](./kibana-plugin-core-server.corestatus.md) | Status of core services. |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,18 +117,14 @@ const createStartContractMock = () => {
heapTotalBytes: 1,
heapUsedBytes: 1,
},
os: {
platform: 'darwin',
platformRelease: 'test',
},
},
services: {
savedObjects: {
indices: [
{
docsCount: 1,
docsDeleted: 1,
name: 'test_index',
alias: 'test_index',
primaryStoreSizeBytes: 1,
storeSizeBytes: 1,
},
Expand Down
55 changes: 46 additions & 9 deletions src/core/server/core_usage_data/core_usage_data_service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,38 @@ describe('CoreUsageDataService', () => {
it('returns core metrics for default config', () => {
const metrics = metricsServiceMock.createInternalSetupContract();
service.setup({ metrics });
const elasticsearch = elasticsearchServiceMock.createStart();
elasticsearch.client.asInternalUser.cat.indices.mockResolvedValueOnce({
body: [
{
name: '.kibana_task_manager_1',
'docs.count': 10,
'docs.deleted': 10,
'store.size': 1000,
'pri.store.size': 2000,
},
],
} as any);
elasticsearch.client.asInternalUser.cat.indices.mockResolvedValueOnce({
body: [
{
name: '.kibana_1',
'docs.count': 20,
'docs.deleted': 20,
'store.size': 2000,
'pri.store.size': 4000,
},
],
} as any);
const typeRegistry = savedObjectsServiceMock.createTypeRegistryMock();
typeRegistry.getAllTypes.mockReturnValue([
{ name: 'type 1', indexPattern: '.kibana' },
{ name: 'type 2', indexPattern: '.kibana_task_manager' },
] as any);

const { getCoreUsageData } = service.start({
savedObjects: savedObjectsServiceMock.createInternalStartContract(),
elasticsearch: elasticsearchServiceMock.createStart(),
savedObjects: savedObjectsServiceMock.createInternalStartContract(typeRegistry),
elasticsearch,
});
expect(getCoreUsageData()).resolves.toMatchInlineSnapshot(`
Object {
Expand Down Expand Up @@ -169,16 +197,25 @@ describe('CoreUsageDataService', () => {
"heapTotalBytes": 1,
"heapUsedBytes": 1,
},
"os": Object {
"distro": undefined,
"distroRelease": undefined,
"platform": "darwin",
"platformRelease": "test",
},
},
"services": Object {
"savedObjects": Object {
"indices": Array [],
"indices": Array [
Object {
"alias": ".kibana",
"docsCount": 10,
"docsDeleted": 10,
"primaryStoreSizeBytes": 2000,
"storeSizeBytes": 1000,
},
Object {
"alias": ".kibana_task_manager",
"docsCount": 20,
"docsDeleted": 20,
"primaryStoreSizeBytes": 4000,
"storeSizeBytes": 2000,
},
],
},
},
}
Expand Down
46 changes: 27 additions & 19 deletions src/core/server/core_usage_data/core_usage_data_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,24 @@ export interface StartDeps {
elasticsearch: ElasticsearchServiceStart;
}

/**
* Because users can configure their Saved Object to any arbitrary index name,
* we need to map customized index names back to a "standard" index name.
*
* e.g. If a user configures `kibana.index: .my_saved_objects` we want to the
* collected data to be grouped under `.kibana` not ".my_saved_objects".
*
* This is rather brittle, but the option to configure index names might go
* away completely anyway (see #60053).
*
* @param index The index name configured for this SO type
* @param kibanaConfigIndex The default kibana index as configured by the user
* with `kibana.index`
*/
const kibanaOrTaskManagerIndex = (index: string, kibanaConfigIndex: string) => {
return index === kibanaConfigIndex ? '.kibana' : '.kibana_task_manager';
};

export class CoreUsageDataService implements CoreService<void, CoreUsageDataStart> {
private elasticsearchConfig?: ElasticsearchConfigType;
private configService: CoreContext['configService'];
Expand All @@ -67,32 +85,28 @@ export class CoreUsageDataService implements CoreService<void, CoreUsageDataStar
.getTypeRegistry()
.getAllTypes()
.reduce((acc, type) => {
// TODO: Let the registry return `kibana.index` instead of reading
// the config value here.
const index =
savedObjects.getTypeRegistry().getIndex(type.name) || this.kibanaConfig!.index;
const index = type.indexPattern ?? this.kibanaConfig!.index;
return index != null ? acc.add(index) : acc;
}, new Set<string>())
.values()
).map((alias) => {
).map((index) => {
// The _cat/indices API returns the _index_ and doesn't return a way
// to map back from the index to the alias. So we have to make an API
// call for every alias
return elasticsearch.client.asInternalUser.cat
.indices<any[]>({
index: alias,
index,
format: 'JSON',
bytes: 'b',
})
.then(({ body }) => {
const index = body[0];
const stats = body[0];
return {
name: index.index,
alias,
docsCount: index['docs.count'],
docsDeleted: index['docs.deleted'],
storeSizeBytes: index['store.size'],
primaryStoreSizeBytes: index['pri.store.size'],
alias: kibanaOrTaskManagerIndex(index, this.kibanaConfig!.index),
docsCount: stats['docs.count'],
docsDeleted: stats['docs.deleted'],
storeSizeBytes: stats['store.size'],
primaryStoreSizeBytes: stats['pri.store.size'],
};
});
})
Expand Down Expand Up @@ -207,12 +221,6 @@ export class CoreUsageDataService implements CoreService<void, CoreUsageDataStar
heapTotalBytes: this.opsMetrics.process.memory.heap.total_in_bytes,
heapUsedBytes: this.opsMetrics.process.memory.heap.used_in_bytes,
},
os: {
distro: this.opsMetrics.os.distro,
distroRelease: this.opsMetrics.os.distroRelease,
platform: this.opsMetrics.os.platform,
platformRelease: this.opsMetrics.os.platformRelease,
},
},
services: {
savedObjects: soUsageData,
Expand Down
Loading

0 comments on commit 062280e

Please sign in to comment.