support using Kiali API directly
Signed-off-by: zackzhangkai <zackzhang@yunify.com>
This commit is contained in:
@@ -106,6 +106,11 @@ func initializeServicemeshConfig(s *options.ServerRunOptions) {
|
||||
tracing.JaegerQueryUrl = s.ServiceMeshOptions.JaegerQueryHost
|
||||
}
|
||||
|
||||
// Set the kiali query endpoint address
|
||||
if s.ServiceMeshOptions != nil && len(s.ServiceMeshOptions.KialiQueryHost) != 0 {
|
||||
tracing.KialiQueryUrl = s.ServiceMeshOptions.KialiQueryHost
|
||||
}
|
||||
|
||||
// Exclude system namespaces
|
||||
config.API.Namespaces.Exclude = []string{"istio-system", "kube-.*"}
|
||||
config.InCluster = true
|
||||
|
||||
1
go.mod
1
go.mod
@@ -51,7 +51,6 @@ require (
|
||||
github.com/kubernetes-csi/external-snapshotter/v2 v2.1.0
|
||||
github.com/kubesphere/sonargo v0.0.2
|
||||
github.com/lib/pq v1.2.0 // indirect
|
||||
github.com/mitchellh/mapstructure v1.2.2
|
||||
github.com/onsi/ginkgo v1.12.0
|
||||
github.com/onsi/gomega v1.9.0
|
||||
github.com/open-policy-agent/opa v0.18.0
|
||||
|
||||
@@ -29,9 +29,31 @@ import (
|
||||
// default jaeger query api endpoint address
|
||||
var JaegerQueryUrl = "http://jaeger-query.istio-system.svc:16686"
|
||||
|
||||
/*
|
||||
Use Kiali API directly if config existed in configmap.
|
||||
Such as:
|
||||
kubectl -n kubesphere-system get cm kubesphere-config -oyaml
|
||||
...
|
||||
kialiQueryHost: http://kiali.istio-system:20001
|
||||
...
|
||||
|
||||
Otherwise, use the API provided by kiali code.
|
||||
|
||||
Announce: The API provided by kiali code will deprecated in the future.
|
||||
*/
|
||||
|
||||
var KialiQueryUrl string
|
||||
|
||||
// Get app metrics
|
||||
func getAppMetrics(request *restful.Request, response *restful.Response) {
|
||||
handlers.AppMetrics(request, response)
|
||||
if len(KialiQueryUrl) == 0 {
|
||||
handlers.AppMetrics(request, response)
|
||||
} else {
|
||||
namespace := request.PathParameter("namespace")
|
||||
app := request.PathParameter("app")
|
||||
url := fmt.Sprintf("%s/kiali/api/namespaces/%s/apps/%s/metrics?%s", KialiQueryUrl, namespace, app, request.Request.URL.RawQuery)
|
||||
getData(response, url)
|
||||
}
|
||||
}
|
||||
|
||||
// Get workload metrics
|
||||
@@ -43,17 +65,35 @@ func getWorkloadMetrics(request *restful.Request, response *restful.Response) {
|
||||
request.Request.URL.RawQuery = fmt.Sprintf("%s&namespaces=%s&workload=%s", request.Request.URL.RawQuery, namespace, workload)
|
||||
}
|
||||
|
||||
handlers.WorkloadMetrics(request, response)
|
||||
if len(KialiQueryUrl) == 0 {
|
||||
handlers.WorkloadMetrics(request, response)
|
||||
} else {
|
||||
url := fmt.Sprintf("%s/kiali/api/namespaces/%s/workloads/%s/metrics?%s", KialiQueryUrl, namespace, workload, request.Request.URL.RawQuery)
|
||||
getData(response, url)
|
||||
}
|
||||
}
|
||||
|
||||
// Get service metrics
|
||||
func getServiceMetrics(request *restful.Request, response *restful.Response) {
|
||||
handlers.ServiceMetrics(request, response)
|
||||
if len(KialiQueryUrl) == 0 {
|
||||
handlers.ServiceMetrics(request, response)
|
||||
} else {
|
||||
namespace := request.PathParameter("namespace")
|
||||
service := request.PathParameter("service")
|
||||
url := fmt.Sprintf("%s/kiali/api/namespaces/%s/services/%s/metrics?%s", KialiQueryUrl, namespace, service, request.Request.URL.RawQuery)
|
||||
getData(response, url)
|
||||
}
|
||||
}
|
||||
|
||||
// Get namespace metrics
|
||||
func getNamespaceMetrics(request *restful.Request, response *restful.Response) {
|
||||
handlers.NamespaceMetrics(request, response)
|
||||
if len(KialiQueryUrl) == 0 {
|
||||
handlers.NamespaceMetrics(request, response)
|
||||
} else {
|
||||
namespace := request.PathParameter("namespace")
|
||||
url := fmt.Sprintf("%s/kiali/api/namespaces/%s/metrics?%s", KialiQueryUrl, namespace, request.Request.URL.RawQuery)
|
||||
getData(response, url)
|
||||
}
|
||||
}
|
||||
|
||||
// Get service graph for namespace
|
||||
@@ -64,9 +104,15 @@ func getNamespaceGraph(request *restful.Request, response *restful.Response) {
|
||||
request.Request.URL.RawQuery = fmt.Sprintf("%s&namespaces=%s", request.Request.URL.RawQuery, namespace)
|
||||
}
|
||||
|
||||
handlers.GetNamespaceGraph(request, response)
|
||||
if len(KialiQueryUrl) == 0 {
|
||||
handlers.GetNamespaceGraph(request, response)
|
||||
} else {
|
||||
url := fmt.Sprintf("%s/kiali/api/namespaces/graph?%s", KialiQueryUrl, request.Request.URL.RawQuery)
|
||||
getData(response, url)
|
||||
}
|
||||
}
|
||||
|
||||
// Deprecated
|
||||
// Get service graph for namespaces
|
||||
func getNamespacesGraph(request *restful.Request, response *restful.Response) {
|
||||
handlers.GraphNamespaces(request, response)
|
||||
@@ -74,37 +120,65 @@ func getNamespacesGraph(request *restful.Request, response *restful.Response) {
|
||||
|
||||
// Get namespace health
|
||||
func getNamespaceHealth(request *restful.Request, response *restful.Response) {
|
||||
handlers.NamespaceHealth(request, response)
|
||||
if len(KialiQueryUrl) == 0 {
|
||||
handlers.NamespaceHealth(request, response)
|
||||
} else {
|
||||
namespace := request.PathParameter("namespace")
|
||||
url := fmt.Sprintf("%s/kiali/api/namespaces/%s/health?%s", KialiQueryUrl, namespace, request.Request.URL.RawQuery)
|
||||
getData(response, url)
|
||||
}
|
||||
}
|
||||
|
||||
// Get workload health
|
||||
func getWorkloadHealth(request *restful.Request, response *restful.Response) {
|
||||
handlers.WorkloadHealth(request, response)
|
||||
if len(KialiQueryUrl) == 0 {
|
||||
handlers.WorkloadHealth(request, response)
|
||||
} else {
|
||||
namespace := request.PathParameter("namespace")
|
||||
workload := request.PathParameter("workload")
|
||||
url := fmt.Sprintf("%s/kiali/api/namespaces/%s/workloads/%s/health?%s", KialiQueryUrl, namespace, workload, request.Request.URL.RawQuery)
|
||||
getData(response, url)
|
||||
}
|
||||
}
|
||||
|
||||
// Get app health
|
||||
func getAppHealth(request *restful.Request, response *restful.Response) {
|
||||
handlers.AppHealth(request, response)
|
||||
if len(KialiQueryUrl) == 0 {
|
||||
handlers.AppHealth(request, response)
|
||||
} else {
|
||||
namespace := request.PathParameter("namespace")
|
||||
app := request.PathParameter("app")
|
||||
url := fmt.Sprintf("%s/kiali/api/namespaces/%s/apps/%s/health?%s", KialiQueryUrl, namespace, app, request.Request.URL.RawQuery)
|
||||
getData(response, url)
|
||||
}
|
||||
}
|
||||
|
||||
// Get service health
|
||||
func getServiceHealth(request *restful.Request, response *restful.Response) {
|
||||
handlers.ServiceHealth(request, response)
|
||||
if len(KialiQueryUrl) == 0 {
|
||||
handlers.ServiceHealth(request, response)
|
||||
} else {
|
||||
namespace := request.PathParameter("namespace")
|
||||
service := request.PathParameter("service")
|
||||
url := fmt.Sprintf("%s/kiali/api/namespaces/%s/services/%s/health?%s", KialiQueryUrl, namespace, service, request.Request.URL.RawQuery)
|
||||
getData(response, url)
|
||||
}
|
||||
}
|
||||
|
||||
func getServiceTracing(request *restful.Request, response *restful.Response) {
|
||||
namespace := request.PathParameter("namespace")
|
||||
service := request.PathParameter("service")
|
||||
|
||||
serviceName := fmt.Sprintf("%s.%s", service, namespace)
|
||||
|
||||
url := fmt.Sprintf("%s/api/traces?%s&service=%s", JaegerQueryUrl, request.Request.URL.RawQuery, serviceName)
|
||||
getData(response, url)
|
||||
}
|
||||
|
||||
func getData(response *restful.Response, url string) {
|
||||
resp, err := http.Get(url)
|
||||
klog.V(4).Infof("Proxy trace request to %s", url)
|
||||
klog.V(4).Infof("Proxy request to %s", url)
|
||||
|
||||
if err != nil {
|
||||
klog.Errorf("query jaeger failed with err %v", err)
|
||||
klog.Errorf("query url %s failed with err %v", url, err)
|
||||
api.HandleInternalError(response, nil, err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -26,6 +26,9 @@ type Options struct {
|
||||
// jaeger query service url
|
||||
JaegerQueryHost string `json:"jaegerQueryHost,omitempty" yaml:"jaegerQueryHost"`
|
||||
|
||||
// kiali query service url
|
||||
KialiQueryHost string `json:"kialiQueryHost,omitempty" yaml:"kialiQueryHost"`
|
||||
|
||||
// prometheus service url for servicemesh metrics
|
||||
ServicemeshPrometheusHost string `json:"servicemeshPrometheusHost,omitempty" yaml:"servicemeshPrometheusHost"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user