Skip to content

Commit 8163326

Browse files
authored
Fix/domain list next page token (#393)
* moving nextPageToken parsing into bodyTransform and responseTransform layer * adding null check * cleanup console log * reduce domain list page size now that pagination is properly fixed. * fixed breaking unit test * refactoring combine function to switch argument positions. reuse cliTransform. rename w next page token request transform. * removing unused function * removing special condition checks * removing unused function * fixing integration tests * removing responseTransform for ListDomains * refactoring code for nextPageToken for all places used in node server. This is replaced with 1 common bodyTransform function. * removing debug log
1 parent 33cee0e commit 8163326

File tree

18 files changed

+89
-48
lines changed

18 files changed

+89
-48
lines changed

client/containers/domain-autocomplete/getters.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ const getters = {
5050
domainList,
5151
});
5252

53-
return combine(combinedDomainList)(
53+
return combine(
5454
sortDomainList,
5555
filterTopDomainList,
5656
formatDomainList
57-
);
57+
)(combinedDomainList);
5858
},
5959
[DOMAIN_AUTOCOMPLETE_DOMAIN_LIST]: state =>
6060
sortDomainList(get(state, statePrefix('domainList')) || []),

client/helpers/combine.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2020
// THE SOFTWARE.
2121

22-
const combine = data => (...callbacks) =>
22+
const combine = (...callbacks) => data =>
2323
callbacks.reduce(
2424
(accumulator, callback) => (accumulator = callback(accumulator)),
2525
data
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2020
// THE SOFTWARE.
2121

22-
const combine = data => (...callbacks) =>
22+
const combine = (...callbacks) => data =>
2323
callbacks.reduce(
2424
(accumulator, callback) => (accumulator = callback(accumulator)),
2525
data

server/helpers/index.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright (c) 2021 Uber Technologies Inc.
2+
//
3+
//
4+
// Permission is hereby granted, free of charge, to any person obtaining a copy
5+
// of this software and associated documentation files (the "Software"), to deal
6+
// in the Software without restriction, including without limitation the rights
7+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
// copies of the Software, and to permit persons to whom the Software is
9+
// furnished to do so, subject to the following conditions:
10+
//
11+
// The above copyright notice and this permission notice shall be included in
12+
// all copies or substantial portions of the Software.
13+
//
14+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20+
// THE SOFTWARE.
21+
22+
const combine = require('./combine');
23+
24+
module.exports = {
25+
combine,
26+
};

server/middleware/tchannel-client/helpers/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ const lookupAsync = require('./lookup-async');
2727
const makeChannels = require('./make-channels');
2828
const makeRequest = require('./make-request');
2929
const uiTransform = require('./ui-transform');
30-
const withDomainPagingAndWorkflowExecution = require('./with-domain-paging-and-workflow-execution');
3130
const withDomainPaging = require('./with-domain-paging');
31+
const withNextPageTokenBodyTransform = require('./with-next-page-token-body-transform');
3232
const withVerboseWorkflowExecution = require('./with-verbose-workflow-execution');
3333
const withWorkflowExecution = require('./with-workflow-execution');
3434

@@ -41,8 +41,8 @@ module.exports = {
4141
makeChannels,
4242
makeRequest,
4343
uiTransform,
44-
withDomainPagingAndWorkflowExecution,
4544
withDomainPaging,
45+
withNextPageTokenBodyTransform,
4646
withVerboseWorkflowExecution,
4747
withWorkflowExecution,
4848
};

server/middleware/tchannel-client/helpers/make-request.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,14 @@ const formatBody = require('./format-body');
2323
const formatMethod = require('./format-method');
2424
const formatRequestName = require('./format-request-name');
2525
const uiTransform = require('./ui-transform');
26+
const withNextPageTokenBodyTransform = require('./with-next-page-token-body-transform');
2627

2728
const makeRequest = ({ authTokenHeaders, channels, ctx, requestConfig }) => ({
28-
bodyTransform,
29+
bodyTransform = withNextPageTokenBodyTransform,
2930
channelName = 'cadence',
3031
method,
3132
requestName,
32-
responseTransform,
33+
responseTransform = uiTransform,
3334
serviceName = 'WorkflowService',
3435
}) => body =>
3536
new Promise((resolve, reject) => {
@@ -50,7 +51,7 @@ const makeRequest = ({ authTokenHeaders, channels, ctx, requestConfig }) => ({
5051
if (error) {
5152
reject(error);
5253
} else if (response.ok) {
53-
resolve((responseTransform || uiTransform)(response.body));
54+
resolve(responseTransform(response.body));
5455
} else {
5556
ctx.throw(
5657
response.typeName === 'entityNotExistError' ? 404 : 400,

server/middleware/tchannel-client/helpers/with-domain-paging-and-workflow-execution.js renamed to server/middleware/tchannel-client/helpers/with-next-page-token-body-transform.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,18 @@
1919
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2020
// THE SOFTWARE.
2121

22-
const withDomainPaging = require('./with-domain-paging');
23-
const withWorkflowExecution = require('./with-workflow-execution');
22+
const withNextPageTokenBodyTransform = body => {
23+
if (!body || typeof body !== 'object') {
24+
return body;
25+
}
2426

25-
const withDomainPagingAndWorkflowExecution = ctx => body =>
26-
Object.assign(withDomainPaging(ctx)(body), withWorkflowExecution(ctx)(body));
27+
const { nextPageToken } = body;
2728

28-
module.exports = withDomainPagingAndWorkflowExecution;
29+
body.nextPageToken = nextPageToken
30+
? Buffer.from(nextPageToken, 'base64')
31+
: undefined;
32+
33+
return body;
34+
};
35+
36+
module.exports = withNextPageTokenBodyTransform;

server/middleware/tchannel-client/index.js

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,16 @@
2323

2424
const TChannel = require('tchannel');
2525

26+
const { combine } = require('../../helpers');
27+
2628
const {
2729
cliTransform,
2830
makeChannels,
2931
makeRequest,
3032
withDomainPaging,
33+
withNextPageTokenBodyTransform,
3134
withWorkflowExecution,
3235
withVerboseWorkflowExecution,
33-
withDomainPagingAndWorkflowExecution,
3436
} = require('./helpers');
3537

3638
const tchannelClient = ({ peers, requestConfig }) =>
@@ -50,12 +52,18 @@ const tchannelClient = ({ peers, requestConfig }) =>
5052
archivedWorkflows: request({
5153
method: 'ListArchivedWorkflowExecutions',
5254
requestName: 'list',
53-
bodyTransform: withDomainPaging(ctx),
55+
bodyTransform: combine(
56+
withDomainPaging(ctx),
57+
withNextPageTokenBodyTransform
58+
),
5459
}),
5560
closedWorkflows: request({
5661
method: 'ListClosedWorkflowExecutions',
5762
requestName: 'list',
58-
bodyTransform: withDomainPaging(ctx),
63+
bodyTransform: combine(
64+
withDomainPaging(ctx),
65+
withNextPageTokenBodyTransform
66+
),
5967
}),
6068
describeCluster: request({
6169
channelName: 'admin',
@@ -78,13 +86,21 @@ const tchannelClient = ({ peers, requestConfig }) =>
7886
exportHistory: request({
7987
method: 'GetWorkflowExecutionHistory',
8088
requestName: 'get',
81-
bodyTransform: withDomainPagingAndWorkflowExecution(ctx),
89+
bodyTransform: combine(
90+
withDomainPaging(ctx),
91+
withWorkflowExecution(ctx),
92+
withNextPageTokenBodyTransform
93+
),
8294
responseTransform: cliTransform,
8395
}),
8496
getHistory: request({
8597
method: 'GetWorkflowExecutionHistory',
8698
requestName: 'get',
87-
bodyTransform: withDomainPagingAndWorkflowExecution(ctx),
99+
bodyTransform: combine(
100+
withDomainPaging(ctx),
101+
withWorkflowExecution(ctx),
102+
withNextPageTokenBodyTransform
103+
),
88104
}),
89105
listDomains: request({
90106
method: 'ListDomains',
@@ -96,12 +112,18 @@ const tchannelClient = ({ peers, requestConfig }) =>
96112
listWorkflows: request({
97113
method: 'ListWorkflowExecutions',
98114
requestName: 'list',
99-
bodyTransform: withDomainPaging(ctx),
115+
bodyTransform: combine(
116+
withDomainPaging(ctx),
117+
withNextPageTokenBodyTransform
118+
),
100119
}),
101120
openWorkflows: request({
102121
method: 'ListOpenWorkflowExecutions',
103122
requestName: 'list',
104-
bodyTransform: withDomainPaging(ctx),
123+
bodyTransform: combine(
124+
withDomainPaging(ctx),
125+
withNextPageTokenBodyTransform
126+
),
105127
}),
106128
queryWorkflow: request({
107129
method: 'QueryWorkflow',

server/router/helpers/index.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
// THE SOFTWARE.
2121

2222
const buildQueryString = require('./build-query-string');
23-
const combine = require('./combine');
2423
const delay = require('./delay');
2524
const injectDomainIntoWorkflowList = require('./inject-domain-into-workflow-list');
2625
const isAdvancedVisibilityEnabled = require('./is-advanced-visibility-enabled');
@@ -31,7 +30,6 @@ const replacer = require('./replacer');
3130

3231
module.exports = {
3332
buildQueryString,
34-
combine,
3533
delay,
3634
injectDomainIntoWorkflowList,
3735
isAdvancedVisibilityEnabled,

server/router/helpers/list-workflows.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ async function listWorkflows({ clusterService, state }, ctx) {
4747
const earliestTime = momentToLong(startTime);
4848
const latestTime = momentToLong(endTime);
4949
const { nextPageToken, status, workflowId, workflowName } = query;
50-
const nextPageTokenBuffer =
51-
nextPageToken && Buffer.from(nextPageToken, 'base64');
5250

5351
const requestArgs = advancedVisibility
5452
? {
@@ -65,7 +63,7 @@ async function listWorkflows({ clusterService, state }, ctx) {
6563
...(workflowName && { typeFilter: { name: workflowName } }),
6664
...(workflowId && { executionFilter: { workflowId } }),
6765
...(status && { statusFilter: status }),
68-
...(nextPageTokenBuffer && { nextPageToken: nextPageTokenBuffer }),
66+
nextPageToken,
6967
};
7068

7169
const requestApi = advancedVisibility ? 'listWorkflows' : state + 'Workflows';

0 commit comments

Comments
 (0)