├── vendor └── github.com │ ├── spf13 │ ├── pflag │ │ ├── .gitignore │ │ ├── .travis.yml │ │ ├── LICENSE │ │ ├── int.go │ │ ├── string.go │ │ ├── int64.go │ │ ├── int8.go │ │ ├── uint.go │ │ ├── count.go │ │ ├── golangflag.go │ │ ├── uint8.go │ │ ├── int16.go │ │ ├── int32.go │ │ ├── ip.go │ │ ├── uint16.go │ │ ├── float64.go │ │ ├── uint32.go │ │ ├── uint64.go │ │ ├── bool.go │ │ ├── float32.go │ │ ├── duration.go │ │ └── ipnet.go │ └── cobra │ │ ├── command_notwin.go │ │ ├── .mailmap │ │ ├── command_win.go │ │ ├── .travis.yml │ │ ├── .gitignore │ │ ├── args.go │ │ └── zsh_completions.go │ ├── heptiolabs │ └── healthcheck │ │ ├── .gitignore │ │ ├── .travis.yml │ │ ├── Gopkg.toml │ │ ├── doc.go │ │ ├── timeout.go │ │ ├── CODE_OF_CONDUCT.md │ │ ├── CONTRIBUTING.md │ │ ├── types.go │ │ ├── Gopkg.lock │ │ ├── metrics_handler.go │ │ ├── async.go │ │ ├── checks.go │ │ └── handler.go │ ├── prometheus │ ├── procfs │ │ ├── .gitignore │ │ ├── MAINTAINERS.md │ │ ├── .travis.yml │ │ ├── NOTICE │ │ ├── README.md │ │ ├── CONTRIBUTING.md │ │ ├── internal │ │ │ └── util │ │ │ │ └── parse.go │ │ ├── doc.go │ │ ├── proc_io.go │ │ ├── nfs │ │ │ ├── parse_nfs.go │ │ │ └── parse_nfsd.go │ │ ├── proc_ns.go │ │ ├── fs.go │ │ ├── Makefile │ │ └── buddyinfo.go │ ├── client_golang │ │ ├── prometheus │ │ │ ├── .gitignore │ │ │ ├── README.md │ │ │ ├── fnv.go │ │ │ └── collector.go │ │ ├── AUTHORS.md │ │ └── NOTICE │ ├── client_model │ │ └── NOTICE │ └── common │ │ ├── NOTICE │ │ ├── model │ │ ├── model.go │ │ ├── fnv.go │ │ ├── fingerprinting.go │ │ ├── silence.go │ │ └── metric.go │ │ ├── expfmt │ │ ├── fuzz.go │ │ ├── expfmt.go │ │ └── encode.go │ │ └── internal │ │ └── bitbucket.org │ │ └── ww │ │ └── goautoneg │ │ └── README.txt │ ├── matttproud │ └── golang_protobuf_extensions │ │ ├── pbutil │ │ ├── .gitignore │ │ ├── Makefile │ │ ├── doc.go │ │ ├── encode.go │ │ └── decode.go │ │ └── NOTICE │ ├── google │ └── skylark │ │ ├── .travis.yml │ │ ├── LICENSE │ │ └── syntax │ │ └── walk.go │ ├── golang │ └── protobuf │ │ ├── AUTHORS │ │ ├── CONTRIBUTORS │ │ └── LICENSE │ ├── inconshreveable │ └── mousetrap │ │ ├── trap_others.go │ │ ├── LICENSE │ │ ├── README.md │ │ ├── trap_windows_1.4.go │ │ └── trap_windows.go │ ├── beorn7 │ └── perks │ │ └── LICENSE │ └── windmilleng │ └── wmclient │ └── pkg │ ├── analytics │ ├── cli.go │ └── opt.go │ └── dirs │ └── dirs.go ├── docs ├── logo.png ├── pets_analytics_opt.md ├── pets_down.md ├── pets_list.md ├── pets_logs.md ├── pets_analytics.md ├── pets.md └── pets_up.md ├── main.go ├── .gitignore ├── Makefile ├── cmd └── pets │ ├── provider.go │ ├── down.go │ ├── list.go │ ├── logs.go │ ├── up.go │ └── cmd.go ├── Gopkg.toml ├── internal ├── proc │ ├── run_test.go │ ├── proc.go │ └── run.go ├── loader │ ├── go_test.go │ └── go.go ├── service │ └── service.go └── health │ └── health.go ├── .circleci └── config.yml ├── pets_release.sh └── README.md /vendor/github.com/spf13/pflag/.gitignore: -------------------------------------------------------------------------------- 1 | .idea/* 2 | 3 | -------------------------------------------------------------------------------- /vendor/github.com/heptiolabs/healthcheck/.gitignore: -------------------------------------------------------------------------------- 1 | /vendor 2 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/procfs/.gitignore: -------------------------------------------------------------------------------- 1 | /fixtures/ 2 | -------------------------------------------------------------------------------- /docs/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tilt-dev/pets/HEAD/docs/logo.png -------------------------------------------------------------------------------- /vendor/github.com/matttproud/golang_protobuf_extensions/pbutil/.gitignore: -------------------------------------------------------------------------------- 1 | cover.dat 2 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/procfs/MAINTAINERS.md: -------------------------------------------------------------------------------- 1 | * Tobias Schmidt 2 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/client_golang/prometheus/.gitignore: -------------------------------------------------------------------------------- 1 | command-line-arguments.test 2 | -------------------------------------------------------------------------------- /vendor/github.com/matttproud/golang_protobuf_extensions/NOTICE: -------------------------------------------------------------------------------- 1 | Copyright 2012 Matt T. Proud (matt.proud@gmail.com) 2 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/cobra/command_notwin.go: -------------------------------------------------------------------------------- 1 | // +build !windows 2 | 3 | package cobra 4 | 5 | var preExecHookFn func(*Command) 6 | -------------------------------------------------------------------------------- /vendor/github.com/google/skylark/.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | 3 | language: go 4 | 5 | go_import_path: github.com/google/skylark 6 | 7 | go: 8 | - 1.9.x 9 | - master 10 | -------------------------------------------------------------------------------- /vendor/github.com/matttproud/golang_protobuf_extensions/pbutil/Makefile: -------------------------------------------------------------------------------- 1 | all: 2 | 3 | cover: 4 | go test -cover -v -coverprofile=cover.dat ./... 5 | go tool cover -func cover.dat 6 | 7 | .PHONY: cover 8 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/cobra/.mailmap: -------------------------------------------------------------------------------- 1 | Steve Francia 2 | Bjørn Erik Pedersen 3 | Fabiano Franz 4 | -------------------------------------------------------------------------------- /vendor/github.com/golang/protobuf/AUTHORS: -------------------------------------------------------------------------------- 1 | # This source code refers to The Go Authors for copyright purposes. 2 | # The master list of authors is in the main Go distribution, 3 | # visible at http://tip.golang.org/AUTHORS. 4 | -------------------------------------------------------------------------------- /vendor/github.com/golang/protobuf/CONTRIBUTORS: -------------------------------------------------------------------------------- 1 | # This source code was written by the Go contributors. 2 | # The master list of contributors is in the main Go distribution, 3 | # visible at http://tip.golang.org/CONTRIBUTORS. 4 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/client_golang/prometheus/README.md: -------------------------------------------------------------------------------- 1 | See [![go-doc](https://godoc.org/github.com/prometheus/client_golang/prometheus?status.svg)](https://godoc.org/github.com/prometheus/client_golang/prometheus). 2 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/client_model/NOTICE: -------------------------------------------------------------------------------- 1 | Data model artifacts for Prometheus. 2 | Copyright 2012-2015 The Prometheus Authors 3 | 4 | This product includes software developed at 5 | SoundCloud Ltd. (http://soundcloud.com/). 6 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/common/NOTICE: -------------------------------------------------------------------------------- 1 | Common libraries shared by Prometheus Go components. 2 | Copyright 2015 The Prometheus Authors 3 | 4 | This product includes software developed at 5 | SoundCloud Ltd. (http://soundcloud.com/). 6 | -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | 7 | "github.com/windmilleng/pets/cmd/pets" 8 | ) 9 | 10 | func main() { 11 | if err := pets.Execute(); err != nil { 12 | fmt.Println(err) 13 | os.Exit(1) 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Binaries for programs and plugins 2 | *.exe 3 | *.exe~ 4 | *.dll 5 | *.so 6 | *.dylib 7 | 8 | # Test binary, build with `go test -c` 9 | *.test 10 | 11 | # Output of the go coverage tool, specifically when used with LiteIDE 12 | *.out 13 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/procfs/.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | 3 | language: go 4 | 5 | go: 6 | - 1.9.x 7 | - 1.10.x 8 | 9 | go_import_path: github.com/prometheus/procfs 10 | 11 | script: 12 | - make style check_license vet test staticcheck 13 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | 2 | 3 | .PHONY: test 4 | test: 5 | go test -timeout 20s ./... 6 | 7 | .PHONY: lint 8 | lint: 9 | go vet ./... 10 | 11 | .PHONY: deps 12 | deps: 13 | dep ensure 14 | 15 | .PHONY: install 16 | install: 17 | go install github.com/windmilleng/pets 18 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/procfs/NOTICE: -------------------------------------------------------------------------------- 1 | procfs provides functions to retrieve system, kernel and process 2 | metrics from the pseudo-filesystem proc. 3 | 4 | Copyright 2014-2015 The Prometheus Authors 5 | 6 | This product includes software developed at 7 | SoundCloud Ltd. (http://soundcloud.com/). 8 | -------------------------------------------------------------------------------- /vendor/github.com/heptiolabs/healthcheck/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | go_import_path: github.com/heptiolabs/healthcheck 3 | go: 4 | - 1.9.x 5 | 6 | sudo: false 7 | 8 | install: 9 | - go get -u github.com/golang/dep/cmd/dep 10 | && dep ensure -vendor-only -v 11 | 12 | script: 13 | - go test -v -cover . 14 | -------------------------------------------------------------------------------- /vendor/github.com/heptiolabs/healthcheck/Gopkg.toml: -------------------------------------------------------------------------------- 1 | # Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md 2 | # for detailed Gopkg.toml documentation. 3 | 4 | [[constraint]] 5 | name = "github.com/prometheus/client_golang" 6 | version = "0.8.0" 7 | 8 | [[constraint]] 9 | name = "github.com/stretchr/testify" 10 | version = "1.1.4" 11 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | 3 | language: go 4 | 5 | go: 6 | - 1.7.3 7 | - 1.8.1 8 | - tip 9 | 10 | matrix: 11 | allow_failures: 12 | - go: tip 13 | 14 | install: 15 | - go get github.com/golang/lint/golint 16 | - export PATH=$GOPATH/bin:$PATH 17 | - go install ./... 18 | 19 | script: 20 | - verify/all.sh -v 21 | - go test ./... 22 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/cobra/command_win.go: -------------------------------------------------------------------------------- 1 | // +build windows 2 | 3 | package cobra 4 | 5 | import ( 6 | "os" 7 | "time" 8 | 9 | "github.com/inconshreveable/mousetrap" 10 | ) 11 | 12 | var preExecHookFn = preExecHook 13 | 14 | func preExecHook(c *Command) { 15 | if MousetrapHelpText != "" && mousetrap.StartedByExplorer() { 16 | c.Print(MousetrapHelpText) 17 | time.Sleep(5 * time.Second) 18 | os.Exit(1) 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /cmd/pets/provider.go: -------------------------------------------------------------------------------- 1 | package pets 2 | 3 | import ( 4 | "os" 5 | 6 | "github.com/windmilleng/pets/internal/mill" 7 | "github.com/windmilleng/pets/internal/proc" 8 | "github.com/windmilleng/pets/internal/school" 9 | ) 10 | 11 | func newPetsitter() (*mill.Petsitter, error) { 12 | procfs, err := proc.NewProcFS() 13 | if err != nil { 14 | return nil, err 15 | } 16 | runner := proc.NewRunner(procfs) 17 | school := school.NewPetSchool(procfs) 18 | return mill.NewPetsitter(os.Stdout, os.Stderr, runner, procfs, school, dryRun), nil 19 | } 20 | -------------------------------------------------------------------------------- /vendor/github.com/inconshreveable/mousetrap/trap_others.go: -------------------------------------------------------------------------------- 1 | // +build !windows 2 | 3 | package mousetrap 4 | 5 | // StartedByExplorer returns true if the program was invoked by the user 6 | // double-clicking on the executable from explorer.exe 7 | // 8 | // It is conservative and returns false if any of the internal calls fail. 9 | // It does not guarantee that the program was run from a terminal. It only can tell you 10 | // whether it was launched from explorer.exe 11 | // 12 | // On non-Windows platforms, it always returns false. 13 | func StartedByExplorer() bool { 14 | return false 15 | } 16 | -------------------------------------------------------------------------------- /vendor/github.com/inconshreveable/mousetrap/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2014 Alan Shreve 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/cobra/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | 3 | matrix: 4 | include: 5 | - go: 1.9.4 6 | - go: 1.10.0 7 | - go: tip 8 | allow_failures: 9 | - go: tip 10 | 11 | before_install: 12 | - mkdir -p bin 13 | - curl -Lso bin/shellcheck https://github.com/caarlos0/shellcheck-docker/releases/download/v0.4.3/shellcheck 14 | - chmod +x bin/shellcheck 15 | script: 16 | - PATH=$PATH:$PWD/bin go test -v ./... 17 | - go build 18 | - diff -u <(echo -n) <(gofmt -d -s .) 19 | - if [ -z $NOVET ]; then 20 | diff -u <(echo -n) <(go tool vet . 2>&1 | grep -vE 'ExampleCommand|bash_completions.*Fprint'); 21 | fi 22 | -------------------------------------------------------------------------------- /docs/pets_analytics_opt.md: -------------------------------------------------------------------------------- 1 | ## pets analytics opt 2 | 3 | opt-in or -out to windmill analytics collection/upload 4 | 5 | ### Synopsis 6 | 7 | opt-in or -out to windmill analytics collection/upload 8 | 9 | ``` 10 | pets analytics opt [flags] 11 | ``` 12 | 13 | ### Options 14 | 15 | ``` 16 | -h, --help help for opt 17 | ``` 18 | 19 | ### Options inherited from parent commands 20 | 21 | ``` 22 | -d, --dry-run just print recommended commands, don't run them 23 | ``` 24 | 25 | ### SEE ALSO 26 | 27 | * [pets analytics](pets_analytics.md) - info and status about windmill analytics 28 | 29 | ###### Auto generated by spf13/cobra on 3-Aug-2018 30 | -------------------------------------------------------------------------------- /docs/pets_down.md: -------------------------------------------------------------------------------- 1 | ## pets down 2 | 3 | Kill all processes started by pets 4 | 5 | ### Synopsis 6 | 7 | Kill all processes started by pets 8 | 9 | ``` 10 | pets down [flags] 11 | ``` 12 | 13 | ### Options 14 | 15 | ``` 16 | -h, --help help for down 17 | ``` 18 | 19 | ### Options inherited from parent commands 20 | 21 | ``` 22 | -d, --dry-run just print recommended commands, don't run them 23 | ``` 24 | 25 | ### SEE ALSO 26 | 27 | * [pets](pets.md) - PETS makes it easy to manage lots of servers running on your machine that you want to keep a close eye on for local development. 28 | 29 | ###### Auto generated by spf13/cobra on 3-Aug-2018 30 | -------------------------------------------------------------------------------- /docs/pets_list.md: -------------------------------------------------------------------------------- 1 | ## pets list 2 | 3 | List all processes started by pets 4 | 5 | ### Synopsis 6 | 7 | List all processes started by pets 8 | 9 | ``` 10 | pets list [flags] 11 | ``` 12 | 13 | ### Options 14 | 15 | ``` 16 | -h, --help help for list 17 | ``` 18 | 19 | ### Options inherited from parent commands 20 | 21 | ``` 22 | -d, --dry-run just print recommended commands, don't run them 23 | ``` 24 | 25 | ### SEE ALSO 26 | 27 | * [pets](pets.md) - PETS makes it easy to manage lots of servers running on your machine that you want to keep a close eye on for local development. 28 | 29 | ###### Auto generated by spf13/cobra on 3-Aug-2018 30 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/cobra/.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files, Static and Dynamic libs (Shared Objects) 2 | *.o 3 | *.a 4 | *.so 5 | 6 | # Folders 7 | _obj 8 | _test 9 | 10 | # Architecture specific extensions/prefixes 11 | *.[568vq] 12 | [568vq].out 13 | 14 | *.cgo1.go 15 | *.cgo2.c 16 | _cgo_defun.c 17 | _cgo_gotypes.go 18 | _cgo_export.* 19 | 20 | _testmain.go 21 | 22 | # Vim files https://github.com/github/gitignore/blob/master/Global/Vim.gitignore 23 | # swap 24 | [._]*.s[a-w][a-z] 25 | [._]s[a-w][a-z] 26 | # session 27 | Session.vim 28 | # temporary 29 | .netrwhist 30 | *~ 31 | # auto-generated tag files 32 | tags 33 | 34 | *.exe 35 | 36 | cobra.test 37 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/client_golang/AUTHORS.md: -------------------------------------------------------------------------------- 1 | The Prometheus project was started by Matt T. Proud (emeritus) and 2 | Julius Volz in 2012. 3 | 4 | Maintainers of this repository: 5 | 6 | * Björn Rabenstein 7 | 8 | The following individuals have contributed code to this repository 9 | (listed in alphabetical order): 10 | 11 | * Bernerd Schaefer 12 | * Björn Rabenstein 13 | * Daniel Bornkessel 14 | * Jeff Younker 15 | * Julius Volz 16 | * Matt T. Proud 17 | * Tobias Schmidt 18 | 19 | -------------------------------------------------------------------------------- /docs/pets_logs.md: -------------------------------------------------------------------------------- 1 | ## pets logs 2 | 3 | Get logs for running servers 4 | 5 | ### Synopsis 6 | 7 | Get logs for running servers 8 | 9 | ``` 10 | pets logs [flags] 11 | ``` 12 | 13 | ### Examples 14 | 15 | ``` 16 | pets logs 17 | pets logs frontend 18 | ``` 19 | 20 | ### Options 21 | 22 | ``` 23 | -h, --help help for logs 24 | ``` 25 | 26 | ### Options inherited from parent commands 27 | 28 | ``` 29 | -d, --dry-run just print recommended commands, don't run them 30 | ``` 31 | 32 | ### SEE ALSO 33 | 34 | * [pets](pets.md) - PETS makes it easy to manage lots of servers running on your machine that you want to keep a close eye on for local development. 35 | 36 | ###### Auto generated by spf13/cobra on 3-Aug-2018 37 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/procfs/README.md: -------------------------------------------------------------------------------- 1 | # procfs 2 | 3 | This procfs package provides functions to retrieve system, kernel and process 4 | metrics from the pseudo-filesystem proc. 5 | 6 | *WARNING*: This package is a work in progress. Its API may still break in 7 | backwards-incompatible ways without warnings. Use it at your own risk. 8 | 9 | [![GoDoc](https://godoc.org/github.com/prometheus/procfs?status.png)](https://godoc.org/github.com/prometheus/procfs) 10 | [![Build Status](https://travis-ci.org/prometheus/procfs.svg?branch=master)](https://travis-ci.org/prometheus/procfs) 11 | [![Go Report Card](https://goreportcard.com/badge/github.com/prometheus/procfs)](https://goreportcard.com/report/github.com/prometheus/procfs) 12 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/client_golang/prometheus/fnv.go: -------------------------------------------------------------------------------- 1 | package prometheus 2 | 3 | // Inline and byte-free variant of hash/fnv's fnv64a. 4 | 5 | const ( 6 | offset64 = 14695981039346656037 7 | prime64 = 1099511628211 8 | ) 9 | 10 | // hashNew initializies a new fnv64a hash value. 11 | func hashNew() uint64 { 12 | return offset64 13 | } 14 | 15 | // hashAdd adds a string to a fnv64a hash value, returning the updated hash. 16 | func hashAdd(h uint64, s string) uint64 { 17 | for i := 0; i < len(s); i++ { 18 | h ^= uint64(s[i]) 19 | h *= prime64 20 | } 21 | return h 22 | } 23 | 24 | // hashAddByte adds a byte to a fnv64a hash value, returning the updated hash. 25 | func hashAddByte(h uint64, b byte) uint64 { 26 | h ^= uint64(b) 27 | h *= prime64 28 | return h 29 | } 30 | -------------------------------------------------------------------------------- /docs/pets_analytics.md: -------------------------------------------------------------------------------- 1 | ## pets analytics 2 | 3 | info and status about windmill analytics 4 | 5 | ### Synopsis 6 | 7 | info and status about windmill analytics 8 | 9 | ``` 10 | pets analytics [flags] 11 | ``` 12 | 13 | ### Options 14 | 15 | ``` 16 | -h, --help help for analytics 17 | ``` 18 | 19 | ### Options inherited from parent commands 20 | 21 | ``` 22 | -d, --dry-run just print recommended commands, don't run them 23 | ``` 24 | 25 | ### SEE ALSO 26 | 27 | * [pets](pets.md) - PETS makes it easy to manage lots of servers running on your machine that you want to keep a close eye on for local development. 28 | * [pets analytics opt](pets_analytics_opt.md) - opt-in or -out to windmill analytics collection/upload 29 | 30 | ###### Auto generated by spf13/cobra on 3-Aug-2018 31 | -------------------------------------------------------------------------------- /vendor/github.com/matttproud/golang_protobuf_extensions/pbutil/doc.go: -------------------------------------------------------------------------------- 1 | // Copyright 2013 Matt T. Proud 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Package pbutil provides record length-delimited Protocol Buffer streaming. 16 | package pbutil 17 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/common/model/model.go: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Prometheus Authors 2 | // Licensed under the Apache License, Version 2.0 (the "License"); 3 | // you may not use this file except in compliance with the License. 4 | // You may obtain a copy of the License at 5 | // 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | 14 | // Package model contains common data structures that are shared across 15 | // Prometheus components and libraries. 16 | package model 17 | -------------------------------------------------------------------------------- /Gopkg.toml: -------------------------------------------------------------------------------- 1 | # Gopkg.toml example 2 | # 3 | # Refer to https://golang.github.io/dep/docs/Gopkg.toml.html 4 | # for detailed Gopkg.toml documentation. 5 | # 6 | # required = ["github.com/user/thing/cmd/thing"] 7 | # ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"] 8 | # 9 | # [[constraint]] 10 | # name = "github.com/user/project" 11 | # version = "1.0.0" 12 | # 13 | # [[constraint]] 14 | # name = "github.com/user/project2" 15 | # branch = "dev" 16 | # source = "github.com/myfork/project2" 17 | # 18 | # [[override]] 19 | # name = "github.com/x/y" 20 | # version = "2.4.0" 21 | # 22 | # [prune] 23 | # non-go = false 24 | # go-tests = true 25 | # unused-packages = true 26 | 27 | 28 | [[constraint]] 29 | name = "github.com/spf13/cobra" 30 | version = "0.0.3" 31 | 32 | [prune] 33 | go-tests = true 34 | unused-packages = true 35 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/client_golang/NOTICE: -------------------------------------------------------------------------------- 1 | Prometheus instrumentation library for Go applications 2 | Copyright 2012-2015 The Prometheus Authors 3 | 4 | This product includes software developed at 5 | SoundCloud Ltd. (http://soundcloud.com/). 6 | 7 | 8 | The following components are included in this product: 9 | 10 | perks - a fork of https://github.com/bmizerany/perks 11 | https://github.com/beorn7/perks 12 | Copyright 2013-2015 Blake Mizerany, Björn Rabenstein 13 | See https://github.com/beorn7/perks/blob/master/README.md for license details. 14 | 15 | Go support for Protocol Buffers - Google's data interchange format 16 | http://github.com/golang/protobuf/ 17 | Copyright 2010 The Go Authors 18 | See source code for license details. 19 | 20 | Support for streaming Protocol Buffer messages for the Go language (golang). 21 | https://github.com/matttproud/golang_protobuf_extensions 22 | Copyright 2013 Matt T. Proud 23 | Licensed under the Apache License, Version 2.0 24 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/procfs/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | Prometheus uses GitHub to manage reviews of pull requests. 4 | 5 | * If you have a trivial fix or improvement, go ahead and create a pull request, 6 | addressing (with `@...`) the maintainer of this repository (see 7 | [MAINTAINERS.md](MAINTAINERS.md)) in the description of the pull request. 8 | 9 | * If you plan to do something more involved, first discuss your ideas 10 | on our [mailing list](https://groups.google.com/forum/?fromgroups#!forum/prometheus-developers). 11 | This will avoid unnecessary work and surely give you and us a good deal 12 | of inspiration. 13 | 14 | * Relevant coding style guidelines are the [Go Code Review 15 | Comments](https://code.google.com/p/go-wiki/wiki/CodeReviewComments) 16 | and the _Formatting and style_ section of Peter Bourgon's [Go: Best 17 | Practices for Production 18 | Environments](http://peter.bourgon.org/go-in-production/#formatting-and-style). 19 | -------------------------------------------------------------------------------- /vendor/github.com/inconshreveable/mousetrap/README.md: -------------------------------------------------------------------------------- 1 | # mousetrap 2 | 3 | mousetrap is a tiny library that answers a single question. 4 | 5 | On a Windows machine, was the process invoked by someone double clicking on 6 | the executable file while browsing in explorer? 7 | 8 | ### Motivation 9 | 10 | Windows developers unfamiliar with command line tools will often "double-click" 11 | the executable for a tool. Because most CLI tools print the help and then exit 12 | when invoked without arguments, this is often very frustrating for those users. 13 | 14 | mousetrap provides a way to detect these invocations so that you can provide 15 | more helpful behavior and instructions on how to run the CLI tool. To see what 16 | this looks like, both from an organizational and a technical perspective, see 17 | https://inconshreveable.com/09-09-2014/sweat-the-small-stuff/ 18 | 19 | ### The interface 20 | 21 | The library exposes a single interface: 22 | 23 | func StartedByExplorer() (bool) 24 | -------------------------------------------------------------------------------- /docs/pets.md: -------------------------------------------------------------------------------- 1 | ## pets 2 | 3 | PETS makes it easy to manage lots of servers running on your machine that you want to keep a close eye on for local development. 4 | 5 | ### Synopsis 6 | 7 | A PETS file is like a Makefile for running servers and connecting them 8 | to other servers. With PETS, we can switch back and forth quickly 9 | between servers running locally and servers running in the cloud. 10 | 11 | ``` 12 | pets [arguments] [flags] 13 | ``` 14 | 15 | ### Options 16 | 17 | ``` 18 | -d, --dry-run just print recommended commands, don't run them 19 | -h, --help help for pets 20 | ``` 21 | 22 | ### SEE ALSO 23 | 24 | * [pets analytics](pets_analytics.md) - info and status about windmill analytics 25 | * [pets down](pets_down.md) - Kill all processes started by pets 26 | * [pets list](pets_list.md) - List all processes started by pets 27 | * [pets logs](pets_logs.md) - Get logs for running servers 28 | * [pets up](pets_up.md) - Start servers specified in the Petsfile 29 | 30 | ###### Auto generated by spf13/cobra on 3-Aug-2018 31 | -------------------------------------------------------------------------------- /vendor/github.com/beorn7/perks/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (C) 2013 Blake Mizerany 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /vendor/github.com/heptiolabs/healthcheck/doc.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 by the contributors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | /* 16 | Package healthcheck helps you implement Kubernetes liveness and readiness checks 17 | for your application. It supports synchronous and asynchronous (background) 18 | checks. It can optionally report each check's status as a set of Prometheus 19 | gauge metrics for cluster-wide monitoring and alerting. 20 | 21 | It also includes a small library of generic checks for DNS, TCP, and HTTP 22 | reachability as well as Goroutine usage. 23 | */ 24 | package healthcheck 25 | -------------------------------------------------------------------------------- /docs/pets_up.md: -------------------------------------------------------------------------------- 1 | ## pets up 2 | 3 | Start servers specified in the Petsfile 4 | 5 | ### Synopsis 6 | 7 | Start servers specified in the Petsfile. 8 | 9 | To start all servers with tier "local", run: 'pets up' 10 | 11 | To start all servers on a different provider tier (for example, k8s), run: 'pets up --tier=k8s' 12 | 13 | To start a single server and all its dependencies, run: 'pets up my-server'. 14 | 15 | 16 | ``` 17 | pets up [flags] 18 | ``` 19 | 20 | ### Examples 21 | 22 | ``` 23 | pets up 24 | pets up frontend 25 | pets up frontend --tier=k8s 26 | ``` 27 | 28 | ### Options 29 | 30 | ``` 31 | -h, --help help for up 32 | --tier string The tier of servers to start up. Defaults to 'local' (default "local") 33 | --with strings Override servers in the server graph. Example: --with=backend=k8s 34 | ``` 35 | 36 | ### Options inherited from parent commands 37 | 38 | ``` 39 | -d, --dry-run just print recommended commands, don't run them 40 | ``` 41 | 42 | ### SEE ALSO 43 | 44 | * [pets](pets.md) - PETS makes it easy to manage lots of servers running on your machine that you want to keep a close eye on for local development. 45 | 46 | ###### Auto generated by spf13/cobra on 3-Aug-2018 47 | -------------------------------------------------------------------------------- /internal/proc/run_test.go: -------------------------------------------------------------------------------- 1 | package proc 2 | 3 | import ( 4 | "bytes" 5 | "os" 6 | "testing" 7 | ) 8 | 9 | func TestRun(t *testing.T) { 10 | f := newProcFixture(t) 11 | defer f.tearDown() 12 | 13 | procfs := f.procfs 14 | stdout := &bytes.Buffer{} 15 | stderr := &bytes.Buffer{} 16 | cwd, _ := os.Getwd() 17 | 18 | r := NewRunner(procfs) 19 | err := r.RunWithIO([]string{"echo", "hello"}, cwd, stdout, stderr) 20 | if err != nil { 21 | t.Fatal(err) 22 | } 23 | 24 | out := stdout.String() 25 | if out != "hello\n" { 26 | t.Errorf("Expected 'hello'. Actual: %s", out) 27 | } 28 | } 29 | 30 | func TestStartAddsToProcFS(t *testing.T) { 31 | f := newProcFixture(t) 32 | defer f.tearDown() 33 | 34 | procfs := f.procfs 35 | stdout := &bytes.Buffer{} 36 | stderr := &bytes.Buffer{} 37 | cwd, _ := os.Getwd() 38 | 39 | r := NewRunner(procfs) 40 | petsCmd, err := r.StartWithIO([]string{"sleep", "10"}, cwd, stdout, stderr) 41 | if err != nil { 42 | t.Fatal(err) 43 | } 44 | defer petsCmd.Cmd.Process.Kill() 45 | 46 | procs, err := procfs.ProcsFromFS() 47 | if err != nil { 48 | t.Fatal(err) 49 | } 50 | 51 | if len(procs) != 1 || procs[0].Pid != petsCmd.Proc.Pid { 52 | t.Fatalf("Unexpected procs on disk: %v", procs) 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/common/expfmt/fuzz.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Prometheus Authors 2 | // Licensed under the Apache License, Version 2.0 (the "License"); 3 | // you may not use this file except in compliance with the License. 4 | // You may obtain a copy of the License at 5 | // 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | 14 | // Build only when actually fuzzing 15 | // +build gofuzz 16 | 17 | package expfmt 18 | 19 | import "bytes" 20 | 21 | // Fuzz text metric parser with with github.com/dvyukov/go-fuzz: 22 | // 23 | // go-fuzz-build github.com/prometheus/common/expfmt 24 | // go-fuzz -bin expfmt-fuzz.zip -workdir fuzz 25 | // 26 | // Further input samples should go in the folder fuzz/corpus. 27 | func Fuzz(in []byte) int { 28 | parser := TextParser{} 29 | _, err := parser.TextToMetricFamilies(bytes.NewReader(in)) 30 | 31 | if err != nil { 32 | return 0 33 | } 34 | 35 | return 1 36 | } 37 | -------------------------------------------------------------------------------- /.circleci/config.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | jobs: 3 | build-linux: 4 | docker: 5 | - image: circleci/golang:1.10 6 | working_directory: /go/src/github.com/windmilleng/pets 7 | steps: 8 | - checkout 9 | - run: sudo apt install netcat-openbsd 10 | # for testing load() 11 | - run: go get github.com/windmilleng/blorg-frontend 12 | - run: make lint 13 | - run: make test 14 | 15 | build-macos: 16 | macos: 17 | xcode: "9.4.0" 18 | 19 | working_directory: ~/go/src/github.com/windmilleng/pets 20 | steps: 21 | - run: echo 'export PATH=~/go/bin:$PATH' >> $BASH_ENV 22 | - checkout 23 | - restore_cache: 24 | keys: 25 | - v5_homebrew_cache 26 | # NOTE(dmiller): bump homebrew_cache version after adding something here 27 | - run: brew install coreutils go 28 | - save_cache: 29 | paths: 30 | - /usr/local/Homebrew 31 | key: v5_homebrew_cache 32 | # for testing load() 33 | - run: go get github.com/windmilleng/blorg-frontend 34 | - run: make test 35 | 36 | workflows: 37 | version: 2 38 | build: 39 | # The linux job is cheaper than the others, so run that first. 40 | jobs: 41 | - build-linux 42 | - build-macos: 43 | requires: 44 | - build-linux 45 | -------------------------------------------------------------------------------- /cmd/pets/down.go: -------------------------------------------------------------------------------- 1 | package pets 2 | 3 | import ( 4 | "fmt" 5 | "syscall" 6 | "time" 7 | 8 | "github.com/spf13/cobra" 9 | "github.com/windmilleng/pets/internal/proc" 10 | ) 11 | 12 | var DownCmd = &cobra.Command{ 13 | Use: "down", 14 | Short: "Kill all processes started by pets", 15 | Run: func(cms *cobra.Command, args []string) { 16 | analyticsService.Incr("cmd.down", nil) 17 | defer analyticsService.Flush(time.Second) 18 | 19 | procfs, err := proc.NewProcFS() 20 | if err != nil { 21 | fatal(err) 22 | } 23 | 24 | procs, err := procfs.ProcsFromFS() 25 | if err != nil { 26 | fatal(err) 27 | } 28 | 29 | if len(procs) == 0 { 30 | fmt.Println("No pets running") 31 | return 32 | } 33 | 34 | for _, p := range procs { 35 | if p.ServiceName != "" { 36 | fmt.Printf("Stopping %s\n", p.ServiceKey()) 37 | } else { 38 | fmt.Printf("Stopping pid %d\n", p.Pid) 39 | } 40 | 41 | // TODO: Decide what to do in edge cases, when killing pets doesn't work 42 | // for now, ignore any errors. 43 | 44 | // Pets starts all processes with a process group. -p.Pid is a posix trick 45 | // to kill all processes in the group. This is helpful for things like 'go run' 46 | // that spawn subprocesses, so that the subprocesses get killed too. 47 | pgid := -p.Pid 48 | syscall.Kill(pgid, syscall.SIGINT) 49 | } 50 | 51 | procfs.RemoveAllProcs() 52 | }, 53 | } 54 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/common/model/fnv.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Prometheus Authors 2 | // Licensed under the Apache License, Version 2.0 (the "License"); 3 | // you may not use this file except in compliance with the License. 4 | // You may obtain a copy of the License at 5 | // 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | 14 | package model 15 | 16 | // Inline and byte-free variant of hash/fnv's fnv64a. 17 | 18 | const ( 19 | offset64 = 14695981039346656037 20 | prime64 = 1099511628211 21 | ) 22 | 23 | // hashNew initializies a new fnv64a hash value. 24 | func hashNew() uint64 { 25 | return offset64 26 | } 27 | 28 | // hashAdd adds a string to a fnv64a hash value, returning the updated hash. 29 | func hashAdd(h uint64, s string) uint64 { 30 | for i := 0; i < len(s); i++ { 31 | h ^= uint64(s[i]) 32 | h *= prime64 33 | } 34 | return h 35 | } 36 | 37 | // hashAddByte adds a byte to a fnv64a hash value, returning the updated hash. 38 | func hashAddByte(h uint64, b byte) uint64 { 39 | h ^= uint64(b) 40 | h *= prime64 41 | return h 42 | } 43 | -------------------------------------------------------------------------------- /vendor/github.com/inconshreveable/mousetrap/trap_windows_1.4.go: -------------------------------------------------------------------------------- 1 | // +build windows 2 | // +build go1.4 3 | 4 | package mousetrap 5 | 6 | import ( 7 | "os" 8 | "syscall" 9 | "unsafe" 10 | ) 11 | 12 | func getProcessEntry(pid int) (*syscall.ProcessEntry32, error) { 13 | snapshot, err := syscall.CreateToolhelp32Snapshot(syscall.TH32CS_SNAPPROCESS, 0) 14 | if err != nil { 15 | return nil, err 16 | } 17 | defer syscall.CloseHandle(snapshot) 18 | var procEntry syscall.ProcessEntry32 19 | procEntry.Size = uint32(unsafe.Sizeof(procEntry)) 20 | if err = syscall.Process32First(snapshot, &procEntry); err != nil { 21 | return nil, err 22 | } 23 | for { 24 | if procEntry.ProcessID == uint32(pid) { 25 | return &procEntry, nil 26 | } 27 | err = syscall.Process32Next(snapshot, &procEntry) 28 | if err != nil { 29 | return nil, err 30 | } 31 | } 32 | } 33 | 34 | // StartedByExplorer returns true if the program was invoked by the user double-clicking 35 | // on the executable from explorer.exe 36 | // 37 | // It is conservative and returns false if any of the internal calls fail. 38 | // It does not guarantee that the program was run from a terminal. It only can tell you 39 | // whether it was launched from explorer.exe 40 | func StartedByExplorer() bool { 41 | pe, err := getProcessEntry(os.Getppid()) 42 | if err != nil { 43 | return false 44 | } 45 | return "explorer.exe" == syscall.UTF16ToString(pe.ExeFile[:]) 46 | } 47 | -------------------------------------------------------------------------------- /internal/loader/go_test.go: -------------------------------------------------------------------------------- 1 | package loader 2 | 3 | import ( 4 | "go/build" 5 | "io/ioutil" 6 | "os" 7 | "path/filepath" 8 | "strings" 9 | "testing" 10 | ) 11 | 12 | func TestLoadGoRepo(t *testing.T) { 13 | f := newGoFixture(t) 14 | defer f.tearDown() 15 | 16 | dir, err := LoadGoRepo("github.com/windmilleng/blorg-frontend", f.buildCtx()) 17 | if err != nil { 18 | t.Fatal(err) 19 | } 20 | 21 | _, err = os.Stat(filepath.Join(dir, "main.go")) 22 | if err != nil { 23 | t.Fatal(err) 24 | } 25 | 26 | if !strings.Contains(dir, f.dir) { 27 | t.Fatalf("Expected Go repo downloaded inside test tempdir. Actual: %s", dir) 28 | } 29 | } 30 | 31 | func TestLoadGoRepoFails(t *testing.T) { 32 | f := newGoFixture(t) 33 | defer f.tearDown() 34 | 35 | _, err := LoadGoRepo("github.com/windmilleng/blorg-nonsense", f.buildCtx()) 36 | if err == nil || !strings.Contains(err.Error(), "failed with output") { 37 | t.Errorf("Expected error with exit status. Actual: %v", err) 38 | } 39 | } 40 | 41 | type goFixture struct { 42 | t *testing.T 43 | dir string 44 | } 45 | 46 | func newGoFixture(t *testing.T) *goFixture { 47 | dir, _ := ioutil.TempDir("", t.Name()) 48 | return &goFixture{ 49 | t: t, 50 | dir: dir, 51 | } 52 | } 53 | 54 | func (f *goFixture) buildCtx() build.Context { 55 | buildCtx := build.Default 56 | buildCtx.GOPATH = f.dir 57 | return buildCtx 58 | } 59 | 60 | func (f *goFixture) tearDown() { 61 | os.RemoveAll(f.dir) 62 | } 63 | -------------------------------------------------------------------------------- /cmd/pets/list.go: -------------------------------------------------------------------------------- 1 | package pets 2 | 3 | import ( 4 | "fmt" 5 | "time" 6 | 7 | "github.com/spf13/cobra" 8 | "github.com/windmilleng/pets/internal/proc" 9 | ) 10 | 11 | var ListCmd = &cobra.Command{ 12 | Use: "list", 13 | Short: "List all processes started by pets", 14 | Run: func(cms *cobra.Command, args []string) { 15 | procfs, err := proc.NewProcFS() 16 | if err != nil { 17 | fatal(err) 18 | } 19 | 20 | procs, err := procfs.ProcsFromFS() 21 | if err != nil { 22 | fatal(err) 23 | } 24 | 25 | if len(procs) == 0 { 26 | fmt.Println("No pets running") 27 | return 28 | } 29 | 30 | fmt.Printf("%-25s%-15s%-15s%-15s\n", "Name", "Age", "Host", "Port") 31 | for _, p := range procs { 32 | el := timeDur(p.TimeSince().Truncate(time.Second)) 33 | fmt.Printf("%-25s%-15s%-15s%-15d\n", p.DisplayName, el, p.Hostname, p.Port) 34 | } 35 | }, 36 | } 37 | 38 | func timeDur(d time.Duration) string { 39 | if seconds := int(d.Seconds()); seconds < -1 { 40 | return fmt.Sprintf("") 41 | } else if seconds < 0 { 42 | return fmt.Sprintf("0s") 43 | } else if seconds < 60 { 44 | return fmt.Sprintf("%ds", seconds) 45 | } else if minutes := int(d.Minutes()); minutes < 60 { 46 | return fmt.Sprintf("%dm", minutes) 47 | } else if hours := int(d.Hours()); hours < 24 { 48 | return fmt.Sprintf("%dh", hours) 49 | } else if hours < 24*365 { 50 | return fmt.Sprintf("%dd", hours/24) 51 | } 52 | return fmt.Sprintf("%dy", int(d.Hours()/24/365)) 53 | } 54 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/procfs/internal/util/parse.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Prometheus Authors 2 | // Licensed under the Apache License, Version 2.0 (the "License"); 3 | // you may not use this file except in compliance with the License. 4 | // You may obtain a copy of the License at 5 | // 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | 14 | package util 15 | 16 | import "strconv" 17 | 18 | // ParseUint32s parses a slice of strings into a slice of uint32s. 19 | func ParseUint32s(ss []string) ([]uint32, error) { 20 | us := make([]uint32, 0, len(ss)) 21 | for _, s := range ss { 22 | u, err := strconv.ParseUint(s, 10, 32) 23 | if err != nil { 24 | return nil, err 25 | } 26 | 27 | us = append(us, uint32(u)) 28 | } 29 | 30 | return us, nil 31 | } 32 | 33 | // ParseUint64s parses a slice of strings into a slice of uint64s. 34 | func ParseUint64s(ss []string) ([]uint64, error) { 35 | us := make([]uint64, 0, len(ss)) 36 | for _, s := range ss { 37 | u, err := strconv.ParseUint(s, 10, 64) 38 | if err != nil { 39 | return nil, err 40 | } 41 | 42 | us = append(us, u) 43 | } 44 | 45 | return us, nil 46 | } 47 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/procfs/doc.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 Prometheus Team 2 | // Licensed under the Apache License, Version 2.0 (the "License"); 3 | // you may not use this file except in compliance with the License. 4 | // You may obtain a copy of the License at 5 | // 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | 14 | // Package procfs provides functions to retrieve system, kernel and process 15 | // metrics from the pseudo-filesystem proc. 16 | // 17 | // Example: 18 | // 19 | // package main 20 | // 21 | // import ( 22 | // "fmt" 23 | // "log" 24 | // 25 | // "github.com/prometheus/procfs" 26 | // ) 27 | // 28 | // func main() { 29 | // p, err := procfs.Self() 30 | // if err != nil { 31 | // log.Fatalf("could not get process: %s", err) 32 | // } 33 | // 34 | // stat, err := p.NewStat() 35 | // if err != nil { 36 | // log.Fatalf("could not get process stat: %s", err) 37 | // } 38 | // 39 | // fmt.Printf("command: %s\n", stat.Comm) 40 | // fmt.Printf("cpu time: %fs\n", stat.CPUTime()) 41 | // fmt.Printf("vsize: %dB\n", stat.VirtualMemory()) 42 | // fmt.Printf("rss: %dB\n", stat.ResidentMemory()) 43 | // } 44 | // 45 | package procfs 46 | -------------------------------------------------------------------------------- /vendor/github.com/google/skylark/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2017 The Bazel Authors. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are 5 | met: 6 | 7 | 1. Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the 13 | distribution. 14 | 15 | 3. Neither the name of the copyright holder nor the names of its 16 | contributors may be used to endorse or promote products derived 17 | from this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | -------------------------------------------------------------------------------- /pets_release.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # builds and zips pets binaries for macOS and Linux 4 | # should be run from .../go/.../windmilleng/pets 5 | 6 | # Requirements: 7 | # - gothub (https://github.com/itchio/gothub) 8 | # - valid github token in environ: $GITHUB_TOKEN="abcd..." 9 | 10 | if [[ -z "$(which gothub)" ]]; then 11 | echo "This script requires gothub (https://github.com/itchio/gothub)." 12 | echo "Install with: go get github.com/itchio/gothub" 13 | fi 14 | 15 | if [[ -z ${GITHUB_TOKEN} ]]; then 16 | echo "\$GITHUB_TOKEN not set, aborting." 17 | exit 1 18 | fi 19 | 20 | mkdir dist; cd dist 21 | 22 | # macOS bin 23 | echo "Building and zipping macOS binary..." 24 | env GOOS=darwin GOARCH=amd64 go build -v -o pets github.com/windmilleng/pets 25 | zip -m pets_macos_amd64.zip pets 26 | 27 | echo "Building and zipping Linux binary..." 28 | env GOOS=linux GOARCH=amd64 go build -v -o pets github.com/windmilleng/pets 29 | zip -m pets_linux_amd64.zip pets 30 | 31 | echo "Enter tag for new release: " 32 | read TAG 33 | 34 | echo "Enter description for new release (leave blank to just use tag): " 35 | read DESC 36 | 37 | if [[ -z ${DESC} ]]; then 38 | DESC=${TAG} 39 | fi 40 | 41 | echo "Pushing release to GitHub..." 42 | gothub release --user windmilleng --repo pets --tag ${TAG} --description ${DESC} 43 | gothub upload --user windmilleng --repo pets --tag ${TAG} --name pets_linux_amd64.zip --file pets_linux_amd64.zip 44 | gothub upload --user windmilleng --repo pets --tag ${TAG} --name pets_macos_amd64.zip --file pets_macos_amd64.zip 45 | 46 | echo "Verify your release at: https://github.com/windmilleng/pets/releases/latest" 47 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012 Alex Ogier. All rights reserved. 2 | Copyright (c) 2012 The Go Authors. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are 6 | met: 7 | 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above 11 | copyright notice, this list of conditions and the following disclaimer 12 | in the documentation and/or other materials provided with the 13 | distribution. 14 | * Neither the name of Google Inc. nor the names of its 15 | contributors may be used to endorse or promote products derived from 16 | this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/common/expfmt/expfmt.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Prometheus Authors 2 | // Licensed under the Apache License, Version 2.0 (the "License"); 3 | // you may not use this file except in compliance with the License. 4 | // You may obtain a copy of the License at 5 | // 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | 14 | // Package expfmt contains tools for reading and writing Prometheus metrics. 15 | package expfmt 16 | 17 | // Format specifies the HTTP content type of the different wire protocols. 18 | type Format string 19 | 20 | // Constants to assemble the Content-Type values for the different wire protocols. 21 | const ( 22 | TextVersion = "0.0.4" 23 | ProtoType = `application/vnd.google.protobuf` 24 | ProtoProtocol = `io.prometheus.client.MetricFamily` 25 | ProtoFmt = ProtoType + "; proto=" + ProtoProtocol + ";" 26 | 27 | // The Content-Type values for the different wire protocols. 28 | FmtUnknown Format = `` 29 | FmtText Format = `text/plain; version=` + TextVersion + `; charset=utf-8` 30 | FmtProtoDelim Format = ProtoFmt + ` encoding=delimited` 31 | FmtProtoText Format = ProtoFmt + ` encoding=text` 32 | FmtProtoCompact Format = ProtoFmt + ` encoding=compact-text` 33 | ) 34 | 35 | const ( 36 | hdrContentType = "Content-Type" 37 | hdrAccept = "Accept" 38 | ) 39 | -------------------------------------------------------------------------------- /vendor/github.com/windmilleng/wmclient/pkg/analytics/cli.go: -------------------------------------------------------------------------------- 1 | package analytics 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | "path/filepath" 7 | 8 | "github.com/spf13/cobra" 9 | 10 | "github.com/windmilleng/wmclient/pkg/dirs" 11 | ) 12 | 13 | func analyticsStatus(_ *cobra.Command, args []string) error { 14 | choice, err := OptStatus() 15 | if err != nil { 16 | return err 17 | } 18 | 19 | fmt.Printf("analytics status: %s\n", choice) 20 | 21 | return nil 22 | } 23 | 24 | func analyticsOpt(_ *cobra.Command, args []string) (outerErr error) { 25 | defer func() { 26 | if outerErr == nil { 27 | return 28 | } 29 | fmt.Printf("choice can be one of {%s, %s}\n", OptIn, OptOut) 30 | }() 31 | if len(args) == 0 { 32 | fmt.Printf("choice can be one of {%s, %s}\n", OptIn, OptOut) 33 | return fmt.Errorf("no choice given; pass it as first arg: analytics opt ") 34 | } 35 | choiceStr := args[0] 36 | err := SetOptStr(choiceStr) 37 | if err != nil { 38 | return err 39 | } 40 | d, err := dirs.UseWindmillDir() 41 | if err != nil { 42 | return err 43 | } 44 | fmt.Fprintf(os.Stderr, "wrote user collection strategy %q to file %v\n", choiceStr, filepath.Join(d.Root(), choiceFile)) 45 | return nil 46 | } 47 | 48 | const choiceFile = "analytics/user/choice.txt" 49 | 50 | func initCLI() (*cobra.Command, error) { 51 | analytics := &cobra.Command{ 52 | Use: "analytics", 53 | Short: "info and status about windmill analytics", 54 | RunE: analyticsStatus, 55 | } 56 | 57 | opt := &cobra.Command{ 58 | Use: "opt", 59 | Short: "opt-in or -out to windmill analytics collection/upload", 60 | RunE: analyticsOpt, 61 | } 62 | analytics.AddCommand(opt) 63 | 64 | return analytics, nil 65 | } 66 | -------------------------------------------------------------------------------- /vendor/github.com/golang/protobuf/LICENSE: -------------------------------------------------------------------------------- 1 | Go support for Protocol Buffers - Google's data interchange format 2 | 3 | Copyright 2010 The Go Authors. All rights reserved. 4 | https://github.com/golang/protobuf 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are 8 | met: 9 | 10 | * Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above 13 | copyright notice, this list of conditions and the following disclaimer 14 | in the documentation and/or other materials provided with the 15 | distribution. 16 | * Neither the name of Google Inc. nor the names of its 17 | contributors may be used to endorse or promote products derived from 18 | this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | -------------------------------------------------------------------------------- /vendor/github.com/matttproud/golang_protobuf_extensions/pbutil/encode.go: -------------------------------------------------------------------------------- 1 | // Copyright 2013 Matt T. Proud 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package pbutil 16 | 17 | import ( 18 | "encoding/binary" 19 | "io" 20 | 21 | "github.com/golang/protobuf/proto" 22 | ) 23 | 24 | // WriteDelimited encodes and dumps a message to the provided writer prefixed 25 | // with a 32-bit varint indicating the length of the encoded message, producing 26 | // a length-delimited record stream, which can be used to chain together 27 | // encoded messages of the same type together in a file. It returns the total 28 | // number of bytes written and any applicable error. This is roughly 29 | // equivalent to the companion Java API's MessageLite#writeDelimitedTo. 30 | func WriteDelimited(w io.Writer, m proto.Message) (n int, err error) { 31 | buffer, err := proto.Marshal(m) 32 | if err != nil { 33 | return 0, err 34 | } 35 | 36 | var buf [binary.MaxVarintLen32]byte 37 | encodedLength := binary.PutUvarint(buf[:], uint64(len(buffer))) 38 | 39 | sync, err := w.Write(buf[:encodedLength]) 40 | if err != nil { 41 | return sync, err 42 | } 43 | 44 | n, err = w.Write(buffer) 45 | return n + sync, err 46 | } 47 | -------------------------------------------------------------------------------- /vendor/github.com/heptiolabs/healthcheck/timeout.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 by the contributors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package healthcheck 16 | 17 | import ( 18 | "fmt" 19 | "time" 20 | ) 21 | 22 | // TimeoutError is the error returned when a Timeout-wrapped Check takes too long 23 | type timeoutError time.Duration 24 | 25 | func (e timeoutError) Error() string { 26 | return fmt.Sprintf("timed out after %s", time.Duration(e).String()) 27 | } 28 | 29 | // Timeout returns whether this error is a timeout (always true for timeoutError) 30 | func (e timeoutError) Timeout() bool { 31 | return true 32 | } 33 | 34 | // Temporary returns whether this error is temporary (always true for timeoutError) 35 | func (e timeoutError) Temporary() bool { 36 | return true 37 | } 38 | 39 | // Timeout adds a timeout to a Check. If the underlying check takes longer than 40 | // the timeout, it returns an error. 41 | func Timeout(check Check, timeout time.Duration) Check { 42 | return func() error { 43 | c := make(chan error, 1) 44 | go func() { c <- check() }() 45 | select { 46 | case err := <-c: 47 | return err 48 | case <-time.After(timeout): 49 | return timeoutError(timeout) 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /internal/service/service.go: -------------------------------------------------------------------------------- 1 | // Data structures for identifying services (processes with network host/port) 2 | package service 3 | 4 | import ( 5 | "fmt" 6 | "regexp" 7 | ) 8 | 9 | // A name for the service, e.g., "my-frontend". 10 | // 11 | // In a 'pets up', only one service of each name is allowed. 12 | type Name string 13 | 14 | // A tier for the service, e.g., "local", "prod", "staging" 15 | // 16 | // Kubernetes models this with a much more free-form "add arbitrary tags that 17 | // you can select services on". This is deliberately more limited. 18 | // 19 | type Tier string 20 | 21 | // The primary key for a particular way of running a service (e.g., "my-frontend 22 | // running on local") 23 | // 24 | // Only one provider of each Key=(Name, Tier) tuple is allowed in a Petsfile 25 | // and all the Petsfiles it loads. 26 | type Key struct { 27 | Name `json:",omitempty"` 28 | Tier `json:",omitempty"` 29 | } 30 | 31 | func NewKey(name Name, tier Tier) Key { 32 | return Key{Name: name, Tier: tier} 33 | } 34 | 35 | var validNameMatcher = regexp.MustCompile("^[a-zA-Z_-][a-zA-Z0-9_-]*$") 36 | var validTierMatcher = validNameMatcher 37 | 38 | func (n Name) Validate() error { 39 | if !validNameMatcher.MatchString(string(n)) { 40 | return fmt.Errorf("Invalid service name %q. Service names must match regexp %q", n, validNameMatcher) 41 | } 42 | return nil 43 | } 44 | 45 | func (t Tier) Validate() error { 46 | if !validTierMatcher.MatchString(string(t)) { 47 | return fmt.Errorf("Invalid service tier %q. Service names must match regexp %q", t, validTierMatcher) 48 | } 49 | return nil 50 | } 51 | 52 | func (k Key) Validate() error { 53 | err := k.Name.Validate() 54 | if err != nil { 55 | return err 56 | } 57 | return k.Tier.Validate() 58 | } 59 | 60 | func (k Key) String() string { 61 | return fmt.Sprintf("%s-%s", k.Name, k.Tier) 62 | } 63 | -------------------------------------------------------------------------------- /internal/health/health.go: -------------------------------------------------------------------------------- 1 | package health 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | "os" 7 | "syscall" 8 | "time" 9 | 10 | "github.com/heptiolabs/healthcheck" 11 | "github.com/windmilleng/pets/internal/proc" 12 | ) 13 | 14 | // The go stdlib returns this error if we try to signal 15 | // a process that's still being set up. 16 | const processStartingErr = "no data yet" 17 | 18 | func ProcessAliveCheck(pid int) healthcheck.Check { 19 | return func() error { 20 | process, err := os.FindProcess(pid) 21 | if err != nil { 22 | return err 23 | } 24 | 25 | // 0 is a POSIX trick to ask the OS if it knows about the process 26 | return process.Signal(syscall.Signal(0)) 27 | } 28 | } 29 | 30 | // Perform the health check until: 31 | // 1) the process dies, or 32 | // 2) the tcp health check passes 33 | func WaitForTCP(process proc.PetsProc, interval time.Duration) error { 34 | ctx, cancel := context.WithCancel(context.Background()) 35 | 36 | // The healthchecks start background goroutines. Cancel them all 37 | // when we're done waiting. 38 | defer cancel() 39 | 40 | pid := process.Pid 41 | host := process.Host() 42 | processAliveCheck := healthcheck.AsyncWithContext( 43 | ctx, ProcessAliveCheck(pid), interval) 44 | tcpHealthCheck := healthcheck.AsyncWithContext( 45 | ctx, healthcheck.TCPDialCheck(host, interval), interval) 46 | for true { 47 | err := processAliveCheck() 48 | if err != nil { 49 | // if the process is still starting, that's fine. Try again later. 50 | if err.Error() == processStartingErr { 51 | time.Sleep(10 * time.Millisecond) 52 | continue 53 | } 54 | 55 | return fmt.Errorf("Process died without opening a network connection") 56 | } 57 | 58 | err = tcpHealthCheck() 59 | if err == nil { 60 | // The process is alive and it passed the TCP check! 61 | return nil 62 | } 63 | 64 | // Otherwise, sleep and try again later. 65 | time.Sleep(interval) 66 | } 67 | return nil 68 | } 69 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/procfs/proc_io.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Prometheus Authors 2 | // Licensed under the Apache License, Version 2.0 (the "License"); 3 | // you may not use this file except in compliance with the License. 4 | // You may obtain a copy of the License at 5 | // 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | 14 | package procfs 15 | 16 | import ( 17 | "fmt" 18 | "io/ioutil" 19 | "os" 20 | ) 21 | 22 | // ProcIO models the content of /proc//io. 23 | type ProcIO struct { 24 | // Chars read. 25 | RChar uint64 26 | // Chars written. 27 | WChar uint64 28 | // Read syscalls. 29 | SyscR uint64 30 | // Write syscalls. 31 | SyscW uint64 32 | // Bytes read. 33 | ReadBytes uint64 34 | // Bytes written. 35 | WriteBytes uint64 36 | // Bytes written, but taking into account truncation. See 37 | // Documentation/filesystems/proc.txt in the kernel sources for 38 | // detailed explanation. 39 | CancelledWriteBytes int64 40 | } 41 | 42 | // NewIO creates a new ProcIO instance from a given Proc instance. 43 | func (p Proc) NewIO() (ProcIO, error) { 44 | pio := ProcIO{} 45 | 46 | f, err := os.Open(p.path("io")) 47 | if err != nil { 48 | return pio, err 49 | } 50 | defer f.Close() 51 | 52 | data, err := ioutil.ReadAll(f) 53 | if err != nil { 54 | return pio, err 55 | } 56 | 57 | ioFormat := "rchar: %d\nwchar: %d\nsyscr: %d\nsyscw: %d\n" + 58 | "read_bytes: %d\nwrite_bytes: %d\n" + 59 | "cancelled_write_bytes: %d\n" 60 | 61 | _, err = fmt.Sscanf(string(data), ioFormat, &pio.RChar, &pio.WChar, &pio.SyscR, 62 | &pio.SyscW, &pio.ReadBytes, &pio.WriteBytes, &pio.CancelledWriteBytes) 63 | 64 | return pio, err 65 | } 66 | -------------------------------------------------------------------------------- /cmd/pets/logs.go: -------------------------------------------------------------------------------- 1 | package pets 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | 7 | "github.com/spf13/cobra" 8 | "github.com/windmilleng/pets/internal/proc" 9 | "github.com/windmilleng/pets/internal/service" 10 | ) 11 | 12 | var LogsCmd = &cobra.Command{ 13 | Use: "logs", 14 | Short: "Get logs for running servers", 15 | Example: `pets logs 16 | pets logs frontend`, 17 | } 18 | 19 | func runLogsCmd(cmd *cobra.Command, args []string) { 20 | if len(args) > 1 { 21 | LogsCmd.Usage() 22 | 23 | fmt.Printf("\nToo many arguments: %+v\n", args) 24 | os.Exit(1) 25 | } 26 | 27 | procfs, err := proc.NewProcFS() 28 | if err != nil { 29 | fatal(err) 30 | } 31 | 32 | procs, err := procfs.ProcsFromFS() 33 | if err != nil { 34 | fatal(err) 35 | } 36 | 37 | // Right now, this only gets logs from running services. What about logs 38 | // from dead services? 39 | name := service.Name("") 40 | if len(args) == 1 { 41 | name = service.Name(args[0]) 42 | } 43 | 44 | printed := false 45 | for _, p := range procs { 46 | if p.ServiceName == "" { 47 | continue 48 | } 49 | 50 | // If the user specified a particular service, skip any services that don't match. 51 | if name != "" && p.ServiceName != name { 52 | continue 53 | } 54 | 55 | contents, err := procfs.ReadLogFile(p.ServiceKey()) 56 | if err != nil { 57 | fatal(err) 58 | } 59 | 60 | if name == "" { 61 | // If the user is printing logs for multiple services, print a header. 62 | if printed { 63 | fmt.Println("") 64 | } 65 | fmt.Printf(`-------------------------- 66 | PETS logs: %s-%s 67 | -------------------------- 68 | `, p.ServiceName, p.ServiceTier) 69 | } 70 | 71 | fmt.Print(contents) 72 | printed = true 73 | } 74 | 75 | if !printed { 76 | if name == "" { 77 | fmt.Println("No running services") 78 | } else { 79 | fmt.Printf("No running services matching: %s\n", name) 80 | } 81 | } 82 | } 83 | 84 | func initLogsCmd() { 85 | LogsCmd.Run = runLogsCmd 86 | RootCmd.AddCommand(LogsCmd) 87 | } 88 | -------------------------------------------------------------------------------- /vendor/github.com/windmilleng/wmclient/pkg/analytics/opt.go: -------------------------------------------------------------------------------- 1 | package analytics 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | "strings" 7 | 8 | "github.com/windmilleng/wmclient/pkg/dirs" 9 | ) 10 | 11 | type Opt int 12 | 13 | const ( 14 | OptDefault Opt = iota 15 | OptOut 16 | OptIn 17 | ) 18 | 19 | var Choices = map[Opt]string{ 20 | OptDefault: "default", 21 | OptOut: "opt-out", 22 | OptIn: "opt-in", 23 | } 24 | 25 | func (o Opt) String() string { 26 | val, ok := Choices[o] 27 | if ok { 28 | return val 29 | } 30 | return fmt.Sprintf("opt[%d]", o) 31 | } 32 | 33 | func OptStatus() (Opt, error) { 34 | txt, err := readChoiceFile() 35 | if err != nil { 36 | return OptDefault, err 37 | } 38 | 39 | switch txt { 40 | case Choices[OptIn]: 41 | return OptIn, nil 42 | case Choices[OptOut]: 43 | return OptOut, nil 44 | } 45 | 46 | return OptDefault, nil 47 | } 48 | 49 | func SetOptStr(s string) error { 50 | choice := OptDefault 51 | for k, v := range Choices { 52 | if v == s { 53 | choice = k 54 | } 55 | // allow " analytics opt in" to work 56 | if v == "opt-"+s { 57 | choice = k 58 | } 59 | } 60 | 61 | return SetOpt(choice) 62 | } 63 | 64 | func SetOpt(c Opt) error { 65 | s := c.String() 66 | 67 | d, err := dirs.UseWindmillDir() 68 | if err != nil { 69 | return err 70 | } 71 | 72 | if err = d.WriteFile(choiceFile, s); err != nil { 73 | return err 74 | } 75 | 76 | return nil 77 | } 78 | 79 | func readChoiceFile() (string, error) { 80 | d, err := dirs.UseWindmillDir() 81 | if err != nil { 82 | return "", err 83 | } 84 | 85 | txt, err := d.ReadFile(choiceFile) 86 | if err != nil { 87 | if !os.IsNotExist(err) { 88 | return "", err 89 | } 90 | txt = "" 91 | } 92 | 93 | return strings.TrimSpace(txt), nil 94 | } 95 | 96 | func optedIn() bool { 97 | opt, err := OptStatus() 98 | if err != nil { 99 | fmt.Fprintf(os.Stderr, "analytics.optedIn: %v\n", err) 100 | } 101 | 102 | return opt == OptIn 103 | } 104 | -------------------------------------------------------------------------------- /vendor/github.com/heptiolabs/healthcheck/CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Community Code of Conduct 2 | 3 | ## Contributor Code of Conduct 4 | 5 | As contributors and maintainers of this project, and in the interest of fostering 6 | an open and welcoming community, we pledge to respect all people who contribute 7 | through reporting issues, posting feature requests, updating documentation, 8 | submitting pull requests or patches, and other activities. 9 | 10 | We are committed to making participation in this project a harassment-free experience for 11 | everyone, regardless of level of experience, gender, gender identity and expression, 12 | sexual orientation, disability, personal appearance, body size, race, ethnicity, age, 13 | religion, or nationality. 14 | 15 | Examples of unacceptable behavior by participants include: 16 | 17 | * The use of sexualized language or imagery 18 | * Personal attacks 19 | * Trolling or insulting/derogatory comments 20 | * Public or private harassment 21 | * Publishing other's private information, such as physical or electronic addresses, 22 | without explicit permission 23 | * Other unethical or unprofessional conduct. 24 | 25 | Project maintainers have the right and responsibility to remove, edit, or reject 26 | comments, commits, code, wiki edits, issues, and other contributions that are not 27 | aligned to this Code of Conduct. By adopting this Code of Conduct, project maintainers 28 | commit themselves to fairly and consistently applying these principles to every aspect 29 | of managing this project. Project maintainers who do not follow or enforce the Code of 30 | Conduct may be permanently removed from the project team. 31 | 32 | This code of conduct applies both within project spaces and in public spaces 33 | when an individual is representing the project or its community. 34 | 35 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project maintainer(s). 36 | 37 | This Code of Conduct is adapted from the [CNCF Code of Conduct](https://github.com/cncf/foundation/blob/master/code-of-conduct.md) and [Contributor Covenant](http://contributor-covenant.org/version/1/2/0/), version 1.2.0. 38 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/procfs/nfs/parse_nfs.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Prometheus Authors 2 | // Licensed under the Apache License, Version 2.0 (the "License"); 3 | // you may not use this file except in compliance with the License. 4 | // You may obtain a copy of the License at 5 | // 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | 14 | package nfs 15 | 16 | import ( 17 | "bufio" 18 | "fmt" 19 | "io" 20 | "strings" 21 | 22 | "github.com/prometheus/procfs/internal/util" 23 | ) 24 | 25 | // ParseClientRPCStats returns stats read from /proc/net/rpc/nfs 26 | func ParseClientRPCStats(r io.Reader) (*ClientRPCStats, error) { 27 | stats := &ClientRPCStats{} 28 | 29 | scanner := bufio.NewScanner(r) 30 | for scanner.Scan() { 31 | line := scanner.Text() 32 | parts := strings.Fields(scanner.Text()) 33 | // require at least 34 | if len(parts) < 2 { 35 | return nil, fmt.Errorf("invalid NFS metric line %q", line) 36 | } 37 | 38 | values, err := util.ParseUint64s(parts[1:]) 39 | if err != nil { 40 | return nil, fmt.Errorf("error parsing NFS metric line: %s", err) 41 | } 42 | 43 | switch metricLine := parts[0]; metricLine { 44 | case "net": 45 | stats.Network, err = parseNetwork(values) 46 | case "rpc": 47 | stats.ClientRPC, err = parseClientRPC(values) 48 | case "proc2": 49 | stats.V2Stats, err = parseV2Stats(values) 50 | case "proc3": 51 | stats.V3Stats, err = parseV3Stats(values) 52 | case "proc4": 53 | stats.ClientV4Stats, err = parseClientV4Stats(values) 54 | default: 55 | return nil, fmt.Errorf("unknown NFS metric line %q", metricLine) 56 | } 57 | if err != nil { 58 | return nil, fmt.Errorf("errors parsing NFS metric line: %s", err) 59 | } 60 | } 61 | 62 | if err := scanner.Err(); err != nil { 63 | return nil, fmt.Errorf("error scanning NFS file: %s", err) 64 | } 65 | 66 | return stats, nil 67 | } 68 | -------------------------------------------------------------------------------- /internal/loader/go.go: -------------------------------------------------------------------------------- 1 | package loader 2 | 3 | import ( 4 | "fmt" 5 | "go/build" 6 | "os" 7 | "os/exec" 8 | "path/filepath" 9 | ) 10 | 11 | // Loads a Go repo and returns an absolute directory path. 12 | // 13 | // The Go repo may or may not have a pets file. 14 | // 15 | // Callers can inject their own GOROOT/GOPATH. The default build.Context is build.Default. 16 | // https://golang.org/pkg/go/build/#Default 17 | // 18 | // TODO(nick): Long-term, we will need to have some way to give PETS more 19 | // control over which version of the repo loads. 20 | // 21 | // I personally think that the MVS (minimal version selection) approach is promising, 22 | // where each repo has a .petslock file that describes the minimum version of its 23 | // dependencies, and the user can specify later versions. 24 | // 25 | // Right now we do the dumbest possible thing of doing a 'go get', which will get 26 | // the repo if it doesn't exist and use the repo on disk if it does exist. 27 | func LoadGoRepo(importPath string, buildCtx build.Context) (string, error) { 28 | cmd := exec.Command("go", "get", importPath) 29 | 30 | env := append([]string{}, os.Environ()...) 31 | env = append(env, 32 | fmt.Sprintf("GOROOT=%s", buildCtx.GOROOT), 33 | fmt.Sprintf("GOPATH=%s", buildCtx.GOPATH)) 34 | cmd.Env = env 35 | 36 | err := cmd.Run() 37 | if err != nil { 38 | exitErr, isExit := err.(*exec.ExitError) 39 | if isExit { 40 | return "", fmt.Errorf("go get %q failed with output:\n%s\n", importPath, string(exitErr.Stderr)) 41 | } 42 | return "", fmt.Errorf("go get %q failed: %v", importPath, err) 43 | } 44 | 45 | // The build package doesn't expose an easy function for getting the absolute 46 | // path to the directory, so we have to do this ourselves. 47 | srcDirs := buildCtx.SrcDirs() 48 | foundDir := "" 49 | for _, srcDir := range srcDirs { 50 | importDir := filepath.Join(srcDir, importPath) 51 | info, err := os.Stat(importDir) 52 | if err != nil || !info.IsDir() { 53 | // Try the next candidate. 54 | continue 55 | } 56 | 57 | foundDir = importDir 58 | break 59 | } 60 | 61 | if foundDir == "" { 62 | return "", fmt.Errorf("LoadGoRepo(%q): package not found in %v", importPath, srcDirs) 63 | } 64 | return foundDir, nil 65 | } 66 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/procfs/proc_ns.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Prometheus Authors 2 | // Licensed under the Apache License, Version 2.0 (the "License"); 3 | // you may not use this file except in compliance with the License. 4 | // You may obtain a copy of the License at 5 | // 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | 14 | package procfs 15 | 16 | import ( 17 | "fmt" 18 | "os" 19 | "strconv" 20 | "strings" 21 | ) 22 | 23 | // Namespace represents a single namespace of a process. 24 | type Namespace struct { 25 | Type string // Namespace type. 26 | Inode uint32 // Inode number of the namespace. If two processes are in the same namespace their inodes will match. 27 | } 28 | 29 | // Namespaces contains all of the namespaces that the process is contained in. 30 | type Namespaces map[string]Namespace 31 | 32 | // NewNamespaces reads from /proc/[pid/ns/* to get the namespaces of which the 33 | // process is a member. 34 | func (p Proc) NewNamespaces() (Namespaces, error) { 35 | d, err := os.Open(p.path("ns")) 36 | if err != nil { 37 | return nil, err 38 | } 39 | defer d.Close() 40 | 41 | names, err := d.Readdirnames(-1) 42 | if err != nil { 43 | return nil, fmt.Errorf("failed to read contents of ns dir: %v", err) 44 | } 45 | 46 | ns := make(Namespaces, len(names)) 47 | for _, name := range names { 48 | target, err := os.Readlink(p.path("ns", name)) 49 | if err != nil { 50 | return nil, err 51 | } 52 | 53 | fields := strings.SplitN(target, ":", 2) 54 | if len(fields) != 2 { 55 | return nil, fmt.Errorf("failed to parse namespace type and inode from '%v'", target) 56 | } 57 | 58 | typ := fields[0] 59 | inode, err := strconv.ParseUint(strings.Trim(fields[1], "[]"), 10, 32) 60 | if err != nil { 61 | return nil, fmt.Errorf("failed to parse inode from '%v': %v", fields[1], err) 62 | } 63 | 64 | ns[name] = Namespace{typ, uint32(inode)} 65 | } 66 | 67 | return ns, nil 68 | } 69 | -------------------------------------------------------------------------------- /vendor/github.com/heptiolabs/healthcheck/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | ## DCO Sign off 2 | 3 | All authors to the project retain copyright to their work. However, to ensure 4 | that they are only submitting work that they have rights to, we are requiring 5 | everyone to acknowldge this by signing their work. 6 | 7 | Any copyright notices in this repos should specify the authors as "the contributors". 8 | 9 | To sign your work, just add a line like this at the end of your commit message: 10 | 11 | ``` 12 | Signed-off-by: Joe Beda 13 | ``` 14 | 15 | This can easily be done with the `--signoff` option to `git commit`. 16 | 17 | By doing this you state that you can certify the following (from https://developercertificate.org/): 18 | 19 | ``` 20 | Developer Certificate of Origin 21 | Version 1.1 22 | 23 | Copyright (C) 2004, 2006 The Linux Foundation and its contributors. 24 | 1 Letterman Drive 25 | Suite D4700 26 | San Francisco, CA, 94129 27 | 28 | Everyone is permitted to copy and distribute verbatim copies of this 29 | license document, but changing it is not allowed. 30 | 31 | 32 | Developer's Certificate of Origin 1.1 33 | 34 | By making a contribution to this project, I certify that: 35 | 36 | (a) The contribution was created in whole or in part by me and I 37 | have the right to submit it under the open source license 38 | indicated in the file; or 39 | 40 | (b) The contribution is based upon previous work that, to the best 41 | of my knowledge, is covered under an appropriate open source 42 | license and I have the right under that license to submit that 43 | work with modifications, whether created in whole or in part 44 | by me, under the same open source license (unless I am 45 | permitted to submit under a different license), as indicated 46 | in the file; or 47 | 48 | (c) The contribution was provided directly to me by some other 49 | person who certified (a), (b) or (c) and I have not modified 50 | it. 51 | 52 | (d) I understand and agree that this project and the contribution 53 | are public and that a record of the contribution (including all 54 | personal information I submit with it, including my sign-off) is 55 | maintained indefinitely and may be redistributed consistent with 56 | this project or the open source license(s) involved. 57 | ``` -------------------------------------------------------------------------------- /vendor/github.com/heptiolabs/healthcheck/types.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 by the contributors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package healthcheck 16 | 17 | import ( 18 | "net/http" 19 | ) 20 | 21 | // Check is a health/readiness check. 22 | type Check func() error 23 | 24 | // Handler is an http.Handler with additional methods that register health and 25 | // readiness checks. It handles handle "/live" and "/ready" HTTP 26 | // endpoints. 27 | type Handler interface { 28 | // The Handler is an http.Handler, so it can be exposed directly and handle 29 | // /live and /ready endpoints. 30 | http.Handler 31 | 32 | // AddLivenessCheck adds a check that indicates that this instance of the 33 | // application should be destroyed or restarted. A failed liveness check 34 | // indicates that this instance is unhealthy, not some upstream dependency. 35 | // Every liveness check is also included as a readiness check. 36 | AddLivenessCheck(name string, check Check) 37 | 38 | // AddReadinessCheck adds a check that indicates that this instance of the 39 | // application is currently unable to serve requests because of an upstream 40 | // or some transient failure. If a readiness check fails, this instance 41 | // should no longer receiver requests, but should not be restarted or 42 | // destroyed. 43 | AddReadinessCheck(name string, check Check) 44 | 45 | // LiveEndpoint is the HTTP handler for just the /live endpoint, which is 46 | // useful if you need to attach it into your own HTTP handler tree. 47 | LiveEndpoint(http.ResponseWriter, *http.Request) 48 | 49 | // ReadyEndpoint is the HTTP handler for just the /ready endpoint, which is 50 | // useful if you need to attach it into your own HTTP handler tree. 51 | ReadyEndpoint(http.ResponseWriter, *http.Request) 52 | } 53 | -------------------------------------------------------------------------------- /internal/proc/proc.go: -------------------------------------------------------------------------------- 1 | package proc 2 | 3 | import ( 4 | "fmt" 5 | "net" 6 | "os" 7 | "os/exec" 8 | "syscall" 9 | "time" 10 | 11 | "github.com/windmilleng/pets/internal/service" 12 | ) 13 | 14 | // Process state that we expect to be written to disk and queried. 15 | type PetsProc struct { 16 | // A name to show to humans 17 | DisplayName string `json:",omitempty"` 18 | 19 | // The process ID of a running process. 20 | Pid int `json:",omitempty"` 21 | 22 | // When the process started 23 | StartTime time.Time 24 | 25 | // The hostname that the process is listening on (e.g., 'localhost') 26 | Hostname string `json:",omitempty"` 27 | 28 | // The port that the process is listening on (e.g., '8080') 29 | Port int `json:",omitempty"` 30 | 31 | // The name+tier of the service that this process exposes 32 | ServiceName service.Name `json:",omitempty"` 33 | ServiceTier service.Tier `json:",omitempty"` 34 | } 35 | 36 | func (p PetsProc) Host() string { 37 | return net.JoinHostPort(p.Hostname, fmt.Sprintf("%d", p.Port)) 38 | } 39 | 40 | // Creates a new PetsProc that we know is listening on the given host and port. 41 | // 42 | // Calling this method automatically creates a copy because it's a struct method 43 | // rather than a pointer method. 44 | func (p PetsProc) WithExposedHost(hostname string, port int) PetsProc { 45 | p.Hostname = hostname 46 | p.Port = port 47 | return p 48 | } 49 | 50 | func (p PetsProc) TimeSince() time.Duration { 51 | return time.Since(p.StartTime) 52 | } 53 | 54 | // Creates a new PetsProc that matches a service key. 55 | // 56 | // Calling this method automatically creates a copy because it's a struct method 57 | // rather than a pointer method. 58 | func (p PetsProc) WithServiceKey(key service.Key) PetsProc { 59 | p.ServiceName = key.Name 60 | p.ServiceTier = key.Tier 61 | p.DisplayName = string(p.ServiceName) + "-" + string(p.ServiceTier) 62 | return p 63 | } 64 | 65 | func (p PetsProc) ServiceKey() service.Key { 66 | return service.NewKey(p.ServiceName, p.ServiceTier) 67 | } 68 | 69 | type PetsCommand struct { 70 | Proc PetsProc 71 | Cmd *exec.Cmd 72 | } 73 | 74 | // Checks if a process is still alive. 75 | func isAlive(pid int) bool { 76 | process, err := os.FindProcess(pid) 77 | if err != nil { 78 | return false 79 | } 80 | 81 | // 0 is a POSIX trick to ask the OS if it knows about the process 82 | err = process.Signal(syscall.Signal(0)) 83 | return err == nil 84 | } 85 | -------------------------------------------------------------------------------- /vendor/github.com/heptiolabs/healthcheck/Gopkg.lock: -------------------------------------------------------------------------------- 1 | # This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. 2 | 3 | 4 | [[projects]] 5 | branch = "master" 6 | name = "github.com/beorn7/perks" 7 | packages = ["quantile"] 8 | revision = "4c0e84591b9aa9e6dcfdf3e020114cd81f89d5f9" 9 | 10 | [[projects]] 11 | name = "github.com/davecgh/go-spew" 12 | packages = ["spew"] 13 | revision = "346938d642f2ec3594ed81d874461961cd0faa76" 14 | version = "v1.1.0" 15 | 16 | [[projects]] 17 | branch = "master" 18 | name = "github.com/golang/protobuf" 19 | packages = ["proto"] 20 | revision = "1643683e1b54a9e88ad26d98f81400c8c9d9f4f9" 21 | 22 | [[projects]] 23 | name = "github.com/matttproud/golang_protobuf_extensions" 24 | packages = ["pbutil"] 25 | revision = "3247c84500bff8d9fb6d579d800f20b3e091582c" 26 | version = "v1.0.0" 27 | 28 | [[projects]] 29 | name = "github.com/pmezard/go-difflib" 30 | packages = ["difflib"] 31 | revision = "792786c7400a136282c1664665ae0a8db921c6c2" 32 | version = "v1.0.0" 33 | 34 | [[projects]] 35 | name = "github.com/prometheus/client_golang" 36 | packages = ["prometheus","prometheus/promhttp"] 37 | revision = "c5b7fccd204277076155f10851dad72b76a49317" 38 | version = "v0.8.0" 39 | 40 | [[projects]] 41 | branch = "master" 42 | name = "github.com/prometheus/client_model" 43 | packages = ["go"] 44 | revision = "6f3806018612930941127f2a7c6c453ba2c527d2" 45 | 46 | [[projects]] 47 | branch = "master" 48 | name = "github.com/prometheus/common" 49 | packages = ["expfmt","internal/bitbucket.org/ww/goautoneg","model"] 50 | revision = "1bab55dd05dbff384524a6a1c99006d9eb5f139b" 51 | 52 | [[projects]] 53 | branch = "master" 54 | name = "github.com/prometheus/procfs" 55 | packages = [".","xfs"] 56 | revision = "a6e9df898b1336106c743392c48ee0b71f5c4efa" 57 | 58 | [[projects]] 59 | name = "github.com/stretchr/testify" 60 | packages = ["assert"] 61 | revision = "69483b4bd14f5845b5a1e55bca19e954e827f1d0" 62 | version = "v1.1.4" 63 | 64 | [[projects]] 65 | name = "gopkg.in/DATA-DOG/go-sqlmock.v1" 66 | packages = ["."] 67 | revision = "d76b18b42f285b792bf985118980ce9eacea9d10" 68 | version = "v1.3.0" 69 | 70 | [solve-meta] 71 | analyzer-name = "dep" 72 | analyzer-version = 1 73 | inputs-digest = "044076023b3d86dbc55581284b8dceffad716fc8800f4f013d94173d9c11cedb" 74 | solver-name = "gps-cdcl" 75 | solver-version = 1 76 | -------------------------------------------------------------------------------- /vendor/github.com/heptiolabs/healthcheck/metrics_handler.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 by the contributors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package healthcheck 16 | 17 | import ( 18 | "net/http" 19 | 20 | "github.com/prometheus/client_golang/prometheus" 21 | ) 22 | 23 | type metricsHandler struct { 24 | handler Handler 25 | registry prometheus.Registerer 26 | namespace string 27 | } 28 | 29 | // NewMetricsHandler returns a healthcheck Handler that also exposes metrics 30 | // into the provided Prometheus registry. 31 | func NewMetricsHandler(registry prometheus.Registerer, namespace string) Handler { 32 | return &metricsHandler{ 33 | handler: NewHandler(), 34 | registry: registry, 35 | namespace: namespace, 36 | } 37 | } 38 | 39 | func (h *metricsHandler) AddLivenessCheck(name string, check Check) { 40 | h.handler.AddLivenessCheck(name, h.wrap(name, check)) 41 | } 42 | 43 | func (h *metricsHandler) AddReadinessCheck(name string, check Check) { 44 | h.handler.AddReadinessCheck(name, h.wrap(name, check)) 45 | } 46 | 47 | func (h *metricsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { 48 | h.handler.ServeHTTP(w, r) 49 | } 50 | 51 | func (h *metricsHandler) LiveEndpoint(w http.ResponseWriter, r *http.Request) { 52 | h.handler.LiveEndpoint(w, r) 53 | } 54 | 55 | func (h *metricsHandler) ReadyEndpoint(w http.ResponseWriter, r *http.Request) { 56 | h.handler.ReadyEndpoint(w, r) 57 | } 58 | 59 | func (h *metricsHandler) wrap(name string, check Check) Check { 60 | h.registry.MustRegister(prometheus.NewGaugeFunc( 61 | prometheus.GaugeOpts{ 62 | Namespace: h.namespace, 63 | Subsystem: "healthcheck", 64 | Name: "status", 65 | Help: "Current check status (0 indicates success, 1 indicates failure)", 66 | ConstLabels: prometheus.Labels{"check": name}, 67 | }, 68 | func() float64 { 69 | if check() == nil { 70 | return 0 71 | } 72 | return 1 73 | }, 74 | )) 75 | return check 76 | } 77 | -------------------------------------------------------------------------------- /cmd/pets/up.go: -------------------------------------------------------------------------------- 1 | package pets 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | "strings" 7 | "time" 8 | 9 | "github.com/spf13/cobra" 10 | "github.com/windmilleng/pets/internal/mill" 11 | "github.com/windmilleng/pets/internal/service" 12 | ) 13 | 14 | var upTier string 15 | var upOverrides []string 16 | 17 | var UpCmd = &cobra.Command{ 18 | Use: "up", 19 | Short: "Start servers specified in the Petsfile", 20 | Long: `Start servers specified in the Petsfile. 21 | 22 | To start all servers with tier "local", run: 'pets up' 23 | 24 | To start all servers on a different provider tier (for example, k8s), run: 'pets up --tier=k8s' 25 | 26 | To start a single server and all its dependencies, run: 'pets up my-server'. 27 | `, 28 | Example: `pets up 29 | pets up frontend 30 | pets up frontend --tier=k8s`, 31 | } 32 | 33 | func runUpCmd(cmd *cobra.Command, args []string) { 34 | if len(args) > 1 { 35 | UpCmd.Usage() 36 | 37 | fmt.Printf("\nToo many arguments: %+v\n", args) 38 | os.Exit(1) 39 | } 40 | 41 | overrideMap := make(map[service.Name]service.Tier) 42 | for _, override := range upOverrides { 43 | parts := strings.Split(override, "=") 44 | if len(parts) != 2 { 45 | fmt.Printf("--with flag should have format 'service=tier'. Actual value: %s\n", override) 46 | os.Exit(1) 47 | } 48 | 49 | overrideMap[service.Name(parts[0])] = service.Tier(parts[1]) 50 | } 51 | 52 | analyticsService.Incr("cmd.up", nil) 53 | defer analyticsService.Flush(time.Second) 54 | 55 | file := mill.GetFilePath() 56 | petsitter, err := newPetsitter() 57 | if err != nil { 58 | fatal(err) 59 | } 60 | 61 | err = petsitter.ExecFile(file) 62 | if err != nil { 63 | fatal(err) 64 | } 65 | 66 | school := petsitter.School 67 | 68 | for name, tier := range overrideMap { 69 | err = school.AddOverride(name, tier) 70 | if err != nil { 71 | fatal(err) 72 | } 73 | } 74 | 75 | if len(args) == 1 { 76 | _, err = school.UpByKey(service.Key{ 77 | Name: service.Name(args[0]), 78 | Tier: service.Tier(upTier), 79 | }) 80 | if err != nil { 81 | fatal(err) 82 | } 83 | } else { 84 | _, err = school.UpByTier(service.Tier(upTier)) 85 | if err != nil { 86 | fatal(err) 87 | } 88 | } 89 | } 90 | 91 | func initUpCmd() { 92 | RootCmd.AddCommand(UpCmd) 93 | UpCmd.Run = runUpCmd 94 | UpCmd.Flags().StringVar(&upTier, "tier", "local", "The tier of servers to start up. Defaults to 'local'") 95 | UpCmd.Flags().StringSliceVar(&upOverrides, "with", nil, "Override servers in the server graph. Example: --with=backend=k8s") 96 | } 97 | -------------------------------------------------------------------------------- /internal/proc/run.go: -------------------------------------------------------------------------------- 1 | package proc 2 | 3 | import ( 4 | "fmt" 5 | "io" 6 | "os" 7 | "os/exec" 8 | "syscall" 9 | "time" 10 | 11 | "github.com/windmilleng/pets/internal/service" 12 | ) 13 | 14 | type Runner struct { 15 | fs ProcFS 16 | } 17 | 18 | func NewRunner(fs ProcFS) Runner { 19 | return Runner{ 20 | fs: fs, 21 | } 22 | } 23 | 24 | // Run a command, waiting until it exits. 25 | // 26 | // args: The command to run. 27 | // cwd: The current working directory. 28 | func (r Runner) Run(args []string, cwd string) error { 29 | return r.RunWithIO(args, cwd, os.Stdout, os.Stderr) 30 | } 31 | 32 | // Run a command, waiting until it exits, forwarding all stdout/stderr to the given streams. 33 | func (r Runner) RunWithIO(args []string, cwd string, stdout, stderr io.Writer) error { 34 | pCmd, err := r.StartWithIO(args, cwd, stdout, stderr) 35 | if err != nil { 36 | return fmt.Errorf("Run: %v", err) 37 | } 38 | err = pCmd.Cmd.Wait() 39 | r.fs.RemoveProc(pCmd.Proc) 40 | return err 41 | } 42 | 43 | func (r Runner) StartWithStdLogs(args []string, cwd string, key service.Key) (PetsCommand, error) { 44 | writer, err := r.fs.OpenFreshLogFile(key) 45 | if err != nil { 46 | return PetsCommand{}, fmt.Errorf("StartWithStdLogs: %v", err) 47 | } 48 | 49 | return r.StartWithIO(args, cwd, writer, writer) 50 | } 51 | 52 | // Starts a command, waiting until it exits, forwarding all stdout/stderr to the given streams. 53 | func (r Runner) StartWithIO(args []string, cwd string, stdout, stderr io.Writer) (PetsCommand, error) { 54 | if len(args) == 0 { 55 | return PetsCommand{}, fmt.Errorf("Empty args: %v", args) 56 | } 57 | 58 | cmd := exec.Command(args[0], args[1:]...) 59 | 60 | // Sets the process group ID so that if this process spawns sub-processes, 61 | // we can kill them later. 62 | cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true} 63 | 64 | cmd.Dir = cwd 65 | cmd.Stdout = stdout 66 | cmd.Stderr = stderr 67 | 68 | return r.startCmd(cmd, args[0]) 69 | } 70 | 71 | // Start a command, and return information about its running state. 72 | func (r Runner) startCmd(cmd *exec.Cmd, displayName string) (PetsCommand, error) { 73 | err := cmd.Start() 74 | if err != nil { 75 | return PetsCommand{}, err 76 | } 77 | 78 | process := cmd.Process 79 | proc := PetsProc{ 80 | Pid: process.Pid, 81 | DisplayName: displayName, 82 | StartTime: time.Now(), 83 | } 84 | err = r.fs.AddProc(proc) 85 | if err != nil { 86 | return PetsCommand{}, err 87 | } 88 | return PetsCommand{ 89 | Proc: proc, 90 | Cmd: cmd, 91 | }, nil 92 | } 93 | -------------------------------------------------------------------------------- /cmd/pets/cmd.go: -------------------------------------------------------------------------------- 1 | package pets 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | 7 | "github.com/google/skylark" 8 | "github.com/spf13/cobra" 9 | "github.com/windmilleng/wmclient/pkg/analytics" 10 | ) 11 | 12 | const petsAppName = "pets" 13 | 14 | var analyticsService analytics.Analytics 15 | 16 | var dryRun bool 17 | 18 | func init() { 19 | RootCmd.PersistentFlags().BoolVarP(&dryRun, "dry-run", "d", false, "just print recommended commands, don't run them") 20 | RootCmd.AddCommand(ListCmd) 21 | RootCmd.AddCommand(DownCmd) 22 | initLogsCmd() 23 | initUpCmd() 24 | } 25 | 26 | func Execute() error { 27 | var analyticsCmd *cobra.Command 28 | var err error 29 | 30 | analyticsService, analyticsCmd, err = analytics.Init(petsAppName) 31 | if err != nil { 32 | return err 33 | } 34 | 35 | status, err := analytics.OptStatus() 36 | if err != nil { 37 | return err 38 | } 39 | 40 | if status == analytics.OptDefault { 41 | fmt.Fprintf(os.Stderr, "Send anonymized usage data to Windmill [y/n]? ") 42 | 43 | var response string 44 | fmt.Scanln(&response) 45 | if response == "" || response[0] == 'y' || response[0] == 'Y' { 46 | analytics.SetOpt(analytics.OptIn) 47 | fmt.Fprintln(os.Stderr, "Thanks! Setting 'pets analytics opt in'") 48 | } else { 49 | analytics.SetOpt(analytics.OptOut) 50 | fmt.Fprintln(os.Stderr, "Thanks! Setting 'pets analytics opt out'") 51 | } 52 | 53 | fmt.Fprintln(os.Stderr, "You set can update your privacy preferences later with 'pets analytics'") 54 | } 55 | 56 | RootCmd.AddCommand(analyticsCmd) 57 | 58 | // NOTE(nick): uncomment this code to generate markdown usage 59 | //doc.GenMarkdownTree(RootCmd, "./docs") 60 | 61 | return RootCmd.Execute() 62 | } 63 | 64 | var RootCmd = &cobra.Command{ 65 | Use: "pets [arguments]", 66 | Short: "PETS makes it easy to manage lots of servers running on your machine that you want to keep a close eye on for local development.", 67 | Long: `A PETS file is like a Makefile for running servers and connecting them 68 | to other servers. With PETS, we can switch back and forth quickly 69 | between servers running locally and servers running in the cloud.`, 70 | Run: pets, 71 | } 72 | 73 | func pets(cmd *cobra.Command, args []string) { 74 | if dryRun { 75 | fmt.Fprintln(os.Stderr, "pets dry-run") 76 | } else { 77 | fmt.Fprintln(os.Stderr, "You ran pets!") 78 | } 79 | } 80 | 81 | func fatal(err error) { 82 | evalErr, isEvalErr := err.(*skylark.EvalError) 83 | if isEvalErr { 84 | fmt.Println(evalErr.Backtrace()) 85 | } else { 86 | fmt.Println(err) 87 | } 88 | os.Exit(1) 89 | } 90 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/common/internal/bitbucket.org/ww/goautoneg/README.txt: -------------------------------------------------------------------------------- 1 | PACKAGE 2 | 3 | package goautoneg 4 | import "bitbucket.org/ww/goautoneg" 5 | 6 | HTTP Content-Type Autonegotiation. 7 | 8 | The functions in this package implement the behaviour specified in 9 | http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html 10 | 11 | Copyright (c) 2011, Open Knowledge Foundation Ltd. 12 | All rights reserved. 13 | 14 | Redistribution and use in source and binary forms, with or without 15 | modification, are permitted provided that the following conditions are 16 | met: 17 | 18 | Redistributions of source code must retain the above copyright 19 | notice, this list of conditions and the following disclaimer. 20 | 21 | Redistributions in binary form must reproduce the above copyright 22 | notice, this list of conditions and the following disclaimer in 23 | the documentation and/or other materials provided with the 24 | distribution. 25 | 26 | Neither the name of the Open Knowledge Foundation Ltd. nor the 27 | names of its contributors may be used to endorse or promote 28 | products derived from this software without specific prior written 29 | permission. 30 | 31 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 32 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 33 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 34 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 35 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 36 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 37 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 38 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 39 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 40 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 41 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 42 | 43 | 44 | FUNCTIONS 45 | 46 | func Negotiate(header string, alternatives []string) (content_type string) 47 | Negotiate the most appropriate content_type given the accept header 48 | and a list of alternatives. 49 | 50 | func ParseAccept(header string) (accept []Accept) 51 | Parse an Accept Header string returning a sorted list 52 | of clauses 53 | 54 | 55 | TYPES 56 | 57 | type Accept struct { 58 | Type, SubType string 59 | Q float32 60 | Params map[string]string 61 | } 62 | Structure to represent a clause in an HTTP Accept Header 63 | 64 | 65 | SUBDIRECTORIES 66 | 67 | .hg 68 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/procfs/fs.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Prometheus Authors 2 | // Licensed under the Apache License, Version 2.0 (the "License"); 3 | // you may not use this file except in compliance with the License. 4 | // You may obtain a copy of the License at 5 | // 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | 14 | package procfs 15 | 16 | import ( 17 | "fmt" 18 | "os" 19 | "path" 20 | 21 | "github.com/prometheus/procfs/nfs" 22 | "github.com/prometheus/procfs/xfs" 23 | ) 24 | 25 | // FS represents the pseudo-filesystem proc, which provides an interface to 26 | // kernel data structures. 27 | type FS string 28 | 29 | // DefaultMountPoint is the common mount point of the proc filesystem. 30 | const DefaultMountPoint = "/proc" 31 | 32 | // NewFS returns a new FS mounted under the given mountPoint. It will error 33 | // if the mount point can't be read. 34 | func NewFS(mountPoint string) (FS, error) { 35 | info, err := os.Stat(mountPoint) 36 | if err != nil { 37 | return "", fmt.Errorf("could not read %s: %s", mountPoint, err) 38 | } 39 | if !info.IsDir() { 40 | return "", fmt.Errorf("mount point %s is not a directory", mountPoint) 41 | } 42 | 43 | return FS(mountPoint), nil 44 | } 45 | 46 | // Path returns the path of the given subsystem relative to the procfs root. 47 | func (fs FS) Path(p ...string) string { 48 | return path.Join(append([]string{string(fs)}, p...)...) 49 | } 50 | 51 | // XFSStats retrieves XFS filesystem runtime statistics. 52 | func (fs FS) XFSStats() (*xfs.Stats, error) { 53 | f, err := os.Open(fs.Path("fs/xfs/stat")) 54 | if err != nil { 55 | return nil, err 56 | } 57 | defer f.Close() 58 | 59 | return xfs.ParseStats(f) 60 | } 61 | 62 | // NFSClientRPCStats retrieves NFS client RPC statistics. 63 | func (fs FS) NFSClientRPCStats() (*nfs.ClientRPCStats, error) { 64 | f, err := os.Open(fs.Path("net/rpc/nfs")) 65 | if err != nil { 66 | return nil, err 67 | } 68 | defer f.Close() 69 | 70 | return nfs.ParseClientRPCStats(f) 71 | } 72 | 73 | // NFSdServerRPCStats retrieves NFS daemon RPC statistics. 74 | func (fs FS) NFSdServerRPCStats() (*nfs.ServerRPCStats, error) { 75 | f, err := os.Open(fs.Path("net/rpc/nfsd")) 76 | if err != nil { 77 | return nil, err 78 | } 79 | defer f.Close() 80 | 81 | return nfs.ParseServerRPCStats(f) 82 | } 83 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/procfs/Makefile: -------------------------------------------------------------------------------- 1 | # Copyright 2018 The Prometheus Authors 2 | # Licensed under the Apache License, Version 2.0 (the "License"); 3 | # you may not use this file except in compliance with the License. 4 | # You may obtain a copy of the License at 5 | # 6 | # http://www.apache.org/licenses/LICENSE-2.0 7 | # 8 | # Unless required by applicable law or agreed to in writing, software 9 | # distributed under the License is distributed on an "AS IS" BASIS, 10 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | # See the License for the specific language governing permissions and 12 | # limitations under the License. 13 | 14 | # Ensure GOBIN is not set during build so that promu is installed to the correct path 15 | unexport GOBIN 16 | 17 | GO ?= go 18 | GOFMT ?= $(GO)fmt 19 | FIRST_GOPATH := $(firstword $(subst :, ,$(shell $(GO) env GOPATH))) 20 | STATICCHECK := $(FIRST_GOPATH)/bin/staticcheck 21 | pkgs = $(shell $(GO) list ./... | grep -v /vendor/) 22 | 23 | PREFIX ?= $(shell pwd) 24 | BIN_DIR ?= $(shell pwd) 25 | 26 | ifdef DEBUG 27 | bindata_flags = -debug 28 | endif 29 | 30 | STATICCHECK_IGNORE = 31 | 32 | all: format staticcheck build test 33 | 34 | style: 35 | @echo ">> checking code style" 36 | @! $(GOFMT) -d $(shell find . -path ./vendor -prune -o -name '*.go' -print) | grep '^' 37 | 38 | check_license: 39 | @echo ">> checking license header" 40 | @./scripts/check_license.sh 41 | 42 | test: fixtures/.unpacked sysfs/fixtures/.unpacked 43 | @echo ">> running all tests" 44 | @$(GO) test -race $(shell $(GO) list ./... | grep -v /vendor/ | grep -v examples) 45 | 46 | format: 47 | @echo ">> formatting code" 48 | @$(GO) fmt $(pkgs) 49 | 50 | vet: 51 | @echo ">> vetting code" 52 | @$(GO) vet $(pkgs) 53 | 54 | staticcheck: $(STATICCHECK) 55 | @echo ">> running staticcheck" 56 | @$(STATICCHECK) -ignore "$(STATICCHECK_IGNORE)" $(pkgs) 57 | 58 | %/.unpacked: %.ttar 59 | ./ttar -C $(dir $*) -x -f $*.ttar 60 | touch $@ 61 | 62 | update_fixtures: fixtures.ttar sysfs/fixtures.ttar 63 | 64 | %fixtures.ttar: %/fixtures 65 | rm -v $(dir $*)fixtures/.unpacked 66 | ./ttar -C $(dir $*) -c -f $*fixtures.ttar fixtures/ 67 | 68 | $(FIRST_GOPATH)/bin/staticcheck: 69 | @GOOS= GOARCH= $(GO) get -u honnef.co/go/tools/cmd/staticcheck 70 | 71 | .PHONY: all style check_license format test vet staticcheck 72 | 73 | # Declaring the binaries at their default locations as PHONY targets is a hack 74 | # to ensure the latest version is downloaded on every make execution. 75 | # If this is not desired, copy/symlink these binaries to a different path and 76 | # set the respective environment variables. 77 | .PHONY: $(GOPATH)/bin/staticcheck 78 | -------------------------------------------------------------------------------- /vendor/github.com/inconshreveable/mousetrap/trap_windows.go: -------------------------------------------------------------------------------- 1 | // +build windows 2 | // +build !go1.4 3 | 4 | package mousetrap 5 | 6 | import ( 7 | "fmt" 8 | "os" 9 | "syscall" 10 | "unsafe" 11 | ) 12 | 13 | const ( 14 | // defined by the Win32 API 15 | th32cs_snapprocess uintptr = 0x2 16 | ) 17 | 18 | var ( 19 | kernel = syscall.MustLoadDLL("kernel32.dll") 20 | CreateToolhelp32Snapshot = kernel.MustFindProc("CreateToolhelp32Snapshot") 21 | Process32First = kernel.MustFindProc("Process32FirstW") 22 | Process32Next = kernel.MustFindProc("Process32NextW") 23 | ) 24 | 25 | // ProcessEntry32 structure defined by the Win32 API 26 | type processEntry32 struct { 27 | dwSize uint32 28 | cntUsage uint32 29 | th32ProcessID uint32 30 | th32DefaultHeapID int 31 | th32ModuleID uint32 32 | cntThreads uint32 33 | th32ParentProcessID uint32 34 | pcPriClassBase int32 35 | dwFlags uint32 36 | szExeFile [syscall.MAX_PATH]uint16 37 | } 38 | 39 | func getProcessEntry(pid int) (pe *processEntry32, err error) { 40 | snapshot, _, e1 := CreateToolhelp32Snapshot.Call(th32cs_snapprocess, uintptr(0)) 41 | if snapshot == uintptr(syscall.InvalidHandle) { 42 | err = fmt.Errorf("CreateToolhelp32Snapshot: %v", e1) 43 | return 44 | } 45 | defer syscall.CloseHandle(syscall.Handle(snapshot)) 46 | 47 | var processEntry processEntry32 48 | processEntry.dwSize = uint32(unsafe.Sizeof(processEntry)) 49 | ok, _, e1 := Process32First.Call(snapshot, uintptr(unsafe.Pointer(&processEntry))) 50 | if ok == 0 { 51 | err = fmt.Errorf("Process32First: %v", e1) 52 | return 53 | } 54 | 55 | for { 56 | if processEntry.th32ProcessID == uint32(pid) { 57 | pe = &processEntry 58 | return 59 | } 60 | 61 | ok, _, e1 = Process32Next.Call(snapshot, uintptr(unsafe.Pointer(&processEntry))) 62 | if ok == 0 { 63 | err = fmt.Errorf("Process32Next: %v", e1) 64 | return 65 | } 66 | } 67 | } 68 | 69 | func getppid() (pid int, err error) { 70 | pe, err := getProcessEntry(os.Getpid()) 71 | if err != nil { 72 | return 73 | } 74 | 75 | pid = int(pe.th32ParentProcessID) 76 | return 77 | } 78 | 79 | // StartedByExplorer returns true if the program was invoked by the user double-clicking 80 | // on the executable from explorer.exe 81 | // 82 | // It is conservative and returns false if any of the internal calls fail. 83 | // It does not guarantee that the program was run from a terminal. It only can tell you 84 | // whether it was launched from explorer.exe 85 | func StartedByExplorer() bool { 86 | ppid, err := getppid() 87 | if err != nil { 88 | return false 89 | } 90 | 91 | pe, err := getProcessEntry(ppid) 92 | if err != nil { 93 | return false 94 | } 95 | 96 | name := syscall.UTF16ToString(pe.szExeFile[:]) 97 | return name == "explorer.exe" 98 | } 99 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/procfs/buddyinfo.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 The Prometheus Authors 2 | // Licensed under the Apache License, Version 2.0 (the "License"); 3 | // you may not use this file except in compliance with the License. 4 | // You may obtain a copy of the License at 5 | // 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | 14 | package procfs 15 | 16 | import ( 17 | "bufio" 18 | "fmt" 19 | "io" 20 | "os" 21 | "strconv" 22 | "strings" 23 | ) 24 | 25 | // A BuddyInfo is the details parsed from /proc/buddyinfo. 26 | // The data is comprised of an array of free fragments of each size. 27 | // The sizes are 2^n*PAGE_SIZE, where n is the array index. 28 | type BuddyInfo struct { 29 | Node string 30 | Zone string 31 | Sizes []float64 32 | } 33 | 34 | // NewBuddyInfo reads the buddyinfo statistics. 35 | func NewBuddyInfo() ([]BuddyInfo, error) { 36 | fs, err := NewFS(DefaultMountPoint) 37 | if err != nil { 38 | return nil, err 39 | } 40 | 41 | return fs.NewBuddyInfo() 42 | } 43 | 44 | // NewBuddyInfo reads the buddyinfo statistics from the specified `proc` filesystem. 45 | func (fs FS) NewBuddyInfo() ([]BuddyInfo, error) { 46 | file, err := os.Open(fs.Path("buddyinfo")) 47 | if err != nil { 48 | return nil, err 49 | } 50 | defer file.Close() 51 | 52 | return parseBuddyInfo(file) 53 | } 54 | 55 | func parseBuddyInfo(r io.Reader) ([]BuddyInfo, error) { 56 | var ( 57 | buddyInfo = []BuddyInfo{} 58 | scanner = bufio.NewScanner(r) 59 | bucketCount = -1 60 | ) 61 | 62 | for scanner.Scan() { 63 | var err error 64 | line := scanner.Text() 65 | parts := strings.Fields(line) 66 | 67 | if len(parts) < 4 { 68 | return nil, fmt.Errorf("invalid number of fields when parsing buddyinfo") 69 | } 70 | 71 | node := strings.TrimRight(parts[1], ",") 72 | zone := strings.TrimRight(parts[3], ",") 73 | arraySize := len(parts[4:]) 74 | 75 | if bucketCount == -1 { 76 | bucketCount = arraySize 77 | } else { 78 | if bucketCount != arraySize { 79 | return nil, fmt.Errorf("mismatch in number of buddyinfo buckets, previous count %d, new count %d", bucketCount, arraySize) 80 | } 81 | } 82 | 83 | sizes := make([]float64, arraySize) 84 | for i := 0; i < arraySize; i++ { 85 | sizes[i], err = strconv.ParseFloat(parts[i+4], 64) 86 | if err != nil { 87 | return nil, fmt.Errorf("invalid value in buddyinfo: %s", err) 88 | } 89 | } 90 | 91 | buddyInfo = append(buddyInfo, BuddyInfo{node, zone, sizes}) 92 | } 93 | 94 | return buddyInfo, scanner.Err() 95 | } 96 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/procfs/nfs/parse_nfsd.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Prometheus Authors 2 | // Licensed under the Apache License, Version 2.0 (the "License"); 3 | // you may not use this file except in compliance with the License. 4 | // You may obtain a copy of the License at 5 | // 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | 14 | package nfs 15 | 16 | import ( 17 | "bufio" 18 | "fmt" 19 | "io" 20 | "strings" 21 | 22 | "github.com/prometheus/procfs/internal/util" 23 | ) 24 | 25 | // ParseServerRPCStats returns stats read from /proc/net/rpc/nfsd 26 | func ParseServerRPCStats(r io.Reader) (*ServerRPCStats, error) { 27 | stats := &ServerRPCStats{} 28 | 29 | scanner := bufio.NewScanner(r) 30 | for scanner.Scan() { 31 | line := scanner.Text() 32 | parts := strings.Fields(scanner.Text()) 33 | // require at least 34 | if len(parts) < 2 { 35 | return nil, fmt.Errorf("invalid NFSd metric line %q", line) 36 | } 37 | label := parts[0] 38 | 39 | var values []uint64 40 | var err error 41 | if label == "th" { 42 | if len(parts) < 3 { 43 | return nil, fmt.Errorf("invalid NFSd th metric line %q", line) 44 | } 45 | values, err = util.ParseUint64s(parts[1:3]) 46 | } else { 47 | values, err = util.ParseUint64s(parts[1:]) 48 | } 49 | if err != nil { 50 | return nil, fmt.Errorf("error parsing NFSd metric line: %s", err) 51 | } 52 | 53 | switch metricLine := parts[0]; metricLine { 54 | case "rc": 55 | stats.ReplyCache, err = parseReplyCache(values) 56 | case "fh": 57 | stats.FileHandles, err = parseFileHandles(values) 58 | case "io": 59 | stats.InputOutput, err = parseInputOutput(values) 60 | case "th": 61 | stats.Threads, err = parseThreads(values) 62 | case "ra": 63 | stats.ReadAheadCache, err = parseReadAheadCache(values) 64 | case "net": 65 | stats.Network, err = parseNetwork(values) 66 | case "rpc": 67 | stats.ServerRPC, err = parseServerRPC(values) 68 | case "proc2": 69 | stats.V2Stats, err = parseV2Stats(values) 70 | case "proc3": 71 | stats.V3Stats, err = parseV3Stats(values) 72 | case "proc4": 73 | stats.ServerV4Stats, err = parseServerV4Stats(values) 74 | case "proc4ops": 75 | stats.V4Ops, err = parseV4Ops(values) 76 | default: 77 | return nil, fmt.Errorf("unknown NFSd metric line %q", metricLine) 78 | } 79 | if err != nil { 80 | return nil, fmt.Errorf("errors parsing NFSd metric line: %s", err) 81 | } 82 | } 83 | 84 | if err := scanner.Err(); err != nil { 85 | return nil, fmt.Errorf("error scanning NFSd file: %s", err) 86 | } 87 | 88 | return stats, nil 89 | } 90 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/common/expfmt/encode.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Prometheus Authors 2 | // Licensed under the Apache License, Version 2.0 (the "License"); 3 | // you may not use this file except in compliance with the License. 4 | // You may obtain a copy of the License at 5 | // 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | 14 | package expfmt 15 | 16 | import ( 17 | "fmt" 18 | "io" 19 | "net/http" 20 | 21 | "github.com/golang/protobuf/proto" 22 | "github.com/matttproud/golang_protobuf_extensions/pbutil" 23 | "github.com/prometheus/common/internal/bitbucket.org/ww/goautoneg" 24 | 25 | dto "github.com/prometheus/client_model/go" 26 | ) 27 | 28 | // Encoder types encode metric families into an underlying wire protocol. 29 | type Encoder interface { 30 | Encode(*dto.MetricFamily) error 31 | } 32 | 33 | type encoder func(*dto.MetricFamily) error 34 | 35 | func (e encoder) Encode(v *dto.MetricFamily) error { 36 | return e(v) 37 | } 38 | 39 | // Negotiate returns the Content-Type based on the given Accept header. 40 | // If no appropriate accepted type is found, FmtText is returned. 41 | func Negotiate(h http.Header) Format { 42 | for _, ac := range goautoneg.ParseAccept(h.Get(hdrAccept)) { 43 | // Check for protocol buffer 44 | if ac.Type+"/"+ac.SubType == ProtoType && ac.Params["proto"] == ProtoProtocol { 45 | switch ac.Params["encoding"] { 46 | case "delimited": 47 | return FmtProtoDelim 48 | case "text": 49 | return FmtProtoText 50 | case "compact-text": 51 | return FmtProtoCompact 52 | } 53 | } 54 | // Check for text format. 55 | ver := ac.Params["version"] 56 | if ac.Type == "text" && ac.SubType == "plain" && (ver == TextVersion || ver == "") { 57 | return FmtText 58 | } 59 | } 60 | return FmtText 61 | } 62 | 63 | // NewEncoder returns a new encoder based on content type negotiation. 64 | func NewEncoder(w io.Writer, format Format) Encoder { 65 | switch format { 66 | case FmtProtoDelim: 67 | return encoder(func(v *dto.MetricFamily) error { 68 | _, err := pbutil.WriteDelimited(w, v) 69 | return err 70 | }) 71 | case FmtProtoCompact: 72 | return encoder(func(v *dto.MetricFamily) error { 73 | _, err := fmt.Fprintln(w, v.String()) 74 | return err 75 | }) 76 | case FmtProtoText: 77 | return encoder(func(v *dto.MetricFamily) error { 78 | _, err := fmt.Fprintln(w, proto.MarshalTextString(v)) 79 | return err 80 | }) 81 | case FmtText: 82 | return encoder(func(v *dto.MetricFamily) error { 83 | _, err := MetricFamilyToText(w, v) 84 | return err 85 | }) 86 | } 87 | panic("expfmt.NewEncoder: unknown format") 88 | } 89 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/cobra/args.go: -------------------------------------------------------------------------------- 1 | package cobra 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | type PositionalArgs func(cmd *Command, args []string) error 8 | 9 | // Legacy arg validation has the following behaviour: 10 | // - root commands with no subcommands can take arbitrary arguments 11 | // - root commands with subcommands will do subcommand validity checking 12 | // - subcommands will always accept arbitrary arguments 13 | func legacyArgs(cmd *Command, args []string) error { 14 | // no subcommand, always take args 15 | if !cmd.HasSubCommands() { 16 | return nil 17 | } 18 | 19 | // root command with subcommands, do subcommand checking. 20 | if !cmd.HasParent() && len(args) > 0 { 21 | return fmt.Errorf("unknown command %q for %q%s", args[0], cmd.CommandPath(), cmd.findSuggestions(args[0])) 22 | } 23 | return nil 24 | } 25 | 26 | // NoArgs returns an error if any args are included. 27 | func NoArgs(cmd *Command, args []string) error { 28 | if len(args) > 0 { 29 | return fmt.Errorf("unknown command %q for %q", args[0], cmd.CommandPath()) 30 | } 31 | return nil 32 | } 33 | 34 | // OnlyValidArgs returns an error if any args are not in the list of ValidArgs. 35 | func OnlyValidArgs(cmd *Command, args []string) error { 36 | if len(cmd.ValidArgs) > 0 { 37 | for _, v := range args { 38 | if !stringInSlice(v, cmd.ValidArgs) { 39 | return fmt.Errorf("invalid argument %q for %q%s", v, cmd.CommandPath(), cmd.findSuggestions(args[0])) 40 | } 41 | } 42 | } 43 | return nil 44 | } 45 | 46 | // ArbitraryArgs never returns an error. 47 | func ArbitraryArgs(cmd *Command, args []string) error { 48 | return nil 49 | } 50 | 51 | // MinimumNArgs returns an error if there is not at least N args. 52 | func MinimumNArgs(n int) PositionalArgs { 53 | return func(cmd *Command, args []string) error { 54 | if len(args) < n { 55 | return fmt.Errorf("requires at least %d arg(s), only received %d", n, len(args)) 56 | } 57 | return nil 58 | } 59 | } 60 | 61 | // MaximumNArgs returns an error if there are more than N args. 62 | func MaximumNArgs(n int) PositionalArgs { 63 | return func(cmd *Command, args []string) error { 64 | if len(args) > n { 65 | return fmt.Errorf("accepts at most %d arg(s), received %d", n, len(args)) 66 | } 67 | return nil 68 | } 69 | } 70 | 71 | // ExactArgs returns an error if there are not exactly n args. 72 | func ExactArgs(n int) PositionalArgs { 73 | return func(cmd *Command, args []string) error { 74 | if len(args) != n { 75 | return fmt.Errorf("accepts %d arg(s), received %d", n, len(args)) 76 | } 77 | return nil 78 | } 79 | } 80 | 81 | // RangeArgs returns an error if the number of args is not within the expected range. 82 | func RangeArgs(min int, max int) PositionalArgs { 83 | return func(cmd *Command, args []string) error { 84 | if len(args) < min || len(args) > max { 85 | return fmt.Errorf("accepts between %d and %d arg(s), received %d", min, max, len(args)) 86 | } 87 | return nil 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/int.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import "strconv" 4 | 5 | // -- int Value 6 | type intValue int 7 | 8 | func newIntValue(val int, p *int) *intValue { 9 | *p = val 10 | return (*intValue)(p) 11 | } 12 | 13 | func (i *intValue) Set(s string) error { 14 | v, err := strconv.ParseInt(s, 0, 64) 15 | *i = intValue(v) 16 | return err 17 | } 18 | 19 | func (i *intValue) Type() string { 20 | return "int" 21 | } 22 | 23 | func (i *intValue) String() string { return strconv.Itoa(int(*i)) } 24 | 25 | func intConv(sval string) (interface{}, error) { 26 | return strconv.Atoi(sval) 27 | } 28 | 29 | // GetInt return the int value of a flag with the given name 30 | func (f *FlagSet) GetInt(name string) (int, error) { 31 | val, err := f.getFlagType(name, "int", intConv) 32 | if err != nil { 33 | return 0, err 34 | } 35 | return val.(int), nil 36 | } 37 | 38 | // IntVar defines an int flag with specified name, default value, and usage string. 39 | // The argument p points to an int variable in which to store the value of the flag. 40 | func (f *FlagSet) IntVar(p *int, name string, value int, usage string) { 41 | f.VarP(newIntValue(value, p), name, "", usage) 42 | } 43 | 44 | // IntVarP is like IntVar, but accepts a shorthand letter that can be used after a single dash. 45 | func (f *FlagSet) IntVarP(p *int, name, shorthand string, value int, usage string) { 46 | f.VarP(newIntValue(value, p), name, shorthand, usage) 47 | } 48 | 49 | // IntVar defines an int flag with specified name, default value, and usage string. 50 | // The argument p points to an int variable in which to store the value of the flag. 51 | func IntVar(p *int, name string, value int, usage string) { 52 | CommandLine.VarP(newIntValue(value, p), name, "", usage) 53 | } 54 | 55 | // IntVarP is like IntVar, but accepts a shorthand letter that can be used after a single dash. 56 | func IntVarP(p *int, name, shorthand string, value int, usage string) { 57 | CommandLine.VarP(newIntValue(value, p), name, shorthand, usage) 58 | } 59 | 60 | // Int defines an int flag with specified name, default value, and usage string. 61 | // The return value is the address of an int variable that stores the value of the flag. 62 | func (f *FlagSet) Int(name string, value int, usage string) *int { 63 | p := new(int) 64 | f.IntVarP(p, name, "", value, usage) 65 | return p 66 | } 67 | 68 | // IntP is like Int, but accepts a shorthand letter that can be used after a single dash. 69 | func (f *FlagSet) IntP(name, shorthand string, value int, usage string) *int { 70 | p := new(int) 71 | f.IntVarP(p, name, shorthand, value, usage) 72 | return p 73 | } 74 | 75 | // Int defines an int flag with specified name, default value, and usage string. 76 | // The return value is the address of an int variable that stores the value of the flag. 77 | func Int(name string, value int, usage string) *int { 78 | return CommandLine.IntP(name, "", value, usage) 79 | } 80 | 81 | // IntP is like Int, but accepts a shorthand letter that can be used after a single dash. 82 | func IntP(name, shorthand string, value int, usage string) *int { 83 | return CommandLine.IntP(name, shorthand, value, usage) 84 | } 85 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # PETS 2 | 3 | Process for Editing Tons of Services 🐈🐈🐈 4 | 5 | [![Build Status](https://circleci.com/gh/windmilleng/pets/tree/master.svg?style=shield)](https://circleci.com/gh/windmilleng/pets) 6 | [![GoDoc](https://godoc.org/github.com/windmilleng/pets?status.svg)](https://godoc.org/github.com/windmilleng/pets) 7 | 8 | Kubernetes makes it easy to manage herds of cattle: lots of servers running in 9 | production. 10 | 11 | `pets` makes it easy to manage herds of cats: lots of servers running on your 12 | machine that you want to keep a close eye on for local development. 13 | 14 | 15 | 16 | ## The Big Idea 17 | 18 | `pets` is for the cloud-service developer who has multiple servers that they run 19 | for day-to-day feature work. Maybe the servers run as bare processes. Maybe they 20 | run in containers. Or in minikube. Or in a remote Kubernetes cluster. 21 | 22 | We should be able to express the constellation of servers independently of how 23 | we start them. A `Petsfile` is like a `Makefile` for expressing how servers 24 | start and fit together. This lets us switch back and forth quickly between 25 | servers running locally and servers running in the cloud. 26 | 27 | ## Installation 28 | 29 | ### Binaries 30 | 31 | You can find pre-compiled binaries for common platforms on the [releases page](https://github.com/windmilleng/pets/releases). 32 | 33 | ### From source 34 | 35 | ``` 36 | go get -u github.com/windmilleng/pets 37 | ``` 38 | 39 | ## Usage 40 | 41 | To get started using pets, read [the introductory blog post](https://medium.com/p/5f4ecba11f7d). 42 | 43 | For more detail on how to use the CLI, you can browse the [CLI documentation](docs/pets.md). 44 | 45 | For more detail on how to write a configuration file for your project, see the [config documentation](docs/config.md). 46 | 47 | ## Examples 48 | 49 | We've written some example projects that use a Petsfile so start a frontend 50 | server with two backend servers and a database: 51 | 52 | - [Frontend Petsfile](https://github.com/windmilleng/blorg-frontend/blob/master/Petsfile) 53 | - [Backend #1 Petsfile](https://github.com/windmilleng/blorg-backend/blob/master/Petsfile) 54 | - [Backend #2 Petsfile](https://github.com/windmilleng/blorgly-backend/blob/master/Petsfile) 55 | 56 | ## Privacy 57 | 58 | This tool can send usage reports to https://events.windmill.build, to help us 59 | understand what features people use. We only report on which `pets` commands 60 | run and how long they run for. 61 | 62 | You can enable usage reports by running 63 | 64 | ``` 65 | pets analytics opt in 66 | ``` 67 | 68 | (and disable them by running `pets analytics opt out`.) 69 | 70 | We do not report any personally identifiable information. We do not report any 71 | identifiable data about your code. 72 | 73 | We do not share this data with anyone who is not an employee of Windmill 74 | Engineering. Data may be sent to third-party service providers like Datadog, 75 | but only to help us analyze the data. 76 | 77 | ## License 78 | Copyright 2018 Windmill Engineering 79 | 80 | Licensed under [the Apache License, Version 2.0](LICENSE) 81 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/common/model/fingerprinting.go: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Prometheus Authors 2 | // Licensed under the Apache License, Version 2.0 (the "License"); 3 | // you may not use this file except in compliance with the License. 4 | // You may obtain a copy of the License at 5 | // 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | 14 | package model 15 | 16 | import ( 17 | "fmt" 18 | "strconv" 19 | ) 20 | 21 | // Fingerprint provides a hash-capable representation of a Metric. 22 | // For our purposes, FNV-1A 64-bit is used. 23 | type Fingerprint uint64 24 | 25 | // FingerprintFromString transforms a string representation into a Fingerprint. 26 | func FingerprintFromString(s string) (Fingerprint, error) { 27 | num, err := strconv.ParseUint(s, 16, 64) 28 | return Fingerprint(num), err 29 | } 30 | 31 | // ParseFingerprint parses the input string into a fingerprint. 32 | func ParseFingerprint(s string) (Fingerprint, error) { 33 | num, err := strconv.ParseUint(s, 16, 64) 34 | if err != nil { 35 | return 0, err 36 | } 37 | return Fingerprint(num), nil 38 | } 39 | 40 | func (f Fingerprint) String() string { 41 | return fmt.Sprintf("%016x", uint64(f)) 42 | } 43 | 44 | // Fingerprints represents a collection of Fingerprint subject to a given 45 | // natural sorting scheme. It implements sort.Interface. 46 | type Fingerprints []Fingerprint 47 | 48 | // Len implements sort.Interface. 49 | func (f Fingerprints) Len() int { 50 | return len(f) 51 | } 52 | 53 | // Less implements sort.Interface. 54 | func (f Fingerprints) Less(i, j int) bool { 55 | return f[i] < f[j] 56 | } 57 | 58 | // Swap implements sort.Interface. 59 | func (f Fingerprints) Swap(i, j int) { 60 | f[i], f[j] = f[j], f[i] 61 | } 62 | 63 | // FingerprintSet is a set of Fingerprints. 64 | type FingerprintSet map[Fingerprint]struct{} 65 | 66 | // Equal returns true if both sets contain the same elements (and not more). 67 | func (s FingerprintSet) Equal(o FingerprintSet) bool { 68 | if len(s) != len(o) { 69 | return false 70 | } 71 | 72 | for k := range s { 73 | if _, ok := o[k]; !ok { 74 | return false 75 | } 76 | } 77 | 78 | return true 79 | } 80 | 81 | // Intersection returns the elements contained in both sets. 82 | func (s FingerprintSet) Intersection(o FingerprintSet) FingerprintSet { 83 | myLength, otherLength := len(s), len(o) 84 | if myLength == 0 || otherLength == 0 { 85 | return FingerprintSet{} 86 | } 87 | 88 | subSet := s 89 | superSet := o 90 | 91 | if otherLength < myLength { 92 | subSet = o 93 | superSet = s 94 | } 95 | 96 | out := FingerprintSet{} 97 | 98 | for k := range subSet { 99 | if _, ok := superSet[k]; ok { 100 | out[k] = struct{}{} 101 | } 102 | } 103 | 104 | return out 105 | } 106 | -------------------------------------------------------------------------------- /vendor/github.com/matttproud/golang_protobuf_extensions/pbutil/decode.go: -------------------------------------------------------------------------------- 1 | // Copyright 2013 Matt T. Proud 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package pbutil 16 | 17 | import ( 18 | "encoding/binary" 19 | "errors" 20 | "io" 21 | 22 | "github.com/golang/protobuf/proto" 23 | ) 24 | 25 | var errInvalidVarint = errors.New("invalid varint32 encountered") 26 | 27 | // ReadDelimited decodes a message from the provided length-delimited stream, 28 | // where the length is encoded as 32-bit varint prefix to the message body. 29 | // It returns the total number of bytes read and any applicable error. This is 30 | // roughly equivalent to the companion Java API's 31 | // MessageLite#parseDelimitedFrom. As per the reader contract, this function 32 | // calls r.Read repeatedly as required until exactly one message including its 33 | // prefix is read and decoded (or an error has occurred). The function never 34 | // reads more bytes from the stream than required. The function never returns 35 | // an error if a message has been read and decoded correctly, even if the end 36 | // of the stream has been reached in doing so. In that case, any subsequent 37 | // calls return (0, io.EOF). 38 | func ReadDelimited(r io.Reader, m proto.Message) (n int, err error) { 39 | // Per AbstractParser#parsePartialDelimitedFrom with 40 | // CodedInputStream#readRawVarint32. 41 | var headerBuf [binary.MaxVarintLen32]byte 42 | var bytesRead, varIntBytes int 43 | var messageLength uint64 44 | for varIntBytes == 0 { // i.e. no varint has been decoded yet. 45 | if bytesRead >= len(headerBuf) { 46 | return bytesRead, errInvalidVarint 47 | } 48 | // We have to read byte by byte here to avoid reading more bytes 49 | // than required. Each read byte is appended to what we have 50 | // read before. 51 | newBytesRead, err := r.Read(headerBuf[bytesRead : bytesRead+1]) 52 | if newBytesRead == 0 { 53 | if err != nil { 54 | return bytesRead, err 55 | } 56 | // A Reader should not return (0, nil), but if it does, 57 | // it should be treated as no-op (according to the 58 | // Reader contract). So let's go on... 59 | continue 60 | } 61 | bytesRead += newBytesRead 62 | // Now present everything read so far to the varint decoder and 63 | // see if a varint can be decoded already. 64 | messageLength, varIntBytes = proto.DecodeVarint(headerBuf[:bytesRead]) 65 | } 66 | 67 | messageBuf := make([]byte, messageLength) 68 | newBytesRead, err := io.ReadFull(r, messageBuf) 69 | bytesRead += newBytesRead 70 | if err != nil { 71 | return bytesRead, err 72 | } 73 | 74 | return bytesRead, proto.Unmarshal(messageBuf, m) 75 | } 76 | -------------------------------------------------------------------------------- /vendor/github.com/heptiolabs/healthcheck/async.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 by the contributors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package healthcheck 16 | 17 | import ( 18 | "context" 19 | "errors" 20 | "time" 21 | ) 22 | 23 | // ErrNoData is returned if the first call of an Async() wrapped Check has not 24 | // yet returned. 25 | var ErrNoData = errors.New("no data yet") 26 | 27 | // Async converts a Check into an asynchronous check that runs in a background 28 | // goroutine at a fixed interval. The check is called at a fixed rate, not with 29 | // a fixed delay between invocations. If your check takes longer than the 30 | // interval to execute, the next execution will happen immediately. 31 | // 32 | // Note: if you need to clean up the background goroutine, use AsyncWithContext(). 33 | func Async(check Check, interval time.Duration) Check { 34 | return AsyncWithContext(context.Background(), check, interval) 35 | } 36 | 37 | // AsyncWithContext converts a Check into an asynchronous check that runs in a 38 | // background goroutine at a fixed interval. The check is called at a fixed 39 | // rate, not with a fixed delay between invocations. If your check takes longer 40 | // than the interval to execute, the next execution will happen immediately. 41 | // 42 | // Note: if you don't need to cancel execution (because this runs forever), use Async() 43 | func AsyncWithContext(ctx context.Context, check Check, interval time.Duration) Check { 44 | // create a chan that will buffer the most recent check result 45 | result := make(chan error, 1) 46 | 47 | // fill it with ErrNoData so we'll start in an initially failing state 48 | // (we don't want to be ready/live until we've actually executed the check 49 | // once, but that might be slow). 50 | result <- ErrNoData 51 | 52 | // make a wrapper that runs the check, and swaps out the current head of 53 | // the channel with the latest result 54 | update := func() { 55 | err := check() 56 | <-result 57 | result <- err 58 | } 59 | 60 | // spawn a background goroutine to run the check 61 | go func() { 62 | // call once right away (time.Tick() doesn't always tick immediately 63 | // but we want an initial result as soon as possible) 64 | update() 65 | 66 | // loop forever or until the context is canceled 67 | ticker := time.Tick(interval) 68 | for { 69 | select { 70 | case <-ticker: 71 | update() 72 | case <-ctx.Done(): 73 | return 74 | } 75 | } 76 | }() 77 | 78 | // return a Check function that closes over our result and mutex 79 | return func() error { 80 | // peek at the head of the channel, then put it back 81 | err := <-result 82 | result <- err 83 | return err 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /vendor/github.com/windmilleng/wmclient/pkg/dirs/dirs.go: -------------------------------------------------------------------------------- 1 | package dirs 2 | 3 | import ( 4 | "fmt" 5 | "io/ioutil" 6 | "os" 7 | "os/user" 8 | "path/filepath" 9 | ) 10 | 11 | func CurrentHomeDir() (string, error) { 12 | home := os.Getenv("HOME") 13 | if home != "" { 14 | return home, nil 15 | } 16 | 17 | current, err := user.Current() 18 | if err != nil { 19 | return "", err 20 | } 21 | return current.HomeDir, nil 22 | } 23 | 24 | // WindmillDir returns the root Windmill directory; by default ~/.windmill 25 | func GetWindmillDir() (string, error) { 26 | dir := os.Getenv("WMDAEMON_HOME") 27 | if dir == "" { 28 | dir = os.Getenv("WINDMILL_DIR") 29 | } 30 | if dir == "" { 31 | homedir, err := CurrentHomeDir() 32 | if err != nil { 33 | return "", err 34 | } 35 | 36 | if homedir == "" { 37 | return "", fmt.Errorf("Cannot find home directory; $HOME unset") 38 | } 39 | dir = filepath.Join(homedir, ".windmill") 40 | } 41 | 42 | dir, err := filepath.Abs(dir) 43 | if err != nil { 44 | return "", err 45 | } 46 | 47 | if _, err := os.Stat(dir); err != nil { 48 | if os.IsNotExist(err) { 49 | os.Mkdir(dir, os.FileMode(0755)) 50 | } else { 51 | return "", err 52 | } 53 | } 54 | 55 | return dir, nil 56 | } 57 | 58 | func UseWindmillDir() (*WindmillDir, error) { 59 | dir, err := GetWindmillDir() 60 | if err != nil { 61 | return nil, err 62 | } 63 | 64 | return &WindmillDir{dir: dir}, nil 65 | } 66 | 67 | // Create a windmill dir at an arbitrary directory. Useful for testing. 68 | func NewWindmillDirAt(dir string) *WindmillDir { 69 | return &WindmillDir{dir: dir} 70 | } 71 | 72 | type WindmillDir struct { 73 | dir string 74 | } 75 | 76 | func (d *WindmillDir) Root() string { 77 | return d.dir 78 | } 79 | 80 | func (d *WindmillDir) OpenFile(p string, flag int, perm os.FileMode) (*os.File, error) { 81 | err := d.MkdirAll(filepath.Dir(p)) 82 | if err != nil { 83 | return nil, err 84 | } 85 | 86 | return os.OpenFile(filepath.Join(d.dir, p), flag, perm) 87 | } 88 | 89 | func (d *WindmillDir) WriteFile(p, text string) error { 90 | err := d.MkdirAll(filepath.Dir(p)) 91 | if err != nil { 92 | return err 93 | } 94 | 95 | return ioutil.WriteFile(filepath.Join(d.dir, p), []byte(text), os.FileMode(0700)) 96 | } 97 | 98 | func (d *WindmillDir) ReadFile(p string) (string, error) { 99 | if filepath.IsAbs(p) { 100 | return "", fmt.Errorf("WindmillDir.ReadFile: p must be relative to .windmill root: %v", p) 101 | } 102 | 103 | abs := filepath.Join(d.dir, p) 104 | bs, err := ioutil.ReadFile(abs) 105 | if err != nil { 106 | return "", err 107 | } 108 | 109 | return string(bs), nil 110 | } 111 | 112 | func (d *WindmillDir) MkdirAll(p string) error { 113 | if filepath.IsAbs(p) { 114 | return fmt.Errorf("WindmillDir.MkdirAll: p must be relative to .windmill root: %v", p) 115 | } 116 | 117 | return os.MkdirAll(filepath.Join(d.dir, p), os.FileMode(0700)) 118 | } 119 | 120 | func (d *WindmillDir) Abs(p string) (string, error) { 121 | if filepath.IsAbs(p) { 122 | return "", fmt.Errorf("WindmillDir.Abs: p must be relative to .windmill root: %v", p) 123 | } 124 | 125 | return filepath.Join(d.dir, p), nil 126 | } 127 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/string.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | // -- string Value 4 | type stringValue string 5 | 6 | func newStringValue(val string, p *string) *stringValue { 7 | *p = val 8 | return (*stringValue)(p) 9 | } 10 | 11 | func (s *stringValue) Set(val string) error { 12 | *s = stringValue(val) 13 | return nil 14 | } 15 | func (s *stringValue) Type() string { 16 | return "string" 17 | } 18 | 19 | func (s *stringValue) String() string { return string(*s) } 20 | 21 | func stringConv(sval string) (interface{}, error) { 22 | return sval, nil 23 | } 24 | 25 | // GetString return the string value of a flag with the given name 26 | func (f *FlagSet) GetString(name string) (string, error) { 27 | val, err := f.getFlagType(name, "string", stringConv) 28 | if err != nil { 29 | return "", err 30 | } 31 | return val.(string), nil 32 | } 33 | 34 | // StringVar defines a string flag with specified name, default value, and usage string. 35 | // The argument p points to a string variable in which to store the value of the flag. 36 | func (f *FlagSet) StringVar(p *string, name string, value string, usage string) { 37 | f.VarP(newStringValue(value, p), name, "", usage) 38 | } 39 | 40 | // StringVarP is like StringVar, but accepts a shorthand letter that can be used after a single dash. 41 | func (f *FlagSet) StringVarP(p *string, name, shorthand string, value string, usage string) { 42 | f.VarP(newStringValue(value, p), name, shorthand, usage) 43 | } 44 | 45 | // StringVar defines a string flag with specified name, default value, and usage string. 46 | // The argument p points to a string variable in which to store the value of the flag. 47 | func StringVar(p *string, name string, value string, usage string) { 48 | CommandLine.VarP(newStringValue(value, p), name, "", usage) 49 | } 50 | 51 | // StringVarP is like StringVar, but accepts a shorthand letter that can be used after a single dash. 52 | func StringVarP(p *string, name, shorthand string, value string, usage string) { 53 | CommandLine.VarP(newStringValue(value, p), name, shorthand, usage) 54 | } 55 | 56 | // String defines a string flag with specified name, default value, and usage string. 57 | // The return value is the address of a string variable that stores the value of the flag. 58 | func (f *FlagSet) String(name string, value string, usage string) *string { 59 | p := new(string) 60 | f.StringVarP(p, name, "", value, usage) 61 | return p 62 | } 63 | 64 | // StringP is like String, but accepts a shorthand letter that can be used after a single dash. 65 | func (f *FlagSet) StringP(name, shorthand string, value string, usage string) *string { 66 | p := new(string) 67 | f.StringVarP(p, name, shorthand, value, usage) 68 | return p 69 | } 70 | 71 | // String defines a string flag with specified name, default value, and usage string. 72 | // The return value is the address of a string variable that stores the value of the flag. 73 | func String(name string, value string, usage string) *string { 74 | return CommandLine.StringP(name, "", value, usage) 75 | } 76 | 77 | // StringP is like String, but accepts a shorthand letter that can be used after a single dash. 78 | func StringP(name, shorthand string, value string, usage string) *string { 79 | return CommandLine.StringP(name, shorthand, value, usage) 80 | } 81 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/int64.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import "strconv" 4 | 5 | // -- int64 Value 6 | type int64Value int64 7 | 8 | func newInt64Value(val int64, p *int64) *int64Value { 9 | *p = val 10 | return (*int64Value)(p) 11 | } 12 | 13 | func (i *int64Value) Set(s string) error { 14 | v, err := strconv.ParseInt(s, 0, 64) 15 | *i = int64Value(v) 16 | return err 17 | } 18 | 19 | func (i *int64Value) Type() string { 20 | return "int64" 21 | } 22 | 23 | func (i *int64Value) String() string { return strconv.FormatInt(int64(*i), 10) } 24 | 25 | func int64Conv(sval string) (interface{}, error) { 26 | return strconv.ParseInt(sval, 0, 64) 27 | } 28 | 29 | // GetInt64 return the int64 value of a flag with the given name 30 | func (f *FlagSet) GetInt64(name string) (int64, error) { 31 | val, err := f.getFlagType(name, "int64", int64Conv) 32 | if err != nil { 33 | return 0, err 34 | } 35 | return val.(int64), nil 36 | } 37 | 38 | // Int64Var defines an int64 flag with specified name, default value, and usage string. 39 | // The argument p points to an int64 variable in which to store the value of the flag. 40 | func (f *FlagSet) Int64Var(p *int64, name string, value int64, usage string) { 41 | f.VarP(newInt64Value(value, p), name, "", usage) 42 | } 43 | 44 | // Int64VarP is like Int64Var, but accepts a shorthand letter that can be used after a single dash. 45 | func (f *FlagSet) Int64VarP(p *int64, name, shorthand string, value int64, usage string) { 46 | f.VarP(newInt64Value(value, p), name, shorthand, usage) 47 | } 48 | 49 | // Int64Var defines an int64 flag with specified name, default value, and usage string. 50 | // The argument p points to an int64 variable in which to store the value of the flag. 51 | func Int64Var(p *int64, name string, value int64, usage string) { 52 | CommandLine.VarP(newInt64Value(value, p), name, "", usage) 53 | } 54 | 55 | // Int64VarP is like Int64Var, but accepts a shorthand letter that can be used after a single dash. 56 | func Int64VarP(p *int64, name, shorthand string, value int64, usage string) { 57 | CommandLine.VarP(newInt64Value(value, p), name, shorthand, usage) 58 | } 59 | 60 | // Int64 defines an int64 flag with specified name, default value, and usage string. 61 | // The return value is the address of an int64 variable that stores the value of the flag. 62 | func (f *FlagSet) Int64(name string, value int64, usage string) *int64 { 63 | p := new(int64) 64 | f.Int64VarP(p, name, "", value, usage) 65 | return p 66 | } 67 | 68 | // Int64P is like Int64, but accepts a shorthand letter that can be used after a single dash. 69 | func (f *FlagSet) Int64P(name, shorthand string, value int64, usage string) *int64 { 70 | p := new(int64) 71 | f.Int64VarP(p, name, shorthand, value, usage) 72 | return p 73 | } 74 | 75 | // Int64 defines an int64 flag with specified name, default value, and usage string. 76 | // The return value is the address of an int64 variable that stores the value of the flag. 77 | func Int64(name string, value int64, usage string) *int64 { 78 | return CommandLine.Int64P(name, "", value, usage) 79 | } 80 | 81 | // Int64P is like Int64, but accepts a shorthand letter that can be used after a single dash. 82 | func Int64P(name, shorthand string, value int64, usage string) *int64 { 83 | return CommandLine.Int64P(name, shorthand, value, usage) 84 | } 85 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/int8.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import "strconv" 4 | 5 | // -- int8 Value 6 | type int8Value int8 7 | 8 | func newInt8Value(val int8, p *int8) *int8Value { 9 | *p = val 10 | return (*int8Value)(p) 11 | } 12 | 13 | func (i *int8Value) Set(s string) error { 14 | v, err := strconv.ParseInt(s, 0, 8) 15 | *i = int8Value(v) 16 | return err 17 | } 18 | 19 | func (i *int8Value) Type() string { 20 | return "int8" 21 | } 22 | 23 | func (i *int8Value) String() string { return strconv.FormatInt(int64(*i), 10) } 24 | 25 | func int8Conv(sval string) (interface{}, error) { 26 | v, err := strconv.ParseInt(sval, 0, 8) 27 | if err != nil { 28 | return 0, err 29 | } 30 | return int8(v), nil 31 | } 32 | 33 | // GetInt8 return the int8 value of a flag with the given name 34 | func (f *FlagSet) GetInt8(name string) (int8, error) { 35 | val, err := f.getFlagType(name, "int8", int8Conv) 36 | if err != nil { 37 | return 0, err 38 | } 39 | return val.(int8), nil 40 | } 41 | 42 | // Int8Var defines an int8 flag with specified name, default value, and usage string. 43 | // The argument p points to an int8 variable in which to store the value of the flag. 44 | func (f *FlagSet) Int8Var(p *int8, name string, value int8, usage string) { 45 | f.VarP(newInt8Value(value, p), name, "", usage) 46 | } 47 | 48 | // Int8VarP is like Int8Var, but accepts a shorthand letter that can be used after a single dash. 49 | func (f *FlagSet) Int8VarP(p *int8, name, shorthand string, value int8, usage string) { 50 | f.VarP(newInt8Value(value, p), name, shorthand, usage) 51 | } 52 | 53 | // Int8Var defines an int8 flag with specified name, default value, and usage string. 54 | // The argument p points to an int8 variable in which to store the value of the flag. 55 | func Int8Var(p *int8, name string, value int8, usage string) { 56 | CommandLine.VarP(newInt8Value(value, p), name, "", usage) 57 | } 58 | 59 | // Int8VarP is like Int8Var, but accepts a shorthand letter that can be used after a single dash. 60 | func Int8VarP(p *int8, name, shorthand string, value int8, usage string) { 61 | CommandLine.VarP(newInt8Value(value, p), name, shorthand, usage) 62 | } 63 | 64 | // Int8 defines an int8 flag with specified name, default value, and usage string. 65 | // The return value is the address of an int8 variable that stores the value of the flag. 66 | func (f *FlagSet) Int8(name string, value int8, usage string) *int8 { 67 | p := new(int8) 68 | f.Int8VarP(p, name, "", value, usage) 69 | return p 70 | } 71 | 72 | // Int8P is like Int8, but accepts a shorthand letter that can be used after a single dash. 73 | func (f *FlagSet) Int8P(name, shorthand string, value int8, usage string) *int8 { 74 | p := new(int8) 75 | f.Int8VarP(p, name, shorthand, value, usage) 76 | return p 77 | } 78 | 79 | // Int8 defines an int8 flag with specified name, default value, and usage string. 80 | // The return value is the address of an int8 variable that stores the value of the flag. 81 | func Int8(name string, value int8, usage string) *int8 { 82 | return CommandLine.Int8P(name, "", value, usage) 83 | } 84 | 85 | // Int8P is like Int8, but accepts a shorthand letter that can be used after a single dash. 86 | func Int8P(name, shorthand string, value int8, usage string) *int8 { 87 | return CommandLine.Int8P(name, shorthand, value, usage) 88 | } 89 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/uint.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import "strconv" 4 | 5 | // -- uint Value 6 | type uintValue uint 7 | 8 | func newUintValue(val uint, p *uint) *uintValue { 9 | *p = val 10 | return (*uintValue)(p) 11 | } 12 | 13 | func (i *uintValue) Set(s string) error { 14 | v, err := strconv.ParseUint(s, 0, 64) 15 | *i = uintValue(v) 16 | return err 17 | } 18 | 19 | func (i *uintValue) Type() string { 20 | return "uint" 21 | } 22 | 23 | func (i *uintValue) String() string { return strconv.FormatUint(uint64(*i), 10) } 24 | 25 | func uintConv(sval string) (interface{}, error) { 26 | v, err := strconv.ParseUint(sval, 0, 0) 27 | if err != nil { 28 | return 0, err 29 | } 30 | return uint(v), nil 31 | } 32 | 33 | // GetUint return the uint value of a flag with the given name 34 | func (f *FlagSet) GetUint(name string) (uint, error) { 35 | val, err := f.getFlagType(name, "uint", uintConv) 36 | if err != nil { 37 | return 0, err 38 | } 39 | return val.(uint), nil 40 | } 41 | 42 | // UintVar defines a uint flag with specified name, default value, and usage string. 43 | // The argument p points to a uint variable in which to store the value of the flag. 44 | func (f *FlagSet) UintVar(p *uint, name string, value uint, usage string) { 45 | f.VarP(newUintValue(value, p), name, "", usage) 46 | } 47 | 48 | // UintVarP is like UintVar, but accepts a shorthand letter that can be used after a single dash. 49 | func (f *FlagSet) UintVarP(p *uint, name, shorthand string, value uint, usage string) { 50 | f.VarP(newUintValue(value, p), name, shorthand, usage) 51 | } 52 | 53 | // UintVar defines a uint flag with specified name, default value, and usage string. 54 | // The argument p points to a uint variable in which to store the value of the flag. 55 | func UintVar(p *uint, name string, value uint, usage string) { 56 | CommandLine.VarP(newUintValue(value, p), name, "", usage) 57 | } 58 | 59 | // UintVarP is like UintVar, but accepts a shorthand letter that can be used after a single dash. 60 | func UintVarP(p *uint, name, shorthand string, value uint, usage string) { 61 | CommandLine.VarP(newUintValue(value, p), name, shorthand, usage) 62 | } 63 | 64 | // Uint defines a uint flag with specified name, default value, and usage string. 65 | // The return value is the address of a uint variable that stores the value of the flag. 66 | func (f *FlagSet) Uint(name string, value uint, usage string) *uint { 67 | p := new(uint) 68 | f.UintVarP(p, name, "", value, usage) 69 | return p 70 | } 71 | 72 | // UintP is like Uint, but accepts a shorthand letter that can be used after a single dash. 73 | func (f *FlagSet) UintP(name, shorthand string, value uint, usage string) *uint { 74 | p := new(uint) 75 | f.UintVarP(p, name, shorthand, value, usage) 76 | return p 77 | } 78 | 79 | // Uint defines a uint flag with specified name, default value, and usage string. 80 | // The return value is the address of a uint variable that stores the value of the flag. 81 | func Uint(name string, value uint, usage string) *uint { 82 | return CommandLine.UintP(name, "", value, usage) 83 | } 84 | 85 | // UintP is like Uint, but accepts a shorthand letter that can be used after a single dash. 86 | func UintP(name, shorthand string, value uint, usage string) *uint { 87 | return CommandLine.UintP(name, shorthand, value, usage) 88 | } 89 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/count.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import "strconv" 4 | 5 | // -- count Value 6 | type countValue int 7 | 8 | func newCountValue(val int, p *int) *countValue { 9 | *p = val 10 | return (*countValue)(p) 11 | } 12 | 13 | func (i *countValue) Set(s string) error { 14 | // "+1" means that no specific value was passed, so increment 15 | if s == "+1" { 16 | *i = countValue(*i + 1) 17 | return nil 18 | } 19 | v, err := strconv.ParseInt(s, 0, 0) 20 | *i = countValue(v) 21 | return err 22 | } 23 | 24 | func (i *countValue) Type() string { 25 | return "count" 26 | } 27 | 28 | func (i *countValue) String() string { return strconv.Itoa(int(*i)) } 29 | 30 | func countConv(sval string) (interface{}, error) { 31 | i, err := strconv.Atoi(sval) 32 | if err != nil { 33 | return nil, err 34 | } 35 | return i, nil 36 | } 37 | 38 | // GetCount return the int value of a flag with the given name 39 | func (f *FlagSet) GetCount(name string) (int, error) { 40 | val, err := f.getFlagType(name, "count", countConv) 41 | if err != nil { 42 | return 0, err 43 | } 44 | return val.(int), nil 45 | } 46 | 47 | // CountVar defines a count flag with specified name, default value, and usage string. 48 | // The argument p points to an int variable in which to store the value of the flag. 49 | // A count flag will add 1 to its value evey time it is found on the command line 50 | func (f *FlagSet) CountVar(p *int, name string, usage string) { 51 | f.CountVarP(p, name, "", usage) 52 | } 53 | 54 | // CountVarP is like CountVar only take a shorthand for the flag name. 55 | func (f *FlagSet) CountVarP(p *int, name, shorthand string, usage string) { 56 | flag := f.VarPF(newCountValue(0, p), name, shorthand, usage) 57 | flag.NoOptDefVal = "+1" 58 | } 59 | 60 | // CountVar like CountVar only the flag is placed on the CommandLine instead of a given flag set 61 | func CountVar(p *int, name string, usage string) { 62 | CommandLine.CountVar(p, name, usage) 63 | } 64 | 65 | // CountVarP is like CountVar only take a shorthand for the flag name. 66 | func CountVarP(p *int, name, shorthand string, usage string) { 67 | CommandLine.CountVarP(p, name, shorthand, usage) 68 | } 69 | 70 | // Count defines a count flag with specified name, default value, and usage string. 71 | // The return value is the address of an int variable that stores the value of the flag. 72 | // A count flag will add 1 to its value evey time it is found on the command line 73 | func (f *FlagSet) Count(name string, usage string) *int { 74 | p := new(int) 75 | f.CountVarP(p, name, "", usage) 76 | return p 77 | } 78 | 79 | // CountP is like Count only takes a shorthand for the flag name. 80 | func (f *FlagSet) CountP(name, shorthand string, usage string) *int { 81 | p := new(int) 82 | f.CountVarP(p, name, shorthand, usage) 83 | return p 84 | } 85 | 86 | // Count defines a count flag with specified name, default value, and usage string. 87 | // The return value is the address of an int variable that stores the value of the flag. 88 | // A count flag will add 1 to its value evey time it is found on the command line 89 | func Count(name string, usage string) *int { 90 | return CommandLine.CountP(name, "", usage) 91 | } 92 | 93 | // CountP is like Count only takes a shorthand for the flag name. 94 | func CountP(name, shorthand string, usage string) *int { 95 | return CommandLine.CountP(name, shorthand, usage) 96 | } 97 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/golangflag.go: -------------------------------------------------------------------------------- 1 | // Copyright 2009 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package pflag 6 | 7 | import ( 8 | goflag "flag" 9 | "reflect" 10 | "strings" 11 | ) 12 | 13 | // flagValueWrapper implements pflag.Value around a flag.Value. The main 14 | // difference here is the addition of the Type method that returns a string 15 | // name of the type. As this is generally unknown, we approximate that with 16 | // reflection. 17 | type flagValueWrapper struct { 18 | inner goflag.Value 19 | flagType string 20 | } 21 | 22 | // We are just copying the boolFlag interface out of goflag as that is what 23 | // they use to decide if a flag should get "true" when no arg is given. 24 | type goBoolFlag interface { 25 | goflag.Value 26 | IsBoolFlag() bool 27 | } 28 | 29 | func wrapFlagValue(v goflag.Value) Value { 30 | // If the flag.Value happens to also be a pflag.Value, just use it directly. 31 | if pv, ok := v.(Value); ok { 32 | return pv 33 | } 34 | 35 | pv := &flagValueWrapper{ 36 | inner: v, 37 | } 38 | 39 | t := reflect.TypeOf(v) 40 | if t.Kind() == reflect.Interface || t.Kind() == reflect.Ptr { 41 | t = t.Elem() 42 | } 43 | 44 | pv.flagType = strings.TrimSuffix(t.Name(), "Value") 45 | return pv 46 | } 47 | 48 | func (v *flagValueWrapper) String() string { 49 | return v.inner.String() 50 | } 51 | 52 | func (v *flagValueWrapper) Set(s string) error { 53 | return v.inner.Set(s) 54 | } 55 | 56 | func (v *flagValueWrapper) Type() string { 57 | return v.flagType 58 | } 59 | 60 | // PFlagFromGoFlag will return a *pflag.Flag given a *flag.Flag 61 | // If the *flag.Flag.Name was a single character (ex: `v`) it will be accessiblei 62 | // with both `-v` and `--v` in flags. If the golang flag was more than a single 63 | // character (ex: `verbose`) it will only be accessible via `--verbose` 64 | func PFlagFromGoFlag(goflag *goflag.Flag) *Flag { 65 | // Remember the default value as a string; it won't change. 66 | flag := &Flag{ 67 | Name: goflag.Name, 68 | Usage: goflag.Usage, 69 | Value: wrapFlagValue(goflag.Value), 70 | // Looks like golang flags don't set DefValue correctly :-( 71 | //DefValue: goflag.DefValue, 72 | DefValue: goflag.Value.String(), 73 | } 74 | // Ex: if the golang flag was -v, allow both -v and --v to work 75 | if len(flag.Name) == 1 { 76 | flag.Shorthand = flag.Name 77 | } 78 | if fv, ok := goflag.Value.(goBoolFlag); ok && fv.IsBoolFlag() { 79 | flag.NoOptDefVal = "true" 80 | } 81 | return flag 82 | } 83 | 84 | // AddGoFlag will add the given *flag.Flag to the pflag.FlagSet 85 | func (f *FlagSet) AddGoFlag(goflag *goflag.Flag) { 86 | if f.Lookup(goflag.Name) != nil { 87 | return 88 | } 89 | newflag := PFlagFromGoFlag(goflag) 90 | f.AddFlag(newflag) 91 | } 92 | 93 | // AddGoFlagSet will add the given *flag.FlagSet to the pflag.FlagSet 94 | func (f *FlagSet) AddGoFlagSet(newSet *goflag.FlagSet) { 95 | if newSet == nil { 96 | return 97 | } 98 | newSet.VisitAll(func(goflag *goflag.Flag) { 99 | f.AddGoFlag(goflag) 100 | }) 101 | if f.addedGoFlagSets == nil { 102 | f.addedGoFlagSets = make([]*goflag.FlagSet, 0) 103 | } 104 | f.addedGoFlagSets = append(f.addedGoFlagSets, newSet) 105 | } 106 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/uint8.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import "strconv" 4 | 5 | // -- uint8 Value 6 | type uint8Value uint8 7 | 8 | func newUint8Value(val uint8, p *uint8) *uint8Value { 9 | *p = val 10 | return (*uint8Value)(p) 11 | } 12 | 13 | func (i *uint8Value) Set(s string) error { 14 | v, err := strconv.ParseUint(s, 0, 8) 15 | *i = uint8Value(v) 16 | return err 17 | } 18 | 19 | func (i *uint8Value) Type() string { 20 | return "uint8" 21 | } 22 | 23 | func (i *uint8Value) String() string { return strconv.FormatUint(uint64(*i), 10) } 24 | 25 | func uint8Conv(sval string) (interface{}, error) { 26 | v, err := strconv.ParseUint(sval, 0, 8) 27 | if err != nil { 28 | return 0, err 29 | } 30 | return uint8(v), nil 31 | } 32 | 33 | // GetUint8 return the uint8 value of a flag with the given name 34 | func (f *FlagSet) GetUint8(name string) (uint8, error) { 35 | val, err := f.getFlagType(name, "uint8", uint8Conv) 36 | if err != nil { 37 | return 0, err 38 | } 39 | return val.(uint8), nil 40 | } 41 | 42 | // Uint8Var defines a uint8 flag with specified name, default value, and usage string. 43 | // The argument p points to a uint8 variable in which to store the value of the flag. 44 | func (f *FlagSet) Uint8Var(p *uint8, name string, value uint8, usage string) { 45 | f.VarP(newUint8Value(value, p), name, "", usage) 46 | } 47 | 48 | // Uint8VarP is like Uint8Var, but accepts a shorthand letter that can be used after a single dash. 49 | func (f *FlagSet) Uint8VarP(p *uint8, name, shorthand string, value uint8, usage string) { 50 | f.VarP(newUint8Value(value, p), name, shorthand, usage) 51 | } 52 | 53 | // Uint8Var defines a uint8 flag with specified name, default value, and usage string. 54 | // The argument p points to a uint8 variable in which to store the value of the flag. 55 | func Uint8Var(p *uint8, name string, value uint8, usage string) { 56 | CommandLine.VarP(newUint8Value(value, p), name, "", usage) 57 | } 58 | 59 | // Uint8VarP is like Uint8Var, but accepts a shorthand letter that can be used after a single dash. 60 | func Uint8VarP(p *uint8, name, shorthand string, value uint8, usage string) { 61 | CommandLine.VarP(newUint8Value(value, p), name, shorthand, usage) 62 | } 63 | 64 | // Uint8 defines a uint8 flag with specified name, default value, and usage string. 65 | // The return value is the address of a uint8 variable that stores the value of the flag. 66 | func (f *FlagSet) Uint8(name string, value uint8, usage string) *uint8 { 67 | p := new(uint8) 68 | f.Uint8VarP(p, name, "", value, usage) 69 | return p 70 | } 71 | 72 | // Uint8P is like Uint8, but accepts a shorthand letter that can be used after a single dash. 73 | func (f *FlagSet) Uint8P(name, shorthand string, value uint8, usage string) *uint8 { 74 | p := new(uint8) 75 | f.Uint8VarP(p, name, shorthand, value, usage) 76 | return p 77 | } 78 | 79 | // Uint8 defines a uint8 flag with specified name, default value, and usage string. 80 | // The return value is the address of a uint8 variable that stores the value of the flag. 81 | func Uint8(name string, value uint8, usage string) *uint8 { 82 | return CommandLine.Uint8P(name, "", value, usage) 83 | } 84 | 85 | // Uint8P is like Uint8, but accepts a shorthand letter that can be used after a single dash. 86 | func Uint8P(name, shorthand string, value uint8, usage string) *uint8 { 87 | return CommandLine.Uint8P(name, shorthand, value, usage) 88 | } 89 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/int16.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import "strconv" 4 | 5 | // -- int16 Value 6 | type int16Value int16 7 | 8 | func newInt16Value(val int16, p *int16) *int16Value { 9 | *p = val 10 | return (*int16Value)(p) 11 | } 12 | 13 | func (i *int16Value) Set(s string) error { 14 | v, err := strconv.ParseInt(s, 0, 16) 15 | *i = int16Value(v) 16 | return err 17 | } 18 | 19 | func (i *int16Value) Type() string { 20 | return "int16" 21 | } 22 | 23 | func (i *int16Value) String() string { return strconv.FormatInt(int64(*i), 10) } 24 | 25 | func int16Conv(sval string) (interface{}, error) { 26 | v, err := strconv.ParseInt(sval, 0, 16) 27 | if err != nil { 28 | return 0, err 29 | } 30 | return int16(v), nil 31 | } 32 | 33 | // GetInt16 returns the int16 value of a flag with the given name 34 | func (f *FlagSet) GetInt16(name string) (int16, error) { 35 | val, err := f.getFlagType(name, "int16", int16Conv) 36 | if err != nil { 37 | return 0, err 38 | } 39 | return val.(int16), nil 40 | } 41 | 42 | // Int16Var defines an int16 flag with specified name, default value, and usage string. 43 | // The argument p points to an int16 variable in which to store the value of the flag. 44 | func (f *FlagSet) Int16Var(p *int16, name string, value int16, usage string) { 45 | f.VarP(newInt16Value(value, p), name, "", usage) 46 | } 47 | 48 | // Int16VarP is like Int16Var, but accepts a shorthand letter that can be used after a single dash. 49 | func (f *FlagSet) Int16VarP(p *int16, name, shorthand string, value int16, usage string) { 50 | f.VarP(newInt16Value(value, p), name, shorthand, usage) 51 | } 52 | 53 | // Int16Var defines an int16 flag with specified name, default value, and usage string. 54 | // The argument p points to an int16 variable in which to store the value of the flag. 55 | func Int16Var(p *int16, name string, value int16, usage string) { 56 | CommandLine.VarP(newInt16Value(value, p), name, "", usage) 57 | } 58 | 59 | // Int16VarP is like Int16Var, but accepts a shorthand letter that can be used after a single dash. 60 | func Int16VarP(p *int16, name, shorthand string, value int16, usage string) { 61 | CommandLine.VarP(newInt16Value(value, p), name, shorthand, usage) 62 | } 63 | 64 | // Int16 defines an int16 flag with specified name, default value, and usage string. 65 | // The return value is the address of an int16 variable that stores the value of the flag. 66 | func (f *FlagSet) Int16(name string, value int16, usage string) *int16 { 67 | p := new(int16) 68 | f.Int16VarP(p, name, "", value, usage) 69 | return p 70 | } 71 | 72 | // Int16P is like Int16, but accepts a shorthand letter that can be used after a single dash. 73 | func (f *FlagSet) Int16P(name, shorthand string, value int16, usage string) *int16 { 74 | p := new(int16) 75 | f.Int16VarP(p, name, shorthand, value, usage) 76 | return p 77 | } 78 | 79 | // Int16 defines an int16 flag with specified name, default value, and usage string. 80 | // The return value is the address of an int16 variable that stores the value of the flag. 81 | func Int16(name string, value int16, usage string) *int16 { 82 | return CommandLine.Int16P(name, "", value, usage) 83 | } 84 | 85 | // Int16P is like Int16, but accepts a shorthand letter that can be used after a single dash. 86 | func Int16P(name, shorthand string, value int16, usage string) *int16 { 87 | return CommandLine.Int16P(name, shorthand, value, usage) 88 | } 89 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/int32.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import "strconv" 4 | 5 | // -- int32 Value 6 | type int32Value int32 7 | 8 | func newInt32Value(val int32, p *int32) *int32Value { 9 | *p = val 10 | return (*int32Value)(p) 11 | } 12 | 13 | func (i *int32Value) Set(s string) error { 14 | v, err := strconv.ParseInt(s, 0, 32) 15 | *i = int32Value(v) 16 | return err 17 | } 18 | 19 | func (i *int32Value) Type() string { 20 | return "int32" 21 | } 22 | 23 | func (i *int32Value) String() string { return strconv.FormatInt(int64(*i), 10) } 24 | 25 | func int32Conv(sval string) (interface{}, error) { 26 | v, err := strconv.ParseInt(sval, 0, 32) 27 | if err != nil { 28 | return 0, err 29 | } 30 | return int32(v), nil 31 | } 32 | 33 | // GetInt32 return the int32 value of a flag with the given name 34 | func (f *FlagSet) GetInt32(name string) (int32, error) { 35 | val, err := f.getFlagType(name, "int32", int32Conv) 36 | if err != nil { 37 | return 0, err 38 | } 39 | return val.(int32), nil 40 | } 41 | 42 | // Int32Var defines an int32 flag with specified name, default value, and usage string. 43 | // The argument p points to an int32 variable in which to store the value of the flag. 44 | func (f *FlagSet) Int32Var(p *int32, name string, value int32, usage string) { 45 | f.VarP(newInt32Value(value, p), name, "", usage) 46 | } 47 | 48 | // Int32VarP is like Int32Var, but accepts a shorthand letter that can be used after a single dash. 49 | func (f *FlagSet) Int32VarP(p *int32, name, shorthand string, value int32, usage string) { 50 | f.VarP(newInt32Value(value, p), name, shorthand, usage) 51 | } 52 | 53 | // Int32Var defines an int32 flag with specified name, default value, and usage string. 54 | // The argument p points to an int32 variable in which to store the value of the flag. 55 | func Int32Var(p *int32, name string, value int32, usage string) { 56 | CommandLine.VarP(newInt32Value(value, p), name, "", usage) 57 | } 58 | 59 | // Int32VarP is like Int32Var, but accepts a shorthand letter that can be used after a single dash. 60 | func Int32VarP(p *int32, name, shorthand string, value int32, usage string) { 61 | CommandLine.VarP(newInt32Value(value, p), name, shorthand, usage) 62 | } 63 | 64 | // Int32 defines an int32 flag with specified name, default value, and usage string. 65 | // The return value is the address of an int32 variable that stores the value of the flag. 66 | func (f *FlagSet) Int32(name string, value int32, usage string) *int32 { 67 | p := new(int32) 68 | f.Int32VarP(p, name, "", value, usage) 69 | return p 70 | } 71 | 72 | // Int32P is like Int32, but accepts a shorthand letter that can be used after a single dash. 73 | func (f *FlagSet) Int32P(name, shorthand string, value int32, usage string) *int32 { 74 | p := new(int32) 75 | f.Int32VarP(p, name, shorthand, value, usage) 76 | return p 77 | } 78 | 79 | // Int32 defines an int32 flag with specified name, default value, and usage string. 80 | // The return value is the address of an int32 variable that stores the value of the flag. 81 | func Int32(name string, value int32, usage string) *int32 { 82 | return CommandLine.Int32P(name, "", value, usage) 83 | } 84 | 85 | // Int32P is like Int32, but accepts a shorthand letter that can be used after a single dash. 86 | func Int32P(name, shorthand string, value int32, usage string) *int32 { 87 | return CommandLine.Int32P(name, shorthand, value, usage) 88 | } 89 | -------------------------------------------------------------------------------- /vendor/github.com/google/skylark/syntax/walk.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 The Bazel Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package syntax 6 | 7 | // Walk traverses a syntax tree in depth-first order. 8 | // It starts by calling f(n); n must not be nil. 9 | // If f returns true, Walk calls itself 10 | // recursively for each non-nil child of n. 11 | // Walk then calls f(nil). 12 | func Walk(n Node, f func(Node) bool) { 13 | if !f(n) { 14 | return 15 | } 16 | 17 | // TODO(adonovan): opt: order cases using profile data. 18 | switch n := n.(type) { 19 | case *File: 20 | walkStmts(n.Stmts, f) 21 | 22 | case *ExprStmt: 23 | Walk(n.X, f) 24 | 25 | case *BranchStmt: 26 | // no-op 27 | 28 | case *IfStmt: 29 | Walk(n.Cond, f) 30 | walkStmts(n.True, f) 31 | walkStmts(n.False, f) 32 | 33 | case *AssignStmt: 34 | Walk(n.RHS, f) 35 | Walk(n.LHS, f) 36 | 37 | case *DefStmt: 38 | Walk(n.Name, f) 39 | for _, param := range n.Function.Params { 40 | Walk(param, f) 41 | } 42 | walkStmts(n.Function.Body, f) 43 | 44 | case *ForStmt: 45 | Walk(n.Vars, f) 46 | Walk(n.X, f) 47 | walkStmts(n.Body, f) 48 | 49 | case *ReturnStmt: 50 | if n.Result != nil { 51 | Walk(n.Result, f) 52 | } 53 | 54 | case *LoadStmt: 55 | Walk(n.Module, f) 56 | for _, from := range n.From { 57 | Walk(from, f) 58 | } 59 | for _, to := range n.To { 60 | Walk(to, f) 61 | } 62 | 63 | case *Ident, *Literal: 64 | // no-op 65 | 66 | case *ListExpr: 67 | for _, x := range n.List { 68 | Walk(x, f) 69 | } 70 | 71 | case *ParenExpr: 72 | Walk(n.X, f) 73 | 74 | case *CondExpr: 75 | Walk(n.Cond, f) 76 | Walk(n.True, f) 77 | Walk(n.False, f) 78 | 79 | case *IndexExpr: 80 | Walk(n.X, f) 81 | Walk(n.Y, f) 82 | 83 | case *DictEntry: 84 | Walk(n.Key, f) 85 | Walk(n.Value, f) 86 | 87 | case *SliceExpr: 88 | Walk(n.X, f) 89 | if n.Lo != nil { 90 | Walk(n.Lo, f) 91 | } 92 | if n.Hi != nil { 93 | Walk(n.Hi, f) 94 | } 95 | if n.Step != nil { 96 | Walk(n.Step, f) 97 | } 98 | 99 | case *Comprehension: 100 | for _, clause := range n.Clauses { 101 | Walk(clause, f) 102 | } 103 | Walk(n.Body, f) 104 | 105 | case *IfClause: 106 | Walk(n.Cond, f) 107 | 108 | case *ForClause: 109 | Walk(n.Vars, f) 110 | Walk(n.X, f) 111 | 112 | case *TupleExpr: 113 | for _, x := range n.List { 114 | Walk(x, f) 115 | } 116 | 117 | case *DictExpr: 118 | for _, entry := range n.List { 119 | entry := entry.(*DictEntry) 120 | Walk(entry.Key, f) 121 | Walk(entry.Value, f) 122 | } 123 | 124 | case *UnaryExpr: 125 | Walk(n.X, f) 126 | 127 | case *BinaryExpr: 128 | Walk(n.X, f) 129 | Walk(n.Y, f) 130 | 131 | case *DotExpr: 132 | Walk(n.X, f) 133 | Walk(n.Name, f) 134 | 135 | case *CallExpr: 136 | Walk(n.Fn, f) 137 | for _, arg := range n.Args { 138 | Walk(arg, f) 139 | } 140 | 141 | case *LambdaExpr: 142 | for _, param := range n.Function.Params { 143 | Walk(param, f) 144 | } 145 | walkStmts(n.Function.Body, f) 146 | 147 | default: 148 | panic(n) 149 | } 150 | 151 | f(nil) 152 | } 153 | 154 | func walkStmts(stmts []Stmt, f func(Node) bool) { 155 | for _, stmt := range stmts { 156 | Walk(stmt, f) 157 | } 158 | } 159 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/common/model/silence.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Prometheus Authors 2 | // Licensed under the Apache License, Version 2.0 (the "License"); 3 | // you may not use this file except in compliance with the License. 4 | // You may obtain a copy of the License at 5 | // 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | 14 | package model 15 | 16 | import ( 17 | "encoding/json" 18 | "fmt" 19 | "regexp" 20 | "time" 21 | ) 22 | 23 | // Matcher describes a matches the value of a given label. 24 | type Matcher struct { 25 | Name LabelName `json:"name"` 26 | Value string `json:"value"` 27 | IsRegex bool `json:"isRegex"` 28 | } 29 | 30 | func (m *Matcher) UnmarshalJSON(b []byte) error { 31 | type plain Matcher 32 | if err := json.Unmarshal(b, (*plain)(m)); err != nil { 33 | return err 34 | } 35 | 36 | if len(m.Name) == 0 { 37 | return fmt.Errorf("label name in matcher must not be empty") 38 | } 39 | if m.IsRegex { 40 | if _, err := regexp.Compile(m.Value); err != nil { 41 | return err 42 | } 43 | } 44 | return nil 45 | } 46 | 47 | // Validate returns true iff all fields of the matcher have valid values. 48 | func (m *Matcher) Validate() error { 49 | if !m.Name.IsValid() { 50 | return fmt.Errorf("invalid name %q", m.Name) 51 | } 52 | if m.IsRegex { 53 | if _, err := regexp.Compile(m.Value); err != nil { 54 | return fmt.Errorf("invalid regular expression %q", m.Value) 55 | } 56 | } else if !LabelValue(m.Value).IsValid() || len(m.Value) == 0 { 57 | return fmt.Errorf("invalid value %q", m.Value) 58 | } 59 | return nil 60 | } 61 | 62 | // Silence defines the representation of a silence definition in the Prometheus 63 | // eco-system. 64 | type Silence struct { 65 | ID uint64 `json:"id,omitempty"` 66 | 67 | Matchers []*Matcher `json:"matchers"` 68 | 69 | StartsAt time.Time `json:"startsAt"` 70 | EndsAt time.Time `json:"endsAt"` 71 | 72 | CreatedAt time.Time `json:"createdAt,omitempty"` 73 | CreatedBy string `json:"createdBy"` 74 | Comment string `json:"comment,omitempty"` 75 | } 76 | 77 | // Validate returns true iff all fields of the silence have valid values. 78 | func (s *Silence) Validate() error { 79 | if len(s.Matchers) == 0 { 80 | return fmt.Errorf("at least one matcher required") 81 | } 82 | for _, m := range s.Matchers { 83 | if err := m.Validate(); err != nil { 84 | return fmt.Errorf("invalid matcher: %s", err) 85 | } 86 | } 87 | if s.StartsAt.IsZero() { 88 | return fmt.Errorf("start time missing") 89 | } 90 | if s.EndsAt.IsZero() { 91 | return fmt.Errorf("end time missing") 92 | } 93 | if s.EndsAt.Before(s.StartsAt) { 94 | return fmt.Errorf("start time must be before end time") 95 | } 96 | if s.CreatedBy == "" { 97 | return fmt.Errorf("creator information missing") 98 | } 99 | if s.Comment == "" { 100 | return fmt.Errorf("comment missing") 101 | } 102 | if s.CreatedAt.IsZero() { 103 | return fmt.Errorf("creation timestamp missing") 104 | } 105 | return nil 106 | } 107 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/cobra/zsh_completions.go: -------------------------------------------------------------------------------- 1 | package cobra 2 | 3 | import ( 4 | "bytes" 5 | "fmt" 6 | "io" 7 | "os" 8 | "strings" 9 | ) 10 | 11 | // GenZshCompletionFile generates zsh completion file. 12 | func (c *Command) GenZshCompletionFile(filename string) error { 13 | outFile, err := os.Create(filename) 14 | if err != nil { 15 | return err 16 | } 17 | defer outFile.Close() 18 | 19 | return c.GenZshCompletion(outFile) 20 | } 21 | 22 | // GenZshCompletion generates a zsh completion file and writes to the passed writer. 23 | func (c *Command) GenZshCompletion(w io.Writer) error { 24 | buf := new(bytes.Buffer) 25 | 26 | writeHeader(buf, c) 27 | maxDepth := maxDepth(c) 28 | writeLevelMapping(buf, maxDepth) 29 | writeLevelCases(buf, maxDepth, c) 30 | 31 | _, err := buf.WriteTo(w) 32 | return err 33 | } 34 | 35 | func writeHeader(w io.Writer, cmd *Command) { 36 | fmt.Fprintf(w, "#compdef %s\n\n", cmd.Name()) 37 | } 38 | 39 | func maxDepth(c *Command) int { 40 | if len(c.Commands()) == 0 { 41 | return 0 42 | } 43 | maxDepthSub := 0 44 | for _, s := range c.Commands() { 45 | subDepth := maxDepth(s) 46 | if subDepth > maxDepthSub { 47 | maxDepthSub = subDepth 48 | } 49 | } 50 | return 1 + maxDepthSub 51 | } 52 | 53 | func writeLevelMapping(w io.Writer, numLevels int) { 54 | fmt.Fprintln(w, `_arguments \`) 55 | for i := 1; i <= numLevels; i++ { 56 | fmt.Fprintf(w, ` '%d: :->level%d' \`, i, i) 57 | fmt.Fprintln(w) 58 | } 59 | fmt.Fprintf(w, ` '%d: :%s'`, numLevels+1, "_files") 60 | fmt.Fprintln(w) 61 | } 62 | 63 | func writeLevelCases(w io.Writer, maxDepth int, root *Command) { 64 | fmt.Fprintln(w, "case $state in") 65 | defer fmt.Fprintln(w, "esac") 66 | 67 | for i := 1; i <= maxDepth; i++ { 68 | fmt.Fprintf(w, " level%d)\n", i) 69 | writeLevel(w, root, i) 70 | fmt.Fprintln(w, " ;;") 71 | } 72 | fmt.Fprintln(w, " *)") 73 | fmt.Fprintln(w, " _arguments '*: :_files'") 74 | fmt.Fprintln(w, " ;;") 75 | } 76 | 77 | func writeLevel(w io.Writer, root *Command, i int) { 78 | fmt.Fprintf(w, " case $words[%d] in\n", i) 79 | defer fmt.Fprintln(w, " esac") 80 | 81 | commands := filterByLevel(root, i) 82 | byParent := groupByParent(commands) 83 | 84 | for p, c := range byParent { 85 | names := names(c) 86 | fmt.Fprintf(w, " %s)\n", p) 87 | fmt.Fprintf(w, " _arguments '%d: :(%s)'\n", i, strings.Join(names, " ")) 88 | fmt.Fprintln(w, " ;;") 89 | } 90 | fmt.Fprintln(w, " *)") 91 | fmt.Fprintln(w, " _arguments '*: :_files'") 92 | fmt.Fprintln(w, " ;;") 93 | 94 | } 95 | 96 | func filterByLevel(c *Command, l int) []*Command { 97 | cs := make([]*Command, 0) 98 | if l == 0 { 99 | cs = append(cs, c) 100 | return cs 101 | } 102 | for _, s := range c.Commands() { 103 | cs = append(cs, filterByLevel(s, l-1)...) 104 | } 105 | return cs 106 | } 107 | 108 | func groupByParent(commands []*Command) map[string][]*Command { 109 | m := make(map[string][]*Command) 110 | for _, c := range commands { 111 | parent := c.Parent() 112 | if parent == nil { 113 | continue 114 | } 115 | m[parent.Name()] = append(m[parent.Name()], c) 116 | } 117 | return m 118 | } 119 | 120 | func names(commands []*Command) []string { 121 | ns := make([]string, len(commands)) 122 | for i, c := range commands { 123 | ns[i] = c.Name() 124 | } 125 | return ns 126 | } 127 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/ip.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import ( 4 | "fmt" 5 | "net" 6 | "strings" 7 | ) 8 | 9 | // -- net.IP value 10 | type ipValue net.IP 11 | 12 | func newIPValue(val net.IP, p *net.IP) *ipValue { 13 | *p = val 14 | return (*ipValue)(p) 15 | } 16 | 17 | func (i *ipValue) String() string { return net.IP(*i).String() } 18 | func (i *ipValue) Set(s string) error { 19 | ip := net.ParseIP(strings.TrimSpace(s)) 20 | if ip == nil { 21 | return fmt.Errorf("failed to parse IP: %q", s) 22 | } 23 | *i = ipValue(ip) 24 | return nil 25 | } 26 | 27 | func (i *ipValue) Type() string { 28 | return "ip" 29 | } 30 | 31 | func ipConv(sval string) (interface{}, error) { 32 | ip := net.ParseIP(sval) 33 | if ip != nil { 34 | return ip, nil 35 | } 36 | return nil, fmt.Errorf("invalid string being converted to IP address: %s", sval) 37 | } 38 | 39 | // GetIP return the net.IP value of a flag with the given name 40 | func (f *FlagSet) GetIP(name string) (net.IP, error) { 41 | val, err := f.getFlagType(name, "ip", ipConv) 42 | if err != nil { 43 | return nil, err 44 | } 45 | return val.(net.IP), nil 46 | } 47 | 48 | // IPVar defines an net.IP flag with specified name, default value, and usage string. 49 | // The argument p points to an net.IP variable in which to store the value of the flag. 50 | func (f *FlagSet) IPVar(p *net.IP, name string, value net.IP, usage string) { 51 | f.VarP(newIPValue(value, p), name, "", usage) 52 | } 53 | 54 | // IPVarP is like IPVar, but accepts a shorthand letter that can be used after a single dash. 55 | func (f *FlagSet) IPVarP(p *net.IP, name, shorthand string, value net.IP, usage string) { 56 | f.VarP(newIPValue(value, p), name, shorthand, usage) 57 | } 58 | 59 | // IPVar defines an net.IP flag with specified name, default value, and usage string. 60 | // The argument p points to an net.IP variable in which to store the value of the flag. 61 | func IPVar(p *net.IP, name string, value net.IP, usage string) { 62 | CommandLine.VarP(newIPValue(value, p), name, "", usage) 63 | } 64 | 65 | // IPVarP is like IPVar, but accepts a shorthand letter that can be used after a single dash. 66 | func IPVarP(p *net.IP, name, shorthand string, value net.IP, usage string) { 67 | CommandLine.VarP(newIPValue(value, p), name, shorthand, usage) 68 | } 69 | 70 | // IP defines an net.IP flag with specified name, default value, and usage string. 71 | // The return value is the address of an net.IP variable that stores the value of the flag. 72 | func (f *FlagSet) IP(name string, value net.IP, usage string) *net.IP { 73 | p := new(net.IP) 74 | f.IPVarP(p, name, "", value, usage) 75 | return p 76 | } 77 | 78 | // IPP is like IP, but accepts a shorthand letter that can be used after a single dash. 79 | func (f *FlagSet) IPP(name, shorthand string, value net.IP, usage string) *net.IP { 80 | p := new(net.IP) 81 | f.IPVarP(p, name, shorthand, value, usage) 82 | return p 83 | } 84 | 85 | // IP defines an net.IP flag with specified name, default value, and usage string. 86 | // The return value is the address of an net.IP variable that stores the value of the flag. 87 | func IP(name string, value net.IP, usage string) *net.IP { 88 | return CommandLine.IPP(name, "", value, usage) 89 | } 90 | 91 | // IPP is like IP, but accepts a shorthand letter that can be used after a single dash. 92 | func IPP(name, shorthand string, value net.IP, usage string) *net.IP { 93 | return CommandLine.IPP(name, shorthand, value, usage) 94 | } 95 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/uint16.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import "strconv" 4 | 5 | // -- uint16 value 6 | type uint16Value uint16 7 | 8 | func newUint16Value(val uint16, p *uint16) *uint16Value { 9 | *p = val 10 | return (*uint16Value)(p) 11 | } 12 | 13 | func (i *uint16Value) Set(s string) error { 14 | v, err := strconv.ParseUint(s, 0, 16) 15 | *i = uint16Value(v) 16 | return err 17 | } 18 | 19 | func (i *uint16Value) Type() string { 20 | return "uint16" 21 | } 22 | 23 | func (i *uint16Value) String() string { return strconv.FormatUint(uint64(*i), 10) } 24 | 25 | func uint16Conv(sval string) (interface{}, error) { 26 | v, err := strconv.ParseUint(sval, 0, 16) 27 | if err != nil { 28 | return 0, err 29 | } 30 | return uint16(v), nil 31 | } 32 | 33 | // GetUint16 return the uint16 value of a flag with the given name 34 | func (f *FlagSet) GetUint16(name string) (uint16, error) { 35 | val, err := f.getFlagType(name, "uint16", uint16Conv) 36 | if err != nil { 37 | return 0, err 38 | } 39 | return val.(uint16), nil 40 | } 41 | 42 | // Uint16Var defines a uint flag with specified name, default value, and usage string. 43 | // The argument p points to a uint variable in which to store the value of the flag. 44 | func (f *FlagSet) Uint16Var(p *uint16, name string, value uint16, usage string) { 45 | f.VarP(newUint16Value(value, p), name, "", usage) 46 | } 47 | 48 | // Uint16VarP is like Uint16Var, but accepts a shorthand letter that can be used after a single dash. 49 | func (f *FlagSet) Uint16VarP(p *uint16, name, shorthand string, value uint16, usage string) { 50 | f.VarP(newUint16Value(value, p), name, shorthand, usage) 51 | } 52 | 53 | // Uint16Var defines a uint flag with specified name, default value, and usage string. 54 | // The argument p points to a uint variable in which to store the value of the flag. 55 | func Uint16Var(p *uint16, name string, value uint16, usage string) { 56 | CommandLine.VarP(newUint16Value(value, p), name, "", usage) 57 | } 58 | 59 | // Uint16VarP is like Uint16Var, but accepts a shorthand letter that can be used after a single dash. 60 | func Uint16VarP(p *uint16, name, shorthand string, value uint16, usage string) { 61 | CommandLine.VarP(newUint16Value(value, p), name, shorthand, usage) 62 | } 63 | 64 | // Uint16 defines a uint flag with specified name, default value, and usage string. 65 | // The return value is the address of a uint variable that stores the value of the flag. 66 | func (f *FlagSet) Uint16(name string, value uint16, usage string) *uint16 { 67 | p := new(uint16) 68 | f.Uint16VarP(p, name, "", value, usage) 69 | return p 70 | } 71 | 72 | // Uint16P is like Uint16, but accepts a shorthand letter that can be used after a single dash. 73 | func (f *FlagSet) Uint16P(name, shorthand string, value uint16, usage string) *uint16 { 74 | p := new(uint16) 75 | f.Uint16VarP(p, name, shorthand, value, usage) 76 | return p 77 | } 78 | 79 | // Uint16 defines a uint flag with specified name, default value, and usage string. 80 | // The return value is the address of a uint variable that stores the value of the flag. 81 | func Uint16(name string, value uint16, usage string) *uint16 { 82 | return CommandLine.Uint16P(name, "", value, usage) 83 | } 84 | 85 | // Uint16P is like Uint16, but accepts a shorthand letter that can be used after a single dash. 86 | func Uint16P(name, shorthand string, value uint16, usage string) *uint16 { 87 | return CommandLine.Uint16P(name, shorthand, value, usage) 88 | } 89 | -------------------------------------------------------------------------------- /vendor/github.com/heptiolabs/healthcheck/checks.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 by the contributors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package healthcheck 16 | 17 | import ( 18 | "context" 19 | "database/sql" 20 | "fmt" 21 | "net" 22 | "net/http" 23 | "runtime" 24 | "time" 25 | ) 26 | 27 | // TCPDialCheck returns a Check that checks TCP connectivity to the provided 28 | // endpoint. 29 | func TCPDialCheck(addr string, timeout time.Duration) Check { 30 | return func() error { 31 | conn, err := net.DialTimeout("tcp", addr, timeout) 32 | if err != nil { 33 | return err 34 | } 35 | return conn.Close() 36 | } 37 | } 38 | 39 | // HTTPGetCheck returns a Check that performs an HTTP GET request against the 40 | // specified URL. The check fails if the response times out or returns a non-200 41 | // status code. 42 | func HTTPGetCheck(url string, timeout time.Duration) Check { 43 | client := http.Client{ 44 | Timeout: timeout, 45 | // never follow redirects 46 | CheckRedirect: func(*http.Request, []*http.Request) error { 47 | return http.ErrUseLastResponse 48 | }, 49 | } 50 | return func() error { 51 | resp, err := client.Get(url) 52 | if err != nil { 53 | return err 54 | } 55 | resp.Body.Close() 56 | if resp.StatusCode != 200 { 57 | return fmt.Errorf("returned status %d", resp.StatusCode) 58 | } 59 | return nil 60 | } 61 | } 62 | 63 | // DatabasePingCheck returns a Check that validates connectivity to a 64 | // database/sql.DB using Ping(). 65 | func DatabasePingCheck(database *sql.DB, timeout time.Duration) Check { 66 | return func() error { 67 | ctx, cancel := context.WithTimeout(context.Background(), timeout) 68 | defer cancel() 69 | if database == nil { 70 | return fmt.Errorf("database is nil") 71 | } 72 | return database.PingContext(ctx) 73 | } 74 | } 75 | 76 | // DNSResolveCheck returns a Check that makes sure the provided host can resolve 77 | // to at least one IP address within the specified timeout. 78 | func DNSResolveCheck(host string, timeout time.Duration) Check { 79 | resolver := net.Resolver{} 80 | return func() error { 81 | ctx, cancel := context.WithTimeout(context.Background(), timeout) 82 | defer cancel() 83 | addrs, err := resolver.LookupHost(ctx, host) 84 | if err != nil { 85 | return err 86 | } 87 | if len(addrs) < 1 { 88 | return fmt.Errorf("could not resolve host") 89 | } 90 | return nil 91 | } 92 | } 93 | 94 | // GoroutineCountCheck returns a Check that fails if too many goroutines are 95 | // running (which could indicate a resource leak). 96 | func GoroutineCountCheck(threshold int) Check { 97 | return func() error { 98 | count := runtime.NumGoroutine() 99 | if count > threshold { 100 | return fmt.Errorf("too many goroutines (%d > %d)", count, threshold) 101 | } 102 | return nil 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/common/model/metric.go: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Prometheus Authors 2 | // Licensed under the Apache License, Version 2.0 (the "License"); 3 | // you may not use this file except in compliance with the License. 4 | // You may obtain a copy of the License at 5 | // 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | 14 | package model 15 | 16 | import ( 17 | "fmt" 18 | "regexp" 19 | "sort" 20 | "strings" 21 | ) 22 | 23 | var ( 24 | separator = []byte{0} 25 | // MetricNameRE is a regular expression matching valid metric 26 | // names. Note that the IsValidMetricName function performs the same 27 | // check but faster than a match with this regular expression. 28 | MetricNameRE = regexp.MustCompile(`^[a-zA-Z_:][a-zA-Z0-9_:]*$`) 29 | ) 30 | 31 | // A Metric is similar to a LabelSet, but the key difference is that a Metric is 32 | // a singleton and refers to one and only one stream of samples. 33 | type Metric LabelSet 34 | 35 | // Equal compares the metrics. 36 | func (m Metric) Equal(o Metric) bool { 37 | return LabelSet(m).Equal(LabelSet(o)) 38 | } 39 | 40 | // Before compares the metrics' underlying label sets. 41 | func (m Metric) Before(o Metric) bool { 42 | return LabelSet(m).Before(LabelSet(o)) 43 | } 44 | 45 | // Clone returns a copy of the Metric. 46 | func (m Metric) Clone() Metric { 47 | clone := make(Metric, len(m)) 48 | for k, v := range m { 49 | clone[k] = v 50 | } 51 | return clone 52 | } 53 | 54 | func (m Metric) String() string { 55 | metricName, hasName := m[MetricNameLabel] 56 | numLabels := len(m) - 1 57 | if !hasName { 58 | numLabels = len(m) 59 | } 60 | labelStrings := make([]string, 0, numLabels) 61 | for label, value := range m { 62 | if label != MetricNameLabel { 63 | labelStrings = append(labelStrings, fmt.Sprintf("%s=%q", label, value)) 64 | } 65 | } 66 | 67 | switch numLabels { 68 | case 0: 69 | if hasName { 70 | return string(metricName) 71 | } 72 | return "{}" 73 | default: 74 | sort.Strings(labelStrings) 75 | return fmt.Sprintf("%s{%s}", metricName, strings.Join(labelStrings, ", ")) 76 | } 77 | } 78 | 79 | // Fingerprint returns a Metric's Fingerprint. 80 | func (m Metric) Fingerprint() Fingerprint { 81 | return LabelSet(m).Fingerprint() 82 | } 83 | 84 | // FastFingerprint returns a Metric's Fingerprint calculated by a faster hashing 85 | // algorithm, which is, however, more susceptible to hash collisions. 86 | func (m Metric) FastFingerprint() Fingerprint { 87 | return LabelSet(m).FastFingerprint() 88 | } 89 | 90 | // IsValidMetricName returns true iff name matches the pattern of MetricNameRE. 91 | // This function, however, does not use MetricNameRE for the check but a much 92 | // faster hardcoded implementation. 93 | func IsValidMetricName(n LabelValue) bool { 94 | if len(n) == 0 { 95 | return false 96 | } 97 | for i, b := range n { 98 | if !((b >= 'a' && b <= 'z') || (b >= 'A' && b <= 'Z') || b == '_' || b == ':' || (b >= '0' && b <= '9' && i > 0)) { 99 | return false 100 | } 101 | } 102 | return true 103 | } 104 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/float64.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import "strconv" 4 | 5 | // -- float64 Value 6 | type float64Value float64 7 | 8 | func newFloat64Value(val float64, p *float64) *float64Value { 9 | *p = val 10 | return (*float64Value)(p) 11 | } 12 | 13 | func (f *float64Value) Set(s string) error { 14 | v, err := strconv.ParseFloat(s, 64) 15 | *f = float64Value(v) 16 | return err 17 | } 18 | 19 | func (f *float64Value) Type() string { 20 | return "float64" 21 | } 22 | 23 | func (f *float64Value) String() string { return strconv.FormatFloat(float64(*f), 'g', -1, 64) } 24 | 25 | func float64Conv(sval string) (interface{}, error) { 26 | return strconv.ParseFloat(sval, 64) 27 | } 28 | 29 | // GetFloat64 return the float64 value of a flag with the given name 30 | func (f *FlagSet) GetFloat64(name string) (float64, error) { 31 | val, err := f.getFlagType(name, "float64", float64Conv) 32 | if err != nil { 33 | return 0, err 34 | } 35 | return val.(float64), nil 36 | } 37 | 38 | // Float64Var defines a float64 flag with specified name, default value, and usage string. 39 | // The argument p points to a float64 variable in which to store the value of the flag. 40 | func (f *FlagSet) Float64Var(p *float64, name string, value float64, usage string) { 41 | f.VarP(newFloat64Value(value, p), name, "", usage) 42 | } 43 | 44 | // Float64VarP is like Float64Var, but accepts a shorthand letter that can be used after a single dash. 45 | func (f *FlagSet) Float64VarP(p *float64, name, shorthand string, value float64, usage string) { 46 | f.VarP(newFloat64Value(value, p), name, shorthand, usage) 47 | } 48 | 49 | // Float64Var defines a float64 flag with specified name, default value, and usage string. 50 | // The argument p points to a float64 variable in which to store the value of the flag. 51 | func Float64Var(p *float64, name string, value float64, usage string) { 52 | CommandLine.VarP(newFloat64Value(value, p), name, "", usage) 53 | } 54 | 55 | // Float64VarP is like Float64Var, but accepts a shorthand letter that can be used after a single dash. 56 | func Float64VarP(p *float64, name, shorthand string, value float64, usage string) { 57 | CommandLine.VarP(newFloat64Value(value, p), name, shorthand, usage) 58 | } 59 | 60 | // Float64 defines a float64 flag with specified name, default value, and usage string. 61 | // The return value is the address of a float64 variable that stores the value of the flag. 62 | func (f *FlagSet) Float64(name string, value float64, usage string) *float64 { 63 | p := new(float64) 64 | f.Float64VarP(p, name, "", value, usage) 65 | return p 66 | } 67 | 68 | // Float64P is like Float64, but accepts a shorthand letter that can be used after a single dash. 69 | func (f *FlagSet) Float64P(name, shorthand string, value float64, usage string) *float64 { 70 | p := new(float64) 71 | f.Float64VarP(p, name, shorthand, value, usage) 72 | return p 73 | } 74 | 75 | // Float64 defines a float64 flag with specified name, default value, and usage string. 76 | // The return value is the address of a float64 variable that stores the value of the flag. 77 | func Float64(name string, value float64, usage string) *float64 { 78 | return CommandLine.Float64P(name, "", value, usage) 79 | } 80 | 81 | // Float64P is like Float64, but accepts a shorthand letter that can be used after a single dash. 82 | func Float64P(name, shorthand string, value float64, usage string) *float64 { 83 | return CommandLine.Float64P(name, shorthand, value, usage) 84 | } 85 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/uint32.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import "strconv" 4 | 5 | // -- uint32 value 6 | type uint32Value uint32 7 | 8 | func newUint32Value(val uint32, p *uint32) *uint32Value { 9 | *p = val 10 | return (*uint32Value)(p) 11 | } 12 | 13 | func (i *uint32Value) Set(s string) error { 14 | v, err := strconv.ParseUint(s, 0, 32) 15 | *i = uint32Value(v) 16 | return err 17 | } 18 | 19 | func (i *uint32Value) Type() string { 20 | return "uint32" 21 | } 22 | 23 | func (i *uint32Value) String() string { return strconv.FormatUint(uint64(*i), 10) } 24 | 25 | func uint32Conv(sval string) (interface{}, error) { 26 | v, err := strconv.ParseUint(sval, 0, 32) 27 | if err != nil { 28 | return 0, err 29 | } 30 | return uint32(v), nil 31 | } 32 | 33 | // GetUint32 return the uint32 value of a flag with the given name 34 | func (f *FlagSet) GetUint32(name string) (uint32, error) { 35 | val, err := f.getFlagType(name, "uint32", uint32Conv) 36 | if err != nil { 37 | return 0, err 38 | } 39 | return val.(uint32), nil 40 | } 41 | 42 | // Uint32Var defines a uint32 flag with specified name, default value, and usage string. 43 | // The argument p points to a uint32 variable in which to store the value of the flag. 44 | func (f *FlagSet) Uint32Var(p *uint32, name string, value uint32, usage string) { 45 | f.VarP(newUint32Value(value, p), name, "", usage) 46 | } 47 | 48 | // Uint32VarP is like Uint32Var, but accepts a shorthand letter that can be used after a single dash. 49 | func (f *FlagSet) Uint32VarP(p *uint32, name, shorthand string, value uint32, usage string) { 50 | f.VarP(newUint32Value(value, p), name, shorthand, usage) 51 | } 52 | 53 | // Uint32Var defines a uint32 flag with specified name, default value, and usage string. 54 | // The argument p points to a uint32 variable in which to store the value of the flag. 55 | func Uint32Var(p *uint32, name string, value uint32, usage string) { 56 | CommandLine.VarP(newUint32Value(value, p), name, "", usage) 57 | } 58 | 59 | // Uint32VarP is like Uint32Var, but accepts a shorthand letter that can be used after a single dash. 60 | func Uint32VarP(p *uint32, name, shorthand string, value uint32, usage string) { 61 | CommandLine.VarP(newUint32Value(value, p), name, shorthand, usage) 62 | } 63 | 64 | // Uint32 defines a uint32 flag with specified name, default value, and usage string. 65 | // The return value is the address of a uint32 variable that stores the value of the flag. 66 | func (f *FlagSet) Uint32(name string, value uint32, usage string) *uint32 { 67 | p := new(uint32) 68 | f.Uint32VarP(p, name, "", value, usage) 69 | return p 70 | } 71 | 72 | // Uint32P is like Uint32, but accepts a shorthand letter that can be used after a single dash. 73 | func (f *FlagSet) Uint32P(name, shorthand string, value uint32, usage string) *uint32 { 74 | p := new(uint32) 75 | f.Uint32VarP(p, name, shorthand, value, usage) 76 | return p 77 | } 78 | 79 | // Uint32 defines a uint32 flag with specified name, default value, and usage string. 80 | // The return value is the address of a uint32 variable that stores the value of the flag. 81 | func Uint32(name string, value uint32, usage string) *uint32 { 82 | return CommandLine.Uint32P(name, "", value, usage) 83 | } 84 | 85 | // Uint32P is like Uint32, but accepts a shorthand letter that can be used after a single dash. 86 | func Uint32P(name, shorthand string, value uint32, usage string) *uint32 { 87 | return CommandLine.Uint32P(name, shorthand, value, usage) 88 | } 89 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/uint64.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import "strconv" 4 | 5 | // -- uint64 Value 6 | type uint64Value uint64 7 | 8 | func newUint64Value(val uint64, p *uint64) *uint64Value { 9 | *p = val 10 | return (*uint64Value)(p) 11 | } 12 | 13 | func (i *uint64Value) Set(s string) error { 14 | v, err := strconv.ParseUint(s, 0, 64) 15 | *i = uint64Value(v) 16 | return err 17 | } 18 | 19 | func (i *uint64Value) Type() string { 20 | return "uint64" 21 | } 22 | 23 | func (i *uint64Value) String() string { return strconv.FormatUint(uint64(*i), 10) } 24 | 25 | func uint64Conv(sval string) (interface{}, error) { 26 | v, err := strconv.ParseUint(sval, 0, 64) 27 | if err != nil { 28 | return 0, err 29 | } 30 | return uint64(v), nil 31 | } 32 | 33 | // GetUint64 return the uint64 value of a flag with the given name 34 | func (f *FlagSet) GetUint64(name string) (uint64, error) { 35 | val, err := f.getFlagType(name, "uint64", uint64Conv) 36 | if err != nil { 37 | return 0, err 38 | } 39 | return val.(uint64), nil 40 | } 41 | 42 | // Uint64Var defines a uint64 flag with specified name, default value, and usage string. 43 | // The argument p points to a uint64 variable in which to store the value of the flag. 44 | func (f *FlagSet) Uint64Var(p *uint64, name string, value uint64, usage string) { 45 | f.VarP(newUint64Value(value, p), name, "", usage) 46 | } 47 | 48 | // Uint64VarP is like Uint64Var, but accepts a shorthand letter that can be used after a single dash. 49 | func (f *FlagSet) Uint64VarP(p *uint64, name, shorthand string, value uint64, usage string) { 50 | f.VarP(newUint64Value(value, p), name, shorthand, usage) 51 | } 52 | 53 | // Uint64Var defines a uint64 flag with specified name, default value, and usage string. 54 | // The argument p points to a uint64 variable in which to store the value of the flag. 55 | func Uint64Var(p *uint64, name string, value uint64, usage string) { 56 | CommandLine.VarP(newUint64Value(value, p), name, "", usage) 57 | } 58 | 59 | // Uint64VarP is like Uint64Var, but accepts a shorthand letter that can be used after a single dash. 60 | func Uint64VarP(p *uint64, name, shorthand string, value uint64, usage string) { 61 | CommandLine.VarP(newUint64Value(value, p), name, shorthand, usage) 62 | } 63 | 64 | // Uint64 defines a uint64 flag with specified name, default value, and usage string. 65 | // The return value is the address of a uint64 variable that stores the value of the flag. 66 | func (f *FlagSet) Uint64(name string, value uint64, usage string) *uint64 { 67 | p := new(uint64) 68 | f.Uint64VarP(p, name, "", value, usage) 69 | return p 70 | } 71 | 72 | // Uint64P is like Uint64, but accepts a shorthand letter that can be used after a single dash. 73 | func (f *FlagSet) Uint64P(name, shorthand string, value uint64, usage string) *uint64 { 74 | p := new(uint64) 75 | f.Uint64VarP(p, name, shorthand, value, usage) 76 | return p 77 | } 78 | 79 | // Uint64 defines a uint64 flag with specified name, default value, and usage string. 80 | // The return value is the address of a uint64 variable that stores the value of the flag. 81 | func Uint64(name string, value uint64, usage string) *uint64 { 82 | return CommandLine.Uint64P(name, "", value, usage) 83 | } 84 | 85 | // Uint64P is like Uint64, but accepts a shorthand letter that can be used after a single dash. 86 | func Uint64P(name, shorthand string, value uint64, usage string) *uint64 { 87 | return CommandLine.Uint64P(name, shorthand, value, usage) 88 | } 89 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/bool.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import "strconv" 4 | 5 | // optional interface to indicate boolean flags that can be 6 | // supplied without "=value" text 7 | type boolFlag interface { 8 | Value 9 | IsBoolFlag() bool 10 | } 11 | 12 | // -- bool Value 13 | type boolValue bool 14 | 15 | func newBoolValue(val bool, p *bool) *boolValue { 16 | *p = val 17 | return (*boolValue)(p) 18 | } 19 | 20 | func (b *boolValue) Set(s string) error { 21 | v, err := strconv.ParseBool(s) 22 | *b = boolValue(v) 23 | return err 24 | } 25 | 26 | func (b *boolValue) Type() string { 27 | return "bool" 28 | } 29 | 30 | func (b *boolValue) String() string { return strconv.FormatBool(bool(*b)) } 31 | 32 | func (b *boolValue) IsBoolFlag() bool { return true } 33 | 34 | func boolConv(sval string) (interface{}, error) { 35 | return strconv.ParseBool(sval) 36 | } 37 | 38 | // GetBool return the bool value of a flag with the given name 39 | func (f *FlagSet) GetBool(name string) (bool, error) { 40 | val, err := f.getFlagType(name, "bool", boolConv) 41 | if err != nil { 42 | return false, err 43 | } 44 | return val.(bool), nil 45 | } 46 | 47 | // BoolVar defines a bool flag with specified name, default value, and usage string. 48 | // The argument p points to a bool variable in which to store the value of the flag. 49 | func (f *FlagSet) BoolVar(p *bool, name string, value bool, usage string) { 50 | f.BoolVarP(p, name, "", value, usage) 51 | } 52 | 53 | // BoolVarP is like BoolVar, but accepts a shorthand letter that can be used after a single dash. 54 | func (f *FlagSet) BoolVarP(p *bool, name, shorthand string, value bool, usage string) { 55 | flag := f.VarPF(newBoolValue(value, p), name, shorthand, usage) 56 | flag.NoOptDefVal = "true" 57 | } 58 | 59 | // BoolVar defines a bool flag with specified name, default value, and usage string. 60 | // The argument p points to a bool variable in which to store the value of the flag. 61 | func BoolVar(p *bool, name string, value bool, usage string) { 62 | BoolVarP(p, name, "", value, usage) 63 | } 64 | 65 | // BoolVarP is like BoolVar, but accepts a shorthand letter that can be used after a single dash. 66 | func BoolVarP(p *bool, name, shorthand string, value bool, usage string) { 67 | flag := CommandLine.VarPF(newBoolValue(value, p), name, shorthand, usage) 68 | flag.NoOptDefVal = "true" 69 | } 70 | 71 | // Bool defines a bool flag with specified name, default value, and usage string. 72 | // The return value is the address of a bool variable that stores the value of the flag. 73 | func (f *FlagSet) Bool(name string, value bool, usage string) *bool { 74 | return f.BoolP(name, "", value, usage) 75 | } 76 | 77 | // BoolP is like Bool, but accepts a shorthand letter that can be used after a single dash. 78 | func (f *FlagSet) BoolP(name, shorthand string, value bool, usage string) *bool { 79 | p := new(bool) 80 | f.BoolVarP(p, name, shorthand, value, usage) 81 | return p 82 | } 83 | 84 | // Bool defines a bool flag with specified name, default value, and usage string. 85 | // The return value is the address of a bool variable that stores the value of the flag. 86 | func Bool(name string, value bool, usage string) *bool { 87 | return BoolP(name, "", value, usage) 88 | } 89 | 90 | // BoolP is like Bool, but accepts a shorthand letter that can be used after a single dash. 91 | func BoolP(name, shorthand string, value bool, usage string) *bool { 92 | b := CommandLine.BoolP(name, shorthand, value, usage) 93 | return b 94 | } 95 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/float32.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import "strconv" 4 | 5 | // -- float32 Value 6 | type float32Value float32 7 | 8 | func newFloat32Value(val float32, p *float32) *float32Value { 9 | *p = val 10 | return (*float32Value)(p) 11 | } 12 | 13 | func (f *float32Value) Set(s string) error { 14 | v, err := strconv.ParseFloat(s, 32) 15 | *f = float32Value(v) 16 | return err 17 | } 18 | 19 | func (f *float32Value) Type() string { 20 | return "float32" 21 | } 22 | 23 | func (f *float32Value) String() string { return strconv.FormatFloat(float64(*f), 'g', -1, 32) } 24 | 25 | func float32Conv(sval string) (interface{}, error) { 26 | v, err := strconv.ParseFloat(sval, 32) 27 | if err != nil { 28 | return 0, err 29 | } 30 | return float32(v), nil 31 | } 32 | 33 | // GetFloat32 return the float32 value of a flag with the given name 34 | func (f *FlagSet) GetFloat32(name string) (float32, error) { 35 | val, err := f.getFlagType(name, "float32", float32Conv) 36 | if err != nil { 37 | return 0, err 38 | } 39 | return val.(float32), nil 40 | } 41 | 42 | // Float32Var defines a float32 flag with specified name, default value, and usage string. 43 | // The argument p points to a float32 variable in which to store the value of the flag. 44 | func (f *FlagSet) Float32Var(p *float32, name string, value float32, usage string) { 45 | f.VarP(newFloat32Value(value, p), name, "", usage) 46 | } 47 | 48 | // Float32VarP is like Float32Var, but accepts a shorthand letter that can be used after a single dash. 49 | func (f *FlagSet) Float32VarP(p *float32, name, shorthand string, value float32, usage string) { 50 | f.VarP(newFloat32Value(value, p), name, shorthand, usage) 51 | } 52 | 53 | // Float32Var defines a float32 flag with specified name, default value, and usage string. 54 | // The argument p points to a float32 variable in which to store the value of the flag. 55 | func Float32Var(p *float32, name string, value float32, usage string) { 56 | CommandLine.VarP(newFloat32Value(value, p), name, "", usage) 57 | } 58 | 59 | // Float32VarP is like Float32Var, but accepts a shorthand letter that can be used after a single dash. 60 | func Float32VarP(p *float32, name, shorthand string, value float32, usage string) { 61 | CommandLine.VarP(newFloat32Value(value, p), name, shorthand, usage) 62 | } 63 | 64 | // Float32 defines a float32 flag with specified name, default value, and usage string. 65 | // The return value is the address of a float32 variable that stores the value of the flag. 66 | func (f *FlagSet) Float32(name string, value float32, usage string) *float32 { 67 | p := new(float32) 68 | f.Float32VarP(p, name, "", value, usage) 69 | return p 70 | } 71 | 72 | // Float32P is like Float32, but accepts a shorthand letter that can be used after a single dash. 73 | func (f *FlagSet) Float32P(name, shorthand string, value float32, usage string) *float32 { 74 | p := new(float32) 75 | f.Float32VarP(p, name, shorthand, value, usage) 76 | return p 77 | } 78 | 79 | // Float32 defines a float32 flag with specified name, default value, and usage string. 80 | // The return value is the address of a float32 variable that stores the value of the flag. 81 | func Float32(name string, value float32, usage string) *float32 { 82 | return CommandLine.Float32P(name, "", value, usage) 83 | } 84 | 85 | // Float32P is like Float32, but accepts a shorthand letter that can be used after a single dash. 86 | func Float32P(name, shorthand string, value float32, usage string) *float32 { 87 | return CommandLine.Float32P(name, shorthand, value, usage) 88 | } 89 | -------------------------------------------------------------------------------- /vendor/github.com/heptiolabs/healthcheck/handler.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 by the contributors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package healthcheck 16 | 17 | import ( 18 | "encoding/json" 19 | "net/http" 20 | "sync" 21 | ) 22 | 23 | // basicHandler is a basic Handler implementation. 24 | type basicHandler struct { 25 | http.ServeMux 26 | checksMutex sync.RWMutex 27 | livenessChecks map[string]Check 28 | readinessChecks map[string]Check 29 | } 30 | 31 | // NewHandler creates a new basic Handler 32 | func NewHandler() Handler { 33 | h := &basicHandler{ 34 | livenessChecks: make(map[string]Check), 35 | readinessChecks: make(map[string]Check), 36 | } 37 | h.Handle("/live", http.HandlerFunc(h.LiveEndpoint)) 38 | h.Handle("/ready", http.HandlerFunc(h.ReadyEndpoint)) 39 | return h 40 | } 41 | 42 | func (s *basicHandler) LiveEndpoint(w http.ResponseWriter, r *http.Request) { 43 | s.handle(w, r, s.livenessChecks) 44 | } 45 | 46 | func (s *basicHandler) ReadyEndpoint(w http.ResponseWriter, r *http.Request) { 47 | s.handle(w, r, s.readinessChecks, s.livenessChecks) 48 | } 49 | 50 | func (s *basicHandler) AddLivenessCheck(name string, check Check) { 51 | s.checksMutex.Lock() 52 | defer s.checksMutex.Unlock() 53 | s.livenessChecks[name] = check 54 | } 55 | 56 | func (s *basicHandler) AddReadinessCheck(name string, check Check) { 57 | s.checksMutex.Lock() 58 | defer s.checksMutex.Unlock() 59 | s.readinessChecks[name] = check 60 | } 61 | 62 | func (s *basicHandler) collectChecks(checks map[string]Check, resultsOut map[string]string, statusOut *int) { 63 | s.checksMutex.RLock() 64 | defer s.checksMutex.RUnlock() 65 | for name, check := range checks { 66 | if err := check(); err != nil { 67 | *statusOut = http.StatusServiceUnavailable 68 | resultsOut[name] = err.Error() 69 | } else { 70 | resultsOut[name] = "OK" 71 | } 72 | } 73 | } 74 | 75 | func (s *basicHandler) handle(w http.ResponseWriter, r *http.Request, checks ...map[string]Check) { 76 | if r.Method != http.MethodGet { 77 | http.Error(w, "method not allowed", http.StatusMethodNotAllowed) 78 | return 79 | } 80 | 81 | checkResults := make(map[string]string) 82 | status := http.StatusOK 83 | for _, checks := range checks { 84 | s.collectChecks(checks, checkResults, &status) 85 | } 86 | 87 | // write out the response code and content type header 88 | w.Header().Set("Content-Type", "application/json; charset=utf-8") 89 | w.WriteHeader(status) 90 | 91 | // unless ?full=1, return an empty body. Kubernetes only cares about the 92 | // HTTP status code, so we won't waste bytes on the full body. 93 | if r.URL.Query().Get("full") != "1" { 94 | w.Write([]byte("{}\n")) 95 | return 96 | } 97 | 98 | // otherwise, write the JSON body ignoring any encoding errors (which 99 | // shouldn't really be possible since we're encoding a map[string]string). 100 | encoder := json.NewEncoder(w) 101 | encoder.SetIndent("", " ") 102 | encoder.Encode(checkResults) 103 | } 104 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/duration.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import ( 4 | "time" 5 | ) 6 | 7 | // -- time.Duration Value 8 | type durationValue time.Duration 9 | 10 | func newDurationValue(val time.Duration, p *time.Duration) *durationValue { 11 | *p = val 12 | return (*durationValue)(p) 13 | } 14 | 15 | func (d *durationValue) Set(s string) error { 16 | v, err := time.ParseDuration(s) 17 | *d = durationValue(v) 18 | return err 19 | } 20 | 21 | func (d *durationValue) Type() string { 22 | return "duration" 23 | } 24 | 25 | func (d *durationValue) String() string { return (*time.Duration)(d).String() } 26 | 27 | func durationConv(sval string) (interface{}, error) { 28 | return time.ParseDuration(sval) 29 | } 30 | 31 | // GetDuration return the duration value of a flag with the given name 32 | func (f *FlagSet) GetDuration(name string) (time.Duration, error) { 33 | val, err := f.getFlagType(name, "duration", durationConv) 34 | if err != nil { 35 | return 0, err 36 | } 37 | return val.(time.Duration), nil 38 | } 39 | 40 | // DurationVar defines a time.Duration flag with specified name, default value, and usage string. 41 | // The argument p points to a time.Duration variable in which to store the value of the flag. 42 | func (f *FlagSet) DurationVar(p *time.Duration, name string, value time.Duration, usage string) { 43 | f.VarP(newDurationValue(value, p), name, "", usage) 44 | } 45 | 46 | // DurationVarP is like DurationVar, but accepts a shorthand letter that can be used after a single dash. 47 | func (f *FlagSet) DurationVarP(p *time.Duration, name, shorthand string, value time.Duration, usage string) { 48 | f.VarP(newDurationValue(value, p), name, shorthand, usage) 49 | } 50 | 51 | // DurationVar defines a time.Duration flag with specified name, default value, and usage string. 52 | // The argument p points to a time.Duration variable in which to store the value of the flag. 53 | func DurationVar(p *time.Duration, name string, value time.Duration, usage string) { 54 | CommandLine.VarP(newDurationValue(value, p), name, "", usage) 55 | } 56 | 57 | // DurationVarP is like DurationVar, but accepts a shorthand letter that can be used after a single dash. 58 | func DurationVarP(p *time.Duration, name, shorthand string, value time.Duration, usage string) { 59 | CommandLine.VarP(newDurationValue(value, p), name, shorthand, usage) 60 | } 61 | 62 | // Duration defines a time.Duration flag with specified name, default value, and usage string. 63 | // The return value is the address of a time.Duration variable that stores the value of the flag. 64 | func (f *FlagSet) Duration(name string, value time.Duration, usage string) *time.Duration { 65 | p := new(time.Duration) 66 | f.DurationVarP(p, name, "", value, usage) 67 | return p 68 | } 69 | 70 | // DurationP is like Duration, but accepts a shorthand letter that can be used after a single dash. 71 | func (f *FlagSet) DurationP(name, shorthand string, value time.Duration, usage string) *time.Duration { 72 | p := new(time.Duration) 73 | f.DurationVarP(p, name, shorthand, value, usage) 74 | return p 75 | } 76 | 77 | // Duration defines a time.Duration flag with specified name, default value, and usage string. 78 | // The return value is the address of a time.Duration variable that stores the value of the flag. 79 | func Duration(name string, value time.Duration, usage string) *time.Duration { 80 | return CommandLine.DurationP(name, "", value, usage) 81 | } 82 | 83 | // DurationP is like Duration, but accepts a shorthand letter that can be used after a single dash. 84 | func DurationP(name, shorthand string, value time.Duration, usage string) *time.Duration { 85 | return CommandLine.DurationP(name, shorthand, value, usage) 86 | } 87 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/ipnet.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import ( 4 | "fmt" 5 | "net" 6 | "strings" 7 | ) 8 | 9 | // IPNet adapts net.IPNet for use as a flag. 10 | type ipNetValue net.IPNet 11 | 12 | func (ipnet ipNetValue) String() string { 13 | n := net.IPNet(ipnet) 14 | return n.String() 15 | } 16 | 17 | func (ipnet *ipNetValue) Set(value string) error { 18 | _, n, err := net.ParseCIDR(strings.TrimSpace(value)) 19 | if err != nil { 20 | return err 21 | } 22 | *ipnet = ipNetValue(*n) 23 | return nil 24 | } 25 | 26 | func (*ipNetValue) Type() string { 27 | return "ipNet" 28 | } 29 | 30 | func newIPNetValue(val net.IPNet, p *net.IPNet) *ipNetValue { 31 | *p = val 32 | return (*ipNetValue)(p) 33 | } 34 | 35 | func ipNetConv(sval string) (interface{}, error) { 36 | _, n, err := net.ParseCIDR(strings.TrimSpace(sval)) 37 | if err == nil { 38 | return *n, nil 39 | } 40 | return nil, fmt.Errorf("invalid string being converted to IPNet: %s", sval) 41 | } 42 | 43 | // GetIPNet return the net.IPNet value of a flag with the given name 44 | func (f *FlagSet) GetIPNet(name string) (net.IPNet, error) { 45 | val, err := f.getFlagType(name, "ipNet", ipNetConv) 46 | if err != nil { 47 | return net.IPNet{}, err 48 | } 49 | return val.(net.IPNet), nil 50 | } 51 | 52 | // IPNetVar defines an net.IPNet flag with specified name, default value, and usage string. 53 | // The argument p points to an net.IPNet variable in which to store the value of the flag. 54 | func (f *FlagSet) IPNetVar(p *net.IPNet, name string, value net.IPNet, usage string) { 55 | f.VarP(newIPNetValue(value, p), name, "", usage) 56 | } 57 | 58 | // IPNetVarP is like IPNetVar, but accepts a shorthand letter that can be used after a single dash. 59 | func (f *FlagSet) IPNetVarP(p *net.IPNet, name, shorthand string, value net.IPNet, usage string) { 60 | f.VarP(newIPNetValue(value, p), name, shorthand, usage) 61 | } 62 | 63 | // IPNetVar defines an net.IPNet flag with specified name, default value, and usage string. 64 | // The argument p points to an net.IPNet variable in which to store the value of the flag. 65 | func IPNetVar(p *net.IPNet, name string, value net.IPNet, usage string) { 66 | CommandLine.VarP(newIPNetValue(value, p), name, "", usage) 67 | } 68 | 69 | // IPNetVarP is like IPNetVar, but accepts a shorthand letter that can be used after a single dash. 70 | func IPNetVarP(p *net.IPNet, name, shorthand string, value net.IPNet, usage string) { 71 | CommandLine.VarP(newIPNetValue(value, p), name, shorthand, usage) 72 | } 73 | 74 | // IPNet defines an net.IPNet flag with specified name, default value, and usage string. 75 | // The return value is the address of an net.IPNet variable that stores the value of the flag. 76 | func (f *FlagSet) IPNet(name string, value net.IPNet, usage string) *net.IPNet { 77 | p := new(net.IPNet) 78 | f.IPNetVarP(p, name, "", value, usage) 79 | return p 80 | } 81 | 82 | // IPNetP is like IPNet, but accepts a shorthand letter that can be used after a single dash. 83 | func (f *FlagSet) IPNetP(name, shorthand string, value net.IPNet, usage string) *net.IPNet { 84 | p := new(net.IPNet) 85 | f.IPNetVarP(p, name, shorthand, value, usage) 86 | return p 87 | } 88 | 89 | // IPNet defines an net.IPNet flag with specified name, default value, and usage string. 90 | // The return value is the address of an net.IPNet variable that stores the value of the flag. 91 | func IPNet(name string, value net.IPNet, usage string) *net.IPNet { 92 | return CommandLine.IPNetP(name, "", value, usage) 93 | } 94 | 95 | // IPNetP is like IPNet, but accepts a shorthand letter that can be used after a single dash. 96 | func IPNetP(name, shorthand string, value net.IPNet, usage string) *net.IPNet { 97 | return CommandLine.IPNetP(name, shorthand, value, usage) 98 | } 99 | -------------------------------------------------------------------------------- /vendor/github.com/prometheus/client_golang/prometheus/collector.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Prometheus Authors 2 | // Licensed under the Apache License, Version 2.0 (the "License"); 3 | // you may not use this file except in compliance with the License. 4 | // You may obtain a copy of the License at 5 | // 6 | // http://www.apache.org/licenses/LICENSE-2.0 7 | // 8 | // Unless required by applicable law or agreed to in writing, software 9 | // distributed under the License is distributed on an "AS IS" BASIS, 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | // See the License for the specific language governing permissions and 12 | // limitations under the License. 13 | 14 | package prometheus 15 | 16 | // Collector is the interface implemented by anything that can be used by 17 | // Prometheus to collect metrics. A Collector has to be registered for 18 | // collection. See Registerer.Register. 19 | // 20 | // The stock metrics provided by this package (Gauge, Counter, Summary, 21 | // Histogram, Untyped) are also Collectors (which only ever collect one metric, 22 | // namely itself). An implementer of Collector may, however, collect multiple 23 | // metrics in a coordinated fashion and/or create metrics on the fly. Examples 24 | // for collectors already implemented in this library are the metric vectors 25 | // (i.e. collection of multiple instances of the same Metric but with different 26 | // label values) like GaugeVec or SummaryVec, and the ExpvarCollector. 27 | type Collector interface { 28 | // Describe sends the super-set of all possible descriptors of metrics 29 | // collected by this Collector to the provided channel and returns once 30 | // the last descriptor has been sent. The sent descriptors fulfill the 31 | // consistency and uniqueness requirements described in the Desc 32 | // documentation. (It is valid if one and the same Collector sends 33 | // duplicate descriptors. Those duplicates are simply ignored. However, 34 | // two different Collectors must not send duplicate descriptors.) This 35 | // method idempotently sends the same descriptors throughout the 36 | // lifetime of the Collector. If a Collector encounters an error while 37 | // executing this method, it must send an invalid descriptor (created 38 | // with NewInvalidDesc) to signal the error to the registry. 39 | Describe(chan<- *Desc) 40 | // Collect is called by the Prometheus registry when collecting 41 | // metrics. The implementation sends each collected metric via the 42 | // provided channel and returns once the last metric has been sent. The 43 | // descriptor of each sent metric is one of those returned by 44 | // Describe. Returned metrics that share the same descriptor must differ 45 | // in their variable label values. This method may be called 46 | // concurrently and must therefore be implemented in a concurrency safe 47 | // way. Blocking occurs at the expense of total performance of rendering 48 | // all registered metrics. Ideally, Collector implementations support 49 | // concurrent readers. 50 | Collect(chan<- Metric) 51 | } 52 | 53 | // selfCollector implements Collector for a single Metric so that the Metric 54 | // collects itself. Add it as an anonymous field to a struct that implements 55 | // Metric, and call init with the Metric itself as an argument. 56 | type selfCollector struct { 57 | self Metric 58 | } 59 | 60 | // init provides the selfCollector with a reference to the metric it is supposed 61 | // to collect. It is usually called within the factory function to create a 62 | // metric. See example. 63 | func (c *selfCollector) init(self Metric) { 64 | c.self = self 65 | } 66 | 67 | // Describe implements Collector. 68 | func (c *selfCollector) Describe(ch chan<- *Desc) { 69 | ch <- c.self.Desc() 70 | } 71 | 72 | // Collect implements Collector. 73 | func (c *selfCollector) Collect(ch chan<- Metric) { 74 | ch <- c.self 75 | } 76 | --------------------------------------------------------------------------------