This commit is contained in:
slice 2018-08-08 16:43:53 -07:00
parent a04d44e7de
commit 190f461706
No known key found for this signature in database
GPG Key ID: 1508C19D7436A26D
19 changed files with 142 additions and 146 deletions

View File

@ -0,0 +1,7 @@
{
"semi": false,
"singleQuote": true,
"trailingComma": "es5",
"arrowParens": "always",
"proseWrap": "always"
}

View File

@ -12,7 +12,10 @@ export default function DegradedNotice ({ services }) {
return ( return (
<div className="degraded-notice"> <div className="degraded-notice">
<header>{keys.length} service{plural} {indicative} unreachable</header> <header>
{keys.length} service
{plural} {indicative} unreachable
</header>
<p> <p>
elstat is having trouble contacting <strong>{serviceNames}</strong>. elstat is having trouble contacting <strong>{serviceNames}</strong>.
</p> </p>

View File

@ -55,9 +55,7 @@ export default class Graph extends Component {
} }
render() { render() {
const yAxis = this.isSmallScreen() const yAxis = this.isSmallScreen() ? null : (
? null
: (
<YAxis <YAxis
dataKey="latency" dataKey="latency"
tickLine={false} tickLine={false}
@ -68,9 +66,7 @@ export default class Graph extends Component {
return ( return (
<div className="graph-container"> <div className="graph-container">
<ResponsiveContainer width="100%" height={175}> <ResponsiveContainer width="100%" height={175}>
<AreaChart <AreaChart data={this.processData()}>
data={this.processData()}
>
<XAxis <XAxis
dataKey="timestamp" dataKey="timestamp"
tickFormatter={(tick) => ms(Date.now() - tick)} tickFormatter={(tick) => ms(Date.now() - tick)}
@ -86,11 +82,7 @@ export default class Graph extends Component {
separator=": " separator=": "
labelFormatter={() => null} labelFormatter={() => null}
/> />
<ReferenceLine <ReferenceLine y={1000} label="1s" stroke="pink" />
y={1000}
label="1s"
stroke="pink"
/>
<Area <Area
type="monotone" type="monotone"
dataKey="latency" dataKey="latency"

View File

@ -13,35 +13,38 @@ const OUTAGE_TYPES = {
} }
export default function Incident({ incident }) { export default function Incident({ incident }) {
const { content, end_date: end, start_date: start, title, type, stages } = incident const {
content,
end_date: end,
start_date: start,
title,
type,
stages,
} = incident
const startDate = new Date(start * 1000) const startDate = new Date(start * 1000)
const endDate = end ? new Date(end * 1000) : null const endDate = end ? new Date(end * 1000) : null
const tooltip = `Started ${startDate.toLocaleString()}` + const tooltip =
`Started ${startDate.toLocaleString()}` +
(endDate ? `, ended ${endDate.toLocaleString()}` : '') (endDate ? `, ended ${endDate.toLocaleString()}` : '')
const ago = ms(Date.now() - start * 1000) const ago = ms(Date.now() - start * 1000)
const agoEnd = end ? ms(Date.now() - end * 1000) : null const agoEnd = end ? ms(Date.now() - end * 1000) : null
const stageNodes = stages.map( const stageNodes = stages
(stage) => <Stage key={stage.title} stage={stage}/> .map((stage) => <Stage key={stage.title} stage={stage} />)
).reverse() // show newest first .reverse() // show newest first
return ( return (
<div className="incident"> <div className="incident">
<h2>{OUTAGE_TYPES[type] || type}: {title}</h2> <h2>
{OUTAGE_TYPES[type] || type}: {title}
</h2>
<p>{content}</p> <p>{content}</p>
<footer title={tooltip}> <footer title={tooltip}>
Started {ago} ago Started {ago} ago
{end ? `, ended ${agoEnd} ago` : null} {end ? `, ended ${agoEnd} ago` : null}
</footer> </footer>
{stageNodes.length {stageNodes.length ? <div className="stages">{stageNodes}</div> : null}
? (
<div className="stages">
{stageNodes}
</div>
)
: null
}
</div> </div>
) )
} }

View File

@ -25,9 +25,9 @@ export default class Incidents extends React.Component {
return null return null
} }
return this.state.incidents.map( return this.state.incidents.map((incident) => (
(incident) => <Incident key={incident.id} incident={incident}/> <Incident key={incident.id} incident={incident} />
) ))
} }
render() { render() {

View File

@ -4,11 +4,7 @@ import PropTypes from 'prop-types'
import './Page.css' import './Page.css'
export default function Page({ children }) { export default function Page({ children }) {
return ( return <div className="page">{children}</div>
<div className="page">
{children}
</div>
)
} }
Page.propTypes = { Page.propTypes = {

View File

@ -32,13 +32,13 @@
} }
.service.service-alive .emoji { .service.service-alive .emoji {
color: #2ECC40; color: #2ecc40;
} }
.service.service-slow .emoji { .service.service-slow .emoji {
color: #FF851B; color: #ff851b;
} }
.service.service-dead .emoji { .service.service-dead .emoji {
color: #FF4136; color: #ff4136;
} }

View File

@ -8,9 +8,7 @@ import './Service.css'
import Graph from './Graph.js' import Graph from './Graph.js'
import config from '../config.json' import config from '../config.json'
const { const { slow_threshold: SLOW_THRESHOLD = 1500 } = config
slow_threshold: SLOW_THRESHOLD = 1500,
} = config
const icons = { const icons = {
alive: 'check-circle', alive: 'check-circle',
@ -38,10 +36,7 @@ export default function Service ({ graph, name, status, latency, description })
const title = titles[state] const title = titles[state]
const icon = icons[state] const icon = icons[state]
const className = classnames( const className = classnames('service', `service-${state}`)
'service',
`service-${state}`
)
return ( return (
<div className={className}> <div className={className}>
@ -50,16 +45,16 @@ export default function Service ({ graph, name, status, latency, description })
<FontAwesomeIcon title={title} icon={icon} /> <FontAwesomeIcon title={title} icon={icon} />
</div> </div>
<h2 className="title"> <h2 className="title">
{name} {latency ? ( {name}{' '}
{latency ? (
<span className="latency"> <span className="latency">
{Math.round(latency)}ms {Math.round(latency)}
ms
</span> </span>
) : null} ) : null}
</h2> </h2>
</header> </header>
<p className="description"> <p className="description">{description}</p>
{description}
</p>
{graph ? <Graph data={graph} /> : null} {graph ? <Graph data={graph} /> : null}
</div> </div>
) )
@ -71,9 +66,7 @@ Service.defaultProps = {
} }
Service.propTypes = { Service.propTypes = {
graph: PropTypes.arrayOf( graph: PropTypes.arrayOf(PropTypes.arrayOf(PropTypes.number)),
PropTypes.arrayOf(PropTypes.number),
),
name: PropTypes.string.isRequired, name: PropTypes.string.isRequired,
status: PropTypes.bool.isRequired, status: PropTypes.bool.isRequired,
latency: PropTypes.number, latency: PropTypes.number,

View File

@ -7,19 +7,17 @@ import Incident from './Incident'
export default function Status({ incident }) { export default function Status({ incident }) {
const incidentOngoing = incident && incident.ongoing === 1 const incidentOngoing = incident && incident.ongoing === 1
const view = incidentOngoing const view = incidentOngoing ? (
? <Incident incident={incident}/> <Incident incident={incident} />
: 'All systems operational' ) : (
'All systems operational'
)
const className = classnames( const className = classnames(
'status', 'status',
incidentOngoing ? 'status-bad' : 'status-good', incidentOngoing ? 'status-bad' : 'status-good'
)
return (
<div className={className}>
{view}
</div>
) )
return <div className={className}>{view}</div>
} }
Status.propTypes = { Status.propTypes = {

View File

@ -10,17 +10,28 @@ it('renders without crashing', () => {
it('shows one service', () => { it('shows one service', () => {
const comp = shallow(<DegradedNotice services={{ first: null }} />) const comp = shallow(<DegradedNotice services={{ first: null }} />)
expect(comp.contains(<header>1 service is unreachable</header>)).toEqual(true) expect(comp.contains(<header>1 service is unreachable</header>)).toEqual(true)
expect(comp.contains( expect(
<p>elstat is having trouble contacting <strong>first</strong>.</p> comp.contains(
)).toEqual(true) <p>
elstat is having trouble contacting <strong>first</strong>.
</p>
)
).toEqual(true)
}) })
it('shows multiple services', () => { it('shows multiple services', () => {
const comp = shallow(<DegradedNotice services={{ first: null, second: null, third: null }}/>) const comp = shallow(
expect(comp.contains( <DegradedNotice services={{ first: null, second: null, third: null }} />
<header>3 services are unreachable</header> )
)).toEqual(true) expect(comp.contains(<header>3 services are unreachable</header>)).toEqual(
expect(comp.contains( true
<p>elstat is having trouble contacting <strong>first, second, third</strong>.</p> )
)).toEqual(true) expect(
comp.contains(
<p>
elstat is having trouble contacting{' '}
<strong>first, second, third</strong>.
</p>
)
).toEqual(true)
}) })

View File

@ -3,11 +3,7 @@ import { shallow } from 'enzyme'
import Service, { getServiceState } from '../Service' import Service, { getServiceState } from '../Service'
const graph = [ const graph = [[1000, 50], [2000, 30], [3000, 60]]
[1000, 50],
[2000, 30],
[3000, 60],
]
const props = { const props = {
name: 'sample service', name: 'sample service',
@ -21,7 +17,9 @@ describe('<Service/>', () => {
}) })
it('omits information', () => { it('omits information', () => {
const comp = shallow(<Service graph={null} status {...props} latency={null}/>) const comp = shallow(
<Service graph={null} status {...props} latency={null} />
)
expect(comp.find('h2.title').text()).toEqual('sample service ') expect(comp.find('h2.title').text()).toEqual('sample service ')
}) })
@ -29,7 +27,9 @@ describe('<Service/>', () => {
const comp = shallow(<Service graph={graph} status {...props} />) const comp = shallow(<Service graph={graph} status {...props} />)
expect(comp.prop('className')).toEqual('service service-alive') expect(comp.prop('className')).toEqual('service service-alive')
expect(comp.find('h2.title').text()).toEqual('sample service 51ms') expect(comp.find('h2.title').text()).toEqual('sample service 51ms')
expect(comp.contains(<p className="description">a cool service</p>)).toEqual(true) expect(
comp.contains(<p className="description">a cool service</p>)
).toEqual(true)
expect(comp.contains(<span className="latency">51ms</span>)).toEqual(true) expect(comp.contains(<span className="latency">51ms</span>)).toEqual(true)
}) })
}) })

View File

@ -6,9 +6,5 @@ import {
} from '@fortawesome/free-solid-svg-icons' } from '@fortawesome/free-solid-svg-icons'
export default function register() { export default function register() {
library.add( library.add(faCheckCircle, faTimesCircle, faExclamationCircle)
faCheckCircle,
faTimesCircle,
faExclamationCircle,
)
} }

View File

@ -7,7 +7,4 @@ import register from './icons.js'
register() register()
ReactDOM.render( ReactDOM.render(<App />, document.getElementById('root'))
<App/>,
document.getElementById('root')
)

View File

@ -56,7 +56,7 @@ export default class StreamingClient extends NanoEvents {
const begin = Date.now() const begin = Date.now()
log('connecting') log('connecting')
const ws = this.ws = new WebSocket(this.url) const ws = (this.ws = new WebSocket(this.url))
window.ws = ws window.ws = ws
ws.onopen = () => { ws.onopen = () => {