mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Allowing to save prometheus service address
Signed-off-by: alexfront <alex.andreev.email@gmail.com>
This commit is contained in:
parent
0393d1f782
commit
de46907956
@ -57,6 +57,10 @@
|
|||||||
font-size: smaller;
|
font-size: smaller;
|
||||||
opacity: 0.8;
|
opacity: 0.8;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
p + p, .hint + p {
|
||||||
|
padding-top: $padding;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.status-table {
|
.status-table {
|
||||||
@ -79,7 +83,13 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.Input,.Select {
|
.Input, .Select {
|
||||||
margin-top: 10px;
|
margin-top: 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.Select {
|
||||||
|
&__control {
|
||||||
|
box-shadow: 0 0 0 1px $borderFaintColor;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@ -1,10 +1,11 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import merge from "lodash/merge";
|
|
||||||
import { observer } from "mobx-react";
|
import { observer } from "mobx-react";
|
||||||
import { prometheusProviders } from "../../../../common/prometheus-providers";
|
import { prometheusProviders } from "../../../../common/prometheus-providers";
|
||||||
import { Cluster } from "../../../../main/cluster";
|
import { Cluster } from "../../../../main/cluster";
|
||||||
import { SubTitle } from "../../layout/sub-title";
|
import { SubTitle } from "../../layout/sub-title";
|
||||||
import { Select, SelectOption } from "../../select";
|
import { Select, SelectOption } from "../../select";
|
||||||
|
import { Input } from "../../input";
|
||||||
|
import { observable, computed } from "mobx";
|
||||||
|
|
||||||
const options: SelectOption<string>[] = [
|
const options: SelectOption<string>[] = [
|
||||||
{ value: "", label: "Auto detect" },
|
{ value: "", label: "Auto detect" },
|
||||||
@ -17,6 +18,52 @@ interface Props {
|
|||||||
|
|
||||||
@observer
|
@observer
|
||||||
export class ClusterPrometheusSetting extends React.Component<Props> {
|
export class ClusterPrometheusSetting extends React.Component<Props> {
|
||||||
|
@observable path = "";
|
||||||
|
@observable provider = "";
|
||||||
|
|
||||||
|
@computed get canEditPrometheusPath() {
|
||||||
|
if (this.provider === "" || this.provider === "lens") return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
componentDidMount() {
|
||||||
|
const { prometheus, prometheusProvider } = this.props.cluster.preferences;
|
||||||
|
if (prometheus) {
|
||||||
|
const prefix = prometheus.prefix || "";
|
||||||
|
this.path = `${prometheus.namespace}/${prometheus.service}:${prometheus.port}${prefix}`;
|
||||||
|
}
|
||||||
|
if (prometheusProvider) {
|
||||||
|
this.provider = prometheusProvider.type;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
parsePrometheusPath = () => {
|
||||||
|
if (!this.provider || !this.path) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
const parsed = this.path.split(/\/|:/, 3);
|
||||||
|
const apiPrefix = this.path.substring(parsed.join("/").length);
|
||||||
|
if (!parsed[0] || !parsed[1] || !parsed[2]) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
namespace: parsed[0],
|
||||||
|
service: parsed[1],
|
||||||
|
port: parseInt(parsed[2]),
|
||||||
|
prefix: apiPrefix
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onSaveProvider = () => {
|
||||||
|
this.props.cluster.preferences.prometheusProvider = this.provider ?
|
||||||
|
{ type: this.provider } :
|
||||||
|
null;
|
||||||
|
}
|
||||||
|
|
||||||
|
onSavePath = () => {
|
||||||
|
this.props.cluster.preferences.prometheus = this.parsePrometheusPath();
|
||||||
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@ -26,18 +73,32 @@ export class ClusterPrometheusSetting extends React.Component<Props> {
|
|||||||
<a href="https://github.com/lensapp/lens/blob/master/troubleshooting/custom-prometheus.md" target="_blank">guide</a>{" "}
|
<a href="https://github.com/lensapp/lens/blob/master/troubleshooting/custom-prometheus.md" target="_blank">guide</a>{" "}
|
||||||
for possible configuration changes.
|
for possible configuration changes.
|
||||||
</p>
|
</p>
|
||||||
|
<p>Prometheus installation method.</p>
|
||||||
<Select
|
<Select
|
||||||
value={this.props.cluster.preferences.prometheusProvider?.type || ""}
|
value={this.provider}
|
||||||
onChange={({value}) => {
|
onChange={({value}) => {
|
||||||
const provider = {
|
this.provider = value;
|
||||||
prometheusProvider: {
|
this.onSaveProvider();
|
||||||
type: value
|
|
||||||
}
|
|
||||||
}
|
|
||||||
merge(this.props.cluster.preferences, provider);
|
|
||||||
}}
|
}}
|
||||||
options={options}
|
options={options}
|
||||||
/>
|
/>
|
||||||
|
<span className="hint">What query format is used to fetch metrics from Prometheus</span>
|
||||||
|
{this.canEditPrometheusPath && (
|
||||||
|
<>
|
||||||
|
<p>Prometheus service address.</p>
|
||||||
|
<Input
|
||||||
|
theme="round-black"
|
||||||
|
value={this.path}
|
||||||
|
onChange={(value) => this.path = value}
|
||||||
|
onBlur={this.onSavePath}
|
||||||
|
placeholder="<namespace>/<service>:<port>"
|
||||||
|
/>
|
||||||
|
<span className="hint">
|
||||||
|
An address to an existing Prometheus installation{" "}
|
||||||
|
(<namespace>/<service>:<port>). Lens tries to auto-detect address if left empty.
|
||||||
|
</span>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user