Skip to content

Commit

Permalink
Merge branch 'master' into packagize
Browse files Browse the repository at this point in the history
  • Loading branch information
Songmu committed Mar 11, 2017
2 parents 54579be + fe14b9b commit f1f07a5
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 28 deletions.
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ env:
global:
- PATH=~/gopath/bin:$PATH
- DEBIAN_FRONTEND=noninteractive
- secure: "A7F4DYfPLjDwh/B0CWAX2y9cChZtGENRF9dJy5l35gK6pc0a4oVzm2GuzZFYubp1ByWIW+No+iXnw2CGYCS2jMdYMeNLjrfN4orEENVrsXIaq+itF7+Ub/O3WaM9ukpfeXZKzFS/EyxvyRYMPmpc2pwqA1HGQ5qTDVzlFE+zCnD4rAAQdCf5KbNuZEcXyOOWKUX8d0ZmmvVYjJM8CKqfxNwWXsVaNBzXww8isa9FaRMiWlei2ca1ORvzVg4xkvcd66xgdj6n07a8oMMaOdmqG4I3qAeh92ruEpWLT4uVzzobDpVUezJ3vH8IXoBizu0Xg9aijFHqlZ6PBDT+jISI2cpfzMgRHORvHk+Qha5AxWkVLinvo/FBGHYEZzkvNOSAqbi+RdesKnDKf4Lktx9LRSRr7Q4fhFUIY2ya33GHS4RjpNtYPrpSZ+QRAVkoRCkPJFhmfgaPYmyC94tTv2c8QDY2p1aXFC10wY5FF/Z2P0Mbcy/q92GSKxxHMM523UVBvgItAdEZEBqLSvFIuM5rf3UcOtJlgoIiiLJ9hskDEOw10Kl0uIuq/tlBp71SuFpYxFPB8lumTzaa8TQQO4pCoyq3zhe0PlbZk621pJRcxnF5pIEen6/7xmwr8+DASE/4yiV+vfhYz9/mUAbwR31k/5lVgvr/tBJLgvY9vyfM0eE="
- secure: "b8owqViNq38vwWow+rAPe/0loB477tR+FBSxNSJs4hwhTO5jPq8v6Ht+AgfzKRl898Ee5kbsPHGPt3O7x9evEU2DF05EoIUHKQfmMdZyD8UKAo5uLNL9B7kYCItmKODVwZKyo79FBvhVgU/B6+Ii40A6CJ6G5iSPxFI/Yy4fDiopxRHOKNGB4zwmBzwXZ2rTYxGJG/YW6Hjza/ThBdi5W6x3yhHsTndaq05p3ypF6BfBd/Ybm1e2iEajS40kN1WWJo5Y2YHrz6PAIVOjOCeOZEIdE1TCqzR8OaCAeHqkIwd02M8qL17aZDvKJESt8yROK5jZ1tTHDmSxOkNdNSYysYL30QhxKtGNgV+7VAq7r6n5datlBbjXXNqo3X41n+6tJE50hCvr7ntSXeSvDSPgMkTtKjSy6MxGzZTvEum4eX5PFKAta96TzvapTU7S71l6BWDj0biWCX89f4FTi5Dk9s4K+bsBcljiLAVqv9UFj7zDHraYde91FjTXZA+qdL1jAg6WJlgKQVIa7PJGD3GCRpQAdTrEuW2JJylwt5g/y2Deu4vA+XgG+L8AJxTFBNN9sMdtIKFQnQyyK5CYUmGnDuFzkYaapYxwpq+w8At/No5l9dlMosLr7NJym5ICcQnO0zUwEXGHisIpv4PcVbUB+1l/i6FnjUp4bOg4KEVhCC0="
sudo: false
addons:
apt:
Expand Down Expand Up @@ -36,12 +36,12 @@ before_deploy:
- git fetch --tags --depth=100 || true
deploy:
- provider: script
script: tool/releng --task=upload-to-github-release -v && tool/releng --task=upload-master-to-github-release -v
script: tool/releng --task=upload-to-github-release && tool/releng --task=upload-master-to-github-release
skip_cleanup: true
on:
branch: master
- provider: script
script: tool/releng --task=create-pullrequest --current-branch=$TRAVIS_BRANCH --package-name=mackerel-check-plugins -v
script: tool/releng --task=create-pullrequest --current-branch=$TRAVIS_BRANCH --package-name=mackerel-check-plugins
skip_cleanup: true
on:
all_branches: true
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## 0.9.5 (2017-03-09)

* add appveyor.yml and fix failing tests on windows #145 (Songmu)
* [check-tcp] connect timeout #146 (Songmu)
* [check-tcp] [bugfix] fix decimal threshold value handling #147 (Songmu)


## 0.9.4 (2017-02-22)

* ensure close temporary file in writeFileAtomically #141 (itchyny)
Expand Down
45 changes: 24 additions & 21 deletions check-tcp/lib/check-tcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,14 @@ func (opts *tcpOpts) merge(ex exchange) {
}
}

func dial(network, address string, ssl bool, noCheckCertificate bool) (net.Conn, error) {
func dial(network, address string, ssl bool, noCheckCertificate bool, timeout time.Duration) (net.Conn, error) {
d := &net.Dialer{Timeout: timeout}
if ssl {
return tls.Dial(network, address, &tls.Config{
return tls.DialWithDialer(d, network, address, &tls.Config{
InsecureSkipVerify: noCheckCertificate,
})
}
return net.Dial(network, address)
return d.Dial(network, address)
}

func (opts *tcpOpts) run() *checkers.Checker {
Expand All @@ -163,32 +164,34 @@ func (opts *tcpOpts) run() *checkers.Checker {
os.Setenv("LANG", "C")
os.Setenv("LC_ALL", "C")

address := fmt.Sprintf("%s:%d", opts.Hostname, opts.Port)
proto := "tcp"
addr := fmt.Sprintf("%s:%d", opts.Hostname, opts.Port)
if opts.UnixSock != "" {
proto = "unix"
addr = opts.UnixSock
}
timeout := time.Duration(opts.Timeout * float64(time.Second))
start := time.Now()
if opts.Delay > 0 {
time.Sleep(time.Duration(opts.Delay) * time.Second)
}
var conn net.Conn
if opts.UnixSock != "" {
conn, err = dial("unix", opts.UnixSock, opts.SSL, opts.NoCheckCertificate)
} else {
conn, err = dial("tcp", address, opts.SSL, opts.NoCheckCertificate)
}

conn, err := dial(proto, addr, opts.SSL, opts.NoCheckCertificate, timeout)
if err != nil {
return checkers.Critical(err.Error())
}
defer conn.Close()

if opts.Send != "" {
err := write(conn, []byte(opts.Send), opts.Timeout)
err := write(conn, []byte(opts.Send), timeout)
if err != nil {
return checkers.Critical(err.Error())
}
}

res := ""
if opts.expectReg != nil {
buf, err := slurp(conn, opts.MaxBytes, opts.Timeout)
buf, err := slurp(conn, opts.MaxBytes, timeout)
if err != nil {
return checkers.Critical(err.Error())
}
Expand All @@ -199,21 +202,21 @@ func (opts *tcpOpts) run() *checkers.Checker {
}

if opts.Quit != "" {
err := write(conn, []byte(opts.Quit), opts.Timeout)
err := write(conn, []byte(opts.Quit), timeout)
if err != nil {
return checkers.Critical(err.Error())
}
}
elapsed := time.Now().Sub(start)
elapsedSeconds := float64(time.Now().Sub(start)) / float64(time.Second)

chkSt := checkers.OK
if opts.Warning > 0 && elapsed > time.Duration(opts.Warning)*time.Second {
if opts.Warning > 0 && elapsedSeconds > opts.Warning {
chkSt = checkers.WARNING
}
if opts.Critical > 0 && elapsed > time.Duration(opts.Critical)*time.Second {
if opts.Critical > 0 && elapsedSeconds > opts.Critical {
chkSt = checkers.CRITICAL
}
msg := fmt.Sprintf("%.3f seconds response time on", float64(elapsed)/float64(time.Second))
msg := fmt.Sprintf("%.3f seconds response time on", elapsedSeconds)
if opts.Hostname != "" {
msg += " " + opts.Hostname
}
Expand All @@ -226,23 +229,23 @@ func (opts *tcpOpts) run() *checkers.Checker {
return checkers.NewChecker(chkSt, msg)
}

func write(conn net.Conn, content []byte, timeout float64) error {
func write(conn net.Conn, content []byte, timeout time.Duration) error {
if timeout > 0 {
conn.SetWriteDeadline(time.Now().Add(time.Duration(timeout) * time.Second))
conn.SetWriteDeadline(time.Now().Add(timeout))
}
_, err := conn.Write(content)
return err
}

func slurp(conn net.Conn, maxbytes int, timeout float64) ([]byte, error) {
func slurp(conn net.Conn, maxbytes int, timeout time.Duration) ([]byte, error) {
buf := []byte{}
readLimit := 32 * 1024
if maxbytes > 0 {
readLimit = maxbytes
}
readBytes := 0
if timeout > 0 {
conn.SetReadDeadline(time.Now().Add(time.Duration(timeout) * time.Second))
conn.SetReadDeadline(time.Now().Add(timeout))
}
for {
tmpBuf := make([]byte, readLimit)
Expand Down
4 changes: 2 additions & 2 deletions check-tcp/lib/check-tcp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ func TestUnixDomainSocket(t *testing.T) {
testUnexpected()

testOverWarn := func() {
opts, err := parseArgs([]string{"-U", sock, "--send", `PING`, "-E", "-e", "OKOK", "-w", "0.1"})
opts, err := parseArgs([]string{"-U", sock, "--send", `PING`, "-E", "-e", "OKOK", "-w", "0.000000001"})
assert.Equal(t, nil, err, "no errors")
ckr := opts.run()
assert.Equal(t, checkers.WARNING, ckr.Status, "should be Warning")
Expand All @@ -244,7 +244,7 @@ func TestUnixDomainSocket(t *testing.T) {
testOverWarn()

testOverCrit := func() {
opts, err := parseArgs([]string{"-U", sock, "--send", `PING`, "-E", "-e", "OKOK", "-c", "0.1"})
opts, err := parseArgs([]string{"-U", sock, "--send", `PING`, "-E", "-e", "OKOK", "-c", "0.000000001"})
assert.Equal(t, nil, err, "no errors")
ckr := opts.run()
assert.Equal(t, checkers.CRITICAL, ckr.Status, "should be Critical")
Expand Down
11 changes: 11 additions & 0 deletions packaging/deb/debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
mackerel-check-plugins (0.9.5-1) stable; urgency=low

* add appveyor.yml and fix failing tests on windows (by Songmu)
<https://github.com/mackerelio/go-check-plugins/pull/145>
* [check-tcp] connect timeout (by Songmu)
<https://github.com/mackerelio/go-check-plugins/pull/146>
* [check-tcp] [bugfix] fix decimal threshold value handling (by Songmu)
<https://github.com/mackerelio/go-check-plugins/pull/147>

-- mackerel <mackerel-developers@hatena.ne.jp> Thu, 09 Mar 2017 08:37:31 +0000

mackerel-check-plugins (0.9.4-1) stable; urgency=low

* ensure close temporary file in writeFileAtomically (by itchyny)
Expand Down
5 changes: 5 additions & 0 deletions packaging/rpm/mackerel-check-plugins.spec
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ done
%{__oldtargetdir}/*

%changelog
* Thu Mar 09 2017 <mackerel-developers@hatena.ne.jp> - 0.9.5-1
- add appveyor.yml and fix failing tests on windows (by Songmu)
- [check-tcp] connect timeout (by Songmu)
- [check-tcp] [bugfix] fix decimal threshold value handling (by Songmu)

* Wed Feb 22 2017 <mackerel-developers@hatena.ne.jp> - 0.9.4-1
- ensure close temporary file in writeFileAtomically (by itchyny)
- Write the file in same directory (by mattn)
Expand Down
11 changes: 9 additions & 2 deletions tool/releng
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ sub DEBUG() { $ENV{MC_RELENG_DEBUG} || $verbose }

sub command {say('+ '. join ' ', @_) if DEBUG; !system(@_) or croak $!}
sub command_with_exit_code {say('+ '. join ' ', @_) if DEBUG; system(@_)}
sub command_without_stderr {say('+ '. join ' ', @_) if DEBUG; !system(join(' ', @_) . ' >/dev/null 2>&1') or croak $!}
sub _git {
if($dry_run){
return
Expand All @@ -76,6 +77,12 @@ sub git_with_exit_code {
unshift @_, _git; goto \&command_with_exit_code
}

sub git_without_stderr {
if($dry_run){
return
}
unshift @_, _git; goto \&command_without_stderr
}

sub _hub {
if($dry_run){
Expand Down Expand Up @@ -463,7 +470,7 @@ sub create_pull_request {
git qw/config user.email/, 'mackerel-developers@hatena.ne.jp';
git qw/config user.name/, 'mackerel';
git qw/commit -am/, "update changelogs";
git qw/push -u/, "https://$ENV{GITHUB_TOKEN}\@github.com/$REPO_NAME.git";
git_without_stderr qw/push -u/, "https://$ENV{GITHUB_TOKEN}\@github.com/$REPO_NAME.git";
infof "Difference is pushed to GitHub.\n";
}

Expand All @@ -479,7 +486,7 @@ sub create_pull_request {
infof "Releasing pull request is created. Review and merge it. You can update changelogs and commit more in this branch before merging.\n";
} else {
# do push and pull-request again
git qw/push -u/, "https://$ENV{GITHUB_TOKEN}\@github.com/$REPO_NAME.git";
git_without_stderr qw/push -u/, "https://$ENV{GITHUB_TOKEN}\@github.com/$REPO_NAME.git";
$ret = hub_with_exit_code qw/pull-request -m/, $pr_body, qq/-b/, qq/$REPO_NAME:master/;
if(!defined($ret) || $ret == 0){
infof "Releasing pull request is created. Review and merge it. You can update changelogs and commit more in this branch before merging.\n";
Expand Down

0 comments on commit f1f07a5

Please sign in to comment.