Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug 1777486: Read monitoriong URLs from the console-config configmap #4309

Merged
merged 1 commit into from Mar 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
46 changes: 36 additions & 10 deletions cmd/bridge/main.go
Expand Up @@ -80,7 +80,7 @@ func main() {
fK8sModeOffClusterEndpoint := fs.String("k8s-mode-off-cluster-endpoint", "", "URL of the Kubernetes API server.")
fK8sModeOffClusterSkipVerifyTLS := fs.Bool("k8s-mode-off-cluster-skip-verify-tls", false, "DEV ONLY. When true, skip verification of certs presented by k8s API server.")
fK8sModeOffClusterPrometheus := fs.String("k8s-mode-off-cluster-prometheus", "", "DEV ONLY. URL of the cluster's Prometheus server.")
fK8sModeOffClusterThanos := fs.String("k8s-mode-off-cluster-thanos", "", "DEV ONLY. URL of the cluster's Prometheus server.")
fK8sModeOffClusterThanos := fs.String("k8s-mode-off-cluster-thanos", "", "DEV ONLY. URL of the cluster's Thanos server.")
fK8sModeOffClusterAlertmanager := fs.String("k8s-mode-off-cluster-alertmanager", "", "DEV ONLY. URL of the cluster's AlertManager server.")
fK8sModeOffClusterMetering := fs.String("k8s-mode-off-cluster-metering", "", "DEV ONLY. URL of the cluster's metering server.")

Expand Down Expand Up @@ -108,6 +108,11 @@ func main() {
fStatuspageID := fs.String("statuspage-id", "", "Unique ID assigned by statuspage.io page that provides status info.")
fDocumentationBaseURL := fs.String("documentation-base-url", "", "The base URL for documentation links.")

fAlermanagerPublicURL := fs.String("alermanager-public-url", "", "Public URL of the cluster's AlertManager server.")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be Alertmanager instead of AlertManager

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree this one should be changed since it's public facing.

fGrafanaPublicURL := fs.String("grafana-public-url", "", "Public URL of the cluster's Grafana server.")
fPrometheusPublicURL := fs.String("prometheus-public-url", "", "Public URL of the cluster's Prometheus server.")
fThanosPublicURL := fs.String("thanos-public-url", "", "Public URL of the cluster's Thanos server.")

fLoadTestFactor := fs.Int("load-test-factor", 0, "DEV ONLY. The factor used to multiply k8s API list responses for load testing purposes.")

helmConfig := chartproxy.RegisterFlags(fs)
Expand Down Expand Up @@ -160,6 +165,23 @@ func main() {
documentationBaseURL = bridge.ValidateFlagIsURL("documentation-base-url", *fDocumentationBaseURL)
}

alertManagerPublicURL := &url.URL{}
if *fAlermanagerPublicURL != "" {
alertManagerPublicURL = bridge.ValidateFlagIsURL("alermanager-public-url", *fAlermanagerPublicURL)
}
grafanaPublicURL := &url.URL{}
if *fGrafanaPublicURL != "" {
grafanaPublicURL = bridge.ValidateFlagIsURL("grafana-public-url", *fGrafanaPublicURL)
}
prometheusPublicURL := &url.URL{}
if *fPrometheusPublicURL != "" {
prometheusPublicURL = bridge.ValidateFlagIsURL("prometheus-public-url", *fPrometheusPublicURL)
}
thanosPublicURL := &url.URL{}
if *fThanosPublicURL != "" {
thanosPublicURL = bridge.ValidateFlagIsURL("thanos-public-url", *fThanosPublicURL)
}

branding := *fBranding
if branding == "origin" {
branding = "okd"
Expand All @@ -182,15 +204,19 @@ func main() {
}

srv := &server.Server{
PublicDir: *fPublicDir,
BaseURL: baseURL,
LogoutRedirect: logoutRedirect,
Branding: branding,
CustomProductName: *fCustomProductName,
CustomLogoFile: *fCustomLogoFile,
StatuspageID: *fStatuspageID,
DocumentationBaseURL: documentationBaseURL,
LoadTestFactor: *fLoadTestFactor,
PublicDir: *fPublicDir,
BaseURL: baseURL,
LogoutRedirect: logoutRedirect,
Branding: branding,
CustomProductName: *fCustomProductName,
CustomLogoFile: *fCustomLogoFile,
StatuspageID: *fStatuspageID,
DocumentationBaseURL: documentationBaseURL,
AlertManagerPublicURL: alertManagerPublicURL,
GrafanaPublicURL: grafanaPublicURL,
PrometheusPublicURL: prometheusPublicURL,
ThanosPublicURL: thanosPublicURL,
LoadTestFactor: *fLoadTestFactor,
}

// if !in-cluster (dev) we should not pass these values to the frontend
Expand Down
Expand Up @@ -91,10 +91,10 @@ describe('<PrometheusGraphLink />', () => {
});

describe('getPrometheusExpressionBrowserURL()', () => {
const urls = {
'prometheus-k8s': 'https://mock.prometheus.url',
};
const url = getPrometheusExpressionBrowserURL(urls, ['test-query-1', 'test-query-2']);
const url = getPrometheusExpressionBrowserURL('https://mock.prometheus.url', [
'test-query-1',
'test-query-2',
]);
expect(url).toBe(
'https://mock.prometheus.url/graph?g0.range_input=1h&g0.expr=test-query-1&g0.tab=0&g1.range_input=1h&g1.expr=test-query-2&g1.tab=0',
);
Expand Down
23 changes: 0 additions & 23 deletions frontend/public/actions/features.ts
Expand Up @@ -193,28 +193,6 @@ const detectCanCreateProject = (dispatch) =>
},
);

const monitoringConfigMapPath = `${k8sBasePath}/api/v1/namespaces/openshift-monitoring/configmaps/sharing-config`;
const detectMonitoringURLs = (dispatch) =>
coFetchJSON(monitoringConfigMapPath).then(
(res) => {
const { alertmanagerURL, grafanaURL, prometheusURL } = res.data;
if (!_.isEmpty(alertmanagerURL)) {
dispatch(setMonitoringURL(MonitoringRoutes.Alertmanager, alertmanagerURL));
}
if (!_.isEmpty(grafanaURL)) {
dispatch(setMonitoringURL(MonitoringRoutes.Grafana, grafanaURL));
}
if (!_.isEmpty(prometheusURL)) {
dispatch(setMonitoringURL(MonitoringRoutes.Prometheus, prometheusURL));
}
},
(err) => {
if (!_.includes([401, 403, 404, 500], _.get(err, 'response.status'))) {
setTimeout(() => detectMonitoringURLs(dispatch), 15000);
}
},
);

const loggingConfigMapPath = `${k8sBasePath}/api/v1/namespaces/openshift-logging/configmaps/sharing-config`;
const detectLoggingURL = (dispatch) =>
coFetchJSON(loggingConfigMapPath).then(
Expand Down Expand Up @@ -278,7 +256,6 @@ export const detectFeatures = () => (dispatch: Dispatch) =>
[
detectOpenShift,
detectCanCreateProject,
detectMonitoringURLs,
detectClusterVersion,
detectUser,
detectLoggingURL,
Expand Down
8 changes: 3 additions & 5 deletions frontend/public/components/graphs/prometheus-graph.tsx
Expand Up @@ -6,13 +6,11 @@ import { Link } from 'react-router-dom';

import { FLAGS } from '@console/shared';
import { featureReducerName } from '../../reducers/features';
import { MonitoringRoutes } from '../../reducers/monitoring';
import { getActivePerspective, getActiveNamespace } from '../../reducers/ui';
import { RootState } from '../../redux';

export const getPrometheusExpressionBrowserURL = (urls, queries): string => {
const base = urls && urls[MonitoringRoutes.Prometheus];
if (!base || _.isEmpty(queries)) {
export const getPrometheusExpressionBrowserURL = (url, queries): string => {
if (!url || _.isEmpty(queries)) {
return null;
}
const params = new URLSearchParams();
Expand All @@ -21,7 +19,7 @@ export const getPrometheusExpressionBrowserURL = (urls, queries): string => {
params.set(`g${i}.expr`, query);
params.set(`g${i}.tab`, '0');
});
return `${base}/graph?${params.toString()}`;
return `${url}/graph?${params.toString()}`;
};

const mapStateToProps = (state: RootState) => ({
Expand Down
18 changes: 4 additions & 14 deletions frontend/public/components/monitoring.tsx
Expand Up @@ -21,14 +21,7 @@ import { withFallback } from '@console/shared/src/components/error/error-boundar
import * as k8sActions from '../actions/k8s';
import * as UIActions from '../actions/ui';
import { coFetchJSON } from '../co-fetch';
import {
alertState,
AlertStates,
connectToURLs,
MonitoringRoutes,
silenceState,
SilenceStates,
} from '../reducers/monitoring';
import { alertState, AlertStates, silenceState, SilenceStates } from '../reducers/monitoring';
import store from '../redux';
import { Table, TableData, TableRow, TextFilter } from './factory';
import { confirmModal } from './modals';
Expand Down Expand Up @@ -767,18 +760,15 @@ const AlertsPageDescription = () => (
</p>
);

const HeaderAlertmanagerLink_ = ({ path, urls }) =>
_.isEmpty(urls[MonitoringRoutes.Alertmanager]) ? null : (
const HeaderAlertmanagerLink = ({ path }) =>
_.isEmpty(window.SERVER_FLAGS.alertManagerPublicURL) ? null : (
<span className="monitoring-header-link">
<ExternalLink
href={`${urls[MonitoringRoutes.Alertmanager]}${path || ''}`}
href={`${window.SERVER_FLAGS.alertManagerPublicURL}${path || ''}`}
text="Alertmanager UI"
/>
</span>
);
const HeaderAlertmanagerLink = connectToURLs(MonitoringRoutes.Alertmanager)(
HeaderAlertmanagerLink_,
);

const alertsRowFilter = {
type: 'alert-state',
Expand Down
8 changes: 3 additions & 5 deletions frontend/public/components/monitoring/dashboards/index.tsx
Expand Up @@ -16,7 +16,6 @@ import { withFallback } from '@console/shared/src/components/error/error-boundar

import * as UIActions from '../../../actions/ui';
import { ErrorBoundaryFallback } from '../../error';
import { connectToURLs, MonitoringRoutes } from '../../../reducers/monitoring';
import { RootState } from '../../../redux';
import { getPrometheusURL, PrometheusEndpoint } from '../../graphs/helpers';
import { ExternalLink, history, LoadingInline, useSafeFetch } from '../../utils';
Expand Down Expand Up @@ -402,13 +401,12 @@ const Board: React.FC<BoardProps> = ({ rows }) => (
</>
);

const GrafanaLink_ = ({ urls }) =>
_.isEmpty(urls[MonitoringRoutes.Grafana]) ? null : (
const GrafanaLink = () =>
_.isEmpty(window.SERVER_FLAGS.grafanaPublicURL) ? null : (
<span className="monitoring-header-link">
<ExternalLink href={urls[MonitoringRoutes.Grafana]} text="Grafana UI" />
<ExternalLink href={window.SERVER_FLAGS.grafanaPublicURL} text="Grafana UI" />
</span>
);
const GrafanaLink = connectToURLs(MonitoringRoutes.Grafana)(GrafanaLink_);

const MonitoringDashboardsPage_: React.FC<MonitoringDashboardsPageProps> = ({
deleteAll,
Expand Down
12 changes: 6 additions & 6 deletions frontend/public/components/monitoring/metrics.tsx
Expand Up @@ -43,7 +43,6 @@ import {
YellowExclamationTriangleIcon,
} from '@console/shared';
import * as UIActions from '../../actions/ui';
import { connectToURLs, MonitoringRoutes } from '../../reducers/monitoring';
import { RootState } from '../../redux';
import { fuzzyCaseInsensitive } from '../factory/table-filters';
import { PROMETHEUS_BASE_PATH } from '../graphs';
Expand Down Expand Up @@ -171,13 +170,16 @@ const MetricsActionsMenu = connect(
},
)(MetricsActionsMenu_);

const headerPrometheusLinkStateToProps = ({ UI }: RootState, { urls }) => {
const headerPrometheusLinkStateToProps = ({ UI }: RootState) => {
const liveQueries = UI.getIn(['queryBrowser', 'queries']).filter(
(q) => q.get('isEnabled') && q.get('query'),
);
const queryStrings = _.map(liveQueries.toJS(), 'query');
const url = window.SERVER_FLAGS.prometheusPublicURL;
return {
url: getPrometheusExpressionBrowserURL(urls, queryStrings) || urls[MonitoringRoutes.Prometheus],
url:
getPrometheusExpressionBrowserURL(url, queryStrings) ||
window.SERVER_FLAGS.prometheusPublicURL,
};
};

Expand All @@ -188,9 +190,7 @@ const HeaderPrometheusLink_ = ({ url }) => {
</span>
) : null;
};
const HeaderPrometheusLink = connectToURLs(MonitoringRoutes.Prometheus)(
connect(headerPrometheusLinkStateToProps)(HeaderPrometheusLink_),
);
const HeaderPrometheusLink = connect(headerPrometheusLinkStateToProps)(HeaderPrometheusLink_);

export const graphStateToProps = ({ UI }: RootState) => ({
hideGraphs: !!UI.getIn(['monitoring', 'hideGraphs']),
Expand Down
4 changes: 4 additions & 0 deletions frontend/public/declarations.d.ts
Expand Up @@ -31,6 +31,10 @@ declare interface Window {
prometheusBaseURL: string;
prometheusTenancyBaseURL: string;
requestTokenURL: string;
alertManagerPublicURL: string;
grafanaPublicURL: string;
prometheusPublicURL: string;
thanosPublicURL: string;
statuspageID: string;
GOARCH: string;
GOOS: string;
Expand Down
3 changes: 0 additions & 3 deletions frontend/public/reducers/monitoring.ts
Expand Up @@ -18,9 +18,6 @@ export const enum SilenceStates {
}

export enum MonitoringRoutes {
Prometheus = 'prometheus-k8s',
Alertmanager = 'alertmanager-main',
Grafana = 'grafana',
Kibana = 'kibana',
}

Expand Down
47 changes: 30 additions & 17 deletions pkg/server/server.go
Expand Up @@ -64,6 +64,10 @@ type jsGlobals struct {
CustomLogoURL string `json:"customLogoURL"`
StatuspageID string `json:"statuspageID"`
DocumentationBaseURL string `json:"documentationBaseURL"`
AlertManagerPublicURL string `json:"alertManagerPublicURL"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Alertmanager" is written as one word, so we should use AlertmanagerPublicURL and alertmanagerPublicURL.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was following the pattern we already use https://github.com/openshift/console/blob/master/pkg/server/server.go#L60
Would change this name nit globally as a followUP

GrafanaPublicURL string `json:"grafanaPublicURL"`
PrometheusPublicURL string `json:"prometheusPublicURL"`
ThanosPublicURL string `json:"thanosPublicURL"`
LoadTestFactor int `json:"loadTestFactor"`
GOARCH string `json:"GOARCH"`
GOOS string `json:"GOOS"`
Expand Down Expand Up @@ -98,6 +102,11 @@ type Server struct {
HelmChartRepoProxyConfig *proxy.Config
GOARCH string
GOOS string
// Monitoring and Logging related URLs
AlertManagerPublicURL *url.URL
GrafanaPublicURL *url.URL
PrometheusPublicURL *url.URL
ThanosPublicURL *url.URL
}

func (s *Server) authDisabled() bool {
Expand Down Expand Up @@ -340,23 +349,27 @@ func (s *Server) handleMonitoringDashboardConfigmaps(w http.ResponseWriter, r *h

func (s *Server) indexHandler(w http.ResponseWriter, r *http.Request) {
jsg := &jsGlobals{
ConsoleVersion: version.Version,
AuthDisabled: s.authDisabled(),
KubectlClientID: s.KubectlClientID,
BasePath: s.BaseURL.Path,
LoginURL: proxy.SingleJoiningSlash(s.BaseURL.String(), authLoginEndpoint),
LoginSuccessURL: proxy.SingleJoiningSlash(s.BaseURL.String(), AuthLoginSuccessEndpoint),
LoginErrorURL: proxy.SingleJoiningSlash(s.BaseURL.String(), AuthLoginErrorEndpoint),
LogoutURL: proxy.SingleJoiningSlash(s.BaseURL.String(), authLogoutEndpoint),
LogoutRedirect: s.LogoutRedirect.String(),
KubeAPIServerURL: s.KubeAPIServerURL,
Branding: s.Branding,
CustomProductName: s.CustomProductName,
StatuspageID: s.StatuspageID,
DocumentationBaseURL: s.DocumentationBaseURL.String(),
LoadTestFactor: s.LoadTestFactor,
GOARCH: s.GOARCH,
GOOS: s.GOOS,
ConsoleVersion: version.Version,
AuthDisabled: s.authDisabled(),
KubectlClientID: s.KubectlClientID,
BasePath: s.BaseURL.Path,
LoginURL: proxy.SingleJoiningSlash(s.BaseURL.String(), authLoginEndpoint),
LoginSuccessURL: proxy.SingleJoiningSlash(s.BaseURL.String(), AuthLoginSuccessEndpoint),
LoginErrorURL: proxy.SingleJoiningSlash(s.BaseURL.String(), AuthLoginErrorEndpoint),
LogoutURL: proxy.SingleJoiningSlash(s.BaseURL.String(), authLogoutEndpoint),
LogoutRedirect: s.LogoutRedirect.String(),
KubeAPIServerURL: s.KubeAPIServerURL,
Branding: s.Branding,
CustomProductName: s.CustomProductName,
StatuspageID: s.StatuspageID,
DocumentationBaseURL: s.DocumentationBaseURL.String(),
AlertManagerPublicURL: s.AlertManagerPublicURL.String(),
GrafanaPublicURL: s.GrafanaPublicURL.String(),
PrometheusPublicURL: s.PrometheusPublicURL.String(),
ThanosPublicURL: s.ThanosPublicURL.String(),
GOARCH: s.GOARCH,
GOOS: s.GOOS,
LoadTestFactor: s.LoadTestFactor,
}

if !s.authDisabled() {
Expand Down
16 changes: 16 additions & 0 deletions pkg/serverconfig/config.go
Expand Up @@ -35,6 +35,7 @@ func SetFlagsFromConfig(fs *flag.FlagSet, filename string) (err error) {
addAuth(fs, &config.Auth)
addCustomization(fs, &config.Customization)
addProviders(fs, &config.Providers)
addMonitoringInfo(fs, &config.MonitoringInfo)
addHelmConfig(fs, &config.Helm)

return nil
Expand Down Expand Up @@ -137,6 +138,21 @@ func addProviders(fs *flag.FlagSet, providers *Providers) {
}
}

func addMonitoringInfo(fs *flag.FlagSet, monitoring *MonitoringInfo) {
if monitoring.AlertmanagerPublicURL != "" {
fs.Set("alermanager-url", monitoring.AlertmanagerPublicURL)
}
if monitoring.GrafanaPublicURL != "" {
fs.Set("grafana-url", monitoring.GrafanaPublicURL)
}
if monitoring.PrometheusPublicURL != "" {
fs.Set("prometheus-url", monitoring.PrometheusPublicURL)
}
if monitoring.ThanosPublicURL != "" {
fs.Set("thanos-url", monitoring.ThanosPublicURL)
}
}

func addCustomization(fs *flag.FlagSet, customization *Customization) {
if customization.Branding != "" {
fs.Set("branding", customization.Branding)
Expand Down