Merge pull request #1007 from micro/ultra-hacks

ultra hacks to make debug handler work in proxy
This commit is contained in:
Asim Aslam 2019-12-02 15:11:56 +00:00 committed by GitHub
commit 62bf0df864
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 13 deletions

View File

@ -7,8 +7,8 @@ import (
"time" "time"
"github.com/micro/go-micro/debug/log" "github.com/micro/go-micro/debug/log"
proto "github.com/micro/go-micro/debug/proto" proto "github.com/micro/go-micro/debug/proto"
"github.com/micro/go-micro/server"
) )
var ( var (
@ -46,7 +46,12 @@ func (d *Debug) Stats(ctx context.Context, req *proto.StatsRequest, rsp *proto.S
return nil return nil
} }
func (d *Debug) Logs(ctx context.Context, req *proto.LogRequest, stream proto.Debug_LogsStream) error { func (d *Debug) Logs(ctx context.Context, stream server.Stream) error {
req := new(proto.LogRequest)
if err := stream.Recv(req); err != nil {
return err
}
var options []log.ReadOption var options []log.ReadOption
since := time.Unix(req.Since, 0) since := time.Unix(req.Since, 0)
@ -90,7 +95,7 @@ func (d *Debug) Logs(ctx context.Context, req *proto.LogRequest, stream proto.De
return nil return nil
} }
func (d *Debug) sendRecord(record log.Record, stream proto.Debug_LogsStream) error { func (d *Debug) sendRecord(record log.Record, stream server.Stream) error {
metadata := make(map[string]string) metadata := make(map[string]string)
for k, v := range record.Metadata { for k, v := range record.Metadata {
metadata[k] = v metadata[k] = v

View File

@ -16,8 +16,6 @@ import (
"github.com/micro/go-micro/server" "github.com/micro/go-micro/server"
"github.com/micro/go-micro/util/log" "github.com/micro/go-micro/util/log"
"github.com/micro/go-micro/util/wrapper" "github.com/micro/go-micro/util/wrapper"
pb "github.com/micro/go-micro/debug/proto"
) )
type service struct { type service struct {
@ -143,9 +141,12 @@ func (s *service) Stop() error {
func (s *service) Run() error { func (s *service) Run() error {
// register the debug handler // register the debug handler
pb.RegisterDebugHandler(s.opts.Server, s.opts.Server.Handle(
handler.DefaultHandler, s.opts.Server.NewHandler(
server.InternalHandler(true)) handler.DefaultHandler,
server.InternalHandler(true),
),
)
// start the profiler // start the profiler
// TODO: set as an option to the service, don't just use pprof // TODO: set as an option to the service, don't just use pprof

View File

@ -5,7 +5,6 @@ import (
"context" "context"
"sync" "sync"
proto "github.com/micro/go-micro/debug/proto"
"github.com/micro/go-micro/debug/handler" "github.com/micro/go-micro/debug/handler"
"github.com/micro/go-micro/proxy" "github.com/micro/go-micro/proxy"
"github.com/micro/go-micro/server" "github.com/micro/go-micro/server"
@ -40,10 +39,11 @@ func (s *Server) ServeRequest(ctx context.Context, req server.Request, rsp serve
func New(name string, p proxy.Proxy) *Server { func New(name string, p proxy.Proxy) *Server {
// only register this once // only register this once
once.Do(func() { once.Do(func() {
proto.RegisterDebugHandler( server.DefaultRouter.Handle(
server.DefaultServer, server.DefaultRouter.NewHandler(
handler.DefaultHandler, handler.DefaultHandler,
server.InternalHandler(true), server.InternalHandler(true),
),
) )
}) })