[server/logging] remove doTagsMatch() helper

This commit is contained in:
spalger 2016-10-20 13:19:33 -07:00
parent 38bcad9a05
commit a8eea585d5
3 changed files with 5 additions and 57 deletions

View file

@ -1,30 +0,0 @@
import expect from 'expect.js';
import { doTagsMatch } from '../do_tags_match';
describe('doTagsMatch helper', () => {
it('returns false for non-objects', () => {
expect(doTagsMatch(1, [])).to.be(false);
expect(doTagsMatch('string', [])).to.be(false);
expect(doTagsMatch(null, [])).to.be(false);
expect(doTagsMatch(undefined, [])).to.be(false);
});
it('returns false when object does not have tags array', () => {
expect(doTagsMatch({}, [])).to.be(false);
expect(doTagsMatch({ tags: 'taga' }, ['taga'])).to.be(false);
});
it('returns false when tags do not match', () => {
expect(doTagsMatch({ tags: ['a', 'b', 'c']}, ['b', 'c'])).to.be(false);
expect(doTagsMatch({ tags: ['b', 'b', 'c']}, ['b', 'c'])).to.be(false);
expect(doTagsMatch({ tags: ['b', 'b', 'c']}, ['b', 'c', 'a'])).to.be(false);
expect(doTagsMatch({ tags: ['b', 'c']}, ['b', 'c', 'a'])).to.be(false);
expect(doTagsMatch({ tags: []}, ['foo'])).to.be(false);
});
it('returns true when tags do match', () => {
expect(doTagsMatch({ tags: ['a', 'b', 'c']}, ['a', 'b', 'c'])).to.be(true);
expect(doTagsMatch({ tags: ['c', 'a', 'b']}, ['a', 'b', 'c'])).to.be(true);
});
});

View file

@ -1,24 +0,0 @@
import { isArray } from 'lodash';
export function doTagsMatch(event, expectedTags) {
if (!event || !isArray(event.tags)) {
return false;
}
if (event.tags.length !== expectedTags.length) {
return false;
}
const unmatchedEventTags = event.tags.slice(0);
const unmatchedExpectedTags = [];
expectedTags.forEach(t => {
const i = unmatchedEventTags.indexOf(t);
if (i > -1) {
unmatchedEventTags.splice(i, 1);
} else {
unmatchedExpectedTags.push(t);
}
});
return unmatchedEventTags.concat(unmatchedExpectedTags).length === 0;
}

View file

@ -1,7 +1,9 @@
import Stream from 'stream';
import _ from 'lodash';
import { get, isEqual, sortBy } from 'lodash';
import { doTagsMatch } from './do_tags_match';
function doTagsMatch(event, tags) {
return isEqual(sortBy(get(event, 'tags')), sortBy(tags));
}
export class LogInterceptor extends Stream.Transform {
constructor() {
@ -23,7 +25,7 @@ export class LogInterceptor extends Stream.Transform {
*/
downgradeIfEconnreset(event) {
const isClientError = doTagsMatch(event, ['error', 'client', 'connection']);
const isEconnreset = isClientError && _.get(event, 'data.errno') === 'ECONNRESET';
const isEconnreset = isClientError && get(event, 'data.errno') === 'ECONNRESET';
if (!isEconnreset) return false;