Skip to content

Commit

Permalink
feat(applications): add scalers for cpu and memory (#1295)
Browse files Browse the repository at this point in the history
<!--- Provide a general summary of your changes in the Title above -->

## Description

- Enable automatic scaling based on CPU and memory for graphql and
web-api (enduser only)
- Setting 70 as the limit, this can be tweaked as we see how the
services behave under load
- Set a max number of 10 revisions for now. We might need to increase
this in yt01

<!--- Describe your changes in detail -->

## Related Issue(s)

- #1293

## Verification

- [ ] **Your** code builds clean without any errors or warnings
- [ ] Manual testing done (required)
- [ ] Relevant automated test added (if you find this hard, leave it and
we'll help out)

## Documentation

- [ ] Documentation is updated (either in `docs`-directory, Altinnpedia
or a separate linked PR in
[altinn-studio-docs.](https://github.com/Altinn/altinn-studio-docs), if
applicable)


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **New Features**
- Introduced dynamic scaling configuration for container apps, allowing
for minimum and maximum replicas and custom scaling based on CPU and
memory utilization.
- **Enhancements**
- Improved deployment flexibility with a centralized scaling parameter
for container apps.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
  • Loading branch information
arealmaas authored Oct 16, 2024
1 parent 4baf47e commit eb0f19b
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 4 deletions.
26 changes: 26 additions & 0 deletions .azure/applications/graphql/main.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,31 @@ var probes = [
}
]

var scale = {
minReplicas: 2
maxReplicas: 10
rules: [
{
custom: {
type: 'cpu'
metricType: 'Utilization'
metadata: {
value: '70'
}
}
}
{
custom: {
type: 'memory'
metricType: 'Utilization'
metadata: {
value: '70'
}
}
}
]
}

resource environmentKeyVaultResource 'Microsoft.KeyVault/vaults@2023-07-01' existing = {
name: environmentKeyVaultName
}
Expand All @@ -126,6 +151,7 @@ module containerApp '../../modules/containerApp/main.bicep' = {
revisionSuffix: revisionSuffix
probes: probes
port: port
scale: scale
}
}

Expand Down
25 changes: 25 additions & 0 deletions .azure/applications/web-api-eu/main.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,30 @@ var containerAppEnvVars = [
}
]

var scale = {
minReplicas: 2
maxReplicas: 10
rules: [
{
custom: {
type: 'cpu'
metricType: 'Utilization'
metadata: {
value: '70'
}
}
}
{
custom: {
type: 'memory'
metricType: 'Utilization'
metadata: {
value: '70'
}
}
}
]
}
resource environmentKeyVaultResource 'Microsoft.KeyVault/vaults@2023-07-01' existing = {
name: environmentKeyVaultName
}
Expand Down Expand Up @@ -128,6 +152,7 @@ module containerApp '../../modules/containerApp/main.bicep' = {
resources: resources
probes: probes
revisionSuffix: revisionSuffix
scale: scale
}
}

Expand Down
11 changes: 7 additions & 4 deletions .azure/modules/containerApp/main.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ param revisionSuffix string
@description('The probes for the container app')
param probes array = []

@description('The scaling configuration for the container app')
param scale object = {
minReplicas: 1
maxReplicas: 1 // temp disable scaling by default for outbox scheduling
}

// TODO: Refactor to make userAssignedIdentityId a required parameter once all container apps use user-assigned identities
@description('The ID of the user-assigned managed identity (optional)')
param userAssignedIdentityId string = ''
Expand Down Expand Up @@ -74,10 +80,7 @@ resource containerApp 'Microsoft.App/containerApps@2024-03-01' = {
environmentId: containerAppEnvId
template: {
revisionSuffix: cleanedRevisionSuffix
scale: {
minReplicas: 1
maxReplicas: 1 // temp disable scaling for outbox scheduling
}
scale: scale
containers: [
{
name: name
Expand Down

0 comments on commit eb0f19b

Please sign in to comment.