Skip to content

Commit

Permalink
[hasura] add explicit application pautoscaling resources
Browse files Browse the repository at this point in the history
  • Loading branch information
freemvmt committed Dec 20, 2024
1 parent 26cdd78 commit b47f6e2
Showing 1 changed file with 43 additions and 4 deletions.
47 changes: 43 additions & 4 deletions infrastructure/application/services/hasura.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,10 @@ export const createHasuraService = async ({
cluster,
subnets: networking.requireOutput("publicSubnetIds"),
desiredCount: 1,
deploymentMinimumHealthyPercent: 100,
deploymentMaximumPercent: 400,
deploymentMinimumHealthyPercent: 50,
deploymentMaximumPercent: 200,
// extend service-level health check grace period to match hasura server migrations timeout
healthCheckGracePeriodSeconds: 600,

taskDefinitionArgs: {
logGroup: new aws.cloudwatch.LogGroup("hasura", {
namePrefix: "hasura",
Expand Down Expand Up @@ -158,9 +157,49 @@ export const createHasuraService = async ({
},
},
},
});

// TODO: bump awsx to 1.x to use the FargateService scaleConfig option to replace more verbose config below
const hasuraScalingTarget = new aws.appautoscaling.Target("hasura-scaling-target", {
// start conservative, can always bump max as required
maxCapacity: 3,
minCapacity: 1,
resourceId: pulumi.interpolate`service/${cluster.cluster.name}/${hasuraService.service.name}`,
scalableDimension: "ecs:service:DesiredCount",
serviceNamespace: "ecs",
});

const hasuraCpuScaling = new aws.appautoscaling.Policy("hasura-cpu-scaling", {
policyType: "TargetTrackingScaling",
resourceId: hasuraScalingTarget.resourceId,
scalableDimension: hasuraScalingTarget.scalableDimension,
serviceNamespace: hasuraScalingTarget.serviceNamespace,
targetTrackingScalingPolicyConfiguration: {
predefinedMetricSpecification: {
predefinedMetricType: "ECSServiceAverageCPUUtilization",
},
// scale out quickly for responsiveness, but scale in more slowly to avoid thrashing
targetValue: 60.0,
scaleInCooldown: 300,
scaleOutCooldown: 60,
},
});

const hasuraMemoryScaling = new aws.appautoscaling.Policy("hasura-memory-scaling", {
policyType: "TargetTrackingScaling",
resourceId: hasuraScalingTarget.resourceId,
scalableDimension: hasuraScalingTarget.scalableDimension,
serviceNamespace: hasuraScalingTarget.serviceNamespace,
targetTrackingScalingPolicyConfiguration: {
predefinedMetricSpecification: {
predefinedMetricType: "ECSServiceAverageMemoryUtilization",
},
targetValue: 75.0,
scaleInCooldown: 300,
scaleOutCooldown: 60,
},
});

new cloudflare.Record("hasura", {
name: tldjs.getSubdomain(DOMAIN)
? `hasura.${tldjs.getSubdomain(DOMAIN)}`
Expand Down

0 comments on commit b47f6e2

Please sign in to comment.