Skip to content

Commit

Permalink
Remove legacy analytics (#3179)
Browse files Browse the repository at this point in the history
We're getting good results from #3093, so there's no reason to keep maintaining this code.

Ref #1848 #2068
  • Loading branch information
paulmelnikow authored Mar 8, 2019
1 parent 667bbbe commit 612831a
Show file tree
Hide file tree
Showing 9 changed files with 8 additions and 212 deletions.
3 changes: 0 additions & 3 deletions core/base-service/base-static.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict'

const makeBadge = require('../../gh-badges/lib/make-badge')
const analytics = require('../server/analytics')
const BaseService = require('./base')
const {
serverHasBeenUpSinceResourceCached,
Expand All @@ -23,8 +22,6 @@ module.exports = class BaseStaticService extends BaseService {
})

camp.route(regex, async (queryParams, match, end, ask) => {
analytics.noteRequest(queryParams, match)

if (serverHasBeenUpSinceResourceCached(ask.req)) {
// Send Not Modified.
ask.res.statusCode = 304
Expand Down
3 changes: 0 additions & 3 deletions core/base-service/legacy-request-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const queryString = require('query-string')
const LruCache = require('../../gh-badges/lib/lru-cache')
const makeBadge = require('../../gh-badges/lib/make-badge')
const { makeBadgeData: getBadgeData } = require('../../lib/badge-data')
const analytics = require('../server/analytics')
const log = require('../server/log')
const { setCacheHeaders } = require('./cache-headers')
const {
Expand Down Expand Up @@ -121,8 +120,6 @@ function handleRequest(cacheHeaderConfig, handlerOptions) {
})
}

analytics.noteRequest(queryParams, match)

const filteredQueryParams = {}
allowedKeys.forEach(key => {
filteredQueryParams[key] = queryParams[key]
Expand Down
3 changes: 0 additions & 3 deletions core/base-service/legacy-request-handler.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const fetch = require('node-fetch')
const nock = require('nock')
const portfinder = require('portfinder')
const Camp = require('camp')
const analytics = require('../server/analytics')
const { makeBadgeData: getBadgeData } = require('../../lib/badge-data')
const {
handleRequest,
Expand Down Expand Up @@ -50,8 +49,6 @@ function fakeHandlerWithNetworkIo(queryParams, match, sendBadge, request) {
}

describe('The request handler', function() {
before(analytics.load)

let port, baseUrl
beforeEach(async function() {
port = await portfinder.getPortPromise()
Expand Down
148 changes: 0 additions & 148 deletions core/server/analytics.js

This file was deleted.

7 changes: 0 additions & 7 deletions core/server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ const {
} = require('../base-service/legacy-request-handler')
const { clearRegularUpdateCache } = require('../legacy/regular-update')
const { staticBadgeUrl } = require('../badge-urls/make-badge-url')
const analytics = require('./analytics')
const log = require('./log')
const sysMonitor = require('./monitor')
const PrometheusMetrics = require('./prometheus-metrics')
Expand Down Expand Up @@ -252,10 +251,6 @@ module.exports = class Server {
key,
}))

analytics.load()
analytics.scheduleAutosaving()
analytics.setRoutes(camp)

this.cleanupMonitor = sysMonitor.setRoutes({ rateLimit }, camp)

const { githubConstellation, metrics } = this
Expand Down Expand Up @@ -304,7 +299,5 @@ module.exports = class Server {
if (this.metrics) {
this.metrics.stop()
}

analytics.cancelAutosaving()
}
}
30 changes: 0 additions & 30 deletions core/server/server.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const isPng = require('is-png')
const isSvg = require('is-svg')
const sinon = require('sinon')
const portfinder = require('portfinder')
const Joi = require('joi')
const svg2img = require('../../gh-badges/lib/svg-to-img')
const { createTestServer } = require('./in-process-server-test-helpers')

Expand Down Expand Up @@ -126,33 +125,4 @@ describe('The server', function() {
expect(await res.text()).to.include(expectedError)
})
})

describe('analytics endpoint', function() {
it('should return analytics in the expected format', async function() {
const countSchema = Joi.array()
.items(
Joi.number()
.integer()
.min(0)
.required()
)
.length(36)
.required()
const analyticsSchema = Joi.object({
vendorMonthly: countSchema,
rawMonthly: countSchema,
vendorFlatMonthly: countSchema,
rawFlatMonthly: countSchema,
vendorFlatSquareMonthly: countSchema,
rawFlatSquareMonthly: countSchema,
}).required()

const res = await fetch(`${baseUrl}$analytics/v1`)
expect(res.ok).to.be.true

const json = await res.json()

Joi.assert(json, analyticsSchema)
})
})
})
4 changes: 2 additions & 2 deletions doc/code-walkthrough.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ test this kind of logic through unit tests (e.g. of `render()` and
2. The Server, which is defined in
[`core/server/server.js`][core/server/server], is based on the web
framework [Scoutcamp][]. It creates an http server, sets up helpers for
analytics, token persistence, and monitoring. Then it loads all the
services, injecting dependencies as it asks each one to register its route
token persistence and monitoring. Then it loads all the services,
injecting dependencies as it asks each one to register its route
with Scoutcamp.

3. The service registration continues in `BaseService.register`. From its
Expand Down
19 changes: 5 additions & 14 deletions doc/production-hosting.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ Shields has mercifully little persistent state:

1. The GitHub tokens we collect are saved on each server in JSON files on disk.
They can be fetched from the [GitHub auth admin endpoint][] for debugging.
2. The analytics data is also saved on each server in JSON files on disk.
3. The server keeps a few caches in memory. These are neither persisted nor
2. The server keeps a few caches in memory. These are neither persisted nor
inspectable.
- The [request cache][]
- The [regular-update cache][]
Expand Down Expand Up @@ -214,31 +213,23 @@ the server. It's generously donated by [Sentry][sentry home]. We bundle

## Monitoring

Overall server performance and requests by service are monitored using
[Prometheus and Grafana][metrics].

Request performance is monitored in two places:

- [Status][] (using [UptimeRobot][])
- [Server metrics][] using Prometheus and Grafana
- [@RedSparr0w's monitor][monitor] which posts [notifications][] to a private
[#monitor chat room][monitor discord]

Overall server performance is monitored using Prometheus and Grafana.
Coming soon! ([#2068][issue 2068])

[metrics]: https://metrics.shields.io/
[status]: https://status.shields.io/
[server metrics]: https://metrics.shields.io/
[uptimerobot]: https://uptimerobot.com/
[monitor]: https://shields.redsparr0w.com/1568/
[notifications]: http://shields.redsparr0w.com/discord_notification
[monitor discord]: https://discordapp.com/channels/308323056592486420/470700909182320646
[issue 2068]: https://github.com/badges/shields/issues/2068

## Analytics

The server analytics data is public and can be fetched from the
[analytics endpoint][] or using the [analytics script][].

[analytics endpoint]: https://github.com/badges/shields/blob/master/lib/analytics.js
[analytics script]: https://github.com/badges/ServerScript/blob/master/stats.js

## Known limitations

Expand Down
3 changes: 1 addition & 2 deletions now.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
"version": 1,
"name": "shields",
"env": {
"PERSISTENCE_DIR": "/tmp/persistence",
"SHIELDS_ANALYTICS_FILE": "/tmp/analytics.json"
"PERSISTENCE_DIR": "/tmp/persistence"
},
"type": "npm",
"engines": {
Expand Down

0 comments on commit 612831a

Please sign in to comment.