Skip to content

Commit

Permalink
chore: added convertJaegerTraceToProfile test, basic UI test, snapshot
Browse files Browse the repository at this point in the history
Signed-off-by: pavelpashkovsky <pavelpashkovsky@gmail.com>
  • Loading branch information
pavelpashkovsky committed Aug 10, 2022
1 parent 821cfa3 commit cef24cc
Show file tree
Hide file tree
Showing 6 changed files with 926 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/jaeger-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
},
"dependencies": {
"@jaegertracing/plexus": "0.2.0",
"@pyroscope/flamegraph": "0.17.2",
"@pyroscope/flamegraph": "0.18.4-1379-557f0b4.0",
"@types/classnames": "^2.2.7",
"@types/deep-freeze": "^0.1.1",
"@types/history": "^4.7.2",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`<TraceFlamegraph /> renders as expected 1`] = `
<div
className="Flamegraph-wrapper"
>
<dg
colorMode="light"
profile={
Object {
"flamebearer": Object {
"levels": Array [
Array [
0,
1181596,
0,
0,
],
Array [
0,
1181596,
213262,
1,
],
Array [
0,
968334,
1268,
2,
],
Array [
0,
967066,
733,
3,
],
Array [
0,
966333,
966333,
4,
],
],
"maxSelf": 0,
"names": Array [
"total",
"load-generator: OrderVehicle",
"load-generator: HTTP GET",
"ride-sharing-app: BikeHandler",
"ride-sharing-app: FindNearestVehicle",
],
"numTicks": 1181596,
},
"metadata": Object {
"format": "single",
"sampleRate": 1000000,
"spyName": "tracing",
"units": "trace_samples",
},
"version": 1,
}
}
/>
</div>
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// Copyright (c) 2022 The Jaeger Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import React from 'react';
import { shallow } from 'enzyme';
import { convertJaegerTraceToProfile } from '@pyroscope/flamegraph';

import TraceFlamegraph from './index';

const testTrace = require('./testTrace.json');

const profile = convertJaegerTraceToProfile(testTrace.data);

describe('convertJaegerTraceToProfile', () => {
it('returns correct profile format', () => {
expect(profile.version).toBe(1);

expect(Array.isArray(profile.flamebearer.levels)).toBe(true);
expect(profile.flamebearer.levels[0].every(el => typeof el === 'number')).toBe(true);
expect(Array.isArray(profile.flamebearer.names)).toBe(true);
expect(profile.flamebearer.names.every(el => typeof el === 'string')).toBe(true);
expect(typeof profile.flamebearer.numTicks).toBe('number');

expect(typeof profile.metadata.format).toBe('string');
expect(typeof profile.metadata.sampleRate).toBe('number');
expect(typeof profile.metadata.spyName).toBe('string');
expect(typeof profile.metadata.units).toBe('string');
});
});

describe('<TraceFlamegraph />', () => {
let wrapper;

beforeEach(() => {
const props = { trace: testTrace };
wrapper = shallow(<TraceFlamegraph {...props} />);
});

it('renders as expected', () => {
expect(wrapper).toMatchSnapshot();
});

it('does not explode', () => {
expect(wrapper).toBeDefined();
expect(wrapper.find('.Flamegraph-wrapper').length).toBe(1);
});

it('renders profile table and flamegraph', () => {
expect(wrapper).toBeDefined();
expect(wrapper.html().includes('flamegraph-table')).toBe(true);
expect(wrapper.html().includes('flamegraph-view')).toBe(true);
});

it('may show no profile', () => {
const props = {};
wrapper = shallow(<TraceFlamegraph {...props} />);
expect(wrapper).toBeDefined();
expect(wrapper.html().includes('no-profiling-data')).toBe(true);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import '@pyroscope/flamegraph/dist/index.css';
import './index.css';

const TraceFlamegraph = ({ trace }: any) => {
const convertedProfile = convertJaegerTraceToProfile(trace.data);
const convertedProfile = trace && trace.data ? convertJaegerTraceToProfile(trace.data) : null;

return (
<div className="Flamegraph-wrapper">
Expand Down
Loading

0 comments on commit cef24cc

Please sign in to comment.