集群健康检查URL中可以输入主机名

This commit is contained in:
GoEdgeLab
2021-02-24 16:20:04 +08:00
parent ac58b02235
commit a9768892eb

View File

@@ -1,131 +1,150 @@
Vue.component("health-check-config-box", { Vue.component("health-check-config-box", {
props: ["v-health-check-config"], props: ["v-health-check-config"],
data: function () { data: function () {
let healthCheckConfig = this.vHealthCheckConfig let healthCheckConfig = this.vHealthCheckConfig
let urlProtocol = "http" let urlProtocol = "http"
let urlPort = "" let urlPort = ""
let urlRequestURI = "/" let urlRequestURI = "/"
let urlHost = ""
if (healthCheckConfig == null) { if (healthCheckConfig == null) {
healthCheckConfig = { healthCheckConfig = {
isOn: false, isOn: false,
url: "", url: "",
interval: {count: 60, unit: "second"}, interval: {count: 60, unit: "second"},
statusCodes: [200], statusCodes: [200],
timeout: {count: 10, unit: "second"}, timeout: {count: 10, unit: "second"},
countTries: 3, countTries: 3,
tryDelay: {count: 100, unit: "ms"}, tryDelay: {count: 100, unit: "ms"},
autoDown: true, autoDown: true,
countUp: 1, countUp: 1,
countDown: 1 countDown: 1
} }
let that = this let that = this
setTimeout(function () { setTimeout(function () {
that.changeURL() that.changeURL()
}, 500) }, 500)
} else { } else {
try { try {
let url = new URL(healthCheckConfig.url) let url = new URL(healthCheckConfig.url)
urlProtocol = url.protocol.substring(0, url.protocol.length - 1) urlProtocol = url.protocol.substring(0, url.protocol.length - 1)
urlPort = url.port
urlRequestURI = url.pathname
if (url.search.length > 0) {
urlRequestURI += url.search
}
} catch (e) {
}
if (healthCheckConfig.statusCodes == null) { // 域名
healthCheckConfig.statusCodes = [200] urlHost = url.host
} if (urlHost == "%24%7Bhost%7D") {
if (healthCheckConfig.interval == null) { urlHost = "${host}"
healthCheckConfig.interval = {count: 60, unit: "second"} }
} let colonIndex = urlHost.indexOf(":")
if (healthCheckConfig.timeout == null) { if (colonIndex > 0) {
healthCheckConfig.timeout = {count: 10, unit: "second"} urlHost = urlHost.substring(0, colonIndex)
} }
if (healthCheckConfig.tryDelay == null) {
healthCheckConfig.tryDelay = {count: 100, unit: "ms"} urlPort = url.port
} urlRequestURI = url.pathname
if (healthCheckConfig.countUp == null || healthCheckConfig.countUp < 1) { if (url.search.length > 0) {
healthCheckConfig.countUp = 1 urlRequestURI += url.search
} }
if (healthCheckConfig.countDown == null || healthCheckConfig.countDown < 1) { } catch (e) {
healthCheckConfig.countDown = 1 }
}
} if (healthCheckConfig.statusCodes == null) {
console.log(healthCheckConfig.countUp, healthCheckConfig.countDown) healthCheckConfig.statusCodes = [200]
return { }
healthCheck: healthCheckConfig, if (healthCheckConfig.interval == null) {
advancedVisible: false, healthCheckConfig.interval = {count: 60, unit: "second"}
urlProtocol: urlProtocol, }
urlPort: urlPort, if (healthCheckConfig.timeout == null) {
urlRequestURI: urlRequestURI healthCheckConfig.timeout = {count: 10, unit: "second"}
} }
}, if (healthCheckConfig.tryDelay == null) {
watch: { healthCheckConfig.tryDelay = {count: 100, unit: "ms"}
urlRequestURI: function () { }
if (this.urlRequestURI.length > 0 && this.urlRequestURI[0] != "/") { if (healthCheckConfig.countUp == null || healthCheckConfig.countUp < 1) {
this.urlRequestURI = "/" + this.urlRequestURI healthCheckConfig.countUp = 1
} }
this.changeURL() if (healthCheckConfig.countDown == null || healthCheckConfig.countDown < 1) {
}, healthCheckConfig.countDown = 1
urlPort: function (v) { }
let port = parseInt(v) }
if (!isNaN(port)) { return {
this.urlPort = port.toString() healthCheck: healthCheckConfig,
} else { advancedVisible: false,
this.urlPort = "" urlProtocol: urlProtocol,
} urlHost: urlHost,
this.changeURL() urlPort: urlPort,
}, urlRequestURI: urlRequestURI
urlProtocol: function () { }
this.changeURL() },
}, watch: {
"healthCheck.countTries": function (v) { urlRequestURI: function () {
let count = parseInt(v) if (this.urlRequestURI.length > 0 && this.urlRequestURI[0] != "/") {
if (!isNaN(count)) { this.urlRequestURI = "/" + this.urlRequestURI
this.healthCheck.countTries = count }
} else { this.changeURL()
this.healthCheck.countTries = 0 },
} urlPort: function (v) {
}, let port = parseInt(v)
"healthCheck.countUp": function (v) { if (!isNaN(port)) {
let count = parseInt(v) this.urlPort = port.toString()
if (!isNaN(count)) { } else {
this.healthCheck.countUp = count this.urlPort = ""
} else { }
this.healthCheck.countUp = 0 this.changeURL()
} },
}, urlProtocol: function () {
"healthCheck.countDown": function (v) { this.changeURL()
let count = parseInt(v) },
if (!isNaN(count)) { urlHost: function () {
this.healthCheck.countDown = count this.changeURL()
} else { },
this.healthCheck.countDown = 0 "healthCheck.countTries": function (v) {
} let count = parseInt(v)
} if (!isNaN(count)) {
}, this.healthCheck.countTries = count
methods: { } else {
showAdvanced: function () { this.healthCheck.countTries = 0
this.advancedVisible = !this.advancedVisible }
}, },
changeURL: function () { "healthCheck.countUp": function (v) {
this.healthCheck.url = this.urlProtocol + "://${host}" + ((this.urlPort.length > 0) ? ":" + this.urlPort : "") + this.urlRequestURI let count = parseInt(v)
}, if (!isNaN(count)) {
changeStatus: function (values) { this.healthCheck.countUp = count
this.healthCheck.statusCodes = values.$map(function (k, v) { } else {
let status = parseInt(v) this.healthCheck.countUp = 0
if (isNaN(status)) { }
return 0 },
} else { "healthCheck.countDown": function (v) {
return status let count = parseInt(v)
} if (!isNaN(count)) {
}) this.healthCheck.countDown = count
} } else {
}, this.healthCheck.countDown = 0
template: `<div> }
}
},
methods: {
showAdvanced: function () {
this.advancedVisible = !this.advancedVisible
},
changeURL: function () {
let urlHost = this.urlHost
if (urlHost.length == 0) {
urlHost = "${host}"
}
this.healthCheck.url = this.urlProtocol + "://" + urlHost + ((this.urlPort.length > 0) ? ":" + this.urlPort : "") + this.urlRequestURI
},
changeStatus: function (values) {
this.healthCheck.statusCodes = values.$map(function (k, v) {
let status = parseInt(v)
if (isNaN(status)) {
return 0
} else {
return status
}
})
}
},
template: `<div>
<input type="hidden" name="healthCheckJSON" :value="JSON.stringify(healthCheck)"/> <input type="hidden" name="healthCheckJSON" :value="JSON.stringify(healthCheck)"/>
<table class="ui table definition selectable"> <table class="ui table definition selectable">
<tbody> <tbody>
@@ -143,28 +162,40 @@ Vue.component("health-check-config-box", {
<tr> <tr>
<td>URL *</td> <td>URL *</td>
<td> <td>
<div class="ui fields inline"> <table class="ui table">
<div class="ui field"> <tr>
<select class="ui dropdown" v-model="urlProtocol"> <td class="title">协议</td>
<td>
<select class="ui dropdown auto-width" v-model="urlProtocol">
<option value="http">http://</option> <option value="http">http://</option>
<option value="https">https://</option> <option value="https">https://</option>
</select> </select>
</div> </td>
<div class="ui field"> </tr>
<var style="color:grey">\${host}</var> <tr>
</div> <td>域名</td>
<div class="ui field">:</div> <td>
<div class="ui field"> <input type="text" v-model="urlHost"/>
<input type="text" maxlength="5" style="width:5.4em" placeholder="端口" v-model="urlPort"/> </td>
</div> </tr>
<div class="ui field"> <tr>
<input type="text" v-model="urlRequestURI" placeholder="/" style="width:23em"/> <td>端口</td>
</div> <td>
</div> <input type="text" maxlength="5" style="width:5.4em" placeholder="端口" v-model="urlPort"/>
</td>
</tr>
<tr>
<td>RequestURI</td>
<td><input type="text" v-model="urlRequestURI" placeholder="/" style="width:20em"/></td>
</tr>
</table>
<div class="ui divider"></div> <div class="ui divider"></div>
<p class="comment" v-if="healthCheck.url.length > 0">拼接后的URL<code-label>{{healthCheck.url}}</code-label>,其中\${host}指的是节点地址。</p> <p class="comment" v-if="healthCheck.url.length > 0">拼接后的URL<code-label>{{healthCheck.url}}</code-label>,其中\${host}指的是域名。</p>
</td> </td>
</tr> </tr>
<tr>
<td></td>
</tr>
<tr> <tr>
<td>检测时间间隔</td> <td>检测时间间隔</td>
<td> <td>