Skip to content

Commit

Permalink
Merge branch 'main' into elastic#8611
Browse files Browse the repository at this point in the history
  • Loading branch information
alexwizp authored Mar 13, 2024
2 parents 538d0af + d7a8dd4 commit a2b73ab
Show file tree
Hide file tree
Showing 15 changed files with 598 additions and 142 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,7 @@ src/plugins/kibana_usage_collection @elastic/kibana-core
src/plugins/kibana_utils @elastic/appex-sharedux
x-pack/plugins/kubernetes_security @elastic/kibana-cloud-security-posture
packages/kbn-language-documentation-popover @elastic/kibana-visualizations
x-pack/examples/lens_config_builder_example @elastic/kibana-visualizations
packages/kbn-lens-embeddable-utils @elastic/obs-ux-infra_services-team @elastic/kibana-visualizations
packages/kbn-lens-formula-docs @elastic/kibana-visualizations
x-pack/examples/lens_embeddable_inline_editing_example @elastic/kibana-visualizations
Expand Down
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,7 @@
"@kbn/kibana-utils-plugin": "link:src/plugins/kibana_utils",
"@kbn/kubernetes-security-plugin": "link:x-pack/plugins/kubernetes_security",
"@kbn/language-documentation-popover": "link:packages/kbn-language-documentation-popover",
"@kbn/lens-config-builder-example-plugin": "link:x-pack/examples/lens_config_builder_example",
"@kbn/lens-embeddable-utils": "link:packages/kbn-lens-embeddable-utils",
"@kbn/lens-formula-docs": "link:packages/kbn-lens-formula-docs",
"@kbn/lens-inline-editing-example-plugin": "link:x-pack/examples/lens_embeddable_inline_editing_example",
Expand Down Expand Up @@ -929,7 +930,7 @@
"compare-versions": "3.5.1",
"constate": "^3.3.2",
"copy-to-clipboard": "^3.0.8",
"core-js": "^3.34.0",
"core-js": "^3.36.0",
"cronstrue": "^1.51.0",
"css-box-model": "^1.2.1",
"css.escape": "^1.5.1",
Expand Down Expand Up @@ -1528,7 +1529,7 @@
"blob-polyfill": "^7.0.20220408",
"callsites": "^3.1.0",
"chance": "1.0.18",
"chromedriver": "^121.0.0",
"chromedriver": "^122.0.5",
"clean-webpack-plugin": "^3.0.0",
"cli-progress": "^3.12.0",
"cli-table3": "^0.6.1",
Expand Down Expand Up @@ -1578,7 +1579,7 @@
"file-loader": "^4.2.0",
"find-cypress-specs": "^1.41.4",
"form-data": "^4.0.0",
"geckodriver": "^4.3.0",
"geckodriver": "^4.3.3",
"gulp-brotli": "^3.0.0",
"gulp-postcss": "^9.0.1",
"gulp-sourcemaps": "2.6.5",
Expand Down Expand Up @@ -1652,7 +1653,7 @@
"regenerate": "^1.4.0",
"resolve": "^1.22.0",
"rxjs-marbles": "^7.0.1",
"sass-embedded": "^1.70.0",
"sass-embedded": "^1.71.1",
"sass-loader": "^10.5.1",
"selenium-webdriver": "^4.18.1",
"sharp": "0.32.6",
Expand Down Expand Up @@ -1683,7 +1684,7 @@
"val-loader": "^1.1.1",
"vinyl-fs": "^4.0.0",
"watchpack": "^1.6.0",
"web-streams-polyfill": "^3.2.1",
"web-streams-polyfill": "^4.0.0",
"webpack": "^4.41.5",
"webpack-bundle-analyzer": "^4.5.0",
"webpack-cli": "^4.10.0",
Expand Down
106 changes: 106 additions & 0 deletions packages/kbn-profiling-utils/common/profiling.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ import {
FrameSymbolStatus,
FrameType,
getCalleeFunction,
getCalleeLabel,
getCalleeSource,
getFrameSymbolStatus,
getLanguageType,
normalizeFrameType,
StackFrameMetadata,
} from './profiling';

describe('Stack frame metadata operations', () => {
Expand Down Expand Up @@ -136,3 +138,107 @@ describe('getLanguageType', () => {
})
);
});

describe('getCalleeLabel', () => {
it('returns error message for FrameType.Error', () => {
const metadata: StackFrameMetadata = {
FrameID: '1',
FileID: 'file1',
FrameType: FrameType.Error,
Inline: false,
AddressOrLine: 404,
FunctionName: '',
FunctionOffset: 0,
SourceFilename: '',
SourceLine: 0,
ExeFileName: 'app.exe',
};

expect(getCalleeLabel(metadata)).toEqual('Error: unwinding error code #404');
});

it('returns label with inline indicator if Inline is true', () => {
const metadata: StackFrameMetadata = {
FrameID: '2',
FileID: 'file2',
FrameType: FrameType.Native,
Inline: true,
AddressOrLine: 123,
FunctionName: 'someFunction',
FunctionOffset: 0,
SourceFilename: 'path/to/file.ts',
SourceLine: 5,
ExeFileName: 'app.exe',
};

expect(getCalleeLabel(metadata)).toEqual('-> app.exe: someFunction() in file.ts#5');
});

it('returns label without function name if FunctionName is empty', () => {
const metadata: StackFrameMetadata = {
FrameID: '3',
FileID: 'file3',
FrameType: FrameType.Native,
Inline: false,
AddressOrLine: 456,
FunctionName: '',
FunctionOffset: 0,
SourceFilename: 'path/to/file.ts',
SourceLine: 0,
ExeFileName: 'app.exe',
};

expect(getCalleeLabel(metadata)).toEqual('app.exe');
});

it('returns label without line number if SourceLine is 0', () => {
const metadata: StackFrameMetadata = {
FrameID: '4',
FileID: 'file4',
FrameType: FrameType.Native,
Inline: false,
AddressOrLine: 789,
FunctionName: 'someFunction',
FunctionOffset: 0,
SourceFilename: 'path/to/file.ts',
SourceLine: 0,
ExeFileName: 'app.exe',
};

expect(getCalleeLabel(metadata)).toEqual('app.exe: someFunction() in file.ts');
});

it('returns label with function name and line number', () => {
const metadata: StackFrameMetadata = {
FrameID: '5',
FileID: 'file5',
FrameType: FrameType.Native,
Inline: false,
AddressOrLine: 101112,
FunctionName: 'someFunction',
FunctionOffset: 0,
SourceFilename: 'path/to/file.ts',
SourceLine: 10,
ExeFileName: 'app.exe',
};

expect(getCalleeLabel(metadata)).toEqual('app.exe: someFunction() in file.ts#10');
});

it('returns label without function name', () => {
const metadata: StackFrameMetadata = {
FrameID: '5',
FileID: 'file5',
FrameType: FrameType.Native,
Inline: false,
AddressOrLine: 101112,
FunctionName: 'someFunction',
FunctionOffset: 0,
SourceFilename: '',
SourceLine: 10,
ExeFileName: 'app.exe',
};

expect(getCalleeLabel(metadata)).toEqual('app.exe: someFunction()');
});
});
33 changes: 24 additions & 9 deletions packages/kbn-profiling-utils/common/profiling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,9 @@ function checkIfStringHasParentheses(s: string) {
}

function getFunctionName(metadata: StackFrameMetadata) {
return metadata.FunctionName !== '' && !checkIfStringHasParentheses(metadata.FunctionName)
? `${metadata.FunctionName}()`
: metadata.FunctionName;
return checkIfStringHasParentheses(metadata.FunctionName)
? metadata.FunctionName
: `${metadata.FunctionName}()`;
}

function getExeFileName(metadata: StackFrameMetadata) {
Expand All @@ -241,17 +241,32 @@ function getExeFileName(metadata: StackFrameMetadata) {
* @returns string
*/
export function getCalleeLabel(metadata: StackFrameMetadata) {
const inlineLabel = metadata.Inline ? '-> ' : '';
if (metadata.FrameType === FrameType.Error) {
return `Error: unwinding error code #${metadata.AddressOrLine.toString()}`;
} else if (metadata.FunctionName !== '') {
const sourceFilename = metadata.SourceFilename;
const sourceURL = sourceFilename ? sourceFilename.split('/').pop() : '';
}

const inlineLabel = metadata.Inline ? '-> ' : '';

if (metadata.FunctionName === '') {
return `${inlineLabel}${getExeFileName(metadata)}`;
}

const sourceFilename = metadata.SourceFilename;
const sourceURL = sourceFilename ? sourceFilename.split('/').pop() : '';

if (!sourceURL) {
return `${inlineLabel}${getExeFileName(metadata)}: ${getFunctionName(metadata)}`;
}

if (metadata.SourceLine === 0) {
return `${inlineLabel}${getExeFileName(metadata)}: ${getFunctionName(
metadata
)} in ${sourceURL}#${metadata.SourceLine}`;
)} in ${sourceURL}`;
}
return `${inlineLabel}${getExeFileName(metadata)}`;

return `${inlineLabel}${getExeFileName(metadata)}: ${getFunctionName(metadata)} in ${sourceURL}#${
metadata.SourceLine
}`;
}
/**
* Get callee function name
Expand Down
5 changes: 4 additions & 1 deletion packages/kbn-test/src/jest/setup/setup_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@

import 'jest-styled-components';
import '@testing-library/jest-dom';
import 'web-streams-polyfill/es6'; // ReadableStream polyfill

// uses subpath exports
// eslint-disable-next-line @kbn/imports/no_unresolvable_imports
import 'web-streams-polyfill/polyfill'; // ReadableStream polyfill

/**
* Removed in Jest 27/jsdom, used in some transitive dependencies
Expand Down
2 changes: 2 additions & 0 deletions tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -970,6 +970,8 @@
"@kbn/kubernetes-security-plugin/*": ["x-pack/plugins/kubernetes_security/*"],
"@kbn/language-documentation-popover": ["packages/kbn-language-documentation-popover"],
"@kbn/language-documentation-popover/*": ["packages/kbn-language-documentation-popover/*"],
"@kbn/lens-config-builder-example-plugin": ["x-pack/examples/lens_config_builder_example"],
"@kbn/lens-config-builder-example-plugin/*": ["x-pack/examples/lens_config_builder_example/*"],
"@kbn/lens-embeddable-utils": ["packages/kbn-lens-embeddable-utils"],
"@kbn/lens-embeddable-utils/*": ["packages/kbn-lens-embeddable-utils/*"],
"@kbn/lens-formula-docs": ["packages/kbn-lens-formula-docs"],
Expand Down
5 changes: 5 additions & 0 deletions x-pack/examples/lens_config_builder_example/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"rules": {
"@typescript-eslint/consistent-type-definitions": 0
}
}
7 changes: 7 additions & 0 deletions x-pack/examples/lens_config_builder_example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Lens Config Builder examples

To run this example plugin, use the command `yarn start --run-examples`.

This example shows how to embed Lens into other applications. Using the `EmbeddableComponent` of the `lens` start plugin,
you can pass in a valid Lens configuration which will get rendered the same way Lens dashboard panels work. Updating the
configuration will reload the embedded visualization.
19 changes: 19 additions & 0 deletions x-pack/examples/lens_config_builder_example/kibana.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"type": "plugin",
"id": "@kbn/lens-config-builder-example-plugin",
"owner": "@elastic/kibana-visualizations",
"plugin": {
"id": "lensConfigBuilderExample",
"server": false,
"browser": true,
"configPath": [
"lens_config_builder_example"
],
"requiredPlugins": [
"lens",
"data",
"embeddable",
"developerExamples"
]
}
}
Loading

0 comments on commit a2b73ab

Please sign in to comment.