Skip to content

Commit f986eb2

Browse files
committed
feat: support byReceiptTime parameter for search queries
1 parent cc7cf11 commit f986eb2

3 files changed

Lines changed: 277 additions & 4 deletions

File tree

src/search.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,20 @@ class Search {
103103
}
104104
}
105105

106-
async newSearchJob(queryParams) {
106+
async newSearchJob(_queryParams) {
107107
log('newSearchJob');
108108

109-
queryParams.timeZone = queryParams.timeZone || this.config.timezone;
110-
queryParams.from = moment(queryParams.from).tz(this.config.timezone).format();
111-
queryParams.to = moment(queryParams.to).tz(this.config.timezone).format();
109+
const queryParams = {
110+
query: _queryParams.query
111+
};
112+
113+
queryParams.from = moment(_queryParams.from).tz(this.config.timezone).format();
114+
queryParams.to = moment(_queryParams.to).tz(this.config.timezone).format();
115+
queryParams.timeZone = _queryParams.timeZone || this.config.timezone;
116+
117+
if (_queryParams.byReceiptTime === true || _queryParams.byReceiptTime === 'true') {
118+
queryParams.byReceiptTime = 'true';
119+
}
112120

113121
const requestParams = {
114122
method: 'post',

test/fixtures/01.js

Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
module.exports = [{
2+
scope: 'https://api.jp.sumologic.com:443',
3+
method: 'POST',
4+
path: '/api/v1/search/jobs',
5+
body: {
6+
query: 'sample_query',
7+
from: '2019-06-25T10:14:31+09:00',
8+
to: '2019-06-25T17:14:31+09:00',
9+
timeZone: 'Asia/Tokyo',
10+
byReceiptTime: 'true'
11+
},
12+
status: 202,
13+
response: {
14+
id: '750D3ABE4460BA73',
15+
link: {
16+
rel: 'self',
17+
href: 'https://api.jp.sumologic.com/api/v1/search/jobs/750D3ABE4460BA73'
18+
}
19+
},
20+
rawHeaders: [
21+
'Date',
22+
'Wed, 10 Jul 2019 04:10:36 GMT',
23+
'Content-Type',
24+
'application/json',
25+
'Transfer-Encoding',
26+
'chunked',
27+
'Connection',
28+
'close',
29+
'Set-Cookie',
30+
'AWSALB=Pxmydyk+9LMvAEfZH2h55jJve2ufmwdneWqzPcrul85wJo8SD0DoFmSBQIDhde3Sv1rp4Z/D3JXi7l0MLGtr0e1IhE6XhN8ihEAQoMPtEcPrJCRi7EYX0AJCS/03; Expires=Wed, 17 Jul 2019 04:10:36 GMT; Path=/',
31+
'Cache-Control',
32+
'no-cache, no-store, max-age=0, must-revalidate',
33+
'Pragma',
34+
'no-cache',
35+
'Expires',
36+
'Thu, 01 Jan 1970 00:00:00 GMT',
37+
'X-XSS-Protection',
38+
'1; mode=block',
39+
'X-Frame-Options',
40+
'DENY',
41+
'X-Content-Type-Options',
42+
'nosniff',
43+
'Set-Cookie',
44+
'JSESSIONID=node0z8u0k92qywg3ek8wy6br6dj2843.node0; Path=/api',
45+
'Location',
46+
'https://api.jp.sumologic.com/api/v1/search/jobs/750D3ABE4460BA73'
47+
]
48+
},
49+
{
50+
scope: 'https://api.jp.sumologic.com:443',
51+
method: 'GET',
52+
path: '/api/v1/search/jobs/750D3ABE4460BA73',
53+
body: '',
54+
status: 200,
55+
response: {
56+
state: 'DONE GATHERING RESULTS',
57+
histogramBuckets: [
58+
{
59+
startTimestamp: 1561425300000,
60+
length: 300000,
61+
count: 576
62+
},
63+
{
64+
startTimestamp: 1561425271000,
65+
length: 29000,
66+
count: 78
67+
}
68+
],
69+
messageCount: 3,
70+
recordCount: 0,
71+
pendingWarnings: [],
72+
pendingErrors: []
73+
},
74+
rawHeaders: [
75+
'Date',
76+
'Wed, 10 Jul 2019 04:10:36 GMT',
77+
'Content-Type',
78+
'application/json;charset=utf-8',
79+
'Transfer-Encoding',
80+
'chunked',
81+
'Connection',
82+
'close',
83+
'Set-Cookie',
84+
'AWSALB=G6vGpwo8A/C1Zu+1IpQU3WVBpYJqr+JToBZ0+s8l3EPYaePY5gVHxz8IJUTa1Mf/YdJnS09GFLakCjPP3v4z5CAqyObDcQTWUb+UI8ddmyxFEuSt+C7A8xApOZlm; Expires=Wed, 17 Jul 2019 04:10:36 GMT; Path=/',
85+
'Cache-Control',
86+
'no-cache, no-store, max-age=0, must-revalidate',
87+
'Pragma',
88+
'no-cache',
89+
'Expires',
90+
'Thu, 01 Jan 1970 00:00:00 GMT',
91+
'X-XSS-Protection',
92+
'1; mode=block',
93+
'X-Frame-Options',
94+
'DENY',
95+
'X-Content-Type-Options',
96+
'nosniff',
97+
'Set-Cookie',
98+
'JSESSIONID=node0shrdo704xzmy1sgazlho1l8z42840.node0; Path=/api',
99+
'Vary',
100+
'Accept-Encoding, User-Agent'
101+
]
102+
}, {
103+
scope: 'https://api.jp.sumologic.com:443',
104+
method: 'GET',
105+
path: '/api/v1/search/jobs/750D3ABE4460BA73/messages?offset=0&limit=50000',
106+
body: '',
107+
status: 200,
108+
response: {
109+
fields: [
110+
{
111+
name: 'sample-field',
112+
fieldType: 'long',
113+
keyField: false
114+
}
115+
],
116+
messages: [
117+
{
118+
map: {
119+
msg: 'message1'
120+
}
121+
},
122+
{
123+
map: {
124+
msg: 'message2'
125+
}
126+
},
127+
{
128+
map: {
129+
msg: 'message3'
130+
}
131+
}
132+
]
133+
},
134+
rawHeaders: [
135+
'Date',
136+
'Wed, 10 Jul 2019 04:10:36 GMT',
137+
'Content-Type',
138+
'application/json;charset=utf-8',
139+
'Transfer-Encoding',
140+
'chunked',
141+
'Connection',
142+
'close',
143+
'Set-Cookie',
144+
'AWSALB=TwtM7wDsw4K/kc52LbyjxJZNENNUeDU/t0/9NVDxUU/0EqLuCyor/Ym9eevsol1hl8BTFVnuVEIGxdkgM0mqzDEUHARpwhHjl8axm8NKxpJFYV+BMU9lyuLbMdXo; Expires=Wed, 17 Jul 2019 04:10:36 GMT; Path=/',
145+
'Cache-Control',
146+
'no-cache, no-store, max-age=0, must-revalidate',
147+
'Pragma',
148+
'no-cache',
149+
'Expires',
150+
'Thu, 01 Jan 1970 00:00:00 GMT',
151+
'X-XSS-Protection',
152+
'1; mode=block',
153+
'X-Frame-Options',
154+
'DENY',
155+
'X-Content-Type-Options',
156+
'nosniff',
157+
'Set-Cookie',
158+
'JSESSIONID=node013d6vnkzzyjexr2dcnemtws1d2841.node0; Path=/api',
159+
'Vary',
160+
'Accept-Encoding, User-Agent'
161+
]
162+
}, {
163+
scope: 'https://api.jp.sumologic.com:443',
164+
method: 'DELETE',
165+
path: '/api/v1/search/jobs/750D3ABE4460BA73',
166+
body: '',
167+
status: 200,
168+
response: {
169+
id: '750D3ABE4460BA73'
170+
},
171+
rawHeaders: [
172+
'Date',
173+
'Wed, 10 Jul 2019 04:10:37 GMT',
174+
'Content-Type',
175+
'application/json;charset=utf-8',
176+
'Transfer-Encoding',
177+
'chunked',
178+
'Connection',
179+
'close',
180+
'Set-Cookie',
181+
'AWSALB=lmcUMXglhcyc2AeVaWGWPZB9eWMxQ8VEJHBgZlUuqa37n5yLlvp01+7LL2Z8ghzQkm7CxmBlzW3u+Anhi5HwJIuMeJ/hDQFpM5Xw2dJNynVWe8sR0xO4QuR5yU4B; Expires=Wed, 17 Jul 2019 04:10:37 GMT; Path=/',
182+
'Cache-Control',
183+
'no-cache, no-store, max-age=0, must-revalidate',
184+
'Pragma',
185+
'no-cache',
186+
'Expires',
187+
'Thu, 01 Jan 1970 00:00:00 GMT',
188+
'X-XSS-Protection',
189+
'1; mode=block',
190+
'X-Frame-Options',
191+
'DENY',
192+
'X-Content-Type-Options',
193+
'nosniff',
194+
'Set-Cookie',
195+
'JSESSIONID=node0mkt2s73n3p8umrb4rofhd25a2842.node0; Path=/api'
196+
]
197+
}];

test/search.test.js

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,4 +206,72 @@ describe('search()', () => {
206206
});
207207
}
208208
});
209+
210+
test('it respects the byReceiptTime parameter', async () => {
211+
const requests = require('./fixtures/01.js');
212+
requests.forEach((req) => {
213+
const urlAndBody = [req.path];
214+
if (req.method === 'POST') {
215+
urlAndBody.push(JSON.stringify(req.body));
216+
}
217+
nock('https://api.jp.sumologic.com/')[req.method.toLowerCase()](...urlAndBody)
218+
.reply(...[req.status, req.response]);
219+
});
220+
221+
const client = createClient({ pollingDelay: 1 });
222+
const searchParams = {
223+
query: 'sample_query',
224+
from: '2019-06-25T10:14:31+09:00',
225+
to: '2019-06-25T17:14:31+09:00',
226+
byReceiptTime: true
227+
};
228+
const iterator = await client.getIterator(searchParams);
229+
for await (const response of iterator) {
230+
expect(response.state).toEqual({
231+
state: 'DONE GATHERING RESULTS',
232+
histogramBuckets: [
233+
{
234+
startTimestamp: 1561425300000,
235+
length: 300000,
236+
count: 576
237+
},
238+
{
239+
startTimestamp: 1561425271000,
240+
length: 29000,
241+
count: 78
242+
}
243+
],
244+
messageCount: 3,
245+
recordCount: 0,
246+
pendingWarnings: [],
247+
pendingErrors: []
248+
});
249+
expect(response.results).toEqual({
250+
fields: [
251+
{
252+
name: 'sample-field',
253+
fieldType: 'long',
254+
keyField: false
255+
}
256+
],
257+
messages: [
258+
{
259+
map: {
260+
msg: 'message1'
261+
}
262+
},
263+
{
264+
map: {
265+
msg: 'message2'
266+
}
267+
},
268+
{
269+
map: {
270+
msg: 'message3'
271+
}
272+
}
273+
]
274+
});
275+
}
276+
});
209277
});

0 commit comments

Comments
 (0)