From 741297eb12cfb20ff294ccc6a8bdf050249b7a47 Mon Sep 17 00:00:00 2001 From: nofar9792 Date: Sun, 30 Jan 2022 13:11:39 +0200 Subject: [PATCH 1/4] Time frame Signed-off-by: nofar9792 --- .../__snapshots__/index.test.js.snap | 3 ++ .../__snapshots__/serviceGraph.test.js.snap | 30 +++++++++++++++++++ .../components/Monitor/ServicesView/index.tsx | 3 ++ .../Monitor/ServicesView/serviceGraph.test.js | 10 ++++++- .../Monitor/ServicesView/serviceGraph.tsx | 5 ++++ 5 files changed, 50 insertions(+), 1 deletion(-) diff --git a/packages/jaeger-ui/src/components/Monitor/ServicesView/__snapshots__/index.test.js.snap b/packages/jaeger-ui/src/components/Monitor/ServicesView/__snapshots__/index.test.js.snap index 0430e24544..6b84827784 100644 --- a/packages/jaeger-ui/src/components/Monitor/ServicesView/__snapshots__/index.test.js.snap +++ b/packages/jaeger-ui/src/components/Monitor/ServicesView/__snapshots__/index.test.js.snap @@ -171,6 +171,7 @@ exports[` ATM snapshot test 1`] = ` ] } name="Latency, ms" + selectedTimeFrame={3600000} showHorizontalLines={true} showLegend={true} width={300} @@ -202,6 +203,7 @@ exports[` ATM snapshot test 1`] = ` } } name="Error rate, %" + selectedTimeFrame={3600000} width={300} yDomain={ Array [ @@ -237,6 +239,7 @@ exports[` ATM snapshot test 1`] = ` } } name="Request rate, req/s" + selectedTimeFrame={3600000} showHorizontalLines={true} width={300} /> diff --git a/packages/jaeger-ui/src/components/Monitor/ServicesView/__snapshots__/serviceGraph.test.js.snap b/packages/jaeger-ui/src/components/Monitor/ServicesView/__snapshots__/serviceGraph.test.js.snap index 567b2a6932..e84a35c1d0 100644 --- a/packages/jaeger-ui/src/components/Monitor/ServicesView/__snapshots__/serviceGraph.test.js.snap +++ b/packages/jaeger-ui/src/components/Monitor/ServicesView/__snapshots__/serviceGraph.test.js.snap @@ -80,6 +80,12 @@ exports[` Base graph should be displayed 1`] = ` } onMouseLeave={[Function]} width={300} + xDomain={ + Array [ + 1466420890000, + 1466424490000, + ] + } > Base graph with custom color should be displayed 1`] = ` } onMouseLeave={[Function]} width={300} + xDomain={ + Array [ + 1466420890000, + 1466424490000, + ] + } > Base graph with horizontal lines should be displayed 1`] } onMouseLeave={[Function]} width={300} + xDomain={ + Array [ + 1466420890000, + 1466424490000, + ] + } > Base graph with legends should be displayed 1`] = ` } onMouseLeave={[Function]} width={300} + xDomain={ + Array [ + 1466420890000, + 1466424490000, + ] + } > Crosshair map test 1`] = ` } onMouseLeave={[Function]} width={300} + xDomain={ + Array [ + 1466420890000, + 1466424490000, + ] + } > @@ -264,6 +265,7 @@ export class MonitorATMServicesViewImpl extends React.PureComponent @@ -277,6 +279,7 @@ export class MonitorATMServicesViewImpl extends React.PureComponent diff --git a/packages/jaeger-ui/src/components/Monitor/ServicesView/serviceGraph.test.js b/packages/jaeger-ui/src/components/Monitor/ServicesView/serviceGraph.test.js index 25bcc51807..12e888d87d 100644 --- a/packages/jaeger-ui/src/components/Monitor/ServicesView/serviceGraph.test.js +++ b/packages/jaeger-ui/src/components/Monitor/ServicesView/serviceGraph.test.js @@ -25,11 +25,19 @@ const props = { loading: true, marginClassName: '', crosshairValues: [], + selectedTimeFrame: 3600000, }; describe('', () => { let wrapper; - + let dateSpy; + beforeAll(() => { + const mockDate = new Date(1466424490000); + dateSpy = jest.spyOn(global, 'Date').mockImplementation(() => mockDate); + }); + afterAll(() => { + dateSpy.mockRestore(); + }); beforeEach(() => { wrapper = shallow(); }); diff --git a/packages/jaeger-ui/src/components/Monitor/ServicesView/serviceGraph.tsx b/packages/jaeger-ui/src/components/Monitor/ServicesView/serviceGraph.tsx index 0e6d03ba1a..a722f64458 100644 --- a/packages/jaeger-ui/src/components/Monitor/ServicesView/serviceGraph.tsx +++ b/packages/jaeger-ui/src/components/Monitor/ServicesView/serviceGraph.tsx @@ -41,6 +41,7 @@ type TProps = { yDomain?: number[]; color?: string; marginClassName?: string; + selectedTimeFrame: number; }; type TCrossHairValues = { @@ -145,10 +146,13 @@ export class ServiceGraphImpl extends React.PureComponent { marginClassName, name, error, + selectedTimeFrame, } = this.props; let GraphComponent = this.generatePlaceholder(); const noDataComponent = this.generatePlaceholder('No Data'); const apiErrorComponent = this.generatePlaceholder('Couldn’t fetch data'); + const currentTime = new Date().getTime(); + const xDomain = [currentTime - selectedTimeFrame, currentTime]; const Plot = ( { onMouseLeave={() => this.setState({ crosshairValues: [] })} width={width} height={this.height - 74} + xDomain={xDomain} yDomain={yDomain} > {showHorizontalLines ? : null} From f739027f83223e02166cf7e91aacc0c82a6bca77 Mon Sep 17 00:00:00 2001 From: nofar9792 Date: Mon, 14 Feb 2022 14:33:04 +0200 Subject: [PATCH 2/4] Fix shifting graph Signed-off-by: nofar9792 --- .../__snapshots__/index.test.js.snap | 25 ++++++++++++---- .../__snapshots__/serviceGraph.test.js.snap | 30 ------------------- .../Monitor/ServicesView/index.test.js | 5 ++++ .../components/Monitor/ServicesView/index.tsx | 8 +++-- .../Monitor/ServicesView/serviceGraph.test.js | 10 +------ .../Monitor/ServicesView/serviceGraph.tsx | 6 ++-- 6 files changed, 33 insertions(+), 51 deletions(-) diff --git a/packages/jaeger-ui/src/components/Monitor/ServicesView/__snapshots__/index.test.js.snap b/packages/jaeger-ui/src/components/Monitor/ServicesView/__snapshots__/index.test.js.snap index 6b84827784..93ffb71867 100644 --- a/packages/jaeger-ui/src/components/Monitor/ServicesView/__snapshots__/index.test.js.snap +++ b/packages/jaeger-ui/src/components/Monitor/ServicesView/__snapshots__/index.test.js.snap @@ -55,7 +55,7 @@ exports[` ATM snapshot test 1`] = ` " metrics in selected timeframe. View all traces @@ -171,10 +171,15 @@ exports[` ATM snapshot test 1`] = ` ] } name="Latency, ms" - selectedTimeFrame={3600000} showHorizontalLines={true} showLegend={true} width={300} + xDomain={ + Array [ + 1466420890000, + 1466424490000, + ] + } /> ATM snapshot test 1`] = ` } } name="Error rate, %" - selectedTimeFrame={3600000} width={300} + xDomain={ + Array [ + 1466420890000, + 1466424490000, + ] + } yDomain={ Array [ 0, @@ -239,9 +249,14 @@ exports[` ATM snapshot test 1`] = ` } } name="Request rate, req/s" - selectedTimeFrame={3600000} showHorizontalLines={true} width={300} + xDomain={ + Array [ + 1466420890000, + 1466424490000, + ] + } /> @@ -338,7 +353,7 @@ exports[` ATM snapshot test 1`] = ` }, ] } - endTime={1487076708000} + endTime={1466424490000} error={ Object { "opsCalls": null, diff --git a/packages/jaeger-ui/src/components/Monitor/ServicesView/__snapshots__/serviceGraph.test.js.snap b/packages/jaeger-ui/src/components/Monitor/ServicesView/__snapshots__/serviceGraph.test.js.snap index e84a35c1d0..567b2a6932 100644 --- a/packages/jaeger-ui/src/components/Monitor/ServicesView/__snapshots__/serviceGraph.test.js.snap +++ b/packages/jaeger-ui/src/components/Monitor/ServicesView/__snapshots__/serviceGraph.test.js.snap @@ -80,12 +80,6 @@ exports[` Base graph should be displayed 1`] = ` } onMouseLeave={[Function]} width={300} - xDomain={ - Array [ - 1466420890000, - 1466424490000, - ] - } > Base graph with custom color should be displayed 1`] = ` } onMouseLeave={[Function]} width={300} - xDomain={ - Array [ - 1466420890000, - 1466424490000, - ] - } > Base graph with horizontal lines should be displayed 1`] } onMouseLeave={[Function]} width={300} - xDomain={ - Array [ - 1466420890000, - 1466424490000, - ] - } > Base graph with legends should be displayed 1`] = ` } onMouseLeave={[Function]} width={300} - xDomain={ - Array [ - 1466420890000, - 1466424490000, - ] - } > Crosshair map test 1`] = ` } onMouseLeave={[Function]} width={300} - xDomain={ - Array [ - 1466420890000, - 1466424490000, - ] - } > ', () => { const mockFetchServices = jest.fn(); const mockFetchAllServiceMetrics = jest.fn(); const mockFetchAggregatedServiceMetrics = jest.fn(); + beforeAll(() => { + Date.now = jest.fn(() => 1466424490000); + }); beforeEach(() => { wrapper = shallow( @@ -54,6 +57,8 @@ describe('', () => { afterEach(() => { wrapper = null; + // dateSpy.mockRestore(); + jest.clearAllMocks(); }); diff --git a/packages/jaeger-ui/src/components/Monitor/ServicesView/index.tsx b/packages/jaeger-ui/src/components/Monitor/ServicesView/index.tsx index 2830f47188..0e466f4a61 100644 --- a/packages/jaeger-ui/src/components/Monitor/ServicesView/index.tsx +++ b/packages/jaeger-ui/src/components/Monitor/ServicesView/index.tsx @@ -171,6 +171,8 @@ export class MonitorATMServicesViewImpl extends React.PureComponent; @@ -251,7 +253,7 @@ export class MonitorATMServicesViewImpl extends React.PureComponent @@ -265,7 +267,7 @@ export class MonitorATMServicesViewImpl extends React.PureComponent @@ -279,7 +281,7 @@ export class MonitorATMServicesViewImpl extends React.PureComponent diff --git a/packages/jaeger-ui/src/components/Monitor/ServicesView/serviceGraph.test.js b/packages/jaeger-ui/src/components/Monitor/ServicesView/serviceGraph.test.js index 12e888d87d..25bcc51807 100644 --- a/packages/jaeger-ui/src/components/Monitor/ServicesView/serviceGraph.test.js +++ b/packages/jaeger-ui/src/components/Monitor/ServicesView/serviceGraph.test.js @@ -25,19 +25,11 @@ const props = { loading: true, marginClassName: '', crosshairValues: [], - selectedTimeFrame: 3600000, }; describe('', () => { let wrapper; - let dateSpy; - beforeAll(() => { - const mockDate = new Date(1466424490000); - dateSpy = jest.spyOn(global, 'Date').mockImplementation(() => mockDate); - }); - afterAll(() => { - dateSpy.mockRestore(); - }); + beforeEach(() => { wrapper = shallow(); }); diff --git a/packages/jaeger-ui/src/components/Monitor/ServicesView/serviceGraph.tsx b/packages/jaeger-ui/src/components/Monitor/ServicesView/serviceGraph.tsx index a722f64458..08c4ab01ed 100644 --- a/packages/jaeger-ui/src/components/Monitor/ServicesView/serviceGraph.tsx +++ b/packages/jaeger-ui/src/components/Monitor/ServicesView/serviceGraph.tsx @@ -41,7 +41,7 @@ type TProps = { yDomain?: number[]; color?: string; marginClassName?: string; - selectedTimeFrame: number; + xDomain: number[]; }; type TCrossHairValues = { @@ -146,13 +146,11 @@ export class ServiceGraphImpl extends React.PureComponent { marginClassName, name, error, - selectedTimeFrame, + xDomain, } = this.props; let GraphComponent = this.generatePlaceholder(); const noDataComponent = this.generatePlaceholder('No Data'); const apiErrorComponent = this.generatePlaceholder('Couldn’t fetch data'); - const currentTime = new Date().getTime(); - const xDomain = [currentTime - selectedTimeFrame, currentTime]; const Plot = ( Date: Tue, 15 Feb 2022 17:31:23 +0200 Subject: [PATCH 3/4] Remove comment Signed-off-by: nofar9792 --- .../jaeger-ui/src/components/Monitor/ServicesView/index.test.js | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/jaeger-ui/src/components/Monitor/ServicesView/index.test.js b/packages/jaeger-ui/src/components/Monitor/ServicesView/index.test.js index 1866bc9180..3434f6d1ba 100644 --- a/packages/jaeger-ui/src/components/Monitor/ServicesView/index.test.js +++ b/packages/jaeger-ui/src/components/Monitor/ServicesView/index.test.js @@ -57,7 +57,6 @@ describe('', () => { afterEach(() => { wrapper = null; - // dateSpy.mockRestore(); jest.clearAllMocks(); }); From 4f54f1d770e4287ef6cd07411290f74628e7c53e Mon Sep 17 00:00:00 2001 From: nofar9792 Date: Sun, 20 Feb 2022 18:24:31 +0200 Subject: [PATCH 4/4] Calc domain in ctor Signed-off-by: nofar9792 --- .../src/components/Monitor/ServicesView/index.tsx | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/jaeger-ui/src/components/Monitor/ServicesView/index.tsx b/packages/jaeger-ui/src/components/Monitor/ServicesView/index.tsx index 9c0410a604..ee87b2b86c 100644 --- a/packages/jaeger-ui/src/components/Monitor/ServicesView/index.tsx +++ b/packages/jaeger-ui/src/components/Monitor/ServicesView/index.tsx @@ -89,6 +89,7 @@ export const getLoopbackInterval = (interval: number) => { // export for tests export class MonitorATMServicesViewImpl extends React.PureComponent { graphDivWrapper: React.RefObject; + graphXDomain: number[]; serviceSelectorValue: string = ''; endTime: number = Date.now(); state = { @@ -100,6 +101,9 @@ export class MonitorATMServicesViewImpl extends React.PureComponent; @@ -253,7 +255,7 @@ export class MonitorATMServicesViewImpl extends React.PureComponent @@ -267,7 +269,7 @@ export class MonitorATMServicesViewImpl extends React.PureComponent @@ -281,7 +283,7 @@ export class MonitorATMServicesViewImpl extends React.PureComponent