Skip to content
This repository has been archived by the owner on Mar 25, 2020. It is now read-only.

Publish rss feeds #26

Merged
merged 4 commits into from
May 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
387 changes: 166 additions & 221 deletions cloudformation/lamb-status.yml

Large diffs are not rendered by default.

26 changes: 16 additions & 10 deletions packages/frontend/src/components/statusPage/History/History.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { PropTypes } from 'react'
import classnames from 'classnames'
import ModestLink from 'components/common/ModestLink'
import Title from 'components/statusPage/Title'
import SubscribeButton from 'components/statusPage/SubscribeButton'
import IncidentItem from 'components/statusPage/IncidentItem'
import MaintenanceItem from 'components/statusPage/MaintenanceItem'
import { getDateTimeFormat } from 'utils/datetime'
Expand Down Expand Up @@ -91,16 +92,21 @@ export default class History extends React.Component {
const events = incidents.concat(maintenances)
const eventsByMonth = this.renderEventsByMonth(events)

return (<div className={classnames(classes.layout, 'mdl-grid')}
style={{ opacity: this.state.isFetching ? 0.5 : 1 }}>
<Title service_name={settings.serviceName} />
<div className='mdl-cell mdl-cell--12-col'>
<h4>Incident History</h4>
</div>
<div className='mdl-cell mdl-cell--12-col mdl-list'>
{eventsByMonth}
return (
<div className={classnames(classes.layout, 'mdl-grid')}
style={{ opacity: this.state.isFetching ? 0.5 : 1 }}>
<div className={classnames(classes.top)}>
<Title service_name={settings.serviceName} />
<SubscribeButton />
</div>
<div className='mdl-cell mdl-cell--12-col'>
<h4>Incident History</h4>
</div>
<div className='mdl-cell mdl-cell--12-col mdl-list'>
{eventsByMonth}
</div>
<ModestLink link='/' text='Current Incidents' />
</div>
<ModestLink link='/' text='Current Incidents' />
</div>)
)
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
.top {
display: flex;
justify-content: space-between;
width: 100%;
}

.date_item {
height: auto;
}
Expand Down
26 changes: 16 additions & 10 deletions packages/frontend/src/components/statusPage/Statuses/Statuses.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Button from 'components/common/Button'
import ModestLink from 'components/common/ModestLink'
import MetricsGraph from 'components/common/MetricsGraph'
import Title from 'components/statusPage/Title'
import SubscribeButton from 'components/statusPage/SubscribeButton'
import Components from 'components/statusPage/Components'
import Incidents from 'components/statusPage/Incidents'
import ScheduledMaintenances from 'components/statusPage/ScheduledMaintenances'
Expand Down Expand Up @@ -95,15 +96,20 @@ export default class Statuses extends React.Component {
)
}

return (<div className={classnames(classes.layout, 'mdl-grid')}
style={{ opacity: this.state.isFetching ? 0.5 : 1 }}>
<Title service_name={settings.serviceName} />
{components}
{maintenances}
{metricsTitle}
{metricsContent}
{incidents}
<ModestLink link='/history' text='Incident History' />
</div>)
return (
<div className={classnames(classes.layout, 'mdl-grid')}
style={{ opacity: this.state.isFetching ? 0.5 : 1 }}>
<div className={classnames(classes.top)}>
<Title service_name={settings.serviceName} />
<SubscribeButton />
</div>
{components}
{maintenances}
{metricsTitle}
{metricsContent}
{incidents}
<ModestLink link='/history' text='Incident History' />
</div>
)
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
.top {
display: flex;
justify-content: space-between;
width: 100%;
}

.title {
margin-top: 32px;
margin-bottom: -8px;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.rss-icon {
margin-top: 28px;
margin-bottom: 16px;
height: 24px;
line-height: 24px;

border-radius: 20%;
background-color: #f57c00;
color: #fff;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import React from 'react'
import classnames from 'classnames'
import classes from './SubscribeButton.scss'

export default class SubscribeButton extends React.Component {
render () {
return (
<a href='history.rss'>
<i className={classnames(classes['rss-icon'], 'material-icons')}>rss_feed</i>
</a>
)
}
}
23 changes: 1 addition & 22 deletions packages/lambda/bin/setup-apex.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,27 +49,6 @@ const createFunctionJSON = (role, timeout, memory, targetDirs) => {
console.log(`${dir}/function.json created`)
})
}
const metricsFunctionRoleArn = getArn(awsResourceIDs, 'MetricsFunctionRoleArn')
createFunctionJSON(metricsFunctionRoleArn, 60, 512, [
createFunctionJSON(lambdaRoleArn, 60, 512, [
buildDir + '/functions/CollectMetricsData'
])
createFunctionJSON(metricsFunctionRoleArn, 30, 128, [
buildDir + '/functions/GetExternalMetrics'
])
const s3HandleFunctionRoleArn = getArn(awsResourceIDs, 'S3HandleFunctionRoleArn')
createFunctionJSON(s3HandleFunctionRoleArn, 30, 128, [
buildDir + '/functions/S3PutObject',
buildDir + '/functions/S3SyncObjects'
])
const cognitoHandleFunctionRoleArn = getArn(awsResourceIDs, 'CognitoHandleFunctionRoleArn')
createFunctionJSON(cognitoHandleFunctionRoleArn, 30, 128, [
buildDir + '/functions/CognitoCreateUser',
buildDir + '/functions/CognitoCreateUserPool',
buildDir + '/functions/CognitoCreateUserPoolClient',
buildDir + '/functions/DBCreateItems',
buildDir + '/functions/PatchSettings'
])
const apiGatewayHandleFunctionRoleArn = getArn(awsResourceIDs, 'APIGatewayHandleFunctionRoleArn')
createFunctionJSON(apiGatewayHandleFunctionRoleArn, 30, 128, [
buildDir + '/functions/APIGatewayDeploy'
])
4 changes: 4 additions & 0 deletions packages/lambda/config/webpack.config.es6.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ export default {
DBCreateItems: [
'babel-polyfill',
'./src/api/dbCreateItems/index.js'
],
UpdateFeeds: [
'babel-polyfill',
'./src/api/updateFeeds/index.js'
]
},
output: {
Expand Down
1 change: 1 addition & 0 deletions packages/lambda/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"json-loader": "^0.5.4",
"mime": "^1.3.4",
"mkdirp": "^0.5.1",
"moment": "^2.18.1",
"rimraf": "^2.5.4",
"verror": "^1.8.1",
"webpack": "^1.13.2"
Expand Down
3 changes: 3 additions & 0 deletions packages/lambda/src/api/deleteIncidents/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { Incidents } from 'model/incidents'
import SNS from 'aws/sns'

export async function handle (event, context, callback) {
try {
const incidents = new Incidents()
const incident = await incidents.lookup(event.params.incidentid)
await incident.delete()

await new SNS().notifyIncident(incident)
} catch (error) {
console.log(error.message)
console.log(error.stack)
Expand Down
3 changes: 3 additions & 0 deletions packages/lambda/src/api/deleteMaintenances/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { Maintenances } from 'model/maintenances'
import SNS from 'aws/sns'

export async function handle (event, context, callback) {
try {
const maintenances = new Maintenances()
const maintenance = await maintenances.lookup(event.params.maintenanceid)
await maintenance.delete()

await new SNS().notifyIncident(maintenance)
} catch (error) {
console.log(error.message)
console.log(error.stack)
Expand Down
3 changes: 3 additions & 0 deletions packages/lambda/src/api/patchIncidents/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Incident } from 'model/incidents'
import SNS from 'aws/sns'

export async function handle (event, context, callback) {
try {
Expand All @@ -7,6 +8,8 @@ export async function handle (event, context, callback) {
await incident.validate()
await incident.save()

await new SNS().notifyIncident(incident)

const obj = incident.objectify()
const comps = obj.components
delete obj.components
Expand Down
3 changes: 3 additions & 0 deletions packages/lambda/src/api/patchMaintenances/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Maintenance } from 'model/maintenances'
import SNS from 'aws/sns'

export async function handle (event, context, callback) {
try {
Expand All @@ -8,6 +9,8 @@ export async function handle (event, context, callback) {
await maintenance.validate()
await maintenance.save()

await new SNS().notifyIncident(maintenance)

const obj = maintenance.objectify()
const comps = obj.components
delete obj.components
Expand Down
3 changes: 3 additions & 0 deletions packages/lambda/src/api/postIncidents/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Incident } from 'model/incidents'
import SNS from 'aws/sns'

export async function handle (event, context, callback) {
try {
Expand All @@ -7,6 +8,8 @@ export async function handle (event, context, callback) {
await incident.validate()
await incident.save()

await new SNS().notifyIncident(incident)

const obj = incident.objectify()
const comps = obj.components
delete obj.components
Expand Down
3 changes: 3 additions & 0 deletions packages/lambda/src/api/postMaintenances/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Maintenance } from 'model/maintenances'
import SNS from 'aws/sns'

export async function handle (event, context, callback) {
try {
Expand All @@ -7,6 +8,8 @@ export async function handle (event, context, callback) {
await maintenance.validate()
await maintenance.save()

await new SNS().notifyIncident(maintenance)

const obj = maintenance.objectify()
const comps = obj.components
delete obj.components
Expand Down
87 changes: 87 additions & 0 deletions packages/lambda/src/api/updateFeeds/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import Feed from 'feed'
import { Settings } from 'model/settings'
import { Incidents } from 'model/incidents'
import { Maintenances } from 'model/maintenances'
import S3 from 'aws/s3'
import CloudFormation from 'aws/cloudFormation'
import { stackName } from 'utils/const'
import { getDateTimeFormat } from 'utils/datetime'

export async function handle (event, context, callback) {
try {
const settings = new Settings()
const statusPageURL = await settings.getStatusPageURL()
const serviceName = await settings.getServiceName()
const feed = new Feed({
id: `tag:${statusPageURL},2017:/history`,
link: statusPageURL,
title: `${serviceName} Status - Incident History`,
author: {
name: serviceName
}
})

let events = (await new Incidents().all()).concat(await new Maintenances().all())
events.sort(latestToOldest)
const maxItems = 25
for (let i = 0; i < maxItems; i++) {
feed.addItem(await buildItem(events[i], statusPageURL))
}

const { AWS_REGION: region } = process.env
const bucket = await new CloudFormation(stackName).getStatusPageBucketName()
const s3 = new S3()
await s3.putObject(region, bucket, 'history.atom', feed.atom1())
await s3.putObject(region, bucket, 'history.rss', feed.rss2())
callback(null)
} catch (error) {
console.log(error.message)
console.log(error.stack)
callback('Error: failed to update the feeds')
}
}

const latestToOldest = (a, b) => {
if (a.updatedAt < b.updatedAt) return 1
else if (b.updatedAt < a.updatedAt) return -1
return 0
}

const buildItem = async (event, statusPageURL) => {
let id, link, eventUpdates
if (event.hasOwnProperty('incidentID')) {
const incidentUpdates = await event.getIncidentUpdates()
incidentUpdates.sort(latestToOldest)

id = `tag:${statusPageURL},2017:Incident/${event.incidentID}`
link = `${statusPageURL}/incidents/${event.incidentID}`
eventUpdates = incidentUpdates.map(update => {
update.status = update.incidentStatus
return update
})
} else if (event.hasOwnProperty('maintenanceID')) {
const maintenanceUpdates = await event.getMaintenanceUpdates()
maintenanceUpdates.sort(latestToOldest)

id = `tag:${statusPageURL},2017:Maintenance/${event.maintenanceID}`
link = `${statusPageURL}/maintenances/${event.maintenanceID}`
eventUpdates = maintenanceUpdates.map(update => {
update.status = update.maintenanceStatus
return update
})
} else {
throw new Error('Unknown event: ', event)
}

const content = eventUpdates.map(update => {
return `<p><small>${getDateTimeFormat(update.updatedAt)}</small><br><strong>${update.status}</strong> - ${update.message}</p>`
}).join('')
return {
id,
link,
content,
published: new Date(eventUpdates[0].updatedAt),
date: new Date(event.updatedAt),
title: event.name
}
}
Loading