-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into ui/replication-status-discoverability
- Loading branch information
Showing
574 changed files
with
21,847 additions
and
14,119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package api | ||
|
||
import ( | ||
"bufio" | ||
"context" | ||
"fmt" | ||
) | ||
|
||
// Monitor returns a channel that outputs strings containing the log messages | ||
// coming from the server. | ||
func (c *Sys) Monitor(ctx context.Context, logLevel string) (chan string, error) { | ||
r := c.c.NewRequest("GET", "/v1/sys/monitor") | ||
|
||
if logLevel == "" { | ||
r.Params.Add("log_level", "info") | ||
} else { | ||
r.Params.Add("log_level", logLevel) | ||
} | ||
|
||
resp, err := c.c.RawRequestWithContext(ctx, r) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
logCh := make(chan string, 64) | ||
|
||
go func() { | ||
scanner := bufio.NewScanner(resp.Body) | ||
droppedCount := 0 | ||
|
||
defer close(logCh) | ||
defer resp.Body.Close() | ||
|
||
for { | ||
if ctx.Err() != nil { | ||
return | ||
} | ||
|
||
if !scanner.Scan() { | ||
return | ||
} | ||
|
||
logMessage := scanner.Text() | ||
|
||
if droppedCount > 0 { | ||
select { | ||
case logCh <- fmt.Sprintf("Monitor dropped %d logs during monitor request\n", droppedCount): | ||
droppedCount = 0 | ||
default: | ||
droppedCount++ | ||
continue | ||
} | ||
} | ||
|
||
select { | ||
case logCh <- logMessage: | ||
default: | ||
droppedCount++ | ||
} | ||
} | ||
}() | ||
|
||
return logCh, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.