-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #253 from Uniswap/parallelize-read
feat: update firehose client to use aws v3 sdk
- Loading branch information
Showing
5 changed files
with
729 additions
and
205 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,40 @@ | ||
import { Firehose } from 'aws-sdk'; | ||
import { AnalyticsEvent } from '../../entities/analytics-events'; | ||
import { FirehoseClient, PutRecordCommand } from '@aws-sdk/client-firehose'; | ||
import { default as Logger } from 'bunyan'; | ||
|
||
import { IAnalyticsLogger } from '.'; | ||
import { AnalyticsEvent } from '../../entities/analytics-events'; | ||
|
||
export class FirehoseLogger implements IAnalyticsLogger { | ||
private log: Logger; | ||
private readonly streamName: string; | ||
private readonly firehose: Firehose; | ||
private readonly firehose: FirehoseClient; | ||
|
||
constructor(_log: Logger, streamArn: string) { | ||
this.log = _log; | ||
// Split the streamArn to extract the streamName | ||
const streamArnParts = streamArn.split('/'); | ||
|
||
if (streamArnParts.length !== 2) { | ||
this.log.error( | ||
{ streamArn: streamArn }, | ||
`Firehose client error parsing stream from ${streamArn}.` | ||
); | ||
this.log.error({ streamArn: streamArn }, `Firehose client error parsing stream from ${streamArn}.`); | ||
} | ||
|
||
this.streamName = streamArnParts[1]; | ||
this.firehose = new Firehose(); | ||
this.firehose = new FirehoseClient(); | ||
} | ||
|
||
async sendAnalyticsEvent(analyticsEvent: AnalyticsEvent): Promise<void> { | ||
const jsonString = JSON.stringify(analyticsEvent) + '\n'; | ||
const params = { | ||
DeliveryStreamName: this.streamName, | ||
Record: { | ||
Data: jsonString, | ||
Data: Buffer.from(jsonString, 'base64'), | ||
}, | ||
}; | ||
|
||
try { | ||
await this.firehose.putRecord(params).promise(); | ||
await this.firehose.send(new PutRecordCommand(params)); | ||
} catch (error) { | ||
this.log.error( | ||
{ streamName: this.streamName }, | ||
`Firehose client error putting record. ${error}` | ||
); | ||
this.log.error({ streamName: this.streamName }, `Firehose client error putting record. ${error}`); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.