-
Notifications
You must be signed in to change notification settings - Fork 474
/
namespaces.go
84 lines (67 loc) · 2.33 KB
/
namespaces.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package handlers
import (
"net/http"
"github.com/gorilla/mux"
"github.com/kiali/kiali/log"
"github.com/kiali/kiali/models"
"github.com/kiali/kiali/prometheus"
)
func NamespaceList(w http.ResponseWriter, r *http.Request) {
business, err := getBusiness(r)
if err != nil {
log.Error(err)
RespondWithError(w, http.StatusInternalServerError, err.Error())
return
}
namespaces, err := business.Namespace.GetNamespaces()
if err != nil {
log.Error(err)
RespondWithError(w, http.StatusInternalServerError, err.Error())
return
}
RespondWithJSON(w, http.StatusOK, namespaces)
}
// 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)
}
// getServiceMetrics (mock-friendly version)
func getNamespaceMetrics(w http.ResponseWriter, r *http.Request, promSupplier promClientSupplier) {
vars := mux.Vars(r)
namespace := vars["namespace"]
prom, namespaceInfo := initClientsForMetrics(w, r, promSupplier, namespace)
if prom == nil {
// any returned value nil means error & response already written
return
}
params := prometheus.IstioMetricsQuery{Namespace: namespace}
err := extractIstioMetricsQueryParams(r, ¶ms, namespaceInfo)
if err != nil {
RespondWithError(w, http.StatusBadRequest, err.Error())
return
}
metrics := prom.GetMetrics(¶ms)
RespondWithJSON(w, http.StatusOK, metrics)
}
// NamespaceValidationSummary is the API handler to fetch validations summary to be displayed.
// It is related to all the Istio Objects within the namespace
func NamespaceValidationSummary(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
namespace := vars["namespace"]
business, err := getBusiness(r)
if err != nil {
log.Error(err)
RespondWithError(w, http.StatusInternalServerError, err.Error())
return
}
var validationSummary models.IstioValidationSummary
istioConfigValidationResults, errValidations := business.Validations.GetValidations(namespace, "")
if errValidations != nil {
log.Error(errValidations)
RespondWithError(w, http.StatusInternalServerError, errValidations.Error())
} else {
validationSummary = istioConfigValidationResults.SummarizeValidation(namespace)
}
RespondWithJSON(w, http.StatusOK, validationSummary)
}