Skip to content

Send a phone call from AI agent, in an API call. Or, directly call the bot from the configured phone number!

Python

finops: Replace Azure Cache for Redis by a Redis container

Clémence Lesné86fe6190920b
diff --git a/Makefile b/Makefile
index 535a990..8f2bc28 100644
--- a/Makefile
+++ b/Makefile
@@ -212,7 +212,7 @@ sync-local-config:
--query "[0].properties.template.containers[0].env[?name=='CONFIG_JSON'].value" \
--resource-group $(name_sanitized) \
| iconv -f utf-8 -t utf-8 -c \
- | yq \
- --output-format yaml \
+ | yq eval 'del(.cache)' \
+ --output-format=yaml \
--prettyPrint \
> config.yaml
diff --git a/README.md b/README.md
index af1942e..0299d3c 100644
--- a/README.md
+++ b/README.md
@@ -633,12 +633,6 @@ This totalizes $720.07 /month, $0.12 /hour, with the following breakdown:
| Sweden Central | Serverless vCPU | $0.000024 /sec | $128.56 | Avg of 2 replicas with 1 vCPU |
| Sweden Central | Serverless memory (average of 2 replicas) | $0.000003 /sec | $32.14 | Avg of 2 replicas with 2GB |
-[Azure Cache for Redis](https://azure.microsoft.com/en-us/pricing/details/cache/):
-
-| Region | Metric | Cost | Total (monthly $) | Note |
-|-|-|-|-|-|
-| Sweden Central | Standard C0 | $40.15 /month | $40.15 | Has 250MB of memory, should be upgraded for more intensive usage |
-
[Azure AI Search](https://azure.microsoft.com/en-us/pricing/details/search/):
| Region | Metric | Cost | Total (monthly $) | Note |
diff --git a/app/helpers/config_models/cache.py b/app/helpers/config_models/cache.py
index 3c5229d..f916064 100644
--- a/app/helpers/config_models/cache.py
+++ b/app/helpers/config_models/cache.py
@@ -28,7 +28,7 @@ class MemoryModel(BaseModel, frozen=True):
class RedisModel(BaseModel, frozen=True):
database: int = Field(default=0, ge=0)
host: str
- password: SecretStr
+ password: SecretStr | None = None
port: int = 6379
ssl: bool = True
diff --git a/app/persistence/redis.py b/app/persistence/redis.py
index 776ea95..ef35997 100644
--- a/app/persistence/redis.py
+++ b/app/persistence/redis.py
@@ -138,7 +138,9 @@ class RedisCache(ICache):
host=self._config.host,
port=self._config.port,
# Authentication
- password=self._config.password.get_secret_value(),
+ password=self._config.password.get_secret_value()
+ if self._config.password
+ else None,
)
@asynccontextmanager
diff --git a/cicd/bicep/app.bicep b/cicd/bicep/app.bicep
index 0a38907..79ac456 100644
--- a/cicd/bicep/app.bicep
+++ b/cicd/bicep/app.bicep
@@ -101,9 +101,8 @@ var config = {
cache: {
mode: 'redis'
redis: {
- host: redis.properties.hostName
- password: redis.listKeys().primaryKey
- port: redis.properties.sslPort
+ host: redis.name
+ ssl: false
}
}
app_configuration: {
@@ -160,6 +159,48 @@ resource acaEnv 'Microsoft.App/managedEnvironments@2024-02-02-preview' = {
}
}
+resource redis 'Microsoft.App/containerApps@2024-03-01' = {
+ name: 'redis'
+ location: location
+ tags: tags
+ properties: {
+ configuration: {
+ activeRevisionsMode: 'Single'
+ ingress: {
+ exposedPort: 6379
+ targetPort: 6379
+ transport: 'tcp'
+ }
+ }
+ environmentId: acaEnv.id
+ template: {
+ scale: {
+ maxReplicas: 1
+ minReplicas: 1
+ }
+ containers: [
+ {
+ image: 'redis/redis-stack-server:7.4.0-v2'
+ name: 'redis'
+ resources: {
+ cpu: json('0.5')
+ memory: '1Gi'
+ }
+ probes: [
+ {
+ type: 'Startup'
+ tcpSocket: {
+ port: 6379
+ }
+ initialDelaySeconds: 10
+ }
+ ]
+ }
+ ]
+ }
+ }
+}
+
var containerAppScaleRules = [
for queue in [
callQueue.name
@@ -909,21 +950,6 @@ resource translate 'Microsoft.CognitiveServices/accounts@2024-06-01-preview' = {
}
}
-resource redis 'Microsoft.Cache/redis@2024-03-01' = {
- name: prefix
- location: location
- tags: tags
- properties: {
- sku: {
- capacity: 0 // 250 MB of data
- family: 'C'
- name: 'Standard' // First tier with SLA
- }
- minimumTlsVersion: '1.2'
- redisVersion: '6' // v6.x
- }
-}
-
resource configStore 'Microsoft.AppConfiguration/configurationStores@2023-03-01' = {
name: prefix
location: location