This repository has been archived by the owner on Apr 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
290 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import * as React from 'react'; | ||
import { ToolbarDropdown } from '../../components/ToolbarDropdown/ToolbarDropdown'; | ||
import { Toolbar, FormGroup, Checkbox } from 'patternfly-react'; | ||
import ServiceId from '../../types/ServiceId'; | ||
import { HistoryManager, URLParams } from '../../app/History'; | ||
import { config } from '../../config'; | ||
import history from '../../app/History'; | ||
import ServiceTracesJaeger from './ServiceTraces/ServiceTracesJaeger'; | ||
|
||
type ServiceTraceState = { | ||
duration: number; | ||
onlyErrors: boolean; | ||
}; | ||
|
||
class ServiceTraces extends React.Component<ServiceId, ServiceTraceState> { | ||
static Durations = config().toolbar.intervalDuration; | ||
static DefaultDuration = config().toolbar.defaultDuration; | ||
|
||
constructor(props: ServiceId) { | ||
super(props); | ||
const urlParams = new URLSearchParams(history.location.search); | ||
this.state = { | ||
duration: this.initialDuration(urlParams), | ||
onlyErrors: true | ||
}; | ||
} | ||
|
||
initialDuration = (urlParams: URLSearchParams): number => { | ||
let d = urlParams.get(URLParams.DURATION); | ||
if (d !== null) { | ||
sessionStorage.setItem(URLParams.DURATION, d); | ||
return Number(d); | ||
} | ||
d = sessionStorage.getItem(URLParams.DURATION); | ||
return d !== null ? Number(d) : ServiceTraces.DefaultDuration; | ||
}; | ||
|
||
onDurationChange = (key: number) => { | ||
sessionStorage.setItem(URLParams.DURATION, String(key)); | ||
HistoryManager.setParam(URLParams.DURATION, String(key)); | ||
this.setState({ duration: key }); | ||
}; | ||
|
||
onErrorsChange = evt => { | ||
this.setState({ onlyErrors: evt.target.checked }); | ||
}; | ||
|
||
render() { | ||
return ( | ||
<div> | ||
<Toolbar> | ||
<FormGroup> | ||
<ToolbarDropdown | ||
id={'traces_filter_interval_duration'} | ||
disabled={false} | ||
handleSelect={this.onDurationChange} | ||
nameDropdown={'Displaying'} | ||
initialValue={this.state.duration} | ||
initialLabel={String(ServiceTraces.Durations[this.state.duration])} | ||
options={ServiceTraces.Durations} | ||
/> | ||
</FormGroup> | ||
<FormGroup controlId="checkbox"> | ||
<Checkbox inline={true} checked={this.state.onlyErrors} onChange={this.onErrorsChange}> | ||
Only Errors | ||
</Checkbox> | ||
</FormGroup> | ||
</Toolbar> | ||
<ServiceTracesJaeger | ||
service={this.props.service} | ||
duration={this.state.duration} | ||
onlyErrors={this.state.onlyErrors} | ||
/> | ||
</div> | ||
); | ||
} | ||
|
||
/*private navigateToJaeger = () => { | ||
API.getJaegerInfo(authentication()) | ||
.then(response => { | ||
let data = response['data']; | ||
window.open(data.url + `/search?service=${this.props.match.params.service}`, '_blank'); | ||
}) | ||
.catch(error => { | ||
MessageCenter.add(API.getErrorMsg('Could not fetch Jaeger info', error)); | ||
console.log(error); | ||
}); | ||
};*/ | ||
} | ||
|
||
export default ServiceTraces; |
73 changes: 73 additions & 0 deletions
73
src/pages/ServiceDetails/ServiceTraces/ServiceTracesJaeger.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import * as React from 'react'; | ||
import Iframe from 'react-iframe'; | ||
|
||
type ServiceTracesJaegerProps = { | ||
service: string; | ||
duration: number; | ||
onlyErrors: boolean; | ||
}; | ||
|
||
type ServiceTracesJaegerState = { | ||
url: string; | ||
}; | ||
|
||
class ServiceTracesJaeger extends React.Component<ServiceTracesJaegerProps, ServiceTracesJaegerState> { | ||
constructor(props: ServiceTracesJaegerProps) { | ||
super(props); | ||
this.state = { | ||
url: this.jaegerQuery() | ||
}; | ||
} | ||
|
||
jaegerQuery = () => { | ||
const dateNow = Date.now(); | ||
const start = (dateNow - this.props.duration * 1000) * 1000; | ||
const end = dateNow * 1000; | ||
const errors = this.props.onlyErrors ? `&tags=%7B"error"%3A"true"%7D` : ``; | ||
const service = this.props.service === 'Filter by Service' ? `` : `&service=${this.props.service}`; | ||
console.log( | ||
`http://localhost:3000/search?embed` + | ||
`&limit=20` + | ||
`&start=${start}` + | ||
`&end=${end}` + | ||
`&maxDuration` + | ||
`&minDuration` + | ||
service + | ||
errors | ||
); | ||
return ( | ||
`http://localhost:3000/search?embed` + | ||
`&limit=20` + | ||
`&start=${start}` + | ||
`&end=${end}` + | ||
`&maxDuration` + | ||
`&minDuration` + | ||
service + | ||
errors | ||
); | ||
}; | ||
|
||
componentDidUpdate(prevProps: ServiceTracesJaegerProps) { | ||
if (this.props !== prevProps) { | ||
this.setState({ | ||
url: this.jaegerQuery() | ||
}); | ||
} | ||
} | ||
|
||
render() { | ||
return ( | ||
<div> | ||
<Iframe | ||
url={this.state.url} | ||
position="inherit" | ||
allowFullScreen={true} | ||
height="800px" | ||
sandbox="allow-same-origin" | ||
/> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
export default ServiceTracesJaeger; |
Oops, something went wrong.