-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtestRepair.js
More file actions
149 lines (126 loc) · 4.74 KB
/
testRepair.js
File metadata and controls
149 lines (126 loc) · 4.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
const assert = require('assert');
const promClient = require('prom-client');
const { v4: uuid } = require('uuid');
const { Warp10Client } = require('../../../../libV2/warp10');
const { convertTimestamp } = require('../../../../libV2/utils');
const { RepairTask } = require('../../../../libV2/tasks');
const { generateCustomEvents, fetchRecords } = require('../../../utils/v2Data');
const { assertMetricValue } = require('../../../utils/prom');
// Ten minutes in the past
const _now = Math.floor(new Date().getTime() / 1000) - (600);
const getTs = delta => convertTimestamp(_now + delta);
const checkpointLabelToLevel = {
bck: 'buckets',
acc: 'accounts',
usr: 'users',
};
function assertCheckpoint(expected, checkpoint) {
assert.strictEqual(checkpoint.inB, expected.in);
assert.strictEqual(checkpoint.outB, expected.out);
assert.strictEqual(checkpoint.objD, expected.count);
assert.strictEqual(checkpoint.sizeD, expected.bytes);
assert.deepStrictEqual(checkpoint.ops, expected.ops);
}
function assertResults(totals, series) {
series.forEach(checkpoint => {
const [[label, id]] = Object.entries(checkpoint.labels)
.filter(([k]) => checkpointLabelToLevel[k] !== undefined);
const level = checkpointLabelToLevel[label];
assert.strictEqual(checkpoint.values.length, 1);
assertCheckpoint(
totals[level][id],
checkpoint.values[0],
);
});
}
describe('Test Repair', function () {
this.timeout(10000);
let prefix;
let warp10;
let repairTask;
beforeEach(async () => {
prefix = uuid();
warp10 = new Warp10Client({ nodeId: prefix });
repairTask = new RepairTask({ warp10: [warp10], enableMetrics: true });
await repairTask.setup();
repairTask._program = { opts: () => ({ lag: 0, nodeId: prefix }) };
});
afterEach(async () => {
await repairTask.join();
promClient.register.clear();
});
it('should create corrections from events', async () => {
const start = getTs(-300);
const stop = getTs(-120);
const { events, totals } = generateCustomEvents(start, stop, 100,
{ [uuid()]: { [uuid()]: [uuid()] } });
await warp10.ingest({ className: 'utapi.repair.event' }, events);
await repairTask._execute(getTs(0));
const series = await fetchRecords(
warp10,
'utapi.repair.correction',
{ node: prefix },
{ end: getTs(1), count: -1 },
'@utapi/decodeRecord',
);
assert.strictEqual(series.length, 3);
assertResults(totals, series);
await assertMetricValue('s3_utapi_repair_task_created_total', series.length);
});
it('should only include events not in an existing correction', async () => {
const accounts = { [uuid()]: { [uuid()]: [uuid()] } };
const { events: historicalEvents } = generateCustomEvents(
getTs(-500),
getTs(-400),
100,
accounts,
);
const { events, totals } = generateCustomEvents(
getTs(-400) + 1,
getTs(-120),
100,
accounts,
);
await warp10.ingest({ className: 'utapi.repair.event' }, historicalEvents);
await warp10.ingest({ className: 'utapi.repair.event' }, events);
await repairTask._execute(getTs(-400));
await repairTask._execute(getTs(0));
const series = await fetchRecords(
warp10,
'utapi.repair.correction',
{ node: prefix },
{ end: getTs(1), count: 1 },
'@utapi/decodeRecord',
);
assert.strictEqual(series.length, 3);
assertResults(totals, series);
});
it('should not create a correction if no new events have occurred', async () => {
const { events, totals } = generateCustomEvents(
getTs(-300),
getTs(-120),
100,
{ [uuid()]: { [uuid()]: [uuid()] } },
);
await warp10.ingest({ className: 'utapi.repair.event' }, events);
await repairTask._execute(getTs(-100));
const series = await fetchRecords(
warp10,
'utapi.repair.correction',
{ node: prefix },
{ end: getTs(1), count: -1 },
'@utapi/decodeRecord',
);
assert.strictEqual(series.length, 3);
assertResults(totals, series);
await repairTask._execute(getTs(0));
const results = await fetchRecords(
warp10,
'utapi.repair.correction',
{ node: prefix },
{ start: getTs(1), end: getTs(10 * 1000 * 1000) },
'@utapi/decodeRecord',
);
assert.strictEqual(results.length, 0);
});
});