Skip to content

Commit

Permalink
Merge pull request #13 from coveord/feature/UA-8974_add_cacentral1
Browse files Browse the repository at this point in the history
feat: Added `ca-central-1` [UA-8974]
  • Loading branch information
nlegros-coveo authored May 23, 2024
2 parents d918083 + efbb742 commit ff87ca9
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 6 deletions.
11 changes: 10 additions & 1 deletion src/AnimatedGlobe.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import globeData from "./data/admin-data.json";
import {
AWSRegionGeo,
LambdaURLAu,
LambdaURLCaCentral,
LambdaURLEU,
LambdaURLUsEast,
LiveEvent,
Expand Down Expand Up @@ -92,13 +93,17 @@ export const AnimatedGlobe: FunctionComponent<AnimatedGlobeProps> = ({
const resAu: LiveEvent[] = (await (
await fetch(`${LambdaURLAu}&last=${tickSpeed}`)
).json()) as LiveEvent[];
const resCaCentral: LiveEvent[] = (await (
await fetch(`${LambdaURLCaCentral}&last=${tickSpeed}`)
).json()) as LiveEvent[];

type validRegions = "us-east-1" | "eu-west-1" | "ap-southeast-2";
type validRegions = "us-east-1" | "eu-west-1" | "ap-southeast-2" | "ca-central-1";

const resTotal: Record<validRegions, LiveEvent[]> = {
"us-east-1": resUsEast,
"eu-west-1": resEu,
"ap-southeast-2": resAu,
"ca-central-1": resCaCentral,
};

const datum = Object.entries(resTotal).flatMap(([region, liveEvents]) => {
Expand Down Expand Up @@ -286,6 +291,10 @@ export const AnimatedGlobe: FunctionComponent<AnimatedGlobeProps> = ({
...AWSRegionGeo["ap-southeast-2"],
size: 1,
},
{
...AWSRegionGeo["ca-central-1"],
size: 1,
},
].concat([])}
htmlElement={() => {
const el = document.createElement("img");
Expand Down
58 changes: 53 additions & 5 deletions src/Charts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Grid, Text } from "@mantine/core";
import {
envRegionMapping,
LambdaURLAu,
LambdaURLCaCentral,
LambdaURLEU,
LambdaURLUsEast,
LiveEvent,
Expand Down Expand Up @@ -35,6 +36,7 @@ export const Charts: FunctionComponent<ChartsProps> = (props) => {
const [latencyUs, setLatencyUs] = useState<number>(0);
const [latencyEu, setLatencyEu] = useState<number>(0);
const [latencyAu, setLatencyAu] = useState<number>(0);
const [latencyCaCentral, setLatencyCaCentral] = useState<number>(0);

const [purchasesPerMinute, setPurchasesPerMinute] = useState<number>(0);
const [revenuePerMinute, setRevenuePerMinute] = useState<number>(0);
Expand Down Expand Up @@ -246,13 +248,42 @@ export const Charts: FunctionComponent<ChartsProps> = (props) => {
}
};

const getCaCentralEvents = async () => {
const events = await usClient
.get<LiveEvent[]>(`${LambdaURLCaCentral}&last=${props.tickSpeed}`)
.then((res) => res.data)
.catch((e) => {
console.log(e);
const liveEvent: LiveEvent = {
city: "",
event_id: "",
inserted_at: 0,
lat: "",
lng: "",
region: "us-east-1",
timestamp: 0,
type: "",
};
return [liveEvent];
});

if (events[0]) {
const total = events.reduce((previous, current) => {
return current.timestamp + previous;
}, 0);
const mean = total / events.length;
setLatencyCaCentral(Math.round((new Date().getTime() - mean) / 1000));
}
}

const emitData = async () => {
const promiseAu: Promise<void> = getAuEvents();
const promiseEu: Promise<void> = getEuEvents();
const promiseUs: Promise<void> = getUsEvents();
const promiseCaCentral: Promise<void> = getCaCentralEvents();


await Promise.all([promiseAu, promiseEu, promiseUs]);
await Promise.all([promiseAu, promiseEu, promiseUs, promiseCaCentral]);

setAnimationTick(animationTick + 1);
};
Expand Down Expand Up @@ -384,14 +415,14 @@ export const Charts: FunctionComponent<ChartsProps> = (props) => {
bottom: 0,
padding: 10,
zIndex: 2,
width: "320px",
width: "420px",
height: 120,
left: 0
}}>
<Text color="white" weight={"bold"}>Latency</Text>

<Grid>
<Grid.Col span={4} style={{ color: "white" }}>
<Grid.Col span={3} style={{ color: "white" }}>
<Text size={14} color="white">
us-east-1
</Text>
Expand All @@ -410,7 +441,7 @@ export const Charts: FunctionComponent<ChartsProps> = (props) => {
{latencyUs.toString()} seconds
</Text>
</Grid.Col>
<Grid.Col span={4} style={{ color: "white" }}>
<Grid.Col span={3} style={{ color: "white" }}>
<Text size={14} color="white">
eu-west-1
</Text>
Expand All @@ -429,7 +460,7 @@ export const Charts: FunctionComponent<ChartsProps> = (props) => {
{latencyEu.toString()} seconds
</Text>
</Grid.Col>
<Grid.Col span={4} style={{ color: "white" }}>
<Grid.Col span={3} style={{ color: "white" }}>
<Text size={14} color="white">
ap-southeast-2
</Text>
Expand All @@ -448,6 +479,23 @@ export const Charts: FunctionComponent<ChartsProps> = (props) => {
{latencyAu.toString()} seconds
</Text>
</Grid.Col>
<Grid.Col span={3} style={{ color: "white" }}>
<Text size={14} color="white">ca-central-1</Text>
<Text
size="sm"
color={
latencyCaCentral === 0
? "grey"
: latencyCaCentral < 5
? "green"
: latencyCaCentral < 20
? "yellow"
: "red"
}
>
{latencyCaCentral.toString()} seconds
</Text>
</Grid.Col>
</Grid>
</div>

Expand Down
14 changes: 14 additions & 0 deletions src/Events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ export const AWSRegionGeo = {
lat: -33.865143,
lng: 151.2099,
},
"ca-central-1": {
lat: 45.502079010009766,
lng: -73.56201171875,
},
};

export const envRegionMapping: any = {
Expand Down Expand Up @@ -73,6 +77,12 @@ export const envRegionMapping: any = {
"lambdaEndpoint": `https://72fup7tch7frsprfdvbctvaiv40sommb.lambda-url.ap-southeast-2.on.aws/?password=${localStorage.getItem(
"pw"
)}`
},
{
"region": "ca-central-1",
"lambdaEndpoint": `https://bmhvpjqu6axz5sybivpkt4j4oy0maebe.lambda-url.ca-central-1.on.aws/?password=${localStorage.getItem(
"pw"
)}`
}
]
}
Expand All @@ -88,3 +98,7 @@ export const LambdaURLEU = `https://c6xdcpmacp66i4njcrrwatb73i0opcjr.lambda-url.
export const LambdaURLAu = `https://72fup7tch7frsprfdvbctvaiv40sommb.lambda-url.ap-southeast-2.on.aws/?password=${localStorage.getItem(
"pw"
)}`;
export const LambdaURLCaCentral = `https://bmhvpjqu6axz5sybivpkt4j4oy0maebe.lambda-url.ca-central-1.on.aws/?password=${localStorage.getItem(
"pw"
)}`;

0 comments on commit ff87ca9

Please sign in to comment.