├── .github └── workflows │ └── test.yml ├── .gitignore ├── CHANGELOG.md ├── CONTRIBUTORS.md ├── LICENSE.md ├── README.md ├── _vendor ├── README.md └── src │ ├── code.google.com │ └── p │ │ └── goprotobuf │ │ ├── AUTHORS │ │ ├── CONTRIBUTORS │ │ ├── LICENSE │ │ ├── Make.protobuf │ │ ├── Makefile │ │ ├── README │ │ ├── lib │ │ └── codereview │ │ │ └── codereview.cfg │ │ ├── proto │ │ ├── Makefile │ │ ├── all_test.go │ │ ├── clone.go │ │ ├── clone_test.go │ │ ├── decode.go │ │ ├── encode.go │ │ ├── equal.go │ │ ├── equal_test.go │ │ ├── extensions.go │ │ ├── extensions_test.go │ │ ├── lib.go │ │ ├── message_set.go │ │ ├── message_set_test.go │ │ ├── pointer_reflect.go │ │ ├── pointer_unsafe.go │ │ ├── properties.go │ │ ├── size2_test.go │ │ ├── size_test.go │ │ ├── testdata │ │ │ ├── Makefile │ │ │ ├── golden_test.go │ │ │ ├── test.pb.go │ │ │ └── test.proto │ │ ├── text.go │ │ ├── text_parser.go │ │ ├── text_parser_test.go │ │ └── text_test.go │ │ └── protoc-gen-go │ │ ├── Makefile │ │ ├── descriptor │ │ ├── Makefile │ │ ├── descriptor.pb.go │ │ └── descriptor.pb.golden │ │ ├── doc.go │ │ ├── generator │ │ ├── Makefile │ │ ├── generator.go │ │ └── name_test.go │ │ ├── main.go │ │ ├── plugin │ │ ├── Makefile │ │ ├── plugin.pb.go │ │ └── plugin.pb.golden │ │ └── testdata │ │ ├── Makefile │ │ ├── extension_base.proto │ │ ├── extension_extra.proto │ │ ├── extension_test.go │ │ ├── extension_user.proto │ │ ├── golden_test.go │ │ ├── imp.pb.go.golden │ │ ├── imp.proto │ │ ├── imp2.proto │ │ ├── imp3.proto │ │ ├── main_test.go │ │ ├── multi │ │ ├── multi1.proto │ │ ├── multi2.proto │ │ └── multi3.proto │ │ └── my_test │ │ ├── test.pb.go │ │ ├── test.pb.go.golden │ │ └── test.proto │ └── github.com │ ├── garyburd │ └── redigo │ │ ├── README.markdown │ │ ├── redis │ │ ├── conn.go │ │ ├── conn_test.go │ │ ├── doc.go │ │ ├── log.go │ │ ├── pool.go │ │ ├── pool_test.go │ │ ├── pubsub.go │ │ ├── pubsub_test.go │ │ ├── redis.go │ │ ├── reply.go │ │ ├── reply_test.go │ │ ├── scan.go │ │ ├── scan_test.go │ │ ├── script.go │ │ ├── script_test.go │ │ ├── test_test.go │ │ └── zpop_example_test.go │ │ └── redisx │ │ ├── doc.go │ │ ├── example.go │ │ ├── struct.go │ │ ├── struct_test.go │ │ └── util.go │ ├── gorilla │ ├── context │ │ ├── .travis.yml │ │ ├── LICENSE │ │ ├── README.md │ │ ├── context.go │ │ ├── context_test.go │ │ └── doc.go │ ├── mux │ │ ├── .travis.yml │ │ ├── LICENSE │ │ ├── README.md │ │ ├── bench_test.go │ │ ├── doc.go │ │ ├── mux.go │ │ ├── mux_test.go │ │ ├── old_test.go │ │ ├── regexp.go │ │ └── route.go │ └── pat │ │ ├── .travis.yml │ │ ├── LICENSE │ │ ├── README.md │ │ ├── doc.go │ │ ├── pat.go │ │ └── pat_test.go │ ├── matttproud │ └── golang_protobuf_extensions │ │ ├── .travis.yml │ │ ├── LICENSE │ │ ├── README.md │ │ └── ext │ │ ├── all_test.go │ │ ├── decode.go │ │ ├── documentation.go │ │ ├── encode.go │ │ └── fixtures_test.go │ ├── peterbourgon │ └── g2s │ │ ├── .gitignore │ │ ├── .travis.yml │ │ ├── LICENSE │ │ ├── README.md │ │ ├── fix.bash │ │ ├── g2s.go │ │ ├── g2s_test.go │ │ ├── safe.go │ │ └── types.go │ ├── prometheus │ ├── client_golang │ │ ├── .gitignore │ │ ├── .travis.yml │ │ ├── LICENSE │ │ ├── Makefile │ │ ├── README.md │ │ ├── _vendor │ │ │ ├── goautoneg │ │ │ │ ├── MANIFEST │ │ │ │ ├── Makefile │ │ │ │ ├── README.txt │ │ │ │ ├── autoneg.go │ │ │ │ └── autoneg_test.go │ │ │ └── perks │ │ │ │ ├── MANIFEST │ │ │ │ ├── README.md │ │ │ │ └── quantile │ │ │ │ ├── bench_test.go │ │ │ │ ├── example_test.go │ │ │ │ ├── exampledata.txt │ │ │ │ ├── pool.go │ │ │ │ ├── pool_1_3.go │ │ │ │ ├── stream.go │ │ │ │ └── stream_test.go │ │ ├── extraction │ │ │ ├── discriminator.go │ │ │ ├── discriminator_test.go │ │ │ ├── extraction.go │ │ │ ├── fixtures │ │ │ │ ├── empty.json │ │ │ │ └── test0_0_1-0_0_2.json │ │ │ ├── metricfamilyprocessor.go │ │ │ ├── metricfamilyprocessor_test.go │ │ │ ├── processor.go │ │ │ ├── processor0_0_1.go │ │ │ ├── processor0_0_1_test.go │ │ │ ├── processor0_0_2.go │ │ │ ├── processor0_0_2_test.go │ │ │ ├── textprocessor.go │ │ │ └── textprocessor_test.go │ │ ├── model │ │ │ ├── fingerprinting.go │ │ │ ├── labelname.go │ │ │ ├── labelname_test.go │ │ │ ├── labelset.go │ │ │ ├── labelvalue.go │ │ │ ├── labelvalue_test.go │ │ │ ├── metric.go │ │ │ ├── metric_test.go │ │ │ ├── model.go │ │ │ ├── model_test.go │ │ │ ├── sample.go │ │ │ ├── sample_test.go │ │ │ ├── samplevalue.go │ │ │ ├── signature.go │ │ │ ├── signature_test.go │ │ │ ├── timestamp.go │ │ │ └── timestamp_test.go │ │ ├── prometheus │ │ │ ├── .gitignore │ │ │ ├── README.md │ │ │ ├── benchmark_test.go │ │ │ ├── collector.go │ │ │ ├── counter.go │ │ │ ├── counter_test.go │ │ │ ├── desc.go │ │ │ ├── doc.go │ │ │ ├── example_clustermanager_test.go │ │ │ ├── example_memstats_test.go │ │ │ ├── example_selfcollector_test.go │ │ │ ├── examples_test.go │ │ │ ├── expvar.go │ │ │ ├── expvar_test.go │ │ │ ├── gauge.go │ │ │ ├── gauge_test.go │ │ │ ├── http.go │ │ │ ├── http_test.go │ │ │ ├── metric.go │ │ │ ├── metric_test.go │ │ │ ├── registry.go │ │ │ ├── registry_test.go │ │ │ ├── summary.go │ │ │ ├── summary_test.go │ │ │ ├── untyped.go │ │ │ ├── value.go │ │ │ ├── vec.go │ │ │ └── vec_test.go │ │ └── text │ │ │ ├── create.go │ │ │ ├── create_test.go │ │ │ ├── parse.go │ │ │ ├── parse_test.go │ │ │ └── proto.go │ └── client_model │ │ ├── .gitignore │ │ ├── Makefile │ │ ├── README.md │ │ ├── contributing.md │ │ ├── cpp │ │ ├── metrics.pb.cc │ │ └── metrics.pb.h │ │ ├── go │ │ └── metrics.pb.go │ │ ├── metrics.proto │ │ ├── pom.xml │ │ ├── python │ │ └── prometheus │ │ │ ├── __init__.py │ │ │ └── client │ │ │ ├── __init__.py │ │ │ └── model │ │ │ ├── __init__.py │ │ │ └── metrics_pb2.py │ │ ├── ruby │ │ ├── .gitignore │ │ ├── Gemfile │ │ ├── LICENSE │ │ ├── Makefile │ │ ├── README.md │ │ ├── Rakefile │ │ ├── lib │ │ │ └── prometheus │ │ │ │ └── client │ │ │ │ ├── model.rb │ │ │ │ └── model │ │ │ │ ├── metrics.pb.rb │ │ │ │ └── version.rb │ │ └── prometheus-client-model.gemspec │ │ ├── setup.py │ │ └── src │ │ └── main │ │ └── java │ │ └── io │ │ └── prometheus │ │ └── client │ │ └── Metrics.java │ ├── streadway │ └── handy │ │ ├── README.md │ │ ├── breaker │ │ ├── breaker.go │ │ ├── breaker_test.go │ │ ├── doc.go │ │ ├── handler.go │ │ ├── handler_test.go │ │ ├── metrics.go │ │ ├── metrics_test.go │ │ ├── simulation_test.go │ │ ├── transport.go │ │ └── transport_test.go │ │ ├── cors │ │ ├── cors.go │ │ └── cors_test.go │ │ ├── doc.go │ │ ├── encoding │ │ ├── gzip.go │ │ └── gzip_test.go │ │ ├── proxy │ │ ├── proxy.go │ │ └── proxy_test.go │ │ ├── redirect │ │ ├── https.go │ │ └── https_test.go │ │ ├── report │ │ ├── event.go │ │ ├── json.go │ │ └── json_test.go │ │ ├── rewrite │ │ ├── method.go │ │ └── method_test.go │ │ └── statsd │ │ ├── codes.go │ │ ├── doc.go │ │ ├── durations.go │ │ ├── example_test.go │ │ └── instrumentation_test.go │ └── tsenart │ └── tb │ ├── README.md │ ├── bucket.go │ ├── bucket_test.go │ ├── examples │ └── echo.go │ ├── http │ ├── client.go │ └── server.go │ ├── io │ └── io.go │ ├── tb.go │ ├── throttler.go │ └── throttler_test.go ├── cluster ├── README.md ├── cluster.go └── cluster_test.go ├── common ├── README.md ├── cursor.go ├── cursor_test.go ├── doc.go ├── key_score_member.go └── key_score_member_test.go ├── farm ├── README.md ├── farm.go ├── farm_semantics_test.go ├── farm_test.go ├── mock_cluster_test.go ├── parse_farm_string.go ├── parse_farm_string_test.go ├── read_strategies.go ├── read_strategies_test.go ├── repair_strategies.go ├── repair_strategies_test.go └── tupleset_test.go ├── go.mod ├── go.sum ├── instrumentation ├── README.md ├── instrumentation.go ├── multi_instrumentation.go ├── nop_instrumentation.go ├── plaintext │ └── plaintext.go ├── prometheus │ └── prometheus.go └── statsd │ └── statsd.go ├── pool ├── README.md ├── connection_pool.go ├── connection_pool_test.go ├── hashes.go ├── hashes_test.go ├── integration_test.go └── pool.go ├── roshi-server ├── Makefile ├── README.md ├── main.go └── main_test.go └── roshi-walker ├── Makefile ├── README.md └── main.go /.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | name: Test 2 | 3 | on: 4 | workflow_dispatch: 5 | push: 6 | branches: [ master ] 7 | pull_request: 8 | branches: [ master ] 9 | 10 | jobs: 11 | 12 | build: 13 | runs-on: ubuntu-latest 14 | 15 | steps: 16 | - uses: actions/checkout@v2 17 | 18 | - name: Set up Go 19 | uses: actions/setup-go@v2 20 | with: 21 | go-version: 1.16 22 | 23 | # Some tests require an already-running Redis server, some require the 24 | # redis-server binary. Install Redis directly on the test instance, this 25 | # also starts a server on port 6379. 26 | - name: Install redis-server 27 | run: sudo apt-get install redis-server 28 | 29 | - name: Build 30 | run: go build -v ./... 31 | 32 | - name: Test 33 | run: go test -race -v ./... 34 | env: 35 | TEST_REDIS_ADDRESSES: "localhost:6379" 36 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | roshi-server/roshi-server 2 | roshi-walker/roshi-walker 3 | roshi-walker/fill 4 | 5 | # Compiled Object files, Static and Dynamic libs (Shared Objects) 6 | *.o 7 | *.a 8 | *.so 9 | 10 | # Folders 11 | _obj 12 | _test 13 | 14 | # Architecture specific extensions/prefixes 15 | *.[568vq] 16 | [568vq].out 17 | 18 | *.cgo1.go 19 | *.cgo2.c 20 | _cgo_defun.c 21 | _cgo_gotypes.go 22 | _cgo_export.* 23 | 24 | _testmain.go 25 | 26 | *.exe 27 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | ## 0.0.1 / 2014-01-14 4 | 5 | - Initial copy from [peterbourgon/crdt](https://github.com/peterbourgon/crdt) 6 | -------------------------------------------------------------------------------- /CONTRIBUTORS.md: -------------------------------------------------------------------------------- 1 | - Tomás Senart 2 | - Peter Bourgon 3 | - Björn Rabenstein 4 | - Johan Uhle 5 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright © 2014, SoundCloud Ltd. 2 | 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 met: 6 | 7 | Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | Redistributions in binary form must reproduce the above copyright notice, this 11 | list of conditions and the following disclaimer in the documentation and/or 12 | other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 15 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 16 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | -------------------------------------------------------------------------------- /_vendor/README.md: -------------------------------------------------------------------------------- 1 | # vendor 2 | 3 | This directory holds vendored dependencies, managed via [git subtrees][0]. All 4 | management commands should be run from the top level of the repository. The 5 | blessed build procedure for the binaries (encoded in their Makefiles) makes use 6 | of this directory; normal development will use whichever version(s) are in your 7 | normal GOPATH. 8 | 9 | [0]: http://blogs.atlassian.com/2013/05/alternatives-to-git-submodule-git-subtree 10 | 11 | ## Adding a new dependency 12 | 13 | git subtree add --prefix _vendor/src/github.com/foo/bar git@github.com:foo/bar master --squash 14 | 15 | ## Updating a dependency 16 | 17 | git subtree pull --prefix _vendor/src/github.com/foo/bar git@github.com:foo/bar master --squash 18 | 19 | -------------------------------------------------------------------------------- /_vendor/src/code.google.com/p/goprotobuf/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/src/code.google.com/p/goprotobuf/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/src/code.google.com/p/goprotobuf/LICENSE: -------------------------------------------------------------------------------- 1 | Go support for Protocol Buffers - Google's data interchange format 2 | 3 | Copyright 2010 The Go Authors. All rights reserved. 4 | http://code.google.com/p/goprotobuf/ 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/src/code.google.com/p/goprotobuf/Make.protobuf: -------------------------------------------------------------------------------- 1 | # Go support for Protocol Buffers - Google's data interchange format 2 | # 3 | # Copyright 2010 The Go Authors. All rights reserved. 4 | # http://code.google.com/p/goprotobuf/ 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 | # Includable Makefile to add a rule for generating .pb.go files from .proto files 33 | # (Google protocol buffer descriptions). 34 | # Typical use if myproto.proto is a file in package mypackage in this directory: 35 | # 36 | # include $(GOROOT)/src/pkg/code.google.com/p/goprotobuf/Make.protobuf 37 | 38 | %.pb.go: %.proto 39 | protoc --go_out=. $< 40 | 41 | -------------------------------------------------------------------------------- /_vendor/src/code.google.com/p/goprotobuf/Makefile: -------------------------------------------------------------------------------- 1 | # Go support for Protocol Buffers - Google's data interchange format 2 | # 3 | # Copyright 2010 The Go Authors. All rights reserved. 4 | # http://code.google.com/p/goprotobuf/ 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 | 33 | all: install 34 | 35 | install: 36 | go install ./proto 37 | go install ./protoc-gen-go 38 | 39 | test: 40 | go test ./proto 41 | make -C protoc-gen-go/testdata test 42 | 43 | clean: 44 | go clean ./... 45 | 46 | nuke: 47 | go clean -i ./... 48 | 49 | regenerate: 50 | make -C protoc-gen-go/descriptor regenerate 51 | make -C protoc-gen-go/plugin regenerate 52 | make -C proto/testdata regenerate 53 | -------------------------------------------------------------------------------- /_vendor/src/code.google.com/p/goprotobuf/lib/codereview/codereview.cfg: -------------------------------------------------------------------------------- 1 | defaultcc: golang-codereviews@googlegroups.com 2 | contributors: http://go.googlecode.com/hg/CONTRIBUTORS 3 | -------------------------------------------------------------------------------- /_vendor/src/code.google.com/p/goprotobuf/proto/Makefile: -------------------------------------------------------------------------------- 1 | # Go support for Protocol Buffers - Google's data interchange format 2 | # 3 | # Copyright 2010 The Go Authors. All rights reserved. 4 | # http://code.google.com/p/goprotobuf/ 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 | install: 33 | go install 34 | 35 | test: install generate-test-pbs 36 | go test 37 | 38 | 39 | generate-test-pbs: 40 | make install && cd testdata && make 41 | -------------------------------------------------------------------------------- /_vendor/src/code.google.com/p/goprotobuf/proto/extensions_test.go: -------------------------------------------------------------------------------- 1 | // Go support for Protocol Buffers - Google's data interchange format 2 | // 3 | // Copyright 2014 The Go Authors. All rights reserved. 4 | // http://code.google.com/p/goprotobuf/ 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 | package proto_test 33 | 34 | import ( 35 | "testing" 36 | 37 | pb "./testdata" 38 | "code.google.com/p/goprotobuf/proto" 39 | ) 40 | 41 | func TestGetExtensionsWithMissingExtensions(t *testing.T) { 42 | msg := &pb.MyMessage{} 43 | ext1 := &pb.Ext{} 44 | if err := proto.SetExtension(msg, pb.E_Ext_More, ext1); err != nil { 45 | t.Fatalf("Could not set ext1: %s", ext1) 46 | } 47 | exts, err := proto.GetExtensions(msg, []*proto.ExtensionDesc{ 48 | pb.E_Ext_More, 49 | pb.E_Ext_Text, 50 | }) 51 | if err != nil { 52 | t.Fatalf("GetExtensions() failed: %s", err) 53 | } 54 | if exts[0] != ext1 { 55 | t.Errorf("ext1 not in returned extensions: %T %v", exts[0], exts[0]) 56 | } 57 | if exts[1] != nil { 58 | t.Errorf("ext2 in returned extensions: %T %v", exts[1], exts[1]) 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /_vendor/src/code.google.com/p/goprotobuf/proto/size2_test.go: -------------------------------------------------------------------------------- 1 | // Go support for Protocol Buffers - Google's data interchange format 2 | // 3 | // Copyright 2012 The Go Authors. All rights reserved. 4 | // http://code.google.com/p/goprotobuf/ 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 | package proto 33 | 34 | import ( 35 | "testing" 36 | ) 37 | 38 | // This is a separate file and package from size_test.go because that one uses 39 | // generated messages and thus may not be in package proto without having a circular 40 | // dependency, whereas this file tests unexported details of size.go. 41 | 42 | func TestVarintSize(t *testing.T) { 43 | // Check the edge cases carefully. 44 | testCases := []struct { 45 | n uint64 46 | size int 47 | }{ 48 | {0, 1}, 49 | {1, 1}, 50 | {127, 1}, 51 | {128, 2}, 52 | {16383, 2}, 53 | {16384, 3}, 54 | {1<<63 - 1, 9}, 55 | {1 << 63, 10}, 56 | } 57 | for _, tc := range testCases { 58 | size := sizeVarint(tc.n) 59 | if size != tc.size { 60 | t.Errorf("sizeVarint(%d) = %d, want %d", tc.n, size, tc.size) 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /_vendor/src/code.google.com/p/goprotobuf/proto/testdata/Makefile: -------------------------------------------------------------------------------- 1 | # Go support for Protocol Buffers - Google's data interchange format 2 | # 3 | # Copyright 2010 The Go Authors. All rights reserved. 4 | # http://code.google.com/p/goprotobuf/ 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 | 33 | include ../../Make.protobuf 34 | 35 | all: regenerate 36 | 37 | regenerate: 38 | rm -f test.pb.go 39 | make test.pb.go 40 | 41 | # The following rules are just aids to development. Not needed for typical testing. 42 | 43 | diff: regenerate 44 | hg diff test.pb.go 45 | 46 | restore: 47 | cp test.pb.go.golden test.pb.go 48 | 49 | preserve: 50 | cp test.pb.go test.pb.go.golden 51 | -------------------------------------------------------------------------------- /_vendor/src/code.google.com/p/goprotobuf/protoc-gen-go/Makefile: -------------------------------------------------------------------------------- 1 | # Go support for Protocol Buffers - Google's data interchange format 2 | # 3 | # Copyright 2010 The Go Authors. All rights reserved. 4 | # http://code.google.com/p/goprotobuf/ 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 | include $(GOROOT)/src/Make.cmd 33 | 34 | test: 35 | cd testdata && make test 36 | -------------------------------------------------------------------------------- /_vendor/src/code.google.com/p/goprotobuf/protoc-gen-go/descriptor/Makefile: -------------------------------------------------------------------------------- 1 | # Go support for Protocol Buffers - Google's data interchange format 2 | # 3 | # Copyright 2010 The Go Authors. All rights reserved. 4 | # http://code.google.com/p/goprotobuf/ 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 | # Not stored here, but descriptor.proto is in http://code.google.com/p/protobuf 33 | # at protobuf-2.5.0/src/google/protobuf/descriptor.proto 34 | regenerate: 35 | echo WARNING! THIS RULE IS PROBABLY NOT RIGHT FOR YOUR INSTALLATION 36 | cd $(HOME)/src/protobuf-2.5.0/src && \ 37 | protoc --go_out=. ./google/protobuf/descriptor.proto && \ 38 | cp ./google/protobuf/descriptor.pb.go $(GOPATH)/src/code.google.com/p/goprotobuf/protoc-gen-go/descriptor/descriptor.pb.go 39 | 40 | restore: 41 | cp descriptor.pb.golden descriptor.pb.go 42 | 43 | preserve: 44 | cp descriptor.pb.go descriptor.pb.golden 45 | -------------------------------------------------------------------------------- /_vendor/src/code.google.com/p/goprotobuf/protoc-gen-go/doc.go: -------------------------------------------------------------------------------- 1 | // Go support for Protocol Buffers - Google's data interchange format 2 | // 3 | // Copyright 2010 The Go Authors. All rights reserved. 4 | // http://code.google.com/p/goprotobuf/ 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 | /* 33 | A plugin for the Google protocol buffer compiler to generate Go code. 34 | Run it by building this program and putting it in your path with the name 35 | protoc-gen-go 36 | That word 'go' at the end becomes part of the option string set for the 37 | protocol compiler, so once the protocol compiler (protoc) is installed 38 | you can run 39 | protoc --go_out=output_directory input_directory/file.proto 40 | to generate Go bindings for the protocol defined by file.proto. 41 | With that input, the output will be written to 42 | output_directory/file.pb.go 43 | 44 | The generated code is documented in the package comment for 45 | the library. 46 | 47 | See the README and documentation for protocol buffers to learn more: 48 | http://code.google.com/p/protobuf/ 49 | 50 | */ 51 | package documentation 52 | -------------------------------------------------------------------------------- /_vendor/src/code.google.com/p/goprotobuf/protoc-gen-go/generator/Makefile: -------------------------------------------------------------------------------- 1 | # Go support for Protocol Buffers - Google's data interchange format 2 | # 3 | # Copyright 2010 The Go Authors. All rights reserved. 4 | # http://code.google.com/p/goprotobuf/ 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 | include $(GOROOT)/src/Make.inc 33 | 34 | TARG=code.google.com/p/goprotobuf/compiler/generator 35 | GOFILES=\ 36 | generator.go\ 37 | 38 | DEPS=../descriptor ../plugin ../../proto 39 | 40 | include $(GOROOT)/src/Make.pkg 41 | -------------------------------------------------------------------------------- /_vendor/src/code.google.com/p/goprotobuf/protoc-gen-go/generator/name_test.go: -------------------------------------------------------------------------------- 1 | // Go support for Protocol Buffers - Google's data interchange format 2 | // 3 | // Copyright 2013 The Go Authors. All rights reserved. 4 | // http://code.google.com/p/goprotobuf/ 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 | package generator 33 | 34 | import ( 35 | "testing" 36 | ) 37 | 38 | func TestCamelCase(t *testing.T) { 39 | tests := []struct { 40 | in, want string 41 | }{ 42 | {"one", "One"}, 43 | {"one_two", "OneTwo"}, 44 | {"_my_field_name_2", "XMyFieldName_2"}, 45 | {"Something_Capped", "Something_Capped"}, 46 | {"my_Name", "My_Name"}, 47 | {"OneTwo", "OneTwo"}, 48 | {"_", "X"}, 49 | {"_a_", "XA_"}, 50 | } 51 | for _, tc := range tests { 52 | if got := CamelCase(tc.in); got != tc.want { 53 | t.Errorf("CamelCase(%q) = %q, want %q", tc.in, got, tc.want) 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /_vendor/src/code.google.com/p/goprotobuf/protoc-gen-go/plugin/Makefile: -------------------------------------------------------------------------------- 1 | # Go support for Protocol Buffers - Google's data interchange format 2 | # 3 | # Copyright 2010 The Go Authors. All rights reserved. 4 | # http://code.google.com/p/goprotobuf/ 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 | # Not stored here, but plugin.proto is in http://code.google.com/p/protobuf 33 | # at protobuf-2.5.0/src/google/protobuf/compiler/plugin.proto 34 | # Also we need to fix an import. 35 | regenerate: 36 | echo WARNING! THIS RULE IS PROBABLY NOT RIGHT FOR YOUR INSTALLATION 37 | cd $(HOME)/src/protobuf-2.5.0/src && \ 38 | protoc --go_out=. ./google/protobuf/compiler/plugin.proto && \ 39 | cat ./google/protobuf/compiler/plugin.pb.go | \ 40 | sed '/^import/s;google/protobuf/descriptor.pb;code.google.com/p/goprotobuf/protoc-gen-go/descriptor;' > $(GOPATH)/src/code.google.com/p/goprotobuf/protoc-gen-go/plugin/plugin.pb.go 41 | 42 | restore: 43 | cp plugin.pb.golden plugin.pb.go 44 | 45 | preserve: 46 | cp plugin.pb.go plugin.pb.golden 47 | -------------------------------------------------------------------------------- /_vendor/src/code.google.com/p/goprotobuf/protoc-gen-go/testdata/Makefile: -------------------------------------------------------------------------------- 1 | # Go support for Protocol Buffers - Google's data interchange format 2 | # 3 | # Copyright 2010 The Go Authors. All rights reserved. 4 | # http://code.google.com/p/goprotobuf/ 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 | all: 33 | @echo run make test 34 | 35 | include ../../Make.protobuf 36 | 37 | test: golden testbuild 38 | 39 | #test: golden testbuild extension_test 40 | # ./extension_test 41 | # @echo PASS 42 | 43 | golden: 44 | make -B my_test/test.pb.go 45 | diff -w my_test/test.pb.go my_test/test.pb.go.golden 46 | 47 | nuke: clean 48 | 49 | testbuild: buildprotos 50 | go test 51 | 52 | buildprotos: 53 | # Invoke protoc once to generate three independent .pb.go files in the same package. 54 | protoc --go_out=. multi/multi{1,2,3}.proto 55 | 56 | #extension_test: extension_test.$O 57 | # $(LD) -L. -o $@ $< 58 | 59 | #multi.a: multi3.pb.$O multi2.pb.$O multi1.pb.$O 60 | # rm -f multi.a 61 | # $(QUOTED_GOBIN)/gopack grc $@ $< 62 | 63 | #test.pb.go: imp.pb.go 64 | #multi1.pb.go: multi2.pb.go multi3.pb.go 65 | #main.$O: imp.pb.$O test.pb.$O multi.a 66 | #extension_test.$O: extension_base.pb.$O extension_extra.pb.$O extension_user.pb.$O 67 | -------------------------------------------------------------------------------- /_vendor/src/code.google.com/p/goprotobuf/protoc-gen-go/testdata/extension_base.proto: -------------------------------------------------------------------------------- 1 | // Go support for Protocol Buffers - Google's data interchange format 2 | // 3 | // Copyright 2010 The Go Authors. All rights reserved. 4 | // http://code.google.com/p/goprotobuf/ 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 | package extension_base; 33 | 34 | message BaseMessage { 35 | optional int32 height = 1; 36 | extensions 4 to 9; 37 | extensions 16 to max; 38 | } 39 | 40 | // Another message that may be extended, using message_set_wire_format. 41 | message OldStyleMessage { 42 | option message_set_wire_format = true; 43 | extensions 100 to max; 44 | } 45 | -------------------------------------------------------------------------------- /_vendor/src/code.google.com/p/goprotobuf/protoc-gen-go/testdata/extension_extra.proto: -------------------------------------------------------------------------------- 1 | // Go support for Protocol Buffers - Google's data interchange format 2 | // 3 | // Copyright 2011 The Go Authors. All rights reserved. 4 | // http://code.google.com/p/goprotobuf/ 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 | syntax = "proto2"; 33 | 34 | package extension_extra; 35 | 36 | message ExtraMessage { 37 | optional int32 width = 1; 38 | } 39 | -------------------------------------------------------------------------------- /_vendor/src/code.google.com/p/goprotobuf/protoc-gen-go/testdata/imp.proto: -------------------------------------------------------------------------------- 1 | // Go support for Protocol Buffers - Google's data interchange format 2 | // 3 | // Copyright 2010 The Go Authors. All rights reserved. 4 | // http://code.google.com/p/goprotobuf/ 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 | package imp; 33 | 34 | import "imp2.proto"; 35 | import "imp3.proto"; 36 | 37 | message ImportedMessage { 38 | required int64 field = 1; 39 | 40 | // The forwarded getters for these fields are fiddly to get right. 41 | optional ImportedMessage2 local_msg = 2; 42 | optional ForeignImportedMessage foreign_msg = 3; // in imp3.proto 43 | optional Owner enum_field = 4; 44 | 45 | repeated string name = 5; 46 | repeated Owner boss = 6; 47 | repeated ImportedMessage2 memo = 7; 48 | 49 | enum Owner { 50 | DAVE = 1; 51 | MIKE = 2; 52 | } 53 | 54 | extensions 90 to 100; 55 | } 56 | 57 | message ImportedMessage2 { 58 | } 59 | 60 | message ImportedExtendable { 61 | option message_set_wire_format = true; 62 | extensions 100 to max; 63 | } 64 | -------------------------------------------------------------------------------- /_vendor/src/code.google.com/p/goprotobuf/protoc-gen-go/testdata/imp2.proto: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2011 The Go Authors. All rights reserved. 3 | // http://code.google.com/p/goprotobuf/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // 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 | // OWNER 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 | 31 | package imp; 32 | 33 | message PubliclyImportedMessage { 34 | optional int64 field = 1; 35 | } 36 | 37 | enum PubliclyImportedEnum { 38 | GLASSES = 1; 39 | HAIR = 2; 40 | } 41 | -------------------------------------------------------------------------------- /_vendor/src/code.google.com/p/goprotobuf/protoc-gen-go/testdata/imp3.proto: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2012 The Go Authors. All rights reserved. 3 | // http://code.google.com/p/goprotobuf/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // 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 | // OWNER 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 | 31 | package imp; 32 | 33 | message ForeignImportedMessage { 34 | optional string tuber = 1; 35 | } 36 | -------------------------------------------------------------------------------- /_vendor/src/code.google.com/p/goprotobuf/protoc-gen-go/testdata/main_test.go: -------------------------------------------------------------------------------- 1 | // Go support for Protocol Buffers - Google's data interchange format 2 | // 3 | // Copyright 2010 The Go Authors. All rights reserved. 4 | // http://code.google.com/p/goprotobuf/ 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 | // A simple binary to link together the protocol buffers in this test. 33 | 34 | package testdata 35 | 36 | import ( 37 | "testing" 38 | 39 | "./multi" 40 | "./my_test" 41 | ) 42 | 43 | func TestLink(t *testing.T) { 44 | _ = &multi.Multi1{} 45 | _ = &my_test.Request{} 46 | } 47 | -------------------------------------------------------------------------------- /_vendor/src/code.google.com/p/goprotobuf/protoc-gen-go/testdata/multi/multi1.proto: -------------------------------------------------------------------------------- 1 | // Go support for Protocol Buffers - Google's data interchange format 2 | // 3 | // Copyright 2010 The Go Authors. All rights reserved. 4 | // http://code.google.com/p/goprotobuf/ 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 | import "multi/multi2.proto"; 33 | import "multi/multi3.proto"; 34 | 35 | package multi; 36 | 37 | message Multi1 { 38 | required Multi2 multi2 = 1; 39 | optional Multi2.Color color = 2; 40 | optional Multi3.HatType hat_type = 3; 41 | } 42 | 43 | -------------------------------------------------------------------------------- /_vendor/src/code.google.com/p/goprotobuf/protoc-gen-go/testdata/multi/multi2.proto: -------------------------------------------------------------------------------- 1 | // Go support for Protocol Buffers - Google's data interchange format 2 | // 3 | // Copyright 2010 The Go Authors. All rights reserved. 4 | // http://code.google.com/p/goprotobuf/ 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 | package multi; 33 | 34 | message Multi2 { 35 | required int32 required_value = 1; 36 | 37 | enum Color { 38 | BLUE = 1; 39 | GREEN = 2; 40 | RED = 3; 41 | }; 42 | optional Color color = 2; 43 | } 44 | 45 | -------------------------------------------------------------------------------- /_vendor/src/code.google.com/p/goprotobuf/protoc-gen-go/testdata/multi/multi3.proto: -------------------------------------------------------------------------------- 1 | // Go support for Protocol Buffers - Google's data interchange format 2 | // 3 | // Copyright 2010 The Go Authors. All rights reserved. 4 | // http://code.google.com/p/goprotobuf/ 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 | package multi; 33 | 34 | message Multi3 { 35 | enum HatType { 36 | FEDORA = 1; 37 | FEZ = 2; 38 | }; 39 | optional HatType hat_type = 1; 40 | } 41 | 42 | -------------------------------------------------------------------------------- /_vendor/src/github.com/garyburd/redigo/README.markdown: -------------------------------------------------------------------------------- 1 | Redigo 2 | ====== 3 | 4 | Redigo is a [Go](http://golang.org/) client for the [Redis](http://redis.io/) database. 5 | 6 | Features 7 | ------- 8 | 9 | * A [Print-like](http://godoc.org/github.com/garyburd/redigo/redis#hdr-Executing_Commands) API with support for all Redis commands. 10 | * [Pipelining](http://godoc.org/github.com/garyburd/redigo/redis#hdr-Pipelining), including pipelined transactions. 11 | * [Publish/Subscribe](http://godoc.org/github.com/garyburd/redigo/redis#hdr-Publish_and_Subscribe). 12 | * [Connection pooling](http://godoc.org/github.com/garyburd/redigo/redis#Pool). 13 | * [Script helper type](http://godoc.org/github.com/garyburd/redigo/redis#Script) with optimistic use of EVALSHA. 14 | * [Helper functions](http://godoc.org/github.com/garyburd/redigo/redis#hdr-Reply_Helpers) for working with command replies. 15 | 16 | Documentation 17 | ------------- 18 | 19 | - [API Reference](http://godoc.org/github.com/garyburd/redigo/redis) 20 | - [FAQ](https://github.com/garyburd/redigo/wiki/FAQ) 21 | 22 | Installation 23 | ------------ 24 | 25 | Install Redigo using the "go get" command: 26 | 27 | go get github.com/garyburd/redigo/redis 28 | 29 | The Go distribution is Redigo's only dependency. 30 | 31 | Contributing 32 | ------------ 33 | 34 | Contributions are welcome. 35 | 36 | Before writing code, send mail to gary@beagledreams.com to discuss what you 37 | plan to do. This gives me a chance to validate the design, avoid duplication of 38 | effort and ensure that the changes fit the goals of the project. Do not start 39 | the discussion with a pull request. 40 | 41 | License 42 | ------- 43 | 44 | Redigo is available under the [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0.html). 45 | -------------------------------------------------------------------------------- /_vendor/src/github.com/garyburd/redigo/redis/redis.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 Gary Burd 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"): you may 4 | // not use this file except in compliance with the License. You may obtain 5 | // 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, WITHOUT 11 | // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | // License for the specific language governing permissions and limitations 13 | // under the License. 14 | 15 | package redis 16 | 17 | // Error represents an error returned in a command reply. 18 | type Error string 19 | 20 | func (err Error) Error() string { return string(err) } 21 | 22 | // Conn represents a connection to a Redis server. 23 | type Conn interface { 24 | // Close closes the connection. 25 | Close() error 26 | 27 | // Err returns a non-nil value if the connection is broken. The returned 28 | // value is either the first non-nil value returned from the underlying 29 | // network connection or a protocol parsing error. Applications should 30 | // close broken connections. 31 | Err() error 32 | 33 | // Do sends a command to the server and returns the received reply. 34 | Do(commandName string, args ...interface{}) (reply interface{}, err error) 35 | 36 | // Send writes the command to the client's output buffer. 37 | Send(commandName string, args ...interface{}) error 38 | 39 | // Flush flushes the output buffer to the Redis server. 40 | Flush() error 41 | 42 | // Receive receives a single reply from the Redis server 43 | Receive() (reply interface{}, err error) 44 | } 45 | -------------------------------------------------------------------------------- /_vendor/src/github.com/garyburd/redigo/redis/test_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 Gary Burd 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"): you may 4 | // not use this file except in compliance with the License. You may obtain 5 | // 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, WITHOUT 11 | // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | // License for the specific language governing permissions and limitations 13 | // under the License. 14 | 15 | package redis 16 | 17 | import ( 18 | "bufio" 19 | "net" 20 | ) 21 | 22 | type dummyClose struct{ net.Conn } 23 | 24 | func (dummyClose) Close() error { return nil } 25 | 26 | // NewConnBufio is a hook for tests. 27 | func NewConnBufio(rw bufio.ReadWriter) Conn { 28 | return &conn{br: rw.Reader, bw: rw.Writer, conn: dummyClose{}} 29 | } 30 | -------------------------------------------------------------------------------- /_vendor/src/github.com/garyburd/redigo/redisx/doc.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 Gary Burd 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"): you may 4 | // not use this file except in compliance with the License. You may obtain 5 | // 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, WITHOUT 11 | // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | // License for the specific language governing permissions and limitations 13 | // under the License. 14 | 15 | // Package redisx contains experimental features for Redigo. Features in this 16 | // package may be modified or deleted at any time. 17 | package redisx 18 | -------------------------------------------------------------------------------- /_vendor/src/github.com/garyburd/redigo/redisx/example.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 Gary Burd 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"): you may 4 | // not use this file except in compliance with the License. You may obtain 5 | // 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, WITHOUT 11 | // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | // License for the specific language governing permissions and limitations 13 | // under the License. 14 | 15 | // +build ignore 16 | 17 | package main 18 | 19 | import ( 20 | "github.com/garyburd/redigo/redis" 21 | "github.com/garyburd/redigo/redisx" 22 | "log" 23 | ) 24 | 25 | type MyStruct struct { 26 | A int 27 | B string 28 | } 29 | 30 | func main() { 31 | c, err := redis.Dial("tcp", ":6379") 32 | if err != nil { 33 | log.Fatal(err) 34 | } 35 | 36 | v0 := &MyStruct{1, "hello"} 37 | 38 | _, err = c.Do("HMSET", redisx.AppendStruct([]interface{}{"key"}, v0)...) 39 | if err != nil { 40 | log.Fatal(err) 41 | } 42 | 43 | reply, err := c.Do("HGETALL", "key") 44 | if err != nil { 45 | log.Fatal(err) 46 | } 47 | 48 | v1 := &MyStruct{} 49 | 50 | err = redisx.ScanStruct(reply, v1) 51 | if err != nil { 52 | log.Fatal(err) 53 | } 54 | log.Printf("v1=%v", v1) 55 | } 56 | -------------------------------------------------------------------------------- /_vendor/src/github.com/garyburd/redigo/redisx/struct_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 Gary Burd 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"): you may 4 | // not use this file except in compliance with the License. You may obtain 5 | // 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, WITHOUT 11 | // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | // License for the specific language governing permissions and limitations 13 | // under the License. 14 | 15 | package redisx_test 16 | 17 | import ( 18 | "github.com/garyburd/redigo/redisx" 19 | "reflect" 20 | "testing" 21 | ) 22 | 23 | var scanStructTests = []struct { 24 | title string 25 | reply []string 26 | value interface{} 27 | }{ 28 | {"basic", 29 | []string{"i", "-1234", "u", "5678", "s", "hello", "p", "world", "b", "", "Bt", "1", "Bf", "0"}, 30 | &struct { 31 | I int `redis:"i"` 32 | U uint `redis:"u"` 33 | S string `redis:"s"` 34 | P []byte `redis:"p"` 35 | B bool `redis:"b"` 36 | Bt bool 37 | Bf bool 38 | }{ 39 | -1234, 5678, "hello", []byte("world"), false, true, false, 40 | }, 41 | }, 42 | } 43 | 44 | func TestScanStruct(t *testing.T) { 45 | for _, tt := range scanStructTests { 46 | 47 | var reply []interface{} 48 | for _, v := range tt.reply { 49 | reply = append(reply, []byte(v)) 50 | } 51 | 52 | value := reflect.New(reflect.ValueOf(tt.value).Type().Elem()) 53 | 54 | if err := redisx.ScanStruct(reply, value.Interface()); err != nil { 55 | t.Fatalf("ScanStruct(%s) returned error %v", tt.title, err) 56 | } 57 | 58 | if !reflect.DeepEqual(value.Interface(), tt.value) { 59 | t.Fatalf("ScanStruct(%s) returned %v, want %v", tt.title, value.Interface(), tt.value) 60 | } 61 | } 62 | } 63 | 64 | var formatStructTests = []struct { 65 | title string 66 | args []interface{} 67 | value interface{} 68 | }{ 69 | {"basic", 70 | []interface{}{"i", int(-1234), "u", uint(5678), "s", "hello", "p", []byte("world"), "Bt", true, "Bf", false}, 71 | &struct { 72 | I int `redis:"i"` 73 | U uint `redis:"u"` 74 | S string `redis:"s"` 75 | P []byte `redis:"p"` 76 | Bt bool 77 | Bf bool 78 | }{ 79 | -1234, 5678, "hello", []byte("world"), true, false, 80 | }, 81 | }, 82 | } 83 | 84 | func TestFormatStruct(t *testing.T) { 85 | for _, tt := range formatStructTests { 86 | args := redisx.AppendStruct(nil, tt.value) 87 | if !reflect.DeepEqual(args, tt.args) { 88 | t.Fatalf("FormatStruct(%s) returned %v, want %v", tt.title, args, tt.args) 89 | } 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /_vendor/src/github.com/gorilla/context/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | 3 | go: 4 | - 1.0 5 | - 1.1 6 | - 1.2 7 | - tip 8 | -------------------------------------------------------------------------------- /_vendor/src/github.com/gorilla/context/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012 Rodrigo Moraes. 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 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above 10 | copyright notice, this list of conditions and the following disclaimer 11 | in the documentation and/or other materials provided with the 12 | distribution. 13 | * Neither the name of Google Inc. nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /_vendor/src/github.com/gorilla/context/README.md: -------------------------------------------------------------------------------- 1 | context 2 | ======= 3 | [![Build Status](https://travis-ci.org/gorilla/context.png?branch=master)](https://travis-ci.org/gorilla/context) 4 | 5 | gorilla/context is a general purpose registry for global request variables. 6 | 7 | Read the full documentation here: http://www.gorillatoolkit.org/pkg/context 8 | -------------------------------------------------------------------------------- /_vendor/src/github.com/gorilla/context/context_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 The Gorilla 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 context 6 | 7 | import ( 8 | "net/http" 9 | "testing" 10 | ) 11 | 12 | type keyType int 13 | 14 | const ( 15 | key1 keyType = iota 16 | key2 17 | ) 18 | 19 | func TestContext(t *testing.T) { 20 | assertEqual := func(val interface{}, exp interface{}) { 21 | if val != exp { 22 | t.Errorf("Expected %v, got %v.", exp, val) 23 | } 24 | } 25 | 26 | r, _ := http.NewRequest("GET", "http://localhost:8080/", nil) 27 | 28 | // Get() 29 | assertEqual(Get(r, key1), nil) 30 | 31 | // Set() 32 | Set(r, key1, "1") 33 | assertEqual(Get(r, key1), "1") 34 | assertEqual(len(data[r]), 1) 35 | 36 | Set(r, key2, "2") 37 | assertEqual(Get(r, key2), "2") 38 | assertEqual(len(data[r]), 2) 39 | 40 | //GetOk 41 | value, ok := GetOk(r, key1) 42 | assertEqual(value, "1") 43 | assertEqual(ok, true) 44 | 45 | value, ok = GetOk(r, "not exists") 46 | assertEqual(value, nil) 47 | assertEqual(ok, false) 48 | 49 | Set(r, "nil value", nil) 50 | value, ok = GetOk(r, "nil value") 51 | assertEqual(value, nil) 52 | assertEqual(ok, true) 53 | 54 | // Delete() 55 | Delete(r, key1) 56 | assertEqual(Get(r, key1), nil) 57 | assertEqual(len(data[r]), 2) 58 | 59 | Delete(r, key2) 60 | assertEqual(Get(r, key2), nil) 61 | assertEqual(len(data[r]), 1) 62 | 63 | // Clear() 64 | Clear(r) 65 | assertEqual(len(data), 0) 66 | } 67 | -------------------------------------------------------------------------------- /_vendor/src/github.com/gorilla/mux/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | 3 | go: 4 | - 1.0 5 | - 1.1 6 | - 1.2 7 | - tip 8 | -------------------------------------------------------------------------------- /_vendor/src/github.com/gorilla/mux/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012 Rodrigo Moraes. 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 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above 10 | copyright notice, this list of conditions and the following disclaimer 11 | in the documentation and/or other materials provided with the 12 | distribution. 13 | * Neither the name of Google Inc. nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /_vendor/src/github.com/gorilla/mux/README.md: -------------------------------------------------------------------------------- 1 | mux 2 | === 3 | [![Build Status](https://travis-ci.org/gorilla/mux.png?branch=master)](https://travis-ci.org/gorilla/mux) 4 | 5 | gorilla/mux is a powerful URL router and dispatcher. 6 | 7 | Read the full documentation here: http://www.gorillatoolkit.org/pkg/mux 8 | -------------------------------------------------------------------------------- /_vendor/src/github.com/gorilla/mux/bench_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 The Gorilla 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 mux 6 | 7 | import ( 8 | "net/http" 9 | "testing" 10 | ) 11 | 12 | func BenchmarkMux(b *testing.B) { 13 | router := new(Router) 14 | handler := func(w http.ResponseWriter, r *http.Request) {} 15 | router.HandleFunc("/v1/{v1}", handler) 16 | 17 | request, _ := http.NewRequest("GET", "/v1/anything", nil) 18 | for i := 0; i < b.N; i++ { 19 | router.ServeHTTP(nil, request) 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /_vendor/src/github.com/gorilla/pat/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | 3 | go: 4 | - 1.0 5 | - 1.1 6 | - 1.2 7 | - tip 8 | -------------------------------------------------------------------------------- /_vendor/src/github.com/gorilla/pat/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012 Rodrigo Moraes. 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 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above 10 | copyright notice, this list of conditions and the following disclaimer 11 | in the documentation and/or other materials provided with the 12 | distribution. 13 | * Neither the name of Google Inc. nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /_vendor/src/github.com/gorilla/pat/README.md: -------------------------------------------------------------------------------- 1 | pat 2 | === 3 | [![Build Status](https://travis-ci.org/gorilla/pat.png?branch=master)](https://travis-ci.org/gorilla/pat) 4 | -------------------------------------------------------------------------------- /_vendor/src/github.com/gorilla/pat/doc.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 The Gorilla 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 | /* 6 | Package gorilla/pat is a request router and dispatcher with a pat-like 7 | interface. It is an alternative to gorilla/mux that showcases how it can 8 | be used as a base for different API flavors. Package pat is documented at: 9 | 10 | http://godoc.org/github.com/bmizerany/pat 11 | 12 | Let's start registering a couple of URL paths and handlers: 13 | 14 | func main() { 15 | r := pat.New() 16 | r.Get("/products", ProductsHandler) 17 | r.Get("/articles", ArticlesHandler) 18 | r.Get("/", HomeHandler) 19 | http.Handle("/", r) 20 | } 21 | 22 | Here we register three routes mapping URL paths to handlers. This is 23 | equivalent to how http.HandleFunc() works: if an incoming GET request matches 24 | one of the paths, the corresponding handler is called passing 25 | (http.ResponseWriter, *http.Request) as parameters. 26 | 27 | Note: gorilla/pat matches path prefixes, so you must register the most 28 | specific paths first. 29 | 30 | Note: differently from pat, these methods accept a handler function, and not an 31 | http.Handler. We think this is shorter and more convenient. To set an 32 | http.Handler, use the Add() method. 33 | 34 | Paths can have variables. They are defined using the format {name} or 35 | {name:pattern}. If a regular expression pattern is not defined, the matched 36 | variable will be anything until the next slash. For example: 37 | 38 | r := pat.New() 39 | r.Get("/articles/{category}/{id:[0-9]+}", ArticleHandler) 40 | r.Get("/articles/{category}/", ArticlesCategoryHandler) 41 | r.Get("/products/{key}", ProductHandler) 42 | 43 | The names are used to create a map of route variables which are stored in the 44 | URL query, prefixed by a colon: 45 | 46 | category := req.URL.Query().Get(":category") 47 | 48 | As in the gorilla/mux package, other matchers can be added to the registered 49 | routes and URLs can be reversed as well. To build a URL for a route, first 50 | add a name to it: 51 | 52 | r.Get("/products/{key}", ProductHandler).Name("product") 53 | 54 | Then you can get it using the name and generate a URL: 55 | 56 | url, err := r.GetRoute("product").URL("key", "transmogrifier") 57 | 58 | ...and the result will be a url.URL with the following path: 59 | 60 | "/products/transmogrifier" 61 | 62 | Check the mux documentation for more details about URL building and extra 63 | matchers: 64 | 65 | http://gorilla-web.appspot.com/pkg/mux/ 66 | */ 67 | package pat 68 | -------------------------------------------------------------------------------- /_vendor/src/github.com/gorilla/pat/pat_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 The Gorilla 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 pat 6 | 7 | import ( 8 | "net/http" 9 | "testing" 10 | 11 | "github.com/gorilla/mux" 12 | ) 13 | 14 | func myHandler(w http.ResponseWriter, r *http.Request) { 15 | } 16 | 17 | func testMatch(t *testing.T, meth, pat, path string, ok bool, vars map[string]string) { 18 | r := New() 19 | switch meth { 20 | case "DELETE": 21 | r.Delete(pat, myHandler) 22 | case "GET": 23 | r.Get(pat, myHandler) 24 | case "POST": 25 | r.Post(pat, myHandler) 26 | case "PUT": 27 | r.Put(pat, myHandler) 28 | } 29 | req, _ := http.NewRequest(meth, "http://localhost"+path, nil) 30 | m := mux.RouteMatch{} 31 | if r.Match(req, &m) != ok { 32 | if ok { 33 | t.Errorf("Expected request to %q to match %q", path, pat) 34 | } else { 35 | t.Errorf("Expected request to %q to not match %q", path, pat) 36 | } 37 | } else if ok && vars != nil { 38 | registerVars(req, m.Vars) 39 | q := req.URL.Query() 40 | for k, v := range vars { 41 | if q.Get(k) != v { 42 | t.Errorf("Variable missing: %q (value: %q)", k, q.Get(k)) 43 | } 44 | } 45 | } 46 | } 47 | 48 | func TestPatMatch(t *testing.T) { 49 | testMatch(t, "DELETE", "/foo/{name}", "/foo/bar", true, map[string]string{":name": "bar"}) 50 | testMatch(t, "GET", "/foo/{name}", "/foo/bar/baz", true, map[string]string{":name": "bar"}) 51 | testMatch(t, "POST", "/foo/{name}/baz", "/foo/bar/baz", true, map[string]string{":name": "bar"}) 52 | testMatch(t, "PUT", "/foo/{name}/baz", "/foo/bar/baz/ding", true, map[string]string{":name": "bar"}) 53 | testMatch(t, "GET", "/foo/x{name}", "/foo/xbar", true, map[string]string{":name": "bar"}) 54 | testMatch(t, "GET", "/foo/x{name}", "/foo/xbar/baz", true, map[string]string{":name": "bar"}) 55 | } 56 | -------------------------------------------------------------------------------- /_vendor/src/github.com/matttproud/golang_protobuf_extensions/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | 3 | -------------------------------------------------------------------------------- /_vendor/src/github.com/matttproud/golang_protobuf_extensions/README.md: -------------------------------------------------------------------------------- 1 | # Overview 2 | This repository provides various Protocol Buffer extensions for the Go 3 | language (golang), namely support for record length-delimited message 4 | streaming. 5 | 6 | Until [Code Review 9102043](https://codereview.appspot.com/9102043/) is merged, this repository will exist here in the wild. 7 | 8 | # Documentation 9 | We have [generated Go Doc documentation](http://godoc.org/github.com/matttproud/golang_protobuf_extensions/ext) here. 10 | 11 | # Testing 12 | [![Build Status](https://travis-ci.org/matttproud/golang_protobuf_extensions.png?branch=master)](https://travis-ci.org/matttproud/golang_protobuf_extensions) 13 | -------------------------------------------------------------------------------- /_vendor/src/github.com/matttproud/golang_protobuf_extensions/ext/documentation.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 | // Helpers for Protocol Buffers to enable record length-delimited streaming. 16 | package ext 17 | -------------------------------------------------------------------------------- /_vendor/src/github.com/matttproud/golang_protobuf_extensions/ext/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 ext 16 | 17 | import ( 18 | "encoding/binary" 19 | "io" 20 | 21 | "code.google.com/p/goprotobuf/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. 29 | func WriteDelimited(w io.Writer, m proto.Message) (n int, err error) { 30 | buffer, err := proto.Marshal(m) 31 | if err != nil { 32 | return 0, err 33 | } 34 | 35 | buf := make([]byte, binary.MaxVarintLen32) 36 | encodedLength := binary.PutUvarint(buf, uint64(len(buffer))) 37 | 38 | sync, err := w.Write(buf[:encodedLength]) 39 | if err != nil { 40 | return sync, err 41 | } 42 | 43 | n, err = w.Write(buffer) 44 | return n + sync, err 45 | } 46 | -------------------------------------------------------------------------------- /_vendor/src/github.com/peterbourgon/g2s/.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 | *.exe 23 | -------------------------------------------------------------------------------- /_vendor/src/github.com/peterbourgon/g2s/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | 3 | -------------------------------------------------------------------------------- /_vendor/src/github.com/peterbourgon/g2s/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012, Peter Bourgon, SoundCloud Ltd. 2 | 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 met: 6 | 7 | Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | Redistributions in binary form must reproduce the above copyright notice, this 11 | list of conditions and the following disclaimer in the documentation and/or 12 | other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 15 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 16 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | -------------------------------------------------------------------------------- /_vendor/src/github.com/peterbourgon/g2s/README.md: -------------------------------------------------------------------------------- 1 | # g2s 2 | 3 | Get to Statsd: forward simple statistics to a statsd server. 4 | 5 | [![Build Status][1]][2] [![GoDoc][3]][4] 6 | 7 | [1]: https://secure.travis-ci.org/peterbourgon/g2s.png 8 | [2]: http://www.travis-ci.org/peterbourgon/g2s 9 | [3]: https://godoc.org/github.com/peterbourgon/g2s?status.svg 10 | [4]: https://godoc.org/github.com/peterbourgon/g2s 11 | 12 | # Usage 13 | 14 | g2s provides a Statsd object, which provides some convenience functions for 15 | each of the supported statsd statistic-types. Just call the relevant function 16 | on the Statsd object wherever it makes sense in your code. 17 | 18 | ```go 19 | s, err := g2s.Dial("udp", "statsd-server:8125") 20 | if err != nil { 21 | // do something 22 | } 23 | 24 | s.Counter(1.0, "my.silly.counter", 1) 25 | s.Timing(1.0, "my.silly.slow-process", time.Since(somethingBegan)) 26 | s.Timing(0.2, "my.silly.fast-process", 7*time.Millisecond) 27 | s.Gauge(1.0, "my.silly.status", "green") 28 | ``` 29 | 30 | If you use a standard UDP connection to a statsd server, all 'update'-class 31 | functions are goroutine safe. They should return quickly, but they're safe to 32 | fire in a seperate goroutine. 33 | 34 | # Upgrading API 35 | 36 | Upgrade to the latest API by running `./fix.bash *.go` where `*.go` expands to 37 | the paths of the source files you'd like to rewrite to the new API. 38 | -------------------------------------------------------------------------------- /_vendor/src/github.com/peterbourgon/g2s/fix.bash: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | # Applies transformations to source trees to keep up to date with 4 | # with the external API. 5 | # 6 | if [ -z "$@" ]; then 7 | echo "Usage: $0 path/to/package" 8 | exit 1 9 | fi 10 | 11 | gofmt \ 12 | -r 'NewStatsd(a) -> Dial("udp",a)' \ 13 | -r 'UpdateGague(a,b) -> Gauge(1.0,a,b)' \ 14 | -r 'UpdateSampledGaguge(a,b,c) -> Gauge(c,a,b)' \ 15 | -r 'SendTiming(a,b) -> Timing(1.0,a,b)' \ 16 | -r 'SendSampledTiming(a,b,c) -> Timing(c,a,b)' \ 17 | -r 'IncrementCounter(a,b) -> Count(1.0,a,b)' \ 18 | -r 'IncrementSampledCounter(a,b,c) -> Count(c,a,b)' \ 19 | -w $@ 20 | -------------------------------------------------------------------------------- /_vendor/src/github.com/peterbourgon/g2s/safe.go: -------------------------------------------------------------------------------- 1 | package g2s 2 | 3 | import ( 4 | "time" 5 | ) 6 | 7 | type noStatsd struct{} 8 | 9 | func (n noStatsd) Counter(float32, string, ...int) {} 10 | func (n noStatsd) Timing(float32, string, ...time.Duration) {} 11 | func (n noStatsd) Gauge(float32, string, ...string) {} 12 | 13 | // Noop returns a struct that satisfies the Statter interface but silently 14 | // ignores all Statter method invocations. It's designed to be used when normal 15 | // g2s construction fails, eg. 16 | // 17 | // s, err := g2s.Dial("udp", someEndpoint) 18 | // if err != nil { 19 | // log.Printf("not sending statistics to statsd (%s)", err) 20 | // s = g2s.Noop() 21 | // } 22 | // 23 | func Noop() Statter { 24 | return noStatsd{} 25 | } 26 | -------------------------------------------------------------------------------- /_vendor/src/github.com/peterbourgon/g2s/types.go: -------------------------------------------------------------------------------- 1 | package g2s 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | type sendable interface { 8 | Message() string 9 | } 10 | 11 | type sampling struct { 12 | enabled bool 13 | rate float32 14 | } 15 | 16 | func (s *sampling) Suffix() string { 17 | if s.enabled { 18 | return fmt.Sprintf("|@%f", s.rate) 19 | } 20 | return "" 21 | } 22 | 23 | type counterUpdate struct { 24 | bucket string 25 | n int 26 | sampling 27 | } 28 | 29 | func (u *counterUpdate) Message() string { 30 | return fmt.Sprintf("%s:%d|c%s\n", u.bucket, u.n, u.sampling.Suffix()) 31 | } 32 | 33 | type timingUpdate struct { 34 | bucket string 35 | ms int 36 | sampling 37 | } 38 | 39 | func (u *timingUpdate) Message() string { 40 | return fmt.Sprintf("%s:%d|ms\n", u.bucket, u.ms) 41 | } 42 | 43 | type gaugeUpdate struct { 44 | bucket string 45 | val string 46 | sampling 47 | } 48 | 49 | func (u *gaugeUpdate) Message() string { 50 | return fmt.Sprintf("%s:%s|g\n", u.bucket, u.val) 51 | } 52 | -------------------------------------------------------------------------------- /_vendor/src/github.com/prometheus/client_golang/.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 | *.exe 23 | 24 | *~ 25 | *# 26 | .build 27 | -------------------------------------------------------------------------------- /_vendor/src/github.com/prometheus/client_golang/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | 3 | go: 4 | - 1.2.1 5 | 6 | script: 7 | - make -f Makefile 8 | -------------------------------------------------------------------------------- /_vendor/src/github.com/prometheus/client_golang/README.md: -------------------------------------------------------------------------------- 1 | # Overview 2 | This is the [Prometheus](http://www.prometheus.io) 3 | [Go](http://golang.org) client library. It provides several distinct 4 | functions, and there is separate documentation for each respective 5 | component. You will want to select the appropriate topic below to 6 | continue your journey: 7 | 8 | 1. See the [exposition library](prometheus/README.md) if you want to 9 | export metrics to a Prometheus server or pushgateway 10 | 11 | 2. See the [consumption library](extraction/README.md) if you want to 12 | process metrics exported by a Prometheus client. (The Prometheus server 13 | is using that library.) 14 | 15 | [![GoDoc](https://godoc.org/github.com/prometheus/client_golang?status.png)](https://godoc.org/github.com/prometheus/client_golang) 16 | 17 | # Getting Started 18 | 19 | * The source code is periodically indexed: [Go Exposition Client](http://godoc.org/github.com/prometheus/client_golang). 20 | * All of the core developers are accessible via the [Prometheus Developers Mailinglist](https://groups.google.com/forum/?fromgroups#!forum/prometheus-developers). 21 | 22 | # Testing 23 | $ go test ./... 24 | 25 | # Continuous Integration 26 | [![Build Status](https://secure.travis-ci.org/prometheus/client_golang.png?branch=master)]() 27 | 28 | ## Contributing 29 | 30 | See the contributing guidelines for the [Prometheus server](https://github.com/prometheus/prometheus/blob/master/CONTRIBUTING.md). 31 | -------------------------------------------------------------------------------- /_vendor/src/github.com/prometheus/client_golang/_vendor/goautoneg/MANIFEST: -------------------------------------------------------------------------------- 1 | Imported at 75cd24fc2f2c from https://bitbucket.org/ww/goautoneg. 2 | -------------------------------------------------------------------------------- /_vendor/src/github.com/prometheus/client_golang/_vendor/goautoneg/Makefile: -------------------------------------------------------------------------------- 1 | include $(GOROOT)/src/Make.inc 2 | 3 | TARG=bitbucket.org/ww/goautoneg 4 | GOFILES=autoneg.go 5 | 6 | include $(GOROOT)/src/Make.pkg 7 | 8 | format: 9 | gofmt -w *.go 10 | 11 | docs: 12 | gomake clean 13 | godoc ${TARG} > README.txt 14 | -------------------------------------------------------------------------------- /_vendor/src/github.com/prometheus/client_golang/_vendor/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/src/github.com/prometheus/client_golang/_vendor/goautoneg/autoneg_test.go: -------------------------------------------------------------------------------- 1 | package goautoneg 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | var chrome = "application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5" 8 | 9 | func TestParseAccept(t *testing.T) { 10 | alternatives := []string{"text/html", "image/png"} 11 | content_type := Negotiate(chrome, alternatives) 12 | if content_type != "image/png" { 13 | t.Errorf("got %s expected image/png", content_type) 14 | } 15 | 16 | alternatives = []string{"text/html", "text/plain", "text/n3"} 17 | content_type = Negotiate(chrome, alternatives) 18 | if content_type != "text/html" { 19 | t.Errorf("got %s expected text/html", content_type) 20 | } 21 | 22 | alternatives = []string{"text/n3", "text/plain"} 23 | content_type = Negotiate(chrome, alternatives) 24 | if content_type != "text/plain" { 25 | t.Errorf("got %s expected text/plain", content_type) 26 | } 27 | 28 | alternatives = []string{"text/n3", "application/rdf+xml"} 29 | content_type = Negotiate(chrome, alternatives) 30 | if content_type != "text/n3" { 31 | t.Errorf("got %s expected text/n3", content_type) 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /_vendor/src/github.com/prometheus/client_golang/_vendor/perks/MANIFEST: -------------------------------------------------------------------------------- 1 | Imported at da3e0acc8525a74a0ac8651ac5e7a68891291fdf from https://github.com/u-c-l/perks/tree/opt/pool-for-sample . 2 | -------------------------------------------------------------------------------- /_vendor/src/github.com/prometheus/client_golang/_vendor/perks/README.md: -------------------------------------------------------------------------------- 1 | # Perks for Go (golang.org) 2 | 3 | Perks contains the Go package quantile that computes approximate quantiles over 4 | an unbounded data stream within low memory and CPU bounds. 5 | 6 | For more information and examples, see: 7 | http://godoc.org/github.com/bmizerany/perks 8 | 9 | A very special thank you and shout out to Graham Cormode (Rutgers University), 10 | Flip Korn (AT&T Labs–Research), S. Muthukrishnan (Rutgers University), and 11 | Divesh Srivastava (AT&T Labs–Research) for their research and publication of 12 | [Effective Computation of Biased Quantiles over Data Streams](http://www.cs.rutgers.edu/~muthu/bquant.pdf) 13 | 14 | Thank you, also: 15 | * Armon Dadgar (@armon) 16 | * Andrew Gerrand (@nf) 17 | * Brad Fitzpatrick (@bradfitz) 18 | * Keith Rarick (@kr) 19 | 20 | FAQ: 21 | 22 | Q: Why not move the quantile package into the project root? 23 | A: I want to add more packages to perks later. 24 | 25 | Copyright (C) 2013 Blake Mizerany 26 | 27 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 28 | 29 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 30 | 31 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 32 | -------------------------------------------------------------------------------- /_vendor/src/github.com/prometheus/client_golang/_vendor/perks/quantile/bench_test.go: -------------------------------------------------------------------------------- 1 | package quantile 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | func BenchmarkInsertTargeted(b *testing.B) { 8 | s := NewTargeted(0.01, 0.5, 0.9, 0.99) 9 | b.ResetTimer() 10 | for i := float64(0); i < float64(b.N); i++ { 11 | s.Insert(i) 12 | } 13 | } 14 | 15 | func BenchmarkInsertTargetedSmallEpsilon(b *testing.B) { 16 | s := NewTargeted(0.01, 0.5, 0.9, 0.99) 17 | s.SetEpsilon(0.0001) 18 | b.ResetTimer() 19 | for i := float64(0); i < float64(b.N); i++ { 20 | s.Insert(i) 21 | } 22 | } 23 | 24 | func BenchmarkInsertBiased(b *testing.B) { 25 | s := NewBiased() 26 | b.ResetTimer() 27 | for i := float64(0); i < float64(b.N); i++ { 28 | s.Insert(i) 29 | } 30 | } 31 | 32 | func BenchmarkInsertBiasedSmallEpsilon(b *testing.B) { 33 | s := NewBiased() 34 | s.SetEpsilon(0.0001) 35 | b.ResetTimer() 36 | for i := float64(0); i < float64(b.N); i++ { 37 | s.Insert(i) 38 | } 39 | } 40 | 41 | func BenchmarkQuery(b *testing.B) { 42 | s := NewTargeted(0.01, 0.5, 0.9, 0.99) 43 | for i := float64(0); i < 1e6; i++ { 44 | s.Insert(i) 45 | } 46 | b.ResetTimer() 47 | n := float64(b.N) 48 | for i := float64(0); i < n; i++ { 49 | s.Query(i / n) 50 | } 51 | } 52 | 53 | func BenchmarkQuerySmallEpsilon(b *testing.B) { 54 | s := NewTargeted(0.01, 0.5, 0.9, 0.99) 55 | s.SetEpsilon(0.0001) 56 | for i := float64(0); i < 1e6; i++ { 57 | s.Insert(i) 58 | } 59 | b.ResetTimer() 60 | n := float64(b.N) 61 | for i := float64(0); i < n; i++ { 62 | s.Query(i / n) 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /_vendor/src/github.com/prometheus/client_golang/_vendor/perks/quantile/pool.go: -------------------------------------------------------------------------------- 1 | //+build !go1.3 2 | 3 | package quantile 4 | 5 | type samplePool struct { 6 | pool chan *Sample 7 | } 8 | 9 | func newSamplePool(capacity int) *samplePool { 10 | return &samplePool{pool: make(chan *Sample, capacity)} 11 | } 12 | 13 | func (sp *samplePool) Get(value, width, delta float64) *Sample { 14 | select { 15 | case sample := <-sp.pool: 16 | sample.Value, sample.Width, sample.Delta = value, width, delta 17 | return sample 18 | default: 19 | return &Sample{value, width, delta} 20 | } 21 | } 22 | 23 | func (sp *samplePool) Put(sample *Sample) { 24 | select { 25 | case sp.pool <- sample: 26 | default: 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /_vendor/src/github.com/prometheus/client_golang/_vendor/perks/quantile/pool_1_3.go: -------------------------------------------------------------------------------- 1 | //+build go1.3 2 | 3 | package quantile 4 | 5 | import "sync" 6 | 7 | // With the Go1.3 sync Pool, there is no max capacity, and a globally shared 8 | // pool is more efficient. 9 | var globalSamplePool = sync.Pool{New: func() interface{} { return &Sample{} }} 10 | 11 | type samplePool struct{} 12 | 13 | func newSamplePool(capacity int) *samplePool { 14 | // capacity ignored for Go1.3 sync.Pool. 15 | return &samplePool{} 16 | } 17 | 18 | func (_ samplePool) Get(value, width, delta float64) *Sample { 19 | sample := globalSamplePool.Get().(*Sample) 20 | sample.Value, sample.Width, sample.Delta = value, width, delta 21 | return sample 22 | } 23 | 24 | func (_ samplePool) Put(sample *Sample) { 25 | globalSamplePool.Put(sample) 26 | } 27 | -------------------------------------------------------------------------------- /_vendor/src/github.com/prometheus/client_golang/extraction/discriminator.go: -------------------------------------------------------------------------------- 1 | // Copyright 2013 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 extraction 15 | 16 | import ( 17 | "errors" 18 | "fmt" 19 | "mime" 20 | "net/http" 21 | ) 22 | 23 | // ProcessorForRequestHeader interprets a HTTP request header to determine 24 | // what Processor should be used for the given input. If no acceptable 25 | // Processor can be found, an error is returned. 26 | func ProcessorForRequestHeader(header http.Header) (Processor, error) { 27 | if header == nil { 28 | return nil, errors.New("received illegal and nil header") 29 | } 30 | 31 | mediatype, params, err := mime.ParseMediaType(header.Get("Content-Type")) 32 | if err != nil { 33 | return nil, fmt.Errorf("invalid Content-Type header %q: %s", header.Get("Content-Type"), err) 34 | } 35 | switch mediatype { 36 | case "application/vnd.google.protobuf": 37 | if params["proto"] != "io.prometheus.client.MetricFamily" { 38 | return nil, fmt.Errorf("unrecognized protocol message %s", params["proto"]) 39 | } 40 | if params["encoding"] != "delimited" { 41 | return nil, fmt.Errorf("unsupported encoding %s", params["encoding"]) 42 | } 43 | return MetricFamilyProcessor, nil 44 | case "text/plain": 45 | switch params["version"] { 46 | case "0.0.4": 47 | return Processor004, nil 48 | case "": 49 | // Fallback: most recent version. 50 | return Processor004, nil 51 | default: 52 | return nil, fmt.Errorf("unrecognized API version %s", params["version"]) 53 | } 54 | case "application/json": 55 | var prometheusAPIVersion string 56 | 57 | if params["schema"] == "prometheus/telemetry" && params["version"] != "" { 58 | prometheusAPIVersion = params["version"] 59 | } else { 60 | prometheusAPIVersion = header.Get("X-Prometheus-API-Version") 61 | } 62 | 63 | switch prometheusAPIVersion { 64 | case "0.0.2": 65 | return Processor002, nil 66 | case "0.0.1": 67 | return Processor001, nil 68 | default: 69 | return nil, fmt.Errorf("unrecognized API version %s", prometheusAPIVersion) 70 | } 71 | default: 72 | return nil, fmt.Errorf("unsupported media type %q, expected %q", mediatype, "application/json") 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /_vendor/src/github.com/prometheus/client_golang/extraction/extraction.go: -------------------------------------------------------------------------------- 1 | // Copyright 2013 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 extraction decodes Prometheus clients' data streams for consumers. 15 | package extraction 16 | -------------------------------------------------------------------------------- /_vendor/src/github.com/prometheus/client_golang/extraction/fixtures/empty.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/soundcloud/roshi/243de2162b08f7760dbf6a12a080180bd876b232/_vendor/src/github.com/prometheus/client_golang/extraction/fixtures/empty.json -------------------------------------------------------------------------------- /_vendor/src/github.com/prometheus/client_golang/extraction/fixtures/test0_0_1-0_0_2.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "baseLabels": { 4 | "__name__": "rpc_calls_total", 5 | "job": "batch_job" 6 | }, 7 | "docstring": "RPC calls.", 8 | "metric": { 9 | "type": "counter", 10 | "value": [ 11 | { 12 | "labels": { 13 | "service": "zed" 14 | }, 15 | "value": 25 16 | }, 17 | { 18 | "labels": { 19 | "service": "bar" 20 | }, 21 | "value": 25 22 | }, 23 | { 24 | "labels": { 25 | "service": "foo" 26 | }, 27 | "value": 25 28 | } 29 | ] 30 | } 31 | }, 32 | { 33 | "baseLabels": { 34 | "__name__": "rpc_latency_microseconds" 35 | }, 36 | "docstring": "RPC latency.", 37 | "metric": { 38 | "type": "histogram", 39 | "value": [ 40 | { 41 | "labels": { 42 | "service": "foo" 43 | }, 44 | "value": { 45 | "0.010000": 15.890724674774395, 46 | "0.050000": 15.890724674774395, 47 | "0.500000": 84.63044031436561, 48 | "0.900000": 160.21100853053224, 49 | "0.990000": 172.49828748957728 50 | } 51 | }, 52 | { 53 | "labels": { 54 | "service": "zed" 55 | }, 56 | "value": { 57 | "0.010000": 0.0459814091918713, 58 | "0.050000": 0.0459814091918713, 59 | "0.500000": 0.6120456642749681, 60 | "0.900000": 1.355915069887731, 61 | "0.990000": 1.772733213161236 62 | } 63 | }, 64 | { 65 | "labels": { 66 | "service": "bar" 67 | }, 68 | "value": { 69 | "0.010000": 78.48563317257356, 70 | "0.050000": 78.48563317257356, 71 | "0.500000": 97.31798360385088, 72 | "0.900000": 109.89202084295582, 73 | "0.990000": 109.99626121011262 74 | } 75 | } 76 | ] 77 | } 78 | } 79 | ] 80 | -------------------------------------------------------------------------------- /_vendor/src/github.com/prometheus/client_golang/extraction/textprocessor.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 extraction 15 | 16 | import ( 17 | "io" 18 | 19 | "github.com/prometheus/client_golang/text" 20 | ) 21 | 22 | type processor004 struct{} 23 | 24 | // Processor004 s responsible for decoding payloads from the text based variety 25 | // of protocol version 0.0.4. 26 | var Processor004 = &processor004{} 27 | 28 | func (t *processor004) ProcessSingle(i io.Reader, out Ingester, o *ProcessOptions) error { 29 | var parser text.Parser 30 | metricFamilies, err := parser.TextToMetricFamilies(i) 31 | if err != nil { 32 | return err 33 | } 34 | for _, metricFamily := range metricFamilies { 35 | if err := extractMetricFamily(out, o, metricFamily); err != nil { 36 | return err 37 | } 38 | } 39 | return nil 40 | } 41 | -------------------------------------------------------------------------------- /_vendor/src/github.com/prometheus/client_golang/model/labelname.go: -------------------------------------------------------------------------------- 1 | // Copyright 2013 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 model 15 | 16 | import ( 17 | "strings" 18 | ) 19 | 20 | const ( 21 | // ExporterLabelPrefix is the label name prefix to prepend if a 22 | // synthetic label is already present in the exported metrics. 23 | ExporterLabelPrefix LabelName = "exporter_" 24 | 25 | // MetricNameLabel is the label name indicating the metric name of a 26 | // timeseries. 27 | MetricNameLabel LabelName = "__name__" 28 | 29 | // ReservedLabelPrefix is a prefix which is not legal in user-supplied 30 | // label names. 31 | ReservedLabelPrefix = "__" 32 | 33 | // JobLabel is the label name indicating the job from which a timeseries 34 | // was scraped. 35 | JobLabel LabelName = "job" 36 | ) 37 | 38 | // A LabelName is a key for a LabelSet or Metric. It has a value associated 39 | // therewith. 40 | type LabelName string 41 | 42 | // LabelNames is a sortable LabelName slice. In implements sort.Interface. 43 | type LabelNames []LabelName 44 | 45 | func (l LabelNames) Len() int { 46 | return len(l) 47 | } 48 | 49 | func (l LabelNames) Less(i, j int) bool { 50 | return l[i] < l[j] 51 | } 52 | 53 | func (l LabelNames) Swap(i, j int) { 54 | l[i], l[j] = l[j], l[i] 55 | } 56 | 57 | func (l LabelNames) String() string { 58 | labelStrings := make([]string, 0, len(l)) 59 | for _, label := range l { 60 | labelStrings = append(labelStrings, string(label)) 61 | } 62 | return strings.Join(labelStrings, ", ") 63 | } 64 | -------------------------------------------------------------------------------- /_vendor/src/github.com/prometheus/client_golang/model/labelname_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2013 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 model 15 | 16 | import ( 17 | "sort" 18 | "testing" 19 | ) 20 | 21 | func testLabelNames(t testing.TB) { 22 | var scenarios = []struct { 23 | in LabelNames 24 | out LabelNames 25 | }{ 26 | { 27 | in: LabelNames{"ZZZ", "zzz"}, 28 | out: LabelNames{"ZZZ", "zzz"}, 29 | }, 30 | { 31 | in: LabelNames{"aaa", "AAA"}, 32 | out: LabelNames{"AAA", "aaa"}, 33 | }, 34 | } 35 | 36 | for i, scenario := range scenarios { 37 | sort.Sort(scenario.in) 38 | 39 | for j, expected := range scenario.out { 40 | if expected != scenario.in[j] { 41 | t.Errorf("%d.%d expected %s, got %s", i, j, expected, scenario.in[j]) 42 | } 43 | } 44 | } 45 | } 46 | 47 | func TestLabelNames(t *testing.T) { 48 | testLabelNames(t) 49 | } 50 | 51 | func BenchmarkLabelNames(b *testing.B) { 52 | for i := 0; i < b.N; i++ { 53 | testLabelNames(b) 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /_vendor/src/github.com/prometheus/client_golang/model/labelset.go: -------------------------------------------------------------------------------- 1 | // Copyright 2013 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 model 15 | 16 | import ( 17 | "fmt" 18 | "sort" 19 | "strings" 20 | ) 21 | 22 | // A LabelSet is a collection of LabelName and LabelValue pairs. The LabelSet 23 | // may be fully-qualified down to the point where it may resolve to a single 24 | // Metric in the data store or not. All operations that occur within the realm 25 | // of a LabelSet can emit a vector of Metric entities to which the LabelSet may 26 | // match. 27 | type LabelSet map[LabelName]LabelValue 28 | 29 | // Merge is a helper function to non-destructively merge two label sets. 30 | func (l LabelSet) Merge(other LabelSet) LabelSet { 31 | result := make(LabelSet, len(l)) 32 | 33 | for k, v := range l { 34 | result[k] = v 35 | } 36 | 37 | for k, v := range other { 38 | result[k] = v 39 | } 40 | 41 | return result 42 | } 43 | 44 | func (l LabelSet) String() string { 45 | labelStrings := make([]string, 0, len(l)) 46 | for label, value := range l { 47 | labelStrings = append(labelStrings, fmt.Sprintf("%s=%q", label, value)) 48 | } 49 | 50 | switch len(labelStrings) { 51 | case 0: 52 | return "" 53 | default: 54 | sort.Strings(labelStrings) 55 | return fmt.Sprintf("{%s}", strings.Join(labelStrings, ", ")) 56 | } 57 | } 58 | 59 | // MergeFromMetric merges Metric into this LabelSet. 60 | func (l LabelSet) MergeFromMetric(m Metric) { 61 | for k, v := range m { 62 | l[k] = v 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /_vendor/src/github.com/prometheus/client_golang/model/labelvalue.go: -------------------------------------------------------------------------------- 1 | // Copyright 2013 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 model 15 | 16 | import ( 17 | "sort" 18 | ) 19 | 20 | // A LabelValue is an associated value for a LabelName. 21 | type LabelValue string 22 | 23 | // LabelValues is a sortable LabelValue slice. It implements sort.Interface. 24 | type LabelValues []LabelValue 25 | 26 | func (l LabelValues) Len() int { 27 | return len(l) 28 | } 29 | 30 | func (l LabelValues) Less(i, j int) bool { 31 | return sort.StringsAreSorted([]string{string(l[i]), string(l[j])}) 32 | } 33 | 34 | func (l LabelValues) Swap(i, j int) { 35 | l[i], l[j] = l[j], l[i] 36 | } 37 | -------------------------------------------------------------------------------- /_vendor/src/github.com/prometheus/client_golang/model/labelvalue_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2013 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 model 15 | 16 | import ( 17 | "sort" 18 | "testing" 19 | ) 20 | 21 | func testLabelValues(t testing.TB) { 22 | var scenarios = []struct { 23 | in LabelValues 24 | out LabelValues 25 | }{ 26 | { 27 | in: LabelValues{"ZZZ", "zzz"}, 28 | out: LabelValues{"ZZZ", "zzz"}, 29 | }, 30 | { 31 | in: LabelValues{"aaa", "AAA"}, 32 | out: LabelValues{"AAA", "aaa"}, 33 | }, 34 | } 35 | 36 | for i, scenario := range scenarios { 37 | sort.Sort(scenario.in) 38 | 39 | for j, expected := range scenario.out { 40 | if expected != scenario.in[j] { 41 | t.Errorf("%d.%d expected %s, got %s", i, j, expected, scenario.in[j]) 42 | } 43 | } 44 | } 45 | } 46 | 47 | func TestLabelValues(t *testing.T) { 48 | testLabelValues(t) 49 | } 50 | 51 | func BenchmarkLabelValues(b *testing.B) { 52 | for i := 0; i < b.N; i++ { 53 | testLabelValues(b) 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /_vendor/src/github.com/prometheus/client_golang/model/metric.go: -------------------------------------------------------------------------------- 1 | // Copyright 2013 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 model 15 | 16 | import ( 17 | "fmt" 18 | "sort" 19 | "strings" 20 | ) 21 | 22 | // A Metric is similar to a LabelSet, but the key difference is that a Metric is 23 | // a singleton and refers to one and only one stream of samples. 24 | type Metric map[LabelName]LabelValue 25 | 26 | // Equal compares the fingerprints of both metrics. 27 | func (m Metric) Equal(o Metric) bool { 28 | lFingerprint := &Fingerprint{} 29 | rFingerprint := &Fingerprint{} 30 | 31 | lFingerprint.LoadFromMetric(m) 32 | rFingerprint.LoadFromMetric(o) 33 | 34 | return lFingerprint.Equal(rFingerprint) 35 | } 36 | 37 | // Before compares the fingerprints of both metrics. 38 | func (m Metric) Before(o Metric) bool { 39 | lFingerprint := &Fingerprint{} 40 | rFingerprint := &Fingerprint{} 41 | 42 | lFingerprint.LoadFromMetric(m) 43 | rFingerprint.LoadFromMetric(o) 44 | 45 | return lFingerprint.Less(rFingerprint) 46 | } 47 | 48 | func (m Metric) String() string { 49 | metricName, ok := m[MetricNameLabel] 50 | if !ok { 51 | panic("Tried to print metric without name") 52 | } 53 | labelStrings := make([]string, 0, len(m)-1) 54 | for label, value := range m { 55 | if label != MetricNameLabel { 56 | labelStrings = append(labelStrings, fmt.Sprintf("%s=%q", label, value)) 57 | } 58 | } 59 | 60 | switch len(labelStrings) { 61 | case 0: 62 | return string(metricName) 63 | default: 64 | sort.Strings(labelStrings) 65 | return fmt.Sprintf("%s{%s}", metricName, strings.Join(labelStrings, ", ")) 66 | } 67 | } 68 | 69 | // MergeFromLabelSet merges a label set into this Metric, prefixing a collision 70 | // prefix to the label names merged from the label set where required. 71 | func (m Metric) MergeFromLabelSet(labels LabelSet, collisionPrefix LabelName) { 72 | for k, v := range labels { 73 | if collisionPrefix != "" { 74 | for { 75 | if _, exists := m[k]; !exists { 76 | break 77 | } 78 | k = collisionPrefix + k 79 | } 80 | } 81 | 82 | m[k] = v 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /_vendor/src/github.com/prometheus/client_golang/model/metric_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2013 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 model 15 | 16 | import "testing" 17 | 18 | func testMetric(t testing.TB) { 19 | var scenarios = []struct { 20 | input map[string]string 21 | hash uint64 22 | rowkey string 23 | }{ 24 | { 25 | input: map[string]string{}, 26 | rowkey: "02676020557754725067--0-", 27 | hash: 2676020557754725067, 28 | }, 29 | { 30 | input: map[string]string{ 31 | "first_name": "electro", 32 | "occupation": "robot", 33 | "manufacturer": "westinghouse", 34 | }, 35 | rowkey: "04776841610193542734-f-6-t", 36 | hash: 4776841610193542734, 37 | }, 38 | { 39 | input: map[string]string{ 40 | "x": "y", 41 | }, 42 | rowkey: "01306929544689993150-x-2-y", 43 | hash: 1306929544689993150, 44 | }, 45 | } 46 | 47 | for i, scenario := range scenarios { 48 | metric := Metric{} 49 | for key, value := range scenario.input { 50 | metric[LabelName(key)] = LabelValue(value) 51 | } 52 | 53 | expectedRowKey := scenario.rowkey 54 | expectedHash := scenario.hash 55 | fingerprint := &Fingerprint{} 56 | fingerprint.LoadFromMetric(metric) 57 | actualRowKey := fingerprint.String() 58 | actualHash := fingerprint.Hash 59 | 60 | if expectedRowKey != actualRowKey { 61 | t.Errorf("%d. expected %s, got %s", i, expectedRowKey, actualRowKey) 62 | } 63 | if actualHash != expectedHash { 64 | t.Errorf("%d. expected %d, got %d", i, expectedHash, actualHash) 65 | } 66 | } 67 | } 68 | 69 | func TestMetric(t *testing.T) { 70 | testMetric(t) 71 | } 72 | 73 | func BenchmarkMetric(b *testing.B) { 74 | for i := 0; i < b.N; i++ { 75 | testMetric(b) 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /_vendor/src/github.com/prometheus/client_golang/model/model.go: -------------------------------------------------------------------------------- 1 | // Copyright 2013 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 model contains core representation of Prometheus client primitives. 15 | package model 16 | -------------------------------------------------------------------------------- /_vendor/src/github.com/prometheus/client_golang/model/sample.go: -------------------------------------------------------------------------------- 1 | // Copyright 2013 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 model 15 | 16 | // Sample is a sample value with a timestamp and a metric. 17 | type Sample struct { 18 | Metric Metric 19 | Value SampleValue 20 | Timestamp Timestamp 21 | } 22 | 23 | // Equal compares first the metrics, then the timestamp, then the value. 24 | func (s *Sample) Equal(o *Sample) bool { 25 | if s == o { 26 | return true 27 | } 28 | 29 | if !s.Metric.Equal(o.Metric) { 30 | return false 31 | } 32 | if !s.Timestamp.Equal(o.Timestamp) { 33 | return false 34 | } 35 | if !s.Value.Equal(o.Value) { 36 | return false 37 | } 38 | 39 | return true 40 | } 41 | 42 | // Samples is a sortable Sample slice. It implements sort.Interface. 43 | type Samples []*Sample 44 | 45 | func (s Samples) Len() int { 46 | return len(s) 47 | } 48 | 49 | // Less compares first the metrics, then the timestamp. 50 | func (s Samples) Less(i, j int) bool { 51 | switch { 52 | case s[i].Metric.Before(s[j].Metric): 53 | return true 54 | case s[j].Metric.Before(s[i].Metric): 55 | return false 56 | case s[i].Timestamp.Before(s[j].Timestamp): 57 | return true 58 | default: 59 | return false 60 | } 61 | } 62 | 63 | func (s Samples) Swap(i, j int) { 64 | s[i], s[j] = s[j], s[i] 65 | } 66 | -------------------------------------------------------------------------------- /_vendor/src/github.com/prometheus/client_golang/model/samplevalue.go: -------------------------------------------------------------------------------- 1 | // Copyright 2013 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 model 15 | 16 | import ( 17 | "fmt" 18 | ) 19 | 20 | // A SampleValue is a representation of a value for a given sample at a given 21 | // time. 22 | type SampleValue float64 23 | 24 | // Equal does a straight v==o. 25 | func (v SampleValue) Equal(o SampleValue) bool { 26 | return v == o 27 | } 28 | 29 | // MarshalJSON implements json.Marshaler. 30 | func (v SampleValue) MarshalJSON() ([]byte, error) { 31 | return []byte(fmt.Sprintf(`"%f"`, v)), nil 32 | } 33 | 34 | func (v SampleValue) String() string { 35 | return fmt.Sprint(float64(v)) 36 | } 37 | -------------------------------------------------------------------------------- /_vendor/src/github.com/prometheus/client_golang/model/signature.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 model 15 | 16 | import ( 17 | "bytes" 18 | "hash" 19 | "hash/fnv" 20 | ) 21 | 22 | // SeparatorByte is a byte that cannot occur in valid UTF-8 sequences and is 23 | // used to separate label names, label values, and other strings from each other 24 | // when calculating their combined hash value (aka signature aka fingerprint). 25 | const SeparatorByte byte = 255 26 | 27 | var ( 28 | // cache the signature of an empty label set. 29 | emptyLabelSignature = fnv.New64a().Sum64() 30 | 31 | hashAndBufPool = make(chan *hashAndBuf, 1024) 32 | ) 33 | 34 | type hashAndBuf struct { 35 | h hash.Hash64 36 | b bytes.Buffer 37 | } 38 | 39 | func getHashAndBuf() *hashAndBuf { 40 | select { 41 | case hb := <-hashAndBufPool: 42 | return hb 43 | default: 44 | return &hashAndBuf{h: fnv.New64a()} 45 | } 46 | } 47 | 48 | func putHashAndBuf(hb *hashAndBuf) { 49 | select { 50 | case hashAndBufPool <- hb: 51 | default: 52 | } 53 | } 54 | 55 | // LabelsToSignature returns a unique signature (i.e., fingerprint) for a given 56 | // label set. 57 | func LabelsToSignature(labels map[string]string) uint64 { 58 | if len(labels) == 0 { 59 | return emptyLabelSignature 60 | } 61 | 62 | var result uint64 63 | hb := getHashAndBuf() 64 | defer putHashAndBuf(hb) 65 | 66 | for k, v := range labels { 67 | hb.b.WriteString(k) 68 | hb.b.WriteByte(SeparatorByte) 69 | hb.b.WriteString(v) 70 | hb.h.Write(hb.b.Bytes()) 71 | result ^= hb.h.Sum64() 72 | hb.h.Reset() 73 | hb.b.Reset() 74 | } 75 | return result 76 | } 77 | 78 | // LabelValuesToSignature returns a unique signature (i.e., fingerprint) for the 79 | // values of a given label set. 80 | func LabelValuesToSignature(labels map[string]string) uint64 { 81 | if len(labels) == 0 { 82 | return emptyLabelSignature 83 | } 84 | 85 | var result uint64 86 | hb := getHashAndBuf() 87 | defer putHashAndBuf(hb) 88 | 89 | for _, v := range labels { 90 | hb.b.WriteString(v) 91 | hb.h.Write(hb.b.Bytes()) 92 | result ^= hb.h.Sum64() 93 | hb.h.Reset() 94 | hb.b.Reset() 95 | } 96 | return result 97 | } 98 | -------------------------------------------------------------------------------- /_vendor/src/github.com/prometheus/client_golang/model/timestamp_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2013 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 model 15 | 16 | import ( 17 | "testing" 18 | native_time "time" 19 | ) 20 | 21 | func TestComparators(t *testing.T) { 22 | t1a := TimestampFromUnix(0) 23 | t1b := TimestampFromUnix(0) 24 | t2 := TimestampFromUnix(2*second - 1) 25 | 26 | if !t1a.Equal(t1b) { 27 | t.Fatalf("Expected %s to be equal to %s", t1a, t1b) 28 | } 29 | if t1a.Equal(t2) { 30 | t.Fatalf("Expected %s to not be equal to %s", t1a, t2) 31 | } 32 | 33 | if !t1a.Before(t2) { 34 | t.Fatalf("Expected %s to be before %s", t1a, t2) 35 | } 36 | if t1a.Before(t1b) { 37 | t.Fatalf("Expected %s to not be before %s", t1a, t1b) 38 | } 39 | 40 | if !t2.After(t1a) { 41 | t.Fatalf("Expected %s to be after %s", t2, t1a) 42 | } 43 | if t1b.After(t1a) { 44 | t.Fatalf("Expected %s to not be after %s", t1b, t1a) 45 | } 46 | } 47 | 48 | func TestTimestampConversions(t *testing.T) { 49 | unix := int64(1136239445) 50 | t1 := native_time.Unix(unix, 0) 51 | t2 := native_time.Unix(unix, second-1) 52 | 53 | ts := TimestampFromUnix(unix) 54 | if !ts.Time().Equal(t1) { 55 | t.Fatalf("Expected %s, got %s", t1, ts.Time()) 56 | } 57 | 58 | // Test available precision. 59 | ts = TimestampFromTime(t2) 60 | if !ts.Time().Equal(t1) { 61 | t.Fatalf("Expected %s, got %s", t1, ts.Time()) 62 | } 63 | 64 | if ts.Unix() != unix { 65 | t.Fatalf("Expected %d, got %d", unix, ts.Unix()) 66 | } 67 | } 68 | 69 | func TestDuration(t *testing.T) { 70 | duration := native_time.Second + native_time.Minute + native_time.Hour 71 | goTime := native_time.Unix(1136239445, 0) 72 | 73 | ts := TimestampFromTime(goTime) 74 | if !goTime.Add(duration).Equal(ts.Add(duration).Time()) { 75 | t.Fatalf("Expected %s to be equal to %s", goTime.Add(duration), ts.Add(duration)) 76 | } 77 | 78 | earlier := ts.Add(-duration) 79 | delta := ts.Sub(earlier) 80 | if delta != duration { 81 | t.Fatalf("Expected %s to be equal to %s", delta, duration) 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /_vendor/src/github.com/prometheus/client_golang/prometheus/.gitignore: -------------------------------------------------------------------------------- 1 | command-line-arguments.test 2 | -------------------------------------------------------------------------------- /_vendor/src/github.com/prometheus/client_golang/prometheus/README.md: -------------------------------------------------------------------------------- 1 | # Overview 2 | This is the [Prometheus](http://www.prometheus.io) telemetric 3 | instrumentation client [Go](http://golang.org) client library. It 4 | enable authors to define process-space metrics for their servers and 5 | expose them through a web service interface for extraction, 6 | aggregation, and a whole slew of other post processing techniques. 7 | 8 | # Installing 9 | $ go get github.com/prometheus/client_golang/prometheus 10 | 11 | # Example 12 | ```go 13 | package main 14 | 15 | import ( 16 | "net/http" 17 | 18 | "github.com/prometheus/client_golang/prometheus" 19 | ) 20 | 21 | var ( 22 | indexed = prometheus.NewCounter(prometheus.CounterOpts{ 23 | Namespace: "my_company", 24 | Subsystem: "indexer", 25 | Name: "documents_indexed", 26 | Help: "The number of documents indexed.", 27 | }) 28 | size = prometheus.NewGauge(prometheus.GaugeOpts{ 29 | Namespace: "my_company", 30 | Subsystem: "storage", 31 | Name: "documents_total_size_bytes", 32 | Help: "The total size of all documents in the storage."}}) 33 | ) 34 | 35 | func main() { 36 | http.Handle("/metrics", prometheus.Handler()) 37 | 38 | indexed.Inc() 39 | size.Set(5) 40 | 41 | http.ListenAndServe(":8080", nil) 42 | } 43 | 44 | func init() { 45 | prometheus.MustRegister(indexed) 46 | prometheus.MustRegister(size) 47 | } 48 | ``` 49 | 50 | # Documentation 51 | 52 | [![GoDoc](https://godoc.org/github.com/prometheus/client_golang?status.png)](https://godoc.org/github.com/prometheus/client_golang) 53 | 54 | -------------------------------------------------------------------------------- /_vendor/src/github.com/prometheus/client_golang/prometheus/counter_test.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 prometheus 15 | 16 | import "testing" 17 | 18 | func TestCounterAdd(t *testing.T) { 19 | counter := NewCounter(CounterOpts{ 20 | Name: "test", 21 | Help: "test help", 22 | }).(*counter) 23 | counter.Inc() 24 | if expected, got := 1., counter.val; expected != got { 25 | t.Errorf("Expected %f, got %f.", expected, got) 26 | } 27 | counter.Add(42) 28 | if expected, got := 43., counter.val; expected != got { 29 | t.Errorf("Expected %f, got %f.", expected, got) 30 | } 31 | 32 | if expected, got := "counter cannot decrease in value", decreaseCounter(counter).Error(); expected != got { 33 | t.Errorf("Expected error %q, got %q.", expected, got) 34 | } 35 | } 36 | 37 | func decreaseCounter(c *counter) (err error) { 38 | defer func() { 39 | if e := recover(); e != nil { 40 | err = e.(error) 41 | } 42 | }() 43 | c.Add(-1) 44 | return nil 45 | } 46 | -------------------------------------------------------------------------------- /_vendor/src/github.com/prometheus/client_golang/prometheus/example_selfcollector_test.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 prometheus_test 15 | 16 | import ( 17 | "runtime" 18 | 19 | "code.google.com/p/goprotobuf/proto" 20 | 21 | dto "github.com/prometheus/client_model/go" 22 | 23 | "github.com/prometheus/client_golang/prometheus" 24 | ) 25 | 26 | func NewCallbackMetric(desc *prometheus.Desc, callback func() float64) *CallbackMetric { 27 | result := &CallbackMetric{desc: desc, callback: callback} 28 | result.Init(result) // Initialize the SelfCollector. 29 | return result 30 | } 31 | 32 | // TODO: Come up with a better example. 33 | 34 | // CallbackMetric is an example for a user-defined Metric that exports the 35 | // result of a function call as a metric of type "untyped" without any 36 | // labels. It uses SelfCollector to turn the Metric into a Collector so that it 37 | // can be registered with Prometheus. 38 | // 39 | // Note that this example is pretty much academic as the prometheus package 40 | // already provides an UntypedFunc type. 41 | type CallbackMetric struct { 42 | prometheus.SelfCollector 43 | 44 | desc *prometheus.Desc 45 | callback func() float64 46 | } 47 | 48 | func (cm *CallbackMetric) Desc() *prometheus.Desc { 49 | return cm.desc 50 | } 51 | 52 | func (cm *CallbackMetric) Write(m *dto.Metric) { 53 | m.Untyped = &dto.Untyped{Value: proto.Float64(cm.callback())} 54 | } 55 | 56 | func ExampleSelfCollector() { 57 | m := NewCallbackMetric( 58 | prometheus.NewDesc( 59 | "runtime_goroutines_count", 60 | "Total number of goroutines that currently exist.", 61 | nil, nil, // No labels, these must be nil. 62 | ), 63 | func() float64 { 64 | return float64(runtime.NumGoroutine()) 65 | }, 66 | ) 67 | prometheus.MustRegister(m) 68 | } 69 | -------------------------------------------------------------------------------- /_vendor/src/github.com/prometheus/client_golang/prometheus/metric_test.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 prometheus 15 | 16 | import "testing" 17 | 18 | func TestBuildFQName(t *testing.T) { 19 | scenarios := []struct{ namespace, subsystem, name, result string }{ 20 | {"a", "b", "c", "a_b_c"}, 21 | {"", "b", "c", "b_c"}, 22 | {"a", "", "c", "a_c"}, 23 | {"", "", "c", "c"}, 24 | {"a", "b", "", ""}, 25 | {"a", "", "", ""}, 26 | {"", "b", "", ""}, 27 | {" ", "", "", ""}, 28 | } 29 | 30 | for i, s := range scenarios { 31 | if want, got := s.result, BuildFQName(s.namespace, s.subsystem, s.name); want != got { 32 | t.Errorf("%d. want %s, got %s", i, want, got) 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /_vendor/src/github.com/prometheus/client_golang/text/proto.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 text 15 | 16 | import ( 17 | "fmt" 18 | "io" 19 | 20 | "code.google.com/p/goprotobuf/proto" 21 | "github.com/matttproud/golang_protobuf_extensions/ext" 22 | 23 | dto "github.com/prometheus/client_model/go" 24 | ) 25 | 26 | // WriteProtoDelimited writes the MetricFamily to the writer in delimited 27 | // protobuf format and returns the number of bytes written and any error 28 | // encountered. 29 | func WriteProtoDelimited(w io.Writer, p *dto.MetricFamily) (int, error) { 30 | return ext.WriteDelimited(w, p) 31 | } 32 | 33 | // WriteProtoText writes the MetricFamily to the writer in text format and 34 | // returns the number of bytes written and any error encountered. 35 | func WriteProtoText(w io.Writer, p *dto.MetricFamily) (int, error) { 36 | return fmt.Fprintf(w, "%s\n", proto.MarshalTextString(p)) 37 | } 38 | 39 | // WriteProtoCompactText writes the MetricFamily to the writer in compact text 40 | // format and returns the number of bytes written and any error encountered. 41 | func WriteProtoCompactText(w io.Writer, p *dto.MetricFamily) (int, error) { 42 | return fmt.Fprintf(w, "%s\n", p) 43 | } 44 | -------------------------------------------------------------------------------- /_vendor/src/github.com/prometheus/client_model/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | -------------------------------------------------------------------------------- /_vendor/src/github.com/prometheus/client_model/Makefile: -------------------------------------------------------------------------------- 1 | # Copyright 2013 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 | KEY_ID ?= _DEFINE_ME_ 15 | 16 | all: cpp go java python ruby 17 | 18 | SUFFIXES: 19 | 20 | cpp: cpp/metrics.pb.cc cpp/metrics.pb.h 21 | 22 | cpp/metrics.pb.cc: metrics.proto 23 | protoc $< --cpp_out=cpp/ 24 | 25 | cpp/metrics.pb.h: metrics.proto 26 | protoc $< --cpp_out=cpp/ 27 | 28 | go: go/metrics.pb.go 29 | 30 | go/metrics.pb.go: metrics.proto 31 | protoc $< --go_out=go/ 32 | 33 | java: src/main/java/io/prometheus/client/Metrics.java pom.xml 34 | mvn clean compile package 35 | 36 | src/main/java/io/prometheus/client/Metrics.java: metrics.proto 37 | protoc $< --java_out=src/main/java 38 | 39 | python: python/prometheus/client/model/metrics_pb2.py 40 | 41 | python/prometheus/client/model/metrics_pb2.py: metrics.proto 42 | protoc $< --python_out=python/prometheus/client/model 43 | 44 | ruby: 45 | $(MAKE) -C ruby build 46 | 47 | clean: 48 | -rm -rf cpp/* 49 | -rm -rf go/* 50 | -rm -rf java/* 51 | -rm -rf python/* 52 | -$(MAKE) -C ruby clean 53 | -mvn clean 54 | 55 | maven-deploy-snapshot: java 56 | mvn clean deploy -Dgpg.keyname=$(KEY_ID) -DperformRelease=true 57 | 58 | maven-deploy-release: java 59 | mvn clean release:clean release:prepare release:perform -Dgpg.keyname=$(KEY_ID) -DperformRelease=true 60 | 61 | .PHONY: all clean cpp go java maven-deploy-snapshot maven-deploy-release python ruby 62 | -------------------------------------------------------------------------------- /_vendor/src/github.com/prometheus/client_model/README.md: -------------------------------------------------------------------------------- 1 | # Background 2 | Under most circumstances, manually downloading this repository should never 3 | be required. 4 | 5 | # Prerequisites 6 | # Base 7 | * [Google Protocol Buffers](https://developers.google.com/protocol-buffers) 8 | 9 | ## Java 10 | * [Apache Maven](http://maven.apache.org) 11 | * [Prometheus Maven Repository](https://github.com/prometheus/io.prometheus-maven-repository) checked out into ../io.prometheus-maven-repository 12 | 13 | ## Go 14 | * [Go](http://golang.org) 15 | * [goprotobuf](https://code.google.com/p/goprotobuf) 16 | 17 | ## Ruby 18 | * [Ruby](https://www.ruby-lang.org) 19 | * [bundler](https://rubygems.org/gems/bundler) 20 | 21 | # Building 22 | $ make 23 | 24 | # Getting Started 25 | * The Go source code is periodically indexed: [Go Protocol Buffer Model](http://godoc.org/github.com/prometheus/client_model/go). 26 | * All of the core developers are accessible via the [Prometheus Developers Mailinglist](https://groups.google.com/forum/?fromgroups#!forum/prometheus-developers). 27 | -------------------------------------------------------------------------------- /_vendor/src/github.com/prometheus/client_model/contributing.md: -------------------------------------------------------------------------------- 1 | Please review the Gerrit setup for this project 2 | at http://review.prometheus.io/. 3 | -------------------------------------------------------------------------------- /_vendor/src/github.com/prometheus/client_model/metrics.proto: -------------------------------------------------------------------------------- 1 | // Copyright 2013 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 | syntax = "proto2"; 15 | 16 | package io.prometheus.client; 17 | option java_package = "io.prometheus.client"; 18 | 19 | message LabelPair { 20 | optional string name = 1; 21 | optional string value = 2; 22 | } 23 | 24 | enum MetricType { 25 | COUNTER = 0; 26 | GAUGE = 1; 27 | SUMMARY = 2; 28 | UNTYPED = 3; 29 | } 30 | 31 | message Gauge { 32 | optional double value = 1; 33 | } 34 | 35 | message Counter { 36 | optional double value = 1; 37 | } 38 | 39 | message Quantile { 40 | optional double quantile = 1; 41 | optional double value = 2; 42 | } 43 | 44 | message Summary { 45 | optional uint64 sample_count = 1; 46 | optional double sample_sum = 2; 47 | repeated Quantile quantile = 3; 48 | } 49 | 50 | message Untyped { 51 | optional double value = 1; 52 | } 53 | 54 | message Metric { 55 | repeated LabelPair label = 1; 56 | optional Gauge gauge = 2; 57 | optional Counter counter = 3; 58 | optional Summary summary = 4; 59 | optional Untyped untyped = 5; 60 | optional int64 timestamp_ms = 6; 61 | } 62 | 63 | message MetricFamily { 64 | optional string name = 1; 65 | optional string help = 2; 66 | optional MetricType type = 3; 67 | repeated Metric metric = 4; 68 | } 69 | -------------------------------------------------------------------------------- /_vendor/src/github.com/prometheus/client_model/python/prometheus/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2013 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 | -------------------------------------------------------------------------------- /_vendor/src/github.com/prometheus/client_model/python/prometheus/client/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2013 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 | -------------------------------------------------------------------------------- /_vendor/src/github.com/prometheus/client_model/python/prometheus/client/model/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2013 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 | __all__ = ['metrics_pb2'] 15 | -------------------------------------------------------------------------------- /_vendor/src/github.com/prometheus/client_model/ruby/.gitignore: -------------------------------------------------------------------------------- 1 | *.gem 2 | .bundle 3 | Gemfile.lock 4 | pkg 5 | vendor/bundle 6 | -------------------------------------------------------------------------------- /_vendor/src/github.com/prometheus/client_model/ruby/Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | # Specify your gem's dependencies in prometheus-client-model.gemspec 4 | gemspec 5 | -------------------------------------------------------------------------------- /_vendor/src/github.com/prometheus/client_model/ruby/Makefile: -------------------------------------------------------------------------------- 1 | VENDOR_BUNDLE = vendor/bundle 2 | 3 | build: $(VENDOR_BUNDLE)/.bundled 4 | BEEFCAKE_NAMESPACE=Prometheus::Client protoc --beefcake_out lib/prometheus/client/model -I .. ../metrics.proto 5 | 6 | $(VENDOR_BUNDLE): 7 | mkdir -p $@ 8 | 9 | $(VENDOR_BUNDLE)/.bundled: $(VENDOR_BUNDLE) Gemfile 10 | bundle install --quiet --path $< 11 | @touch $@ 12 | 13 | clean: 14 | -rm -f lib/prometheus/client/model/metrics.pb.rb 15 | -rm -rf $(VENDOR_BUNDLE) 16 | 17 | .PHONY: build clean 18 | -------------------------------------------------------------------------------- /_vendor/src/github.com/prometheus/client_model/ruby/README.md: -------------------------------------------------------------------------------- 1 | # Prometheus Ruby client model 2 | 3 | Data model artifacts for the [Prometheus Ruby client][1]. 4 | 5 | ## Installation 6 | 7 | gem install prometheus-client-model 8 | 9 | ## Usage 10 | 11 | Build the artifacts from the protobuf specification: 12 | 13 | make build 14 | 15 | While this Gem's main purpose is to define the Prometheus data types for the 16 | [client][1], it's possible to use it without the client to decode a stream of 17 | delimited protobuf messages: 18 | 19 | ```ruby 20 | require 'open-uri' 21 | require 'prometheus/client/model' 22 | 23 | CONTENT_TYPE = 'application/vnd.google.protobuf; proto=io.prometheus.client.MetricFamily; encoding=delimited' 24 | 25 | stream = open('http://localhost:9090/metrics', 'Accept' => CONTENT_TYPE).read 26 | while family = Prometheus::Client::MetricFamily.read_delimited(stream) 27 | puts family 28 | end 29 | ``` 30 | 31 | [1]: https://github.com/prometheus/client_ruby 32 | -------------------------------------------------------------------------------- /_vendor/src/github.com/prometheus/client_model/ruby/Rakefile: -------------------------------------------------------------------------------- 1 | require "bundler/gem_tasks" 2 | -------------------------------------------------------------------------------- /_vendor/src/github.com/prometheus/client_model/ruby/lib/prometheus/client/model.rb: -------------------------------------------------------------------------------- 1 | require 'prometheus/client/model/metrics.pb' 2 | require 'prometheus/client/model/version' 3 | -------------------------------------------------------------------------------- /_vendor/src/github.com/prometheus/client_model/ruby/lib/prometheus/client/model/metrics.pb.rb: -------------------------------------------------------------------------------- 1 | ## Generated from metrics.proto for io.prometheus.client 2 | require "beefcake" 3 | 4 | module Prometheus 5 | module Client 6 | 7 | module MetricType 8 | COUNTER = 0 9 | GAUGE = 1 10 | SUMMARY = 2 11 | UNTYPED = 3 12 | end 13 | 14 | class LabelPair 15 | include Beefcake::Message 16 | end 17 | 18 | class Gauge 19 | include Beefcake::Message 20 | end 21 | 22 | class Counter 23 | include Beefcake::Message 24 | end 25 | 26 | class Quantile 27 | include Beefcake::Message 28 | end 29 | 30 | class Summary 31 | include Beefcake::Message 32 | end 33 | 34 | class Untyped 35 | include Beefcake::Message 36 | end 37 | 38 | class Metric 39 | include Beefcake::Message 40 | end 41 | 42 | class MetricFamily 43 | include Beefcake::Message 44 | end 45 | 46 | class LabelPair 47 | optional :name, :string, 1 48 | optional :value, :string, 2 49 | end 50 | 51 | class Gauge 52 | optional :value, :double, 1 53 | end 54 | 55 | class Counter 56 | optional :value, :double, 1 57 | end 58 | 59 | class Quantile 60 | optional :quantile, :double, 1 61 | optional :value, :double, 2 62 | end 63 | 64 | class Summary 65 | optional :sample_count, :uint64, 1 66 | optional :sample_sum, :double, 2 67 | repeated :quantile, Quantile, 3 68 | end 69 | 70 | class Untyped 71 | optional :value, :double, 1 72 | end 73 | 74 | class Metric 75 | repeated :label, LabelPair, 1 76 | optional :gauge, Gauge, 2 77 | optional :counter, Counter, 3 78 | optional :summary, Summary, 4 79 | optional :untyped, Untyped, 5 80 | optional :timestamp_ms, :int64, 6 81 | end 82 | 83 | class MetricFamily 84 | optional :name, :string, 1 85 | optional :help, :string, 2 86 | optional :type, MetricType, 3 87 | repeated :metric, Metric, 4 88 | end 89 | end 90 | end 91 | -------------------------------------------------------------------------------- /_vendor/src/github.com/prometheus/client_model/ruby/lib/prometheus/client/model/version.rb: -------------------------------------------------------------------------------- 1 | module Prometheus 2 | module Client 3 | module Model 4 | VERSION = '0.1.0' 5 | end 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /_vendor/src/github.com/prometheus/client_model/ruby/prometheus-client-model.gemspec: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | lib = File.expand_path('../lib', __FILE__) 3 | $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) 4 | require 'prometheus/client/model/version' 5 | 6 | Gem::Specification.new do |spec| 7 | spec.name = 'prometheus-client-model' 8 | spec.version = Prometheus::Client::Model::VERSION 9 | spec.authors = ['Tobias Schmidt'] 10 | spec.email = ['tobidt@gmail.com'] 11 | spec.summary = 'Data model artifacts for the Prometheus Ruby client' 12 | spec.homepage = 'https://github.com/prometheus/client_model/tree/master/ruby' 13 | spec.license = 'Apache 2.0' 14 | 15 | spec.files = %w[README.md LICENSE] + Dir.glob('{lib/**/*}') 16 | spec.require_paths = ['lib'] 17 | 18 | spec.add_dependency 'beefcake', '>= 0.4.0' 19 | 20 | spec.add_development_dependency 'bundler', '~> 1.3' 21 | spec.add_development_dependency 'rake' 22 | end 23 | -------------------------------------------------------------------------------- /_vendor/src/github.com/prometheus/client_model/setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | from setuptools import setup 4 | 5 | setup( 6 | name = 'prometheus_client_model', 7 | version = '0.0.1', 8 | author = 'Matt T. Proud', 9 | author_email = 'matt.proud@gmail.com', 10 | description = 'Data model artifacts for the Prometheus client.', 11 | license = 'Apache License 2.0', 12 | url = 'http://github.com/prometheus/client_model', 13 | packages = ['prometheus', 'prometheus/client', 'prometheus/client/model'], 14 | package_dir = {'': 'python'}, 15 | requires = ['protobuf(==2.4.1)'], 16 | platforms = 'Platform Independent', 17 | classifiers = ['Development Status :: 3 - Alpha', 18 | 'Intended Audience :: Developers', 19 | 'Intended Audience :: System Administrators', 20 | 'License :: OSI Approved :: Apache Software License', 21 | 'Operating System :: OS Independent', 22 | 'Topic :: Software Development :: Testing', 23 | 'Topic :: System :: Monitoring']) 24 | -------------------------------------------------------------------------------- /_vendor/src/github.com/streadway/handy/README.md: -------------------------------------------------------------------------------- 1 | # Handy Handlers 2 | 3 | Collection of useful HTTP handlers that form a handler stack of filters. Many 4 | are opinionated for a specific purpose. 5 | 6 | # API 7 | 8 | The signature for a handler wrapper ends with an http.Handler interface and returns a http.Handler interface. For example: 9 | 10 | ``` 11 | func Log(w io.Writer, http.Handler) http.Handler 12 | 13 | func CORS(methods, origins []string, http.Handler) http.Handler 14 | ``` 15 | 16 | # Contributing 17 | 18 | Fork the repo and add your fix or handler with tests. Make a pull request. 19 | 20 | # License 21 | 22 | Copyright (c) 2013, SoundCloud Ltd. 23 | All rights reserved. 24 | 25 | Redistribution and use in source and binary forms, with or without 26 | modification, are permitted provided that the following conditions are met: 27 | 28 | Redistributions of source code must retain the above copyright notice, this 29 | list of conditions and the following disclaimer. 30 | 31 | Redistributions in binary form must reproduce the above copyright notice, this 32 | list of conditions and the following disclaimer in the documentation and/or 33 | other materials provided with the distribution. 34 | 35 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 36 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 37 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 38 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 39 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 40 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 41 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 42 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 43 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 44 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 45 | -------------------------------------------------------------------------------- /_vendor/src/github.com/streadway/handy/breaker/doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | Package breaker implements a circuit breaker with configurable failure 3 | thresholds. It provides a Handler, to circuit break in HTTP servers, and a 4 | Transport, to circuit break in HTTP clients. 5 | */ 6 | package breaker 7 | -------------------------------------------------------------------------------- /_vendor/src/github.com/streadway/handy/breaker/handler.go: -------------------------------------------------------------------------------- 1 | package breaker 2 | 3 | import ( 4 | "net/http" 5 | "time" 6 | ) 7 | 8 | // StatusCodeValidator is a function that determines if a status code written 9 | // to a client by a circuit breaking Handler should count as a success or 10 | // failure. The DefaultStatusCodeValidator can be used in most situations. 11 | type StatusCodeValidator func(int) bool 12 | 13 | // Handler produces an http.Handler that's governed by the passed Breaker and 14 | // StatusCodeValidator. Responses written by the next http.Handler whose 15 | // status codes fail the validator signal failures to the breaker. Once the 16 | // breaker opens, incoming requests are terminated before being forwarded with 17 | // HTTP 503. 18 | func Handler(breaker Breaker, validator StatusCodeValidator, next http.Handler) http.Handler { 19 | return &handler{ 20 | breaker: breaker, 21 | validator: validator, 22 | next: next, 23 | } 24 | } 25 | 26 | type handler struct { 27 | breaker Breaker 28 | validator StatusCodeValidator 29 | next http.Handler 30 | } 31 | 32 | func (h *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { 33 | if h.breaker.Allow() { 34 | h.serveClosed(w, r) 35 | } else { 36 | h.serveOpened(w, r) 37 | } 38 | } 39 | 40 | func (h *handler) serveClosed(w http.ResponseWriter, r *http.Request) { 41 | cw := &codeWriter{w, 200} 42 | begin := time.Now() 43 | 44 | h.next.ServeHTTP(cw, r) 45 | 46 | duration := time.Since(begin) 47 | if h.validator(cw.code) { 48 | h.breaker.Success(duration) 49 | } else { 50 | h.breaker.Failure(duration) 51 | } 52 | } 53 | 54 | func (h *handler) serveOpened(w http.ResponseWriter, r *http.Request) { 55 | w.WriteHeader(http.StatusServiceUnavailable) 56 | } 57 | 58 | type codeWriter struct { 59 | http.ResponseWriter 60 | code int 61 | } 62 | 63 | func (w *codeWriter) WriteHeader(code int) { 64 | w.code = code 65 | w.ResponseWriter.WriteHeader(code) 66 | } 67 | 68 | // DefaultStatusCodeValidator considers any status code less than 500 to be a 69 | // success, from the perspective of a server. All other codes are failures. 70 | func DefaultStatusCodeValidator(code int) bool { 71 | return code < 500 72 | } 73 | -------------------------------------------------------------------------------- /_vendor/src/github.com/streadway/handy/breaker/handler_test.go: -------------------------------------------------------------------------------- 1 | package breaker 2 | 3 | import ( 4 | "net/http" 5 | "net/http/httptest" 6 | "testing" 7 | ) 8 | 9 | type code int 10 | 11 | func (h code) ServeHTTP(w http.ResponseWriter, r *http.Request) { 12 | w.WriteHeader(int(h)) 13 | } 14 | 15 | func TestHandlerCircuitStaysClosedWithSingleError(t *testing.T) { 16 | h := Handler(NewBreaker(0.05), DefaultStatusCodeValidator, code(500)) 17 | 18 | resp := httptest.NewRecorder() 19 | req := &http.Request{ 20 | Method: "GET", 21 | } 22 | 23 | h.ServeHTTP(resp, req) 24 | 25 | if !h.(*handler).breaker.Allow() { 26 | t.Fatal("expected circuit to be closed after one bad request") 27 | } 28 | } 29 | 30 | func TestHandlerCircuitOpenWith5PercentError(t *testing.T) { 31 | lastResponse := 200 32 | code := 200 33 | backend := http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { 34 | w.WriteHeader(code) 35 | }) 36 | 37 | h := Handler(NewBreaker(0.05), DefaultStatusCodeValidator, backend) 38 | 39 | for i := 1; i <= 100; i++ { 40 | resp := httptest.NewRecorder() 41 | req := &http.Request{Method: "GET"} 42 | 43 | if i >= 95 { 44 | code = 500 45 | } 46 | 47 | h.ServeHTTP(resp, req) 48 | lastResponse = resp.Code 49 | } 50 | 51 | if lastResponse != 503 { 52 | t.Fatalf("expected circuit to be open with 503 after 5%% error rate, got last response: %d", lastResponse) 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /_vendor/src/github.com/streadway/handy/breaker/metrics.go: -------------------------------------------------------------------------------- 1 | package breaker 2 | 3 | import ( 4 | "container/ring" 5 | "fmt" 6 | "time" 7 | ) 8 | 9 | type counter struct { 10 | second int64 11 | success uint 12 | failure uint 13 | } 14 | 15 | type summary struct { 16 | total uint 17 | errors uint 18 | rate float64 19 | } 20 | 21 | type metric struct { 22 | r *ring.Ring 23 | seconds uint 24 | now func() time.Time 25 | } 26 | 27 | func newMetric(window time.Duration, now func() time.Time) *metric { 28 | seconds := int(window / time.Second) 29 | 30 | if seconds <= 0 { 31 | panic("metrics must have a window of at least 1 Second") 32 | } 33 | 34 | r := ring.New(seconds) 35 | for i := 0; i < seconds; i++ { 36 | r.Value = &counter{} 37 | r = r.Next() 38 | } 39 | 40 | return &metric{r: r, seconds: uint(seconds), now: now} 41 | } 42 | 43 | func (m *metric) String() string { 44 | counters := []counter{} 45 | m.r.Do(func(v interface{}) { counters = append(counters, *v.(*counter)) }) 46 | return fmt.Sprint(counters) 47 | } 48 | 49 | func (m *metric) next() *counter { 50 | bucket := m.now().Unix() 51 | c := m.r.Value.(*counter) 52 | if c.second != bucket { 53 | m.r = m.r.Next() 54 | *m.r.Value.(*counter) = counter{second: bucket} 55 | } 56 | return c 57 | } 58 | 59 | func (m *metric) Success(time.Duration) { 60 | m.next().success++ 61 | } 62 | 63 | func (m *metric) Failure(time.Duration) { 64 | m.next().failure++ 65 | } 66 | 67 | func (m metric) Summary() summary { 68 | var sum summary 69 | 70 | m.r.Do(func(v interface{}) { 71 | c := v.(*counter) 72 | sum.total += c.success + c.failure 73 | sum.errors += c.failure 74 | }) 75 | 76 | if sum.total > 0 { 77 | sum.rate = float64(sum.errors) / float64(sum.total) 78 | } 79 | 80 | return sum 81 | } 82 | -------------------------------------------------------------------------------- /_vendor/src/github.com/streadway/handy/breaker/metrics_test.go: -------------------------------------------------------------------------------- 1 | package breaker 2 | 3 | import ( 4 | "testing" 5 | "time" 6 | ) 7 | 8 | func TestErrorRateUnderThreshold(t *testing.T) { 9 | c := newMetric(5*time.Second, time.Now) 10 | 11 | c.Success(0) 12 | c.Success(0) 13 | c.Success(0) 14 | c.Failure(0) 15 | c.Success(0) 16 | c.Failure(0) 17 | c.Success(0) 18 | c.Success(0) 19 | 20 | if r := c.Summary().rate; r == 0.0 { 21 | t.Errorf("expected error rate to be greater than zero, got: %f in %+v", r, c.Summary()) 22 | } 23 | } 24 | 25 | func TestErrorRateOverThreshold(t *testing.T) { 26 | c := newMetric(5*time.Second, time.Now) 27 | 28 | c.Failure(0) 29 | c.Failure(0) 30 | c.Failure(0) 31 | c.Failure(0) 32 | c.Failure(0) 33 | c.Failure(0) 34 | c.Failure(0) 35 | c.Success(0) 36 | c.Success(0) 37 | 38 | if ex, s := 0.70, c.Summary(); s.rate < ex { 39 | t.Errorf("expected error rate to be over %d%%, got: %f in %+v", int(ex*100), s.rate, s) 40 | } 41 | } 42 | 43 | func TestErrorRateCalculatedFromLast5Seconds(t *testing.T) { 44 | fakenow := time.Now() 45 | c := newMetric(5*time.Second, func() time.Time { return fakenow }) 46 | 47 | // 77% error for 5 seconds 48 | for i := 0; i < 5; i++ { 49 | fakenow = fakenow.Add(time.Second) 50 | 51 | c.Failure(0) 52 | c.Failure(0) 53 | c.Success(0) 54 | } 55 | 56 | // 33.333% error for 5 seconds 57 | for i := 0; i < 5; i++ { 58 | fakenow = fakenow.Add(time.Second) 59 | 60 | c.Failure(0) 61 | c.Success(0) 62 | c.Success(0) 63 | } 64 | 65 | if ex, s := 0.34, c.Summary(); s.rate > ex { 66 | t.Errorf("expected error rate to be under %d%%, got: %f in %+v", int(ex*100), s.rate, s) 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /_vendor/src/github.com/streadway/handy/breaker/simulation_test.go: -------------------------------------------------------------------------------- 1 | package breaker 2 | 3 | import ( 4 | "testing" 5 | "time" 6 | ) 7 | 8 | func failrate(b Breaker, count int, pct float64) { 9 | chance := int(1 / pct) 10 | if chance <= 0 { 11 | chance = 1 12 | } 13 | 14 | for i := 0; i < count; i++ { 15 | if b.Allow() { 16 | if (i%count)%chance == 0 { 17 | b.Failure(0) 18 | } else { 19 | b.Success(0) 20 | } 21 | } 22 | } 23 | } 24 | 25 | func TestSimulateConcurrentBreakerHandlerWithPartialFailures(t *testing.T) { 26 | const requestsPerSecond = 100 27 | const seconds = 5 28 | 29 | now := time.Now() 30 | after := make(chan time.Time) 31 | 32 | b := newBreaker(breakerConfig{ 33 | Window: seconds * time.Second, 34 | MinObservations: requestsPerSecond / seconds, 35 | FailureRatio: 0.05, 36 | Now: func() time.Time { return now }, 37 | After: func(time.Duration) <-chan time.Time { return after }, 38 | }) 39 | 40 | for i := 0; i < seconds; i++ { 41 | failrate(b, requestsPerSecond, 0.20) 42 | now = now.Add(time.Second) 43 | } 44 | 45 | if got, want := b.Allow(), false; got != want { 46 | t.Fatalf("expected to trip at a high failure rate") 47 | } 48 | 49 | after <- now 50 | 51 | if got, want := b.Allow(), true; got != want { 52 | t.Fatalf("expected to allow in half-open state after cooldown") 53 | } 54 | 55 | b.Success(time.Duration(0)) 56 | 57 | if got, want := b.Allow(), true; got != want { 58 | t.Fatalf("expected to close after success from half-open") 59 | } 60 | 61 | for i := 0; i < seconds; i++ { 62 | failrate(b, requestsPerSecond, 0.02) 63 | now = now.Add(time.Second) 64 | } 65 | 66 | if got, want := b.Allow(), true; got != want { 67 | t.Fatalf("expected to stay closed after lower error rate") 68 | } 69 | 70 | for i := 0; i < seconds; i++ { 71 | failrate(b, requestsPerSecond, 0.06) 72 | now = now.Add(time.Second) 73 | } 74 | 75 | if got, want := b.Allow(), false; got != want { 76 | t.Fatalf("expected to open after high error rate again") 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /_vendor/src/github.com/streadway/handy/breaker/transport.go: -------------------------------------------------------------------------------- 1 | package breaker 2 | 3 | import ( 4 | "errors" 5 | "net/http" 6 | "time" 7 | ) 8 | 9 | var ( 10 | // ErrCircuitOpen is returned by the transport when the downstream is 11 | // unavailable due to a broken circuit. 12 | ErrCircuitOpen = errors.New("circuit open") 13 | ) 14 | 15 | // ResponseValidator is a function that determines if an http.Response 16 | // received by a circuit breaking Transport should count as a success or a 17 | // failure. The DefaultResponseValidator can be used in most situations. 18 | type ResponseValidator func(*http.Response) bool 19 | 20 | // Transport produces an http.RoundTripper that's governed by the passed 21 | // Breaker and ResponseValidator. Responses that fail the validator signal 22 | // failures to the breaker. Once the breaker opens, outgoing requests are 23 | // terminated before being forwarded with ErrCircuitOpen. 24 | func Transport(breaker Breaker, validator ResponseValidator, next http.RoundTripper) http.RoundTripper { 25 | return &transport{ 26 | breaker: breaker, 27 | validator: validator, 28 | next: next, 29 | } 30 | } 31 | 32 | type transport struct { 33 | breaker Breaker 34 | validator ResponseValidator 35 | next http.RoundTripper 36 | } 37 | 38 | func (t *transport) RoundTrip(req *http.Request) (*http.Response, error) { 39 | if !t.breaker.Allow() { 40 | return nil, ErrCircuitOpen 41 | } 42 | 43 | begin := time.Now() 44 | resp, err := t.next.RoundTrip(req) 45 | 46 | duration := time.Since(begin) 47 | if err != nil || !t.validator(resp) { 48 | t.breaker.Failure(duration) 49 | } else { 50 | t.breaker.Success(duration) 51 | } 52 | 53 | return resp, err 54 | } 55 | 56 | // DefaultResponseValidator considers any status code less than 400 to be a 57 | // success, from the perspective of a client. All other codes are failures. 58 | func DefaultResponseValidator(resp *http.Response) bool { 59 | return resp.StatusCode < 400 60 | } 61 | -------------------------------------------------------------------------------- /_vendor/src/github.com/streadway/handy/breaker/transport_test.go: -------------------------------------------------------------------------------- 1 | package breaker 2 | 3 | import ( 4 | "net/http" 5 | "net/http/httptest" 6 | "net/url" 7 | "reflect" 8 | "testing" 9 | ) 10 | 11 | func TestTransportCircuitStaysClosedWithSingleError(t *testing.T) { 12 | s := httptest.NewServer(code(500)) 13 | defer s.Close() 14 | 15 | c := http.Client{ 16 | Transport: Transport(NewBreaker(0.05), DefaultResponseValidator, http.DefaultTransport), 17 | } 18 | 19 | c.Get(s.URL) 20 | 21 | if !c.Transport.(*transport).breaker.Allow() { 22 | t.Fatal("expected circuit to be closed after one bad request") 23 | } 24 | } 25 | 26 | func TestTransportCircuitOpenWith5PercentError(t *testing.T) { 27 | pass := httptest.NewServer(code(200)) 28 | defer pass.Close() 29 | 30 | fail := httptest.NewServer(code(500)) 31 | defer fail.Close() 32 | 33 | c := http.Client{ 34 | Transport: Transport(NewBreaker(0.05), DefaultResponseValidator, http.DefaultTransport), 35 | } 36 | 37 | var lastError error 38 | for i := 1; i <= 100; i++ { 39 | url := pass.URL 40 | 41 | if i >= 95 { 42 | url = fail.URL 43 | } 44 | 45 | _, lastError = c.Get(url) 46 | } 47 | 48 | if lastError == nil { 49 | t.Fatalf("expected %q after 5%% error rate, got no error", ErrCircuitOpen) 50 | } 51 | 52 | urlError, ok := lastError.(*url.Error) 53 | if !ok { 54 | t.Fatalf("expected url.Error after 5%% error rate, got %s", reflect.TypeOf(lastError)) 55 | } 56 | 57 | if err := urlError.Err; err != ErrCircuitOpen { 58 | t.Fatalf("expected %q after 5%% error rate, got %q", ErrCircuitOpen, err) 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /_vendor/src/github.com/streadway/handy/cors/cors.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013, SoundCloud Ltd. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the README file. 4 | // Source code and contact info at http://github.com/streadway/handy 5 | 6 | /* 7 | Package cors contains filters to handle CORS related requests defined from 8 | http://www.w3.org/TR/cors/ 9 | */ 10 | package cors 11 | 12 | import ( 13 | "net/http" 14 | "strconv" 15 | "time" 16 | ) 17 | 18 | // Get implements a simple read-only access control policy handling preflight 19 | // and normal requests with a cache age of 10 minutes for preflight requests. 20 | // Methods other than HEAD, OPTIONS, GET will return 405. 21 | // 22 | // The origin parameter should be the case-insentive fully qualified origin 23 | // domain to match or '*' to match any domain. 24 | func Get(origin string, next http.Handler) http.Handler { 25 | const maxAge = 10 * time.Minute 26 | age := strconv.Itoa(int(maxAge / time.Second)) 27 | 28 | return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { 29 | w.Header().Set("Access-Control-Allow-Methods", "GET") 30 | w.Header().Set("Access-Control-Allow-Headers", "Accept, Authorization, Content-Type, Origin") 31 | w.Header().Set("Access-Control-Allow-Origin", origin) 32 | 33 | switch r.Method { 34 | default: 35 | w.WriteHeader(http.StatusMethodNotAllowed) 36 | case "OPTIONS": 37 | if r.Header.Get("Access-Control-Request-Method") == "GET" { 38 | w.Header().Set("Access-Control-Max-Age", age) 39 | return 40 | } 41 | w.WriteHeader(http.StatusUnauthorized) 42 | case "HEAD", "GET": 43 | next.ServeHTTP(w, r) 44 | } 45 | }) 46 | } 47 | -------------------------------------------------------------------------------- /_vendor/src/github.com/streadway/handy/cors/cors_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013, SoundCloud Ltd. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the README file. 4 | // Source code and contact info at http://github.com/streadway/handy 5 | 6 | package cors 7 | 8 | import ( 9 | "net/http" 10 | "net/http/httptest" 11 | "strings" 12 | "testing" 13 | ) 14 | 15 | type code int 16 | 17 | func (h code) ServeHTTP(w http.ResponseWriter, r *http.Request) { 18 | w.WriteHeader(int(h)) 19 | } 20 | 21 | func TestGetPreflightGet(t *testing.T) { 22 | h := Get("*", code(404)) 23 | 24 | resp := httptest.NewRecorder() 25 | req := &http.Request{} 26 | 27 | req.Method = "OPTIONS" 28 | req.Header = map[string][]string{ 29 | "Access-Control-Request-Method": {"GET"}, 30 | "Origin": {"localhost"}, 31 | } 32 | 33 | h.ServeHTTP(resp, req) 34 | 35 | // OPTIONS should always return 200 if the request is ok. 36 | if res := resp.Code; res != 200 { 37 | t.Fatalf("expected 200 for OPTIONS, got: %d", res) 38 | } 39 | 40 | if hdr := resp.HeaderMap.Get("Access-Control-Allow-Origin"); hdr != "*" { 41 | t.Fatalf("expected Access-Control-Origin for OPTIONS, got: %s", hdr) 42 | } 43 | 44 | for _, hdr := range []string{"Origin", "Accept", "Content-Type"} { 45 | if hdrs := resp.HeaderMap.Get("Access-Control-Allow-Headers"); !strings.Contains(hdrs, hdr) { 46 | t.Fatalf("expected Access-Control-Allow-Headers to include Origin, got: %s", hdrs) 47 | } 48 | } 49 | } 50 | 51 | func TestGet(t *testing.T) { 52 | h := Get("*", code(404)) 53 | 54 | resp := httptest.NewRecorder() 55 | req := &http.Request{} 56 | 57 | req.Method = "GET" 58 | req.Header = map[string][]string{ 59 | "Origin": {"localhost"}, 60 | } 61 | 62 | h.ServeHTTP(resp, req) 63 | 64 | if res := resp.Code; res != 404 { 65 | t.Fatalf("expected 404 for GET, got: %d", res) 66 | } 67 | 68 | if hdr := resp.HeaderMap.Get("Access-Control-Allow-Origin"); hdr != "*" { 69 | t.Fatalf("expected Access-Control-Origin for OPTIONS, got: %s", hdr) 70 | } 71 | 72 | for _, hdr := range []string{"Origin", "Accept", "Content-Type"} { 73 | if hdrs := resp.HeaderMap.Get("Access-Control-Allow-Headers"); !strings.Contains(hdrs, hdr) { 74 | t.Fatalf("expected Access-Control-Allow-Headers to include Origin, got: %s", hdrs) 75 | } 76 | } 77 | } 78 | 79 | func TestGetWithPOST(t *testing.T) { 80 | h := Get("*", code(404)) 81 | 82 | resp := httptest.NewRecorder() 83 | req := &http.Request{} 84 | 85 | req.Method = "POST" 86 | req.Header = map[string][]string{ 87 | "Origin": {"localhost"}, 88 | } 89 | 90 | h.ServeHTTP(resp, req) 91 | 92 | if res := resp.Code; res != http.StatusMethodNotAllowed { 93 | t.Fatalf("expected 405 for GET, got: %d", res) 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /_vendor/src/github.com/streadway/handy/doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | Package handy organizes some useful http server handler filters or handlers for reuse. 3 | */ 4 | package documentation 5 | -------------------------------------------------------------------------------- /_vendor/src/github.com/streadway/handy/encoding/gzip.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013, SoundCloud Ltd. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the README file. 4 | // Source code and contact info at http://github.com/streadway/handy 5 | 6 | /* 7 | Package encoding contains Content-Encoding related filters. 8 | */ 9 | package encoding 10 | 11 | import ( 12 | "compress/gzip" 13 | "io" 14 | "net/http" 15 | "strings" 16 | ) 17 | 18 | type gzipWriter struct { 19 | io.Writer 20 | http.ResponseWriter 21 | } 22 | 23 | func (w gzipWriter) Write(b []byte) (int, error) { 24 | return w.Writer.Write(b) 25 | } 26 | 27 | // Gzip calls the next handler with a response writer that will compress the 28 | // outbound writes. This filter assumes a chunked transfer encoding, so do not 29 | // add a Content-Length header in the terminal handler. 30 | // 31 | // If the request does not accept a gzip encoding, this filter has no effect. 32 | func Gzip(next http.Handler) http.Handler { 33 | return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { 34 | if !strings.Contains(r.Header.Get("Accept-Encoding"), "gzip") { 35 | next.ServeHTTP(w, r) 36 | return 37 | } 38 | 39 | w.Header().Set("Content-Encoding", "gzip") 40 | w.Header().Add("Vary", "Accept-Encoding") 41 | 42 | gz := gzip.NewWriter(w) 43 | defer gz.Close() 44 | 45 | next.ServeHTTP(gzipWriter{Writer: gz, ResponseWriter: w}, r) 46 | }) 47 | } 48 | -------------------------------------------------------------------------------- /_vendor/src/github.com/streadway/handy/encoding/gzip_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013, SoundCloud Ltd. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the README file. 4 | // Source code and contact info at http://github.com/streadway/handy 5 | 6 | package encoding 7 | 8 | import ( 9 | "bytes" 10 | "compress/gzip" 11 | "io" 12 | "net/http" 13 | "net/http/httptest" 14 | "testing" 15 | ) 16 | 17 | type body string 18 | 19 | func (h body) ServeHTTP(w http.ResponseWriter, r *http.Request) { 20 | w.Write([]byte(h)) 21 | } 22 | 23 | func TestGzip(t *testing.T) { 24 | const msg = "the meaning of life, the universe and everything" 25 | 26 | h := Gzip(body(msg)) 27 | 28 | resp := httptest.NewRecorder() 29 | req := &http.Request{ 30 | Header: map[string][]string{"Accept-Encoding": {"gzip"}}, 31 | } 32 | 33 | h.ServeHTTP(resp, req) 34 | 35 | if hdr := resp.HeaderMap.Get("Content-Encoding"); hdr != "gzip" { 36 | t.Fatalf("expected content encoding to be gzip, got: %q", hdr) 37 | } 38 | 39 | if hdr := resp.HeaderMap.Get("Vary"); hdr != "Accept-Encoding" { 40 | t.Fatalf("expected to vary on accept encoding, got: %q", hdr) 41 | } 42 | 43 | plain := &bytes.Buffer{} 44 | gz, err := gzip.NewReader(resp.Body) 45 | if err != nil { 46 | t.Fatalf("expected a gzip stream, got: %q", err) 47 | } 48 | 49 | io.Copy(plain, gz) 50 | 51 | if plain.String() != msg { 52 | t.Fatalf("expected to decompress message, got: %q", plain.String()) 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /_vendor/src/github.com/streadway/handy/proxy/proxy.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013, SoundCloud Ltd. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the README file. 4 | // Source code and contact info at http://github.com/streadway/handy 5 | 6 | /* 7 | Package proxy contains a proxying HTTP transport. 8 | */ 9 | package proxy 10 | 11 | import ( 12 | "net/http" 13 | "net/url" 14 | ) 15 | 16 | // Transport is an implementation of the http.RoundTripper that uses a user 17 | // supplied generator function to proxy requests to specific destinations. 18 | type Transport struct { 19 | // Proxy takes an http.Request and provides a URL to use for that request. 20 | // Note that the semantics are different from http.DefaultTransport: this 21 | // proxy is always invoked. If Proxy is nil, requests to the Transport are 22 | // unaltered. 23 | Proxy func(*http.Request) (*url.URL, error) 24 | 25 | // Next is the http.RoundTripper to which requests are forwarded. If Next 26 | // is nil, http.DefaultTransport is used. 27 | Next http.RoundTripper 28 | } 29 | 30 | // RoundTrip implements the RoundTripper interface. 31 | func (t Transport) RoundTrip(req *http.Request) (*http.Response, error) { 32 | if t.Proxy != nil { 33 | url, err := t.Proxy(req) 34 | if err != nil { 35 | return nil, err 36 | } 37 | req.URL = url 38 | } 39 | if t.Next != nil { 40 | return t.Next.RoundTrip(req) 41 | } 42 | return http.DefaultTransport.RoundTrip(req) 43 | } 44 | -------------------------------------------------------------------------------- /_vendor/src/github.com/streadway/handy/proxy/proxy_test.go: -------------------------------------------------------------------------------- 1 | package proxy 2 | 3 | import ( 4 | "net/http" 5 | "net/http/httptest" 6 | "net/url" 7 | "testing" 8 | ) 9 | 10 | type count int 11 | 12 | func (h *count) ServeHTTP(w http.ResponseWriter, r *http.Request) { 13 | (*h)++ 14 | w.WriteHeader(200) 15 | } 16 | 17 | func TestProxy(t *testing.T) { 18 | var c1 count 19 | s1 := httptest.NewServer(&c1) 20 | defer s1.Close() 21 | 22 | var c2 count 23 | s2 := httptest.NewServer(&c2) 24 | defer s2.Close() 25 | 26 | proxyClient := http.Client{ 27 | Transport: Transport{ 28 | Proxy: func(*http.Request) (*url.URL, error) { 29 | return url.Parse(s2.URL) 30 | }, 31 | }, 32 | } 33 | 34 | resp, err := proxyClient.Get(s1.URL) 35 | 36 | if err != nil { 37 | t.Fatal(err) 38 | } 39 | 40 | if resp.StatusCode != 200 { 41 | t.Fatalf("expected 200, got %d", resp.StatusCode) 42 | } 43 | 44 | if expected, got := 0, int(c1); expected != got { 45 | t.Errorf("first server: expected request count %d, got %d", expected, got) 46 | } 47 | if expected, got := 1, int(c2); expected != got { 48 | t.Errorf("second server: expected request count %d, got %d", expected, got) 49 | } 50 | } 51 | 52 | func TestNilValues(t *testing.T) { 53 | var c count 54 | s := httptest.NewServer(&c) 55 | defer s.Close() 56 | 57 | nilClient := http.Client{ 58 | Transport: Transport{}, 59 | } 60 | 61 | resp, err := nilClient.Get(s.URL) 62 | 63 | if err != nil { 64 | t.Fatal(err) 65 | } 66 | 67 | if resp.StatusCode != 200 { 68 | t.Fatalf("expected 200, got %d", resp.StatusCode) 69 | } 70 | 71 | if expected, got := 1, int(c); expected != got { 72 | t.Errorf("expected request count %d, got %d", expected, got) 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /_vendor/src/github.com/streadway/handy/redirect/https.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013, SoundCloud Ltd. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the README file. 4 | // Source code and contact info at http://github.com/streadway/handy 5 | 6 | /* 7 | Package redirect contains filters to handle HTTP and HTTPS redirects 8 | */ 9 | package redirect 10 | 11 | import ( 12 | "net/http" 13 | ) 14 | 15 | // HTTPS ensures the scheme of incoming requests is https:// either from the 16 | // http.Request.URL.Scheme or X-Forwarded-Proto header. When the scheme is not 17 | // https, a redirect with 302 will be made to the same host found in 18 | // http.Request.Host. 19 | func HTTPS(next http.Handler) http.Handler { 20 | return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { 21 | // TODO handle the Forwarded-For header when it ratifies 22 | // http://tools.ietf.org/html/draft-ietf-appsawg-http-forwarded-10 23 | if r.URL.Scheme != "https" && r.Header.Get("X-Forwarded-Proto") != "https" { 24 | r.URL.Scheme = "https" 25 | r.URL.Host = r.Host 26 | http.Redirect(w, r, r.URL.String(), http.StatusFound) 27 | return 28 | } 29 | 30 | next.ServeHTTP(w, r) 31 | }) 32 | } 33 | -------------------------------------------------------------------------------- /_vendor/src/github.com/streadway/handy/report/event.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013, SoundCloud Ltd. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the README file. 4 | // Source code and contact info at http://github.com/streadway/handy 5 | 6 | /* 7 | Package report organizes textual reporting from the HTTP context. 8 | */ 9 | package report 10 | 11 | import ( 12 | "net/http" 13 | "time" 14 | ) 15 | 16 | // Event contains significant fields from the request or response to report 17 | type Event struct { 18 | Time time.Time `json:"time,omitempty"` 19 | Method string `json:"method,omitempty"` 20 | Url string `json:"url,omitempty"` 21 | Path string `json:"path,omitempty"` 22 | Proto string `json:"proto,omitempty"` 23 | Status int `json:"status,omitempty"` 24 | Ms int `json:"ms"` 25 | Size int64 `json:"size"` 26 | RemoteAddr string `json:"remote_addr,omitempty"` 27 | ForwardedFor string `json:"forwarded_for,omitempty"` 28 | ForwardedProto string `json:"forwarded_proto,omitempty"` 29 | Range string `json:"range,omitempty"` 30 | Host string `json:"host,omitempty"` 31 | Referrer string `json:"referrer,omitempty"` 32 | UserAgent string `json:"user_agent,omitempty"` 33 | Authorization string `json:"authorization,omitempty"` 34 | Region string `json:"region,omitempty"` 35 | Country string `json:"country,omitempty"` 36 | City string `json:"city,omitempty"` 37 | RequestId string `json:"request_id,omitempty"` 38 | } 39 | 40 | type eventRecorder struct { 41 | http.ResponseWriter 42 | event Event 43 | } 44 | 45 | // Write sums the writes to produce the actual number of bytes written 46 | func (e *eventRecorder) Write(b []byte) (int, error) { 47 | n, err := e.ResponseWriter.Write(b) 48 | e.event.Size += int64(n) 49 | return n, err 50 | } 51 | 52 | // WriteHeader captures the status code. On success, this method may not be 53 | // called so initialize your event struct with the status value you wish to 54 | // report on success,like 200. 55 | func (e *eventRecorder) WriteHeader(code int) { 56 | e.event.Status = code 57 | e.ResponseWriter.WriteHeader(code) 58 | } 59 | -------------------------------------------------------------------------------- /_vendor/src/github.com/streadway/handy/report/json.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013, SoundCloud Ltd. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the README file. 4 | // Source code and contact info at http://github.com/streadway/handy 5 | 6 | package report 7 | 8 | import ( 9 | "encoding/json" 10 | "io" 11 | "net/http" 12 | "time" 13 | ) 14 | 15 | // JSON writes a JSON encoded Event to the provided writer at the 16 | // completion of each request 17 | func JSON(writer io.Writer, next http.Handler) http.Handler { 18 | out := json.NewEncoder(writer) 19 | 20 | return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { 21 | writer := &eventRecorder{ 22 | ResponseWriter: w, 23 | event: Event{ 24 | // Size & Status possiblly overwritten by the ResponseWriter interface 25 | Status: 200, 26 | Time: time.Now().UTC(), 27 | Method: r.Method, 28 | Url: r.RequestURI, 29 | Path: r.URL.Path, 30 | Proto: r.Proto, 31 | Host: r.Host, 32 | RemoteAddr: r.RemoteAddr, 33 | ForwardedFor: r.Header.Get("X-Forwarded-For"), 34 | ForwardedProto: r.Header.Get("X-Forwarded-Proto"), 35 | Authorization: r.Header.Get("Authorization"), 36 | Referrer: r.Header.Get("Referer"), 37 | UserAgent: r.Header.Get("User-Agent"), 38 | Range: r.Header.Get("Range"), 39 | RequestId: r.Header.Get("X-Request-Id"), 40 | Region: r.Header.Get("X-Region"), 41 | Country: r.Header.Get("X-Country"), 42 | City: r.Header.Get("X-City"), 43 | }, 44 | } 45 | 46 | start := time.Now() 47 | 48 | next.ServeHTTP(writer, r) 49 | 50 | writer.event.Ms = int(time.Since(start) / time.Millisecond) 51 | 52 | out.Encode(writer.event) 53 | }) 54 | } 55 | -------------------------------------------------------------------------------- /_vendor/src/github.com/streadway/handy/report/json_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013, SoundCloud Ltd. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the README file. 4 | // Source code and contact info at http://github.com/streadway/handy 5 | 6 | package report 7 | 8 | import ( 9 | "encoding/json" 10 | "io" 11 | "net/http" 12 | "net/http/httptest" 13 | "testing" 14 | "time" 15 | ) 16 | 17 | func get(h http.Handler, url string) { 18 | res := httptest.NewRecorder() 19 | req, _ := http.NewRequest("GET", url, nil) 20 | h.ServeHTTP(res, req) 21 | } 22 | 23 | type sleeper time.Duration 24 | 25 | func (h sleeper) ServeHTTP(http.ResponseWriter, *http.Request) { 26 | time.Sleep(time.Duration(h)) 27 | } 28 | 29 | func TestMultipleJSONLogLines(t *testing.T) { 30 | const worktime = 10 * time.Millisecond 31 | const requests = 10 32 | 33 | var ( 34 | r, w = io.Pipe() 35 | handler = JSON(w, sleeper(worktime)) 36 | logger = json.NewDecoder(r) 37 | ) 38 | 39 | for i := 0; i < requests; i++ { 40 | go get(handler, "http://example.org/foo") 41 | } 42 | 43 | for i := 0; i < requests; i++ { 44 | report := map[string]interface{}{} 45 | if err := logger.Decode(&report); err != nil { 46 | t.Fatalf("expected to decode json report, got: %q", err) 47 | } 48 | 49 | t.Log(report) 50 | 51 | for field, want := range map[string]interface{}{ 52 | "status": float64(200), 53 | "method": "GET", 54 | "proto": "HTTP/1.1", 55 | "time": "", 56 | "size": "", 57 | "ms": "", 58 | } { 59 | if _, ok := report[field]; !ok { 60 | t.Fatalf("expected to report %q with any value, did not", field) 61 | } 62 | 63 | if want != "" { 64 | if got := report[field]; got != want { 65 | t.Fatalf("expected to report %q with %v, got %v", field, want, got) 66 | } 67 | } 68 | } 69 | 70 | if ms, ok := report["ms"].(float64); !ok { 71 | t.Fatalf("ms is not a number") 72 | } else { 73 | if want, got, delta := worktime, time.Duration(ms)*time.Millisecond, time.Millisecond; want+delta < got || want-delta > got { 74 | t.Fatalf("duration falls outside of %s±%s, got: %d", want, delta, got) 75 | } 76 | } 77 | } 78 | } 79 | 80 | func TestJSONShouldHaveMs(t *testing.T) { 81 | var ( 82 | r, w = io.Pipe() 83 | logger = json.NewDecoder(r) 84 | handler = JSON(w, sleeper(0)) 85 | ) 86 | 87 | go get(handler, "http://example.org/foo") 88 | 89 | report := map[string]interface{}{} 90 | if err := logger.Decode(&report); err != nil { 91 | t.Fatalf("expected to decode json report, got: %q", err) 92 | } 93 | 94 | if _, haveMs := report["ms"]; !haveMs { 95 | t.Fatalf("expected report to include ms, got: %v", report) 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /_vendor/src/github.com/streadway/handy/rewrite/method.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013, SoundCloud Ltd. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the README file. 4 | // Source code and contact info at http://github.com/streadway/handy 5 | 6 | /* 7 | Package rewrite contains filters to handle HTTP rewrites 8 | */ 9 | package rewrite 10 | 11 | import ( 12 | "net/http" 13 | ) 14 | 15 | // Method modifies the http.Request.Method for POST requests to the form value 16 | // "_method" only if that value is one of PUT, PATCH or DELETE. 17 | func Method(next http.Handler) http.Handler { 18 | return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { 19 | if r.Method == "POST" { 20 | switch _method := r.FormValue("_method"); _method { 21 | case "PUT", "PATCH", "DELETE": 22 | r.Method = _method 23 | } 24 | } 25 | next.ServeHTTP(w, r) 26 | }) 27 | } 28 | -------------------------------------------------------------------------------- /_vendor/src/github.com/streadway/handy/rewrite/method_test.go: -------------------------------------------------------------------------------- 1 | package rewrite 2 | 3 | import ( 4 | "net/http" 5 | "net/http/httptest" 6 | "net/url" 7 | "testing" 8 | ) 9 | 10 | type capture struct { 11 | r http.Request 12 | } 13 | 14 | func (h *capture) ServeHTTP(w http.ResponseWriter, r *http.Request) { 15 | h.r = *r 16 | } 17 | 18 | func TestMethodExpectations(t *testing.T) { 19 | for _, test := range []struct { 20 | original, overridden, expected string 21 | }{ 22 | {"GET", "DELETE", "GET"}, 23 | {"GET", "POST", "GET"}, 24 | {"POST", "DELETE", "DELETE"}, 25 | {"POST", "PUT", "PUT"}, 26 | {"POST", "POST", "POST"}, 27 | {"PUT", "DELETE", "PUT"}, 28 | {"DELETE", "PUT", "DELETE"}, 29 | } { 30 | h := &capture{} 31 | 32 | Method(h).ServeHTTP(httptest.NewRecorder(), &http.Request{ 33 | Method: test.original, 34 | Form: url.Values{ 35 | "_method": {test.overridden}}, 36 | }) 37 | 38 | if h.r.Method != test.expected { 39 | t.Fatalf("expected http method %q with override %q but got %q", 40 | test.original, test.expected, h.r.Method) 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /_vendor/src/github.com/streadway/handy/statsd/codes.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013, SoundCloud Ltd. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the README file. 4 | // Source code and contact info at http://github.com/streadway/handy 5 | 6 | package statsd 7 | 8 | import ( 9 | "bytes" 10 | "fmt" 11 | "io" 12 | "log" 13 | "net/http" 14 | "time" 15 | ) 16 | 17 | // capture records the response code returned through the embedded 18 | // ResponseWriter from the WriteHeader call. 19 | type capture struct { 20 | http.ResponseWriter 21 | code int 22 | } 23 | 24 | // WriteHeader captures the returned code and delegates 25 | func (w *capture) WriteHeader(code int) { 26 | w.code = code 27 | w.ResponseWriter.WriteHeader(code) 28 | } 29 | 30 | func reportCodes(statsd io.Writer, key string, report <-chan time.Time, codes <-chan int) { 31 | hist := make(map[int]int) 32 | msg := &bytes.Buffer{} 33 | 34 | for { 35 | select { 36 | case sample := <-codes: 37 | hist[sample] = hist[sample] + 1 38 | 39 | case <-report: 40 | if len(hist) > 0 { 41 | for code, count := range hist { 42 | fmt.Fprintf(msg, "%s.%d:%d|c\n", key, code, count) 43 | } 44 | 45 | if _, err := statsd.Write(msg.Bytes()); err != nil { 46 | log.Printf("error: could not write to statsd: %v", err) 47 | } 48 | 49 | hist = make(map[int]int) 50 | msg.Reset() 51 | } 52 | } 53 | } 54 | } 55 | 56 | // Codes collects and reports the counts of response codes for the handler chain for all requests. 57 | func Codes(statsd io.Writer, key string, interval time.Duration, next http.Handler) http.Handler { 58 | responses := make(chan int) 59 | go reportCodes(statsd, key, time.Tick(interval), responses) 60 | 61 | return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { 62 | // init with 200 so no call to WriteHeader is a success 63 | collector := &capture{w, 200} 64 | next.ServeHTTP(collector, r) 65 | responses <- collector.code 66 | }) 67 | } 68 | -------------------------------------------------------------------------------- /_vendor/src/github.com/streadway/handy/statsd/doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | Package statsd collects and reports telemetry from http handlers. 3 | */ 4 | package statsd 5 | -------------------------------------------------------------------------------- /_vendor/src/github.com/streadway/handy/statsd/durations.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013, SoundCloud Ltd. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the README file. 4 | // Source code and contact info at http://github.com/streadway/handy 5 | 6 | package statsd 7 | 8 | import ( 9 | "bytes" 10 | "fmt" 11 | "io" 12 | "log" 13 | "net/http" 14 | "time" 15 | ) 16 | 17 | // MaxPacketLen is the number of bytes filled before a packet is flushed before the reporting interval. 18 | const maxPacketLen = 2 ^ 15 19 | 20 | func flush(w io.Writer, buf *bytes.Buffer) { 21 | if _, err := w.Write(buf.Bytes()); err != nil { 22 | log.Printf("error: could not write to statsd: %v", err) 23 | } 24 | buf.Reset() 25 | } 26 | 27 | func reportDurations(w io.Writer, key string, interval <-chan time.Time, samples <-chan time.Duration) { 28 | msg := &bytes.Buffer{} 29 | 30 | for { 31 | select { 32 | case sample := <-samples: 33 | if msg.Len() == 0 { 34 | msg.Write([]byte(key)) 35 | } 36 | 37 | fmt.Fprintf(msg, ":%d|ms", int(sample/time.Millisecond)) 38 | 39 | if msg.Len() > maxPacketLen { 40 | flush(w, msg) 41 | } 42 | 43 | case <-interval: 44 | if msg.Len() > 0 { 45 | flush(w, msg) 46 | } 47 | } 48 | } 49 | } 50 | 51 | // Durations writes a statsd formatted packet to the io.Writer with a list of 52 | // durations recorded for each reporting interval or until a packet is filled. 53 | func Durations(statsd io.Writer, key string, interval time.Duration, next http.Handler) http.Handler { 54 | // buffered - reporting is concurrent with the handler 55 | durations := make(chan time.Duration, 1) 56 | go reportDurations(statsd, key, time.Tick(interval), durations) 57 | 58 | return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { 59 | start := time.Now() 60 | next.ServeHTTP(w, r) 61 | durations <- time.Now().Sub(start) 62 | }) 63 | } 64 | -------------------------------------------------------------------------------- /_vendor/src/github.com/streadway/handy/statsd/example_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013, SoundCloud Ltd. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the README file. 4 | // Source code and contact info at http://github.com/streadway/handy 5 | 6 | package statsd_test 7 | 8 | import ( 9 | "github.com/streadway/handy/statsd" 10 | "io" 11 | "io/ioutil" 12 | "net" 13 | "net/http" 14 | "time" 15 | ) 16 | 17 | func ExampleCodes() { 18 | var remote io.Writer 19 | 20 | remote, err := net.Dial("udp", "127.0.0.1:8126") 21 | if err != nil { 22 | // log error and continue 23 | remote = ioutil.Discard 24 | } 25 | 26 | http.ListenAndServe(":8080", 27 | statsd.Codes(remote, "doc.status", 10*time.Second, 28 | http.FileServer(http.Dir("/usr/share/doc")))) 29 | } 30 | -------------------------------------------------------------------------------- /_vendor/src/github.com/streadway/handy/statsd/instrumentation_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013, SoundCloud Ltd. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the README file. 4 | // Source code and contact info at http://github.com/streadway/handy 5 | 6 | package statsd 7 | 8 | import ( 9 | "bytes" 10 | "net/http" 11 | "net/http/httptest" 12 | "strings" 13 | "testing" 14 | "time" 15 | ) 16 | 17 | type codeHandler int 18 | 19 | func (h codeHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { 20 | w.WriteHeader(int(h)) 21 | } 22 | 23 | func TestInstrumentCodes(t *testing.T) { 24 | out := new(bytes.Buffer) 25 | 26 | handler200 := Codes(out, "test", time.Millisecond, codeHandler(200)) 27 | handler404 := Codes(out, "test", time.Millisecond, codeHandler(404)) 28 | 29 | resp := httptest.NewRecorder() 30 | req := &http.Request{} 31 | 32 | handler200.ServeHTTP(resp, req) 33 | handler404.ServeHTTP(resp, req) 34 | 35 | time.Sleep(2 * time.Millisecond) 36 | 37 | got := string(out.Bytes()) 38 | 39 | if !strings.Contains(got, "test.200:1|c") { 40 | t.Fatalf("expected statsd formatted count for 200, got: %q", got) 41 | } 42 | 43 | if !strings.Contains(got, "test.404:1|c") { 44 | t.Fatalf("expected statsd formatted count for 404, got: %q", got) 45 | } 46 | } 47 | 48 | func TestInstrumentDurations(t *testing.T) { 49 | out := new(bytes.Buffer) 50 | 51 | handler := Durations(out, "test", time.Millisecond, codeHandler(200)) 52 | 53 | resp := httptest.NewRecorder() 54 | req := &http.Request{} 55 | 56 | handler.ServeHTTP(resp, req) 57 | handler.ServeHTTP(resp, req) 58 | 59 | time.Sleep(2 * time.Millisecond) 60 | 61 | res := string(out.Bytes()) 62 | 63 | if res != "test:0|ms:0|ms" { 64 | t.Fatalf("expected key and two measurements at 0ms, got %q", res) 65 | } 66 | } 67 | 68 | type writeCounter struct { 69 | count int 70 | } 71 | 72 | func (w *writeCounter) Write(b []byte) (int, error) { 73 | w.count++ 74 | return len(b), nil 75 | } 76 | 77 | func TestInstrumentDurationFlushesAtPacketSize(t *testing.T) { 78 | out := &writeCounter{} 79 | 80 | handler := Durations(out, "test", time.Minute, codeHandler(200)) 81 | 82 | resp := httptest.NewRecorder() 83 | req := &http.Request{} 84 | 85 | for i := 0; i < maxPacketLen; i++ { 86 | handler.ServeHTTP(resp, req) 87 | } 88 | 89 | if out.count < 4 { 90 | t.Fatalf("expected early flush based on packet size, got %d writes", out.count) 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /_vendor/src/github.com/tsenart/tb/examples/echo.go: -------------------------------------------------------------------------------- 1 | package examples 2 | 3 | import ( 4 | "github.com/tsenart/tb" 5 | "io" 6 | "log" 7 | "net" 8 | "time" 9 | ) 10 | 11 | func main() { 12 | ln, err := net.Listen("tcp", ":6789") 13 | if err != nil { 14 | log.Fatal(err) 15 | } 16 | th := tb.NewThrottler(100 * time.Millisecond) 17 | 18 | echo := func(conn net.Conn) { 19 | defer conn.Close() 20 | 21 | host, port, err := net.SplitHostPort(conn.RemoteAddr().String()) 22 | if err != nil { 23 | panic(err) 24 | } 25 | // Throttle to 10 connection per second from the same host 26 | // Handle non-conformity by dropping the connection 27 | if th.Halt(host, 1, 10) { 28 | log.Printf("Throttled %s", host) 29 | return 30 | } 31 | log.Printf("Echoing payload from %s:%s", host, port) 32 | io.Copy(conn, conn) 33 | } 34 | 35 | for { 36 | conn, err := ln.Accept() 37 | if err != nil { 38 | log.Fatal(err) 39 | } 40 | go echo(conn) 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /_vendor/src/github.com/tsenart/tb/http/client.go: -------------------------------------------------------------------------------- 1 | package http 2 | 3 | import ( 4 | "github.com/tsenart/tb" 5 | "net/http" 6 | "time" 7 | ) 8 | 9 | type roundTripperFunc func(r *http.Request) (*http.Response, error) 10 | 11 | func (f roundTripperFunc) RoundTrip(r *http.Request) (*http.Response, error) { 12 | return f(r) 13 | } 14 | 15 | // ByteThrottledRoundTripper wraps another RoundTripper rt, 16 | // throttling all requests to the specified byte rate. 17 | func ByteThrottledRoundTripper(rt http.RoundTripper, rate int64) http.RoundTripper { 18 | freq := time.Duration(1 * time.Millisecond) 19 | bucket := tb.NewBucket(rate, freq) 20 | 21 | return roundTripperFunc(func(r *http.Request) (*http.Response, error) { 22 | got := bucket.Take(r.ContentLength) 23 | for got < r.ContentLength { 24 | got += bucket.Take(r.ContentLength - got) 25 | time.Sleep(freq) 26 | } 27 | return rt.RoundTrip(r) 28 | }) 29 | } 30 | 31 | // ReqThrottledRoundTripper wraps another RoundTripper rt, 32 | // throttling all requests to the specified request rate. 33 | func ReqThrottledRoundTripper(rt http.RoundTripper, rate int64) http.RoundTripper { 34 | freq := time.Duration(1e9 / rate) 35 | bucket := tb.NewBucket(rate, freq) 36 | 37 | return roundTripperFunc(func(r *http.Request) (*http.Response, error) { 38 | got := bucket.Take(1) 39 | for got != 1 { 40 | got = bucket.Take(1) 41 | time.Sleep(freq) 42 | } 43 | return rt.RoundTrip(r) 44 | }) 45 | } 46 | -------------------------------------------------------------------------------- /_vendor/src/github.com/tsenart/tb/http/server.go: -------------------------------------------------------------------------------- 1 | package http 2 | 3 | import ( 4 | "github.com/tsenart/tb" 5 | "net" 6 | "net/http" 7 | "time" 8 | ) 9 | 10 | var byteThrottler = tb.NewThrottler(25 * time.Millisecond) 11 | 12 | // ByteThrottledHandler wraps an http.Handler with per host byte throttling to 13 | // the specified byte rate, responding with 429 when throttled. 14 | func ByteThrottledHandler(h http.Handler, rate int64) http.Handler { 15 | return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { 16 | host, _, _ := net.SplitHostPort(r.RemoteAddr) 17 | if byteThrottler.Halt(host, r.ContentLength, rate) { 18 | http.Error(w, "Too many requests", 429) 19 | return 20 | } 21 | h.ServeHTTP(w, r) 22 | }) 23 | } 24 | 25 | var reqThrottler = tb.NewThrottler(5 * time.Millisecond) 26 | 27 | // ReqThrottledHandler wraps an http.Handler with per host request throttling 28 | // to the specified request rate, responding with 429 when throttled. 29 | func ReqThrottledHandler(h http.Handler, rate int64) http.Handler { 30 | return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { 31 | host, _, _ := net.SplitHostPort(r.RemoteAddr) 32 | if reqThrottler.Halt(host, 1, rate) { 33 | http.Error(w, "Too many requests", 429) 34 | return 35 | } 36 | h.ServeHTTP(w, r) 37 | }) 38 | } 39 | -------------------------------------------------------------------------------- /_vendor/src/github.com/tsenart/tb/io/io.go: -------------------------------------------------------------------------------- 1 | package io 2 | 3 | import ( 4 | "github.com/tsenart/tb" 5 | "io" 6 | "time" 7 | ) 8 | 9 | // NewThrottledWriter is an io.Writer wrapping another io.Writer with 10 | // byte rate throttling, flushing block bytes at a time. 11 | func NewThrottledWriter(rate, block int64, w io.Writer) io.Writer { 12 | return &throttledWriter{rate, block, w, tb.NewBucket(rate, -1)} 13 | } 14 | 15 | type throttledWriter struct { 16 | rate, block int64 17 | w io.Writer 18 | b *tb.Bucket 19 | } 20 | 21 | func (tw *throttledWriter) Write(p []byte) (n int, err error) { 22 | for wr := 0; wr < len(p); { 23 | var got int64 24 | for got < tw.block { 25 | if got += tw.b.Take(tw.block - got); got != tw.block { 26 | time.Sleep(time.Duration((1e9 / tw.rate) * (tw.block - got))) 27 | } 28 | } 29 | if n, err = tw.w.Write(p[wr : wr+int(got)]); err != nil { 30 | return wr, err 31 | } 32 | wr += n 33 | } 34 | return len(p), nil 35 | } 36 | -------------------------------------------------------------------------------- /_vendor/src/github.com/tsenart/tb/tb.go: -------------------------------------------------------------------------------- 1 | // Package tb provides a generic lock-free implementation of the 2 | // Token Bucket algorithm where non-conformity is handled by the user. 3 | // http://en.wikipedia.org/wiki/Token_bucket 4 | package tb 5 | -------------------------------------------------------------------------------- /common/README.md: -------------------------------------------------------------------------------- 1 | # common 2 | 3 | Package common provides type KeyScoreMember, which is the atom that represents 4 | an element in a Roshi set, and maps directly to an element in a Redis ZSET. 5 | -------------------------------------------------------------------------------- /common/cursor.go: -------------------------------------------------------------------------------- 1 | package common 2 | 3 | import ( 4 | "bytes" 5 | "encoding/base64" 6 | "fmt" 7 | "io" 8 | "io/ioutil" 9 | "math" 10 | "strconv" 11 | "strings" 12 | ) 13 | 14 | // Cursor is used as part of SelectRange. 15 | type Cursor struct { 16 | Score float64 17 | Member string 18 | } 19 | 20 | const cursorFormat = `%dA%s` // uint64(float64bits(score)) "A" string(base64(member)) 21 | 22 | // The letter "A" was chosen as a field delimiter from among all characters 23 | // enumerated in IETF RFC 3986 section 2.2 after an exhaustive series of 24 | // aptitude tests, physical challenges, and talent exhibitions. 25 | // Congratulations, A -- you've earned it. 26 | 27 | // String returns a string representation of the cursor, suitable for 28 | // returning in responses. 29 | func (c Cursor) String() string { 30 | var ( 31 | buf = bytes.Buffer{} 32 | enc = base64.NewEncoder(base64.URLEncoding, &buf) 33 | ) 34 | 35 | if _, err := enc.Write([]byte(c.Member)); err != nil { 36 | panic(err) 37 | } 38 | 39 | if err := enc.Close(); err != nil { 40 | panic(err) 41 | } 42 | 43 | return fmt.Sprintf(cursorFormat, math.Float64bits(c.Score), buf.String()) 44 | } 45 | 46 | func (c Cursor) Encode(w io.Writer) { 47 | fmt.Fprintf(w, "%dA", math.Float64bits(c.Score)) 48 | enc := base64.NewEncoder(base64.URLEncoding, w) 49 | enc.Write([]byte(c.Member)) 50 | enc.Close() 51 | } 52 | 53 | // Parse parses the cursor string into the Cursor object. 54 | func (c *Cursor) Parse(s string) error { 55 | fields := strings.SplitN(s, "A", 2) 56 | if len(fields) != 2 { 57 | return fmt.Errorf("invalid cursor string (%s)", s) 58 | } 59 | 60 | score, err := strconv.ParseUint(fields[0], 10, 64) 61 | if err != nil { 62 | return fmt.Errorf("invalid score in cursor string (%s)", err) 63 | } 64 | 65 | decoded, err := ioutil.ReadAll(base64.NewDecoder(base64.URLEncoding, bytes.NewReader([]byte(fields[1])))) 66 | if err != nil { 67 | return fmt.Errorf("invalid member in cursor string (%s)", err) 68 | } 69 | 70 | c.Score = math.Float64frombits(score) 71 | c.Member = string(decoded) 72 | 73 | return nil 74 | } 75 | -------------------------------------------------------------------------------- /common/doc.go: -------------------------------------------------------------------------------- 1 | // Package common holds data structures shared between different packages. 2 | package common 3 | -------------------------------------------------------------------------------- /common/key_score_member.go: -------------------------------------------------------------------------------- 1 | package common 2 | 3 | import ( 4 | "encoding/json" 5 | ) 6 | 7 | // KeyMember is used by the Score method, and other places internally. It's 8 | // probably not useful to external users. 9 | type KeyMember struct { 10 | Key string 11 | Member string 12 | } 13 | 14 | // KeyScoreMember represents one entry in a ZSET. 15 | type KeyScoreMember struct { 16 | Key string 17 | Score float64 18 | Member string 19 | } 20 | 21 | // Cursor generates a cursor for this KeyScoreMember. 22 | func (ksm KeyScoreMember) Cursor() Cursor { 23 | return Cursor{ 24 | Score: ksm.Score, 25 | Member: ksm.Member, 26 | } 27 | } 28 | 29 | // jsonKeyScoreMember is used internally by MarshalJSON and UnmarshalJSON. 30 | type jsonKeyScoreMember struct { 31 | Key []byte `json:"key"` 32 | Score float64 `json:"score"` 33 | Member []byte `json:"member"` 34 | } 35 | 36 | // MarshalJSON makes sure that the strings in KeyScoreMember are 37 | // marshalled properly as byte sequences (i.e. base64 encoded in the 38 | // JSON data; the JSON string encoding is neither efficient nor 39 | // reliable for arbitrary byte sequences). 40 | func (ksm KeyScoreMember) MarshalJSON() ([]byte, error) { 41 | return json.Marshal(&jsonKeyScoreMember{ 42 | Key: []byte(ksm.Key), 43 | Score: ksm.Score, 44 | Member: []byte(ksm.Member), 45 | }) 46 | } 47 | 48 | // UnmarshalJSON makes sure that the strings in KeyScoreMember are 49 | // unmarshalled properly from byte sequences (i.e. base64 encoded in 50 | // the JSON data; the JSON string encoding is neither efficient nor 51 | // reliable for arbitrary byte sequences). 52 | func (ksm *KeyScoreMember) UnmarshalJSON(data []byte) error { 53 | var jsonKSM jsonKeyScoreMember 54 | err := json.Unmarshal(data, &jsonKSM) 55 | if err == nil { 56 | ksm.Key = string(jsonKSM.Key) 57 | ksm.Score = jsonKSM.Score 58 | ksm.Member = string(jsonKSM.Member) 59 | } 60 | return err 61 | } 62 | -------------------------------------------------------------------------------- /common/key_score_member_test.go: -------------------------------------------------------------------------------- 1 | package common 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | func TestMarshal(t *testing.T) { 8 | // TODO 9 | } 10 | 11 | func TestUnmarshal(t *testing.T) { 12 | // TODO 13 | } 14 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/soundcloud/roshi 2 | 3 | go 1.14 4 | 5 | require ( 6 | github.com/beorn7/perks v1.0.1 // indirect 7 | github.com/garyburd/redigo v1.6.0 8 | github.com/golang/protobuf v1.4.2 // indirect 9 | github.com/gorilla/context v1.1.1 // indirect 10 | github.com/gorilla/mux v1.7.4 // indirect 11 | github.com/gorilla/pat v1.0.1 12 | github.com/peterbourgon/g2s v0.0.0-20170223122336-d4e7ad98afea 13 | github.com/prometheus/client_golang v0.9.4 14 | github.com/prometheus/client_model v0.2.0 // indirect 15 | github.com/prometheus/procfs v0.1.3 // indirect 16 | github.com/tsenart/tb v0.0.0-20181025101425-0d2499c8b6e9 17 | golang.org/x/sys v0.0.0-20200615200032-f1bc736245b1 // indirect 18 | ) 19 | 20 | replace github.com/soundcloud/roshi => ./ 21 | -------------------------------------------------------------------------------- /instrumentation/README.md: -------------------------------------------------------------------------------- 1 | # instrumentation 2 | 3 | TODO -------------------------------------------------------------------------------- /pool/README.md: -------------------------------------------------------------------------------- 1 | # pool 2 | 3 | [![GoDoc](https://godoc.org/github.com/soundcloud/roshi/pool?status.png)](https://godoc.org/github.com/soundcloud/roshi/pool) 4 | 5 | Package pool connects to multiple physical Redis instances, and emulates a 6 | single logical Redis instance. Clients are expected (but not required) to use 7 | their Redis keys as hash keys to select a Redis instance. The package 8 | maintains a connection pool to each instance. 9 | 10 | ## Usage 11 | 12 | Simple usage with a single key. 13 | 14 | ```go 15 | p := pool.New(...) 16 | defer p.Close() 17 | 18 | key, value := "foo", "bar" 19 | if err := p.With(key, func(c redis.Conn) error { 20 | _, err := c.Do("SET", key, value) 21 | return err 22 | }); err != nil { 23 | log.Printf("Failure: %s", err) 24 | } 25 | ``` 26 | 27 | Keys may be pre-hashed with the Index method, and connections used for 28 | pipelining. 29 | 30 | ```go 31 | m := map[int][]string{} // index: keys to INCR 32 | for _, key := range keys { 33 | index := p.Index(key) 34 | m[index] = append(m[index], key) 35 | } 36 | 37 | wg := sync.WaitGroup{} 38 | wg.Add(len(m)) 39 | for index, keys := range m { 40 | // Pool is safe for concurrent access. 41 | go func(index int, keys []string) { 42 | p.WithIndex(index, func(c redis.Conn) error) { 43 | defer wg.Done() 44 | for _, key := range keys { 45 | if err := c.Send("INCR", key); err != nil { 46 | return err 47 | } 48 | } 49 | if err := c.Flush(); err != nil { 50 | return err 51 | } 52 | for _ = range keys { 53 | if _, err := c.Receive(); err != nil { 54 | return err 55 | } 56 | } 57 | return nil 58 | }) 59 | }(index, keys) 60 | } 61 | wg.Wait() 62 | ``` 63 | -------------------------------------------------------------------------------- /pool/connection_pool_test.go: -------------------------------------------------------------------------------- 1 | package pool 2 | 3 | import ( 4 | "io/ioutil" 5 | "log" 6 | "math" 7 | "runtime" 8 | "testing" 9 | "time" 10 | ) 11 | 12 | func TestMemoryRegression(t *testing.T) { 13 | log.SetOutput(ioutil.Discard) 14 | quit := make(chan struct{}) 15 | diff := make(chan uint64) 16 | tick := time.Tick(250 * time.Millisecond) 17 | go func() { 18 | var ( 19 | m runtime.MemStats 20 | biggest uint64 21 | smallest = uint64(math.MaxUint64) 22 | ) 23 | for { 24 | select { 25 | case <-tick: 26 | runtime.ReadMemStats(&m) 27 | //t.Logf( 28 | // "%d total allocated bytes; %d still in use overall, %d still in use on the heap", 29 | // m.TotalAlloc, 30 | // m.Alloc, 31 | // m.HeapAlloc, 32 | //) 33 | if m.HeapAlloc > biggest { 34 | biggest = m.HeapAlloc 35 | } 36 | if m.HeapAlloc < smallest { 37 | smallest = m.HeapAlloc 38 | } 39 | case <-quit: 40 | diff <- biggest - smallest 41 | return 42 | } 43 | } 44 | }() 45 | 46 | addr := "127.0.0.1:54321" // invalid 47 | timeout := 500 * time.Millisecond 48 | maxConnections := 25 49 | p := newConnectionPool(addr, timeout, timeout, timeout, maxConnections) 50 | for i, n := 0, 10; i < n; i++ { 51 | runtime.GC() 52 | p.get() 53 | } 54 | 55 | close(quit) 56 | if delta := <-diff; delta > 100 { 57 | t.Errorf("HeapAlloc ∆ was %d", delta) 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /pool/hashes.go: -------------------------------------------------------------------------------- 1 | package pool 2 | 3 | import ( 4 | "bytes" 5 | "encoding/binary" 6 | "hash/fnv" 7 | ) 8 | 9 | // FNV implements the FNV-1 string hashing function. It can be passed to 10 | // NewCluster. 11 | func FNV(s string) uint32 { 12 | h := fnv.New32() 13 | h.Write([]byte(s)) 14 | return h.Sum32() 15 | } 16 | 17 | // FNVa implements the FNV-1a string hashing function. It can be passed to 18 | // NewCluster. 19 | func FNVa(s string) uint32 { 20 | h := fnv.New32a() 21 | h.Write([]byte(s)) 22 | return h.Sum32() 23 | } 24 | 25 | // Murmur3 implements the Murmur3 string hashing function. It can be passed to 26 | // NewCluster. 27 | // 28 | // https://github.com/reusee/mmh3 29 | func Murmur3(s string) uint32 { 30 | key := []byte(s) 31 | 32 | length := len(key) 33 | if length == 0 { 34 | return 0 35 | } 36 | 37 | var c1, c2 uint32 = 0xcc9e2d51, 0x1b873593 38 | var h, k uint32 39 | buf := bytes.NewBufferString(s) 40 | 41 | nblocks := length / 4 42 | for i := 0; i < nblocks; i++ { 43 | binary.Read(buf, binary.LittleEndian, &k) 44 | k *= c1 45 | k = (k << 15) | (k >> (32 - 15)) 46 | k *= c2 47 | h ^= k 48 | h = (h << 13) | (h >> (32 - 13)) 49 | h = (h * 5) + 0xe6546b64 50 | } 51 | 52 | k = 0 53 | tailIndex := nblocks * 4 54 | switch length & 3 { 55 | case 3: 56 | k ^= uint32(key[tailIndex+2]) << 16 57 | fallthrough 58 | case 2: 59 | k ^= uint32(key[tailIndex+1]) << 8 60 | fallthrough 61 | case 1: 62 | k ^= uint32(key[tailIndex]) 63 | k *= c1 64 | k = (k << 15) | (k >> (32 - 15)) 65 | k *= c2 66 | h ^= k 67 | } 68 | h ^= uint32(length) 69 | h ^= h >> 16 70 | h *= 0x85ebca6b 71 | h ^= h >> 13 72 | h *= 0xc2b2ae35 73 | h ^= h >> 16 74 | return h 75 | } 76 | -------------------------------------------------------------------------------- /roshi-server/Makefile: -------------------------------------------------------------------------------- 1 | GO ?= go 2 | GOPATH := $(CURDIR)/../_vendor:$(GOPATH) 3 | 4 | all: build 5 | 6 | build: 7 | $(GO) build 8 | 9 | clean: 10 | $(GO) clean 11 | 12 | check: 13 | @$(GO) list -f '{{join .Deps "\n"}}' | xargs $(GO) list -f '{{if not .Standard}}{{.ImportPath}} {{.Dir}}{{end}}' | column -t 14 | -------------------------------------------------------------------------------- /roshi-walker/Makefile: -------------------------------------------------------------------------------- 1 | GO ?= go 2 | GOPATH := $(CURDIR)/../_vendor:$(GOPATH) 3 | 4 | all: build 5 | 6 | build: 7 | $(GO) build 8 | 9 | clean: 10 | $(GO) clean 11 | 12 | check: 13 | @$(GO) list -f '{{join .Deps "\n"}}' | xargs $(GO) list -f '{{if not .Standard}}{{.ImportPath}} {{.Dir}}{{end}}' | column -t 14 | -------------------------------------------------------------------------------- /roshi-walker/README.md: -------------------------------------------------------------------------------- 1 | # roshi-walker 2 | 3 | roshi-walker walks the keyspace of a Roshi farm in semirandom order (random 4 | order of Redis instances; Redis [SCAN][scan] command on each instance) and a 5 | user-defined rate. It makes Select request for each key, using the 6 | [SendAllReadAll read strategy][send-all-read-all] in order to perform complete 7 | read repair. 8 | 9 | [scan]: http://redis.io/commands/scan 10 | [send-all-read-all]: https://github.com/soundcloud/roshi/tree/master/farm#read-strategies 11 | 12 | ## Getting and building 13 | 14 | roshi-walker uses vendored dependencies and a "blessed build" process to ensure 15 | stability over time. Users should get and build roshi-walker by cloning this 16 | repository and running `make` in the roshi-walker subdirectory. A working Go 17 | toolchain is assumed. 18 | 19 | git clone git@github.com:soundcloud/roshi 20 | cd roshi/roshi-walker 21 | make 22 | 23 | It's also possible to get roshi-walker via `go get`, and/or build it with a 24 | simple `go build`, with the caveat that it will use your normal GOPATH to 25 | resolve dependencies, and therefore will enforce no constraints on dependency 26 | versions, which could introduce bugs or strange behavior. 27 | 28 | ## Usage 29 | 30 | roshi-walker is designed to be used in two situations. 31 | 32 | ### Walk forever 33 | 34 | One or more roshi-walker instances can be started for a given Roshi farm, set 35 | to walk at a moderate rate and run forever. That will ensure that all keys are 36 | made consistent, within some upper time bound. That in turn improves data 37 | durability, especially if normal reads are non-uniform or low volume. 38 | 39 | It's recommended to run a few roshi-walker processes in this mode on every 40 | Roshi farm. Test against your infrastructure to determine an appropriate rate. 41 | 42 | ### Walk once 43 | 44 | roshi-walker supports a **-once** flag, which will walk the entire keyspace 45 | once and exit. This is useful if a Redis instance has crashed and come back 46 | online with no data. In this situation, while the farm still returns correct 47 | data, it is less resilient to further node failure. After the walk is 48 | complete, the empty instance will be repopulated with relevant data via read 49 | repair, and the resiliency of the farm is returned to normal levels. 50 | --------------------------------------------------------------------------------