Skip to content
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

channels-1094 #2024

Closed
wants to merge 73 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
28db0aa
refactor: Refactoring the name for dataFeedCache to be
cogwizzle May 3, 2024
cf0b33d
fix: Changing the variable name back.
cogwizzle May 3, 2024
5496895
chore: Linter.
cogwizzle May 9, 2024
b792860
chore: Minor tweak to syntax to make it more clear.
cogwizzle May 9, 2024
4899aeb
feat: Adding cache logic to message send performer.
cogwizzle May 9, 2024
8ee70f6
refactor: Renaming maxResponseSizeBytes to maxValueSizeBytes.
cogwizzle May 15, 2024
b478bf1
refactor: Only storing status code instead of full response.
cogwizzle May 15, 2024
255dba8
feat: Adding property retry to CustomError.
cogwizzle May 16, 2024
837380f
feat: Changing the downstream logic to support partial DA successes.
cogwizzle May 16, 2024
a616a3f
fix: Type mismatch.
cogwizzle May 21, 2024
e758ce1
Merge branch 'main' of ssh://github.com/segmentio/action-destinations…
cogwizzle May 31, 2024
631df68
fix: Fixing construction of the EngageActionPerformer.
cogwizzle Jun 6, 2024
3244334
fix: Attempt to update type issue.
cogwizzle Jun 6, 2024
7ddc631
Merge branch 'main' of ssh://github.com/segmentio/action-destinations…
cogwizzle Jun 17, 2024
522a103
fix: Fixing type issue.
cogwizzle Jun 17, 2024
2d5c75f
chore: Updating the core version.
cogwizzle Jun 17, 2024
b8a48fd
Merge branch 'main' of ssh://github.com/segmentio/action-destinations…
cogwizzle Jun 26, 2024
3221f34
feat: Updating the actions-core package.
cogwizzle Jun 26, 2024
761b0b9
Merge branch 'main' of ssh://github.com/segmentio/action-destinations…
cogwizzle Jun 27, 2024
f5a2997
feat: Creating a canary script so that publishing canary versions of the
cogwizzle Jun 27, 2024
6f55f20
Merge branch 'main' of ssh://github.com/segmentio/action-destinations…
cogwizzle Jun 27, 2024
26faeb8
feat: Updating test utilities to be easier to use.
cogwizzle Jun 27, 2024
f7cc09c
fix: Adding engageDestinationCache that won't break the test.
cogwizzle Jun 27, 2024
1a7fcab
fix: Updating the max bundle size.
cogwizzle Jun 28, 2024
e6d18de
feat: Increasing the size limit.
cogwizzle Jun 28, 2024
5c86514
fix: Updating broken test.
cogwizzle Jun 28, 2024
7982eb9
feat: Implementing a more simple serialization than JSON as to not block
cogwizzle Jul 8, 2024
47e6208
feat: Adding an info message that tracks if the cache was able to find
cogwizzle Jul 8, 2024
121afa9
Merge branch 'main' of ssh://github.com/segmentio/action-destinations…
cogwizzle Jul 8, 2024
605cd2f
fix: Fixing a type issue with the MessageSendPerformer and the
cogwizzle Jul 8, 2024
fcb020b
feat: Updating yarn file.
cogwizzle Jul 8, 2024
83a201b
feat: Adding logging for caching and reloading from the cache.
cogwizzle Jul 10, 2024
72217d7
fix: Fixing dependency.
cogwizzle Jul 10, 2024
3eb5fda
Merge branch 'main' of ssh://github.com/segmentio/action-destinations…
cogwizzle Jul 16, 2024
516921b
chore: Updating package.
cogwizzle Jul 16, 2024
4ea3d45
chore: canary.
cogwizzle Jul 16, 2024
779c533
feat: Updating the actions-core to new canary build.
cogwizzle Jul 16, 2024
4572060
fix: Attempting to update dependencies.
cogwizzle Jul 17, 2024
a54ae36
fix: Revering change.
cogwizzle Jul 17, 2024
e8e52e6
feat: Updating the shared package.
cogwizzle Jul 17, 2024
5e59f18
Merge branch 'main' of ssh://github.com/segmentio/action-destinations…
cogwizzle Jul 18, 2024
b22ecf5
feat: Yarn.lock.
cogwizzle Jul 18, 2024
cccddf9
fix: Empty message. I hate lerna.
cogwizzle Jul 18, 2024
7ef8179
Merge branch 'main' of ssh://github.com/segmentio/action-destinations…
cogwizzle Jul 22, 2024
8b77355
chore: Updating version of core.
cogwizzle Jul 22, 2024
5357d3f
fix: Fixing serialization bugs so that the cache works as expected.
cogwizzle Jul 24, 2024
a9d8806
chore: Updating version.
cogwizzle Jul 24, 2024
d970343
Merge branch 'main' of ssh://github.com/segmentio/action-destinations…
cogwizzle Jul 24, 2024
f960e80
chore: Updating verison.
cogwizzle Jul 24, 2024
745cf43
chore: Updating core.
cogwizzle Jul 24, 2024
1aa9695
chore: Updating lock.
cogwizzle Jul 24, 2024
0adc2ac
refactor: Updating plain text.
cogwizzle Jul 24, 2024
8ce1549
chore: Adding logging for better debugging.
cogwizzle Jul 24, 2024
c1d40d2
chore: Updating packages.
cogwizzle Jul 24, 2024
0d450e2
Merge branch 'main' of ssh://github.com/segmentio/action-destinations…
cogwizzle Jul 26, 2024
90ee709
feat: Adding additional logging.
cogwizzle Jul 26, 2024
04c4575
chore: Update the version.
cogwizzle Jul 26, 2024
c76c722
Merge remote-tracking branch 'origin/main' into channels-1094
cogwizzle Aug 20, 2024
3df6a9b
channels-1200 fixing stats for Channels-1094 (#2316)
pmunin Aug 20, 2024
79518a7
fix: Reverting package.json.
cogwizzle Aug 20, 2024
2bc39ce
Merge branch 'channels-1094' of ssh://github.com/segmentio/action-des…
cogwizzle Aug 20, 2024
c0a27d4
fix: Fixing duplicate commands.
cogwizzle Aug 20, 2024
c7b272e
fix: Reverting webpack change.
cogwizzle Aug 20, 2024
42da15a
fix: Reverting change.
cogwizzle Aug 20, 2024
591c5b9
reverting irrelevant changes
pmunin Aug 15, 2024
f60d4e2
Merge remote-tracking branch 'refs/remotes/origin/channels-1094' into…
pmunin Aug 20, 2024
41c9de1
reverting irrelevant changes
pmunin Aug 15, 2024
ad7298c
fix: Reverting changes.
cogwizzle Aug 20, 2024
e0e4c4c
Merge branch 'channels-1094' of ssh://github.com/segmentio/action-des…
cogwizzle Aug 20, 2024
5222383
fix: Reverting changes.
cogwizzle Aug 20, 2024
133d08a
fix: Reverting changes.
cogwizzle Aug 20, 2024
b6ada52
fix: Reverting changes.
cogwizzle Aug 20, 2024
55225b0
Merge remote-tracking branch 'origin/main' into channels-1094
pmunin Aug 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ The `perform` method accepts two arguments, (1) the request client instance (ext
- `features` - The features available in the request based on the customer's sourceID. Features can only be enabled and/or used by internal Twilio/Segment employees. Features cannot be used for Partner builds.
- `statsContext` - An object, containing a `statsClient` and `tags`. Stats can only be used by internal Twilio/Segment employees. Stats cannot be used for Partner builds.
- `logger` - Logger can only be used by internal Twilio/Segment employees. Logger cannot be used for Partner builds.
- `dataFeedCache` - DataFeedCache can only be used by internal Twilio/Segment employees. DataFeedCache cannot be used for Partner builds.
- `engageDestinationCache` - EngageDestinationCache can only be used by internal Twilio/Segment employees. EngageDestinationCache should not be used for Partner builds.
- `transactionContext` - An object, containing transaction variables and a method to update transaction variables which are required for few segment developed actions. Transaction Context cannot be used for Partner builds.
- `stateContext` - An object, containing context variables and a method to get and set context variables which are required for few segment developed actions. State Context cannot be used for Partner builds.

Expand Down
62 changes: 62 additions & 0 deletions packages/actions-shared/src/engage/utils/CachedResponse.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
export enum CachedResponseType {
Success = 0,
Error = 1
}

export class CachedValueSerializationError extends Error {
constructor(message: string) {
super(message)
this.name = 'CachedValueSerializationError'
}
}

export class CachedValue {
public status: number
public type: CachedResponseType
protected seperator = ':-:'

constructor(status: number) {
this.status = status
this.type = CachedResponseType.Success
}

serialize(): string {
return `${this.type}${this.seperator}${this.status}`
}
}

export class CachedError extends CachedValue {
public message: string
public code: string
constructor(status: number, message: string, code: string) {
super(status)
this.type = CachedResponseType.Error
this.code = code
this.message = message
}

serialize(): string {
return `${super.serialize()}${this.seperator}${this.message}${this.seperator}${this.code}`
}
}

export class CachedValueFactory {
public static fromString(value: string): CachedValue | CachedError {
const parts = value.split(':-:')
if (parts.length < 2) {
throw new CachedValueSerializationError(`Invalid cached value ${value}`)
}
const [type, status] = parts
if (CachedResponseType.Success === +type) {
return new CachedValue(+status)
} else if (CachedResponseType.Error === +type) {
if (parts.length < 4) {
throw new CachedValueSerializationError(`Invalid cached value ${value}`)
}
const [message, code] = parts.slice(2)
return new CachedError(+status, message, code)
} else {
throw new CachedValueSerializationError(`Invalid cached value ${value}`)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { RequestClient } from '@segment/actions-core/create-request-client'
import { ExecuteInput } from '@segment/actions-core/destination-kit'
import { EngageDestinationCache, ExecuteInput } from '@segment/actions-core/destination-kit'
import { MaybePromise } from '@segment/actions-core/destination-kit/types'
import { EngageLogger } from './EngageLogger'
import { EngageStats } from './EngageStats'
Expand All @@ -17,9 +17,9 @@ import truncate from 'lodash/truncate'
* Base class for all Engage Action Performers. Supplies common functionality like logger, stats, request, operation tracking
*/
export abstract class EngageActionPerformer<TSettings = any, TPayload = any, TReturn = any> {
readonly logger: EngageLogger = new EngageLogger(this)
readonly statsClient: EngageStats = new EngageStats(this)
readonly dataFeedCache = this.executeInput.dataFeedCache
readonly logger: EngageLogger
readonly statsClient: EngageStats
readonly engageDestinationCache: EngageDestinationCache | undefined
readonly currentOperation: OperationContext | undefined

readonly payload: TPayload
Expand All @@ -28,6 +28,9 @@ export abstract class EngageActionPerformer<TSettings = any, TPayload = any, TRe
constructor(readonly requestClient: RequestClient, readonly executeInput: ExecuteInput<TSettings, TPayload>) {
this.payload = executeInput.payload
this.settings = executeInput.settings
this.engageDestinationCache = executeInput.engageDestinationCache
this.logger = new EngageLogger(this)
this.statsClient = new EngageStats(this)
}

beforePerform?(): void | Promise<void>
Expand Down
17 changes: 1 addition & 16 deletions packages/actions-shared/src/engage/utils/EngageStats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,6 @@ export class EngageStats extends OperationStats {

onTry(ctx: OperationStatsContext): () => void {
const res = super.onTry(ctx)
ctx.sharedContext.tags.push(
`space_id:${this.actionPerformer.settings.spaceId}`,
`projectid:${this.actionPerformer.settings.sourceId}`,
`computation_id:${this.actionPerformer.payload.segmentComputationId}`,
`settings_region:${this.actionPerformer.settings.region}`,
`channel:${this.actionPerformer.getChannelType()}`
)
const correlation_id =
this.actionPerformer.payload.customArgs?.correlation_id ||
this.actionPerformer.payload.customArgs?.__segment_internal_correlation_id__
if (correlation_id) ctx.sharedContext.tags.push(`correlation_id:${correlation_id}`)

//for operations like request which can be used in multiple places, we need to have operation_path tag that will show where this operation is invoked from
const parentOperation = (ctx as OperationContext).parent
Expand All @@ -58,7 +47,6 @@ export class EngageStats extends OperationStats {
stats(statsArgs: StatsArgs): void {
if (!this.statsClient) return
const { method: statsMethod, metric, value, tags } = statsArgs
//[statsArgs.method, statsArgs.metric, statsArgs.value, statsArgs.tags]
let statsFunc = this.statsClient?.[statsMethod || 'incr'].bind(this.statsClient)
if (!statsFunc)
switch (
Expand All @@ -68,23 +56,20 @@ export class EngageStats extends OperationStats {
case 'incr':
statsFunc = this.statsClient?.incr.bind(this.statsClient)
break
break
case 'histogram':
statsFunc = this.statsClient?.histogram.bind(this.statsClient)
break
break
case 'set':
statsFunc = this.statsClient?.set.bind(this.statsClient)
break
break
default:
break
}

statsFunc?.(
`${this.actionPerformer.getIntegrationStatsName()}.${metric}`,
typeof value === 'undefined' ? 1 : value,
[...(this.actionPerformer.executeInput.statsContext?.tags || []), ...(tags ?? [])]
this.mergeTags(this.actionPerformer.executeInput.statsContext?.tags, tags)
)
}

Expand Down
Loading
Loading