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

@@ -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)
}
}