Skip to content

Commit

Permalink
Merge branch 'main' into feature/142958
Browse files Browse the repository at this point in the history
  • Loading branch information
dej611 committed Oct 19, 2022
2 parents f9e1bb9 + e363b7c commit bbc0fd2
Show file tree
Hide file tree
Showing 144 changed files with 5,609 additions and 429 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ snapshots.js
/x-pack/plugins/canvas/storybook/build
/x-pack/plugins/reporting/server/export_types/printable_pdf/server/lib/pdf/assets/**
/x-pack/plugins/reporting/server/export_types/printable_pdf_v2/server/lib/pdf/assets/**
/x-pack/plugins/cloud_integrations/cloud_gain_sight/server/assets/**

# package overrides
/packages/kbn-eslint-config
Expand Down
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,7 @@ packages/analytics/shippers/elastic_v3/browser @elastic/kibana-core
packages/analytics/shippers/elastic_v3/common @elastic/kibana-core
packages/analytics/shippers/elastic_v3/server @elastic/kibana-core
packages/analytics/shippers/fullstory @elastic/kibana-core
packages/analytics/shippers/gainsight @elastic/kibana-core
packages/content-management/table_list @elastic/shared-ux
packages/core/analytics/core-analytics-browser @elastic/kibana-core
packages/core/analytics/core-analytics-browser-internal @elastic/kibana-core
Expand Down
5 changes: 5 additions & 0 deletions NOTICE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,11 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Portions of this code are licensed under the following license:
For license information please see https://edge.fullstory.com/s/fs.js.LICENSE.txt

---
Portions of this code are licensed under the following license:
Gainsight PX Agent Wrapper Agent Version: 0.46.0 Installed: 2022-08-25 08:07
https://www.gainsight.com/policy/gainsight-px-license-agreement/

---
This code includes a copy of the `normalize-path`
https://github.com/jonschlinkert/normalize-path/blob/52c3a95ebebc2d98c1ad7606cbafa7e658656899/index.js
Expand Down
4 changes: 4 additions & 0 deletions docs/developer/plugin-list.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,10 @@ The plugin exposes the static DefaultEditorController class to consume.
|Integrates with FullStory in order to provide better product analytics, so we can understand how our users make use of Kibana. This plugin should only run on Elastic Cloud.
|{kib-repo}blob/{branch}/x-pack/plugins/cloud_integrations/cloud_gain_sight/README.md[cloudGainsight]
|Integrates with Gainsight in order to provide better product analytics, so we can understand how our users make use of Kibana. This plugin should only run on Elastic Cloud.
|{kib-repo}blob/{branch}/x-pack/plugins/cloud_integrations/cloud_links/README.md[cloudLinks]
|Adds all the links to the Elastic Cloud console.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const Main = (props: MainProps) => {
const [guidesState, setGuidesState] = useState<GuideState[] | undefined>(undefined);
const [activeGuide, setActiveGuide] = useState<GuideState | undefined>(undefined);

const [selectedGuide, setSelectedGuide] = useState<GuideId | undefined>(undefined);
const [selectedGuide, setSelectedGuide] = useState<GuideId | undefined>('observability');
const [selectedStep, setSelectedStep] = useState<GuideStepIds | undefined>(undefined);

useEffect(() => {
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@
"@kbn/analytics-shippers-elastic-v3-common": "link:bazel-bin/packages/analytics/shippers/elastic_v3/common",
"@kbn/analytics-shippers-elastic-v3-server": "link:bazel-bin/packages/analytics/shippers/elastic_v3/server",
"@kbn/analytics-shippers-fullstory": "link:bazel-bin/packages/analytics/shippers/fullstory",
"@kbn/analytics-shippers-gainsight": "link:bazel-bin/packages/analytics/shippers/gainsight",
"@kbn/apm-config-loader": "link:bazel-bin/packages/kbn-apm-config-loader",
"@kbn/apm-utils": "link:bazel-bin/packages/kbn-apm-utils",
"@kbn/cases-components": "link:bazel-bin/packages/kbn-cases-components",
Expand Down Expand Up @@ -865,6 +866,7 @@
"@types/kbn__analytics-shippers-elastic-v3-common": "link:bazel-bin/packages/analytics/shippers/elastic_v3/common/npm_module_types",
"@types/kbn__analytics-shippers-elastic-v3-server": "link:bazel-bin/packages/analytics/shippers/elastic_v3/server/npm_module_types",
"@types/kbn__analytics-shippers-fullstory": "link:bazel-bin/packages/analytics/shippers/fullstory/npm_module_types",
"@types/kbn__analytics-shippers-gainsight": "link:bazel-bin/packages/analytics/shippers/gainsight/npm_module_types",
"@types/kbn__apm-config-loader": "link:bazel-bin/packages/kbn-apm-config-loader/npm_module_types",
"@types/kbn__apm-synthtrace": "link:bazel-bin/packages/kbn-apm-synthtrace/npm_module_types",
"@types/kbn__apm-utils": "link:bazel-bin/packages/kbn-apm-utils/npm_module_types",
Expand Down
2 changes: 2 additions & 0 deletions packages/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ filegroup(
"//packages/analytics/shippers/elastic_v3/common:build",
"//packages/analytics/shippers/elastic_v3/server:build",
"//packages/analytics/shippers/fullstory:build",
"//packages/analytics/shippers/gainsight:build",
"//packages/content-management/table_list:build",
"//packages/core/analytics/core-analytics-browser:build",
"//packages/core/analytics/core-analytics-browser-internal:build",
Expand Down Expand Up @@ -361,6 +362,7 @@ filegroup(
"//packages/analytics/shippers/elastic_v3/common:build_types",
"//packages/analytics/shippers/elastic_v3/server:build_types",
"//packages/analytics/shippers/fullstory:build_types",
"//packages/analytics/shippers/gainsight:build_types",
"//packages/content-management/table_list:build_types",
"//packages/core/analytics/core-analytics-browser:build_types",
"//packages/core/analytics/core-analytics-browser-internal:build_types",
Expand Down
135 changes: 135 additions & 0 deletions packages/analytics/shippers/gainsight/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
load("@npm//@bazel/typescript:index.bzl", "ts_config")
load("@build_bazel_rules_nodejs//:index.bzl", "js_library")
load("//src/dev/bazel:index.bzl", "jsts_transpiler", "pkg_npm", "pkg_npm_types", "ts_project")

PKG_DIRNAME = "gainsight"
PKG_REQUIRE_NAME = "@kbn/analytics-shippers-gainsight"

SOURCE_FILES = glob(
[
"**/*.ts",
],
exclude = [
"**/*.config.js",
"**/*.mock.*",
"**/*.test.*",
"**/*.stories.*",
"**/__snapshots__/**",
"**/integration_tests/**",
"**/mocks/**",
"**/scripts/**",
"**/storybook/**",
"**/test_fixtures/**",
"**/test_helpers/**",
],
)

SRCS = SOURCE_FILES

filegroup(
name = "srcs",
srcs = SRCS,
)

NPM_MODULE_EXTRA_FILES = [
"package.json",
]

# In this array place runtime dependencies, including other packages and NPM packages
# which must be available for this code to run.
#
# To reference other packages use:
# "//repo/relative/path/to/package"
# eg. "//packages/kbn-utils"
#
# To reference a NPM package use:
# "@npm//name-of-package"
# eg. "@npm//lodash"
RUNTIME_DEPS = [
"@npm//moment",
]

# In this array place dependencies necessary to build the types, which will include the
# :npm_module_types target of other packages and packages from NPM, including @types/*
# packages.
#
# To reference the types for another package use:
# "//repo/relative/path/to/package:npm_module_types"
# eg. "//packages/kbn-utils:npm_module_types"
#
# References to NPM packages work the same as RUNTIME_DEPS
TYPES_DEPS = [
"@npm//@types/node",
"@npm//@types/jest",
"@npm//moment",
"//packages/analytics/client:npm_module_types",
"//packages/kbn-logging-mocks:npm_module_types",
]

jsts_transpiler(
name = "target_node",
srcs = SRCS,
build_pkg_name = package_name(),
)

jsts_transpiler(
name = "target_web",
srcs = SRCS,
build_pkg_name = package_name(),
web = True,
)

ts_config(
name = "tsconfig",
src = "tsconfig.json",
deps = [
"//:tsconfig.base.json",
"//:tsconfig.bazel.json",
],
)

ts_project(
name = "tsc_types",
args = ['--pretty'],
srcs = SRCS,
deps = TYPES_DEPS,
declaration = True,
declaration_map = True,
emit_declaration_only = True,
out_dir = "target_types",
tsconfig = ":tsconfig",
)

js_library(
name = PKG_DIRNAME,
srcs = NPM_MODULE_EXTRA_FILES,
deps = RUNTIME_DEPS + [":target_node", ":target_web"],
package_name = PKG_REQUIRE_NAME,
visibility = ["//visibility:public"],
)

pkg_npm(
name = "npm_module",
deps = [":" + PKG_DIRNAME],
)

filegroup(
name = "build",
srcs = [":npm_module"],
visibility = ["//visibility:public"],
)

pkg_npm_types(
name = "npm_module_types",
srcs = SRCS,
deps = [":tsc_types"],
package_name = PKG_REQUIRE_NAME,
tsconfig = ":tsconfig",
visibility = ["//visibility:public"],
)

filegroup(
name = "build_types",
srcs = [":npm_module_types"],
visibility = ["//visibility:public"],
)
14 changes: 14 additions & 0 deletions packages/analytics/shippers/gainsight/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# @kbn/analytics-shippers-gainsight

gainsight implementation as a shipper for the `@kbn/analytics-client`.

## How to use it

This module is intended to be used **on the browser only**. It does not support server-side events.

```typescript
import { GainsightShipper } from "@kbn/analytics-shippers-gainsight";

analytics.registerShipper(GainsightShipper, { gainsightOrgId: '12345' })
```

10 changes: 10 additions & 0 deletions packages/analytics/shippers/gainsight/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

export { GainsightShipper } from './src/gainsight_shipper';
export type { GainsightSnippetConfig } from './src/load_snippet';
13 changes: 13 additions & 0 deletions packages/analytics/shippers/gainsight/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

module.exports = {
preset: '@kbn/test/jest_node',
rootDir: '../../../../',
roots: ['<rootDir>/packages/analytics/shippers/gainsight'],
};
7 changes: 7 additions & 0 deletions packages/analytics/shippers/gainsight/kibana.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "shared-browser",
"id": "@kbn/analytics-shippers-gainsight",
"owner": "@elastic/kibana-core",
"runtimeDeps": [],
"typeDeps": []
}
9 changes: 9 additions & 0 deletions packages/analytics/shippers/gainsight/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "@kbn/analytics-shippers-gainsight",
"private": true,
"version": "1.0.0",
"browser": "./target_web/index.js",
"main": "./target_node/index.js",
"author": "Kibana Core",
"license": "SSPL-1.0 OR Elastic License 2.0"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import type { GainsightApi } from './types';

export const gainsightApiMock: GainsightApi = jest.fn();
gainsightApiMock.init = true;

jest.doMock('./load_snippet', () => {
return {
loadSnippet: () => gainsightApiMock,
};
});
102 changes: 102 additions & 0 deletions packages/analytics/shippers/gainsight/src/gainsight_shipper.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import { loggerMock } from '@kbn/logging-mocks';
import { gainsightApiMock } from './gainsight_shipper.test.mocks';
import { GainsightShipper } from './gainsight_shipper';

describe('gainsightShipper', () => {
let gainsightShipper: GainsightShipper;

beforeEach(() => {
jest.resetAllMocks();
gainsightShipper = new GainsightShipper(
{
gainsightOrgId: 'test-org-id',
},
{
logger: loggerMock.create(),
sendTo: 'staging',
isDev: true,
}
);
});

describe('extendContext', () => {
describe('identify', () => {
test('calls `identify` when the clusterName is provided', () => {
const userId = 'test-user-id';
const clusterName = '123654';
gainsightShipper.extendContext({ userId, cluster_name: clusterName });
expect(gainsightApiMock).toHaveBeenCalledWith('identify', {
id: clusterName,
userType: 'deployment',
});
});

test('calls `identify` again only if the clusterName changes', () => {
const userId = 'test-user-id';
const clusterName = '123654';
gainsightShipper.extendContext({ userId, cluster_name: clusterName });
expect(gainsightApiMock).toHaveBeenCalledTimes(2);
expect(gainsightApiMock).toHaveBeenCalledWith('identify', {
id: clusterName,
userType: 'deployment',
});
expect(gainsightApiMock).toHaveBeenCalledWith('set', 'globalContext', {
kibanaUserId: userId,
});

gainsightShipper.extendContext({ userId, cluster_name: clusterName });
expect(gainsightApiMock).toHaveBeenCalledTimes(3);

gainsightShipper.extendContext({ userId, cluster_name: `${clusterName}-1` });
expect(gainsightApiMock).toHaveBeenCalledTimes(5); // called again because the user changed
});
});
});

describe('optIn', () => {
test('should call consent true and restart when isOptIn: true', () => {
gainsightShipper.optIn(true);
expect(gainsightApiMock).toHaveBeenCalledWith('config', 'enableTag', true);
});

test('should call consent false and shutdown when isOptIn: false', () => {
gainsightShipper.optIn(false);
expect(gainsightApiMock).toHaveBeenCalledWith('config', 'enableTag', false);
});
});

describe('reportEvents', () => {
test('calls the API once per event in the array with the properties transformed', () => {
gainsightShipper.reportEvents([
{
event_type: 'test-event-1',
timestamp: '2020-01-01T00:00:00.000Z',
properties: { test: 'test-1' },
context: { pageName: 'test-page-1' },
},
{
event_type: 'test-event-2',
timestamp: '2020-01-01T00:00:00.000Z',
properties: { other_property: 'test-2' },
context: { pageName: 'test-page-1' },
},
]);

expect(gainsightApiMock).toHaveBeenCalledTimes(2);
expect(gainsightApiMock).toHaveBeenCalledWith('track', 'test-event-1', {
test: 'test-1',
});
expect(gainsightApiMock).toHaveBeenCalledWith('track', 'test-event-2', {
other_property: 'test-2',
});
});
});
});
Loading

0 comments on commit bbc0fd2

Please sign in to comment.