Skip to content

Commit 6799f08

Browse files
Merge pull request #639 from PeterYurkovich/OCPBUGS-64942
[release-4.17] OCPBUGS-64942: Use tenancy access to metric lables
2 parents f67995d + 8524aca commit 6799f08

7 files changed

Lines changed: 29 additions & 24 deletions

File tree

web/src/components/alerting.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
SilenceStates,
1313
TableColumn,
1414
Timestamp,
15+
useActiveNamespace,
1516
useListPageFilter,
1617
useResolvedExtensions,
1718
VirtualizedTable,
@@ -44,7 +45,6 @@ import { Link, Redirect, Route, RouteComponentProps, Switch, withRouter } from '
4445

4546
// TODO: These will be available in future versions of the plugin SDK
4647
import { formatPrometheusDuration } from './console/utils/datetime';
47-
import { useActiveNamespace } from './console/console-shared/hooks/useActiveNamespace';
4848

4949
import { withFallback } from './console/console-shared/error/error-boundary';
5050
import {
@@ -436,7 +436,7 @@ type SilencedAlertsListProps = RouteComponentProps & { alerts: Alert[] };
436436
const SilencedAlertsList_: React.FC<SilencedAlertsListProps> = ({ alerts, history }) => {
437437
const { t } = useTranslation('plugin__monitoring-plugin');
438438
const { isDev } = usePerspective();
439-
const namespace = useActiveNamespace();
439+
const [namespace] = useActiveNamespace();
440440

441441
return _.isEmpty(alerts) ? (
442442
<div className="pf-u-text-align-center">{t('None found')}</div>
@@ -487,7 +487,7 @@ const SilencedAlertsList = withRouter(SilencedAlertsList_);
487487
const SilencesDetailsPage_: React.FC<RouteComponentProps<{ id: string }>> = ({ match }) => {
488488
const { t } = useTranslation('plugin__monitoring-plugin');
489489

490-
const namespace = useActiveNamespace();
490+
const [namespace] = useActiveNamespace();
491491
const { isDev, alertsKey } = usePerspective();
492492

493493
const alertsLoaded = useSelector(({ observe }: RootState) => observe.get(alertsKey)?.loaded);
@@ -657,7 +657,7 @@ const tableRuleClasses = [
657657
const RuleTableRow: React.FC<RowProps<Rule>> = ({ obj }) => {
658658
const { t } = useTranslation('plugin__monitoring-plugin');
659659
const { isDev } = usePerspective();
660-
const namespace = useActiveNamespace();
660+
const [namespace] = useActiveNamespace();
661661

662662
const title: string = obj.annotations?.description || obj.annotations?.message;
663663

@@ -690,7 +690,7 @@ const RuleTableRow: React.FC<RowProps<Rule>> = ({ obj }) => {
690690
const RulesPage_: React.FC = () => {
691691
const { t } = useTranslation('plugin__monitoring-plugin');
692692
const { isDev, rulesKey, alertsKey } = usePerspective();
693-
const namespace = useActiveNamespace();
693+
const [namespace] = useActiveNamespace();
694694

695695
const data: Rule[] = useSelector(({ observe }: RootState) => observe.get(rulesKey));
696696
const { loaded = false, loadError }: Alerts = useSelector(
@@ -1122,7 +1122,7 @@ const PollerPages = () => {
11221122
const dispatch = useDispatch();
11231123

11241124
const { isDev } = usePerspective();
1125-
const namespace = useActiveNamespace();
1125+
const [namespace] = useActiveNamespace();
11261126

11271127
const [customExtensions] =
11281128
useResolvedExtensions<AlertingRulesSourceExtension>(isAlertingRulesSource);

web/src/components/alerting/SilencesUtils.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
PrometheusAlert,
66
Silence,
77
SilenceStates,
8+
useActiveNamespace,
89
} from '@openshift-console/dynamic-plugin-sdk';
910
import * as _ from 'lodash-es';
1011
import { useTranslation } from 'react-i18next';
@@ -37,7 +38,6 @@ import { usePerspective } from '../hooks/usePerspective';
3738
import { useDispatch } from 'react-redux';
3839
import { LoadingInline } from '../console/utils/status-box';
3940
import { MonitoringResourceIcon, OnToggle, SeverityCounts, StateTimestamp } from './AlertUtils';
40-
import { useActiveNamespace } from '../console/console-shared/hooks/useActiveNamespace';
4141

4242
export const tableSilenceClasses = [
4343
'pf-c-table__action', // Checkbox
@@ -51,7 +51,7 @@ export const tableSilenceClasses = [
5151
export const SilenceTableRow: React.FC<SilenceTableRowProps> = ({ obj, showCheckbox }) => {
5252
const { t } = useTranslation('plugin__monitoring-plugin');
5353
const { isDev } = usePerspective();
54-
const namespace = useActiveNamespace();
54+
const [namespace] = useActiveNamespace();
5555

5656
const { createdBy, endsAt, firingAlerts, id, name, startsAt } = obj;
5757
const state = silenceState(obj);
@@ -191,7 +191,7 @@ const SilenceDropdown_: React.FC<SilenceDropdownProps> = ({
191191
}) => {
192192
const { t } = useTranslation('plugin__monitoring-plugin');
193193
const { isDev } = usePerspective();
194-
const namespace = useActiveNamespace();
194+
const [namespace] = useActiveNamespace();
195195

196196
const [isOpen, setIsOpen, , setClosed] = useBoolean(false);
197197
const [isModalOpen, , setModalOpen, setModalClosed] = useBoolean(false);
@@ -243,7 +243,7 @@ const ExpireSilenceModal: React.FC<ExpireSilenceModalProps> = ({
243243
}) => {
244244
const { t } = useTranslation('plugin__monitoring-plugin');
245245
const { perspective, isDev } = usePerspective();
246-
const namespace = useActiveNamespace();
246+
const [namespace] = useActiveNamespace();
247247

248248
const dispatch = useDispatch();
249249

web/src/components/console/console-shared/hooks/useActiveNamespace.ts

Lines changed: 0 additions & 5 deletions
This file was deleted.

web/src/components/metrics.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
PrometheusData,
55
PrometheusEndpoint,
66
PrometheusLabels,
7+
useActiveNamespace,
78
useResolvedExtensions,
89
YellowExclamationTriangleIcon,
910
} from '@openshift-console/dynamic-plugin-sdk';
@@ -86,7 +87,6 @@ import {
8687
isDataSource,
8788
} from '@openshift-console/dynamic-plugin-sdk/lib/extensions/dashboard-data-source';
8889
import { usePerspective } from './hooks/usePerspective';
89-
import { useActiveNamespace } from './console/console-shared/hooks/useActiveNamespace';
9090

9191
// Stores information about the currently focused query input
9292
let focusedQuery;
@@ -101,7 +101,7 @@ export const PreDefinedQueriesDropdown = () => {
101101
const [selected, setSelected] = React.useState('');
102102
let predefinedQueries: PredefinedQueryType[];
103103

104-
const activeNamespace = useActiveNamespace();
104+
const [activeNamespace] = useActiveNamespace();
105105
const { isDev } = usePerspective();
106106

107107
const { t } = useTranslation('plugin__monitoring-plugin');
@@ -837,7 +837,7 @@ const Query: React.FC<{ index: number; customDatasource?: CustomDataSource }> =
837837
const switchKey = `${id}-${isEnabled}`;
838838
const switchLabel = isEnabled ? t('Disable query') : t('Enable query');
839839

840-
const activeNamespace = useActiveNamespace();
840+
const [activeNamespace] = useActiveNamespace();
841841
const { isDev } = usePerspective();
842842

843843
return (
@@ -867,7 +867,7 @@ const Query: React.FC<{ index: number; customDatasource?: CustomDataSource }> =
867867
<QueryKebab index={index} />
868868
</div>
869869
</div>
870-
{/* If namespace is defined getPrometheusURL() will use the
870+
{/* If namespace is defined getPrometheusURL() will use the
871871
PROMETHEUS_TENANCY_BASE_PATH for the developer view */}
872872
<QueryTable
873873
index={index}

web/src/components/promql-expression-input.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ import {
3333
} from '@codemirror/view';
3434
import {
3535
PrometheusEndpoint,
36+
useActiveNamespace,
37+
useActivePerspective,
3638
YellowExclamationTriangleIcon,
3739
} from '@openshift-console/dynamic-plugin-sdk';
3840
import { Button } from '@patternfly/react-core';
@@ -43,7 +45,7 @@ import { useTranslation } from 'react-i18next';
4345

4446
import { useSafeFetch } from './console/utils/safe-fetch-hook';
4547

46-
import { PROMETHEUS_BASE_PATH } from './utils';
48+
import { PROMETHEUS_BASE_PATH, PROMETHEUS_TENANCY_BASE_PATH } from './utils';
4749
import './_promql-expression-input.scss';
4850

4951
type InteractionTarget = {
@@ -258,14 +260,21 @@ export const PromQLExpressionInput: React.FC<PromQLExpressionInputProps> = ({
258260
const viewRef = React.useRef<EditorView | null>(null);
259261
const [metricNames, setMetricNames] = React.useState<Array<string>>([]);
260262
const [errorMessage, setErrorMessage] = React.useState<string | undefined>();
263+
const [namespace] = useActiveNamespace();
264+
const [perspective] = useActivePerspective();
261265

262266
const placeholder = t('Expression (press Shift+Enter for newlines)');
263267

264268
// eslint-disable-next-line react-hooks/exhaustive-deps
265269
const safeFetch = React.useCallback(useSafeFetch(), []);
266270

267271
React.useEffect(() => {
268-
safeFetch(`${PROMETHEUS_BASE_PATH}/${PrometheusEndpoint.LABEL}/__name__/values`)
272+
let url = `${PROMETHEUS_BASE_PATH}/${PrometheusEndpoint.LABEL}/__name__/values`;
273+
if (perspective === 'dev') {
274+
// eslint-disable-next-line max-len
275+
url = `${PROMETHEUS_TENANCY_BASE_PATH}/${PrometheusEndpoint.LABEL}/__name__/values?namespace=${namespace}`;
276+
}
277+
safeFetch(url)
269278
.then((response) => {
270279
const metrics = response?.data;
271280
setMetricNames(metrics);
@@ -279,7 +288,7 @@ export const PromQLExpressionInput: React.FC<PromQLExpressionInputProps> = ({
279288
setErrorMessage(message);
280289
}
281290
});
282-
}, [safeFetch, t]);
291+
}, [safeFetch, t, namespace, perspective]);
283292

284293
const onClear = () => {
285294
if (viewRef.current !== null) {

web/src/components/query-browser.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
PrometheusResponse,
88
PrometheusResult,
99
PrometheusValue,
10+
useActiveNamespace,
1011
} from '@openshift-console/dynamic-plugin-sdk';
1112
import {
1213
Chart,
@@ -72,7 +73,6 @@ import { PrometheusAPIError, RootState, TimeRange } from './types';
7273
import { getTimeRanges } from './utils';
7374

7475
import { usePerspective } from './hooks/usePerspective';
75-
import { useActiveNamespace } from './console/console-shared/hooks/useActiveNamespace';
7676

7777
const spans = ['5m', '15m', '30m', '1h', '2h', '6h', '12h', '1d', '2d', '1w', '2w'];
7878
export const colors = queryBrowserTheme.line.colorScale;
@@ -712,7 +712,7 @@ const QueryBrowser_: React.FC<QueryBrowserProps> = ({
712712

713713
const canStack = _.sumBy(graphData, 'length') <= maxStacks;
714714

715-
const activeNamespace = useActiveNamespace();
715+
const [activeNamespace] = useActiveNamespace();
716716
const { isDev } = usePerspective();
717717

718718
// If provided, `timespan` overrides any existing span setting

web/src/components/utils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { alertingErrored, alertingLoaded, alertingLoading, Perspective } from '.
2020
import { AlertSource, MonitoringResource, Target, TimeRange } from './types';
2121

2222
export const PROMETHEUS_BASE_PATH = window.SERVER_FLAGS.prometheusBaseURL;
23+
export const PROMETHEUS_TENANCY_BASE_PATH = window.SERVER_FLAGS.prometheusTenancyBaseURL;
2324
export const QUERY_CHUNK_SIZE = 24 * 60 * 60 * 1000;
2425

2526
export const AlertResource: MonitoringResource = {

0 commit comments

Comments
 (0)