@@ -3,26 +3,10 @@ import fetch from 'node-fetch'
33import statsd from '../lib/statsd.js'
44import FailBot from '../lib/failbot.js'
55
6- const SCHEMAS = {
7- page : 'docs.v0.PageEvent' ,
8- exit : 'docs.v0.ExitEvent' ,
9- link : 'docs.v0.LinkEvent' ,
10- search : 'docs.v0.SearchEvent' ,
11- searchResult : 'docs.v0.SearchResultEvent' ,
12- navigate : 'docs.v0.NavigateEvent' ,
13- survey : 'docs.v0.SurveyEvent' ,
14- experiment : 'docs.v0.ExperimentEvent' ,
15- redirect : 'docs.v0.RedirectEvent' ,
16- clipboard : 'docs.v0.ClipboardEvent' ,
17- print : 'docs.v0.PrintEvent' ,
18- preference : 'docs.v0.PreferenceEvent' ,
19- }
20-
216export default class Hydro {
227 constructor ( { secret, endpoint } = { } ) {
238 this . secret = secret || process . env . HYDRO_SECRET
249 this . endpoint = endpoint || process . env . HYDRO_ENDPOINT
25- this . schemas = SCHEMAS
2610 }
2711
2812 /**
@@ -47,20 +31,14 @@ export default class Hydro {
4731 * @param {any } value
4832 */
4933 async publish ( schema , value ) {
50- return this . publishMany ( [ { schema, value } ] )
51- }
52-
53- /**
54- * Publish multiple events to Hydro
55- * @param {[{ schema: string, value: any }] } events
56- */
57- async publishMany ( events ) {
5834 const body = JSON . stringify ( {
59- events : events . map ( ( { schema, value } ) => ( {
60- schema,
61- value : JSON . stringify ( value ) , // We must double-encode the value property
62- cluster : 'potomac' , // We only have ability to publish externally to potomac cluster
63- } ) ) ,
35+ events : [
36+ {
37+ schema,
38+ value : JSON . stringify ( value ) , // We must double-encode the value property
39+ cluster : 'potomac' , // We only have ability to publish externally to potomac cluster
40+ } ,
41+ ] ,
6442 } )
6543 const token = this . generatePayloadHmac ( body )
6644
@@ -81,23 +59,24 @@ export default class Hydro {
8159 statsd . increment ( `hydro.response_code.${ res . status } ` , 1 , statTags )
8260 statsd . increment ( 'hydro.response_code.all' , 1 , statTags )
8361
84- // Track hydro exceptions in Sentry, but don't track 503s because we can't do anything about service availability
85- if ( ! res . ok && res . status !== 503 ) {
62+ // Track hydro exceptions in Sentry,
63+ // but don't track 5xx because we can't do anything about service availability
64+ if ( ! res . ok && res . status < 500 ) {
8665 const err = new Error ( `Hydro request failed: ${ res . statusText } ` )
8766 err . status = res . status
8867
68+ const failures = await res . text ( )
69+
8970 FailBot . report ( err , {
9071 hydroStatus : res . status ,
9172 hydroText : res . statusText ,
73+ hydroFailures : failures ,
9274 } )
9375
9476 // If the Hydro request failed as an "Unprocessable Entity", log it for diagnostics
9577 if ( res . status === 422 ) {
96- const failures = await res . json ( )
9778 console . error (
98- `Hydro schema validation failed:\n - Request: ${ body } \n - Failures: ${ JSON . stringify (
99- failures
100- ) } `
79+ `Hydro schema validation failed:\n - Request: ${ body } \n - Failures: ${ failures } `
10180 )
10281 }
10382
0 commit comments