add controllers
change kiali mux to go-restful add knative
This commit is contained in:
29
vendor/github.com/kiali/kiali/graph/options/options.go
generated
vendored
29
vendor/github.com/kiali/kiali/graph/options/options.go
generated
vendored
@@ -3,14 +3,12 @@ package options
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"github.com/emicklei/go-restful"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
|
||||
"github.com/kiali/kiali/business"
|
||||
"github.com/kiali/kiali/graph"
|
||||
"github.com/kiali/kiali/graph/appender"
|
||||
@@ -64,17 +62,26 @@ type Options struct {
|
||||
VendorOptions
|
||||
}
|
||||
|
||||
func NewOptions(r *http.Request) Options {
|
||||
func getParameters(key string, request *restful.Request) string {
|
||||
value, ok := request.PathParameters()[key]
|
||||
|
||||
if !ok {
|
||||
return request.QueryParameter(key)
|
||||
}
|
||||
|
||||
return value
|
||||
}
|
||||
|
||||
func NewOptions(request *restful.Request) Options {
|
||||
// path variables (0 or more will be set)
|
||||
vars := mux.Vars(r)
|
||||
app := vars["app"]
|
||||
namespace := vars["namespace"]
|
||||
service := vars["service"]
|
||||
version := vars["version"]
|
||||
workload := vars["workload"]
|
||||
app := getParameters("app", request)
|
||||
namespace := getParameters("namespace", request)
|
||||
service := getParameters("service", request)
|
||||
version := getParameters("version", request)
|
||||
workload := getParameters("workload", request)
|
||||
|
||||
// query params
|
||||
params := r.URL.Query()
|
||||
params := request.Request.URL.Query()
|
||||
var duration time.Duration
|
||||
var includeIstio bool
|
||||
var injectServiceNodes bool
|
||||
|
||||
20
vendor/github.com/kiali/kiali/handlers/apps.go
generated
vendored
20
vendor/github.com/kiali/kiali/handlers/apps.go
generated
vendored
@@ -1,6 +1,7 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"github.com/emicklei/go-restful"
|
||||
"net/http"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
@@ -61,31 +62,30 @@ func AppDetails(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
// AppMetrics is the API handler to fetch metrics to be displayed, related to an app-label grouping
|
||||
func AppMetrics(w http.ResponseWriter, r *http.Request) {
|
||||
getAppMetrics(w, r, defaultPromClientSupplier, defaultK8SClientSupplier)
|
||||
func AppMetrics(request *restful.Request, response *restful.Response) {
|
||||
getAppMetrics(request, response, defaultPromClientSupplier, defaultK8SClientSupplier)
|
||||
}
|
||||
|
||||
// getAppMetrics (mock-friendly version)
|
||||
func getAppMetrics(w http.ResponseWriter, r *http.Request, promSupplier promClientSupplier, k8sSupplier k8sClientSupplier) {
|
||||
vars := mux.Vars(r)
|
||||
namespace := vars["namespace"]
|
||||
app := vars["app"]
|
||||
func getAppMetrics(request *restful.Request, response *restful.Response, promSupplier promClientSupplier, k8sSupplier k8sClientSupplier) {
|
||||
namespace := request.PathParameters()["namespace"]
|
||||
app := request.PathParameters()["app"]
|
||||
|
||||
prom, _, namespaceInfo := initClientsForMetrics(w, promSupplier, k8sSupplier, namespace)
|
||||
prom, _, namespaceInfo := initClientsForMetrics(response.ResponseWriter, promSupplier, k8sSupplier, namespace)
|
||||
if prom == nil {
|
||||
// any returned value nil means error & response already written
|
||||
return
|
||||
}
|
||||
|
||||
params := prometheus.IstioMetricsQuery{Namespace: namespace, App: app}
|
||||
err := extractIstioMetricsQueryParams(r, ¶ms, namespaceInfo)
|
||||
err := extractIstioMetricsQueryParams(request.Request, ¶ms, namespaceInfo)
|
||||
if err != nil {
|
||||
RespondWithError(w, http.StatusBadRequest, err.Error())
|
||||
RespondWithError(response.ResponseWriter, http.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
metrics := prom.GetMetrics(¶ms)
|
||||
RespondWithJSON(w, http.StatusOK, metrics)
|
||||
RespondWithJSON(response.ResponseWriter, http.StatusOK, metrics)
|
||||
}
|
||||
|
||||
// CustomDashboard is the API handler to fetch runtime metrics to be displayed, related to a single app
|
||||
|
||||
36
vendor/github.com/kiali/kiali/handlers/graph.go
generated
vendored
36
vendor/github.com/kiali/kiali/handlers/graph.go
generated
vendored
@@ -34,6 +34,7 @@ package handlers
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/emicklei/go-restful"
|
||||
"net/http"
|
||||
"runtime/debug"
|
||||
"time"
|
||||
@@ -51,26 +52,35 @@ import (
|
||||
"github.com/kiali/kiali/prometheus/internalmetrics"
|
||||
)
|
||||
|
||||
// GraphNamespaces is a REST http.HandlerFunc handling graph generation for 1 or more namespaces
|
||||
func GraphNamespaces(w http.ResponseWriter, r *http.Request) {
|
||||
defer handlePanic(w)
|
||||
func GetNamespaceGraph(request * restful.Request, response *restful.Response) {
|
||||
defer handlePanic(response.ResponseWriter)
|
||||
|
||||
client, err := prometheus.NewClient()
|
||||
graph.CheckError(err)
|
||||
|
||||
graphNamespaces(w, r, client)
|
||||
graphNamespaces(request, response, client)
|
||||
}
|
||||
|
||||
// GraphNamespaces is a REST http.HandlerFunc handling graph generation for 1 or more namespaces
|
||||
func GraphNamespaces(request *restful.Request, response *restful.Response) {
|
||||
defer handlePanic(response.ResponseWriter)
|
||||
|
||||
client, err := prometheus.NewClient()
|
||||
graph.CheckError(err)
|
||||
|
||||
graphNamespaces(request, response, client)
|
||||
}
|
||||
|
||||
// graphNamespaces provides a testing hook that can supply a mock client
|
||||
func graphNamespaces(w http.ResponseWriter, r *http.Request, client *prometheus.Client) {
|
||||
o := options.NewOptions(r)
|
||||
func graphNamespaces(reqeust *restful.Request, response *restful.Response, client *prometheus.Client) {
|
||||
o := options.NewOptions(reqeust)
|
||||
|
||||
// time how long it takes to generate this graph
|
||||
promtimer := internalmetrics.GetGraphGenerationTimePrometheusTimer(o.GetGraphKind(), o.GraphType, o.InjectServiceNodes)
|
||||
defer promtimer.ObserveDuration()
|
||||
|
||||
trafficMap := buildNamespacesTrafficMap(o, client)
|
||||
generateGraph(trafficMap, w, o)
|
||||
generateGraph(trafficMap, response.ResponseWriter, o)
|
||||
|
||||
// update metrics
|
||||
internalmetrics.SetGraphNodes(o.GetGraphKind(), o.GraphType, o.InjectServiceNodes, len(trafficMap))
|
||||
@@ -613,18 +623,18 @@ func addNode(trafficMap graph.TrafficMap, namespace, workload, app, version, ser
|
||||
|
||||
// GraphNode is a REST http.HandlerFunc handling node-detail graph
|
||||
// config generation.
|
||||
func GraphNode(w http.ResponseWriter, r *http.Request) {
|
||||
defer handlePanic(w)
|
||||
func GraphNode(request *restful.Request, response *restful.Response) {
|
||||
defer handlePanic(response.ResponseWriter)
|
||||
|
||||
client, err := prometheus.NewClient()
|
||||
graph.CheckError(err)
|
||||
|
||||
graphNode(w, r, client)
|
||||
graphNode(request, response, client)
|
||||
}
|
||||
|
||||
// graphNode provides a testing hook that can supply a mock client
|
||||
func graphNode(w http.ResponseWriter, r *http.Request, client *prometheus.Client) {
|
||||
o := options.NewOptions(r)
|
||||
func graphNode(request *restful.Request, response *restful.Response, client *prometheus.Client) {
|
||||
o := options.NewOptions(request)
|
||||
switch o.Vendor {
|
||||
case "cytoscape":
|
||||
default:
|
||||
@@ -664,7 +674,7 @@ func graphNode(w http.ResponseWriter, r *http.Request, client *prometheus.Client
|
||||
// the current decision is to not reduce the node graph to provide more detail. This may be
|
||||
// confusing to users, we'll see...
|
||||
|
||||
generateGraph(trafficMap, w, o)
|
||||
generateGraph(trafficMap, response.ResponseWriter, o)
|
||||
|
||||
// update metrics
|
||||
internalmetrics.SetGraphNodes(o.GetGraphKind(), o.GraphType, o.InjectServiceNodes, len(trafficMap))
|
||||
|
||||
20
vendor/github.com/kiali/kiali/handlers/namespaces.go
generated
vendored
20
vendor/github.com/kiali/kiali/handlers/namespaces.go
generated
vendored
@@ -1,10 +1,9 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"github.com/emicklei/go-restful"
|
||||
"net/http"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
|
||||
"github.com/kiali/kiali/business"
|
||||
"github.com/kiali/kiali/log"
|
||||
"github.com/kiali/kiali/prometheus"
|
||||
@@ -31,28 +30,27 @@ func NamespaceList(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
// NamespaceMetrics is the API handler to fetch metrics to be displayed, related to all
|
||||
// services in the namespace
|
||||
func NamespaceMetrics(w http.ResponseWriter, r *http.Request) {
|
||||
getNamespaceMetrics(w, r, defaultPromClientSupplier, defaultK8SClientSupplier)
|
||||
func NamespaceMetrics(request *restful.Request, response *restful.Response) {
|
||||
getNamespaceMetrics(request, response, defaultPromClientSupplier, defaultK8SClientSupplier)
|
||||
}
|
||||
|
||||
// getServiceMetrics (mock-friendly version)
|
||||
func getNamespaceMetrics(w http.ResponseWriter, r *http.Request, promSupplier promClientSupplier, k8sSupplier k8sClientSupplier) {
|
||||
vars := mux.Vars(r)
|
||||
namespace := vars["namespace"]
|
||||
func getNamespaceMetrics(request *restful.Request, response *restful.Response, promSupplier promClientSupplier, k8sSupplier k8sClientSupplier) {
|
||||
namespace := request.PathParameters()["namespace"]
|
||||
|
||||
prom, _, namespaceInfo := initClientsForMetrics(w, promSupplier, k8sSupplier, namespace)
|
||||
prom, _, namespaceInfo := initClientsForMetrics(response.ResponseWriter, promSupplier, k8sSupplier, namespace)
|
||||
if prom == nil {
|
||||
// any returned value nil means error & response already written
|
||||
return
|
||||
}
|
||||
|
||||
params := prometheus.IstioMetricsQuery{Namespace: namespace}
|
||||
err := extractIstioMetricsQueryParams(r, ¶ms, namespaceInfo)
|
||||
err := extractIstioMetricsQueryParams(request.Request, ¶ms, namespaceInfo)
|
||||
if err != nil {
|
||||
RespondWithError(w, http.StatusBadRequest, err.Error())
|
||||
RespondWithError(response.ResponseWriter, http.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
metrics := prom.GetMetrics(¶ms)
|
||||
RespondWithJSON(w, http.StatusOK, metrics)
|
||||
RespondWithJSON(response.ResponseWriter, http.StatusOK, metrics)
|
||||
}
|
||||
|
||||
20
vendor/github.com/kiali/kiali/handlers/services.go
generated
vendored
20
vendor/github.com/kiali/kiali/handlers/services.go
generated
vendored
@@ -1,6 +1,7 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"github.com/emicklei/go-restful"
|
||||
"net/http"
|
||||
"sync"
|
||||
|
||||
@@ -36,31 +37,30 @@ func ServiceList(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
// ServiceMetrics is the API handler to fetch metrics to be displayed, related to a single service
|
||||
func ServiceMetrics(w http.ResponseWriter, r *http.Request) {
|
||||
getServiceMetrics(w, r, defaultPromClientSupplier, defaultK8SClientSupplier)
|
||||
func ServiceMetrics(request *restful.Request, response *restful.Response) {
|
||||
getServiceMetrics(request, response, defaultPromClientSupplier, defaultK8SClientSupplier)
|
||||
}
|
||||
|
||||
// getServiceMetrics (mock-friendly version)
|
||||
func getServiceMetrics(w http.ResponseWriter, r *http.Request, promSupplier promClientSupplier, k8sSupplier k8sClientSupplier) {
|
||||
vars := mux.Vars(r)
|
||||
namespace := vars["namespace"]
|
||||
service := vars["service"]
|
||||
func getServiceMetrics(request *restful.Request, response *restful.Response, promSupplier promClientSupplier, k8sSupplier k8sClientSupplier) {
|
||||
namespace := request.PathParameters()["namespace"]
|
||||
service := request.PathParameters()["service"]
|
||||
|
||||
prom, _, namespaceInfo := initClientsForMetrics(w, promSupplier, k8sSupplier, namespace)
|
||||
prom, _, namespaceInfo := initClientsForMetrics(response.ResponseWriter, promSupplier, k8sSupplier, namespace)
|
||||
if prom == nil {
|
||||
// any returned value nil means error & response already written
|
||||
return
|
||||
}
|
||||
|
||||
params := prometheus.IstioMetricsQuery{Namespace: namespace, Service: service}
|
||||
err := extractIstioMetricsQueryParams(r, ¶ms, namespaceInfo)
|
||||
err := extractIstioMetricsQueryParams(request.Request, ¶ms, namespaceInfo)
|
||||
if err != nil {
|
||||
RespondWithError(w, http.StatusBadRequest, err.Error())
|
||||
RespondWithError(response.ResponseWriter, http.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
metrics := prom.GetMetrics(¶ms)
|
||||
RespondWithJSON(w, http.StatusOK, metrics)
|
||||
RespondWithJSON(response.ResponseWriter, http.StatusOK, metrics)
|
||||
}
|
||||
|
||||
// ServiceDetails is the API handler to fetch full details of an specific service
|
||||
|
||||
20
vendor/github.com/kiali/kiali/handlers/workloads.go
generated
vendored
20
vendor/github.com/kiali/kiali/handlers/workloads.go
generated
vendored
@@ -1,6 +1,7 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"github.com/emicklei/go-restful"
|
||||
"net/http"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
@@ -60,31 +61,30 @@ func WorkloadDetails(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
// WorkloadMetrics is the API handler to fetch metrics to be displayed, related to a single workload
|
||||
func WorkloadMetrics(w http.ResponseWriter, r *http.Request) {
|
||||
getWorkloadMetrics(w, r, defaultPromClientSupplier, defaultK8SClientSupplier)
|
||||
func WorkloadMetrics(request *restful.Request, response *restful.Response) {
|
||||
getWorkloadMetrics(request, response, defaultPromClientSupplier, defaultK8SClientSupplier)
|
||||
}
|
||||
|
||||
// getWorkloadMetrics (mock-friendly version)
|
||||
func getWorkloadMetrics(w http.ResponseWriter, r *http.Request, promSupplier promClientSupplier, k8sSupplier k8sClientSupplier) {
|
||||
vars := mux.Vars(r)
|
||||
namespace := vars["namespace"]
|
||||
workload := vars["workload"]
|
||||
func getWorkloadMetrics(request *restful.Request, response *restful.Response, promSupplier promClientSupplier, k8sSupplier k8sClientSupplier) {
|
||||
namespace := request.PathParameter("namespace")
|
||||
workload := request.PathParameter("workload")
|
||||
|
||||
prom, _, namespaceInfo := initClientsForMetrics(w, promSupplier, k8sSupplier, namespace)
|
||||
prom, _, namespaceInfo := initClientsForMetrics(response.ResponseWriter, promSupplier, k8sSupplier, namespace)
|
||||
if prom == nil {
|
||||
// any returned value nil means error & response already written
|
||||
return
|
||||
}
|
||||
|
||||
params := prometheus.IstioMetricsQuery{Namespace: namespace, Workload: workload}
|
||||
err := extractIstioMetricsQueryParams(r, ¶ms, namespaceInfo)
|
||||
err := extractIstioMetricsQueryParams(request.Request, ¶ms, namespaceInfo)
|
||||
if err != nil {
|
||||
RespondWithError(w, http.StatusBadRequest, err.Error())
|
||||
RespondWithError(response.ResponseWriter, http.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
metrics := prom.GetMetrics(¶ms)
|
||||
RespondWithJSON(w, http.StatusOK, metrics)
|
||||
RespondWithJSON(response, http.StatusOK, metrics)
|
||||
}
|
||||
|
||||
// WorkloadDashboard is the API handler to fetch Istio dashboard, related to a single workload
|
||||
|
||||
Reference in New Issue
Block a user