From b758ee8d00b432c77992f9de7ab1861e1c738c72 Mon Sep 17 00:00:00 2001 From: Alex Creasy Date: Tue, 18 Jul 2023 16:26:39 +0100 Subject: [PATCH 1/2] Revert "Revert "Merge pull request #1503 from alexcreasy/configurable-thanos-port"" This reverts commit fec931d899a039a58fb691e0c10d9bc602be81e2. --- backend/src/routes/api/prometheus/index.ts | 2 ++ backend/src/utils/constants.ts | 3 +++ backend/src/utils/prometheusUtils.ts | 5 +++-- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/backend/src/routes/api/prometheus/index.ts b/backend/src/routes/api/prometheus/index.ts index 6e0b3ccc9e..c62dbb55e0 100644 --- a/backend/src/routes/api/prometheus/index.ts +++ b/backend/src/routes/api/prometheus/index.ts @@ -9,6 +9,7 @@ import { import { callPrometheusThanos } from '../../../utils/prometheusUtils'; import { createCustomError } from '../../../utils/requestUtils'; import { logRequestDetails } from '../../../utils/fileUtils'; +import { THANOS_DEFAULT_OAUTH_PORT } from '../../../utils/constants'; const handleError = (e: createError.HttpError) => { if (e?.code) { @@ -56,6 +57,7 @@ module.exports = async (fastify: KubeFastifyInstance) => { request, query, QueryType.QUERY_RANGE, + THANOS_DEFAULT_OAUTH_PORT, ).catch(handleError); }, ); diff --git a/backend/src/utils/constants.ts b/backend/src/utils/constants.ts index d19d3e534d..aea17f47b8 100644 --- a/backend/src/utils/constants.ts +++ b/backend/src/utils/constants.ts @@ -136,3 +136,6 @@ export const DEFAULT_NOTEBOOK_SIZES: NotebookSize[] = [ export const imageUrlRegex = /^([\w.\-_]+((?::\d+|)(?=\/[a-z0-9._-]+\/[a-z0-9._-]+))|)(?:\/|)([a-z0-9.\-_]+(?:\/[a-z0-9.\-_]+|))(?::([\w.\-_]{1,127})|)/; + +export const THANOS_DEFAULT_RBAC_PORT = '9092'; +export const THANOS_DEFAULT_OAUTH_PORT = '9091'; diff --git a/backend/src/utils/prometheusUtils.ts b/backend/src/utils/prometheusUtils.ts index a51bbb1173..f1f299b119 100644 --- a/backend/src/utils/prometheusUtils.ts +++ b/backend/src/utils/prometheusUtils.ts @@ -4,7 +4,7 @@ import { PrometheusQueryRangeResponse, QueryType, } from '../types'; -import { DEV_MODE } from './constants'; +import { DEV_MODE, THANOS_DEFAULT_RBAC_PORT } from './constants'; import { getNamespaces } from './notebookUtils'; import { getDashboardConfig } from './resourceUtils'; import { createCustomError } from './requestUtils'; @@ -88,12 +88,13 @@ export const callPrometheusThanos = ( request: OauthFastifyRequest, query: string, queryType: QueryType = QueryType.QUERY, + port = THANOS_DEFAULT_RBAC_PORT, ): Promise<{ code: number; response: T }> => callPrometheus( fastify, request, query, - generatePrometheusHostURL(fastify, 'thanos-querier', 'openshift-monitoring', '9092'), + generatePrometheusHostURL(fastify, 'thanos-querier', 'openshift-monitoring', port), queryType, ); From 4038b177432cc9b136f04e8b7ae3d43c5b4b03e8 Mon Sep 17 00:00:00 2001 From: Alex Creasy Date: Tue, 18 Jul 2023 17:04:16 +0100 Subject: [PATCH 2/2] Switch Thanos port of serving endpoint --- backend/src/routes/api/prometheus/index.ts | 5 +++-- backend/src/utils/constants.ts | 4 +++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/backend/src/routes/api/prometheus/index.ts b/backend/src/routes/api/prometheus/index.ts index c62dbb55e0..6677de0f0b 100644 --- a/backend/src/routes/api/prometheus/index.ts +++ b/backend/src/routes/api/prometheus/index.ts @@ -9,7 +9,7 @@ import { import { callPrometheusThanos } from '../../../utils/prometheusUtils'; import { createCustomError } from '../../../utils/requestUtils'; import { logRequestDetails } from '../../../utils/fileUtils'; -import { THANOS_DEFAULT_OAUTH_PORT } from '../../../utils/constants'; +import { THANOS_DEFAULT_ADMIN_PORT } from '../../../utils/constants'; const handleError = (e: createError.HttpError) => { if (e?.code) { @@ -57,7 +57,7 @@ module.exports = async (fastify: KubeFastifyInstance) => { request, query, QueryType.QUERY_RANGE, - THANOS_DEFAULT_OAUTH_PORT, + THANOS_DEFAULT_ADMIN_PORT, ).catch(handleError); }, ); @@ -77,6 +77,7 @@ module.exports = async (fastify: KubeFastifyInstance) => { request, query, QueryType.QUERY_RANGE, + THANOS_DEFAULT_ADMIN_PORT, ).catch(handleError); }, ); diff --git a/backend/src/utils/constants.ts b/backend/src/utils/constants.ts index aea17f47b8..e6f67b4aa1 100644 --- a/backend/src/utils/constants.ts +++ b/backend/src/utils/constants.ts @@ -138,4 +138,6 @@ export const imageUrlRegex = /^([\w.\-_]+((?::\d+|)(?=\/[a-z0-9._-]+\/[a-z0-9._-]+))|)(?:\/|)([a-z0-9.\-_]+(?:\/[a-z0-9.\-_]+|))(?::([\w.\-_]{1,127})|)/; export const THANOS_DEFAULT_RBAC_PORT = '9092'; -export const THANOS_DEFAULT_OAUTH_PORT = '9091'; + +// NOTE: This port only works for cluster-admins, it won't work for basic users - regardless of namespace privs. +export const THANOS_DEFAULT_ADMIN_PORT = '9091';