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

Migrere fra Redis til Valkey #2170

Merged
merged 5 commits into from
Feb 24, 2025
Merged
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
8 changes: 4 additions & 4 deletions .github/workflows/deploy-to-nais.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ on:
hpa_file:
required: false
type: string
deploy_redis:
deploy_valkey:
required: false
type: boolean

Expand All @@ -30,14 +30,14 @@ jobs:
steps:
- name: Checkout repo
uses: actions/checkout@v4
- name: Deploy Redis
if: ${{ inputs.deploy_redis == true }}
- name: Deploy Valkey
if: ${{ inputs.deploy_valkey == true }}
uses: nais/deploy/actions/deploy@v2
timeout-minutes: 1
continue-on-error: true
env:
CLUSTER: ${{ inputs.cluster }}
RESOURCE: .nais/redis.yml
RESOURCE: .nais/valkey.yml
VARS: .nais/vars/${{ inputs.vars_file }}
- name: Deploy HPA
if: ${{ inputs.hpa_file }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy.dev1.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@ jobs:
vars_file: vars-dev1.yml
config_file: config.yml
hpa_file: hpa-dev1.yml
deploy_redis: true
deploy_valkey: true
2 changes: 1 addition & 1 deletion .github/workflows/deploy.dev2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@ jobs:
vars_file: vars-dev2.yml
config_file: config.yml
hpa_file: hpa-dev2.yml
deploy_redis: true
deploy_valkey: true
2 changes: 1 addition & 1 deletion .github/workflows/deploy.prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ jobs:
vars_file: vars-prod.yml
config_file: config.yml
hpa_file: hpa-prod.yml
deploy_redis: true
deploy_valkey: true
4 changes: 2 additions & 2 deletions .nais/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ spec:
prometheus:
enabled: true
path: /internal/metrics
redis:
- instance: {{ redis.instance }}
valkey:
- instance: {{ valkey.instance }}
access: readwrite
ingresses:
{{#each ingresses as |url|}}
Expand Down
18 changes: 9 additions & 9 deletions .nais/redis.yml → .nais/valkey.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
apiVersion: aiven.io/v1alpha1
kind: Redis
kind: Valkey
metadata:
labels:
app: nav-enonicxp-frontend
team: personbruker
name: redis-personbruker-{{ redis.instance }}
name: valkey-personbruker-{{ valkey.instance }}
namespace: personbruker
spec:
plan: {{ redis.plan }}
project: {{ redis.project }}
plan: {{ valkey.plan }}
project: {{ valkey.project }}
maintenanceWindowDow: saturday
maintenanceWindowTime: 20:00:00
userConfig:
redis_maxmemory_policy: allkeys-lru
valkey_maxmemory_policy: allkeys-lru

---
apiVersion: aiven.io/v1alpha1
kind: ServiceIntegration
metadata:
labels:
team: personbruker
name: redis-personbruker-{{ redis.instance }}
name: valkey-personbruker-{{ valkey.instance }}
namespace: personbruker
spec:
project: {{ redis.project }}
project: {{ valkey.project }}
integrationType: prometheus
destinationEndpointId: {{ redis.endpointId }}
sourceServiceName: redis-personbruker-{{ redis.instance }}
destinationEndpointId: {{ valkey.endpointId }}
sourceServiceName: valkey-personbruker-{{ valkey.instance }}
2 changes: 1 addition & 1 deletion .nais/vars/vars-dev1.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ resources:
memory: 1000Mi
limits:
memory: 2000Mi
redis:
valkey:
plan: hobbyist
project: nav-dev
instance: pagecache
Expand Down
2 changes: 1 addition & 1 deletion .nais/vars/vars-dev2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ resources:
memory: 500Mi
limits:
memory: 1000Mi
redis:
valkey:
plan: hobbyist
project: nav-dev
instance: pagecache
Expand Down
2 changes: 1 addition & 1 deletion .nais/vars/vars-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ resources:
memory: 2048Mi
limits:
memory: 4096Mi
redis:
valkey:
plan: startup-4
project: nav-prod
instance: pagecache
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ services:
- '3002:3002'
environment:
SERVICE_SECRET: 'dummyToken'
NO_REDIS: true
NO_VALKEY: true

dekoratoren:
container_name: dekoratoren-xpfrontend
Expand Down
6 changes: 3 additions & 3 deletions nodeenv.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ declare global {
ASSET_PREFIX: string;
TELEMETRY_URL: string;
NEXT_PHASE: string;
REDIS_URI_PAGECACHE: string;
REDIS_USERNAME_PAGECACHE: string;
REDIS_PASSWORD_PAGECACHE: string;
VALKEY_URI_PAGECACHE: string;
VALKEY_USERNAME_PAGECACHE: string;
VALKEY_PASSWORD_PAGECACHE: string;
DECORATOR_NOCACHE?: 'true' | 'false';
}
}
Expand Down
20 changes: 11 additions & 9 deletions srcCommon/redis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ type XpResponseProps = Record<string, any>;

const clientOptions: RedisClientOptions = {
url: process.env.REDIS_URI_PAGECACHE,
username: process.env.REDIS_USERNAME_PAGECACHE,
password: process.env.REDIS_PASSWORD_PAGECACHE,
username: process.env.VALKEY_USERNAME_PAGECACHE,
password: process.env.VALKEY_PASSWORD_PAGECACHE,
socket: { keepAlive: 5000, connectTimeout: 10000 },
} as const;

const validateClientOptions = () => {
const isValid = !!(clientOptions.url && clientOptions.username && clientOptions.password);

if (!isValid) {
logger.error(`Client options for Redis has missing parameters!`);
logger.error(`Client options for Valkey has missing parameters!`);
}

return isValid;
Expand All @@ -37,21 +37,23 @@ class RedisCacheImpl {
private renderCacheKeyPrefix = '';

constructor() {
logger.info(clientOptions.url);
logger.info(clientOptions.username);
this.client = createClient(clientOptions)
.on('connect', () => {
logger.info('Redis client connected');
logger.info('Valkey client connected');
})
.on('ready', () => {
logger.info('Redis client ready');
logger.info('Valkey client ready');
})
.on('end', () => {
logger.info('Redis client connection closed');
logger.info('Valkey client connection closed');
})
.on('reconnecting', () => {
logger.info('Redis client reconnecting');
logger.info('Valkey client reconnecting');
})
.on('error', (err) => {
logger.error(`Redis client error: ${err}`);
logger.error(`Valkey client error: ${err}`);
});
}

Expand All @@ -61,7 +63,7 @@ class RedisCacheImpl {

return this.client.connect().then(() => {
logger.info(
`Initialized redis client with url ${clientOptions.url} - Render key prefix: ${this.renderCacheKeyPrefix} - Response key prefix: ${this.responseCacheKeyPrefix}`
`Initialized valkey client with url ${clientOptions.url} - Render key prefix: ${this.renderCacheKeyPrefix} - Response key prefix: ${this.responseCacheKeyPrefix}`
);
return this;
});
Expand Down
Loading