fix bench goroutine leak and add more stats

This commit is contained in:
Sasha Klizhentas 2017-05-14 12:47:04 -07:00
parent 7c50174566
commit cea133f27c
5 changed files with 30 additions and 2 deletions

View file

@ -66,8 +66,10 @@
## If not provided, will default to 5s. 0s means no timeout (not recommended).
timeout = "5s"
# Get all metrics from Kube-apiserver
[[inputs.procstat]]
exe = "teleport"
prefix = "teleport"
[[inputs.prometheus]]
# An array of urls to scrape metrics from.
urls = ["http://127.0.0.1:3434/metrics"]

View file

@ -829,6 +829,7 @@ func (tc *TeleportClient) runCommand(
log.Error(err)
return
}
defer nodeSession.Close()
if err = nodeSession.runCommand(command, tc.OnShellCreated, tc.Config.Interactive); err != nil {
originErr := trace.Unwrap(err)
exitErr, ok := originErr.(*ssh.ExitError)

View file

@ -17,6 +17,7 @@ limitations under the License.
package client
import (
"bytes"
"context"
"io/ioutil"
"time"
@ -55,6 +56,7 @@ type BenchmarkResult struct {
func (tc *TeleportClient) Benchmark(ctx context.Context, bench Benchmark) (*BenchmarkResult, error) {
tc.Stdout = ioutil.Discard
tc.Stderr = ioutil.Discard
tc.Stdin = &bytes.Buffer{}
ctx, cancel := context.WithTimeout(ctx, bench.Duration)
defer cancel()

View file

@ -471,3 +471,10 @@ func (ns *NodeSession) pipeInOut(shell io.ReadWriteCloser) {
}
}()
}
func (ns *NodeSession) Close() error {
if ns.closer != nil {
ns.closer.Close()
}
return nil
}

View file

@ -36,6 +36,7 @@ import (
"github.com/Sirupsen/logrus"
"github.com/buger/goterm"
gops "github.com/google/gops/agent"
)
// CLIConf stores command line arguments and flags:
@ -92,6 +93,11 @@ type CLIConf struct {
BenchRate int
// Context is a context to control execution
Context context.Context
// Gops starts gops agent on a specified address
// if not specified, gops won't start
Gops bool
// GopsAddr specifies to gops addr to listen on
GopsAddr string
}
// Run executes TSH client. same as main() but easier to test
@ -113,6 +119,8 @@ func Run(args []string, underTest bool) {
app.Flag("ttl", "Minutes to live for a SSH session").Int32Var(&cf.MinsToLive)
app.Flag("insecure", "Do not verify server's certificate and host name. Use only in test environments").Default("false").BoolVar(&cf.InsecureSkipVerify)
app.Flag("namespace", "Namespace of the cluster").Default(defaults.Namespace).StringVar(&cf.Namespace)
app.Flag("gops", "Start gops endpoint on a given address").Hidden().BoolVar(&cf.Gops)
app.Flag("gops-addr", "Specify gops addr to listen on").Hidden().StringVar(&cf.GopsAddr)
debugMode := app.Flag("debug", "Verbose logging to stdout").Short('d').Bool()
app.HelpFlag.Short('h')
ver := app.Command("version", "Print the version")
@ -187,6 +195,14 @@ func Run(args []string, underTest bool) {
}()
cf.Context = ctx
if cf.Gops {
logrus.Debugf("starting gops agent")
err = gops.Listen(&gops.Options{Addr: cf.GopsAddr})
if err != nil {
logrus.Warningf("failed to start gops agent %v", err)
}
}
switch command {
case ver.FullCommand():
onVersion()