Skip to content

Commit

Permalink
metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
cskrov committed Feb 2, 2024
1 parent 78944f5 commit e493efa
Show file tree
Hide file tree
Showing 13 changed files with 307 additions and 115 deletions.
22 changes: 19 additions & 3 deletions server/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"dependencies": {
"@navikt/nav-dekoratoren-moduler": "2.1.5",
"compression": "1.7.4",
"cookie": "^0.6.0",
"cors": "2.8.5",
"express": "4.18.2",
"express-prom-bundle": "7.0.0",
Expand All @@ -27,6 +28,7 @@
},
"devDependencies": {
"@types/compression": "1.7.5",
"@types/cookie": "^0.6.0",
"@types/cors": "2.8.17",
"@types/jest": "29.5.11",
"@typescript-eslint/eslint-plugin": "6.20.0",
Expand All @@ -46,4 +48,4 @@
"tsc-alias": "1.8.8",
"typescript": "5.3.3"
}
}
}
2 changes: 1 addition & 1 deletion server/src/config/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const DOMAIN: string = getEnvironmentVersion(
`http://localhost:${serverConfig.port}`,
`http://localhost:${serverConfig.port}`,
'https://klage.intern.dev.nav.no',
'https://klage.intern.nav.no',
'https://klage.nav.no',
);

export const NAIS_NAMESPACE = requiredEnvString('NAIS_NAMESPACE', 'none');
23 changes: 0 additions & 23 deletions server/src/functions/cookies.ts

This file was deleted.

6 changes: 2 additions & 4 deletions server/src/init.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { Express, static as expressStatic } from 'express';
import { frontendDistDirectoryPath } from '@app/config/config';
import { redirectMiddleware } from '@app/middleware/redirect';
import { redirectMiddleware } from '@app/middleware/redirect/redirect';
import { serverConfig } from './config/server-config';
import { getLogger } from './logger';
import { appHandler } from './routes/app-handler';
import { errorReporter } from './routes/error-report';
import { setupProxy } from './routes/setup-proxy';
import { setupVersionRoute } from './routes/version';
import { EmojiIcons, sendToSlack } from './slack';

const log = getLogger('init');
Expand All @@ -25,11 +24,10 @@ export const init = async (server: Express) => {
}
});
server.use(errorReporter());
server.use(setupVersionRoute());
server.use(await setupProxy());
server.use(expressStatic(frontendDistDirectoryPath, { index: false, fallthrough: true }));
server.use(redirectMiddleware);
server.get(['/nb*', '/en*'], appHandler);
server.get('*', appHandler);
server.listen(PORT, () => log.info({ msg: `Listening on port ${PORT}` }));
} catch (e) {
if (e instanceof Error) {
Expand Down
20 changes: 10 additions & 10 deletions server/src/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ export interface AnyObject {

type LogArgs =
| {
msg?: string;
error: Error | unknown;
data?: SerializableValue | AnyObject;
}
msg?: string;
error: Error | unknown;
data?: SerializableValue | AnyObject;
}
| {
msg: string;
error?: Error | unknown;
data?: SerializableValue | AnyObject;
};
msg: string;
error?: Error | unknown;
data?: SerializableValue | AnyObject;
};

interface Logger {
debug: (args: LogArgs) => void;
Expand Down Expand Up @@ -110,8 +110,8 @@ export const httpLoggingMiddleware: RequestHandler = (req, res, next) => {

res.once('finish', () => {
const { method, url } = req;
const referrer = req.get('referrer');
const userAgent = req.get('user-agent');
const referrer = req.header('referrer');
const userAgent = req.header('user-agent');

if (url.endsWith('/isAlive') || url.endsWith('/isReady')) {
return;
Expand Down
32 changes: 32 additions & 0 deletions server/src/middleware/redirect/gauges.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { Gauge } from 'prom-client';
import { registers } from '@app/prometheus/types';

export const anonymousViewCountGauge = new Gauge({
name: 'anonymous_view_count',
help: 'Number of anonymous viewa.',
labelNames: ['url', 'lang', 'type', 'ytelse', 'subpage', 'has_saksnummer', 'redirected_from'],
registers,
});

export const loggedInViewCountGauge = new Gauge({
name: 'logged_in_view_count',
help: 'Number of logged in views.',
labelNames: ['url', 'lang', 'type', 'id', 'subpage', 'has_saksnummer', 'redirected_from'],
registers,
});

const labelNames = ['from_url', 'to_url', 'has_saksnummer'] as const;

export const externalRedirectGauge = new Gauge({
name: 'external_redirect',
help: 'Number of redirects to nav.no/klage.',
labelNames,
registers,
});

export const internalRedirectGauge = new Gauge({
name: 'internal_redirect',
help: 'Number of internal redirects to fix deprected paths.',
labelNames,
registers,
});
Loading

0 comments on commit e493efa

Please sign in to comment.