Skip to content

Commit

Permalink
chore: Implements load balancing automated priority grouping (#282)
Browse files Browse the repository at this point in the history
* chore: Implements load balancing automated priority grouping

* chore: Implements load balancing automated priority grouping
  • Loading branch information
amir-zahedi authored Jan 17, 2025
1 parent c59ab74 commit be49ee0
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/forty-bikes-buy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'gdu': minor
---

Adds loadbalancing rule priority grouping
40 changes: 38 additions & 2 deletions packages/gdu/commands/global-configs/config-tenants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,35 @@ const tenants = ['au', 'nz', 'au-legacy', 'global'];
type ENV = (typeof envs)[number];
type TENANT = (typeof tenants)[number] ;

const environmentOffsets: Record<string, number> = {
dev: 1,
test: 1,
uat: 2,
preprod: 3,
prod: 1,
tokens: 0,
shared: 0,
};

const scopeOffsets: Record<string, number> = {
'global': 1,
'au': 2,
'nz': 3,
'au-legacy': 2,
};

const mfeApplicationOffset = 500;

const mapLBPriority = (value: string, env: ENV, tenant?: TENANT) => {
const envOffset = environmentOffsets[env.toLowerCase()] ?? 0;
const scopeOffset = tenant ? scopeOffsets[tenant.toLowerCase()] ?? 0 : 0;
return (envOffset * 10000) + (scopeOffset * 1000) + (mfeApplicationOffset + parseInt(value, 10) || 0);
}

const tokenMap: Record<string, (value: string, env: ENV, tenant?: TENANT) => any> = {
appListenerPriority: (value, env, tenant) => mapLBPriority(value, env, tenant),
};

export default async () => {
console.log('Global config tenants started');
const TOKENS = await getTokens();
Expand Down Expand Up @@ -116,7 +145,14 @@ export default async () => {
);
const FILTERED_TOKENS = Object.keys(TOKENS).reduce((acc, key) => {
if (fileContent.includes(key)) {
acc[key] = process.env[key];
const mapperEntry = Object.keys(tokenMap).find(
mapKey => key.toLowerCase().startsWith(mapKey.toLowerCase()),
);
if (mapperEntry) {
acc[key] = tokenMap[mapperEntry](process.env[key]!, env, tenant);
} else {
acc[key] = process.env[key];
}
}
return acc;
}, {});
Expand Down Expand Up @@ -149,5 +185,5 @@ export default async () => {
});
});

console.log('Global config tokens finished');
console.log('MFE app config tokens finished');
}

0 comments on commit be49ee0

Please sign in to comment.