Skip to content

Commit

Permalink
Refactor minor issues
Browse files Browse the repository at this point in the history
  • Loading branch information
emadolsky committed Aug 8, 2022
1 parent 5887d8c commit 28f0b52
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
13 changes: 9 additions & 4 deletions carbonserver/carbonserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ func (q *QueryItem) FetchOrLock() (interface{}, bool) {
return nil, false
}

select { //nolint:gosimple
select { //nolint:gosimple //skipcq: SCC-S1000
// TODO: Add timeout support
case <-q.QueryFinished:
break
Expand Down Expand Up @@ -228,6 +228,7 @@ type CarbonserverListener struct {
failOnMaxGlobs bool
percentiles []int
scanFrequency time.Duration
scanTicker *time.Ticker
forceScanChan chan struct{}
metricsAsCounters bool
tcpListener *net.TCPListener
Expand Down Expand Up @@ -446,7 +447,7 @@ type jsonMetricDetailsResponse struct {
}

type fileIndex struct {
typ int //nolint:unused,structcheck
typ int //nolint:unused,structcheck //skipcq: SCC-U1000

idx trigram.Index
files []string
Expand Down Expand Up @@ -1263,7 +1264,7 @@ func (listener *CarbonserverListener) expandGlobs(ctx context.Context, query str
logger := TraceContextToZap(ctx, listener.logger)
matchedCount := 0
defer func(start time.Time) {
dur := time.Now().Sub(start) //nolint:gosimple
dur := time.Since(start)
if dur <= time.Second {
return
}
Expand Down Expand Up @@ -1560,6 +1561,9 @@ func (listener *CarbonserverListener) Stat(send helper.StatCallback) {

func (listener *CarbonserverListener) Stop() error {
close(listener.forceScanChan)
if listener.scanTicker != nil {
listener.scanTicker.Stop()
}
close(listener.exitChan)
if listener.db != nil {
listener.db.Close()
Expand Down Expand Up @@ -1745,7 +1749,8 @@ func (listener *CarbonserverListener) Listen(listen string) error {
listener.exitChan = make(chan struct{})
if (listener.trigramIndex || listener.trieIndex) && listener.scanFrequency != 0 {
listener.forceScanChan = make(chan struct{})
go listener.fileListUpdater(listener.whisperData, time.Tick(listener.scanFrequency), listener.forceScanChan, listener.exitChan) //nolint:staticcheck
listener.scanTicker = time.NewTicker(listener.scanFrequency)
go listener.fileListUpdater(listener.whisperData, listener.scanTicker.C, listener.forceScanChan, listener.exitChan) //nolint:staticcheck
listener.forceScanChan <- struct{}{}
}

Expand Down
16 changes: 8 additions & 8 deletions helper/grpcutil/grpcutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,24 +49,24 @@ func StreamServerTimeHandler(cb func(payload, peer string, t time.Duration)) grp
}
}

func GetWrappedStream(ss grpc.ServerStream) *wrappedStream {
if wss, ok := ss.(*wrappedStream); ok {
func GetWrappedStream(ss grpc.ServerStream) *WrappedStream {
if wss, ok := ss.(*WrappedStream); ok {
return wss
}
return &wrappedStream{
return &WrappedStream{
ServerStream: ss,
ctx: ss.Context(),
}
}

type wrappedStream struct {
type WrappedStream struct {
grpc.ServerStream
ctx context.Context
payload string
gotFirst bool
}

func (ws *wrappedStream) RecvMsg(m interface{}) error {
func (ws *WrappedStream) RecvMsg(m interface{}) error {
err := ws.ServerStream.RecvMsg(m)
if err != nil {
return err
Expand All @@ -81,15 +81,15 @@ func (ws *wrappedStream) RecvMsg(m interface{}) error {
return nil
}

func (ws *wrappedStream) Context() context.Context {
func (ws *WrappedStream) Context() context.Context {
return ws.ctx
}

func (ws *wrappedStream) SetContext(ctx context.Context) {
func (ws *WrappedStream) SetContext(ctx context.Context) {
ws.ctx = ctx
}

func (ws *wrappedStream) Payload() string {
func (ws *WrappedStream) Payload() string {
return ws.payload
}

Expand Down

0 comments on commit 28f0b52

Please sign in to comment.