From 368ecf87716efe59a815976dd8a36abc352f261d Mon Sep 17 00:00:00 2001 From: Gauthier Date: Wed, 20 Aug 2025 11:32:59 +0200 Subject: [PATCH] fix(dnscaching): display stats for DNS caching (#1858) * fix(dnscaching): display stats for DNS caching * fix: add missing translation --- package.json | 2 +- pnpm-lock.yaml | 14 ++++----- server/interfaces/api/settingsInterfaces.ts | 31 ++----------------- server/routes/settings/index.ts | 7 +++-- server/utils/dnsCache.ts | 4 +-- .../Settings/SettingsJobsCache/index.tsx | 5 --- src/i18n/locale/en.json | 7 +++-- 7 files changed, 20 insertions(+), 50 deletions(-) diff --git a/package.json b/package.json index b47b8f2dc..38c6b6605 100644 --- a/package.json +++ b/package.json @@ -57,7 +57,7 @@ "cronstrue": "2.23.0", "date-fns": "2.29.3", "dayjs": "1.11.7", - "dns-caching": "^0.2.4", + "dns-caching": "^0.2.5", "email-templates": "12.0.1", "email-validator": "2.0.4", "express": "4.21.2", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 4012b0350..6e3f5b694 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -84,8 +84,8 @@ importers: specifier: 1.11.7 version: 1.11.7 dns-caching: - specifier: ^0.2.4 - version: 0.2.4 + specifier: ^0.2.5 + version: 0.2.5 email-templates: specifier: 12.0.1 version: 12.0.1(@babel/core@7.24.7)(encoding@0.1.13)(handlebars@4.7.8)(mustache@4.2.0)(pug@3.0.3)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(underscore@1.13.7) @@ -4864,8 +4864,8 @@ packages: dlv@1.1.3: resolution: {integrity: sha512-+HlytyjlPKnIG8XuRG8WvmBP8xs8P71y+SKKS6ZXWoEgLuePxtDoUEiH7WkdePWrQ5JBpE6aoVqfZfJUQkjXwA==} - dns-caching@0.2.4: - resolution: {integrity: sha512-J48CLnMScOAtWIdExkz+522A0nPUwG5o+w7vVsXBJDipVLugCnps5AVJMn9bOkqQm4GarHtutMHYJEryCTeMjA==} + dns-caching@0.2.5: + resolution: {integrity: sha512-1cnB6i/OG4zfYbRnDjWZDT+FGLvOBuJlFIxVZvHBiaa62SCfaGoP4Si50O14HyoHmx1gadeGWigYXdX5LQAFvg==} doctrine@2.1.0: resolution: {integrity: sha512-35mSku4ZXK0vfCuHEDAwt55dg2jNajHZ1odvF+8SSr82EsZY4QmXfuWso8oEd8zRhVObSN18aM0CjSdoBX7zIw==} @@ -15700,7 +15700,7 @@ snapshots: dlv@1.1.3: {} - dns-caching@0.2.4: + dns-caching@0.2.5: dependencies: lru-cache: 11.1.0 @@ -16093,7 +16093,7 @@ snapshots: debug: 4.4.0(supports-color@5.5.0) enhanced-resolve: 5.17.0 eslint: 8.35.0 - eslint-module-utils: 2.8.1(@typescript-eslint/parser@7.2.0(eslint@8.35.0)(typescript@4.9.5))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.1)(eslint@8.35.0) + eslint-module-utils: 2.8.1(@typescript-eslint/parser@7.2.0(eslint@8.35.0)(typescript@4.9.5))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@7.2.0(eslint@8.35.0)(typescript@4.9.5))(eslint-import-resolver-node@0.3.9)(eslint-plugin-import@2.29.1)(eslint@8.35.0))(eslint@8.35.0) eslint-plugin-import: 2.29.1(@typescript-eslint/parser@5.54.0(eslint@8.35.0)(typescript@4.9.5))(eslint@8.35.0) fast-glob: 3.3.2 get-tsconfig: 4.7.5 @@ -16115,7 +16115,7 @@ snapshots: transitivePeerDependencies: - supports-color - eslint-module-utils@2.8.1(@typescript-eslint/parser@7.2.0(eslint@8.35.0)(typescript@4.9.5))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.1)(eslint@8.35.0): + eslint-module-utils@2.8.1(@typescript-eslint/parser@7.2.0(eslint@8.35.0)(typescript@4.9.5))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@7.2.0(eslint@8.35.0)(typescript@4.9.5))(eslint-import-resolver-node@0.3.9)(eslint-plugin-import@2.29.1)(eslint@8.35.0))(eslint@8.35.0): dependencies: debug: 3.2.7(supports-color@8.1.1) optionalDependencies: diff --git a/server/interfaces/api/settingsInterfaces.ts b/server/interfaces/api/settingsInterfaces.ts index 3fee84be8..5e058eccd 100644 --- a/server/interfaces/api/settingsInterfaces.ts +++ b/server/interfaces/api/settingsInterfaces.ts @@ -1,3 +1,4 @@ +import type { DnsEntries, DnsStats } from 'dns-caching'; import type { PaginatedResponse } from './common'; export type LogMessage = { @@ -61,38 +62,12 @@ export interface CacheItem { }; } -export interface DNSAddresses { - ipv4: number; - ipv6: number; -} - -export interface DNSRecord { - addresses: DNSAddresses; - activeAddress: string; - family: number; - age: number; - ttl: number; - networkErrors: number; - hits: number; - misses: number; -} - -export interface DNSStats { - size: number; - maxSize: number; - hits: number; - misses: number; - failures: number; - ipv4Fallbacks: number; - hitRate: number; -} - export interface CacheResponse { apiCaches: CacheItem[]; imageCache: Record<'tmdb' | 'avatar', { size: number; imageCount: number }>; dnsCache: { - entries: Record; - stats: DNSStats; + stats: DnsStats | undefined; + entries: DnsEntries | undefined; }; } diff --git a/server/routes/settings/index.ts b/server/routes/settings/index.ts index db31b937e..7298e2c93 100644 --- a/server/routes/settings/index.ts +++ b/server/routes/settings/index.ts @@ -28,8 +28,9 @@ import discoverSettingRoutes from '@server/routes/settings/discover'; import { ApiError } from '@server/types/error'; import { appDataPath } from '@server/utils/appDataVolume'; import { getAppVersion } from '@server/utils/appVersion'; -import dnsCache from '@server/utils/dnsCache'; +import { dnsCache } from '@server/utils/dnsCache'; import { getHostname } from '@server/utils/getHostname'; +import type { DnsEntries, DnsStats } from 'dns-caching'; import { Router } from 'express'; import rateLimit from 'express-rate-limit'; import fs from 'fs'; @@ -756,8 +757,8 @@ settingsRoutes.get('/cache', async (_req, res) => { const tmdbImageCache = await ImageProxy.getImageStats('tmdb'); const avatarImageCache = await ImageProxy.getImageStats('avatar'); - const stats = dnsCache?.getStats(); - const entries = dnsCache?.getCacheEntries(); + const stats: DnsStats | undefined = dnsCache?.getStats(); + const entries: DnsEntries | undefined = dnsCache?.getCacheEntries(); return res.status(200).json({ apiCaches, diff --git a/server/utils/dnsCache.ts b/server/utils/dnsCache.ts index 253b9291a..12ab8d40a 100644 --- a/server/utils/dnsCache.ts +++ b/server/utils/dnsCache.ts @@ -1,7 +1,7 @@ import logger from '@server/logger'; import { DnsCacheManager } from 'dns-caching'; -let dnsCache: DnsCacheManager | undefined; +export let dnsCache: DnsCacheManager | undefined; export function initializeDnsCache({ forceMinTtl, @@ -24,5 +24,3 @@ export function initializeDnsCache({ }); dnsCache.initialize(); } - -export default dnsCache; diff --git a/src/components/Settings/SettingsJobsCache/index.tsx b/src/components/Settings/SettingsJobsCache/index.tsx index 5a6ebefea..4b4c98f44 100644 --- a/src/components/Settings/SettingsJobsCache/index.tsx +++ b/src/components/Settings/SettingsJobsCache/index.tsx @@ -65,7 +65,6 @@ const messages: { [messageName: string]: MessageDescriptor } = defineMessages( dnscachehits: 'Hits', dnscachemisses: 'Misses', dnscacheage: 'Age', - dnscachenetworkerrors: 'Network Errors', flushdnscache: 'Flush DNS Cache', dnsCacheGlobalStats: 'Global DNS Cache Stats', dnsCacheGlobalStatsDescription: @@ -629,9 +628,6 @@ const SettingsJobs = () => { {intl.formatMessage(messages.dnscachehits)} {intl.formatMessage(messages.dnscachemisses)} {intl.formatMessage(messages.dnscacheage)} - - {intl.formatMessage(messages.dnscachenetworkerrors)} - @@ -644,7 +640,6 @@ const SettingsJobs = () => { {intl.formatNumber(data.hits)} {intl.formatNumber(data.misses)} {formatAge(data.age)} - {intl.formatNumber(data.networkErrors)}