Skip to content

Commit

Permalink
Merge branch 'opensearch-project:main' into memory-circuit-breaker
Browse files Browse the repository at this point in the history
  • Loading branch information
zuochengding committed Apr 8, 2022
2 parents 4a3851a + db7cb6d commit 1dc085d
Show file tree
Hide file tree
Showing 7 changed files with 157 additions and 33 deletions.
6 changes: 5 additions & 1 deletion config/opensearch_dashboards.yml
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,8 @@

# Set the value of this setting to true to capture region blocked warnings and errors
# for your map rendering services.
# map.showRegionBlockedWarning: false
# map.showRegionBlockedWarning: false

# Set the value of this setting to false to suppress search usage telemetry
# for reducing the load of OpenSearch cluster.
# data.search.usageTelemetry.enabled: false
65 changes: 65 additions & 0 deletions release-notes/opensearch-dashboards.release-notes-1.3.1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
## Version 1.3.1 Release Notes

- **[Branding] Allow for SSL setup failures (#1414)(#1417)**

[Kawika Avilla](mailto:kavilla414@gmail.com)

Setup HTTP Agent in the render portion when it did not need to be
it just needed a one time setup for the life time of the server.

Also if this fails to read the keys then it would fail. But it's
only used for custom branding. We shouldn't failed for custom branding
just rely on default branding.

Issue Resolved:
https://discuss.opendistrocommunity.dev/t/is-opensearch-dashboard-server-certificate-and-key-required-to-be-reloaded-everytime-when-gui-is-accessed/9069/13

* **[CI][build] Use BUILD_NUMBER for building bundles (#1371)(#1407)**

[Kawika Avilla](mailto:kavilla414@gmail.com)

When running a release build for example:

```
yarn build-platform --linux --skip-os-packages --release
```

The build task runs through get_build_number and
checks how many commits you have locally and determines the
build number. From there, and this is the value that
is used to as a cache busting mechanism.

However, in the release build repo
https://github.com/opensearch-project/opensearch-build

When this gets packaged and verified it actually pulls
from the specified branch and only retrieves the HEAD
commit. Thus making the count of commits locally equal
to `1` and get_build_number always return `1` for releases
essentially breaking the cache buster.

The build repo however, sets an env variable of `BUILD_NUMBER`
so if this value is available it will use it instead of commit
count.

The CI runs the unit tests and only gets the latest commit as well
so instead of setting a env build number and basically creating
the same unit test only check this locally.

Issues resolved:

- opensearch-project/opensearch-build#1769
- #1363

* **[Improvement] node healthcheck optimization (#1386)**

[Kawika Avilla](mailto:kavilla414@gmail.com)

Health check when enabled checked the entire cluster to get
the value set from the nodeId. Switching the health check to
query /\_cluster/state/nodes should provide the same data needed
for the health check without transmitting the rest of the
cluster state data over the network.

Issue:
#1354
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ opensearch_dashboards_vars=(
csp.rules
csp.strict
csp.warnLegacyBrowsers
data.search.usageTelemetry.enabled
opensearch.customHeaders
opensearch.hosts
opensearch.logQueries
Expand Down
3 changes: 3 additions & 0 deletions src/plugins/data/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ export const configSchema = schema.object({
enabled: schema.boolean({ defaultValue: false }),
}),
}),
usageTelemetry: schema.object({
enabled: schema.boolean({ defaultValue: false }),
}),
}),
});

Expand Down
40 changes: 40 additions & 0 deletions src/plugins/data/server/search/collectors/usage.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*
* Any modifications Copyright OpenSearch Contributors. See
* GitHub history for details.
*/

import { coreMock } from '../../../../../core/server/mocks';
import { CoreSetup } from '../../../../../core/server';
import { first } from 'rxjs/operators';
import { usageProvider } from '..';
import { ConfigSchema } from '../../../config';

describe('Search usage telemetry', () => {
let mockCoreSetup: MockedKeys<CoreSetup>;
const initializerContext = coreMock.createPluginInitializerContext({
search: { usageTelemetry: { enabled: false } },
});

it('trackSuccess should not throw with disabled usageTelemetry', async () => {
const configObject = await initializerContext.config
.create<ConfigSchema>()
.pipe(first())
.toPromise();
expect(configObject.search.usageTelemetry.enabled).toBe(false);

const searchUsage = usageProvider(mockCoreSetup, initializerContext);
expect(searchUsage.trackSuccess(1)).resolves.not.toThrow();
});

it('trackError should not throw with disabled usageTelemetry', () => {
const searchUsage = usageProvider(mockCoreSetup, initializerContext);
expect(searchUsage.trackError.name).toBe('trackError');
expect(searchUsage.trackError()).resolves.not.toThrow();
});
});
73 changes: 42 additions & 31 deletions src/plugins/data/server/search/collectors/usage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@
* under the License.
*/

import { CoreSetup } from 'opensearch-dashboards/server';
import { CoreSetup, PluginInitializerContext } from 'opensearch-dashboards/server';
import { first } from 'rxjs/operators';
import { Usage } from './register';
import { ConfigSchema } from '../../../config';

const SAVED_OBJECT_ID = 'search-telemetry';

Expand All @@ -38,44 +40,53 @@ export interface SearchUsage {
trackSuccess(duration: number): Promise<void>;
}

export function usageProvider(core: CoreSetup): SearchUsage {
export function usageProvider(
core: CoreSetup,
initializerContext: PluginInitializerContext<ConfigSchema>
): SearchUsage {
const getTracker = (eventType: keyof Usage) => {
return async (duration?: number) => {
const repository = await core
.getStartServices()
.then(([coreStart]) => coreStart.savedObjects.createInternalRepository());
const config = await initializerContext.config
.create<ConfigSchema>()
.pipe(first())
.toPromise();
if (config?.search?.usageTelemetry?.enabled) {
const repository = await core
.getStartServices()
.then(([coreStart]) => coreStart.savedObjects.createInternalRepository());

let attributes: Usage;
let doesSavedObjectExist: boolean = true;
let attributes: Usage;
let doesSavedObjectExist: boolean = true;

try {
const response = await repository.get<Usage>(SAVED_OBJECT_ID, SAVED_OBJECT_ID);
attributes = response.attributes;
} catch (e) {
doesSavedObjectExist = false;
attributes = {
successCount: 0,
errorCount: 0,
averageDuration: 0,
};
}
try {
const response = await repository.get<Usage>(SAVED_OBJECT_ID, SAVED_OBJECT_ID);
attributes = response.attributes;
} catch (e) {
doesSavedObjectExist = false;
attributes = {
successCount: 0,
errorCount: 0,
averageDuration: 0,
};
}

attributes[eventType]++;
attributes[eventType]++;

// Only track the average duration for successful requests
if (eventType === 'successCount') {
attributes.averageDuration =
((duration ?? 0) + (attributes.averageDuration ?? 0)) / (attributes.successCount ?? 1);
}
// Only track the average duration for successful requests
if (eventType === 'successCount') {
attributes.averageDuration =
((duration ?? 0) + (attributes.averageDuration ?? 0)) / (attributes.successCount ?? 1);
}

try {
if (doesSavedObjectExist) {
await repository.update(SAVED_OBJECT_ID, SAVED_OBJECT_ID, attributes);
} else {
await repository.create(SAVED_OBJECT_ID, attributes, { id: SAVED_OBJECT_ID });
try {
if (doesSavedObjectExist) {
await repository.update(SAVED_OBJECT_ID, SAVED_OBJECT_ID, attributes);
} else {
await repository.create(SAVED_OBJECT_ID, attributes, { id: SAVED_OBJECT_ID });
}
} catch (e) {
// Version conflict error, swallow
}
} catch (e) {
// Version conflict error, swallow
}
};
};
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/data/server/search/search_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export class SearchService implements Plugin<ISearchSetup, ISearchStart> {
core: CoreSetup<{}, DataPluginStart>,
{ registerFunction, usageCollection }: SearchServiceSetupDependencies
): ISearchSetup {
const usage = usageCollection ? usageProvider(core) : undefined;
const usage = usageCollection ? usageProvider(core, this.initializerContext) : undefined;

const router = core.http.createRouter();
const routeDependencies = {
Expand Down

0 comments on commit 1dc085d

Please sign in to comment.