-
Notifications
You must be signed in to change notification settings - Fork 14
[Draft] [MWPW-179252] Add pageConfig call for optimal endpoint #569
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: stage
Are you sure you want to change the base?
Changes from 10 commits
e207af4
eda0c0f
d06c44d
5c4620b
dc8853c
2b8696c
a83defa
20b2848
0066bc6
90aac4c
397fce2
e1e7082
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -109,6 +109,7 @@ export default class ActionBinder { | |
| upload_warn_delete_asset: -603, | ||
| validation_warn_validate_files: -604, | ||
| warn_fetch_experiment: -605, | ||
| warn_page_config_call_failed: -606, | ||
| }; | ||
|
|
||
| static NEW_TO_OLD_ERROR_KEY_MAP = { | ||
|
|
@@ -215,13 +216,17 @@ export default class ActionBinder { | |
| }); | ||
| } | ||
|
|
||
| getAcrobatApiConfig() { | ||
| unityConfig.acrobatEndpoint = { | ||
| createAsset: `${unityConfig.apiEndPoint}/asset`, | ||
| finalizeAsset: `${unityConfig.apiEndPoint}/asset/finalize`, | ||
| getMetadata: `${unityConfig.apiEndPoint}/asset/metadata`, | ||
| getAcrobatApiConfig(newAPIEndpoint) { | ||
| const apiEndPoint = newAPIEndpoint || unityConfig.apiEndPoint; | ||
| return { | ||
| acrobatEndpoint: { | ||
| createAsset: `${apiEndPoint}/asset`, | ||
| finalizeAsset: `${apiEndPoint}/asset/finalize`, | ||
| getMetadata: `${apiEndPoint}/asset/metadata`, | ||
| connector: `${apiEndPoint}/asset/connector`, | ||
| log: `${apiEndPoint}/log`, | ||
| }, | ||
| }; | ||
| return unityConfig; | ||
| } | ||
|
|
||
| getAdditionalHeaders() { | ||
|
|
@@ -281,6 +286,7 @@ export default class ActionBinder { | |
| subCode: ActionBinder.ERROR_MAP[errorMetaData.subCode] || errorMetaData.subCode || status, | ||
| desc: errorMetaData.desc || message || info || undefined, | ||
| }, | ||
| logEndPoint: this.acrobatApiConfig?.acrobatEndpoint?.log, | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. slytherin (dc) side changes corresponding to this are in PR: |
||
| sendToSplunk, | ||
| }, | ||
| }, | ||
|
|
@@ -289,7 +295,7 @@ export default class ActionBinder { | |
|
|
||
| async dispatchAnalyticsEvent(eventName, data = null) { | ||
| const sendToSplunk = this.workflowCfg.targetCfg.sendSplunkAnalytics; | ||
| const detail = { event: eventName, ...(data && { data }), sendToSplunk }; | ||
| const detail = { event: eventName, ...(data && { data }), logEndPoint: this.acrobatApiConfig?.acrobatEndpoint?.log, sendToSplunk }; | ||
| this.block.dispatchEvent(new CustomEvent(unityConfig.trackAnalyticsEvent, { detail })); | ||
| } | ||
|
|
||
|
|
@@ -426,7 +432,7 @@ export default class ActionBinder { | |
| const postOpts = await getApiCallOptions('POST', unityConfig.apiKey, this.getAdditionalHeaders() || {}, { body: JSON.stringify(cOpts) }); | ||
| this.promiseStack.push( | ||
| this.networkUtils.fetchFromServiceWithRetry( | ||
| this.acrobatApiConfig.connectorApiEndPoint, | ||
| this.acrobatApiConfig.acrobatEndpoint.connector, | ||
| postOpts, | ||
| ), | ||
| ); | ||
|
|
@@ -511,6 +517,7 @@ export default class ActionBinder { | |
| const { isValid, validFiles } = await this.validateFiles(sanitizedFiles); | ||
| if (!isValid) return; | ||
| await this.initUploadHandler(); | ||
| await this.ensureOptimalEndpoint(); | ||
| if (files.length === 1 || (validFiles.length === 1 && !verbsWithoutFallback.includes(this.workflowCfg.enabledFeatures[0]))) { | ||
| await this.handleSingleFileUpload(validFiles); | ||
| } else { | ||
|
|
@@ -682,6 +689,25 @@ export default class ActionBinder { | |
| this.filesData.assetId = assetId; | ||
| } | ||
|
|
||
| async ensureOptimalEndpoint() { | ||
| if (this.pageConfigPromise) { | ||
| await this.pageConfigPromise; | ||
| } | ||
| } | ||
|
|
||
| async checkandUpdatePageConfigEndpoint() { | ||
| await this.networkUtils.checkandUpdatePageConfigEndpoint( | ||
| (newEndpoint) => { | ||
| // send analytics event before updating the endpoint, where the pageConfig call is made. | ||
|
vipu0303 marked this conversation as resolved.
Outdated
|
||
| this.dispatchAnalyticsEvent('pageConfigUpdated', { newEndpoint }); | ||
| this.acrobatApiConfig = this.getAcrobatApiConfig(newEndpoint); | ||
| }, | ||
| (failure) => { | ||
| this.dispatchErrorToast('warn_page_config_call_failed', null, null, true, true, { code: 'warn_page_config_call_failed', subCode: failure?.status, desc: failure?.type }); | ||
| }, | ||
| ); | ||
| } | ||
|
|
||
| async initActionListeners(b = this.block, actMap = this.actionMap) { | ||
| for (const [key, value] of Object.entries(actMap)) { | ||
| const el = b.querySelector(key); | ||
|
|
@@ -714,5 +740,8 @@ export default class ActionBinder { | |
| if (b === this.block) { | ||
| this.loadTransitionScreen(); | ||
| } | ||
| if (!this.pageConfigPromise) { | ||
| this.pageConfigPromise = this.checkandUpdatePageConfigEndpoint(); | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,3 +1,5 @@ | ||||||
| import { unityConfig, getApiCallOptions } from '../scripts/utils.js'; | ||||||
|
|
||||||
| export default class NetworkUtils { | ||||||
| handleAbortedRequest(url, options) { | ||||||
| if (!(options?.signal?.aborted)) return; | ||||||
|
|
@@ -151,4 +153,30 @@ export default class NetworkUtils { | |||||
| throw error; | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| async checkandUpdatePageConfigEndpoint(updateConfigCallback, onFailure) { | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. updated the name to fetchPageConfig. |
||||||
| try { | ||||||
| const TIMEOUT_MS = 5000; | ||||||
| const getOpts = await getApiCallOptions('GET', unityConfig.apiKey, {}, {}); | ||||||
|
vipu0303 marked this conversation as resolved.
Outdated
|
||||||
| const pageConfigUrl = `${unityConfig.apiEndPoint}/pageConfig`; | ||||||
|
vipu0303 marked this conversation as resolved.
Outdated
|
||||||
| const pageConfigResponse = await this.fetchWithTimeout(pageConfigUrl, getOpts, TIMEOUT_MS); | ||||||
| if (pageConfigResponse.ok) { | ||||||
| const locationHeader = pageConfigResponse.headers.get('location'); | ||||||
| if (locationHeader) { | ||||||
| const newEndpoint = `${locationHeader}/api/v1`; | ||||||
| if (typeof updateConfigCallback === 'function') updateConfigCallback(newEndpoint); | ||||||
| return; | ||||||
| } | ||||||
| console.warn('No location header found, keeping existing API endpoint'); | ||||||
|
vipu0303 marked this conversation as resolved.
Outdated
|
||||||
| if (typeof onFailure === 'function') onFailure({ type: 'no-location-header', status: pageConfigResponse.status }); | ||||||
| return; | ||||||
| } | ||||||
| console.error('pageConfig call failed with status:', pageConfigResponse.status); | ||||||
|
vipu0303 marked this conversation as resolved.
Outdated
|
||||||
| if (typeof onFailure === 'function') onFailure({ type: 'non-ok-status', status: pageConfigResponse.status }); | ||||||
| return; | ||||||
| } catch (error) { | ||||||
| console.error('pageConfig call failed with error:', error); | ||||||
|
vipu0303 marked this conversation as resolved.
Outdated
|
||||||
| if (typeof onFailure === 'function') onFailure({ type: `Network-error - ${error.message}` }); | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
check if the dashboard query needs modification to start recording this. Actual modification to be done after the PR merge
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, it may need dashboard modifications.