Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update dependency Hangfire.PostgreSql to 1.20.10 #395

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions .azure/infrastructure/main.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,9 @@ param idportenClientSecret string

@secure()
param storageAccountName string
param maskinporten_token_exchange_environment string

import { Sku as KeyVaultSku } from '../modules/keyvault/create.bicep'
param keyVaultSku KeyVaultSku

import { Sku as PostgresSku } from '../modules/postgreSql/create.bicep'
param postgresSku PostgresSku

var prodLikeEnvironment = environment == 'production' || maskinporten_token_exchange_environment == 'yt01'
var resourceGroupName = '${namePrefix}-rg'

// Create resource groups
Expand All @@ -50,7 +46,6 @@ module environmentKeyVault '../modules/keyvault/create.bicep' = {
params: {
vaultName: sourceKeyVaultName
location: location
sku: keyVaultSku
tenant_id: tenantId
environment: environment
test_client_id: test_client_id
Expand Down Expand Up @@ -120,8 +115,8 @@ module postgresql '../modules/postgreSql/create.bicep' = {
srcKeyVault: srcKeyVault
srcSecretName: correspondenceAdminPasswordSecretName
administratorLoginPassword: correspondencePgAdminPassword
sku: postgresSku
tenantId: tenantId
prodLikeEnvironment: prodLikeEnvironment
}
}

Expand Down
9 changes: 0 additions & 9 deletions .azure/infrastructure/parameters.json

This file was deleted.

10 changes: 1 addition & 9 deletions .azure/infrastructure/params.bicepparam
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,4 @@ param accessManagementSubscriptionKey = readEnvironmentVariable('ACCESS_MANAGEME
param slackUrl = readEnvironmentVariable('SLACK_URL')
param idportenClientId = readEnvironmentVariable('IDPORTEN_CLIENT_ID')
param idportenClientSecret = readEnvironmentVariable('IDPORTEN_CLIENT_SECRET')
// SKUs
param keyVaultSku = {
name: 'standard'
family: 'A'
}
param postgresSku = {
name: 'Standard_B1ms'
tier: 'Burstable'
}
param maskinporten_token_exchange_environment = readEnvironmentVariable('MASKINPORTEN_TOKEN_EXCHANGE_ENVIRONMENT')
34 changes: 26 additions & 8 deletions .azure/modules/containerApp/main.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,30 @@ param userIdentityClientId string
@secure()
param containerAppEnvId string

type ContainerAppResources = {
cpu: int
memory: string
}
type ContainerAppScale = {
minReplicas: int
maxReplicas: int
}
param prodLikeEnvironment bool = environment == 'production' || maskinporten_token_exchange_environment == 'yt01'
param containerAppResources ContainerAppResources = prodLikeEnvironment ? {
cpu: 2
memory: '4.0Gi'
} : {
cpu: json('0.5')
memory: '1.0Gi'
}
param containerAppScale ContainerAppScale = prodLikeEnvironment ? {
minReplicas: 3
maxReplicas:10
} : {
minReplicas: 1
maxReplicas: 1
}

var probes = [
{
type: 'Liveness'
Expand Down Expand Up @@ -174,20 +198,14 @@ resource containerApp 'Microsoft.App/containerApps@2023-05-01' = {

environmentId: containerAppEnvId
template: {
scale: {
minReplicas: 1
maxReplicas: 1
}
scale: containerAppScale
containers: [
{
name: 'app'
image: image
env: containerAppEnvVars
probes: probes
resources: {
cpu: json('0.5')
memory: '1.0Gi'
}
resources: containerAppResources
}
]
}
Expand Down
11 changes: 4 additions & 7 deletions .azure/modules/keyvault/create.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,6 @@ param environment string
param tenant_id string
@secure()
param test_client_id string
@export()
type Sku = {
name: 'standard'
family: 'A'
}
param sku Sku

resource keyVault 'Microsoft.KeyVault/vaults@2023-07-01' = {
name: vaultName
Expand All @@ -19,7 +13,10 @@ resource keyVault 'Microsoft.KeyVault/vaults@2023-07-01' = {
enabledForTemplateDeployment: true
enabledForDiskEncryption: true
enabledForDeployment: true
sku: sku
sku: {
name: 'standard'
family: 'A'
}
tenantId: tenant_id
accessPolicies: environment == 'test'
? [
Expand Down
42 changes: 28 additions & 14 deletions .azure/modules/postgreSql/create.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@ param location string
param environmentKeyVaultName string
param srcSecretName string

@export()
type Sku = {
name: 'Standard_B1ms' | 'Standard_B2s' | 'Standard_D2ads_v5'
tier: 'Burstable' | 'GeneralPurpose' | 'MemoryOptimized'
}
param sku Sku
@secure()
param srcKeyVault object

Expand All @@ -17,9 +11,11 @@ param administratorLoginPassword string
@secure()
param tenantId string

param prodLikeEnvironment bool

var databaseName = 'correspondence'
var databaseUser = 'adminuser'
var poolSize = 25
var poolSize = prodLikeEnvironment ? 100 : 25

module saveAdmPassword '../keyvault/upsertSecret.bicep' = {
name: 'Save_${srcSecretName}'
Expand Down Expand Up @@ -51,6 +47,8 @@ resource postgres 'Microsoft.DBforPostgreSQL/flexibleServers@2023-12-01-preview'
administratorLoginPassword: administratorLoginPassword
storage: {
storageSizeGB: 32
autoGrow: 'Enabled'
tier: prodLikeEnvironment ? 'P15': 'P4'
}
backup: { backupRetentionDays: 35 }
authConfig: {
Expand All @@ -59,10 +57,25 @@ resource postgres 'Microsoft.DBforPostgreSQL/flexibleServers@2023-12-01-preview'
tenantId: tenantId
}
}
sku: sku
sku: prodLikeEnvironment ? {
name: 'Standard_D8ads_v5'
tier: 'GeneralPurpose'
} : {
name: 'Standard_B1ms'
tier: 'Burstable'
}
}

resource configurations 'Microsoft.DBforPostgreSQL/flexibleServers/configurations@2022-12-01' = {
resource database 'Microsoft.DBforPostgreSQL/flexibleServers/databases@2023-06-01-preview' = {
name: databaseName
parent: postgres
properties: {
charset: 'UTF8'
collation: 'nb_NO.utf8'
}
}

resource extensionsConfiguration 'Microsoft.DBforPostgreSQL/flexibleServers/configurations@2022-12-01' = {
name: 'azure.extensions'
parent: postgres
dependsOn: [database]
Expand All @@ -72,19 +85,20 @@ resource configurations 'Microsoft.DBforPostgreSQL/flexibleServers/configuration
}
}

resource database 'Microsoft.DBforPostgreSQL/flexibleServers/databases@2023-06-01-preview' = {
name: databaseName
resource maxConnectionsConfiguration 'Microsoft.DBforPostgreSQL/flexibleServers/configurations@2022-12-01' = {
name: 'max_connections'
parent: postgres
dependsOn: [extensionsConfiguration]
properties: {
charset: 'UTF8'
collation: 'nb_NO.utf8'
value: prodLikeEnvironment ? '3000' : '50'
source: 'user-override'
}
}

resource allowAzureAccess 'Microsoft.DBforPostgreSQL/flexibleServers/firewallRules@2023-06-01-preview' = {
name: 'azure-access'
parent: postgres
dependsOn: [configurations] // Needs to depend on database to avoid updating at the same time
dependsOn: [maxConnectionsConfiguration] // Needs to depend on database to avoid updating at the same time
properties: {
startIpAddress: '0.0.0.0'
endIpAddress: '0.0.0.0'
Expand Down
1 change: 1 addition & 0 deletions .github/actions/deploy-to-environment/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ runs:
MASKINPORTEN_JWK: ${{ inputs.MASKINPORTEN_JWK }}
PLATFORM_SUBSCRIPTION_KEY: ${{ inputs.PLATFORM_SUBSCRIPTION_KEY }}
SLACK_URL: ${{ inputs.SLACK_URL }}
MASKINPORTEN_TOKEN_EXCHANGE_ENVIRONMENT: ${{ inputs.MASKINPORTEN_TOKEN_EXCHANGE_ENVIRONMENT }}

- name: Migrate database
uses: ./.github/actions/migrate-database
Expand Down
5 changes: 5 additions & 0 deletions .github/actions/update-infrastructure/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ inputs:
IDPORTEN_CLIENT_SECRET:
description: "Client secret for Maskinporten integration used for IDPorten auth"
required: true
MASKINPORTEN_TOKEN_EXCHANGE_ENVIRONMENT:
description: "Maskinporten Token Exchange Environment"
required: false
default: ""

runs:
using: "composite"
Expand Down Expand Up @@ -105,6 +109,7 @@ runs:
IDPORTEN_ISSUER: ${{ inputs.IDPORTEN_ISSUER }}
IDPORTEN_CLIENT_ID: ${{ inputs.IDPORTEN_CLIENT_ID }}
IDPORTEN_CLIENT_SECRET: ${{ inputs.IDPORTEN_CLIENT_SECRET }}
MASKINPORTEN_TOKEN_EXCHANGE_ENVIRONMENT: ${{ inputs.MASKINPORTEN_TOKEN_EXCHANGE_ENVIRONMENT }}
with:
scope: subscription
template: ./.azure/infrastructure/main.bicep
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<PackageReference Include="Azure.Extensions.AspNetCore.Configuration.Secrets" Version="1.3.1" />
<PackageReference Include="Hangfire.AspNetCore" Version="1.8.12" />
<PackageReference Include="Hangfire.MemoryStorage" Version="1.8.1.1" />
<PackageReference Include="Hangfire.PostgreSql" Version="1.20.8" />
<PackageReference Include="Hangfire.PostgreSql" Version="1.20.10" />
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.22.0" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.22.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.6" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

using Hangfire;
using Hangfire.PostgreSql;

using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;

using Npgsql;
Expand All @@ -20,7 +20,11 @@ public static async Task<OneOf<T, Error>> Execute<T>(
{
var result = await RetryPolicy(logger).ExecuteAndCaptureAsync<OneOf<T, Error>>(async (cancellationToken) =>
{
using var transaction = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled);
using var transaction = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions()
{
IsolationLevel = IsolationLevel.ReadCommitted,
Timeout = TimeSpan.FromSeconds(30)
}, TransactionScopeAsyncFlowOption.Enabled);
var result = await operation(cancellationToken);
transaction.Complete();
return result;
Expand All @@ -38,6 +42,7 @@ public static AsyncRetryPolicy RetryPolicy(ILogger logger) => Policy
.Or<PostgresException>()
.Or<BackgroundJobClientException>()
.Or<PostgreSqlDistributedLockException>()
.Or<DbUpdateConcurrencyException>()
.WaitAndRetryAsync(
10,
retryAttempt => TimeSpan.FromMilliseconds(10),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<PackageReference Include="Altinn.Platform.Models" Version="1.6.0" />
<PackageReference Include="Hangfire.AspNetCore" Version="1.8.12" />
<PackageReference Include="Hangfire.Core" Version="1.8.12" />
<PackageReference Include="Hangfire.PostgreSql" Version="1.20.8" />
<PackageReference Include="Hangfire.PostgreSql" Version="1.20.10" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.6" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="8.0.0" />
Expand Down
Loading