-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow option set agent replica time (#923)
Adds a new feature to set and read a specified replicaTime on the HttpAgent Also improves the error handling for replica time errors
- Loading branch information
Showing
14 changed files
with
260 additions
and
37 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
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
3 changes: 3 additions & 0 deletions
3
packages/agent/src/agent/http/__snapshots__/calculateReplicaTime.test.ts.snap
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`calculateReplicaTime 1`] = `2024-08-13T22:49:30.148Z`; |
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { calculateReplicaTime } from './calculateReplicaTime'; | ||
const exampleMessage = `Specified ingress_expiry not within expected range: Minimum allowed expiry: 2024-08-13 22:49:30.148075776 UTC, Maximum allowed expiry: 2024-08-13 22:55:00.148075776 UTC, Provided expiry: 2021-01-01 00:04:00 UTC`; | ||
|
||
test('calculateReplicaTime', () => { | ||
const parsedTime = calculateReplicaTime(exampleMessage); | ||
expect(parsedTime).toMatchSnapshot(); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/** | ||
* Parse the expiry from the message | ||
* @param message an error message | ||
* @returns diff in milliseconds | ||
*/ | ||
export const calculateReplicaTime = (message: string): Date => { | ||
const [min, max] = message.split('UTC'); | ||
|
||
const minsplit = min.trim().split(' ').reverse(); | ||
|
||
const minDateString = `${minsplit[1]} ${minsplit[0]} UTC`; | ||
|
||
const maxsplit = max.trim().split(' ').reverse(); | ||
|
||
const maxDateString = `${maxsplit[1]} ${maxsplit[0]} UTC`; | ||
|
||
return new Date(minDateString); | ||
}; | ||
|
||
function midwayBetweenDates(date1: Date, date2: Date) { | ||
return new Date((date1.getTime() + date2.getTime()) / 2); | ||
} |
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,10 +1,27 @@ | ||
import { HttpAgent } from '.'; | ||
import { AgentError } from '../../errors'; | ||
import { HttpDetailsResponse } from '../api'; | ||
|
||
export class AgentHTTPResponseError extends AgentError { | ||
constructor(message: string, public readonly response: HttpDetailsResponse) { | ||
constructor( | ||
message: string, | ||
public readonly response: HttpDetailsResponse, | ||
) { | ||
super(message); | ||
this.name = this.constructor.name; | ||
Object.setPrototypeOf(this, new.target.prototype); | ||
} | ||
} | ||
|
||
export class ReplicaTimeError extends AgentError { | ||
public readonly replicaTime: Date; | ||
public readonly agent: HttpAgent; | ||
|
||
constructor(message: string, replicaTime: Date, agent: HttpAgent) { | ||
super(message); | ||
this.name = 'ReplicaTimeError'; | ||
this.replicaTime = replicaTime; | ||
this.agent = agent; | ||
Object.setPrototypeOf(this, new.target.prototype); | ||
} | ||
} |
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.