Skip to content

Commit

Permalink
Polish generated docs
Browse files Browse the repository at this point in the history
  • Loading branch information
rudolf committed Nov 30, 2020
1 parent d268882 commit 308a098
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

## SavedObjectsIncrementCounterOptions.initialize property

Sets all the counter fields to 0 if they don't already exist
(default=false) If true, sets all the counter fields to 0 if they don't already exist. Existing fields will be left as-is and won't be incremented.

<b>Signature:</b>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export interface SavedObjectsIncrementCounterOptions extends SavedObjectsBaseOpt
| Property | Type | Description |
| --- | --- | --- |
| [initialize](./kibana-plugin-core-server.savedobjectsincrementcounteroptions.initialize.md) | <code>boolean</code> | Sets all the counter fields to 0 if they don't already exist |
| [migrationVersion](./kibana-plugin-core-server.savedobjectsincrementcounteroptions.migrationversion.md) | <code>SavedObjectsMigrationVersion</code> | |
| [refresh](./kibana-plugin-core-server.savedobjectsincrementcounteroptions.refresh.md) | <code>MutatingOperationRefreshSetting</code> | The Elasticsearch Refresh setting for this operation |
| [initialize](./kibana-plugin-core-server.savedobjectsincrementcounteroptions.initialize.md) | <code>boolean</code> | (default=false) If true, sets all the counter fields to 0 if they don't already exist. Existing fields will be left as-is and won't be incremented. |
| [migrationVersion](./kibana-plugin-core-server.savedobjectsincrementcounteroptions.migrationversion.md) | <code>SavedObjectsMigrationVersion</code> | [SavedObjectsMigrationVersion](./kibana-plugin-core-server.savedobjectsmigrationversion.md) |
| [refresh](./kibana-plugin-core-server.savedobjectsincrementcounteroptions.refresh.md) | <code>MutatingOperationRefreshSetting</code> | (default='wait\_for') The Elasticsearch refresh setting for this operation. See [MutatingOperationRefreshSetting](./kibana-plugin-core-server.mutatingoperationrefreshsetting.md) |
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

## SavedObjectsIncrementCounterOptions.migrationVersion property

[SavedObjectsMigrationVersion](./kibana-plugin-core-server.savedobjectsmigrationversion.md)

<b>Signature:</b>

```typescript
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

## SavedObjectsIncrementCounterOptions.refresh property

The Elasticsearch Refresh setting for this operation
(default='wait\_for') The Elasticsearch refresh setting for this operation. See [MutatingOperationRefreshSetting](./kibana-plugin-core-server.mutatingoperationrefreshsetting.md)

<b>Signature:</b>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,40 @@ incrementCounter(type: string, id: string, counterFieldNames: string[], options?

| Parameter | Type | Description |
| --- | --- | --- |
| type | <code>string</code> | |
| id | <code>string</code> | |
| counterFieldNames | <code>string[]</code> | |
| options | <code>SavedObjectsIncrementCounterOptions</code> | |
| type | <code>string</code> | The type of saved object whose fields should be incremented |
| id | <code>string</code> | The id of the document whose fields should be incremented |
| counterFieldNames | <code>string[]</code> | An array of field names to increment |
| options | <code>SavedObjectsIncrementCounterOptions</code> | [SavedObjectsIncrementCounterOptions](./kibana-plugin-core-server.savedobjectsincrementcounteroptions.md) |

<b>Returns:</b>

`Promise<SavedObject>`

{<!-- -->promise<!-- -->}
The saved object after the specified fields were incremented

## Remarks

\* When supplying a field name like `stats.api.counter` the field name will be used as-is to create a document like: `{attributes: {'stats.api.counter': 1}}` It will not create a nested structure like: `{attributes: {stats: {api: {counter: 1}}}}` When using incrementCounter for collecting usage data, you need to ensure that usage collection happens on a best-effort basis and doesn't negatively affect your plugin or users. See https://github.com/elastic/kibana/blob/master/src/plugins/usage\_collection/README.md\#tracking-interactions-with-incrementcounter)
When supplying a field name like `stats.api.counter` the field name will be used as-is to create a document like: `{attributes: {'stats.api.counter': 1}}` It will not create a nested structure like: `{attributes: {stats: {api: {counter: 1}}}}`

When using incrementCounter for collecting usage data, you need to ensure that usage collection happens on a best-effort basis and doesn't negatively affect your plugin or users. See https://github.com/elastic/kibana/blob/master/src/plugins/usage\_collection/README.md\#tracking-interactions-with-incrementcounter)

## Example


```ts
const repository = coreStart.savedObjects.createInternalRepository();

// Initialize all fields to 0
repository
.incrementCounter('dashboard_counter_type', 'counter_id', [
'stats.apiCalls',
'stats.sampleDataInstalled',
], {initialize: true});

// Increment the apiCalls field counter
repository
.incrementCounter('dashboard_counter_type', 'counter_id', [
'stats.apiCalls',
])

```
Expand Down
32 changes: 23 additions & 9 deletions src/core/server/saved_objects/service/lib/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,17 @@ export interface SavedObjectsRepositoryOptions {
* @public
*/
export interface SavedObjectsIncrementCounterOptions extends SavedObjectsBaseOptions {
/** Sets all the counter fields to 0 if they don't already exist */
/**
* (default=false) If true, sets all the counter fields to 0 if they don't
* already exist. Existing fields will be left as-is and won't be incremented.
*/
initialize?: boolean;
/** {@link SavedObjectsMigrationVersion} */
migrationVersion?: SavedObjectsMigrationVersion;
/** The Elasticsearch Refresh setting for this operation */
/**
* (default='wait_for') The Elasticsearch refresh setting for this
* operation. See {@link MutatingOperationRefreshSetting}
*/
refresh?: MutatingOperationRefreshSetting;
}

Expand Down Expand Up @@ -1521,11 +1528,12 @@ export class SavedObjectsRepository {
* if one doesn't exist for the given id.
*
* @remarks
* * When supplying a field name like `stats.api.counter` the field name will
* When supplying a field name like `stats.api.counter` the field name will
* be used as-is to create a document like:
* `{attributes: {'stats.api.counter': 1}}`
* It will not create a nested structure like:
* `{attributes: {stats: {api: {counter: 1}}}}`
*
* When using incrementCounter for collecting usage data, you need to ensure
* that usage collection happens on a best-effort basis and doesn't
* negatively affect your plugin or users. See https://github.com/elastic/kibana/blob/master/src/plugins/usage_collection/README.md#tracking-interactions-with-incrementcounter)
Expand All @@ -1534,19 +1542,25 @@ export class SavedObjectsRepository {
* ```ts
* const repository = coreStart.savedObjects.createInternalRepository();
*
* // Initialize all fields to 0
* repository
* .incrementCounter('dashboard_counter_type', 'counter_id', [
* 'stats.apiCalls',
* 'stats.sampleDataInstalled',
* ], {initialize: true});
*
* // Increment the apiCalls field counter
* repository
* .incrementCounter('dashboard_counter_type', 'counter_id', [
* 'stats.apiCalls',
* ])
* ```
*
* @param {string} type
* @param {string} id
* @param {string} counterFieldNames
* @param {object} [options={}]
* @property {object} [options.migrationVersion=undefined]
* @returns {promise}
* @param type - The type of saved object whose fields should be incremented
* @param id - The id of the document whose fields should be incremented
* @param counterFieldNames - An array of field names to increment
* @param options - {@link SavedObjectsIncrementCounterOptions}
* @returns The saved object after the specified fields were incremented
*/
async incrementCounter(
type: string,
Expand Down

0 comments on commit 308a098

Please sign in to comment.