From 9014c88fde6431877fb14c1377e46b9fd52b6ac5 Mon Sep 17 00:00:00 2001 From: Anders Nomerstad Date: Fri, 19 Jul 2024 21:42:13 +0200 Subject: [PATCH 01/14] =?UTF-8?q?Oppdaterer=20ndm,=20og=20invaliderer=20re?= =?UTF-8?q?nder-cache=20ved=20ny=20dekorat=C3=B8r-versjon?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/deploy.dev2.yml | 2 +- .nais/vars/vars-dev2.yml | 1 + package-lock.json | 12 +++---- package.json | 2 +- .../src/cache/revalidator-proxy-heartbeat.ts | 20 ++++++----- server/src/server-setup/server-setup.ts | 20 +++++++++-- src/pages/_document.tsx | 9 ++++- .../decorator/decorator-utils-serverside.ts | 8 ++--- srcCommon/redis.ts | 33 +++++++++++++------ 9 files changed, 74 insertions(+), 33 deletions(-) diff --git a/.github/workflows/deploy.dev2.yml b/.github/workflows/deploy.dev2.yml index 3d58a1feb..cb2bff764 100644 --- a/.github/workflows/deploy.dev2.yml +++ b/.github/workflows/deploy.dev2.yml @@ -24,7 +24,7 @@ jobs: ADMIN_ORIGIN: https://portal-admin-q6.oera.no APP_ORIGIN: https://www-2.ansatt.dev.nav.no REVALIDATOR_PROXY_ORIGIN: http://nav-enonicxp-frontend-revalidator-proxy-dev2 - DECORATOR_URL: https://dekoratoren.ekstern.dev.nav.no + DECORATOR_URL: https://dekoratoren-beta.intern.dev.nav.no XP_ORIGIN: https://www-q6.nav.no TELEMETRY_URL: https://telemetry.ekstern.dev.nav.no/collect INNLOGGINGSSTATUS_URL: https://www.ekstern.dev.nav.no/person/nav-dekoratoren-api/auth diff --git a/.nais/vars/vars-dev2.yml b/.nais/vars/vars-dev2.yml index 4c1f83d4c..0315eb5db 100644 --- a/.nais/vars/vars-dev2.yml +++ b/.nais/vars/vars-dev2.yml @@ -4,6 +4,7 @@ dekoratorenApp: nav-dekoratoren-beta externalHosts: - www-q6.nav.no - www-2-failover.intern.dev.nav.no + - dekoratoren-beta.intern.dev.nav.no secret: nav-enonicxp-dev2 ingresses: - https://www-2.ansatt.dev.nav.no diff --git a/package-lock.json b/package-lock.json index d9ef5e16e..1219028c4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17,7 +17,7 @@ "@navikt/ds-css": "6.13.0", "@navikt/ds-react": "6.13.0", "@navikt/ds-tokens": "6.13.0", - "@navikt/nav-dekoratoren-moduler": "2.1.6", + "@navikt/nav-dekoratoren-moduler": "3.0.0-beta.3", "@navikt/nav-office-reception-info": "1.0.6", "@reduxjs/toolkit": "2.2.6", "csp-header": "5.2.1", @@ -2581,12 +2581,12 @@ "license": "MIT" }, "node_modules/@navikt/nav-dekoratoren-moduler": { - "version": "2.1.6", - "resolved": "https://npm.pkg.github.com/download/@navikt/nav-dekoratoren-moduler/2.1.6/049e1daeecff43519e41e387f21fd7e3634c2bd3", - "integrity": "sha512-P9c+a8/HuIY6XScNr/DVS7lZ0UtndzYAMEaIVdAzCOrG4SudY4tXSp+44g1V58GKml1RjdzOfGVF4hxmFv3SiA==", + "version": "3.0.0-beta.3", + "resolved": "https://npm.pkg.github.com/download/@navikt/nav-dekoratoren-moduler/3.0.0-beta.3/38877d7e8beb001cef226ed1e8bd8d76236bf94c", + "integrity": "sha512-lqk+7ZE4nhS9QDJs1aFzPk/2UMqgLUMqWd71RTmEDLPv9mbUsk1WcncP4cbQIypsgPuXzDUmBG131DkhcZjeQg==", "dependencies": { - "csp-header": "^5.1.0", - "html-react-parser": "^3.0.16", + "csp-header": "5.2.1", + "html-react-parser": "3.0.16", "node-cache": "^5.1.2" }, "engines": { diff --git a/package.json b/package.json index f7609ab4e..258afd77b 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,7 @@ "@navikt/ds-css": "6.13.0", "@navikt/ds-react": "6.13.0", "@navikt/ds-tokens": "6.13.0", - "@navikt/nav-dekoratoren-moduler": "2.1.6", + "@navikt/nav-dekoratoren-moduler": "3.0.0-beta.3", "@navikt/nav-office-reception-info": "1.0.6", "@reduxjs/toolkit": "2.2.6", "csp-header": "5.2.1", diff --git a/server/src/cache/revalidator-proxy-heartbeat.ts b/server/src/cache/revalidator-proxy-heartbeat.ts index 40dac36e7..8aa81b8c6 100644 --- a/server/src/cache/revalidator-proxy-heartbeat.ts +++ b/server/src/cache/revalidator-proxy-heartbeat.ts @@ -3,8 +3,8 @@ // See: https://github.com/navikt/nav-enonicxp-frontend-revalidator-proxy import { networkInterfaces } from 'os'; import { logger } from 'srcCommon/logger'; -import { getRenderCacheKeyPrefix, getResponseCacheKeyPrefix } from 'srcCommon/redis'; import { objectToQueryString } from 'srcCommon/fetch-utils'; +import { redisCache } from './page-cache-handler'; const { ENV, NODE_ENV, DOCKER_HOST_ADDRESS, REVALIDATOR_PROXY_ORIGIN, SERVICE_SECRET } = process.env; @@ -22,10 +22,7 @@ const getPodAddress = () => { const podAddress = nets?.eth0?.[0]?.address; if (!podAddress) { - logger.error( - 'Error: pod IP address could not be determined' + - ' - Event driven cache regeneration will not be active for this instance' - ); + logger.error('Error: pod IP address could not be determined!'); return null; } @@ -37,9 +34,10 @@ const getProxyLivenessUrl = (buildId: string) => { return podAddress ? `${REVALIDATOR_PROXY_ORIGIN}/liveness${objectToQueryString({ address: podAddress, - redisPrefixes: [getRenderCacheKeyPrefix(buildId), getResponseCacheKeyPrefix()].join( - ',' - ), + redisPrefixes: [ + redisCache.responseCacheKeyPrefix, + redisCache.renderCacheKeyPrefix, + ].join(','), })}` : null; }; @@ -66,6 +64,12 @@ export const initRevalidatorProxyHeartbeat = (buildId: string) => { logger.info('Starting heartbeat loop'); const heartbeatFunc = () => { + const url = getProxyLivenessUrl(buildId); + if (!url) { + logger.error('Failed to determine revalidator heartbeat url!'); + return; + } + fetch(url, { headers: { secret: SERVICE_SECRET }, }).catch((e) => logger.error(`Failed to send heartbeat signal - ${e}`)); diff --git a/server/src/server-setup/server-setup.ts b/server/src/server-setup/server-setup.ts index 8ce341945..cd0363f44 100644 --- a/server/src/server-setup/server-setup.ts +++ b/server/src/server-setup/server-setup.ts @@ -9,7 +9,12 @@ import { handleInvalidateAllReq } from 'req-handlers/invalidate-all'; import { handleGetPendingResponses } from 'req-handlers/pending-responses'; import { serverSetupDev } from 'server-setup/server-setup-dev'; import { logger } from 'srcCommon/logger'; -import { redisCache } from 'cache/page-cache-handler'; +import PageCacheHandler, { redisCache } from 'cache/page-cache-handler'; +import { + addDecoratorUpdateListener, + getDecoratorVersionId, +} from '@navikt/nav-dekoratoren-moduler/ssr'; +import { decoratorEnvProps } from '../../../src/utils/decorator/decorator-utils-serverside'; // Set the no-cache header on json files from the incremental cache to ensure // data requested during client side navigation is always validated if cached @@ -29,7 +34,18 @@ export const serverSetup = async (expressApp: Express, nextApp: NextServer) => { const nextServer = await getNextServer(nextApp); const currentBuildId = getNextBuildId(nextServer); - await redisCache.init(currentBuildId); + const decoratorVersionId = await getDecoratorVersionId(decoratorEnvProps); + if (!decoratorVersionId) { + logger.error('Failed to fetch decorator version id!'); + } + + await redisCache.init(currentBuildId, decoratorVersionId); + + addDecoratorUpdateListener(decoratorEnvProps, (versionId) => { + logger.info(`New decorator version: ${versionId} - clearing render caches`); + redisCache.updateRenderCacheKeyPrefix(versionId); + new PageCacheHandler().clear(); + }); logger.info(`Current build id: ${currentBuildId}`); diff --git a/src/pages/_document.tsx b/src/pages/_document.tsx index 251c54227..1c900eab4 100644 --- a/src/pages/_document.tsx +++ b/src/pages/_document.tsx @@ -57,7 +57,14 @@ class MyDocument extends Document { return ( - {Decorator && } + + {Decorator && ( + <> + + + + )} + {Decorator && }
diff --git a/src/utils/decorator/decorator-utils-serverside.ts b/src/utils/decorator/decorator-utils-serverside.ts index 51079ea38..dd242c749 100644 --- a/src/utils/decorator/decorator-utils-serverside.ts +++ b/src/utils/decorator/decorator-utils-serverside.ts @@ -1,9 +1,9 @@ import { + fetchDecoratorReact, DecoratorEnvProps, DecoratorFetchProps, - fetchDecoratorReact, + DecoratorParams, } from '@navikt/nav-dekoratoren-moduler/ssr'; -import { DecoratorParams } from '@navikt/nav-dekoratoren-moduler'; type AppEnv = typeof process.env.ENV; type DecoratorEnv = DecoratorEnvProps['env']; @@ -17,7 +17,7 @@ const envMap: Record = { const decoratorEnv = envMap[process.env.ENV] || 'prod'; -const envProps: DecoratorFetchProps = { +export const decoratorEnvProps: DecoratorFetchProps = { noCache: process.env.DECORATOR_NOCACHE === 'true', ...(decoratorEnv === 'localhost' ? { env: 'localhost', localUrl: process.env.DECORATOR_URL } @@ -26,7 +26,7 @@ const envProps: DecoratorFetchProps = { export const getDecoratorComponents = async (params?: DecoratorParams) => { const decoratorComponents = fetchDecoratorReact({ - ...envProps, + ...decoratorEnvProps, params, }); diff --git a/srcCommon/redis.ts b/srcCommon/redis.ts index 080d55ff6..7f89aec44 100644 --- a/srcCommon/redis.ts +++ b/srcCommon/redis.ts @@ -31,8 +31,10 @@ class RedisCacheImpl { private readonly responseCacheTTL: number = TIME_72_HOURS_IN_MS; private readonly renderCacheTTL: number = TIME_24_HOURS_IN_MS; - private readonly responseCacheKeyPrefix = getResponseCacheKeyPrefix(); - private renderCacheKeyPrefix = ''; + private buildId: string = ''; + + readonly responseCacheKeyPrefix = `${process.env.ENV}:xp-response`; + renderCacheKeyPrefix = ''; constructor() { this.client = createClient(clientOptions) @@ -53,8 +55,9 @@ class RedisCacheImpl { }); } - public async init(buildId: string) { - this.renderCacheKeyPrefix = getRenderCacheKeyPrefix(buildId); + public async init(buildId: string, decoratorVersionId: string) { + this.buildId = buildId; + this.updateRenderCacheKeyPrefix(decoratorVersionId); return this.client.connect().then(() => { logger.info( @@ -64,9 +67,16 @@ class RedisCacheImpl { }); } + public updateRenderCacheKeyPrefix(decoratorVersionId: string) { + this.renderCacheKeyPrefix = `${process.env.ENV}:render:${this.buildId}:${decoratorVersionId}`; + } + public async getRender(key: string) { + const fullKey = this.getFullKey(key, this.renderCacheKeyPrefix); + logger.info(`Fetching from response cache: ${fullKey}`); + return this.client - .getEx(this.getFullKey(key, this.renderCacheKeyPrefix), { + .getEx(fullKey, { PX: this.renderCacheTTL, }) .then((result) => (result ? JSON.parse(result) : result)) @@ -102,7 +112,10 @@ class RedisCacheImpl { } public async setRender(key: string, data: CacheHandlerValue) { - return this.set(this.getFullKey(key, this.renderCacheKeyPrefix), this.renderCacheTTL, data); + const fullKey = this.getFullKey(key, this.renderCacheKeyPrefix); + logger.info(`Saving to render cache: ${fullKey}`); + + return this.set(fullKey, this.renderCacheTTL, data); } public async setResponse(key: string, data: XpResponseProps) { @@ -123,6 +136,10 @@ class RedisCacheDummy extends RedisCacheImpl { return this; } + public updateRenderCacheKeyPrefix(key: string) { + return; + } + public async getRender(key: string) { return null; } @@ -146,7 +163,3 @@ export const RedisCache = validateClientOptions() ? RedisCacheImpl : RedisCacheDummy; - -export const getRenderCacheKeyPrefix = (buildId: string) => `${process.env.ENV}:render:${buildId}`; - -export const getResponseCacheKeyPrefix = () => `${process.env.ENV}:xp-response`; From ef6898be3b7dc8fbbb9f4d347f3b28d3cd7145b8 Mon Sep 17 00:00:00 2001 From: Anders Nomerstad Date: Fri, 19 Jul 2024 21:44:25 +0200 Subject: [PATCH 02/14] linting --- src/utils/fetch/fetch-content.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/fetch/fetch-content.ts b/src/utils/fetch/fetch-content.ts index a1faaa981..87c426dc1 100644 --- a/src/utils/fetch/fetch-content.ts +++ b/src/utils/fetch/fetch-content.ts @@ -26,7 +26,7 @@ const getXpCacheKey = }) : () => ({}); -const redisCache = await new RedisCache().init(process.env.BUILD_ID); +const redisCache = await new RedisCache().init(process.env.BUILD_ID, ''); const fetchConfig = { headers: { From b4dd25c63e682d184cec624a7e65ceda58e4a348 Mon Sep 17 00:00:00 2001 From: Anders Nomerstad Date: Fri, 19 Jul 2024 22:00:13 +0200 Subject: [PATCH 03/14] Fjerner logging, etc --- .../src/cache/revalidator-proxy-heartbeat.ts | 5 +---- srcCommon/redis.ts | 22 +++++++++---------- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/server/src/cache/revalidator-proxy-heartbeat.ts b/server/src/cache/revalidator-proxy-heartbeat.ts index 8aa81b8c6..2001efdc6 100644 --- a/server/src/cache/revalidator-proxy-heartbeat.ts +++ b/server/src/cache/revalidator-proxy-heartbeat.ts @@ -34,10 +34,7 @@ const getProxyLivenessUrl = (buildId: string) => { return podAddress ? `${REVALIDATOR_PROXY_ORIGIN}/liveness${objectToQueryString({ address: podAddress, - redisPrefixes: [ - redisCache.responseCacheKeyPrefix, - redisCache.renderCacheKeyPrefix, - ].join(','), + redisPrefixes: redisCache.getKeyPrefixes().join(','), })}` : null; }; diff --git a/srcCommon/redis.ts b/srcCommon/redis.ts index 7f89aec44..960e4a2c8 100644 --- a/srcCommon/redis.ts +++ b/srcCommon/redis.ts @@ -33,8 +33,8 @@ class RedisCacheImpl { private buildId: string = ''; - readonly responseCacheKeyPrefix = `${process.env.ENV}:xp-response`; - renderCacheKeyPrefix = ''; + private readonly responseCacheKeyPrefix = `${process.env.ENV}:xp-response`; + private renderCacheKeyPrefix = ''; constructor() { this.client = createClient(clientOptions) @@ -67,31 +67,34 @@ class RedisCacheImpl { }); } + public getKeyPrefixes() { + return [responseCacheKeyPrefix, renderCacheKeyPrefix]; + } + public updateRenderCacheKeyPrefix(decoratorVersionId: string) { this.renderCacheKeyPrefix = `${process.env.ENV}:render:${this.buildId}:${decoratorVersionId}`; } public async getRender(key: string) { const fullKey = this.getFullKey(key, this.renderCacheKeyPrefix); - logger.info(`Fetching from response cache: ${fullKey}`); - return this.client .getEx(fullKey, { PX: this.renderCacheTTL, }) .then((result) => (result ? JSON.parse(result) : result)) .catch((e) => { - logger.error(`Error getting render cache value for key ${key} - ${e}`); + logger.error(`Error getting render cache value for key ${fullKey} - ${e}`); return Promise.resolve(null); }); } public async getResponse(key: string) { + const fullKey = this.getFullKey(key, this.responseCacheKeyPrefix); return this.client - .get(this.getFullKey(key, this.responseCacheKeyPrefix)) + .get(fullKey) .then((result) => (result ? JSON.parse(result) : result)) .catch((e) => { - logger.error(`Error getting value for key ${key} - ${e}`); + logger.error(`Error getting value for key ${fullKey} - ${e}`); return Promise.resolve(null); }); } @@ -112,10 +115,7 @@ class RedisCacheImpl { } public async setRender(key: string, data: CacheHandlerValue) { - const fullKey = this.getFullKey(key, this.renderCacheKeyPrefix); - logger.info(`Saving to render cache: ${fullKey}`); - - return this.set(fullKey, this.renderCacheTTL, data); + return this.set(this.getFullKey(key, this.renderCacheKeyPrefix), this.renderCacheTTL, data); } public async setResponse(key: string, data: XpResponseProps) { From 0c74b1952c7e31d27903dad6826ecc8b27d36c25 Mon Sep 17 00:00:00 2001 From: Anders Nomerstad Date: Fri, 19 Jul 2024 22:03:38 +0200 Subject: [PATCH 04/14] Fjerner mer logging --- server/src/server-setup/server-setup-dev.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/server/src/server-setup/server-setup-dev.ts b/server/src/server-setup/server-setup-dev.ts index b99ffe5c0..09a647ca0 100644 --- a/server/src/server-setup/server-setup-dev.ts +++ b/server/src/server-setup/server-setup-dev.ts @@ -26,7 +26,6 @@ export const serverSetupDev = (expressApp: Express, nextApp: NextServer) => { if (APP_ORIGIN.endsWith(DEV_NAIS_DOMAIN)) { expressApp.all('*', (req, res, next) => { if (!req.hostname.endsWith(DEV_NAIS_DOMAIN)) { - logger.info('Redirecting!'); return res.redirect(302, `${APP_ORIGIN}${req.path}`); } From 317b9ce4afc047b922ec2e51b449f96213d52f3d Mon Sep 17 00:00:00 2001 From: Anders Nomerstad Date: Fri, 19 Jul 2024 22:06:10 +0200 Subject: [PATCH 05/14] this! --- next.config.js | 4 ---- server/src/server.ts | 5 +++++ srcCommon/redis.ts | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/next.config.js b/next.config.js index 7e6e61acc..690f31483 100644 --- a/next.config.js +++ b/next.config.js @@ -279,10 +279,6 @@ const config = { { source: '/:path*', headers: [ - { - key: 'app-name', - value: 'nav-enonicxp-frontend', - }, { key: 'Content-Security-Policy', value: await csp(), diff --git a/server/src/server.ts b/server/src/server.ts index 072b0f849..0b57b7316 100644 --- a/server/src/server.ts +++ b/server/src/server.ts @@ -47,6 +47,11 @@ nextApp.prepare().then(async () => { next(); }); + expressApp.all('*', (req, res, next) => { + res.setHeader('app-name', 'nav-enonicxp-frontend'); + next(); + }); + if (isFailover) { serverSetupFailover(expressApp, nextApp); } else { diff --git a/srcCommon/redis.ts b/srcCommon/redis.ts index 960e4a2c8..901862703 100644 --- a/srcCommon/redis.ts +++ b/srcCommon/redis.ts @@ -68,7 +68,7 @@ class RedisCacheImpl { } public getKeyPrefixes() { - return [responseCacheKeyPrefix, renderCacheKeyPrefix]; + return [this.responseCacheKeyPrefix, this.renderCacheKeyPrefix]; } public updateRenderCacheKeyPrefix(decoratorVersionId: string) { From 81a5a5981c78980af7213d1d8e042e3a4ca44574 Mon Sep 17 00:00:00 2001 From: Anders Nomerstad Date: Fri, 19 Jul 2024 22:33:55 +0200 Subject: [PATCH 06/14] Masse logging! --- server/src/cache/revalidator-proxy-heartbeat.ts | 6 ++++++ srcCommon/redis.ts | 3 +++ 2 files changed, 9 insertions(+) diff --git a/server/src/cache/revalidator-proxy-heartbeat.ts b/server/src/cache/revalidator-proxy-heartbeat.ts index 2001efdc6..699068d36 100644 --- a/server/src/cache/revalidator-proxy-heartbeat.ts +++ b/server/src/cache/revalidator-proxy-heartbeat.ts @@ -31,6 +31,10 @@ const getPodAddress = () => { const getProxyLivenessUrl = (buildId: string) => { const podAddress = getPodAddress(); + console.log( + `Redis prefixes: ${redisCache.getKeyPrefixes()} - ${redisCache.getKeyPrefixes().join(',')}` + ); + return podAddress ? `${REVALIDATOR_PROXY_ORIGIN}/liveness${objectToQueryString({ address: podAddress, @@ -67,6 +71,8 @@ export const initRevalidatorProxyHeartbeat = (buildId: string) => { return; } + console.log(`Heartbeat url: ${url}`); + fetch(url, { headers: { secret: SERVICE_SECRET }, }).catch((e) => logger.error(`Failed to send heartbeat signal - ${e}`)); diff --git a/srcCommon/redis.ts b/srcCommon/redis.ts index 901862703..79e49c48a 100644 --- a/srcCommon/redis.ts +++ b/srcCommon/redis.ts @@ -56,6 +56,7 @@ class RedisCacheImpl { } public async init(buildId: string, decoratorVersionId: string) { + console.log(`Initing with ${buildId} ${decoratorVersionId}`); this.buildId = buildId; this.updateRenderCacheKeyPrefix(decoratorVersionId); @@ -72,7 +73,9 @@ class RedisCacheImpl { } public updateRenderCacheKeyPrefix(decoratorVersionId: string) { + console.log(`Setting prefix ${this.renderCacheKeyPrefix}`); this.renderCacheKeyPrefix = `${process.env.ENV}:render:${this.buildId}:${decoratorVersionId}`; + console.log(`Set prefix ${this.renderCacheKeyPrefix}`); } public async getRender(key: string) { From 911243220baf3277aeb5a78446a1ab38ea581131 Mon Sep 17 00:00:00 2001 From: Anders Nomerstad Date: Fri, 19 Jul 2024 22:44:43 +0200 Subject: [PATCH 07/14] Fix redisCache import --- server/src/cache/revalidator-proxy-heartbeat.ts | 13 ++++--------- server/src/server-setup/server-setup-dev.ts | 1 - 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/server/src/cache/revalidator-proxy-heartbeat.ts b/server/src/cache/revalidator-proxy-heartbeat.ts index 699068d36..93c9ec5a9 100644 --- a/server/src/cache/revalidator-proxy-heartbeat.ts +++ b/server/src/cache/revalidator-proxy-heartbeat.ts @@ -4,7 +4,7 @@ import { networkInterfaces } from 'os'; import { logger } from 'srcCommon/logger'; import { objectToQueryString } from 'srcCommon/fetch-utils'; -import { redisCache } from './page-cache-handler'; +import { redisCache } from 'cache/page-cache-handler'; const { ENV, NODE_ENV, DOCKER_HOST_ADDRESS, REVALIDATOR_PROXY_ORIGIN, SERVICE_SECRET } = process.env; @@ -29,7 +29,7 @@ const getPodAddress = () => { return podAddress; }; -const getProxyLivenessUrl = (buildId: string) => { +const getProxyLivenessUrl = () => { const podAddress = getPodAddress(); console.log( `Redis prefixes: ${redisCache.getKeyPrefixes()} - ${redisCache.getKeyPrefixes().join(',')}` @@ -45,7 +45,7 @@ const getProxyLivenessUrl = (buildId: string) => { let didStart = false; -export const initRevalidatorProxyHeartbeat = (buildId: string) => { +export const initRevalidatorProxyHeartbeat = () => { if (NODE_ENV === 'development') { return; } @@ -55,17 +55,12 @@ export const initRevalidatorProxyHeartbeat = (buildId: string) => { return; } - const url = getProxyLivenessUrl(buildId); - if (!url) { - return; - } - didStart = true; logger.info('Starting heartbeat loop'); const heartbeatFunc = () => { - const url = getProxyLivenessUrl(buildId); + const url = getProxyLivenessUrl(); if (!url) { logger.error('Failed to determine revalidator heartbeat url!'); return; diff --git a/server/src/server-setup/server-setup-dev.ts b/server/src/server-setup/server-setup-dev.ts index 09a647ca0..e81307d48 100644 --- a/server/src/server-setup/server-setup-dev.ts +++ b/server/src/server-setup/server-setup-dev.ts @@ -1,6 +1,5 @@ import { Express } from 'express'; import { NextServer } from 'next/dist/server/next'; -import { logger } from 'srcCommon/logger'; const DEV_NAIS_DOMAIN = 'ansatt.dev.nav.no'; const APP_ORIGIN = process.env.APP_ORIGIN; From bd5883e39f62b3393070c1aae5fb7107bb045671 Mon Sep 17 00:00:00 2001 From: Anders Nomerstad Date: Fri, 19 Jul 2024 22:46:29 +0200 Subject: [PATCH 08/14] lint --- server/src/cache/revalidator-proxy-heartbeat.test.ts | 2 +- server/src/server.ts | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/server/src/cache/revalidator-proxy-heartbeat.test.ts b/server/src/cache/revalidator-proxy-heartbeat.test.ts index ffebd8812..99fd0ea8e 100644 --- a/server/src/cache/revalidator-proxy-heartbeat.test.ts +++ b/server/src/cache/revalidator-proxy-heartbeat.test.ts @@ -14,7 +14,7 @@ describe('Revalidator proxy heartbeat', () => { fetchMock.mockResponse('Hello!'); - initRevalidatorProxyHeartbeat('dummy-build-id'); + initRevalidatorProxyHeartbeat(); expect(fetchMock.mock.calls.length).toEqual(1); expect(fetchMock.mock.calls[0][0]).toMatch(new RegExp(`^${revalidatorProxyOrigin}`)); diff --git a/server/src/server.ts b/server/src/server.ts index 0b57b7316..37900fde4 100644 --- a/server/src/server.ts +++ b/server/src/server.ts @@ -83,8 +83,7 @@ nextApp.prepare().then(async () => { } if (!isFailover) { - const buildId = getNextBuildId(nextServer); - initRevalidatorProxyHeartbeat(buildId); + initRevalidatorProxyHeartbeat(); } logger.info(`Server started on port ${port}`); From 40f6ce307508efd9a7ef4da3179017dbf2573625 Mon Sep 17 00:00:00 2001 From: Anders Nomerstad Date: Fri, 19 Jul 2024 23:58:41 +0200 Subject: [PATCH 09/14] Oppdaterer test config --- server/jest.config.mjs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/server/jest.config.mjs b/server/jest.config.mjs index 6c438535e..8e4e368bc 100644 --- a/server/jest.config.mjs +++ b/server/jest.config.mjs @@ -8,6 +8,7 @@ export default { "^.+\\.tsx?$": "ts-jest" }, "moduleNameMapper": { - "srcCommon/(.*)": "/../srcCommon/$1" + "srcCommon/(.*)": "/../srcCommon/$1", + "cache/(.*)": "/src/cache/$1" }, }; From c794a1743eac2126fe77d8ab34fc814d525e90f2 Mon Sep 17 00:00:00 2001 From: Anders Nomerstad Date: Sat, 20 Jul 2024 00:04:04 +0200 Subject: [PATCH 10/14] Import --- server/src/server.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/server.ts b/server/src/server.ts index 37900fde4..6f6c93751 100644 --- a/server/src/server.ts +++ b/server/src/server.ts @@ -5,7 +5,7 @@ import promBundle from 'express-prom-bundle'; import { initRevalidatorProxyHeartbeat } from 'cache/revalidator-proxy-heartbeat'; import { serverSetupFailover } from 'server-setup/server-setup-failover'; import { serverSetup } from 'server-setup/server-setup'; -import { getNextBuildId, getNextServer } from 'next-utils'; +import { getNextServer } from 'next-utils'; import { logger } from 'srcCommon/logger'; import path from 'path'; import { injectNextImageCacheDir } from 'cache/image-cache-handler'; From 31adb03cf48e1cd280079b5d65ed12bada5ae005 Mon Sep 17 00:00:00 2001 From: Anders Nomerstad Date: Sat, 20 Jul 2024 00:17:44 +0200 Subject: [PATCH 11/14] Fjerner logging --- server/src/cache/revalidator-proxy-heartbeat.ts | 6 ------ srcCommon/redis.ts | 3 --- 2 files changed, 9 deletions(-) diff --git a/server/src/cache/revalidator-proxy-heartbeat.ts b/server/src/cache/revalidator-proxy-heartbeat.ts index 93c9ec5a9..9b4d83cb8 100644 --- a/server/src/cache/revalidator-proxy-heartbeat.ts +++ b/server/src/cache/revalidator-proxy-heartbeat.ts @@ -31,10 +31,6 @@ const getPodAddress = () => { const getProxyLivenessUrl = () => { const podAddress = getPodAddress(); - console.log( - `Redis prefixes: ${redisCache.getKeyPrefixes()} - ${redisCache.getKeyPrefixes().join(',')}` - ); - return podAddress ? `${REVALIDATOR_PROXY_ORIGIN}/liveness${objectToQueryString({ address: podAddress, @@ -66,8 +62,6 @@ export const initRevalidatorProxyHeartbeat = () => { return; } - console.log(`Heartbeat url: ${url}`); - fetch(url, { headers: { secret: SERVICE_SECRET }, }).catch((e) => logger.error(`Failed to send heartbeat signal - ${e}`)); diff --git a/srcCommon/redis.ts b/srcCommon/redis.ts index 79e49c48a..901862703 100644 --- a/srcCommon/redis.ts +++ b/srcCommon/redis.ts @@ -56,7 +56,6 @@ class RedisCacheImpl { } public async init(buildId: string, decoratorVersionId: string) { - console.log(`Initing with ${buildId} ${decoratorVersionId}`); this.buildId = buildId; this.updateRenderCacheKeyPrefix(decoratorVersionId); @@ -73,9 +72,7 @@ class RedisCacheImpl { } public updateRenderCacheKeyPrefix(decoratorVersionId: string) { - console.log(`Setting prefix ${this.renderCacheKeyPrefix}`); this.renderCacheKeyPrefix = `${process.env.ENV}:render:${this.buildId}:${decoratorVersionId}`; - console.log(`Set prefix ${this.renderCacheKeyPrefix}`); } public async getRender(key: string) { From 4e6809d73b679a30b711b8d8b895f06480152f97 Mon Sep 17 00:00:00 2001 From: Anders Nomerstad Date: Sat, 20 Jul 2024 00:27:03 +0200 Subject: [PATCH 12/14] Flytter decorator-utils til srccommon --- server/src/server-setup/server-setup.ts | 2 +- src/components/PageWrapper.tsx | 2 +- src/components/_common/metatags/DocumentParameterMetatags.tsx | 2 +- src/pages/_document.tsx | 2 +- .../utils => srcCommon}/decorator/decorator-utils-serverside.ts | 0 {src/utils => srcCommon}/decorator/decorator-utils.ts | 0 6 files changed, 4 insertions(+), 4 deletions(-) rename {src/utils => srcCommon}/decorator/decorator-utils-serverside.ts (100%) rename {src/utils => srcCommon}/decorator/decorator-utils.ts (100%) diff --git a/server/src/server-setup/server-setup.ts b/server/src/server-setup/server-setup.ts index cd0363f44..4b4b89dff 100644 --- a/server/src/server-setup/server-setup.ts +++ b/server/src/server-setup/server-setup.ts @@ -14,7 +14,7 @@ import { addDecoratorUpdateListener, getDecoratorVersionId, } from '@navikt/nav-dekoratoren-moduler/ssr'; -import { decoratorEnvProps } from '../../../src/utils/decorator/decorator-utils-serverside'; +import { decoratorEnvProps } from 'srcCommon/decorator/decorator-utils-serverside'; // Set the no-cache header on json files from the incremental cache to ensure // data requested during client side navigation is always validated if cached diff --git a/src/components/PageWrapper.tsx b/src/components/PageWrapper.tsx index d83c26552..231baa860 100644 --- a/src/components/PageWrapper.tsx +++ b/src/components/PageWrapper.tsx @@ -4,7 +4,7 @@ import { onBreadcrumbClick, onLanguageSelect, setParams } from '@navikt/nav-deko import { ContentProps } from 'types/content-props/_content-common'; import { hookAndInterceptInternalLink, prefetchOnMouseover } from 'utils/links'; import { hasWhiteHeader, hasWhitePage } from 'utils/appearance'; -import { getDecoratorParams } from 'utils/decorator/decorator-utils'; +import { getDecoratorParams } from 'srcCommon/decorator/decorator-utils'; import { getInternalRelativePath } from 'utils/urls'; import { store } from 'store/store'; import { fetchAndSetInnloggingsstatus } from 'utils/fetch/fetch-innloggingsstatus'; diff --git a/src/components/_common/metatags/DocumentParameterMetatags.tsx b/src/components/_common/metatags/DocumentParameterMetatags.tsx index 0aede34e4..a877cf756 100644 --- a/src/components/_common/metatags/DocumentParameterMetatags.tsx +++ b/src/components/_common/metatags/DocumentParameterMetatags.tsx @@ -1,7 +1,7 @@ import React from 'react'; import Head from 'next/head'; import { ContentProps } from 'types/content-props/_content-common'; -import { getDecoratorParams } from 'utils/decorator/decorator-utils'; +import { getDecoratorParams } from 'srcCommon/decorator/decorator-utils'; import { isLegacyContentType } from 'utils/content-types'; type Props = { diff --git a/src/pages/_document.tsx b/src/pages/_document.tsx index 1c900eab4..8874e048b 100644 --- a/src/pages/_document.tsx +++ b/src/pages/_document.tsx @@ -4,7 +4,7 @@ import { DocumentInitialProps } from 'next/dist/pages/_document'; import { DecoratorComponents } from '@navikt/nav-dekoratoren-moduler/ssr'; import { Language } from 'translations'; import { DocumentParameter } from 'components/_common/metatags/DocumentParameterMetatags'; -import { getDecoratorComponents } from 'utils/decorator/decorator-utils-serverside'; +import { getDecoratorComponents } from 'srcCommon/decorator/decorator-utils-serverside'; type DocumentProps = { language: Language; diff --git a/src/utils/decorator/decorator-utils-serverside.ts b/srcCommon/decorator/decorator-utils-serverside.ts similarity index 100% rename from src/utils/decorator/decorator-utils-serverside.ts rename to srcCommon/decorator/decorator-utils-serverside.ts diff --git a/src/utils/decorator/decorator-utils.ts b/srcCommon/decorator/decorator-utils.ts similarity index 100% rename from src/utils/decorator/decorator-utils.ts rename to srcCommon/decorator/decorator-utils.ts From 9ef6f8ffb8284cf6dcab6ebfd8f993f38e476ca1 Mon Sep 17 00:00:00 2001 From: Anders Nomerstad Date: Sat, 20 Jul 2024 00:49:09 +0200 Subject: [PATCH 13/14] beta 3 -> 4 --- package-lock.json | 10 +++++----- package.json | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/package-lock.json b/package-lock.json index 1219028c4..b1dd526b3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17,7 +17,7 @@ "@navikt/ds-css": "6.13.0", "@navikt/ds-react": "6.13.0", "@navikt/ds-tokens": "6.13.0", - "@navikt/nav-dekoratoren-moduler": "3.0.0-beta.3", + "@navikt/nav-dekoratoren-moduler": "3.0.0-beta.4", "@navikt/nav-office-reception-info": "1.0.6", "@reduxjs/toolkit": "2.2.6", "csp-header": "5.2.1", @@ -2581,13 +2581,13 @@ "license": "MIT" }, "node_modules/@navikt/nav-dekoratoren-moduler": { - "version": "3.0.0-beta.3", - "resolved": "https://npm.pkg.github.com/download/@navikt/nav-dekoratoren-moduler/3.0.0-beta.3/38877d7e8beb001cef226ed1e8bd8d76236bf94c", - "integrity": "sha512-lqk+7ZE4nhS9QDJs1aFzPk/2UMqgLUMqWd71RTmEDLPv9mbUsk1WcncP4cbQIypsgPuXzDUmBG131DkhcZjeQg==", + "version": "3.0.0-beta.4", + "resolved": "https://npm.pkg.github.com/download/@navikt/nav-dekoratoren-moduler/3.0.0-beta.4/c1bee4cb2092c6f46a20623464e75e7a95ca47ba", + "integrity": "sha512-EMd8gq2eARy4qnJhnWFo6UzCENZxmFINf4+uhdxt3bNBbLwvJ/48aDVASq7WexYtDZu2HzNaDyr8IiHwx2rTLw==", "dependencies": { "csp-header": "5.2.1", "html-react-parser": "3.0.16", - "node-cache": "^5.1.2" + "node-cache": "5.1.2" }, "engines": { "node": ">=18" diff --git a/package.json b/package.json index 258afd77b..26ffeeb77 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,7 @@ "@navikt/ds-css": "6.13.0", "@navikt/ds-react": "6.13.0", "@navikt/ds-tokens": "6.13.0", - "@navikt/nav-dekoratoren-moduler": "3.0.0-beta.3", + "@navikt/nav-dekoratoren-moduler": "3.0.0-beta.4", "@navikt/nav-office-reception-info": "1.0.6", "@reduxjs/toolkit": "2.2.6", "csp-header": "5.2.1", From 3850d06e94d0ca64fb74f07edf88817ec4ddf7c2 Mon Sep 17 00:00:00 2001 From: Anders Nomerstad Date: Sat, 20 Jul 2024 00:52:22 +0200 Subject: [PATCH 14/14] Flytter decorator-utils tilbake... --- server/src/server-setup/server-setup.ts | 2 +- src/components/PageWrapper.tsx | 2 +- .../_common/metatags/DocumentParameterMetatags.tsx | 2 +- src/pages/_document.tsx | 2 +- {srcCommon/decorator => src/utils}/decorator-utils.ts | 6 +++--- srcCommon/{decorator => }/decorator-utils-serverside.ts | 0 6 files changed, 7 insertions(+), 7 deletions(-) rename {srcCommon/decorator => src/utils}/decorator-utils.ts (95%) rename srcCommon/{decorator => }/decorator-utils-serverside.ts (100%) diff --git a/server/src/server-setup/server-setup.ts b/server/src/server-setup/server-setup.ts index 4b4b89dff..a6cc8b592 100644 --- a/server/src/server-setup/server-setup.ts +++ b/server/src/server-setup/server-setup.ts @@ -14,7 +14,7 @@ import { addDecoratorUpdateListener, getDecoratorVersionId, } from '@navikt/nav-dekoratoren-moduler/ssr'; -import { decoratorEnvProps } from 'srcCommon/decorator/decorator-utils-serverside'; +import { decoratorEnvProps } from 'srcCommon/decorator-utils-serverside'; // Set the no-cache header on json files from the incremental cache to ensure // data requested during client side navigation is always validated if cached diff --git a/src/components/PageWrapper.tsx b/src/components/PageWrapper.tsx index 231baa860..188ff426c 100644 --- a/src/components/PageWrapper.tsx +++ b/src/components/PageWrapper.tsx @@ -4,7 +4,7 @@ import { onBreadcrumbClick, onLanguageSelect, setParams } from '@navikt/nav-deko import { ContentProps } from 'types/content-props/_content-common'; import { hookAndInterceptInternalLink, prefetchOnMouseover } from 'utils/links'; import { hasWhiteHeader, hasWhitePage } from 'utils/appearance'; -import { getDecoratorParams } from 'srcCommon/decorator/decorator-utils'; +import { getDecoratorParams } from 'utils/decorator-utils'; import { getInternalRelativePath } from 'utils/urls'; import { store } from 'store/store'; import { fetchAndSetInnloggingsstatus } from 'utils/fetch/fetch-innloggingsstatus'; diff --git a/src/components/_common/metatags/DocumentParameterMetatags.tsx b/src/components/_common/metatags/DocumentParameterMetatags.tsx index a877cf756..a8e3c776a 100644 --- a/src/components/_common/metatags/DocumentParameterMetatags.tsx +++ b/src/components/_common/metatags/DocumentParameterMetatags.tsx @@ -1,7 +1,7 @@ import React from 'react'; import Head from 'next/head'; import { ContentProps } from 'types/content-props/_content-common'; -import { getDecoratorParams } from 'srcCommon/decorator/decorator-utils'; +import { getDecoratorParams } from 'utils/decorator-utils'; import { isLegacyContentType } from 'utils/content-types'; type Props = { diff --git a/src/pages/_document.tsx b/src/pages/_document.tsx index 8874e048b..d5b59f67a 100644 --- a/src/pages/_document.tsx +++ b/src/pages/_document.tsx @@ -4,7 +4,7 @@ import { DocumentInitialProps } from 'next/dist/pages/_document'; import { DecoratorComponents } from '@navikt/nav-dekoratoren-moduler/ssr'; import { Language } from 'translations'; import { DocumentParameter } from 'components/_common/metatags/DocumentParameterMetatags'; -import { getDecoratorComponents } from 'srcCommon/decorator/decorator-utils-serverside'; +import { getDecoratorComponents } from 'srcCommon/decorator-utils-serverside'; type DocumentProps = { language: Language; diff --git a/srcCommon/decorator/decorator-utils.ts b/src/utils/decorator-utils.ts similarity index 95% rename from srcCommon/decorator/decorator-utils.ts rename to src/utils/decorator-utils.ts index d606afb85..c96608866 100644 --- a/srcCommon/decorator/decorator-utils.ts +++ b/src/utils/decorator-utils.ts @@ -1,11 +1,11 @@ import { DecoratorParams } from '@navikt/nav-dekoratoren-moduler'; import { Language } from 'translations'; -import { getContentLanguages } from 'utils/languages'; import { ContentProps, ContentType } from 'types/content-props/_content-common'; import { LanguageProps } from 'types/language'; -import { stripXpPathPrefix } from 'utils/urls'; import { Audience, getAudience } from 'types/component-props/_mixins'; -import { hasWhiteHeader } from 'utils/appearance'; +import { stripXpPathPrefix } from './urls'; +import { getContentLanguages } from './languages'; +import { hasWhiteHeader } from './appearance'; const defaultLanguage: DecoratorParams['language'] = 'nb'; diff --git a/srcCommon/decorator/decorator-utils-serverside.ts b/srcCommon/decorator-utils-serverside.ts similarity index 100% rename from srcCommon/decorator/decorator-utils-serverside.ts rename to srcCommon/decorator-utils-serverside.ts