Skip to content

Commit

Permalink
[Profiling] Profiling data access plugin (#165198)
Browse files Browse the repository at this point in the history
This is part 1 of a series of PRs to expose the flamegraph to be used by
other plugins.

**The problem**
Currently for plugin-A to show data from plugin-B, it needs to add
dependency on plugin-B. If plugin-B wants to show data from plugin-A, it
also needs to add plugin-A as a dependency, and here is where the
problem happens. In such scenario, we have a cyclic dependency problem.

**The solution**
To solve this problem a new plugin is created, `profiling-data-access`.
This plugin exposes services that consumer plugins can call in other to
have the data they need to show on their end. The `profiling` plugin is
also using this new plugin. For now, only the flamegraph service is
available, The idea is to slowly migrate the data fetching from
profiling to this new plugin in other to facilitate the integration
across plugins.

**Why some many files?**
As I said, only the flamegraph logic was moved to the new plugin, but it
has many files that it needs to properly build the response of the
service call. I moved all these files to the `common` folder inside the
new plugin and adjusted the imports in the profiling plugin.

<img width="1032" alt="Screenshot 2023-08-31 at 09 29 27"
src="https://github.com/elastic/kibana/assets/55978943/287bd28e-b834-45e0-8042-576d1fcff6cd">

---------

Co-authored-by: kibanamachine <[email protected]>
  • Loading branch information
cauemarcondes and kibanamachine authored Sep 1, 2023
1 parent a6d0b78 commit acf8956
Show file tree
Hide file tree
Showing 75 changed files with 499 additions and 697 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,7 @@ packages/kbn-plugin-helpers @elastic/kibana-operations
examples/portable_dashboards_example @elastic/kibana-presentation
examples/preboot_example @elastic/kibana-security @elastic/kibana-core
src/plugins/presentation_util @elastic/kibana-presentation
x-pack/plugins/profiling_data_access @elastic/profiling-ui
x-pack/plugins/profiling @elastic/profiling-ui
x-pack/packages/kbn-random-sampling @elastic/kibana-visualizations
packages/kbn-react-field @elastic/kibana-data-discovery
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 @@ -697,6 +697,10 @@ Elastic.
|Universal Profiling provides fleet-wide, whole-system, continuous profiling with zero instrumentation. Get a comprehensive understanding of what lines of code are consuming compute resources throughout your entire fleet by visualizing your data in Kibana using the flamegraph, stacktraces, and top functions views.
|{kib-repo}blob/{branch}/x-pack/plugins/profiling_data_access[profilingDataAccess]
|WARNING: Missing README.
|{kib-repo}blob/{branch}/x-pack/plugins/remote_clusters/README.md[remoteClusters]
|This plugin helps users manage their remote clusters, which enable cross-cluster search and cross-cluster replication.
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,7 @@
"@kbn/portable-dashboards-example": "link:examples/portable_dashboards_example",
"@kbn/preboot-example-plugin": "link:examples/preboot_example",
"@kbn/presentation-util-plugin": "link:src/plugins/presentation_util",
"@kbn/profiling-data-access-plugin": "link:x-pack/plugins/profiling_data_access",
"@kbn/profiling-plugin": "link:x-pack/plugins/profiling",
"@kbn/random-sampling": "link:x-pack/packages/kbn-random-sampling",
"@kbn/react-field": "link:packages/kbn-react-field",
Expand Down
2 changes: 2 additions & 0 deletions tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -1084,6 +1084,8 @@
"@kbn/preboot-example-plugin/*": ["examples/preboot_example/*"],
"@kbn/presentation-util-plugin": ["src/plugins/presentation_util"],
"@kbn/presentation-util-plugin/*": ["src/plugins/presentation_util/*"],
"@kbn/profiling-data-access-plugin": ["x-pack/plugins/profiling_data_access"],
"@kbn/profiling-data-access-plugin/*": ["x-pack/plugins/profiling_data_access/*"],
"@kbn/profiling-plugin": ["x-pack/plugins/profiling"],
"@kbn/profiling-plugin/*": ["x-pack/plugins/profiling/*"],
"@kbn/random-sampling": ["x-pack/packages/kbn-random-sampling"],
Expand Down
22 changes: 0 additions & 22 deletions x-pack/plugins/profiling/common/base64.ts

This file was deleted.

12 changes: 7 additions & 5 deletions x-pack/plugins/profiling/common/columnar_view_model.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@

import { sum } from 'lodash';

import { createCalleeTree } from './callee';
import { createCalleeTree } from '@kbn/profiling-data-access-plugin/common/callee';
import { createColumnarViewModel } from './columnar_view_model';
import { createBaseFlameGraph, createFlameGraph } from './flamegraph';
import { decodeStackTraceResponse } from './stack_traces';

import { stackTraceFixtures } from './__fixtures__/stacktraces';
import {
createBaseFlameGraph,
createFlameGraph,
} from '@kbn/profiling-data-access-plugin/common/flamegraph';
import { decodeStackTraceResponse } from '@kbn/profiling-data-access-plugin/common/stack_traces';
import { stackTraceFixtures } from '@kbn/profiling-data-access-plugin/common/__fixtures__/stacktraces';

describe('Columnar view model operations', () => {
stackTraceFixtures.forEach(({ response, seconds, upsampledBy }) => {
Expand Down
3 changes: 1 addition & 2 deletions x-pack/plugins/profiling/common/columnar_view_model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
*/

import { ColumnarViewModel } from '@elastic/charts';

import { ElasticFlameGraph } from './flamegraph';
import { ElasticFlameGraph } from '@kbn/profiling-data-access-plugin/common/flamegraph';
import { frameTypeToRGB, rgbToRGBA } from './frame_type_colors';

function normalize(n: number, lower: number, upper: number): number {
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/profiling/common/frame_type_colors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import { FrameType } from './profiling';
import { FrameType } from '@kbn/profiling-data-access-plugin/common/profiling';

/*
* Helper to calculate the color of a given block to be drawn. The desirable outcomes of this are:
Expand Down
6 changes: 2 additions & 4 deletions x-pack/plugins/profiling/common/functions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@
*/

import { sum } from 'lodash';

import { createTopNFunctions } from './functions';
import { decodeStackTraceResponse } from './stack_traces';

import { stackTraceFixtures } from './__fixtures__/stacktraces';
import { decodeStackTraceResponse } from '@kbn/profiling-data-access-plugin/common/stack_traces';
import { stackTraceFixtures } from '@kbn/profiling-data-access-plugin/common/__fixtures__/stacktraces';

describe('TopN function operations', () => {
stackTraceFixtures.forEach(({ response, seconds, upsampledBy }) => {
Expand Down
7 changes: 5 additions & 2 deletions x-pack/plugins/profiling/common/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
*/
import * as t from 'io-ts';
import { sumBy } from 'lodash';
import { createFrameGroupID, FrameGroupID } from './frame_group';
import {
createFrameGroupID,
FrameGroupID,
} from '@kbn/profiling-data-access-plugin/common/frame_group';
import {
createStackFrameMetadata,
emptyExecutable,
Expand All @@ -19,7 +22,7 @@ import {
StackFrameMetadata,
StackTrace,
StackTraceID,
} from './profiling';
} from '@kbn/profiling-data-access-plugin/common/profiling';

interface TopNFunctionAndFrameGroup {
Frame: StackFrameMetadata;
Expand Down
12 changes: 0 additions & 12 deletions x-pack/plugins/profiling/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,6 @@ export function timeRangeFromRequest(request: any): [number, number] {
return [timeFrom, timeTo];
}

// Converts from a Map object to a Record object since Map objects are not
// serializable to JSON by default
export function fromMapToRecord<K extends string, V>(m: Map<K, V>): Record<string, V> {
const output: Record<string, V> = {};

for (const [key, value] of m) {
output[key] = value;
}

return output;
}

export const NOT_AVAILABLE_LABEL = i18n.translate('xpack.profiling.notAvailableLabel', {
defaultMessage: 'N/A',
});
170 changes: 0 additions & 170 deletions x-pack/plugins/profiling/common/run_length_encoding.test.ts

This file was deleted.

Loading

0 comments on commit acf8956

Please sign in to comment.