Skip to content

Commit

Permalink
Fix control visor apps from hv (#1399)
Browse files Browse the repository at this point in the history
* Fix MarshalJSON of LogEntry

* Fix datarace in GobEncode of LogEntry

* Add  App to RPC
  • Loading branch information
ersonp authored Oct 25, 2022
1 parent f90cefa commit 863cbbe
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
17 changes: 9 additions & 8 deletions pkg/transport/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"fmt"
"os"
"path/filepath"
"strconv"
"strings"
"sync"
"sync/atomic"
Expand Down Expand Up @@ -81,28 +80,30 @@ func (le *LogEntry) Reset() {

// MarshalJSON implements json.Marshaller
func (le *LogEntry) MarshalJSON() ([]byte, error) {
var rb string
var sb string
var rb uint64
var sb uint64
if le.RecvBytes != nil {
rb = strconv.FormatUint(atomic.LoadUint64(le.RecvBytes), 10)
rb = atomic.LoadUint64(le.RecvBytes)
}
if le.SentBytes != nil {
sb = strconv.FormatUint(atomic.LoadUint64(le.SentBytes), 10)
sb = atomic.LoadUint64(le.SentBytes)
}
return []byte(`{"recv":` + rb + `,"sent":` + sb + `}`), nil
return []byte(`{"recv":` + fmt.Sprint(rb) + `,"sent":` + fmt.Sprint(sb) + `}`), nil
}

// GobEncode implements gob.GobEncoder
func (le *LogEntry) GobEncode() ([]byte, error) {
var b bytes.Buffer
enc := gob.NewEncoder(&b)
if le.RecvBytes != nil {
if err := enc.Encode(le.RecvBytes); err != nil {
rb := atomic.LoadUint64(le.RecvBytes)
if err := enc.Encode(rb); err != nil {
return nil, err
}
}
if le.SentBytes != nil {
if err := enc.Encode(le.SentBytes); err != nil {
sb := atomic.LoadUint64(le.SentBytes)
if err := enc.Encode(sb); err != nil {
return nil, err
}
}
Expand Down
10 changes: 10 additions & 0 deletions pkg/visor/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,16 @@ func (r *RPC) SetAppError(in *SetAppErrorIn, _ *struct{}) (err error) {
return r.visor.SetAppError(in.AppName, in.Err)
}

// App returns App registered on the Visor.
func (r *RPC) App(appName *string, reply *appserver.AppState) (err error) {
defer rpcutil.LogCall(r.log, "App", nil)(reply, &err)

app, err := r.visor.App(*appName)
*reply = *app

return err
}

// Apps returns list of Apps registered on the Visor.
func (r *RPC) Apps(_ *struct{}, reply *[]*appserver.AppState) (err error) {
defer rpcutil.LogCall(r.log, "Apps", nil)(reply, &err)
Expand Down

0 comments on commit 863cbbe

Please sign in to comment.