From 0cee7b42d5db5f2de407c02003d732ec354d5ace Mon Sep 17 00:00:00 2001 From: Dylan Decrulle Date: Mon, 25 Nov 2024 13:34:23 +0100 Subject: [PATCH 1/2] feat: add env var RUNNING_TIME_THRESHOLD #846 --- web/.env | 6 ++++++ web/src/env.ts | 15 ++++++++++++++- .../MyServicesCard/MyServicesCard.tsx | 3 ++- web/src/vite-env.d.ts | 1 + 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/web/.env b/web/.env index 62c225a5e..14ebf5124 100644 --- a/web/.env +++ b/web/.env @@ -783,6 +783,12 @@ QUOTA_WARNING_THRESHOLD=75% # QUOTA_CRITICAL_THRESHOLD=95% +# This parameter defines the threshold for displaying a service's runtime as a key metric. +# The value is expressed in milliseconds. By default it is set to 7 * 24 * 3600 * 1000, +# it means any service running for 7 days (7 days * 24 hours * 3600 seconds * 1000 milliseconds) +# will have its runtime prominently displayed on the "My Services" page. +RUNNING_TIME_THRESHOLD=604800000 + # This parameter controls if the configurations tabs should be expanded by default # when the user navigates to the launcher page: # https://github.com/InseeFrLab/onyxia/assets/6702424/a1c5597e-82e5-4532-8a9f-ed3ab7cc1d45 diff --git a/web/src/env.ts b/web/src/env.ts index f16da1f42..6520588d6 100644 --- a/web/src/env.ts +++ b/web/src/env.ts @@ -117,7 +117,7 @@ export const { env, injectTransferableEnvsInQueryParams } = createParsedEnvs([ envName: "SPLASHSCREEN_LOGO_SCALE_FACTOR", isUsedInKeycloakTheme: false, validateAndParseOrGetDefault: ({ envValue, envName }) => { - assert(envValue !== "Should have default in .env"); + assert(envValue !== "", "Should have default in .env"); const parsedValue = Number(envValue); @@ -1097,6 +1097,19 @@ export const { env, injectTransferableEnvsInQueryParams } = createParsedEnvs([ return n / 100; } }, + { + envName: "RUNNING_TIME_THRESHOLD", + isUsedInKeycloakTheme: false, + validateAndParseOrGetDefault: ({ envValue, envName }) => { + assert(envValue !== "", "Should have default in .env"); + + const parsedValue = Number(envValue); + + assert(!isNaN(parsedValue), `${envName} is not a number`); + + return parsedValue; + } + }, { envName: "QUOTA_CRITICAL_THRESHOLD", isUsedInKeycloakTheme: false, diff --git a/web/src/ui/pages/myServices/MyServicesCards/MyServicesCard/MyServicesCard.tsx b/web/src/ui/pages/myServices/MyServicesCards/MyServicesCard/MyServicesCard.tsx index 319862d11..d5053bfee 100644 --- a/web/src/ui/pages/myServices/MyServicesCards/MyServicesCard/MyServicesCard.tsx +++ b/web/src/ui/pages/myServices/MyServicesCards/MyServicesCard/MyServicesCard.tsx @@ -21,8 +21,9 @@ import type { Service } from "core/usecases/serviceManagement"; import { assert, type Equals } from "tsafe/assert"; import { TextField, TextFieldProps } from "onyxia-ui/TextField"; import MuiLink from "@mui/material/Link"; +import { env } from "env"; -const runningTimeThreshold = 7 * 24 * 3600 * 1000; +const runningTimeThreshold = env.RUNNING_TIME_THRESHOLD; function getDoesHaveBeenRunningForTooLong(params: { startTime: number }): boolean { const { startTime } = params; diff --git a/web/src/vite-env.d.ts b/web/src/vite-env.d.ts index f53f9c4eb..15093b55f 100644 --- a/web/src/vite-env.d.ts +++ b/web/src/vite-env.d.ts @@ -52,6 +52,7 @@ type ImportMetaEnv = { SAMPLE_DATASET_URL: string QUOTA_WARNING_THRESHOLD: string QUOTA_CRITICAL_THRESHOLD: string + RUNNING_TIME_THRESHOLD: string SERVICE_CONFIGURATION_EXPANDED_BY_DEFAULT: string S3_DOCUMENTATION_LINK: string VAULT_DOCUMENTATION_LINK: string From ee694618d0ecbaaae0465f22ca8074fabbba225e Mon Sep 17 00:00:00 2001 From: Joseph Garrone Date: Mon, 25 Nov 2024 14:46:50 +0100 Subject: [PATCH 2/2] Review --- web/.env | 12 +++++++----- web/src/env.ts | 2 +- .../MyServicesCard/MyServicesCard.tsx | 4 ++-- web/src/vite-env.d.ts | 2 +- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/web/.env b/web/.env index 14ebf5124..97c813de8 100644 --- a/web/.env +++ b/web/.env @@ -783,11 +783,13 @@ QUOTA_WARNING_THRESHOLD=75% # QUOTA_CRITICAL_THRESHOLD=95% -# This parameter defines the threshold for displaying a service's runtime as a key metric. -# The value is expressed in milliseconds. By default it is set to 7 * 24 * 3600 * 1000, -# it means any service running for 7 days (7 days * 24 hours * 3600 seconds * 1000 milliseconds) -# will have its runtime prominently displayed on the "My Services" page. -RUNNING_TIME_THRESHOLD=604800000 +# Services that have been running for too long are displayed on the "My Services" page +# with a warning alerting the user that the service has been running for "too long". +# This parameter allows you to define what "too long" means in your Onyxia instance. +# +# Default: 168 hours (7 days) +# +RUNNING_TIME_THRESHOLD_HOURS=168 # This parameter controls if the configurations tabs should be expanded by default # when the user navigates to the launcher page: diff --git a/web/src/env.ts b/web/src/env.ts index 6520588d6..c4e3ac755 100644 --- a/web/src/env.ts +++ b/web/src/env.ts @@ -1098,7 +1098,7 @@ export const { env, injectTransferableEnvsInQueryParams } = createParsedEnvs([ } }, { - envName: "RUNNING_TIME_THRESHOLD", + envName: "RUNNING_TIME_THRESHOLD_HOURS", isUsedInKeycloakTheme: false, validateAndParseOrGetDefault: ({ envValue, envName }) => { assert(envValue !== "", "Should have default in .env"); diff --git a/web/src/ui/pages/myServices/MyServicesCards/MyServicesCard/MyServicesCard.tsx b/web/src/ui/pages/myServices/MyServicesCards/MyServicesCard/MyServicesCard.tsx index d5053bfee..929a7b5d5 100644 --- a/web/src/ui/pages/myServices/MyServicesCards/MyServicesCard/MyServicesCard.tsx +++ b/web/src/ui/pages/myServices/MyServicesCards/MyServicesCard/MyServicesCard.tsx @@ -23,12 +23,12 @@ import { TextField, TextFieldProps } from "onyxia-ui/TextField"; import MuiLink from "@mui/material/Link"; import { env } from "env"; -const runningTimeThreshold = env.RUNNING_TIME_THRESHOLD; +const THRESHOLD_MS = 1000 * 60 * 60 * env.RUNNING_TIME_THRESHOLD_HOURS; function getDoesHaveBeenRunningForTooLong(params: { startTime: number }): boolean { const { startTime } = params; - return Date.now() - startTime > runningTimeThreshold; + return Date.now() - startTime > THRESHOLD_MS; } export type Props = { diff --git a/web/src/vite-env.d.ts b/web/src/vite-env.d.ts index 15093b55f..066ffd259 100644 --- a/web/src/vite-env.d.ts +++ b/web/src/vite-env.d.ts @@ -52,7 +52,7 @@ type ImportMetaEnv = { SAMPLE_DATASET_URL: string QUOTA_WARNING_THRESHOLD: string QUOTA_CRITICAL_THRESHOLD: string - RUNNING_TIME_THRESHOLD: string + RUNNING_TIME_THRESHOLD_HOURS: string SERVICE_CONFIGURATION_EXPANDED_BY_DEFAULT: string S3_DOCUMENTATION_LINK: string VAULT_DOCUMENTATION_LINK: string