Skip to content

Commit

Permalink
[STRATCONN-4130]- google sheets increase timeout (#2378)
Browse files Browse the repository at this point in the history
* [STRATCONN-4130]- google sheets increase timeout

* update description

* update generated types

* Increase MAX_CELLS

* update generated types

* use math.max of default time out, 30s

* [google-sheets] update limit condition

* update error

* update types

* uncomment unsafe hidden attribute on batch size

* revert changes to operations.ts

* Revert renaming of action

* revert diff

* update default batch size to 1001
  • Loading branch information
varadarajan-tw authored Sep 12, 2024
1 parent 53897b8 commit 2f343f7
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,12 @@ export interface Payload {
* Set as true to ensure Segment sends data to Google Sheets in batches. Please do not set to false.
*/
enable_batching?: boolean
/**
* The number of rows to write to the spreadsheet in a single batch. The value is determined by number of rows * columns that Segment can upload within 30s.
*/
batch_size: number
/**
* The number of bytes to write to the spreadsheet in a single batch. Limit is 2MB.
*/
batch_bytes: number
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ describe('Google Sheets', () => {
spreadsheet_id: 'spreadsheet_id',
spreadsheet_name: 'spreadsheet_name',
data_format: 'data_format',
fields: { column1: 'value1', column2: 'value2' }
fields: { column1: 'value1', column2: 'value2' },
batch_size: 1,
batch_bytes: 1
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ export const CONSTANTS = {
/**
* Based on benchmarks found while testing so we dont reach the timeout limit.
*/
MAX_CELLS: 300000
MAX_CELLS: 600000
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { Settings } from './generated-types'

import postSheet from './postSheet'
import postSheet2 from './postSheet2'
import { DEFAULT_REQUEST_TIMEOUT } from '@segment/actions-core'
interface RefreshTokenResponse {
access_token: string
scope: string
Expand Down Expand Up @@ -41,7 +42,8 @@ const destination: DestinationDefinition<Settings> = {
return {
headers: {
authorization: `Bearer ${auth?.accessToken}`
}
},
timeout: Math.max(30_000, DEFAULT_REQUEST_TIMEOUT) // 30 seconds.
}
},

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,23 @@ const action: ActionDefinition<Settings, Payload> = {
label: 'Batch Data to Google Sheets',
description: 'Set as true to ensure Segment sends data to Google Sheets in batches. Please do not set to false.',
default: true
},
batch_size: {
type: 'number',
label: 'Batch Size',
description:
'The number of rows to write to the spreadsheet in a single batch. The value is determined by number of rows * columns that Segment can upload within 30s.',
default: 1001,
required: true,
unsafe_hidden: true
},
batch_bytes: {
type: 'number',
label: 'Batch Bytes',
description: 'The number of bytes to write to the spreadsheet in a single batch. Limit is 2MB.',
default: 2000000, // 2MB,
required: true,
unsafe_hidden: true
}
},
perform: (request, { payload }) => {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,23 @@ const action: ActionDefinition<Settings, Payload> = {
label: 'Batch Data to Google Sheets',
description: 'Set as true to ensure Segment sends data to Google Sheets in batches. Please do not set to false.',
default: true
},
batch_size: {
type: 'number',
label: 'Batch Size',
description:
'The number of rows to write to the spreadsheet in a single batch. The value is determined by number of rows * columns that Segment can upload within 30s.',
default: 1001,
required: true,
unsafe_hidden: true
},
batch_bytes: {
type: 'number',
label: 'Batch Bytes',
description: 'The number of bytes to write to the spreadsheet in a single batch. Limit is 2MB.',
default: 2000000, // 2MB,
required: true,
unsafe_hidden: true
}
},
perform: (request, { payload, syncMode }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,11 @@ function processGetSpreadsheetResponse(
const numRows = response.values?.length

if (numRows * numColumns > CONSTANTS.MAX_CELLS) {
throw new IntegrationError('Sheet has reached maximum limit', 'INVALID_REQUEST_DATA', 400)
throw new IntegrationError(
`Sheet has reached maximum limit supported by Segment: ${CONSTANTS.MAX_CELLS} cells.`,
'INVALID_REQUEST_DATA',
400
)
}

const updateBatch: UpdateBatch[] = []
Expand Down

0 comments on commit 2f343f7

Please sign in to comment.