add service traces

This commit is contained in:
Jeff
2019-04-09 00:57:42 +08:00
committed by zryfish
parent 6dd03b3df6
commit 4fb5388176
4 changed files with 77 additions and 3 deletions

View File

@@ -10,7 +10,14 @@ type ServerRunOptions struct {
// istio pilot discovery service url
IstioPilotServiceURL string
OpenPitrixServer string
// jaeger query service url
JaegerQueryServiceUrl string
// openpitrix api gateway service url
OpenPitrixServer string
// openpitrix service token
OpenPitrixProxyToken string
}
@@ -19,6 +26,7 @@ func NewServerRunOptions() *ServerRunOptions {
s := ServerRunOptions{
GenericServerRunOptions: genericoptions.NewServerRunOptions(),
IstioPilotServiceURL: "http://istio-pilot.istio-system.svc:8080/version",
JaegerQueryServiceUrl: "http://jaeger-query.istio-system.svc:16686/jaeger",
}
return &s
@@ -29,4 +37,6 @@ func (s *ServerRunOptions) AddFlags(fs *pflag.FlagSet) {
s.GenericServerRunOptions.AddFlags(fs)
fs.StringVar(&s.IstioPilotServiceURL, "istio-pilot-service-url", "http://istio-pilot.istio-system.svc:8080/version", "istio pilot discovery service url")
fs.StringVar(&s.JaegerQueryServiceUrl, "jaeger-query-service-url", "http://jaeger-query.istio-system.svc:16686/jaeger", "jaeger query service url")
}

View File

@@ -27,6 +27,7 @@ import (
"github.com/spf13/pflag"
"kubesphere.io/kubesphere/cmd/ks-apiserver/app/options"
"kubesphere.io/kubesphere/pkg/apiserver/runtime"
"kubesphere.io/kubesphere/pkg/apiserver/servicemesh/tracing"
"kubesphere.io/kubesphere/pkg/filter"
"kubesphere.io/kubesphere/pkg/informers"
"kubesphere.io/kubesphere/pkg/models"
@@ -79,7 +80,7 @@ func Run(s *options.ServerRunOptions) error {
}
initializeESClientConfig()
initializeKialiConfig(s)
initializeServicemeshConfig(s)
err = initializeDatabase()
if err != nil {
@@ -109,10 +110,12 @@ func initializeDatabase() error {
return nil
}
func initializeKialiConfig(s *options.ServerRunOptions) {
func initializeServicemeshConfig(s *options.ServerRunOptions) {
// Initialize kiali config
config := kconfig.NewConfig()
tracing.JaegerQueryUrl = s.JaegerQueryServiceUrl
// Exclude system namespaces
config.API.Namespaces.Exclude = []string{"istio-system", "kubesphere*", "kube*"}
config.InCluster = true

View File

@@ -6,6 +6,7 @@ import (
"k8s.io/apimachinery/pkg/runtime/schema"
"kubesphere.io/kubesphere/pkg/apiserver/runtime"
"kubesphere.io/kubesphere/pkg/apiserver/servicemesh/metrics"
"kubesphere.io/kubesphere/pkg/apiserver/servicemesh/tracing"
"kubesphere.io/kubesphere/pkg/errors"
)
@@ -170,6 +171,23 @@ func addWebService(c *restful.Container) error {
Param(webservice.QueryParameter("queryTime", "the time to use for query")).
Writes(errors.Error{})).Produces(restful.MIME_JSON)
// Get service tracing
webservice.Route(webservice.GET("/namespaces/{namespace}/services/{service}/traces").
To(tracing.GetServiceTracing).
Doc("Get tracing of a service, should have servicemesh enabled first").
Metadata(restfulspec.KeyOpenAPITags, tags).
Param(webservice.PathParameter("namespace", "namespace of service").Required(true)).
Param(webservice.PathParameter("service", "name of service queried").Required(true)).
Param(webservice.QueryParameter("start", "start of time range want to query, in unix timestamp")).
Param(webservice.QueryParameter("end", "end of time range want to query, in unix timestamp")).
Param(webservice.QueryParameter("limit", "maximum tracing entries returned at one query, default 10").DefaultValue("10")).
Param(webservice.QueryParameter("loopback", "loopback of duration want to query, e.g. 30m/1h/2d")).
Param(webservice.QueryParameter("maxDuration", "maximum duration of tracing")).
Param(webservice.QueryParameter("minDuration", "minimum duration of tracing")).
Writes(errors.Error{}).
Consumes(restful.MIME_JSON).
Produces(restful.MIME_JSON))
c.Add(webservice)
return nil

View File

@@ -0,0 +1,43 @@
package tracing
import (
"fmt"
"github.com/emicklei/go-restful"
"io/ioutil"
"log"
"net/http"
)
var JaegerQueryUrl = "http://jaeger-query.istio-system.svc:16686/jaeger"
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)
resp, err := http.Get(url)
if err != nil {
log.Printf("query jaeger faile with err %v", err)
response.WriteError(http.StatusInternalServerError, err)
return
}
body, err := ioutil.ReadAll(resp.Body)
defer resp.Body.Close()
if err != nil {
log.Printf("read response error : %v", err)
response.WriteError(http.StatusInternalServerError, err)
return
}
_, err = response.Write(body)
if err != nil {
log.Printf("write response failed %v", err)
}
}