From 6e12447b0549e01fbda35ceb2db78bee8aa59e12 Mon Sep 17 00:00:00 2001 From: Arve Knudsen Date: Tue, 12 Oct 2021 13:58:01 +0200 Subject: [PATCH] Chore: Use dskit/grpc* (#4523) Signed-off-by: Arve Knudsen Signed-off-by: Alvin Lin --- docs/configuration/config-file-reference.md | 10 + go.mod | 5 +- go.sum | 42 +- pkg/alertmanager/alertmanager_client.go | 4 +- pkg/chunk/gcp/bigtable_index_client.go | 2 +- pkg/configs/client/client.go | 8 +- pkg/configs/db/dbtest/integration.go | 1 + pkg/configs/db/dbtest/unit.go | 1 + pkg/configs/legacy_promql/fuzz.go | 1 + pkg/cortex/cortex.go | 4 +- pkg/distributor/query.go | 4 +- pkg/frontend/v1/frontend.go | 4 +- pkg/frontend/v2/frontend.go | 6 +- pkg/ingester/client/client.go | 3 +- pkg/ingester/client/cortex_util_test.go | 4 +- pkg/querier/store_gateway_client.go | 4 +- pkg/querier/store_gateway_client_test.go | 2 +- pkg/querier/worker/scheduler_processor.go | 6 +- pkg/querier/worker/worker.go | 2 +- pkg/ruler/client_pool.go | 5 +- pkg/ruler/client_pool_test.go | 3 +- pkg/ruler/notifier.go | 2 +- pkg/ruler/ruler.go | 2 +- pkg/scheduler/scheduler.go | 6 +- pkg/scheduler/scheduler_test.go | 4 +- pkg/util/dns_watcher.go | 11 +- pkg/util/grpc/encoding/snappy/snappy_test.go | 71 - .../grpc/healthcheck/health_check_test.go | 145 - pkg/util/grpcclient/ratelimit_test.go | 36 - .../{grpcutil => httpgrpcutil}/carrier.go | 2 +- pkg/util/tls/test/tls_integration_test.go | 567 --- pkg/util/tls/tls_test.go | 190 - tools/blocksconvert/planprocessor/service.go | 2 +- .../coreos/etcd/pkg/fileutil/dir_unix.go | 5 + .../coreos/etcd/pkg/fileutil/dir_windows.go | 5 + .../coreos/etcd/pkg/fileutil/fileutil.go | 43 +- .../coreos/etcd/pkg/fileutil/purge.go | 14 +- .../form3tech-oss/jwt-go/.gitignore | 5 - .../form3tech-oss/jwt-go/.travis.yml | 12 - .../github.com/form3tech-oss/jwt-go/LICENSE | 8 - .../form3tech-oss/jwt-go/MIGRATION_GUIDE.md | 97 - .../github.com/form3tech-oss/jwt-go/README.md | 104 - .../form3tech-oss/jwt-go/VERSION_HISTORY.md | 118 - .../github.com/form3tech-oss/jwt-go/claims.go | 136 - vendor/github.com/form3tech-oss/jwt-go/doc.go | 4 - .../github.com/form3tech-oss/jwt-go/ecdsa.go | 148 - .../form3tech-oss/jwt-go/ecdsa_utils.go | 69 - .../github.com/form3tech-oss/jwt-go/errors.go | 59 - .../github.com/form3tech-oss/jwt-go/hmac.go | 95 - .../form3tech-oss/jwt-go/map_claims.go | 110 - .../github.com/form3tech-oss/jwt-go/none.go | 52 - .../github.com/form3tech-oss/jwt-go/parser.go | 148 - vendor/github.com/form3tech-oss/jwt-go/rsa.go | 101 - .../form3tech-oss/jwt-go/rsa_pss.go | 142 - .../form3tech-oss/jwt-go/rsa_utils.go | 101 - .../form3tech-oss/jwt-go/signing_method.go | 35 - .../github.com/form3tech-oss/jwt-go/token.go | 108 - .../golang/protobuf/descriptor/descriptor.go | 180 - .../golang/protobuf/jsonpb/decode.go | 524 --- .../golang/protobuf/jsonpb/encode.go | 559 --- .../github.com/golang/protobuf/jsonpb/json.go | 69 - .../protoc-gen-go/descriptor/descriptor.pb.go | 200 - .../github.com/gorilla/websocket/.gitignore | 25 - vendor/github.com/gorilla/websocket/AUTHORS | 9 - vendor/github.com/gorilla/websocket/LICENSE | 22 - vendor/github.com/gorilla/websocket/README.md | 64 - vendor/github.com/gorilla/websocket/client.go | 395 -- .../gorilla/websocket/client_clone.go | 16 - .../gorilla/websocket/client_clone_legacy.go | 38 - .../gorilla/websocket/compression.go | 148 - vendor/github.com/gorilla/websocket/conn.go | 1201 ------ .../gorilla/websocket/conn_write.go | 15 - .../gorilla/websocket/conn_write_legacy.go | 18 - vendor/github.com/gorilla/websocket/doc.go | 227 - vendor/github.com/gorilla/websocket/go.mod | 3 - vendor/github.com/gorilla/websocket/go.sum | 0 vendor/github.com/gorilla/websocket/join.go | 42 - vendor/github.com/gorilla/websocket/json.go | 60 - vendor/github.com/gorilla/websocket/mask.go | 54 - .../github.com/gorilla/websocket/mask_safe.go | 15 - .../github.com/gorilla/websocket/prepared.go | 102 - vendor/github.com/gorilla/websocket/proxy.go | 77 - vendor/github.com/gorilla/websocket/server.go | 363 -- vendor/github.com/gorilla/websocket/trace.go | 19 - .../github.com/gorilla/websocket/trace_17.go | 12 - vendor/github.com/gorilla/websocket/util.go | 283 -- .../gorilla/websocket/x_net_proxy.go | 473 --- .../grafana/dskit/crypto}/tls/tls.go | 0 .../grafana/dskit/flagext/deprecated.go | 4 +- .../dskit}/grpcclient/backoff_retry.go | 3 +- .../grafana/dskit}/grpcclient/grpcclient.go | 12 +- .../dskit}/grpcclient/instrumentation.go | 6 +- .../grafana/dskit}/grpcclient/ratelimit.go | 0 .../dskit/grpcencoding}/snappy/snappy.go | 0 .../grafana/dskit/grpcutil}/dns_resolver.go | 35 +- .../grafana/dskit/grpcutil}/health_check.go | 11 +- .../grafana/dskit/grpcutil}/naming.go | 4 +- .../grafana/dskit/grpcutil}/util.go | 2 +- vendor/github.com/grafana/dskit/kv/client.go | 2 +- .../grafana/dskit/kv/consul/client.go | 4 +- .../grafana/dskit/kv/consul/mock.go | 4 +- .../github.com/grafana/dskit/kv/etcd/etcd.go | 21 +- .../github.com/grafana/dskit/kv/etcd/mock.go | 512 ++- .../github.com/grafana/dskit/kv/kvtls/tls.go | 87 - .../grafana/dskit/kv/memberlist/broadcast.go | 4 +- .../dskit/kv/memberlist/kv_init_service.go | 2 +- .../dskit/kv/memberlist/memberlist_client.go | 13 +- .../dskit/kv/memberlist/memberlist_logger.go | 4 +- .../grafana/dskit/kv/memberlist/metrics.go | 2 +- .../dskit/kv/memberlist/tcp_transport.go | 8 +- vendor/github.com/grafana/dskit/kv/mock.go | 4 +- vendor/github.com/grafana/dskit/kv/multi.go | 4 +- .../grafana/dskit/middleware/grpc.go | 83 + .../grafana/dskit/modules/module_service.go | 4 +- .../dskit/modules/module_service_wrapper.go | 2 +- .../grafana/dskit/modules/modules.go | 2 +- .../grafana/dskit/runtimeconfig/manager.go | 4 +- .../go-grpc-prometheus/.gitignore | 201 - .../go-grpc-prometheus/.travis.yml | 25 - .../go-grpc-prometheus/CHANGELOG.md | 24 - .../grpc-ecosystem/go-grpc-prometheus/LICENSE | 201 - .../go-grpc-prometheus/README.md | 247 -- .../go-grpc-prometheus/client.go | 39 - .../go-grpc-prometheus/client_metrics.go | 170 - .../go-grpc-prometheus/client_reporter.go | 46 - .../go-grpc-prometheus/makefile | 16 - .../go-grpc-prometheus/metric_options.go | 41 - .../go-grpc-prometheus/server.go | 48 - .../go-grpc-prometheus/server_metrics.go | 185 - .../go-grpc-prometheus/server_reporter.go | 46 - .../grpc-ecosystem/go-grpc-prometheus/util.go | 50 - .../grpc-ecosystem/grpc-gateway/LICENSE.txt | 27 - .../grpc-gateway/internal/BUILD.bazel | 23 - .../grpc-gateway/internal/errors.pb.go | 189 - .../grpc-gateway/internal/errors.proto | 26 - .../grpc-gateway/runtime/BUILD.bazel | 85 - .../grpc-gateway/runtime/context.go | 291 -- .../grpc-gateway/runtime/convert.go | 318 -- .../grpc-gateway/runtime/doc.go | 5 - .../grpc-gateway/runtime/errors.go | 186 - .../grpc-gateway/runtime/fieldmask.go | 89 - .../grpc-gateway/runtime/handler.go | 212 - .../runtime/marshal_httpbodyproto.go | 43 - .../grpc-gateway/runtime/marshal_json.go | 45 - .../grpc-gateway/runtime/marshal_jsonpb.go | 262 -- .../grpc-gateway/runtime/marshal_proto.go | 62 - .../grpc-gateway/runtime/marshaler.go | 55 - .../runtime/marshaler_registry.go | 99 - .../grpc-gateway/runtime/mux.go | 300 -- .../grpc-gateway/runtime/pattern.go | 262 -- .../grpc-gateway/runtime/proto2_convert.go | 80 - .../grpc-gateway/runtime/proto_errors.go | 106 - .../grpc-gateway/runtime/query.go | 406 -- .../grpc-gateway/utilities/BUILD.bazel | 21 - .../grpc-gateway/utilities/doc.go | 2 - .../grpc-gateway/utilities/pattern.go | 22 - .../grpc-gateway/utilities/readerfactory.go | 20 - .../grpc-gateway/utilities/trie.go | 177 - .../jonboulle/clockwork/.editorconfig | 12 - .../github.com/jonboulle/clockwork/.gitignore | 27 - vendor/github.com/jonboulle/clockwork/LICENSE | 201 - .../github.com/jonboulle/clockwork/README.md | 80 - .../jonboulle/clockwork/clockwork.go | 195 - vendor/github.com/jonboulle/clockwork/go.mod | 3 - .../github.com/jonboulle/clockwork/ticker.go | 72 - vendor/github.com/soheilhy/cmux/.gitignore | 24 - vendor/github.com/soheilhy/cmux/.travis.yml | 29 - vendor/github.com/soheilhy/cmux/CONTRIBUTORS | 12 - vendor/github.com/soheilhy/cmux/LICENSE | 202 - vendor/github.com/soheilhy/cmux/README.md | 83 - vendor/github.com/soheilhy/cmux/buffer.go | 67 - vendor/github.com/soheilhy/cmux/cmux.go | 307 -- vendor/github.com/soheilhy/cmux/doc.go | 18 - vendor/github.com/soheilhy/cmux/go.mod | 5 - vendor/github.com/soheilhy/cmux/go.sum | 12 - vendor/github.com/soheilhy/cmux/matchers.go | 267 -- vendor/github.com/soheilhy/cmux/patricia.go | 179 - vendor/github.com/spf13/pflag/.gitignore | 2 - vendor/github.com/spf13/pflag/.travis.yml | 22 - vendor/github.com/spf13/pflag/LICENSE | 28 - vendor/github.com/spf13/pflag/README.md | 296 -- vendor/github.com/spf13/pflag/bool.go | 94 - vendor/github.com/spf13/pflag/bool_slice.go | 185 - vendor/github.com/spf13/pflag/bytes.go | 209 - vendor/github.com/spf13/pflag/count.go | 96 - vendor/github.com/spf13/pflag/duration.go | 86 - .../github.com/spf13/pflag/duration_slice.go | 166 - vendor/github.com/spf13/pflag/flag.go | 1239 ------ vendor/github.com/spf13/pflag/float32.go | 88 - .../github.com/spf13/pflag/float32_slice.go | 174 - vendor/github.com/spf13/pflag/float64.go | 84 - .../github.com/spf13/pflag/float64_slice.go | 166 - vendor/github.com/spf13/pflag/go.mod | 3 - vendor/github.com/spf13/pflag/go.sum | 0 vendor/github.com/spf13/pflag/golangflag.go | 105 - vendor/github.com/spf13/pflag/int.go | 84 - vendor/github.com/spf13/pflag/int16.go | 88 - vendor/github.com/spf13/pflag/int32.go | 88 - vendor/github.com/spf13/pflag/int32_slice.go | 174 - vendor/github.com/spf13/pflag/int64.go | 84 - vendor/github.com/spf13/pflag/int64_slice.go | 166 - vendor/github.com/spf13/pflag/int8.go | 88 - vendor/github.com/spf13/pflag/int_slice.go | 158 - vendor/github.com/spf13/pflag/ip.go | 94 - vendor/github.com/spf13/pflag/ip_slice.go | 186 - vendor/github.com/spf13/pflag/ipmask.go | 122 - vendor/github.com/spf13/pflag/ipnet.go | 98 - vendor/github.com/spf13/pflag/string.go | 80 - vendor/github.com/spf13/pflag/string_array.go | 129 - vendor/github.com/spf13/pflag/string_slice.go | 163 - .../github.com/spf13/pflag/string_to_int.go | 149 - .../github.com/spf13/pflag/string_to_int64.go | 149 - .../spf13/pflag/string_to_string.go | 160 - vendor/github.com/spf13/pflag/uint.go | 88 - vendor/github.com/spf13/pflag/uint16.go | 88 - vendor/github.com/spf13/pflag/uint32.go | 88 - vendor/github.com/spf13/pflag/uint64.go | 88 - vendor/github.com/spf13/pflag/uint8.go | 88 - vendor/github.com/spf13/pflag/uint_slice.go | 168 - .../tmc/grpc-websocket-proxy/LICENSE | 7 - .../tmc/grpc-websocket-proxy/wsproxy/doc.go | 2 - .../wsproxy/websocket_proxy.go | 350 -- .../weaveworks/common/server/server.go | 2 +- vendor/github.com/xiang90/probing/.gitignore | 24 - vendor/github.com/xiang90/probing/LICENSE | 22 - vendor/github.com/xiang90/probing/README.md | 39 - vendor/github.com/xiang90/probing/prober.go | 139 - vendor/github.com/xiang90/probing/server.go | 25 - vendor/github.com/xiang90/probing/status.go | 108 - .../etcd/api/v3/etcdserverpb/gw/rpc.pb.gw.go | 3771 ----------------- .../etcd/client/pkg/v3/fileutil/dir_unix.go | 28 - .../client/pkg/v3/fileutil/dir_windows.go | 52 - .../etcd/client/pkg/v3/fileutil/doc.go | 16 - .../etcd/client/pkg/v3/fileutil/fileutil.go | 172 - .../etcd/client/pkg/v3/fileutil/lock.go | 26 - .../etcd/client/pkg/v3/fileutil/lock_flock.go | 50 - .../etcd/client/pkg/v3/fileutil/lock_linux.go | 93 - .../etcd/client/pkg/v3/fileutil/lock_plan9.go | 45 - .../client/pkg/v3/fileutil/lock_solaris.go | 63 - .../etcd/client/pkg/v3/fileutil/lock_unix.go | 30 - .../client/pkg/v3/fileutil/lock_windows.go | 126 - .../client/pkg/v3/fileutil/preallocate.go | 54 - .../pkg/v3/fileutil/preallocate_darwin.go | 67 - .../pkg/v3/fileutil/preallocate_unix.go | 50 - .../v3/fileutil/preallocate_unsupported.go | 26 - .../etcd/client/pkg/v3/fileutil/purge.go | 93 - .../etcd/client/pkg/v3/fileutil/read_dir.go | 70 - .../etcd/client/pkg/v3/fileutil/sync.go | 30 - .../client/pkg/v3/fileutil/sync_darwin.go | 39 - .../etcd/client/pkg/v3/fileutil/sync_linux.go | 35 - .../etcd/client/pkg/v3/pathutil/path.go | 31 - .../go.etcd.io/etcd/client/pkg/v3/srv/srv.go | 142 - .../client/pkg/v3/tlsutil/cipher_suites.go | 39 - .../etcd/client/pkg/v3/tlsutil/doc.go | 16 - .../etcd/client/pkg/v3/tlsutil/tlsutil.go | 73 - .../etcd/client/pkg/v3/transport/doc.go | 17 - .../pkg/v3/transport/keepalive_listener.go | 94 - .../client/pkg/v3/transport/limit_listen.go | 80 - .../etcd/client/pkg/v3/transport/listener.go | 574 --- .../client/pkg/v3/transport/listener_opts.go | 76 - .../client/pkg/v3/transport/listener_tls.go | 272 -- .../etcd/client/pkg/v3/transport/sockopt.go | 45 - .../client/pkg/v3/transport/sockopt_unix.go | 22 - .../pkg/v3/transport/sockopt_windows.go | 19 - .../client/pkg/v3/transport/timeout_conn.go | 44 - .../client/pkg/v3/transport/timeout_dialer.go | 36 - .../pkg/v3/transport/timeout_listener.go | 45 - .../pkg/v3/transport/timeout_transport.go | 51 - .../etcd/client/pkg/v3/transport/tls.go | 49 - .../etcd/client/pkg/v3/transport/transport.go | 77 - .../client/pkg/v3/transport/unix_listener.go | 40 - vendor/go.etcd.io/etcd/client/v2/LICENSE | 202 - vendor/go.etcd.io/etcd/client/v2/README.md | 112 - vendor/go.etcd.io/etcd/client/v2/auth_role.go | 236 -- vendor/go.etcd.io/etcd/client/v2/auth_user.go | 319 -- vendor/go.etcd.io/etcd/client/v2/cancelreq.go | 18 - vendor/go.etcd.io/etcd/client/v2/client.go | 717 ---- .../etcd/client/v2/cluster_error.go | 37 - vendor/go.etcd.io/etcd/client/v2/curl.go | 70 - vendor/go.etcd.io/etcd/client/v2/discover.go | 40 - vendor/go.etcd.io/etcd/client/v2/doc.go | 73 - vendor/go.etcd.io/etcd/client/v2/go.mod | 24 - vendor/go.etcd.io/etcd/client/v2/go.sum | 163 - vendor/go.etcd.io/etcd/client/v2/json.go | 73 - vendor/go.etcd.io/etcd/client/v2/keys.go | 680 --- vendor/go.etcd.io/etcd/client/v2/members.go | 303 -- vendor/go.etcd.io/etcd/client/v2/util.go | 53 - .../etcd/client/v3/concurrency/doc.go | 17 - .../etcd/client/v3/concurrency/election.go | 254 -- .../etcd/client/v3/concurrency/key.go | 65 - .../etcd/client/v3/concurrency/mutex.go | 167 - .../etcd/client/v3/concurrency/session.go | 141 - .../etcd/client/v3/concurrency/stm.go | 387 -- vendor/go.etcd.io/etcd/pkg/v3/LICENSE | 202 - vendor/go.etcd.io/etcd/pkg/v3/adt/README.md | 48 - vendor/go.etcd.io/etcd/pkg/v3/adt/adt.go | 16 - .../etcd/pkg/v3/adt/interval_tree.go | 951 ----- .../etcd/pkg/v3/contention/contention.go | 69 - .../go.etcd.io/etcd/pkg/v3/contention/doc.go | 16 - vendor/go.etcd.io/etcd/pkg/v3/cpuutil/doc.go | 16 - .../go.etcd.io/etcd/pkg/v3/cpuutil/endian.go | 36 - vendor/go.etcd.io/etcd/pkg/v3/crc/crc.go | 43 - .../go.etcd.io/etcd/pkg/v3/debugutil/doc.go | 16 - .../go.etcd.io/etcd/pkg/v3/debugutil/pprof.go | 47 - vendor/go.etcd.io/etcd/pkg/v3/flags/flag.go | 132 - .../go.etcd.io/etcd/pkg/v3/flags/ignored.go | 41 - .../etcd/pkg/v3/flags/selective_string.go | 114 - .../go.etcd.io/etcd/pkg/v3/flags/strings.go | 53 - .../etcd/pkg/v3/flags/unique_strings.go | 77 - .../etcd/pkg/v3/flags/unique_urls.go | 93 - vendor/go.etcd.io/etcd/pkg/v3/flags/urls.go | 66 - .../etcd/pkg/v3/httputil/httputil.go | 50 - vendor/go.etcd.io/etcd/pkg/v3/idutil/id.go | 75 - .../etcd/pkg/v3/ioutil/pagewriter.go | 117 - .../etcd/pkg/v3/ioutil/readcloser.go | 66 - .../go.etcd.io/etcd/pkg/v3/ioutil/reader.go | 40 - vendor/go.etcd.io/etcd/pkg/v3/ioutil/util.go | 43 - vendor/go.etcd.io/etcd/pkg/v3/netutil/doc.go | 16 - .../go.etcd.io/etcd/pkg/v3/netutil/netutil.go | 213 - .../go.etcd.io/etcd/pkg/v3/netutil/routes.go | 34 - .../etcd/pkg/v3/netutil/routes_linux.go | 251 -- .../go.etcd.io/etcd/pkg/v3/pbutil/pbutil.go | 56 - .../etcd/pkg/v3/runtime/fds_linux.go | 47 - .../etcd/pkg/v3/runtime/fds_other.go | 31 - vendor/go.etcd.io/etcd/pkg/v3/schedule/doc.go | 16 - .../etcd/pkg/v3/schedule/schedule.go | 165 - .../go.etcd.io/etcd/pkg/v3/traceutil/trace.go | 240 -- vendor/go.etcd.io/etcd/pkg/v3/wait/wait.go | 110 - .../go.etcd.io/etcd/pkg/v3/wait/wait_time.go | 66 - vendor/go.etcd.io/etcd/raft/v3/LICENSE | 202 - vendor/go.etcd.io/etcd/raft/v3/OWNERS | 19 - vendor/go.etcd.io/etcd/raft/v3/README.md | 201 - vendor/go.etcd.io/etcd/raft/v3/bootstrap.go | 80 - .../etcd/raft/v3/confchange/confchange.go | 421 -- .../etcd/raft/v3/confchange/restore.go | 155 - vendor/go.etcd.io/etcd/raft/v3/design.md | 57 - vendor/go.etcd.io/etcd/raft/v3/doc.go | 300 -- vendor/go.etcd.io/etcd/raft/v3/go.mod | 20 - vendor/go.etcd.io/etcd/raft/v3/go.sum | 79 - vendor/go.etcd.io/etcd/raft/v3/log.go | 406 -- .../go.etcd.io/etcd/raft/v3/log_unstable.go | 157 - vendor/go.etcd.io/etcd/raft/v3/logger.go | 142 - vendor/go.etcd.io/etcd/raft/v3/node.go | 590 --- .../go.etcd.io/etcd/raft/v3/quorum/joint.go | 75 - .../etcd/raft/v3/quorum/majority.go | 210 - .../go.etcd.io/etcd/raft/v3/quorum/quorum.go | 58 - .../etcd/raft/v3/quorum/voteresult_string.go | 26 - vendor/go.etcd.io/etcd/raft/v3/raft.go | 1837 -------- .../etcd/raft/v3/raftpb/confchange.go | 170 - .../etcd/raft/v3/raftpb/confstate.go | 44 - .../go.etcd.io/etcd/raft/v3/raftpb/raft.pb.go | 2988 ------------- .../go.etcd.io/etcd/raft/v3/raftpb/raft.proto | 187 - vendor/go.etcd.io/etcd/raft/v3/rawnode.go | 241 -- vendor/go.etcd.io/etcd/raft/v3/read_only.go | 121 - vendor/go.etcd.io/etcd/raft/v3/status.go | 105 - vendor/go.etcd.io/etcd/raft/v3/storage.go | 273 -- .../etcd/raft/v3/tracker/inflights.go | 132 - .../etcd/raft/v3/tracker/progress.go | 255 -- .../go.etcd.io/etcd/raft/v3/tracker/state.go | 42 - .../etcd/raft/v3/tracker/tracker.go | 288 -- vendor/go.etcd.io/etcd/raft/v3/util.go | 233 - vendor/go.etcd.io/etcd/server/v3/LICENSE | 202 - vendor/go.etcd.io/etcd/server/v3/auth/doc.go | 16 - vendor/go.etcd.io/etcd/server/v3/auth/jwt.go | 163 - .../go.etcd.io/etcd/server/v3/auth/metrics.go | 43 - vendor/go.etcd.io/etcd/server/v3/auth/nop.go | 35 - .../go.etcd.io/etcd/server/v3/auth/options.go | 192 - .../etcd/server/v3/auth/range_perm_cache.go | 141 - .../etcd/server/v3/auth/simple_token.go | 247 -- .../go.etcd.io/etcd/server/v3/auth/store.go | 1315 ------ .../etcd/server/v3/config/config.go | 335 -- .../etcd/server/v3/config/v2_deprecation.go | 50 - .../etcd/server/v3/datadir/datadir.go | 40 - .../go.etcd.io/etcd/server/v3/datadir/doc.go | 17 - .../go.etcd.io/etcd/server/v3/embed/config.go | 968 ----- .../etcd/server/v3/embed/config_logging.go | 265 -- .../v3/embed/config_logging_journal_unix.go | 36 - .../embed/config_logging_journal_windows.go | 28 - vendor/go.etcd.io/etcd/server/v3/embed/doc.go | 45 - .../go.etcd.io/etcd/server/v3/embed/etcd.go | 859 ---- .../go.etcd.io/etcd/server/v3/embed/serve.go | 427 -- .../go.etcd.io/etcd/server/v3/embed/util.go | 29 - .../server/v3/etcdserver/api/capability.go | 95 - .../etcd/server/v3/etcdserver/api/cluster.go | 38 - .../etcd/server/v3/etcdserver/api/doc.go | 16 - .../server/v3/etcdserver/api/etcdhttp/base.go | 156 - .../server/v3/etcdserver/api/etcdhttp/doc.go | 16 - .../v3/etcdserver/api/etcdhttp/metrics.go | 204 - .../server/v3/etcdserver/api/etcdhttp/peer.go | 163 - .../v3/etcdserver/api/membership/cluster.go | 882 ---- .../v3/etcdserver/api/membership/confstate.go | 63 - .../v3/etcdserver/api/membership/doc.go | 16 - .../v3/etcdserver/api/membership/downgrade.go | 80 - .../v3/etcdserver/api/membership/errors.go | 35 - .../v3/etcdserver/api/membership/member.go | 142 - .../v3/etcdserver/api/membership/metrics.go | 31 - .../v3/etcdserver/api/membership/store.go | 335 -- .../v3/etcdserver/api/membership/storev2.go | 36 - .../v3/etcdserver/api/rafthttp/coder.go | 27 - .../server/v3/etcdserver/api/rafthttp/doc.go | 16 - .../server/v3/etcdserver/api/rafthttp/http.go | 531 --- .../v3/etcdserver/api/rafthttp/metrics.go | 186 - .../v3/etcdserver/api/rafthttp/msg_codec.go | 68 - .../etcdserver/api/rafthttp/msgappv2_codec.go | 248 -- .../server/v3/etcdserver/api/rafthttp/peer.go | 367 -- .../v3/etcdserver/api/rafthttp/peer_status.go | 90 - .../v3/etcdserver/api/rafthttp/pipeline.go | 178 - .../etcdserver/api/rafthttp/probing_status.go | 98 - .../v3/etcdserver/api/rafthttp/remote.go | 95 - .../api/rafthttp/snapshot_sender.go | 201 - .../v3/etcdserver/api/rafthttp/stream.go | 713 ---- .../v3/etcdserver/api/rafthttp/transport.go | 447 -- .../v3/etcdserver/api/rafthttp/urlpick.go | 57 - .../server/v3/etcdserver/api/rafthttp/util.go | 204 - .../etcd/server/v3/etcdserver/api/snap/db.go | 100 - .../etcd/server/v3/etcdserver/api/snap/doc.go | 17 - .../server/v3/etcdserver/api/snap/message.go | 64 - .../server/v3/etcdserver/api/snap/metrics.go | 82 - .../v3/etcdserver/api/snap/snappb/snap.pb.go | 344 -- .../v3/etcdserver/api/snap/snappb/snap.proto | 14 - .../v3/etcdserver/api/snap/snapshotter.go | 301 -- .../server/v3/etcdserver/api/v2auth/auth.go | 670 --- .../v3/etcdserver/api/v2auth/auth_requests.go | 177 - .../etcdserver/api/v2discovery/discovery.go | 412 -- .../server/v3/etcdserver/api/v2error/error.go | 165 - .../v3/etcdserver/api/v2http/capability.go | 41 - .../server/v3/etcdserver/api/v2http/client.go | 756 ---- .../v3/etcdserver/api/v2http/client_auth.go | 604 --- .../server/v3/etcdserver/api/v2http/doc.go | 16 - .../server/v3/etcdserver/api/v2http/http.go | 82 - .../etcdserver/api/v2http/httptypes/errors.go | 51 - .../etcdserver/api/v2http/httptypes/member.go | 69 - .../v3/etcdserver/api/v2http/metrics.go | 98 - .../v3/etcdserver/api/v2stats/leader.go | 135 - .../server/v3/etcdserver/api/v2stats/queue.go | 110 - .../v3/etcdserver/api/v2stats/server.go | 142 - .../server/v3/etcdserver/api/v2stats/stats.go | 26 - .../server/v3/etcdserver/api/v2store/doc.go | 17 - .../server/v3/etcdserver/api/v2store/event.go | 71 - .../etcdserver/api/v2store/event_history.go | 129 - .../v3/etcdserver/api/v2store/event_queue.go | 34 - .../v3/etcdserver/api/v2store/metrics.go | 130 - .../server/v3/etcdserver/api/v2store/node.go | 396 -- .../v3/etcdserver/api/v2store/node_extern.go | 116 - .../server/v3/etcdserver/api/v2store/stats.go | 145 - .../server/v3/etcdserver/api/v2store/store.go | 799 ---- .../v3/etcdserver/api/v2store/ttl_key_heap.go | 97 - .../v3/etcdserver/api/v2store/watcher.go | 95 - .../v3/etcdserver/api/v2store/watcher_hub.go | 200 - .../server/v3/etcdserver/api/v2v3/cluster.go | 31 - .../etcd/server/v3/etcdserver/api/v2v3/doc.go | 16 - .../server/v3/etcdserver/api/v2v3/server.go | 130 - .../server/v3/etcdserver/api/v2v3/store.go | 638 --- .../server/v3/etcdserver/api/v2v3/watcher.go | 142 - .../v3/etcdserver/api/v3alarm/alarms.go | 153 - .../server/v3/etcdserver/api/v3client/doc.go | 45 - .../v3/etcdserver/api/v3client/v3client.go | 67 - .../etcdserver/api/v3compactor/compactor.go | 73 - .../v3/etcdserver/api/v3compactor/doc.go | 16 - .../v3/etcdserver/api/v3compactor/periodic.go | 205 - .../v3/etcdserver/api/v3compactor/revision.go | 130 - .../v3/etcdserver/api/v3election/doc.go | 16 - .../v3/etcdserver/api/v3election/election.go | 134 - .../v3electionpb/gw/v3election.pb.gw.go | 454 -- .../v3election/v3electionpb/v3election.pb.go | 2541 ----------- .../v3election/v3electionpb/v3election.proto | 119 - .../server/v3/etcdserver/api/v3lock/doc.go | 16 - .../server/v3/etcdserver/api/v3lock/lock.go | 56 - .../api/v3lock/v3lockpb/gw/v3lock.pb.gw.go | 242 -- .../api/v3lock/v3lockpb/v3lock.pb.go | 1141 ----- .../api/v3lock/v3lockpb/v3lock.proto | 65 - .../server/v3/etcdserver/api/v3rpc/auth.go | 166 - .../server/v3/etcdserver/api/v3rpc/codec.go | 34 - .../server/v3/etcdserver/api/v3rpc/grpc.go | 91 - .../server/v3/etcdserver/api/v3rpc/header.go | 49 - .../v3/etcdserver/api/v3rpc/interceptor.go | 345 -- .../server/v3/etcdserver/api/v3rpc/key.go | 271 -- .../server/v3/etcdserver/api/v3rpc/lease.go | 157 - .../v3/etcdserver/api/v3rpc/maintenance.go | 314 -- .../server/v3/etcdserver/api/v3rpc/member.go | 124 - .../server/v3/etcdserver/api/v3rpc/metrics.go | 58 - .../server/v3/etcdserver/api/v3rpc/quota.go | 90 - .../server/v3/etcdserver/api/v3rpc/util.go | 147 - .../server/v3/etcdserver/api/v3rpc/watch.go | 583 --- .../etcd/server/v3/etcdserver/apply.go | 1151 ----- .../etcd/server/v3/etcdserver/apply_auth.go | 247 -- .../etcd/server/v3/etcdserver/apply_v2.go | 159 - .../etcd/server/v3/etcdserver/backend.go | 109 - .../server/v3/etcdserver/cindex/cindex.go | 189 - .../etcd/server/v3/etcdserver/cindex/doc.go | 16 - .../etcd/server/v3/etcdserver/cluster_util.go | 482 --- .../etcd/server/v3/etcdserver/corrupt.go | 442 -- .../etcd/server/v3/etcdserver/doc.go | 16 - .../etcd/server/v3/etcdserver/errors.go | 56 - .../etcd/server/v3/etcdserver/metrics.go | 243 -- .../etcd/server/v3/etcdserver/quota.go | 172 - .../etcd/server/v3/etcdserver/raft.go | 689 --- .../etcd/server/v3/etcdserver/server.go | 2699 ------------ .../v3/etcdserver/server_access_control.go | 65 - .../server/v3/etcdserver/snapshot_merge.go | 85 - .../etcd/server/v3/etcdserver/storage.go | 121 - .../etcd/server/v3/etcdserver/util.go | 198 - .../etcd/server/v3/etcdserver/v2_server.go | 166 - .../etcd/server/v3/etcdserver/v3_server.go | 991 ----- .../etcd/server/v3/etcdserver/zap_raft.go | 102 - vendor/go.etcd.io/etcd/server/v3/lease/doc.go | 16 - .../etcd/server/v3/lease/lease_queue.go | 108 - .../etcd/server/v3/lease/leasehttp/doc.go | 16 - .../etcd/server/v3/lease/leasehttp/http.go | 248 -- .../etcd/server/v3/lease/leasepb/lease.pb.go | 733 ---- .../etcd/server/v3/lease/leasepb/lease.proto | 25 - .../go.etcd.io/etcd/server/v3/lease/lessor.go | 937 ---- .../etcd/server/v3/lease/metrics.go | 59 - .../etcd/server/v3/mvcc/backend/backend.go | 648 --- .../etcd/server/v3/mvcc/backend/batch_tx.go | 344 -- .../server/v3/mvcc/backend/config_default.go | 24 - .../server/v3/mvcc/backend/config_linux.go | 34 - .../server/v3/mvcc/backend/config_windows.go | 27 - .../etcd/server/v3/mvcc/backend/doc.go | 16 - .../etcd/server/v3/mvcc/backend/hooks.go | 36 - .../etcd/server/v3/mvcc/backend/metrics.go | 95 - .../etcd/server/v3/mvcc/backend/read_tx.go | 150 - .../etcd/server/v3/mvcc/backend/tx_buffer.go | 231 - .../etcd/server/v3/mvcc/buckets/bucket.go | 80 - vendor/go.etcd.io/etcd/server/v3/mvcc/doc.go | 16 - .../go.etcd.io/etcd/server/v3/mvcc/index.go | 276 -- .../etcd/server/v3/mvcc/key_index.go | 378 -- vendor/go.etcd.io/etcd/server/v3/mvcc/kv.go | 150 - .../go.etcd.io/etcd/server/v3/mvcc/kv_view.go | 56 - .../go.etcd.io/etcd/server/v3/mvcc/kvstore.go | 555 --- .../etcd/server/v3/mvcc/kvstore_compaction.go | 78 - .../etcd/server/v3/mvcc/kvstore_txn.go | 304 -- .../go.etcd.io/etcd/server/v3/mvcc/metrics.go | 314 -- .../etcd/server/v3/mvcc/metrics_txn.go | 72 - .../etcd/server/v3/mvcc/revision.go | 67 - vendor/go.etcd.io/etcd/server/v3/mvcc/util.go | 37 - .../etcd/server/v3/mvcc/watchable_store.go | 545 --- .../server/v3/mvcc/watchable_store_txn.go | 56 - .../go.etcd.io/etcd/server/v3/mvcc/watcher.go | 193 - .../etcd/server/v3/mvcc/watcher_group.go | 293 -- .../grpcproxy/adapter/auth_client_adapter.go | 97 - .../v3/proxy/grpcproxy/adapter/chan_stream.go | 167 - .../adapter/cluster_client_adapter.go | 49 - .../server/v3/proxy/grpcproxy/adapter/doc.go | 17 - .../adapter/election_client_adapter.go | 80 - .../grpcproxy/adapter/kv_client_adapter.go | 49 - .../grpcproxy/adapter/lease_client_adapter.go | 82 - .../grpcproxy/adapter/lock_client_adapter.go | 37 - .../adapter/maintenance_client_adapter.go | 92 - .../grpcproxy/adapter/watch_client_adapter.go | 66 - .../go.etcd.io/etcd/server/v3/verify/doc.go | 20 - .../etcd/server/v3/verify/verify.go | 148 - .../go.etcd.io/etcd/server/v3/wal/decoder.go | 196 - vendor/go.etcd.io/etcd/server/v3/wal/doc.go | 75 - .../go.etcd.io/etcd/server/v3/wal/encoder.go | 124 - .../etcd/server/v3/wal/file_pipeline.go | 105 - .../go.etcd.io/etcd/server/v3/wal/metrics.go | 42 - .../go.etcd.io/etcd/server/v3/wal/repair.go | 114 - vendor/go.etcd.io/etcd/server/v3/wal/util.go | 112 - vendor/go.etcd.io/etcd/server/v3/wal/wal.go | 1003 ----- .../etcd/server/v3/wal/walpb/record.go | 41 - .../etcd/server/v3/wal/walpb/record.pb.go | 609 --- .../etcd/server/v3/wal/walpb/record.proto | 24 - vendor/go.opentelemetry.io/contrib/.gitignore | 13 - .../go.opentelemetry.io/contrib/.golangci.yml | 32 - .../go.opentelemetry.io/contrib/CHANGELOG.md | 319 -- vendor/go.opentelemetry.io/contrib/CODEOWNERS | 17 - .../contrib/CONTRIBUTING.md | 135 - vendor/go.opentelemetry.io/contrib/LICENSE | 201 - vendor/go.opentelemetry.io/contrib/Makefile | 203 - vendor/go.opentelemetry.io/contrib/README.md | 25 - .../go.opentelemetry.io/contrib/RELEASING.md | 96 - vendor/go.opentelemetry.io/contrib/contrib.go | 28 - vendor/go.opentelemetry.io/contrib/doc.go | 20 - vendor/go.opentelemetry.io/contrib/go.mod | 3 - vendor/go.opentelemetry.io/contrib/go.sum | 0 .../google.golang.org/grpc/otelgrpc/LICENSE | 201 - .../google.golang.org/grpc/otelgrpc/go.mod | 16 - .../google.golang.org/grpc/otelgrpc/go.sum | 122 - .../grpc/otelgrpc/grpctrace.go | 132 - .../grpc/otelgrpc/interceptor.go | 499 --- .../contrib/pre_release.sh | 158 - vendor/go.opentelemetry.io/contrib/tag.sh | 178 - vendor/go.opentelemetry.io/otel/.gitignore | 19 - vendor/go.opentelemetry.io/otel/.gitmodules | 3 - vendor/go.opentelemetry.io/otel/.golangci.yml | 32 - vendor/go.opentelemetry.io/otel/CHANGELOG.md | 1319 ------ vendor/go.opentelemetry.io/otel/CODEOWNERS | 17 - .../go.opentelemetry.io/otel/CONTRIBUTING.md | 380 -- vendor/go.opentelemetry.io/otel/LICENSE | 201 - vendor/go.opentelemetry.io/otel/Makefile | 179 - vendor/go.opentelemetry.io/otel/README.md | 92 - vendor/go.opentelemetry.io/otel/RELEASING.md | 81 - vendor/go.opentelemetry.io/otel/VERSIONING.md | 217 - .../go.opentelemetry.io/otel/attribute/doc.go | 20 - .../otel/attribute/encoder.go | 150 - .../otel/attribute/iterator.go | 143 - .../go.opentelemetry.io/otel/attribute/key.go | 102 - .../go.opentelemetry.io/otel/attribute/kv.go | 108 - .../go.opentelemetry.io/otel/attribute/set.go | 471 -- .../otel/attribute/type_string.go | 28 - .../otel/attribute/value.go | 204 - .../otel/baggage/baggage.go | 67 - .../go.opentelemetry.io/otel/baggage/doc.go | 24 - .../go.opentelemetry.io/otel/codes/codes.go | 106 - vendor/go.opentelemetry.io/otel/codes/doc.go | 25 - vendor/go.opentelemetry.io/otel/doc.go | 38 - .../go.opentelemetry.io/otel/error_handler.go | 22 - .../otel/exporters/otlp/LICENSE | 201 - .../otel/exporters/otlp/README.md | 31 - .../otel/exporters/otlp/doc.go | 20 - .../otel/exporters/otlp/go.mod | 62 - .../otel/exporters/otlp/go.sum | 123 - .../otlp/internal/otlpconfig/envconfig.go | 196 - .../otlp/internal/otlpconfig/options.go | 376 -- .../exporters/otlp/internal/otlpconfig/tls.go | 69 - .../otlp/internal/transform/attribute.go | 141 - .../internal/transform/instrumentation.go | 31 - .../otlp/internal/transform/metric.go | 631 --- .../otlp/internal/transform/resource.go | 29 - .../exporters/otlp/internal/transform/span.go | 218 - .../otel/exporters/otlp/options.go | 45 - .../otel/exporters/otlp/optiontypes.go | 38 - .../otel/exporters/otlp/otlp.go | 179 - .../exporters/otlp/otlpgrpc/connection.go | 278 -- .../otel/exporters/otlp/otlpgrpc/doc.go | 25 - .../otel/exporters/otlp/otlpgrpc/driver.go | 195 - .../otel/exporters/otlp/otlpgrpc/options.go | 202 - .../otel/exporters/otlp/protocoldriver.go | 145 - .../go.opentelemetry.io/otel/get_main_pkgs.sh | 41 - vendor/go.opentelemetry.io/otel/go.mod | 55 - vendor/go.opentelemetry.io/otel/go.sum | 15 - vendor/go.opentelemetry.io/otel/handler.go | 89 - .../otel/internal/baggage/baggage.go | 338 -- .../otel/internal/global/meter.go | 348 -- .../otel/internal/global/propagator.go | 82 - .../otel/internal/global/state.go | 143 - .../otel/internal/global/trace.go | 147 - .../otel/internal/metric/async.go | 148 - .../otel/internal/rawhelpers.go | 55 - .../otel/internal/trace/noop/noop.go | 35 - .../go.opentelemetry.io/otel/metric/LICENSE | 201 - .../go.opentelemetry.io/otel/metric/config.go | 128 - vendor/go.opentelemetry.io/otel/metric/doc.go | 67 - vendor/go.opentelemetry.io/otel/metric/go.mod | 54 - vendor/go.opentelemetry.io/otel/metric/go.sum | 15 - .../otel/metric/instrumentkind_string.go | 28 - .../go.opentelemetry.io/otel/metric/metric.go | 577 --- .../otel/metric/metric_instrument.go | 777 ---- .../otel/metric/metric_noop.go | 59 - .../otel/metric/metric_sdkapi.go | 95 - .../otel/metric/number/doc.go | 23 - .../otel/metric/number/kind_string.go | 24 - .../otel/metric/number/number.go | 538 --- .../otel/metric/registry/doc.go | 24 - .../otel/metric/registry/registry.go | 170 - .../go.opentelemetry.io/otel/pre_release.sh | 95 - .../go.opentelemetry.io/otel/propagation.go | 31 - .../otel/propagation/baggage.go | 111 - .../otel/propagation/doc.go | 28 - .../otel/propagation/propagation.go | 105 - .../otel/propagation/trace_context.go | 178 - vendor/go.opentelemetry.io/otel/sdk/LICENSE | 201 - .../otel/sdk/export/metric/LICENSE | 201 - .../export/metric/aggregation/aggregation.go | 154 - .../sdk/export/metric/exportkind_string.go | 25 - .../otel/sdk/export/metric/go.mod | 54 - .../otel/sdk/export/metric/go.sum | 15 - .../otel/sdk/export/metric/metric.go | 445 -- .../otel/sdk/instrumentation/library.go | 35 - .../otel/sdk/internal/internal.go | 37 - .../otel/sdk/internal/sanitize.go | 50 - .../otel/sdk/metric/LICENSE | 201 - .../otel/sdk/metric/aggregator/aggregator.go | 52 - .../otel/sdk/metric/aggregator/exact/exact.go | 130 - .../metric/aggregator/histogram/histogram.go | 270 -- .../metric/aggregator/lastvalue/lastvalue.go | 135 - .../metric/aggregator/minmaxsumcount/mmsc.go | 165 - .../otel/sdk/metric/aggregator/sum/sum.go | 106 - .../otel/sdk/metric/atomicfields.go | 24 - .../sdk/metric/controller/basic/config.go | 122 - .../sdk/metric/controller/basic/controller.go | 312 -- .../otel/sdk/metric/controller/time/time.go | 59 - .../otel/sdk/metric/doc.go | 141 - .../otel/sdk/metric/go.mod | 56 - .../otel/sdk/metric/go.sum | 17 - .../otel/sdk/metric/processor/basic/basic.go | 377 -- .../otel/sdk/metric/processor/basic/config.go | 42 - .../otel/sdk/metric/refcount_mapped.go | 59 - .../otel/sdk/metric/sdk.go | 555 --- .../otel/sdk/metric/selector/simple/simple.go | 120 - .../otel/sdk/resource/auto.go | 64 - .../otel/sdk/resource/builtin.go | 103 - .../otel/sdk/resource/config.go | 165 - .../otel/sdk/resource/doc.go | 32 - .../otel/sdk/resource/env.go | 72 - .../otel/sdk/resource/os.go | 39 - .../otel/sdk/resource/process.go | 237 -- .../otel/sdk/resource/resource.go | 196 - .../otel/sdk/trace/attributesmap.go | 91 - .../otel/sdk/trace/batch_span_processor.go | 328 -- .../otel/sdk/trace/config.go | 68 - .../go.opentelemetry.io/otel/sdk/trace/doc.go | 25 - .../otel/sdk/trace/evictedqueue.go | 38 - .../otel/sdk/trace/id_generator.go | 67 - .../otel/sdk/trace/provider.go | 324 -- .../otel/sdk/trace/sampling.go | 290 -- .../otel/sdk/trace/simple_span_processor.go | 80 - .../otel/sdk/trace/span.go | 617 --- .../otel/sdk/trace/span_exporter.go | 39 - .../otel/sdk/trace/span_processor.go | 56 - .../otel/sdk/trace/tracer.go | 75 - .../go.opentelemetry.io/otel/semconv/doc.go | 24 - .../otel/semconv/exception.go | 39 - .../go.opentelemetry.io/otel/semconv/http.go | 297 -- .../otel/semconv/resource.go | 257 -- .../go.opentelemetry.io/otel/semconv/trace.go | 376 -- vendor/go.opentelemetry.io/otel/tag.sh | 178 - vendor/go.opentelemetry.io/otel/trace.go | 44 - vendor/go.opentelemetry.io/otel/trace/LICENSE | 201 - .../go.opentelemetry.io/otel/trace/config.go | 205 - .../go.opentelemetry.io/otel/trace/context.go | 61 - vendor/go.opentelemetry.io/otel/trace/doc.go | 70 - vendor/go.opentelemetry.io/otel/trace/go.mod | 53 - vendor/go.opentelemetry.io/otel/trace/go.sum | 15 - .../otel/trace/nonrecording.go | 27 - vendor/go.opentelemetry.io/otel/trace/noop.go | 84 - .../go.opentelemetry.io/otel/trace/trace.go | 673 --- vendor/go.opentelemetry.io/otel/unit/doc.go | 20 - vendor/go.opentelemetry.io/otel/unit/unit.go | 23 - .../otel/verify_examples.sh | 85 - vendor/go.opentelemetry.io/otel/version.go | 20 - vendor/go.opentelemetry.io/proto/otlp/LICENSE | 201 - .../metrics/v1/metrics_service.pb.go | 255 -- .../metrics/v1/metrics_service.pb.gw.go | 169 - .../metrics/v1/metrics_service_grpc.pb.go | 101 - .../collector/trace/v1/trace_config.pb.go | 573 --- .../collector/trace/v1/trace_service.pb.go | 252 -- .../collector/trace/v1/trace_service.pb.gw.go | 169 - .../trace/v1/trace_service_grpc.pb.go | 101 - .../proto/otlp/common/v1/common.pb.go | 659 --- .../proto/otlp/metrics/v1/metrics.pb.go | 2469 ----------- .../proto/otlp/resource/v1/resource.pb.go | 194 - .../proto/otlp/trace/v1/trace.pb.go | 1206 ------ .../googleapis/api/httpbody/httpbody.pb.go | 232 - .../google.golang.org/grpc/health/client.go | 117 - .../google.golang.org/grpc/health/logging.go | 23 - .../google.golang.org/grpc/health/server.go | 163 - .../natefinch/lumberjack.v2/.gitignore | 23 - .../natefinch/lumberjack.v2/.travis.yml | 6 - .../gopkg.in/natefinch/lumberjack.v2/LICENSE | 21 - .../natefinch/lumberjack.v2/README.md | 179 - .../gopkg.in/natefinch/lumberjack.v2/chown.go | 11 - .../natefinch/lumberjack.v2/chown_linux.go | 19 - .../natefinch/lumberjack.v2/lumberjack.go | 541 --- vendor/modules.txt | 167 +- 756 files changed, 777 insertions(+), 124137 deletions(-) delete mode 100644 pkg/util/grpc/encoding/snappy/snappy_test.go delete mode 100644 pkg/util/grpc/healthcheck/health_check_test.go delete mode 100644 pkg/util/grpcclient/ratelimit_test.go rename pkg/util/{grpcutil => httpgrpcutil}/carrier.go (97%) delete mode 100644 pkg/util/tls/test/tls_integration_test.go delete mode 100644 pkg/util/tls/tls_test.go delete mode 100644 vendor/github.com/form3tech-oss/jwt-go/.gitignore delete mode 100644 vendor/github.com/form3tech-oss/jwt-go/.travis.yml delete mode 100644 vendor/github.com/form3tech-oss/jwt-go/LICENSE delete mode 100644 vendor/github.com/form3tech-oss/jwt-go/MIGRATION_GUIDE.md delete mode 100644 vendor/github.com/form3tech-oss/jwt-go/README.md delete mode 100644 vendor/github.com/form3tech-oss/jwt-go/VERSION_HISTORY.md delete mode 100644 vendor/github.com/form3tech-oss/jwt-go/claims.go delete mode 100644 vendor/github.com/form3tech-oss/jwt-go/doc.go delete mode 100644 vendor/github.com/form3tech-oss/jwt-go/ecdsa.go delete mode 100644 vendor/github.com/form3tech-oss/jwt-go/ecdsa_utils.go delete mode 100644 vendor/github.com/form3tech-oss/jwt-go/errors.go delete mode 100644 vendor/github.com/form3tech-oss/jwt-go/hmac.go delete mode 100644 vendor/github.com/form3tech-oss/jwt-go/map_claims.go delete mode 100644 vendor/github.com/form3tech-oss/jwt-go/none.go delete mode 100644 vendor/github.com/form3tech-oss/jwt-go/parser.go delete mode 100644 vendor/github.com/form3tech-oss/jwt-go/rsa.go delete mode 100644 vendor/github.com/form3tech-oss/jwt-go/rsa_pss.go delete mode 100644 vendor/github.com/form3tech-oss/jwt-go/rsa_utils.go delete mode 100644 vendor/github.com/form3tech-oss/jwt-go/signing_method.go delete mode 100644 vendor/github.com/form3tech-oss/jwt-go/token.go delete mode 100644 vendor/github.com/golang/protobuf/descriptor/descriptor.go delete mode 100644 vendor/github.com/golang/protobuf/jsonpb/decode.go delete mode 100644 vendor/github.com/golang/protobuf/jsonpb/encode.go delete mode 100644 vendor/github.com/golang/protobuf/jsonpb/json.go delete mode 100644 vendor/github.com/golang/protobuf/protoc-gen-go/descriptor/descriptor.pb.go delete mode 100644 vendor/github.com/gorilla/websocket/.gitignore delete mode 100644 vendor/github.com/gorilla/websocket/AUTHORS delete mode 100644 vendor/github.com/gorilla/websocket/LICENSE delete mode 100644 vendor/github.com/gorilla/websocket/README.md delete mode 100644 vendor/github.com/gorilla/websocket/client.go delete mode 100644 vendor/github.com/gorilla/websocket/client_clone.go delete mode 100644 vendor/github.com/gorilla/websocket/client_clone_legacy.go delete mode 100644 vendor/github.com/gorilla/websocket/compression.go delete mode 100644 vendor/github.com/gorilla/websocket/conn.go delete mode 100644 vendor/github.com/gorilla/websocket/conn_write.go delete mode 100644 vendor/github.com/gorilla/websocket/conn_write_legacy.go delete mode 100644 vendor/github.com/gorilla/websocket/doc.go delete mode 100644 vendor/github.com/gorilla/websocket/go.mod delete mode 100644 vendor/github.com/gorilla/websocket/go.sum delete mode 100644 vendor/github.com/gorilla/websocket/join.go delete mode 100644 vendor/github.com/gorilla/websocket/json.go delete mode 100644 vendor/github.com/gorilla/websocket/mask.go delete mode 100644 vendor/github.com/gorilla/websocket/mask_safe.go delete mode 100644 vendor/github.com/gorilla/websocket/prepared.go delete mode 100644 vendor/github.com/gorilla/websocket/proxy.go delete mode 100644 vendor/github.com/gorilla/websocket/server.go delete mode 100644 vendor/github.com/gorilla/websocket/trace.go delete mode 100644 vendor/github.com/gorilla/websocket/trace_17.go delete mode 100644 vendor/github.com/gorilla/websocket/util.go delete mode 100644 vendor/github.com/gorilla/websocket/x_net_proxy.go rename {pkg/util => vendor/github.com/grafana/dskit/crypto}/tls/tls.go (100%) rename {pkg/util => vendor/github.com/grafana/dskit}/grpcclient/backoff_retry.go (99%) rename {pkg/util => vendor/github.com/grafana/dskit}/grpcclient/grpcclient.go (91%) rename {pkg/util => vendor/github.com/grafana/dskit}/grpcclient/instrumentation.go (75%) rename {pkg/util => vendor/github.com/grafana/dskit}/grpcclient/ratelimit.go (100%) rename {pkg/util/grpc/encoding => vendor/github.com/grafana/dskit/grpcencoding}/snappy/snappy.go (100%) rename {pkg/util/grpc/naming => vendor/github.com/grafana/dskit/grpcutil}/dns_resolver.go (90%) rename {pkg/util/grpc/healthcheck => vendor/github.com/grafana/dskit/grpcutil}/health_check.go (87%) rename {pkg/util/grpc/naming => vendor/github.com/grafana/dskit/grpcutil}/naming.go (98%) rename {pkg/util/grpc => vendor/github.com/grafana/dskit/grpcutil}/util.go (95%) delete mode 100644 vendor/github.com/grafana/dskit/kv/kvtls/tls.go create mode 100644 vendor/github.com/grafana/dskit/middleware/grpc.go delete mode 100644 vendor/github.com/grpc-ecosystem/go-grpc-prometheus/.gitignore delete mode 100644 vendor/github.com/grpc-ecosystem/go-grpc-prometheus/.travis.yml delete mode 100644 vendor/github.com/grpc-ecosystem/go-grpc-prometheus/CHANGELOG.md delete mode 100644 vendor/github.com/grpc-ecosystem/go-grpc-prometheus/LICENSE delete mode 100644 vendor/github.com/grpc-ecosystem/go-grpc-prometheus/README.md delete mode 100644 vendor/github.com/grpc-ecosystem/go-grpc-prometheus/client.go delete mode 100644 vendor/github.com/grpc-ecosystem/go-grpc-prometheus/client_metrics.go delete mode 100644 vendor/github.com/grpc-ecosystem/go-grpc-prometheus/client_reporter.go delete mode 100644 vendor/github.com/grpc-ecosystem/go-grpc-prometheus/makefile delete mode 100644 vendor/github.com/grpc-ecosystem/go-grpc-prometheus/metric_options.go delete mode 100644 vendor/github.com/grpc-ecosystem/go-grpc-prometheus/server.go delete mode 100644 vendor/github.com/grpc-ecosystem/go-grpc-prometheus/server_metrics.go delete mode 100644 vendor/github.com/grpc-ecosystem/go-grpc-prometheus/server_reporter.go delete mode 100644 vendor/github.com/grpc-ecosystem/go-grpc-prometheus/util.go delete mode 100644 vendor/github.com/grpc-ecosystem/grpc-gateway/LICENSE.txt delete mode 100644 vendor/github.com/grpc-ecosystem/grpc-gateway/internal/BUILD.bazel delete mode 100644 vendor/github.com/grpc-ecosystem/grpc-gateway/internal/errors.pb.go delete mode 100644 vendor/github.com/grpc-ecosystem/grpc-gateway/internal/errors.proto delete mode 100644 vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/BUILD.bazel delete mode 100644 vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/context.go delete mode 100644 vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/convert.go delete mode 100644 vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/doc.go delete mode 100644 vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/errors.go delete mode 100644 vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/fieldmask.go delete mode 100644 vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/handler.go delete mode 100644 vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/marshal_httpbodyproto.go delete mode 100644 vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/marshal_json.go delete mode 100644 vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/marshal_jsonpb.go delete mode 100644 vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/marshal_proto.go delete mode 100644 vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/marshaler.go delete mode 100644 vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/marshaler_registry.go delete mode 100644 vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/mux.go delete mode 100644 vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/pattern.go delete mode 100644 vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/proto2_convert.go delete mode 100644 vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/proto_errors.go delete mode 100644 vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/query.go delete mode 100644 vendor/github.com/grpc-ecosystem/grpc-gateway/utilities/BUILD.bazel delete mode 100644 vendor/github.com/grpc-ecosystem/grpc-gateway/utilities/doc.go delete mode 100644 vendor/github.com/grpc-ecosystem/grpc-gateway/utilities/pattern.go delete mode 100644 vendor/github.com/grpc-ecosystem/grpc-gateway/utilities/readerfactory.go delete mode 100644 vendor/github.com/grpc-ecosystem/grpc-gateway/utilities/trie.go delete mode 100644 vendor/github.com/jonboulle/clockwork/.editorconfig delete mode 100644 vendor/github.com/jonboulle/clockwork/.gitignore delete mode 100644 vendor/github.com/jonboulle/clockwork/LICENSE delete mode 100644 vendor/github.com/jonboulle/clockwork/README.md delete mode 100644 vendor/github.com/jonboulle/clockwork/clockwork.go delete mode 100644 vendor/github.com/jonboulle/clockwork/go.mod delete mode 100644 vendor/github.com/jonboulle/clockwork/ticker.go delete mode 100644 vendor/github.com/soheilhy/cmux/.gitignore delete mode 100644 vendor/github.com/soheilhy/cmux/.travis.yml delete mode 100644 vendor/github.com/soheilhy/cmux/CONTRIBUTORS delete mode 100644 vendor/github.com/soheilhy/cmux/LICENSE delete mode 100644 vendor/github.com/soheilhy/cmux/README.md delete mode 100644 vendor/github.com/soheilhy/cmux/buffer.go delete mode 100644 vendor/github.com/soheilhy/cmux/cmux.go delete mode 100644 vendor/github.com/soheilhy/cmux/doc.go delete mode 100644 vendor/github.com/soheilhy/cmux/go.mod delete mode 100644 vendor/github.com/soheilhy/cmux/go.sum delete mode 100644 vendor/github.com/soheilhy/cmux/matchers.go delete mode 100644 vendor/github.com/soheilhy/cmux/patricia.go delete mode 100644 vendor/github.com/spf13/pflag/.gitignore delete mode 100644 vendor/github.com/spf13/pflag/.travis.yml delete mode 100644 vendor/github.com/spf13/pflag/LICENSE delete mode 100644 vendor/github.com/spf13/pflag/README.md delete mode 100644 vendor/github.com/spf13/pflag/bool.go delete mode 100644 vendor/github.com/spf13/pflag/bool_slice.go delete mode 100644 vendor/github.com/spf13/pflag/bytes.go delete mode 100644 vendor/github.com/spf13/pflag/count.go delete mode 100644 vendor/github.com/spf13/pflag/duration.go delete mode 100644 vendor/github.com/spf13/pflag/duration_slice.go delete mode 100644 vendor/github.com/spf13/pflag/flag.go delete mode 100644 vendor/github.com/spf13/pflag/float32.go delete mode 100644 vendor/github.com/spf13/pflag/float32_slice.go delete mode 100644 vendor/github.com/spf13/pflag/float64.go delete mode 100644 vendor/github.com/spf13/pflag/float64_slice.go delete mode 100644 vendor/github.com/spf13/pflag/go.mod delete mode 100644 vendor/github.com/spf13/pflag/go.sum delete mode 100644 vendor/github.com/spf13/pflag/golangflag.go delete mode 100644 vendor/github.com/spf13/pflag/int.go delete mode 100644 vendor/github.com/spf13/pflag/int16.go delete mode 100644 vendor/github.com/spf13/pflag/int32.go delete mode 100644 vendor/github.com/spf13/pflag/int32_slice.go delete mode 100644 vendor/github.com/spf13/pflag/int64.go delete mode 100644 vendor/github.com/spf13/pflag/int64_slice.go delete mode 100644 vendor/github.com/spf13/pflag/int8.go delete mode 100644 vendor/github.com/spf13/pflag/int_slice.go delete mode 100644 vendor/github.com/spf13/pflag/ip.go delete mode 100644 vendor/github.com/spf13/pflag/ip_slice.go delete mode 100644 vendor/github.com/spf13/pflag/ipmask.go delete mode 100644 vendor/github.com/spf13/pflag/ipnet.go delete mode 100644 vendor/github.com/spf13/pflag/string.go delete mode 100644 vendor/github.com/spf13/pflag/string_array.go delete mode 100644 vendor/github.com/spf13/pflag/string_slice.go delete mode 100644 vendor/github.com/spf13/pflag/string_to_int.go delete mode 100644 vendor/github.com/spf13/pflag/string_to_int64.go delete mode 100644 vendor/github.com/spf13/pflag/string_to_string.go delete mode 100644 vendor/github.com/spf13/pflag/uint.go delete mode 100644 vendor/github.com/spf13/pflag/uint16.go delete mode 100644 vendor/github.com/spf13/pflag/uint32.go delete mode 100644 vendor/github.com/spf13/pflag/uint64.go delete mode 100644 vendor/github.com/spf13/pflag/uint8.go delete mode 100644 vendor/github.com/spf13/pflag/uint_slice.go delete mode 100644 vendor/github.com/tmc/grpc-websocket-proxy/LICENSE delete mode 100644 vendor/github.com/tmc/grpc-websocket-proxy/wsproxy/doc.go delete mode 100644 vendor/github.com/tmc/grpc-websocket-proxy/wsproxy/websocket_proxy.go delete mode 100644 vendor/github.com/xiang90/probing/.gitignore delete mode 100644 vendor/github.com/xiang90/probing/LICENSE delete mode 100644 vendor/github.com/xiang90/probing/README.md delete mode 100644 vendor/github.com/xiang90/probing/prober.go delete mode 100644 vendor/github.com/xiang90/probing/server.go delete mode 100644 vendor/github.com/xiang90/probing/status.go delete mode 100644 vendor/go.etcd.io/etcd/api/v3/etcdserverpb/gw/rpc.pb.gw.go delete mode 100644 vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/dir_unix.go delete mode 100644 vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/dir_windows.go delete mode 100644 vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/doc.go delete mode 100644 vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/fileutil.go delete mode 100644 vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/lock.go delete mode 100644 vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/lock_flock.go delete mode 100644 vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/lock_linux.go delete mode 100644 vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/lock_plan9.go delete mode 100644 vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/lock_solaris.go delete mode 100644 vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/lock_unix.go delete mode 100644 vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/lock_windows.go delete mode 100644 vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/preallocate.go delete mode 100644 vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/preallocate_darwin.go delete mode 100644 vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/preallocate_unix.go delete mode 100644 vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/preallocate_unsupported.go delete mode 100644 vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/purge.go delete mode 100644 vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/read_dir.go delete mode 100644 vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/sync.go delete mode 100644 vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/sync_darwin.go delete mode 100644 vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/sync_linux.go delete mode 100644 vendor/go.etcd.io/etcd/client/pkg/v3/pathutil/path.go delete mode 100644 vendor/go.etcd.io/etcd/client/pkg/v3/srv/srv.go delete mode 100644 vendor/go.etcd.io/etcd/client/pkg/v3/tlsutil/cipher_suites.go delete mode 100644 vendor/go.etcd.io/etcd/client/pkg/v3/tlsutil/doc.go delete mode 100644 vendor/go.etcd.io/etcd/client/pkg/v3/tlsutil/tlsutil.go delete mode 100644 vendor/go.etcd.io/etcd/client/pkg/v3/transport/doc.go delete mode 100644 vendor/go.etcd.io/etcd/client/pkg/v3/transport/keepalive_listener.go delete mode 100644 vendor/go.etcd.io/etcd/client/pkg/v3/transport/limit_listen.go delete mode 100644 vendor/go.etcd.io/etcd/client/pkg/v3/transport/listener.go delete mode 100644 vendor/go.etcd.io/etcd/client/pkg/v3/transport/listener_opts.go delete mode 100644 vendor/go.etcd.io/etcd/client/pkg/v3/transport/listener_tls.go delete mode 100644 vendor/go.etcd.io/etcd/client/pkg/v3/transport/sockopt.go delete mode 100644 vendor/go.etcd.io/etcd/client/pkg/v3/transport/sockopt_unix.go delete mode 100644 vendor/go.etcd.io/etcd/client/pkg/v3/transport/sockopt_windows.go delete mode 100644 vendor/go.etcd.io/etcd/client/pkg/v3/transport/timeout_conn.go delete mode 100644 vendor/go.etcd.io/etcd/client/pkg/v3/transport/timeout_dialer.go delete mode 100644 vendor/go.etcd.io/etcd/client/pkg/v3/transport/timeout_listener.go delete mode 100644 vendor/go.etcd.io/etcd/client/pkg/v3/transport/timeout_transport.go delete mode 100644 vendor/go.etcd.io/etcd/client/pkg/v3/transport/tls.go delete mode 100644 vendor/go.etcd.io/etcd/client/pkg/v3/transport/transport.go delete mode 100644 vendor/go.etcd.io/etcd/client/pkg/v3/transport/unix_listener.go delete mode 100644 vendor/go.etcd.io/etcd/client/v2/LICENSE delete mode 100644 vendor/go.etcd.io/etcd/client/v2/README.md delete mode 100644 vendor/go.etcd.io/etcd/client/v2/auth_role.go delete mode 100644 vendor/go.etcd.io/etcd/client/v2/auth_user.go delete mode 100644 vendor/go.etcd.io/etcd/client/v2/cancelreq.go delete mode 100644 vendor/go.etcd.io/etcd/client/v2/client.go delete mode 100644 vendor/go.etcd.io/etcd/client/v2/cluster_error.go delete mode 100644 vendor/go.etcd.io/etcd/client/v2/curl.go delete mode 100644 vendor/go.etcd.io/etcd/client/v2/discover.go delete mode 100644 vendor/go.etcd.io/etcd/client/v2/doc.go delete mode 100644 vendor/go.etcd.io/etcd/client/v2/go.mod delete mode 100644 vendor/go.etcd.io/etcd/client/v2/go.sum delete mode 100644 vendor/go.etcd.io/etcd/client/v2/json.go delete mode 100644 vendor/go.etcd.io/etcd/client/v2/keys.go delete mode 100644 vendor/go.etcd.io/etcd/client/v2/members.go delete mode 100644 vendor/go.etcd.io/etcd/client/v2/util.go delete mode 100644 vendor/go.etcd.io/etcd/client/v3/concurrency/doc.go delete mode 100644 vendor/go.etcd.io/etcd/client/v3/concurrency/election.go delete mode 100644 vendor/go.etcd.io/etcd/client/v3/concurrency/key.go delete mode 100644 vendor/go.etcd.io/etcd/client/v3/concurrency/mutex.go delete mode 100644 vendor/go.etcd.io/etcd/client/v3/concurrency/session.go delete mode 100644 vendor/go.etcd.io/etcd/client/v3/concurrency/stm.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/v3/LICENSE delete mode 100644 vendor/go.etcd.io/etcd/pkg/v3/adt/README.md delete mode 100644 vendor/go.etcd.io/etcd/pkg/v3/adt/adt.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/v3/adt/interval_tree.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/v3/contention/contention.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/v3/contention/doc.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/v3/cpuutil/doc.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/v3/cpuutil/endian.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/v3/crc/crc.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/v3/debugutil/doc.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/v3/debugutil/pprof.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/v3/flags/flag.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/v3/flags/ignored.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/v3/flags/selective_string.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/v3/flags/strings.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/v3/flags/unique_strings.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/v3/flags/unique_urls.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/v3/flags/urls.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/v3/httputil/httputil.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/v3/idutil/id.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/v3/ioutil/pagewriter.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/v3/ioutil/readcloser.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/v3/ioutil/reader.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/v3/ioutil/util.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/v3/netutil/doc.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/v3/netutil/netutil.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/v3/netutil/routes.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/v3/netutil/routes_linux.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/v3/pbutil/pbutil.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/v3/runtime/fds_linux.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/v3/runtime/fds_other.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/v3/schedule/doc.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/v3/schedule/schedule.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/v3/traceutil/trace.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/v3/wait/wait.go delete mode 100644 vendor/go.etcd.io/etcd/pkg/v3/wait/wait_time.go delete mode 100644 vendor/go.etcd.io/etcd/raft/v3/LICENSE delete mode 100644 vendor/go.etcd.io/etcd/raft/v3/OWNERS delete mode 100644 vendor/go.etcd.io/etcd/raft/v3/README.md delete mode 100644 vendor/go.etcd.io/etcd/raft/v3/bootstrap.go delete mode 100644 vendor/go.etcd.io/etcd/raft/v3/confchange/confchange.go delete mode 100644 vendor/go.etcd.io/etcd/raft/v3/confchange/restore.go delete mode 100644 vendor/go.etcd.io/etcd/raft/v3/design.md delete mode 100644 vendor/go.etcd.io/etcd/raft/v3/doc.go delete mode 100644 vendor/go.etcd.io/etcd/raft/v3/go.mod delete mode 100644 vendor/go.etcd.io/etcd/raft/v3/go.sum delete mode 100644 vendor/go.etcd.io/etcd/raft/v3/log.go delete mode 100644 vendor/go.etcd.io/etcd/raft/v3/log_unstable.go delete mode 100644 vendor/go.etcd.io/etcd/raft/v3/logger.go delete mode 100644 vendor/go.etcd.io/etcd/raft/v3/node.go delete mode 100644 vendor/go.etcd.io/etcd/raft/v3/quorum/joint.go delete mode 100644 vendor/go.etcd.io/etcd/raft/v3/quorum/majority.go delete mode 100644 vendor/go.etcd.io/etcd/raft/v3/quorum/quorum.go delete mode 100644 vendor/go.etcd.io/etcd/raft/v3/quorum/voteresult_string.go delete mode 100644 vendor/go.etcd.io/etcd/raft/v3/raft.go delete mode 100644 vendor/go.etcd.io/etcd/raft/v3/raftpb/confchange.go delete mode 100644 vendor/go.etcd.io/etcd/raft/v3/raftpb/confstate.go delete mode 100644 vendor/go.etcd.io/etcd/raft/v3/raftpb/raft.pb.go delete mode 100644 vendor/go.etcd.io/etcd/raft/v3/raftpb/raft.proto delete mode 100644 vendor/go.etcd.io/etcd/raft/v3/rawnode.go delete mode 100644 vendor/go.etcd.io/etcd/raft/v3/read_only.go delete mode 100644 vendor/go.etcd.io/etcd/raft/v3/status.go delete mode 100644 vendor/go.etcd.io/etcd/raft/v3/storage.go delete mode 100644 vendor/go.etcd.io/etcd/raft/v3/tracker/inflights.go delete mode 100644 vendor/go.etcd.io/etcd/raft/v3/tracker/progress.go delete mode 100644 vendor/go.etcd.io/etcd/raft/v3/tracker/state.go delete mode 100644 vendor/go.etcd.io/etcd/raft/v3/tracker/tracker.go delete mode 100644 vendor/go.etcd.io/etcd/raft/v3/util.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/LICENSE delete mode 100644 vendor/go.etcd.io/etcd/server/v3/auth/doc.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/auth/jwt.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/auth/metrics.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/auth/nop.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/auth/options.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/auth/range_perm_cache.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/auth/simple_token.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/auth/store.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/config/config.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/config/v2_deprecation.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/datadir/datadir.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/datadir/doc.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/embed/config.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/embed/config_logging.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/embed/config_logging_journal_unix.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/embed/config_logging_journal_windows.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/embed/doc.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/embed/etcd.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/embed/serve.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/embed/util.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/api/capability.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/api/cluster.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/api/doc.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/api/etcdhttp/base.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/api/etcdhttp/doc.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/api/etcdhttp/metrics.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/api/etcdhttp/peer.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/api/membership/cluster.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/api/membership/confstate.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/api/membership/doc.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/api/membership/downgrade.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/api/membership/errors.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/api/membership/member.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/api/membership/metrics.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/api/membership/store.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/api/membership/storev2.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp/coder.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp/doc.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp/http.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp/metrics.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp/msg_codec.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp/msgappv2_codec.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp/peer.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp/peer_status.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp/pipeline.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp/probing_status.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp/remote.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp/snapshot_sender.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp/stream.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp/transport.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp/urlpick.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp/util.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/api/snap/db.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/api/snap/doc.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/api/snap/message.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/api/snap/metrics.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/api/snap/snappb/snap.pb.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/api/snap/snappb/snap.proto delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/api/snap/snapshotter.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2auth/auth.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2auth/auth_requests.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2discovery/discovery.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2error/error.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2http/capability.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2http/client.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2http/client_auth.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2http/doc.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2http/http.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2http/httptypes/errors.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2http/httptypes/member.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2http/metrics.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2stats/leader.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2stats/queue.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2stats/server.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2stats/stats.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2store/doc.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2store/event.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2store/event_history.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2store/event_queue.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2store/metrics.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2store/node.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2store/node_extern.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2store/stats.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2store/store.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2store/ttl_key_heap.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2store/watcher.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2store/watcher_hub.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2v3/cluster.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2v3/doc.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2v3/server.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2v3/store.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2v3/watcher.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3alarm/alarms.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3client/doc.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3client/v3client.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3compactor/compactor.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3compactor/doc.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3compactor/periodic.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3compactor/revision.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3election/doc.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3election/election.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3election/v3electionpb/gw/v3election.pb.gw.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3election/v3electionpb/v3election.pb.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3election/v3electionpb/v3election.proto delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3lock/doc.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3lock/lock.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3lock/v3lockpb/gw/v3lock.pb.gw.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3lock/v3lockpb/v3lock.pb.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3lock/v3lockpb/v3lock.proto delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3rpc/auth.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3rpc/codec.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3rpc/grpc.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3rpc/header.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3rpc/interceptor.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3rpc/key.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3rpc/lease.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3rpc/maintenance.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3rpc/member.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3rpc/metrics.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3rpc/quota.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3rpc/util.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3rpc/watch.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/apply.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/apply_auth.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/apply_v2.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/backend.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/cindex/cindex.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/cindex/doc.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/cluster_util.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/corrupt.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/doc.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/errors.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/metrics.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/quota.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/raft.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/server.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/server_access_control.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/snapshot_merge.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/storage.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/util.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/v2_server.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/v3_server.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/etcdserver/zap_raft.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/lease/doc.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/lease/lease_queue.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/lease/leasehttp/doc.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/lease/leasehttp/http.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/lease/leasepb/lease.pb.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/lease/leasepb/lease.proto delete mode 100644 vendor/go.etcd.io/etcd/server/v3/lease/lessor.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/lease/metrics.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/mvcc/backend/backend.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/mvcc/backend/batch_tx.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/mvcc/backend/config_default.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/mvcc/backend/config_linux.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/mvcc/backend/config_windows.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/mvcc/backend/doc.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/mvcc/backend/hooks.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/mvcc/backend/metrics.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/mvcc/backend/read_tx.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/mvcc/backend/tx_buffer.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/mvcc/buckets/bucket.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/mvcc/doc.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/mvcc/index.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/mvcc/key_index.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/mvcc/kv.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/mvcc/kv_view.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/mvcc/kvstore.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/mvcc/kvstore_compaction.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/mvcc/kvstore_txn.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/mvcc/metrics.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/mvcc/metrics_txn.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/mvcc/revision.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/mvcc/util.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/mvcc/watchable_store.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/mvcc/watchable_store_txn.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/mvcc/watcher.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/mvcc/watcher_group.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/proxy/grpcproxy/adapter/auth_client_adapter.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/proxy/grpcproxy/adapter/chan_stream.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/proxy/grpcproxy/adapter/cluster_client_adapter.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/proxy/grpcproxy/adapter/doc.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/proxy/grpcproxy/adapter/election_client_adapter.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/proxy/grpcproxy/adapter/kv_client_adapter.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/proxy/grpcproxy/adapter/lease_client_adapter.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/proxy/grpcproxy/adapter/lock_client_adapter.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/proxy/grpcproxy/adapter/maintenance_client_adapter.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/proxy/grpcproxy/adapter/watch_client_adapter.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/verify/doc.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/verify/verify.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/wal/decoder.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/wal/doc.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/wal/encoder.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/wal/file_pipeline.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/wal/metrics.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/wal/repair.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/wal/util.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/wal/wal.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/wal/walpb/record.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/wal/walpb/record.pb.go delete mode 100644 vendor/go.etcd.io/etcd/server/v3/wal/walpb/record.proto delete mode 100644 vendor/go.opentelemetry.io/contrib/.gitignore delete mode 100644 vendor/go.opentelemetry.io/contrib/.golangci.yml delete mode 100644 vendor/go.opentelemetry.io/contrib/CHANGELOG.md delete mode 100644 vendor/go.opentelemetry.io/contrib/CODEOWNERS delete mode 100644 vendor/go.opentelemetry.io/contrib/CONTRIBUTING.md delete mode 100644 vendor/go.opentelemetry.io/contrib/LICENSE delete mode 100644 vendor/go.opentelemetry.io/contrib/Makefile delete mode 100644 vendor/go.opentelemetry.io/contrib/README.md delete mode 100644 vendor/go.opentelemetry.io/contrib/RELEASING.md delete mode 100644 vendor/go.opentelemetry.io/contrib/contrib.go delete mode 100644 vendor/go.opentelemetry.io/contrib/doc.go delete mode 100644 vendor/go.opentelemetry.io/contrib/go.mod delete mode 100644 vendor/go.opentelemetry.io/contrib/go.sum delete mode 100644 vendor/go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc/LICENSE delete mode 100644 vendor/go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc/go.mod delete mode 100644 vendor/go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc/go.sum delete mode 100644 vendor/go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc/grpctrace.go delete mode 100644 vendor/go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc/interceptor.go delete mode 100644 vendor/go.opentelemetry.io/contrib/pre_release.sh delete mode 100644 vendor/go.opentelemetry.io/contrib/tag.sh delete mode 100644 vendor/go.opentelemetry.io/otel/.gitignore delete mode 100644 vendor/go.opentelemetry.io/otel/.gitmodules delete mode 100644 vendor/go.opentelemetry.io/otel/.golangci.yml delete mode 100644 vendor/go.opentelemetry.io/otel/CHANGELOG.md delete mode 100644 vendor/go.opentelemetry.io/otel/CODEOWNERS delete mode 100644 vendor/go.opentelemetry.io/otel/CONTRIBUTING.md delete mode 100644 vendor/go.opentelemetry.io/otel/LICENSE delete mode 100644 vendor/go.opentelemetry.io/otel/Makefile delete mode 100644 vendor/go.opentelemetry.io/otel/README.md delete mode 100644 vendor/go.opentelemetry.io/otel/RELEASING.md delete mode 100644 vendor/go.opentelemetry.io/otel/VERSIONING.md delete mode 100644 vendor/go.opentelemetry.io/otel/attribute/doc.go delete mode 100644 vendor/go.opentelemetry.io/otel/attribute/encoder.go delete mode 100644 vendor/go.opentelemetry.io/otel/attribute/iterator.go delete mode 100644 vendor/go.opentelemetry.io/otel/attribute/key.go delete mode 100644 vendor/go.opentelemetry.io/otel/attribute/kv.go delete mode 100644 vendor/go.opentelemetry.io/otel/attribute/set.go delete mode 100644 vendor/go.opentelemetry.io/otel/attribute/type_string.go delete mode 100644 vendor/go.opentelemetry.io/otel/attribute/value.go delete mode 100644 vendor/go.opentelemetry.io/otel/baggage/baggage.go delete mode 100644 vendor/go.opentelemetry.io/otel/baggage/doc.go delete mode 100644 vendor/go.opentelemetry.io/otel/codes/codes.go delete mode 100644 vendor/go.opentelemetry.io/otel/codes/doc.go delete mode 100644 vendor/go.opentelemetry.io/otel/doc.go delete mode 100644 vendor/go.opentelemetry.io/otel/error_handler.go delete mode 100644 vendor/go.opentelemetry.io/otel/exporters/otlp/LICENSE delete mode 100644 vendor/go.opentelemetry.io/otel/exporters/otlp/README.md delete mode 100644 vendor/go.opentelemetry.io/otel/exporters/otlp/doc.go delete mode 100644 vendor/go.opentelemetry.io/otel/exporters/otlp/go.mod delete mode 100644 vendor/go.opentelemetry.io/otel/exporters/otlp/go.sum delete mode 100644 vendor/go.opentelemetry.io/otel/exporters/otlp/internal/otlpconfig/envconfig.go delete mode 100644 vendor/go.opentelemetry.io/otel/exporters/otlp/internal/otlpconfig/options.go delete mode 100644 vendor/go.opentelemetry.io/otel/exporters/otlp/internal/otlpconfig/tls.go delete mode 100644 vendor/go.opentelemetry.io/otel/exporters/otlp/internal/transform/attribute.go delete mode 100644 vendor/go.opentelemetry.io/otel/exporters/otlp/internal/transform/instrumentation.go delete mode 100644 vendor/go.opentelemetry.io/otel/exporters/otlp/internal/transform/metric.go delete mode 100644 vendor/go.opentelemetry.io/otel/exporters/otlp/internal/transform/resource.go delete mode 100644 vendor/go.opentelemetry.io/otel/exporters/otlp/internal/transform/span.go delete mode 100644 vendor/go.opentelemetry.io/otel/exporters/otlp/options.go delete mode 100644 vendor/go.opentelemetry.io/otel/exporters/otlp/optiontypes.go delete mode 100644 vendor/go.opentelemetry.io/otel/exporters/otlp/otlp.go delete mode 100644 vendor/go.opentelemetry.io/otel/exporters/otlp/otlpgrpc/connection.go delete mode 100644 vendor/go.opentelemetry.io/otel/exporters/otlp/otlpgrpc/doc.go delete mode 100644 vendor/go.opentelemetry.io/otel/exporters/otlp/otlpgrpc/driver.go delete mode 100644 vendor/go.opentelemetry.io/otel/exporters/otlp/otlpgrpc/options.go delete mode 100644 vendor/go.opentelemetry.io/otel/exporters/otlp/protocoldriver.go delete mode 100644 vendor/go.opentelemetry.io/otel/get_main_pkgs.sh delete mode 100644 vendor/go.opentelemetry.io/otel/go.mod delete mode 100644 vendor/go.opentelemetry.io/otel/go.sum delete mode 100644 vendor/go.opentelemetry.io/otel/handler.go delete mode 100644 vendor/go.opentelemetry.io/otel/internal/baggage/baggage.go delete mode 100644 vendor/go.opentelemetry.io/otel/internal/global/meter.go delete mode 100644 vendor/go.opentelemetry.io/otel/internal/global/propagator.go delete mode 100644 vendor/go.opentelemetry.io/otel/internal/global/state.go delete mode 100644 vendor/go.opentelemetry.io/otel/internal/global/trace.go delete mode 100644 vendor/go.opentelemetry.io/otel/internal/metric/async.go delete mode 100644 vendor/go.opentelemetry.io/otel/internal/rawhelpers.go delete mode 100644 vendor/go.opentelemetry.io/otel/internal/trace/noop/noop.go delete mode 100644 vendor/go.opentelemetry.io/otel/metric/LICENSE delete mode 100644 vendor/go.opentelemetry.io/otel/metric/config.go delete mode 100644 vendor/go.opentelemetry.io/otel/metric/doc.go delete mode 100644 vendor/go.opentelemetry.io/otel/metric/go.mod delete mode 100644 vendor/go.opentelemetry.io/otel/metric/go.sum delete mode 100644 vendor/go.opentelemetry.io/otel/metric/instrumentkind_string.go delete mode 100644 vendor/go.opentelemetry.io/otel/metric/metric.go delete mode 100644 vendor/go.opentelemetry.io/otel/metric/metric_instrument.go delete mode 100644 vendor/go.opentelemetry.io/otel/metric/metric_noop.go delete mode 100644 vendor/go.opentelemetry.io/otel/metric/metric_sdkapi.go delete mode 100644 vendor/go.opentelemetry.io/otel/metric/number/doc.go delete mode 100644 vendor/go.opentelemetry.io/otel/metric/number/kind_string.go delete mode 100644 vendor/go.opentelemetry.io/otel/metric/number/number.go delete mode 100644 vendor/go.opentelemetry.io/otel/metric/registry/doc.go delete mode 100644 vendor/go.opentelemetry.io/otel/metric/registry/registry.go delete mode 100644 vendor/go.opentelemetry.io/otel/pre_release.sh delete mode 100644 vendor/go.opentelemetry.io/otel/propagation.go delete mode 100644 vendor/go.opentelemetry.io/otel/propagation/baggage.go delete mode 100644 vendor/go.opentelemetry.io/otel/propagation/doc.go delete mode 100644 vendor/go.opentelemetry.io/otel/propagation/propagation.go delete mode 100644 vendor/go.opentelemetry.io/otel/propagation/trace_context.go delete mode 100644 vendor/go.opentelemetry.io/otel/sdk/LICENSE delete mode 100644 vendor/go.opentelemetry.io/otel/sdk/export/metric/LICENSE delete mode 100644 vendor/go.opentelemetry.io/otel/sdk/export/metric/aggregation/aggregation.go delete mode 100644 vendor/go.opentelemetry.io/otel/sdk/export/metric/exportkind_string.go delete mode 100644 vendor/go.opentelemetry.io/otel/sdk/export/metric/go.mod delete mode 100644 vendor/go.opentelemetry.io/otel/sdk/export/metric/go.sum delete mode 100644 vendor/go.opentelemetry.io/otel/sdk/export/metric/metric.go delete mode 100644 vendor/go.opentelemetry.io/otel/sdk/instrumentation/library.go delete mode 100644 vendor/go.opentelemetry.io/otel/sdk/internal/internal.go delete mode 100644 vendor/go.opentelemetry.io/otel/sdk/internal/sanitize.go delete mode 100644 vendor/go.opentelemetry.io/otel/sdk/metric/LICENSE delete mode 100644 vendor/go.opentelemetry.io/otel/sdk/metric/aggregator/aggregator.go delete mode 100644 vendor/go.opentelemetry.io/otel/sdk/metric/aggregator/exact/exact.go delete mode 100644 vendor/go.opentelemetry.io/otel/sdk/metric/aggregator/histogram/histogram.go delete mode 100644 vendor/go.opentelemetry.io/otel/sdk/metric/aggregator/lastvalue/lastvalue.go delete mode 100644 vendor/go.opentelemetry.io/otel/sdk/metric/aggregator/minmaxsumcount/mmsc.go delete mode 100644 vendor/go.opentelemetry.io/otel/sdk/metric/aggregator/sum/sum.go delete mode 100644 vendor/go.opentelemetry.io/otel/sdk/metric/atomicfields.go delete mode 100644 vendor/go.opentelemetry.io/otel/sdk/metric/controller/basic/config.go delete mode 100644 vendor/go.opentelemetry.io/otel/sdk/metric/controller/basic/controller.go delete mode 100644 vendor/go.opentelemetry.io/otel/sdk/metric/controller/time/time.go delete mode 100644 vendor/go.opentelemetry.io/otel/sdk/metric/doc.go delete mode 100644 vendor/go.opentelemetry.io/otel/sdk/metric/go.mod delete mode 100644 vendor/go.opentelemetry.io/otel/sdk/metric/go.sum delete mode 100644 vendor/go.opentelemetry.io/otel/sdk/metric/processor/basic/basic.go delete mode 100644 vendor/go.opentelemetry.io/otel/sdk/metric/processor/basic/config.go delete mode 100644 vendor/go.opentelemetry.io/otel/sdk/metric/refcount_mapped.go delete mode 100644 vendor/go.opentelemetry.io/otel/sdk/metric/sdk.go delete mode 100644 vendor/go.opentelemetry.io/otel/sdk/metric/selector/simple/simple.go delete mode 100644 vendor/go.opentelemetry.io/otel/sdk/resource/auto.go delete mode 100644 vendor/go.opentelemetry.io/otel/sdk/resource/builtin.go delete mode 100644 vendor/go.opentelemetry.io/otel/sdk/resource/config.go delete mode 100644 vendor/go.opentelemetry.io/otel/sdk/resource/doc.go delete mode 100644 vendor/go.opentelemetry.io/otel/sdk/resource/env.go delete mode 100644 vendor/go.opentelemetry.io/otel/sdk/resource/os.go delete mode 100644 vendor/go.opentelemetry.io/otel/sdk/resource/process.go delete mode 100644 vendor/go.opentelemetry.io/otel/sdk/resource/resource.go delete mode 100644 vendor/go.opentelemetry.io/otel/sdk/trace/attributesmap.go delete mode 100644 vendor/go.opentelemetry.io/otel/sdk/trace/batch_span_processor.go delete mode 100644 vendor/go.opentelemetry.io/otel/sdk/trace/config.go delete mode 100644 vendor/go.opentelemetry.io/otel/sdk/trace/doc.go delete mode 100644 vendor/go.opentelemetry.io/otel/sdk/trace/evictedqueue.go delete mode 100644 vendor/go.opentelemetry.io/otel/sdk/trace/id_generator.go delete mode 100644 vendor/go.opentelemetry.io/otel/sdk/trace/provider.go delete mode 100644 vendor/go.opentelemetry.io/otel/sdk/trace/sampling.go delete mode 100644 vendor/go.opentelemetry.io/otel/sdk/trace/simple_span_processor.go delete mode 100644 vendor/go.opentelemetry.io/otel/sdk/trace/span.go delete mode 100644 vendor/go.opentelemetry.io/otel/sdk/trace/span_exporter.go delete mode 100644 vendor/go.opentelemetry.io/otel/sdk/trace/span_processor.go delete mode 100644 vendor/go.opentelemetry.io/otel/sdk/trace/tracer.go delete mode 100644 vendor/go.opentelemetry.io/otel/semconv/doc.go delete mode 100644 vendor/go.opentelemetry.io/otel/semconv/exception.go delete mode 100644 vendor/go.opentelemetry.io/otel/semconv/http.go delete mode 100644 vendor/go.opentelemetry.io/otel/semconv/resource.go delete mode 100644 vendor/go.opentelemetry.io/otel/semconv/trace.go delete mode 100644 vendor/go.opentelemetry.io/otel/tag.sh delete mode 100644 vendor/go.opentelemetry.io/otel/trace.go delete mode 100644 vendor/go.opentelemetry.io/otel/trace/LICENSE delete mode 100644 vendor/go.opentelemetry.io/otel/trace/config.go delete mode 100644 vendor/go.opentelemetry.io/otel/trace/context.go delete mode 100644 vendor/go.opentelemetry.io/otel/trace/doc.go delete mode 100644 vendor/go.opentelemetry.io/otel/trace/go.mod delete mode 100644 vendor/go.opentelemetry.io/otel/trace/go.sum delete mode 100644 vendor/go.opentelemetry.io/otel/trace/nonrecording.go delete mode 100644 vendor/go.opentelemetry.io/otel/trace/noop.go delete mode 100644 vendor/go.opentelemetry.io/otel/trace/trace.go delete mode 100644 vendor/go.opentelemetry.io/otel/unit/doc.go delete mode 100644 vendor/go.opentelemetry.io/otel/unit/unit.go delete mode 100644 vendor/go.opentelemetry.io/otel/verify_examples.sh delete mode 100644 vendor/go.opentelemetry.io/otel/version.go delete mode 100644 vendor/go.opentelemetry.io/proto/otlp/LICENSE delete mode 100644 vendor/go.opentelemetry.io/proto/otlp/collector/metrics/v1/metrics_service.pb.go delete mode 100644 vendor/go.opentelemetry.io/proto/otlp/collector/metrics/v1/metrics_service.pb.gw.go delete mode 100644 vendor/go.opentelemetry.io/proto/otlp/collector/metrics/v1/metrics_service_grpc.pb.go delete mode 100644 vendor/go.opentelemetry.io/proto/otlp/collector/trace/v1/trace_config.pb.go delete mode 100644 vendor/go.opentelemetry.io/proto/otlp/collector/trace/v1/trace_service.pb.go delete mode 100644 vendor/go.opentelemetry.io/proto/otlp/collector/trace/v1/trace_service.pb.gw.go delete mode 100644 vendor/go.opentelemetry.io/proto/otlp/collector/trace/v1/trace_service_grpc.pb.go delete mode 100644 vendor/go.opentelemetry.io/proto/otlp/common/v1/common.pb.go delete mode 100644 vendor/go.opentelemetry.io/proto/otlp/metrics/v1/metrics.pb.go delete mode 100644 vendor/go.opentelemetry.io/proto/otlp/resource/v1/resource.pb.go delete mode 100644 vendor/go.opentelemetry.io/proto/otlp/trace/v1/trace.pb.go delete mode 100644 vendor/google.golang.org/genproto/googleapis/api/httpbody/httpbody.pb.go delete mode 100644 vendor/google.golang.org/grpc/health/client.go delete mode 100644 vendor/google.golang.org/grpc/health/logging.go delete mode 100644 vendor/google.golang.org/grpc/health/server.go delete mode 100644 vendor/gopkg.in/natefinch/lumberjack.v2/.gitignore delete mode 100644 vendor/gopkg.in/natefinch/lumberjack.v2/.travis.yml delete mode 100644 vendor/gopkg.in/natefinch/lumberjack.v2/LICENSE delete mode 100644 vendor/gopkg.in/natefinch/lumberjack.v2/README.md delete mode 100644 vendor/gopkg.in/natefinch/lumberjack.v2/chown.go delete mode 100644 vendor/gopkg.in/natefinch/lumberjack.v2/chown_linux.go delete mode 100644 vendor/gopkg.in/natefinch/lumberjack.v2/lumberjack.go diff --git a/docs/configuration/config-file-reference.md b/docs/configuration/config-file-reference.md index 43d605c31a..e7b1afa5f6 100644 --- a/docs/configuration/config-file-reference.md +++ b/docs/configuration/config-file-reference.md @@ -3809,6 +3809,16 @@ The `memberlist_config` configures the Gossip memberlist. # CLI flag: -memberlist.compression-enabled [compression_enabled: | default = true] +# Gossip address to advertise to other members in the cluster. Used for NAT +# traversal. +# CLI flag: -memberlist.advertise-addr +[advertise_addr: | default = ""] + +# Gossip port to advertise to other members in the cluster. Used for NAT +# traversal. +# CLI flag: -memberlist.advertise-port +[advertise_port: | default = 7946] + # Other cluster members to join. Can be specified multiple times. It can be an # IP, hostname or an entry specified in the DNS Service Discovery format. # CLI flag: -memberlist.join diff --git a/go.mod b/go.mod index 3bf4fdb16a..a0e3a3ea6b 100644 --- a/go.mod +++ b/go.mod @@ -29,8 +29,7 @@ require ( github.com/golang/protobuf v1.5.2 github.com/golang/snappy v0.0.4 github.com/gorilla/mux v1.8.0 - github.com/grafana/dskit v0.0.0-20210908150159-fcf48cb19aa4 - github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 + github.com/grafana/dskit v0.0.0-20211007183133-4c566019f311 github.com/json-iterator/go v1.1.11 github.com/lib/pq v1.3.0 github.com/minio/minio-go/v7 v7.0.10 @@ -52,7 +51,7 @@ require ( github.com/stretchr/testify v1.7.0 github.com/thanos-io/thanos v0.22.0 github.com/uber/jaeger-client-go v2.29.1+incompatible - github.com/weaveworks/common v0.0.0-20210901124008-1fa3f9fa874c + github.com/weaveworks/common v0.0.0-20210913144402-035033b78a78 go.etcd.io/bbolt v1.3.6 go.uber.org/atomic v1.9.0 golang.org/x/net v0.0.0-20210903162142-ad29c8ab022f diff --git a/go.sum b/go.sum index 2f9c6d814a..fb30c39ea2 100644 --- a/go.sum +++ b/go.sum @@ -147,7 +147,6 @@ github.com/Azure/go-autorest/logger v0.2.1/go.mod h1:T9E3cAhj2VqvPOtCYAvby9aBXkZ github.com/Azure/go-autorest/tracing v0.5.0/go.mod h1:r/s2XiOKccPW3HrqB+W0TQzfbtp2fGCgRFtBroKn4Dk= github.com/Azure/go-autorest/tracing v0.6.0 h1:TYi4+3m5t6K48TGI9AUdb+IzbnSxvnvUMfuitfgcfuo= github.com/Azure/go-autorest/tracing v0.6.0/go.mod h1:+vhtPC754Xsa23ID7GlGsrdKBpUA79WCAKPPZVC2DeU= -github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/DATA-DOG/go-sqlmock v1.3.3/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM= @@ -281,7 +280,6 @@ github.com/baidubce/bce-sdk-go v0.9.81 h1:n8KfThLG9fvGv3A+RtTt/jKhg/FPPRpo+iNnS2 github.com/baidubce/bce-sdk-go v0.9.81/go.mod h1:zbYJMQwE4IZuyrJiFO8tO8NbtYiKTFTbwh4eIsqjVdg= github.com/baiyubin/aliyun-sts-go-sdk v0.0.0-20180326062324-cfa1a18b161f/go.mod h1:AuiFmCCPBSrqvVMvuqFuk0qogytodnVFVSN5CeJB8Gc= github.com/beevik/ntp v0.2.0/go.mod h1:hIHWr+l3+/clUnF44zdK+CWW7fO8dR5cIylAQ76NRpg= -github.com/benbjohnson/clock v1.0.3 h1:vkLuvpK4fmtSCuo60+yC63p7y0BmQ8gm5ZXGuBCJyXg= github.com/benbjohnson/clock v1.0.3/go.mod h1:bGMdMPoPVvcYyt1gHDf4J2KE153Yf9BuiUKYMaxlTDM= github.com/benbjohnson/immutable v0.2.1/go.mod h1:uc6OHo6PN2++n98KHLxW8ef4W42ylHiQSENghE1ezxI= github.com/benbjohnson/tmpl v1.0.0/go.mod h1:igT620JFIi44B6awvU9IsDhR77IXWtFigTLil/RPdps= @@ -325,7 +323,6 @@ github.com/cenkalti/backoff/v4 v4.1.1 h1:G2HAfAmvm/GcKan2oOQpBXOd2tT2G57ZnZGWa1P github.com/cenkalti/backoff/v4 v4.1.1/go.mod h1:scbssz8iZGpm3xbr14ovlUdkxfGXNInqkPWOWmG2CLw= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/certifi/gocertifi v0.0.0-20191021191039-0944d244cd40/go.mod h1:sGbDF6GwGcLpkNXPUTkMRoywsNa/ol15pxFe6ERfguA= -github.com/certifi/gocertifi v0.0.0-20200922220541-2c3bb06c6054 h1:uH66TXeswKn5PW5zdZ39xEwfS9an067BirqA+P4QaLI= github.com/certifi/gocertifi v0.0.0-20200922220541-2c3bb06c6054/go.mod h1:sGbDF6GwGcLpkNXPUTkMRoywsNa/ol15pxFe6ERfguA= github.com/cespare/xxhash v0.0.0-20181017004759-096ff4a8a059/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko= @@ -355,11 +352,8 @@ github.com/cockroachdb/apd v1.1.0/go.mod h1:8Sl8LxpKi29FqWXR16WEFZRNSz3SoPzUzeMe github.com/cockroachdb/cockroach-go v0.0.0-20181001143604-e0a95dfd547c/go.mod h1:XGLbWH/ujMcbPbhZq52Nv6UrCghb1yGn//133kEsvDk= github.com/cockroachdb/datadriven v0.0.0-20190531201743-edce55837238/go.mod h1:zn76sxSg3SzpJ0PPJaLDCu+Bu0Lg3sKTORVIj19EIF8= github.com/cockroachdb/datadriven v0.0.0-20190809214429-80d97fb3cbaa/go.mod h1:zn76sxSg3SzpJ0PPJaLDCu+Bu0Lg3sKTORVIj19EIF8= -github.com/cockroachdb/datadriven v0.0.0-20200714090401-bf6692d28da5 h1:xD/lrqdvwsc+O2bjSSi3YqY73Ke3LAiSCx49aCesA0E= github.com/cockroachdb/datadriven v0.0.0-20200714090401-bf6692d28da5/go.mod h1:h6jFvWxBdQXxjopDMZyH2UVceIRfR84bdzbkoKrsWNo= -github.com/cockroachdb/errors v1.2.4 h1:Lap807SXTH5tri2TivECb/4abUkMZC9zRoLarvcKDqs= github.com/cockroachdb/errors v1.2.4/go.mod h1:rQD95gz6FARkaKkQXUksEje/d9a6wBJoCr5oaCLELYA= -github.com/cockroachdb/logtags v0.0.0-20190617123548-eb05cc24525f h1:o/kfcElHqOiXqcou5a3rIlMc7oJbMQkeLk0VQJ7zgqY= github.com/cockroachdb/logtags v0.0.0-20190617123548-eb05cc24525f/go.mod h1:i/u985jwjWRlyHXQbwatDASoW0RMlZ/3i9yJHE2xLkI= github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI= github.com/containerd/aufs v0.0.0-20200908144142-dab0cbea06f4/go.mod h1:nukgQABAEopAHvB6j7cnP5zJ+/3aVcE7hCYqvIwAHyE= @@ -450,8 +444,9 @@ github.com/containers/ocicrypt v1.1.0/go.mod h1:b8AOe0YR67uU8OqfVNcznfFpAzu3rdgU github.com/containers/ocicrypt v1.1.1/go.mod h1:Dm55fwWm1YZAjYRaJ94z2mfZikIyIN4B0oB3dj3jFxY= github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk= github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= -github.com/coreos/etcd v3.3.13+incompatible h1:8F3hqu9fGYLBifCmRCJsicFqDx/D68Rt3q1JMazcgBQ= github.com/coreos/etcd v3.3.13+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= +github.com/coreos/etcd v3.3.25+incompatible h1:0GQEw6h3YnuOVdtwygkIfJ+Omx0tZ8/QkVyXI4LkbeY= +github.com/coreos/etcd v3.3.25+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= github.com/coreos/go-iptables v0.4.5/go.mod h1:/mVI274lEDI2ns62jHCDnCyBF9Iwsmekav8Dbxlm1MU= github.com/coreos/go-iptables v0.5.0/go.mod h1:/mVI274lEDI2ns62jHCDnCyBF9Iwsmekav8Dbxlm1MU= github.com/coreos/go-oidc v2.1.0+incompatible/go.mod h1:CgnwVTmzoESiwO9qyAFEMiHoZ1nMCKZlZ9V6mm3/LKc= @@ -615,7 +610,6 @@ github.com/felixge/httpsnoop v1.0.1 h1:lvB5Jl89CsZtGIWuTcDM1E/vkVs49/Ml7JJe07l8S github.com/felixge/httpsnoop v1.0.1/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= github.com/fogleman/gg v1.2.1-0.20190220221249-0403632d5b90/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzPa1k= github.com/form3tech-oss/jwt-go v3.2.2+incompatible/go.mod h1:pbq4aXjuKjdthFRnoDwaVPLA+WlJuPGy+QneDUgJi2k= -github.com/form3tech-oss/jwt-go v3.2.3+incompatible h1:7ZaBxOI7TMoYBfyA3cQHErNNyAWIKUMIwqxEtgHOs5c= github.com/form3tech-oss/jwt-go v3.2.3+incompatible/go.mod h1:pbq4aXjuKjdthFRnoDwaVPLA+WlJuPGy+QneDUgJi2k= github.com/fortytw2/leaktest v1.3.0/go.mod h1:jDsjWgpAGjm2CA7WthBh/CdZYEPF31XHquHwclZch5g= github.com/foxcpp/go-mockdns v0.0.0-20201212160233-ede2f9158d15/go.mod h1:tPg4cp4nseejPd+UKxtCVQ2hUxNTZ7qQZJa7CLriIeo= @@ -630,7 +624,6 @@ github.com/fsouza/fake-gcs-server v1.7.0/go.mod h1:5XIRs4YvwNbNoz+1JF8j6KLAyDh7R github.com/fullsailor/pkcs7 v0.0.0-20190404230743-d7302db945fa/go.mod h1:KnogPXtdwXqoenmZCw6S+25EAm2MkxbG0deNDu4cbSA= github.com/garyburd/redigo v0.0.0-20150301180006-535138d7bcd7/go.mod h1:NR3MbYisc3/PwhQ00EMzDiPmrwpPxAn5GI05/YaO1SY= github.com/getkin/kin-openapi v0.53.0/go.mod h1:7Yn5whZr5kJi6t+kShccXS8ae1APpYTW6yheSwk8Yi4= -github.com/getsentry/raven-go v0.2.0 h1:no+xWJRb5ZI7eE8TWgIq1jLulQiIoLG0IfYxv5JYMGs= github.com/getsentry/raven-go v0.2.0/go.mod h1:KungGk8q33+aIAZUIVWZDr2OfAEBsO49PX4NzFV5kcQ= github.com/ghodss/yaml v0.0.0-20150909031657-73d445a93680/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= @@ -1015,12 +1008,11 @@ github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI= github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= github.com/gorilla/websocket v0.0.0-20170926233335-4201258b820c/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= -github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc= github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/grafana/dskit v0.0.0-20210818123532-6645f87e9e12/go.mod h1:QaNAQaCSFOtG/NHf6Jd/zh67H25kkrVCq36U61Y2Mhw= github.com/grafana/dskit v0.0.0-20210819132858-471020752967/go.mod h1:uF46UNN1/feB1egpq8UGbBBKvJjGgZauW7pcVbeFLLM= -github.com/grafana/dskit v0.0.0-20210908150159-fcf48cb19aa4 h1:OwWd9nQZYfb01HTJjleuO8eOP5t6Hl2EqVjng6W1juc= -github.com/grafana/dskit v0.0.0-20210908150159-fcf48cb19aa4/go.mod h1:m3eHzwe5IT5eE2MI3Ena2ooU8+Hek8IiVXb9yJ1+0rs= +github.com/grafana/dskit v0.0.0-20211007183133-4c566019f311 h1:Nl20dkRnGb5ucbLJZGZpAJk/gOMNes6LgatxPrvZ+50= +github.com/grafana/dskit v0.0.0-20211007183133-4c566019f311/go.mod h1:uPG2nyK4CtgNDmWv7qyzYcdI+S90kHHRWvHnBtEMBXM= github.com/grafana/gocql v0.0.0-20200605141915-ba5dc39ece85 h1:xLuzPoOzdfNb/RF/IENCw+oLVdZB4G21VPhkHBgwSHY= github.com/grafana/gocql v0.0.0-20200605141915-ba5dc39ece85/go.mod h1:crI9WX6p0IhrqB+DqIUHulRW853PaNFf7o4UprV//3I= github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA= @@ -1034,7 +1026,6 @@ github.com/grpc-ecosystem/go-grpc-middleware/providers/kit/v2 v2.0.0-20201002093 github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.0.0-20200501113911-9a95f0fdbfea/go.mod h1:GugMBs30ZSAkckqXEAIEGyYdDH6EgqowG8ppA3Zt+AY= github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.0.0-rc.2.0.20201207153454-9f6bf00c00a7 h1:guQyUpELu4I0wKgdsRBZDA5blfGiUleuppRSVy9Qbi0= github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.0.0-rc.2.0.20201207153454-9f6bf00c00a7/go.mod h1:GhphxcdlaRyAuBSvo6rV71BvQcvB/vuX8ugCyybuS2k= -github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 h1:Ovs26xHkKqVztRpIrF/92BcuyuQ/YW4NSIpoGtfXNho= github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk= github.com/grpc-ecosystem/grpc-gateway v1.4.1/go.mod h1:RSKVYQBd5MCa4OVpNdGskqpgL2+G+NZTnrVHpWWfpdw= github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= @@ -1044,7 +1035,6 @@ github.com/grpc-ecosystem/grpc-gateway v1.12.1/go.mod h1:8XEsbTttt/W+VvjtQhLACqC github.com/grpc-ecosystem/grpc-gateway v1.14.4/go.mod h1:6CwZWGDSPRJidgKAtJVvND6soZe6fT7iteq8wDPdhb0= github.com/grpc-ecosystem/grpc-gateway v1.14.6/go.mod h1:zdiPV4Yse/1gnckTHtghG4GkDEdKCRJduHpTxT3/jcw= github.com/grpc-ecosystem/grpc-gateway v1.15.0/go.mod h1:vO11I9oWA+KsxmfFQPhLnnIb1VDE24M+pdxZFiuZcA8= -github.com/grpc-ecosystem/grpc-gateway v1.16.0 h1:gmcG1KaJ57LophUzW0Hy8NmPhnMZb4M0+kPpLofRdBo= github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= github.com/grpc-ecosystem/grpc-opentracing v0.0.0-20180507213350-8e809c8a8645/go.mod h1:6iZfnjpejD4L/4DwD7NryNaJyCQdzwWwH2MWhCA90Kw= github.com/hailocab/go-hostpool v0.0.0-20160125115350-e80d13ce29ed h1:5upAirOpQc1Q53c0bnx2ufif5kANL7bfZWcc6VJWJd8= @@ -1194,7 +1184,6 @@ github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfC github.com/joeshaw/multierror v0.0.0-20140124173710-69b34d4ec901/go.mod h1:Z86h9688Y0wesXCyonoVr47MasHilkuLMqGhRZ4Hpak= github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg= github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo= -github.com/jonboulle/clockwork v0.2.2 h1:UOGuzwb1PwsrDAObMuhUnj0p5ULPj8V/xJ7Kx9qUBdQ= github.com/jonboulle/clockwork v0.2.2/go.mod h1:Pkfl5aHPm1nk2H9h0bjmnJD/BcgbGXUBGnn1kMkgxc8= github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= @@ -1739,7 +1728,6 @@ github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9 github.com/snowflakedb/gosnowflake v1.3.4/go.mod h1:NsRq2QeiMUuoNUJhp5Q6xGC4uBrsS9g6LwZVEkTWgsE= github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM= github.com/soheilhy/cmux v0.1.5-0.20210205191134-5ec6847320e5/go.mod h1:T7TcVDs9LWfQgPlPsdngu6I6QIoyIFZDDC6sNE1GqG0= -github.com/soheilhy/cmux v0.1.5 h1:jjzc5WVemNEDTLwv9tlmemhC73tI08BNOIGwBOo10Js= github.com/soheilhy/cmux v0.1.5/go.mod h1:T7TcVDs9LWfQgPlPsdngu6I6QIoyIFZDDC6sNE1GqG0= github.com/sony/gobreaker v0.4.1 h1:oMnRNZXX5j85zso6xCPRNPtmAycat+WcoKbklScLDgQ= github.com/sony/gobreaker v0.4.1/go.mod h1:ZKptC7FHNvhBz7dN2LGjPVBz2sZJmc0/PkyDJOjmxWY= @@ -1821,7 +1809,6 @@ github.com/tinylib/msgp v1.1.0/go.mod h1:+d+yLhGm8mzTaHzB+wgMYrodPfmZrzkirds8fDW github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/tmc/grpc-websocket-proxy v0.0.0-20200427203606-3cfed13b9966/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= -github.com/tmc/grpc-websocket-proxy v0.0.0-20201229170055-e5319fda7802 h1:uruHq4dN7GR16kFc5fp3d1RIYzJW5onx8Ybykw2YQFA= github.com/tmc/grpc-websocket-proxy v0.0.0-20201229170055-e5319fda7802/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM= github.com/uber-go/tally v3.3.15+incompatible/go.mod h1:YDTIBxdXyOU/sCWilKB4bgyufu1cEi0jdVnRdxvjnmU= @@ -1865,8 +1852,8 @@ github.com/weaveworks/common v0.0.0-20201119133501-0619918236ec/go.mod h1:ykzWac github.com/weaveworks/common v0.0.0-20210112142934-23c8d7fa6120/go.mod h1:ykzWac1LtVfOxdCK+jD754at1Ws9dKCwFeUzkFBffPs= github.com/weaveworks/common v0.0.0-20210419092856-009d1eebd624/go.mod h1:ykzWac1LtVfOxdCK+jD754at1Ws9dKCwFeUzkFBffPs= github.com/weaveworks/common v0.0.0-20210722103813-e649eff5ab4a/go.mod h1:YU9FvnS7kUnRt6HY10G+2qHkwzP3n3Vb1XsXDsJTSp8= -github.com/weaveworks/common v0.0.0-20210901124008-1fa3f9fa874c h1:+yzwVr4/12cUgsdjbEHq6MsKB7jWBZpZccAP6xvqTzQ= -github.com/weaveworks/common v0.0.0-20210901124008-1fa3f9fa874c/go.mod h1:YU9FvnS7kUnRt6HY10G+2qHkwzP3n3Vb1XsXDsJTSp8= +github.com/weaveworks/common v0.0.0-20210913144402-035033b78a78 h1:UqH2ncSWwCIhZ6bf2Wz1ifmxorIWFUm0GAfk7xv5c8s= +github.com/weaveworks/common v0.0.0-20210913144402-035033b78a78/go.mod h1:YU9FvnS7kUnRt6HY10G+2qHkwzP3n3Vb1XsXDsJTSp8= github.com/weaveworks/promrus v1.2.0 h1:jOLf6pe6/vss4qGHjXmGz4oDJQA+AOCqEL3FvvZGz7M= github.com/weaveworks/promrus v1.2.0/go.mod h1:SaE82+OJ91yqjrE1rsvBWVzNZKcHYFtMUyS1+Ogs/KA= github.com/willf/bitset v1.1.3/go.mod h1:RjeCKbqT1RxIR/KWY6phxZiaY1IyutSBfGjNPySAYV4= @@ -1883,7 +1870,6 @@ github.com/xdg/stringprep v1.0.0/go.mod h1:Jhud4/sHMO4oL310DaZAKk9ZaJ08SJfe+sJh0 github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU= github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415/go.mod h1:GwrjFmJcFw6At/Gs6z4yjiIwzuJ1/+UwLxMQDVQXShQ= github.com/xeipuuv/gojsonschema v0.0.0-20180618132009-1d523034197f/go.mod h1:5yf86TLmAcydyeJq5YvxkGPE2fm/u4myDekKRoLuqhs= -github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2 h1:eY9dn8+vbi4tKz5Qo6v2eYzo7kUS51QINcR5jNpbZS8= github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= github.com/xlab/treeprint v0.0.0-20180616005107-d6fb6747feb6/go.mod h1:ce1O1j6UtZfjr22oyGxGLbauSBp2YVXpARAosm7dHBg= github.com/xlab/treeprint v1.0.0/go.mod h1:IoImgRak9i3zJyuxOKUP1v4UZd1tMoKkq/Cimt1uhCg= @@ -1927,20 +1913,16 @@ go.etcd.io/etcd/api/v3 v3.5.0/go.mod h1:cbVKeC6lCfl7j/8jBhAK6aIYO9XOjdptoxU/nLQc go.etcd.io/etcd/client/pkg/v3 v3.5.0 h1:2aQv6F436YnN7I4VbI8PPYrBhu+SmrTaADcf8Mi/6PU= go.etcd.io/etcd/client/pkg/v3 v3.5.0/go.mod h1:IJHfcCEKxYu1Os13ZdwCwIUTUVGYTSAM3YSwc9/Ac1g= go.etcd.io/etcd/client/v2 v2.305.0-alpha.0/go.mod h1:kdV+xzCJ3luEBSIeQyB/OEKkWKd8Zkux4sbDeANrosU= -go.etcd.io/etcd/client/v2 v2.305.0 h1:ftQ0nOOHMcbMS3KIaDQ0g5Qcd6bhaBrQT6b89DfwLTs= go.etcd.io/etcd/client/v2 v2.305.0/go.mod h1:h9puh54ZTgAKtEbut2oe9P4L/oqKCVB6xsXlzd7alYQ= go.etcd.io/etcd/client/v3 v3.5.0-alpha.0/go.mod h1:wKt7jgDgf/OfKiYmCq5WFGxOFAkVMLxiiXgLDFhECr8= go.etcd.io/etcd/client/v3 v3.5.0-alpha.0.0.20210225194612-fa82d11a958a/go.mod h1:wKt7jgDgf/OfKiYmCq5WFGxOFAkVMLxiiXgLDFhECr8= go.etcd.io/etcd/client/v3 v3.5.0 h1:62Eh0XOro+rDwkrypAGDfgmNh5Joq+z+W9HZdlXMzek= go.etcd.io/etcd/client/v3 v3.5.0/go.mod h1:AIKXXVX/DQXtfTEqBryiLTUXwON+GuvO6Z7lLS/oTh0= go.etcd.io/etcd/pkg/v3 v3.5.0-alpha.0/go.mod h1:tV31atvwzcybuqejDoY3oaNRTtlD2l/Ot78Pc9w7DMY= -go.etcd.io/etcd/pkg/v3 v3.5.0 h1:ntrg6vvKRW26JRmHTE0iNlDgYK6JX3hg/4cD62X0ixk= go.etcd.io/etcd/pkg/v3 v3.5.0/go.mod h1:UzJGatBQ1lXChBkQF0AuAtkRQMYnHubxAEYIrC3MSsE= go.etcd.io/etcd/raft/v3 v3.5.0-alpha.0/go.mod h1:FAwse6Zlm5v4tEWZaTjmNhe17Int4Oxbu7+2r0DiD3w= -go.etcd.io/etcd/raft/v3 v3.5.0 h1:kw2TmO3yFTgE+F0mdKkG7xMxkit2duBDa2Hu6D/HMlw= go.etcd.io/etcd/raft/v3 v3.5.0/go.mod h1:UFOHSIvO/nKwd4lhkwabrTD3cqW5yVyYYf/KlD00Szc= go.etcd.io/etcd/server/v3 v3.5.0-alpha.0.0.20210225194612-fa82d11a958a/go.mod h1:tsKetYpt980ZTpzl/gb+UOJj9RkIyCb1u4wjzMg90BQ= -go.etcd.io/etcd/server/v3 v3.5.0 h1:jk8D/lwGEDlQU9kZXUFMSANkE22Sg5+mW27ip8xcF9E= go.etcd.io/etcd/server/v3 v3.5.0/go.mod h1:3Ah5ruV+M+7RZr0+Y/5mNLwC+eQlni+mQmOVdCRJoS4= go.mongodb.org/mongo-driver v1.0.3/go.mod h1:u7ryQJ+DOzQmeO7zB6MHyr8jkEQvC8vH7qLUO4lqsUM= go.mongodb.org/mongo-driver v1.0.4/go.mod h1:u7ryQJ+DOzQmeO7zB6MHyr8jkEQvC8vH7qLUO4lqsUM= @@ -1966,28 +1948,17 @@ go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.opencensus.io v0.22.5/go.mod h1:5pWMHQbX5EPX2/62yrJeAkowc+lfs/XD7Uxpq3pI6kk= go.opencensus.io v0.23.0 h1:gqCw0LfLxScz8irSi8exQc7fyQ0fKQU/qnC/X8+V/1M= go.opencensus.io v0.23.0/go.mod h1:XItmlyltB5F7CS4xOC1DcqMoFqwtC6OG2xF7mCv7P7E= -go.opentelemetry.io/contrib v0.20.0 h1:ubFQUn0VCZ0gPwIoJfBJVpeBlyRMxu8Mm/huKWYd9p0= go.opentelemetry.io/contrib v0.20.0/go.mod h1:G/EtFaa6qaN7+LxqfIAT3GiZa7Wv5DTBUzl5H4LY0Kc= -go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.20.0 h1:sO4WKdPAudZGKPcpZT4MJn6JaDmpyLrMPDGGyA1SttE= go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.20.0/go.mod h1:oVGt1LRbBOBq1A5BQLlUg9UaU/54aiHw8cgjV3aWZ/E= go.opentelemetry.io/otel v0.11.0/go.mod h1:G8UCk+KooF2HLkgo8RHX9epABH/aRGYET7gQOqBVdB0= -go.opentelemetry.io/otel v0.20.0 h1:eaP0Fqu7SXHwvjiqDq83zImeehOHX8doTvU9AwXON8g= go.opentelemetry.io/otel v0.20.0/go.mod h1:Y3ugLH2oa81t5QO+Lty+zXf8zC9L26ax4Nzoxm/dooo= -go.opentelemetry.io/otel/exporters/otlp v0.20.0 h1:PTNgq9MRmQqqJY0REVbZFvwkYOA85vbdQU/nVfxDyqg= go.opentelemetry.io/otel/exporters/otlp v0.20.0/go.mod h1:YIieizyaN77rtLJra0buKiNBOm9XQfkPEKBeuhoMwAM= -go.opentelemetry.io/otel/metric v0.20.0 h1:4kzhXFP+btKm4jwxpjIqjs41A7MakRFUS86bqLHTIw8= go.opentelemetry.io/otel/metric v0.20.0/go.mod h1:598I5tYlH1vzBjn+BTuhzTCSb/9debfNp6R3s7Pr1eU= -go.opentelemetry.io/otel/oteltest v0.20.0 h1:HiITxCawalo5vQzdHfKeZurV8x7ljcqAgiWzF6Vaeaw= go.opentelemetry.io/otel/oteltest v0.20.0/go.mod h1:L7bgKf9ZB7qCwT9Up7i9/pn0PWIa9FqQ2IQ8LoxiGnw= -go.opentelemetry.io/otel/sdk v0.20.0 h1:JsxtGXd06J8jrnya7fdI/U/MR6yXA5DtbZy+qoHQlr8= go.opentelemetry.io/otel/sdk v0.20.0/go.mod h1:g/IcepuwNsoiX5Byy2nNV0ySUF1em498m7hBWC279Yc= -go.opentelemetry.io/otel/sdk/export/metric v0.20.0 h1:c5VRjxCXdQlx1HjzwGdQHzZaVI82b5EbBgOu2ljD92g= go.opentelemetry.io/otel/sdk/export/metric v0.20.0/go.mod h1:h7RBNMsDJ5pmI1zExLi+bJK+Dr8NQCh0qGhm1KDnNlE= -go.opentelemetry.io/otel/sdk/metric v0.20.0 h1:7ao1wpzHRVKf0OQ7GIxiQJA6X7DLX9o14gmVon7mMK8= go.opentelemetry.io/otel/sdk/metric v0.20.0/go.mod h1:knxiS8Xd4E/N+ZqKmUPf3gTTZ4/0TjTXukfxjzSTpHE= -go.opentelemetry.io/otel/trace v0.20.0 h1:1DL6EXUdcg95gukhuRRvLDO/4X5THh/5dIV52lqtnbw= go.opentelemetry.io/otel/trace v0.20.0/go.mod h1:6GjCW8zgDjwGHGa6GkyeB8+/5vjT16gUEi0Nf1iBdgw= -go.opentelemetry.io/proto/otlp v0.7.0 h1:rwOQPCuKAKmwGKq2aVNnYIibI6wnV7EvzgfTCzcdGg8= go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI= go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= @@ -2643,7 +2614,6 @@ gopkg.in/ini.v1 v1.42.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= gopkg.in/ini.v1 v1.51.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= gopkg.in/ini.v1 v1.57.0 h1:9unxIsFcTt4I55uWluz+UmL95q4kdJ0buvQ1ZIqVQww= gopkg.in/ini.v1 v1.57.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= -gopkg.in/natefinch/lumberjack.v2 v2.0.0 h1:1Lc07Kr7qY4U2YPouBjpCLxpiyxIVoxqXgkXLknAOE8= gopkg.in/natefinch/lumberjack.v2 v2.0.0/go.mod h1:l0ndWWf7gzL7RNwBG7wST/UCcT4T24xpD6X8LsfU/+k= gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo= gopkg.in/square/go-jose.v2 v2.2.2/go.mod h1:M9dMgbHiYLoDGQrXy7OpJDJWiKiU//h+vD76mk0e1AI= diff --git a/pkg/alertmanager/alertmanager_client.go b/pkg/alertmanager/alertmanager_client.go index e95d8708ae..57571a3146 100644 --- a/pkg/alertmanager/alertmanager_client.go +++ b/pkg/alertmanager/alertmanager_client.go @@ -5,6 +5,8 @@ import ( "time" "github.com/go-kit/log" + "github.com/grafana/dskit/crypto/tls" + "github.com/grafana/dskit/grpcclient" "github.com/pkg/errors" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promauto" @@ -13,8 +15,6 @@ import ( "github.com/cortexproject/cortex/pkg/alertmanager/alertmanagerpb" "github.com/cortexproject/cortex/pkg/ring/client" - "github.com/cortexproject/cortex/pkg/util/grpcclient" - "github.com/cortexproject/cortex/pkg/util/tls" ) // ClientsPool is the interface used to get the client from the pool for a specified address. diff --git a/pkg/chunk/gcp/bigtable_index_client.go b/pkg/chunk/gcp/bigtable_index_client.go index fc716edbb5..7b516212aa 100644 --- a/pkg/chunk/gcp/bigtable_index_client.go +++ b/pkg/chunk/gcp/bigtable_index_client.go @@ -12,12 +12,12 @@ import ( "cloud.google.com/go/bigtable" "github.com/go-kit/log" + "github.com/grafana/dskit/grpcclient" ot "github.com/opentracing/opentracing-go" "github.com/pkg/errors" "github.com/cortexproject/cortex/pkg/chunk" chunk_util "github.com/cortexproject/cortex/pkg/chunk/util" - "github.com/cortexproject/cortex/pkg/util/grpcclient" "github.com/cortexproject/cortex/pkg/util/math" "github.com/cortexproject/cortex/pkg/util/spanlogger" ) diff --git a/pkg/configs/client/client.go b/pkg/configs/client/client.go index 4aaebc37d5..0e7561aa6b 100644 --- a/pkg/configs/client/client.go +++ b/pkg/configs/client/client.go @@ -12,6 +12,7 @@ import ( "time" "github.com/go-kit/log/level" + dstls "github.com/grafana/dskit/crypto/tls" "github.com/grafana/dskit/flagext" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promauto" @@ -20,7 +21,6 @@ import ( "github.com/cortexproject/cortex/pkg/configs/userconfig" util_log "github.com/cortexproject/cortex/pkg/util/log" - tls_cfg "github.com/cortexproject/cortex/pkg/util/tls" ) var ( @@ -29,9 +29,9 @@ var ( // Config says where we can find the ruler userconfig. type Config struct { - ConfigsAPIURL flagext.URLValue `yaml:"configs_api_url"` - ClientTimeout time.Duration `yaml:"client_timeout"` // HTTP timeout duration for requests made to the Weave Cloud configs service. - TLS tls_cfg.ClientConfig `yaml:",inline"` + ConfigsAPIURL flagext.URLValue `yaml:"configs_api_url"` + ClientTimeout time.Duration `yaml:"client_timeout"` // HTTP timeout duration for requests made to the Weave Cloud configs service. + TLS dstls.ClientConfig `yaml:",inline"` } // RegisterFlagsWithPrefix adds the flags required to config this to the given FlagSet diff --git a/pkg/configs/db/dbtest/integration.go b/pkg/configs/db/dbtest/integration.go index cc73b3b381..d9a445a2fb 100644 --- a/pkg/configs/db/dbtest/integration.go +++ b/pkg/configs/db/dbtest/integration.go @@ -1,3 +1,4 @@ +//go:build integration // +build integration package dbtest diff --git a/pkg/configs/db/dbtest/unit.go b/pkg/configs/db/dbtest/unit.go index b782c70edd..f5d7635b08 100644 --- a/pkg/configs/db/dbtest/unit.go +++ b/pkg/configs/db/dbtest/unit.go @@ -1,3 +1,4 @@ +//go:build !integration // +build !integration package dbtest diff --git a/pkg/configs/legacy_promql/fuzz.go b/pkg/configs/legacy_promql/fuzz.go index 40ab846ddd..e54d3e8f79 100644 --- a/pkg/configs/legacy_promql/fuzz.go +++ b/pkg/configs/legacy_promql/fuzz.go @@ -12,6 +12,7 @@ // limitations under the License. // Only build when go-fuzz is in use +//go:build gofuzz // +build gofuzz package promql diff --git a/pkg/cortex/cortex.go b/pkg/cortex/cortex.go index 7351c94fed..0a6ca6c2c1 100644 --- a/pkg/cortex/cortex.go +++ b/pkg/cortex/cortex.go @@ -13,6 +13,7 @@ import ( "github.com/go-kit/log" "github.com/go-kit/log/level" "github.com/grafana/dskit/flagext" + "github.com/grafana/dskit/grpcutil" "github.com/grafana/dskit/kv/memberlist" "github.com/grafana/dskit/modules" "github.com/grafana/dskit/runtimeconfig" @@ -58,7 +59,6 @@ import ( "github.com/cortexproject/cortex/pkg/tenant" "github.com/cortexproject/cortex/pkg/util" "github.com/cortexproject/cortex/pkg/util/fakeauth" - "github.com/cortexproject/cortex/pkg/util/grpc/healthcheck" util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/cortexproject/cortex/pkg/util/process" "github.com/cortexproject/cortex/pkg/util/validation" @@ -430,7 +430,7 @@ func (t *Cortex) Run() error { // before starting servers, register /ready handler and gRPC health check service. // It should reflect entire Cortex. t.Server.HTTP.Path("/ready").Handler(t.readyHandler(sm)) - grpc_health_v1.RegisterHealthServer(t.Server.GRPC, healthcheck.New(sm)) + grpc_health_v1.RegisterHealthServer(t.Server.GRPC, grpcutil.NewHealthCheck(sm)) // Let's listen for events from this manager, and log them. healthy := func() { level.Info(util_log.Logger).Log("msg", "Cortex started") } diff --git a/pkg/distributor/query.go b/pkg/distributor/query.go index 33797a241d..e3d5fe2e9e 100644 --- a/pkg/distributor/query.go +++ b/pkg/distributor/query.go @@ -6,6 +6,7 @@ import ( "sort" "time" + "github.com/grafana/dskit/grpcutil" "github.com/opentracing/opentracing-go" "github.com/prometheus/common/model" "github.com/prometheus/prometheus/pkg/labels" @@ -18,7 +19,6 @@ import ( "github.com/cortexproject/cortex/pkg/tenant" "github.com/cortexproject/cortex/pkg/util" "github.com/cortexproject/cortex/pkg/util/extract" - grpc_util "github.com/cortexproject/cortex/pkg/util/grpc" "github.com/cortexproject/cortex/pkg/util/limiter" "github.com/cortexproject/cortex/pkg/util/validation" ) @@ -308,7 +308,7 @@ func (d *Distributor) queryIngesterStream(ctx context.Context, replicationSet ri break } else if err != nil { // Do not track a failure if the context was canceled. - if !grpc_util.IsGRPCContextCanceled(err) { + if !grpcutil.IsGRPCContextCanceled(err) { d.ingesterQueryFailures.WithLabelValues(ing.Addr).Inc() } diff --git a/pkg/frontend/v1/frontend.go b/pkg/frontend/v1/frontend.go index 04c8cfa8b9..4c58ec44b8 100644 --- a/pkg/frontend/v1/frontend.go +++ b/pkg/frontend/v1/frontend.go @@ -21,7 +21,7 @@ import ( "github.com/cortexproject/cortex/pkg/scheduler/queue" "github.com/cortexproject/cortex/pkg/tenant" "github.com/cortexproject/cortex/pkg/util" - "github.com/cortexproject/cortex/pkg/util/grpcutil" + "github.com/cortexproject/cortex/pkg/util/httpgrpcutil" "github.com/cortexproject/cortex/pkg/util/validation" ) @@ -154,7 +154,7 @@ func (f *Frontend) RoundTripGRPC(ctx context.Context, req *httpgrpc.HTTPRequest) // Propagate trace context in gRPC too - this will be ignored if using HTTP. tracer, span := opentracing.GlobalTracer(), opentracing.SpanFromContext(ctx) if tracer != nil && span != nil { - carrier := (*grpcutil.HttpgrpcHeadersCarrier)(req) + carrier := (*httpgrpcutil.HttpgrpcHeadersCarrier)(req) err := tracer.Inject(span.Context(), opentracing.HTTPHeaders, carrier) if err != nil { return nil, err diff --git a/pkg/frontend/v2/frontend.go b/pkg/frontend/v2/frontend.go index 5495a1ff39..540c515019 100644 --- a/pkg/frontend/v2/frontend.go +++ b/pkg/frontend/v2/frontend.go @@ -12,6 +12,7 @@ import ( "github.com/go-kit/log" "github.com/go-kit/log/level" "github.com/grafana/dskit/flagext" + "github.com/grafana/dskit/grpcclient" "github.com/grafana/dskit/services" "github.com/opentracing/opentracing-go" "github.com/pkg/errors" @@ -23,8 +24,7 @@ import ( "github.com/cortexproject/cortex/pkg/frontend/v2/frontendv2pb" "github.com/cortexproject/cortex/pkg/querier/stats" "github.com/cortexproject/cortex/pkg/tenant" - "github.com/cortexproject/cortex/pkg/util/grpcclient" - "github.com/cortexproject/cortex/pkg/util/grpcutil" + "github.com/cortexproject/cortex/pkg/util/httpgrpcutil" ) // Config for a Frontend. @@ -162,7 +162,7 @@ func (f *Frontend) RoundTripGRPC(ctx context.Context, req *httpgrpc.HTTPRequest) // Propagate trace context in gRPC too - this will be ignored if using HTTP. tracer, span := opentracing.GlobalTracer(), opentracing.SpanFromContext(ctx) if tracer != nil && span != nil { - carrier := (*grpcutil.HttpgrpcHeadersCarrier)(req) + carrier := (*httpgrpcutil.HttpgrpcHeadersCarrier)(req) if err := tracer.Inject(span.Context(), opentracing.HTTPHeaders, carrier); err != nil { return nil, err } diff --git a/pkg/ingester/client/client.go b/pkg/ingester/client/client.go index 6b017a20e2..05f010d717 100644 --- a/pkg/ingester/client/client.go +++ b/pkg/ingester/client/client.go @@ -4,12 +4,11 @@ import ( "flag" "github.com/go-kit/log" + "github.com/grafana/dskit/grpcclient" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promauto" "google.golang.org/grpc" "google.golang.org/grpc/health/grpc_health_v1" - - "github.com/cortexproject/cortex/pkg/util/grpcclient" ) var ingesterClientRequestDuration = promauto.NewHistogramVec(prometheus.HistogramOpts{ diff --git a/pkg/ingester/client/cortex_util_test.go b/pkg/ingester/client/cortex_util_test.go index fb30941214..06f6e94a8c 100644 --- a/pkg/ingester/client/cortex_util_test.go +++ b/pkg/ingester/client/cortex_util_test.go @@ -7,13 +7,13 @@ import ( "testing" "time" + "github.com/grafana/dskit/grpcutil" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" "google.golang.org/grpc" "google.golang.org/grpc/test/bufconn" - grpc_util "github.com/cortexproject/cortex/pkg/util/grpc" "github.com/cortexproject/cortex/pkg/util/test" ) @@ -71,7 +71,7 @@ func TestSendQueryStream(t *testing.T) { // Try to receive the response and assert the error we get is the context.Canceled // wrapped within a gRPC error. _, err = stream.Recv() - assert.Equal(t, true, grpc_util.IsGRPCContextCanceled(err)) + assert.Equal(t, true, grpcutil.IsGRPCContextCanceled(err)) // Wait until the assertions in the server mock have completed. wg.Wait() diff --git a/pkg/querier/store_gateway_client.go b/pkg/querier/store_gateway_client.go index b84a87846c..528c3c2fd9 100644 --- a/pkg/querier/store_gateway_client.go +++ b/pkg/querier/store_gateway_client.go @@ -5,6 +5,8 @@ import ( "time" "github.com/go-kit/log" + "github.com/grafana/dskit/crypto/tls" + "github.com/grafana/dskit/grpcclient" "github.com/pkg/errors" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promauto" @@ -13,8 +15,6 @@ import ( "github.com/cortexproject/cortex/pkg/ring/client" "github.com/cortexproject/cortex/pkg/storegateway/storegatewaypb" - "github.com/cortexproject/cortex/pkg/util/grpcclient" - "github.com/cortexproject/cortex/pkg/util/tls" ) func newStoreGatewayClientFactory(clientCfg grpcclient.Config, reg prometheus.Registerer) client.PoolFactory { diff --git a/pkg/querier/store_gateway_client_test.go b/pkg/querier/store_gateway_client_test.go index 3583bee7e2..afe8e897e7 100644 --- a/pkg/querier/store_gateway_client_test.go +++ b/pkg/querier/store_gateway_client_test.go @@ -6,6 +6,7 @@ import ( "testing" "github.com/grafana/dskit/flagext" + "github.com/grafana/dskit/grpcclient" "github.com/prometheus/client_golang/prometheus" dto "github.com/prometheus/client_model/go" "github.com/stretchr/testify/assert" @@ -15,7 +16,6 @@ import ( "google.golang.org/grpc" "github.com/cortexproject/cortex/pkg/storegateway/storegatewaypb" - "github.com/cortexproject/cortex/pkg/util/grpcclient" ) func Test_newStoreGatewayClientFactory(t *testing.T) { diff --git a/pkg/querier/worker/scheduler_processor.go b/pkg/querier/worker/scheduler_processor.go index 092e28dfd5..bbe0811635 100644 --- a/pkg/querier/worker/scheduler_processor.go +++ b/pkg/querier/worker/scheduler_processor.go @@ -9,6 +9,7 @@ import ( "github.com/go-kit/log" "github.com/go-kit/log/level" "github.com/grafana/dskit/backoff" + "github.com/grafana/dskit/grpcclient" "github.com/grafana/dskit/services" otgrpc "github.com/opentracing-contrib/go-grpc" "github.com/opentracing/opentracing-go" @@ -24,8 +25,7 @@ import ( querier_stats "github.com/cortexproject/cortex/pkg/querier/stats" "github.com/cortexproject/cortex/pkg/ring/client" "github.com/cortexproject/cortex/pkg/scheduler/schedulerpb" - "github.com/cortexproject/cortex/pkg/util/grpcclient" - "github.com/cortexproject/cortex/pkg/util/grpcutil" + "github.com/cortexproject/cortex/pkg/util/httpgrpcutil" util_log "github.com/cortexproject/cortex/pkg/util/log" cortex_middleware "github.com/cortexproject/cortex/pkg/util/middleware" ) @@ -132,7 +132,7 @@ func (sp *schedulerProcessor) querierLoop(c schedulerpb.SchedulerForQuerier_Quer tracer := opentracing.GlobalTracer() // Ignore errors here. If we cannot get parent span, we just don't create new one. - parentSpanContext, _ := grpcutil.GetParentSpanForRequest(tracer, request.HttpRequest) + parentSpanContext, _ := httpgrpcutil.GetParentSpanForRequest(tracer, request.HttpRequest) if parentSpanContext != nil { queueSpan, spanCtx := opentracing.StartSpanFromContextWithTracer(ctx, tracer, "querier_processor_runRequest", opentracing.ChildOf(parentSpanContext)) defer queueSpan.Finish() diff --git a/pkg/querier/worker/worker.go b/pkg/querier/worker/worker.go index 9180a7b4a2..21e7c98566 100644 --- a/pkg/querier/worker/worker.go +++ b/pkg/querier/worker/worker.go @@ -9,6 +9,7 @@ import ( "github.com/go-kit/log" "github.com/go-kit/log/level" + "github.com/grafana/dskit/grpcclient" "github.com/grafana/dskit/services" "github.com/pkg/errors" "github.com/prometheus/client_golang/prometheus" @@ -16,7 +17,6 @@ import ( "google.golang.org/grpc" "github.com/cortexproject/cortex/pkg/util" - "github.com/cortexproject/cortex/pkg/util/grpcclient" ) type Config struct { diff --git a/pkg/ruler/client_pool.go b/pkg/ruler/client_pool.go index c00b2cedcf..717d154e0f 100644 --- a/pkg/ruler/client_pool.go +++ b/pkg/ruler/client_pool.go @@ -3,9 +3,9 @@ package ruler import ( "time" - "github.com/grafana/dskit/services" - "github.com/go-kit/log" + "github.com/grafana/dskit/grpcclient" + "github.com/grafana/dskit/services" "github.com/pkg/errors" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promauto" @@ -13,7 +13,6 @@ import ( "google.golang.org/grpc/health/grpc_health_v1" "github.com/cortexproject/cortex/pkg/ring/client" - "github.com/cortexproject/cortex/pkg/util/grpcclient" ) // ClientsPool is the interface used to get the client from the pool for a specified address. diff --git a/pkg/ruler/client_pool_test.go b/pkg/ruler/client_pool_test.go index 14d7cfb8e7..2f4998f1cf 100644 --- a/pkg/ruler/client_pool_test.go +++ b/pkg/ruler/client_pool_test.go @@ -6,14 +6,13 @@ import ( "testing" "github.com/grafana/dskit/flagext" + "github.com/grafana/dskit/grpcclient" "github.com/prometheus/client_golang/prometheus" dto "github.com/prometheus/client_model/go" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/weaveworks/common/user" "google.golang.org/grpc" - - "github.com/cortexproject/cortex/pkg/util/grpcclient" ) func Test_newRulerClientFactory(t *testing.T) { diff --git a/pkg/ruler/notifier.go b/pkg/ruler/notifier.go index 3b90b25ad3..d8f5a55b7d 100644 --- a/pkg/ruler/notifier.go +++ b/pkg/ruler/notifier.go @@ -11,6 +11,7 @@ import ( gklog "github.com/go-kit/log" "github.com/go-kit/log/level" + "github.com/grafana/dskit/crypto/tls" config_util "github.com/prometheus/common/config" "github.com/prometheus/common/model" "github.com/prometheus/prometheus/config" @@ -19,7 +20,6 @@ import ( "github.com/prometheus/prometheus/notifier" "github.com/cortexproject/cortex/pkg/util" - "github.com/cortexproject/cortex/pkg/util/tls" ) type NotifierConfig struct { diff --git a/pkg/ruler/ruler.go b/pkg/ruler/ruler.go index f92b376f75..4ea083c3d7 100644 --- a/pkg/ruler/ruler.go +++ b/pkg/ruler/ruler.go @@ -15,6 +15,7 @@ import ( "github.com/go-kit/log" "github.com/go-kit/log/level" "github.com/grafana/dskit/flagext" + "github.com/grafana/dskit/grpcclient" "github.com/grafana/dskit/kv" "github.com/grafana/dskit/services" "github.com/pkg/errors" @@ -34,7 +35,6 @@ import ( "github.com/cortexproject/cortex/pkg/tenant" "github.com/cortexproject/cortex/pkg/util" "github.com/cortexproject/cortex/pkg/util/concurrency" - "github.com/cortexproject/cortex/pkg/util/grpcclient" util_log "github.com/cortexproject/cortex/pkg/util/log" "github.com/cortexproject/cortex/pkg/util/validation" ) diff --git a/pkg/scheduler/scheduler.go b/pkg/scheduler/scheduler.go index 4998d0894a..3d3dbdc344 100644 --- a/pkg/scheduler/scheduler.go +++ b/pkg/scheduler/scheduler.go @@ -10,6 +10,7 @@ import ( "github.com/go-kit/log" "github.com/go-kit/log/level" + "github.com/grafana/dskit/grpcclient" "github.com/grafana/dskit/services" otgrpc "github.com/opentracing-contrib/go-grpc" "github.com/opentracing/opentracing-go" @@ -26,8 +27,7 @@ import ( "github.com/cortexproject/cortex/pkg/scheduler/schedulerpb" "github.com/cortexproject/cortex/pkg/tenant" "github.com/cortexproject/cortex/pkg/util" - "github.com/cortexproject/cortex/pkg/util/grpcclient" - "github.com/cortexproject/cortex/pkg/util/grpcutil" + "github.com/cortexproject/cortex/pkg/util/httpgrpcutil" "github.com/cortexproject/cortex/pkg/util/validation" ) @@ -277,7 +277,7 @@ func (s *Scheduler) enqueueRequest(frontendContext context.Context, frontendAddr // Extract tracing information from headers in HTTP request. FrontendContext doesn't have the correct tracing // information, since that is a long-running request. tracer := opentracing.GlobalTracer() - parentSpanContext, err := grpcutil.GetParentSpanForRequest(tracer, msg.HttpRequest) + parentSpanContext, err := httpgrpcutil.GetParentSpanForRequest(tracer, msg.HttpRequest) if err != nil { return err } diff --git a/pkg/scheduler/scheduler_test.go b/pkg/scheduler/scheduler_test.go index bdf8e11ca5..c131ffaf71 100644 --- a/pkg/scheduler/scheduler_test.go +++ b/pkg/scheduler/scheduler_test.go @@ -23,7 +23,7 @@ import ( "github.com/cortexproject/cortex/pkg/frontend/v2/frontendv2pb" "github.com/cortexproject/cortex/pkg/scheduler/schedulerpb" - chunk "github.com/cortexproject/cortex/pkg/util/grpcutil" + "github.com/cortexproject/cortex/pkg/util/httpgrpcutil" "github.com/cortexproject/cortex/pkg/util/test" ) @@ -247,7 +247,7 @@ func TestTracingContext(t *testing.T) { } sp, _ := opentracing.StartSpanFromContext(context.Background(), "client") - opentracing.GlobalTracer().Inject(sp.Context(), opentracing.HTTPHeaders, (*chunk.HttpgrpcHeadersCarrier)(req.HttpRequest)) + opentracing.GlobalTracer().Inject(sp.Context(), opentracing.HTTPHeaders, (*httpgrpcutil.HttpgrpcHeadersCarrier)(req.HttpRequest)) frontendToScheduler(t, frontendLoop, req) diff --git a/pkg/util/dns_watcher.go b/pkg/util/dns_watcher.go index 182d2ebe91..584d91c79c 100644 --- a/pkg/util/dns_watcher.go +++ b/pkg/util/dns_watcher.go @@ -5,10 +5,11 @@ import ( "fmt" "time" + "github.com/grafana/dskit/grpcutil" "github.com/grafana/dskit/services" "github.com/pkg/errors" - "github.com/cortexproject/cortex/pkg/util/grpc/naming" + util_log "github.com/cortexproject/cortex/pkg/util/log" ) // Notifications about address resolution. All notifications are sent on the same goroutine. @@ -21,13 +22,13 @@ type DNSNotifications interface { } type dnsWatcher struct { - watcher naming.Watcher + watcher grpcutil.Watcher notifications DNSNotifications } // NewDNSWatcher creates a new DNS watcher and returns a service that is wrapping it. func NewDNSWatcher(address string, dnsLookupPeriod time.Duration, notifications DNSNotifications) (services.Service, error) { - resolver, err := naming.NewDNSResolverWithFreq(dnsLookupPeriod) + resolver, err := grpcutil.NewDNSResolverWithFreq(dnsLookupPeriod, util_log.Logger) if err != nil { return nil, err } @@ -68,10 +69,10 @@ func (w *dnsWatcher) watchDNSLoop(servCtx context.Context) error { for _, update := range updates { switch update.Op { - case naming.Add: + case grpcutil.Add: w.notifications.AddressAdded(update.Addr) - case naming.Delete: + case grpcutil.Delete: w.notifications.AddressRemoved(update.Addr) default: diff --git a/pkg/util/grpc/encoding/snappy/snappy_test.go b/pkg/util/grpc/encoding/snappy/snappy_test.go deleted file mode 100644 index 315136f906..0000000000 --- a/pkg/util/grpc/encoding/snappy/snappy_test.go +++ /dev/null @@ -1,71 +0,0 @@ -package snappy - -import ( - "bytes" - "io" - "io/ioutil" - "strings" - "testing" - - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" -) - -func TestSnappy(t *testing.T) { - c := newCompressor() - assert.Equal(t, "snappy", c.Name()) - - tests := []struct { - test string - input string - }{ - {"empty", ""}, - {"short", "hello world"}, - {"long", strings.Repeat("123456789", 1024)}, - } - for _, test := range tests { - t.Run(test.test, func(t *testing.T) { - var buf bytes.Buffer - // Compress - w, err := c.Compress(&buf) - require.NoError(t, err) - n, err := w.Write([]byte(test.input)) - require.NoError(t, err) - assert.Len(t, test.input, n) - err = w.Close() - require.NoError(t, err) - // Decompress - r, err := c.Decompress(&buf) - require.NoError(t, err) - out, err := ioutil.ReadAll(r) - require.NoError(t, err) - assert.Equal(t, test.input, string(out)) - }) - } -} - -func BenchmarkSnappyCompress(b *testing.B) { - data := []byte(strings.Repeat("123456789", 1024)) - c := newCompressor() - b.ResetTimer() - for i := 0; i < b.N; i++ { - w, _ := c.Compress(ioutil.Discard) - _, _ = w.Write(data) - _ = w.Close() - } -} - -func BenchmarkSnappyDecompress(b *testing.B) { - data := []byte(strings.Repeat("123456789", 1024)) - c := newCompressor() - var buf bytes.Buffer - w, _ := c.Compress(&buf) - _, _ = w.Write(data) - reader := bytes.NewReader(buf.Bytes()) - b.ResetTimer() - for i := 0; i < b.N; i++ { - r, _ := c.Decompress(reader) - _, _ = ioutil.ReadAll(r) - _, _ = reader.Seek(0, io.SeekStart) - } -} diff --git a/pkg/util/grpc/healthcheck/health_check_test.go b/pkg/util/grpc/healthcheck/health_check_test.go deleted file mode 100644 index f59c8ba466..0000000000 --- a/pkg/util/grpc/healthcheck/health_check_test.go +++ /dev/null @@ -1,145 +0,0 @@ -package healthcheck - -import ( - "context" - "testing" - - "github.com/grafana/dskit/services" - "github.com/pkg/errors" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" -) - -func TestHealthCheck_isHealthy(t *testing.T) { - tests := map[string]struct { - states []services.State - expected bool - }{ - "all services are new": { - states: []services.State{services.New, services.New}, - expected: false, - }, - "all services are starting": { - states: []services.State{services.Starting, services.Starting}, - expected: false, - }, - "some services are starting and some running": { - states: []services.State{services.Starting, services.Running}, - expected: false, - }, - "all services are running": { - states: []services.State{services.Running, services.Running}, - expected: true, - }, - "some services are stopping": { - states: []services.State{services.Running, services.Stopping}, - expected: true, - }, - "some services are terminated while others running": { - states: []services.State{services.Running, services.Terminated}, - expected: true, - }, - "all services are stopping": { - states: []services.State{services.Stopping, services.Stopping}, - expected: true, - }, - "some services are terminated while others stopping": { - states: []services.State{services.Stopping, services.Terminated}, - expected: true, - }, - "a service has failed while others are running": { - states: []services.State{services.Running, services.Failed}, - expected: false, - }, - "all services are terminated": { - states: []services.State{services.Terminated, services.Terminated}, - expected: false, - }, - } - - for testName, testData := range tests { - t.Run(testName, func(t *testing.T) { - var svcs []services.Service - for range testData.states { - svcs = append(svcs, &mockService{}) - } - - sm, err := services.NewManager(svcs...) - require.NoError(t, err) - - // Switch the state of each mocked services. - for i, s := range svcs { - s.(*mockService).switchState(testData.states[i]) - } - - h := New(sm) - assert.Equal(t, testData.expected, h.isHealthy()) - }) - } -} - -type mockService struct { - services.Service - state services.State - listeners []services.Listener -} - -func (s *mockService) switchState(desiredState services.State) { - // Simulate all the states between the current state and the desired one. - orderedStates := []services.State{services.New, services.Starting, services.Running, services.Failed, services.Stopping, services.Terminated} - simulationStarted := false - - for _, orderedState := range orderedStates { - // Skip until we reach the current state. - if !simulationStarted && orderedState != s.state { - continue - } - - // Start the simulation once we reach the current state. - if orderedState == s.state { - simulationStarted = true - continue - } - - // Skip the failed state, unless it's the desired one. - if orderedState == services.Failed && desiredState != services.Failed { - continue - } - - s.state = orderedState - - // Synchronously call listeners to avoid flaky tests. - for _, listener := range s.listeners { - switch orderedState { - case services.Starting: - listener.Starting() - case services.Running: - listener.Running() - case services.Stopping: - listener.Stopping(services.Running) - case services.Failed: - listener.Failed(services.Running, errors.New("mocked error")) - case services.Terminated: - listener.Terminated(services.Stopping) - } - } - - if orderedState == desiredState { - break - } - } -} - -func (s *mockService) State() services.State { - return s.state -} - -func (s *mockService) AddListener(listener services.Listener) { - s.listeners = append(s.listeners, listener) -} - -func (s *mockService) StartAsync(_ context.Context) error { return nil } -func (s *mockService) AwaitRunning(_ context.Context) error { return nil } -func (s *mockService) StopAsync() {} -func (s *mockService) AwaitTerminated(_ context.Context) error { return nil } -func (s *mockService) FailureCase() error { return nil } diff --git a/pkg/util/grpcclient/ratelimit_test.go b/pkg/util/grpcclient/ratelimit_test.go deleted file mode 100644 index 6a8d6345b9..0000000000 --- a/pkg/util/grpcclient/ratelimit_test.go +++ /dev/null @@ -1,36 +0,0 @@ -package grpcclient_test - -import ( - "context" - "testing" - - "github.com/stretchr/testify/assert" - "google.golang.org/grpc" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/status" - - "github.com/cortexproject/cortex/pkg/util/grpcclient" -) - -func TestRateLimiterFailureResultsInResourceExhaustedError(t *testing.T) { - config := grpcclient.Config{ - RateLimitBurst: 0, - RateLimit: 0, - } - conn := grpc.ClientConn{} - invoker := func(currentCtx context.Context, currentMethod string, currentReq, currentRepl interface{}, currentConn *grpc.ClientConn, currentOpts ...grpc.CallOption) error { - return nil - } - - limiter := grpcclient.NewRateLimiter(&config) - err := limiter(context.Background(), "methodName", "", "expectedReply", &conn, invoker) - - if se, ok := err.(interface { - GRPCStatus() *status.Status - }); ok { - assert.Equal(t, se.GRPCStatus().Code(), codes.ResourceExhausted) - assert.Equal(t, se.GRPCStatus().Message(), "rate: Wait(n=1) exceeds limiter's burst 0") - } else { - assert.Fail(t, "Could not convert error into expected Status type") - } -} diff --git a/pkg/util/grpcutil/carrier.go b/pkg/util/httpgrpcutil/carrier.go similarity index 97% rename from pkg/util/grpcutil/carrier.go rename to pkg/util/httpgrpcutil/carrier.go index 1c6dee7ff5..910b4898b2 100644 --- a/pkg/util/grpcutil/carrier.go +++ b/pkg/util/httpgrpcutil/carrier.go @@ -1,4 +1,4 @@ -package grpcutil +package httpgrpcutil import ( "github.com/opentracing/opentracing-go" diff --git a/pkg/util/tls/test/tls_integration_test.go b/pkg/util/tls/test/tls_integration_test.go deleted file mode 100644 index d599ec9fa0..0000000000 --- a/pkg/util/tls/test/tls_integration_test.go +++ /dev/null @@ -1,567 +0,0 @@ -package test - -import ( - "context" - "crypto/x509" - "crypto/x509/pkix" - "flag" - "fmt" - "io" - "io/ioutil" - "net" - "net/http" - "os" - "path/filepath" - "testing" - - "github.com/gogo/status" - "github.com/prometheus/client_golang/prometheus" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - "github.com/weaveworks/common/server" - "google.golang.org/grpc" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/health/grpc_health_v1" - - "github.com/cortexproject/cortex/integration/ca" - "github.com/cortexproject/cortex/pkg/util/grpcclient" - "github.com/cortexproject/cortex/pkg/util/tls" -) - -type tcIntegrationClientServer struct { - name string - tlsGrpcEnabled bool - tlsConfig tls.ClientConfig - httpExpectError func(*testing.T, error) - grpcExpectError func(*testing.T, error) -} - -type grpcHealthCheck struct { - healthy bool -} - -func (h *grpcHealthCheck) Check(_ context.Context, _ *grpc_health_v1.HealthCheckRequest) (*grpc_health_v1.HealthCheckResponse, error) { - if !h.healthy { - return &grpc_health_v1.HealthCheckResponse{Status: grpc_health_v1.HealthCheckResponse_NOT_SERVING}, nil - } - - return &grpc_health_v1.HealthCheckResponse{Status: grpc_health_v1.HealthCheckResponse_SERVING}, nil -} - -func (h *grpcHealthCheck) Watch(_ *grpc_health_v1.HealthCheckRequest, _ grpc_health_v1.Health_WatchServer) error { - return status.Error(codes.Unimplemented, "Watching is not supported") -} - -func getLocalHostPort() (int, error) { - addr, err := net.ResolveTCPAddr("tcp", "localhost:0") - if err != nil { - return 0, err - } - - l, err := net.ListenTCP("tcp", addr) - if err != nil { - return 0, err - } - - if err := l.Close(); err != nil { - return 0, err - } - return l.Addr().(*net.TCPAddr).Port, nil -} - -func newIntegrationClientServer( - t *testing.T, - cfg server.Config, - tcs []tcIntegrationClientServer, -) { - // server registers some metrics to default registry - savedRegistry := prometheus.DefaultRegisterer - prometheus.DefaultRegisterer = prometheus.NewRegistry() - defer func() { - prometheus.DefaultRegisterer = savedRegistry - }() - - grpcPort, err := getLocalHostPort() - require.NoError(t, err) - httpPort, err := getLocalHostPort() - require.NoError(t, err) - - cfg.HTTPListenPort = httpPort - cfg.GRPCListenPort = grpcPort - - serv, err := server.New(cfg) - require.NoError(t, err) - - serv.HTTP.HandleFunc("/hello", func(w http.ResponseWriter, r *http.Request) { - fmt.Fprintf(w, "OK") - }) - - grpc_health_v1.RegisterHealthServer(serv.GRPC, &grpcHealthCheck{true}) - - go func() { - err := serv.Run() - require.NoError(t, err) - }() - - httpURL := fmt.Sprintf("https://localhost:%d/hello", httpPort) - grpcHost := fmt.Sprintf("localhost:%d", grpcPort) - - for _, tc := range tcs { - tlsClientConfig, err := tc.tlsConfig.GetTLSConfig() - require.NoError(t, err) - - // HTTP - t.Run("HTTP/"+tc.name, func(t *testing.T) { - transport := &http.Transport{TLSClientConfig: tlsClientConfig} - client := &http.Client{Transport: transport} - - resp, err := client.Get(httpURL) - if err == nil { - defer resp.Body.Close() - } - if tc.httpExpectError != nil { - tc.httpExpectError(t, err) - return - } - if err != nil { - assert.NoError(t, err, tc.name) - return - } - body, err := ioutil.ReadAll(resp.Body) - assert.NoError(t, err, tc.name) - - assert.Equal(t, []byte("OK"), body, tc.name) - - }) - - // GRPC - t.Run("GRPC/"+tc.name, func(t *testing.T) { - clientConfig := grpcclient.Config{} - clientConfig.RegisterFlags(flag.NewFlagSet("fake", flag.ContinueOnError)) - - clientConfig.TLSEnabled = tc.tlsGrpcEnabled - clientConfig.TLS = tc.tlsConfig - - dialOptions, err := clientConfig.DialOption(nil, nil) - assert.NoError(t, err, tc.name) - dialOptions = append([]grpc.DialOption{grpc.WithDefaultCallOptions(clientConfig.CallOptions()...)}, dialOptions...) - - conn, err := grpc.Dial(grpcHost, dialOptions...) - assert.NoError(t, err, tc.name) - require.NoError(t, err, tc.name) - require.NoError(t, err, tc.name) - - client := grpc_health_v1.NewHealthClient(conn) - - // TODO: Investigate why the client doesn't really receive the - // error about the bad certificate from the server side and just - // see connection closed instead - resp, err := client.Check(context.TODO(), &grpc_health_v1.HealthCheckRequest{}) - if tc.grpcExpectError != nil { - tc.grpcExpectError(t, err) - return - } - assert.NoError(t, err) - if err == nil { - assert.Equal(t, grpc_health_v1.HealthCheckResponse_SERVING, resp.Status) - } - }) - - } - - serv.Shutdown() -} - -func TestServerWithoutTlsEnabled(t *testing.T) { - cfg := server.Config{} - (&cfg).RegisterFlags(flag.NewFlagSet("fake", flag.ContinueOnError)) - - newIntegrationClientServer( - t, - cfg, - []tcIntegrationClientServer{ - { - name: "no-config", - tlsConfig: tls.ClientConfig{}, - httpExpectError: errorContainsString("http: server gave HTTP response to HTTPS client"), - grpcExpectError: nil, - }, - { - name: "tls-enable", - tlsGrpcEnabled: true, - tlsConfig: tls.ClientConfig{}, - httpExpectError: errorContainsString("http: server gave HTTP response to HTTPS client"), - grpcExpectError: errorContainsString("transport: authentication handshake failed: tls: first record does not look like a TLS handshake"), - }, - }, - ) -} - -func TestServerWithLocalhostCertNoClientCertAuth(t *testing.T) { - certs := setupCertificates(t) - - cfg := server.Config{} - (&cfg).RegisterFlags(flag.NewFlagSet("fake", flag.ContinueOnError)) - - unavailableDescErr := errorContainsString("rpc error: code = Unavailable desc =") - - cfg.HTTPTLSConfig.TLSCertPath = certs.serverCertFile - cfg.HTTPTLSConfig.TLSKeyPath = certs.serverKeyFile - cfg.GRPCTLSConfig.TLSCertPath = certs.serverCertFile - cfg.GRPCTLSConfig.TLSKeyPath = certs.serverKeyFile - - // Test a TLS server with localhost cert without any client certificate enforcement - newIntegrationClientServer( - t, - cfg, - []tcIntegrationClientServer{ - { - name: "no-config", - tlsConfig: tls.ClientConfig{}, - httpExpectError: errorContainsString("x509: certificate signed by unknown authority"), - // For GRPC we expect this error as we try to connect without TLS to a TLS enabled server - grpcExpectError: unavailableDescErr, - }, - { - name: "grpc-tls-enabled", - tlsGrpcEnabled: true, - tlsConfig: tls.ClientConfig{}, - httpExpectError: errorContainsString("x509: certificate signed by unknown authority"), - grpcExpectError: errorContainsString("x509: certificate signed by unknown authority"), - }, - { - name: "tls-skip-verify", - tlsGrpcEnabled: true, - tlsConfig: tls.ClientConfig{ - InsecureSkipVerify: true, - }, - }, - { - name: "tls-skip-verify-no-grpc-tls-enabled", - tlsGrpcEnabled: false, - tlsConfig: tls.ClientConfig{ - InsecureSkipVerify: true, - }, - grpcExpectError: unavailableDescErr, - }, - { - name: "ca-path-set", - tlsGrpcEnabled: true, - tlsConfig: tls.ClientConfig{ - CAPath: certs.caCertFile, - }, - }, - { - name: "ca-path-no-grpc-tls-enabled", - tlsGrpcEnabled: false, - tlsConfig: tls.ClientConfig{ - CAPath: certs.caCertFile, - }, - grpcExpectError: unavailableDescErr, - }, - }, - ) -} - -func TestServerWithoutLocalhostCertNoClientCertAuth(t *testing.T) { - certs := setupCertificates(t) - - cfg := server.Config{} - (&cfg).RegisterFlags(flag.NewFlagSet("fake", flag.ContinueOnError)) - - unavailableDescErr := errorContainsString("rpc error: code = Unavailable desc =") - - // Test a TLS server without localhost cert without any client certificate enforcement - cfg.HTTPTLSConfig.TLSCertPath = certs.serverNoLocalhostCertFile - cfg.HTTPTLSConfig.TLSKeyPath = certs.serverNoLocalhostKeyFile - cfg.GRPCTLSConfig.TLSCertPath = certs.serverNoLocalhostCertFile - cfg.GRPCTLSConfig.TLSKeyPath = certs.serverNoLocalhostKeyFile - newIntegrationClientServer( - t, - cfg, - []tcIntegrationClientServer{ - { - name: "no-config", - tlsConfig: tls.ClientConfig{}, - httpExpectError: errorContainsString("x509: certificate is valid for my-other-name, not localhost"), - // For GRPC we expect this error as we try to connect without TLS to a TLS enabled server - grpcExpectError: unavailableDescErr, - }, - { - name: "grpc-tls-enabled", - tlsGrpcEnabled: true, - tlsConfig: tls.ClientConfig{}, - httpExpectError: errorContainsString("x509: certificate is valid for my-other-name, not localhost"), - grpcExpectError: errorContainsString("x509: certificate is valid for my-other-name, not localhost"), - }, - { - name: "ca-path", - tlsGrpcEnabled: true, - tlsConfig: tls.ClientConfig{ - CAPath: certs.caCertFile, - }, - httpExpectError: errorContainsString("x509: certificate is valid for my-other-name, not localhost"), - grpcExpectError: errorContainsString("x509: certificate is valid for my-other-name, not localhost"), - }, - { - name: "server-name", - tlsGrpcEnabled: true, - tlsConfig: tls.ClientConfig{ - CAPath: certs.caCertFile, - ServerName: "my-other-name", - }, - }, - { - name: "tls-skip-verify", - tlsGrpcEnabled: true, - tlsConfig: tls.ClientConfig{ - InsecureSkipVerify: true, - }, - }, - }, - ) -} - -func TestTLSServerWithLocalhostCertWithClientCertificateEnforcementUsingClientCA1(t *testing.T) { - certs := setupCertificates(t) - - cfg := server.Config{} - (&cfg).RegisterFlags(flag.NewFlagSet("fake", flag.ContinueOnError)) - - unavailableDescErr := errorContainsString("rpc error: code = Unavailable desc =") - - // Test a TLS server with localhost cert with client certificate enforcement through client CA 1 - cfg.HTTPTLSConfig.TLSCertPath = certs.serverCertFile - cfg.HTTPTLSConfig.TLSKeyPath = certs.serverKeyFile - cfg.HTTPTLSConfig.ClientCAs = certs.clientCA1CertFile - cfg.HTTPTLSConfig.ClientAuth = "RequireAndVerifyClientCert" - cfg.GRPCTLSConfig.TLSCertPath = certs.serverCertFile - cfg.GRPCTLSConfig.TLSKeyPath = certs.serverKeyFile - cfg.GRPCTLSConfig.ClientCAs = certs.clientCA1CertFile - cfg.GRPCTLSConfig.ClientAuth = "RequireAndVerifyClientCert" - - // TODO: Investigate why we don't really receive the error about the - // bad certificate from the server side and just see connection - // closed/reset instead - badCertErr := errorContainsString("remote error: tls: bad certificate") - newIntegrationClientServer( - t, - cfg, - []tcIntegrationClientServer{ - { - name: "tls-skip-verify", - tlsGrpcEnabled: true, - tlsConfig: tls.ClientConfig{ - InsecureSkipVerify: true, - }, - httpExpectError: badCertErr, - grpcExpectError: unavailableDescErr, - }, - { - name: "ca-path", - tlsGrpcEnabled: true, - tlsConfig: tls.ClientConfig{ - CAPath: certs.caCertFile, - }, - httpExpectError: badCertErr, - grpcExpectError: unavailableDescErr, - }, - { - name: "ca-path-and-client-cert-ca1", - tlsGrpcEnabled: true, - tlsConfig: tls.ClientConfig{ - CAPath: certs.caCertFile, - CertPath: certs.client1CertFile, - KeyPath: certs.client1KeyFile, - }, - }, - { - name: "tls-skip-verify-and-client-cert-ca1", - tlsGrpcEnabled: true, - tlsConfig: tls.ClientConfig{ - InsecureSkipVerify: true, - CertPath: certs.client1CertFile, - KeyPath: certs.client1KeyFile, - }, - }, - { - name: "ca-cert-and-client-cert-ca2", - tlsGrpcEnabled: true, - tlsConfig: tls.ClientConfig{ - CAPath: certs.caCertFile, - CertPath: certs.client2CertFile, - KeyPath: certs.client2KeyFile, - }, - httpExpectError: badCertErr, - grpcExpectError: unavailableDescErr, - }, - }, - ) -} - -func TestTLSServerWithLocalhostCertWithClientCertificateEnforcementUsingClientCA2(t *testing.T) { - certs := setupCertificates(t) - - cfg := server.Config{} - (&cfg).RegisterFlags(flag.NewFlagSet("fake", flag.ContinueOnError)) - - // Test a TLS server with localhost cert with client certificate enforcement through client CA 1 - cfg.HTTPTLSConfig.TLSCertPath = certs.serverCertFile - cfg.HTTPTLSConfig.TLSKeyPath = certs.serverKeyFile - cfg.HTTPTLSConfig.ClientCAs = certs.clientCABothCertFile - cfg.HTTPTLSConfig.ClientAuth = "RequireAndVerifyClientCert" - cfg.GRPCTLSConfig.TLSCertPath = certs.serverCertFile - cfg.GRPCTLSConfig.TLSKeyPath = certs.serverKeyFile - cfg.GRPCTLSConfig.ClientCAs = certs.clientCABothCertFile - cfg.GRPCTLSConfig.ClientAuth = "RequireAndVerifyClientCert" - - newIntegrationClientServer( - t, - cfg, - []tcIntegrationClientServer{ - { - name: "ca-cert-and-client-cert-ca1", - tlsGrpcEnabled: true, - tlsConfig: tls.ClientConfig{ - CAPath: certs.caCertFile, - CertPath: certs.client1CertFile, - KeyPath: certs.client1KeyFile, - }, - }, - { - name: "ca-cert-and-client-cert-ca2", - tlsGrpcEnabled: true, - tlsConfig: tls.ClientConfig{ - CAPath: certs.caCertFile, - CertPath: certs.client2CertFile, - KeyPath: certs.client2KeyFile, - }, - }, - }, - ) -} - -func setupCertificates(t *testing.T) keyMaterial { - testCADir, err := ioutil.TempDir("", "cortex-ca") - require.NoError(t, err) - t.Cleanup(func() { - require.NoError(t, os.RemoveAll(testCADir)) - }) - - // create server side CA - - testCA := ca.New("Cortex Test") - caCertFile := filepath.Join(testCADir, "ca.crt") - require.NoError(t, testCA.WriteCACertificate(caCertFile)) - - serverCertFile := filepath.Join(testCADir, "server.crt") - serverKeyFile := filepath.Join(testCADir, "server.key") - require.NoError(t, testCA.WriteCertificate( - &x509.Certificate{ - Subject: pkix.Name{CommonName: "server"}, - DNSNames: []string{"localhost", "my-other-name"}, - ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth}, - }, - serverCertFile, - serverKeyFile, - )) - - serverNoLocalhostCertFile := filepath.Join(testCADir, "server-no-localhost.crt") - serverNoLocalhostKeyFile := filepath.Join(testCADir, "server-no-localhost.key") - require.NoError(t, testCA.WriteCertificate( - &x509.Certificate{ - Subject: pkix.Name{CommonName: "server-no-localhost"}, - DNSNames: []string{"my-other-name"}, - ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth}, - }, - serverNoLocalhostCertFile, - serverNoLocalhostKeyFile, - )) - - // create client CAs - testClientCA1 := ca.New("Cortex Test Client CA 1") - testClientCA2 := ca.New("Cortex Test Client CA 2") - - clientCA1CertFile := filepath.Join(testCADir, "ca-client-1.crt") - require.NoError(t, testClientCA1.WriteCACertificate(clientCA1CertFile)) - clientCA2CertFile := filepath.Join(testCADir, "ca-client-2.crt") - require.NoError(t, testClientCA2.WriteCACertificate(clientCA2CertFile)) - - // create a ca file with both certs - clientCABothCertFile := filepath.Join(testCADir, "ca-client-both.crt") - func() { - src1, err := os.Open(clientCA1CertFile) - require.NoError(t, err) - defer src1.Close() - src2, err := os.Open(clientCA2CertFile) - require.NoError(t, err) - defer src2.Close() - - dst, err := os.Create(clientCABothCertFile) - require.NoError(t, err) - defer dst.Close() - - _, err = io.Copy(dst, src1) - require.NoError(t, err) - _, err = io.Copy(dst, src2) - require.NoError(t, err) - - }() - - client1CertFile := filepath.Join(testCADir, "client-1.crt") - client1KeyFile := filepath.Join(testCADir, "client-1.key") - require.NoError(t, testClientCA1.WriteCertificate( - &x509.Certificate{ - Subject: pkix.Name{CommonName: "client-1"}, - ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageClientAuth}, - }, - client1CertFile, - client1KeyFile, - )) - - client2CertFile := filepath.Join(testCADir, "client-2.crt") - client2KeyFile := filepath.Join(testCADir, "client-2.key") - require.NoError(t, testClientCA2.WriteCertificate( - &x509.Certificate{ - Subject: pkix.Name{CommonName: "client-2"}, - ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageClientAuth}, - }, - client2CertFile, - client2KeyFile, - )) - - return keyMaterial{ - caCertFile: caCertFile, - serverCertFile: serverCertFile, - serverKeyFile: serverKeyFile, - serverNoLocalhostCertFile: serverNoLocalhostCertFile, - serverNoLocalhostKeyFile: serverNoLocalhostKeyFile, - clientCA1CertFile: clientCA1CertFile, - clientCABothCertFile: clientCABothCertFile, - client1CertFile: client1CertFile, - client1KeyFile: client1KeyFile, - client2CertFile: client2CertFile, - client2KeyFile: client2KeyFile, - } -} - -type keyMaterial struct { - caCertFile string - serverCertFile string - serverKeyFile string - serverNoLocalhostCertFile string - serverNoLocalhostKeyFile string - clientCA1CertFile string - clientCABothCertFile string - client1CertFile string - client1KeyFile string - client2CertFile string - client2KeyFile string -} - -func errorContainsString(str string) func(*testing.T, error) { - return func(t *testing.T, err error) { - require.Error(t, err) - assert.Contains(t, err.Error(), str) - } -} diff --git a/pkg/util/tls/tls_test.go b/pkg/util/tls/tls_test.go deleted file mode 100644 index 478ae02fc6..0000000000 --- a/pkg/util/tls/tls_test.go +++ /dev/null @@ -1,190 +0,0 @@ -package tls - -import ( - "fmt" - "io/ioutil" - "os" - "testing" - - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" -) - -// certPEM and keyPEM are copied from the golang crypto/tls library -// https://github.com/golang/go/blob/7eb5941b95a588a23f18fa4c22fe42ff0119c311/src/crypto/tls/example_test.go#L127 -const certPEM = `-----BEGIN CERTIFICATE----- -MIIBhTCCASugAwIBAgIQIRi6zePL6mKjOipn+dNuaTAKBggqhkjOPQQDAjASMRAw -DgYDVQQKEwdBY21lIENvMB4XDTE3MTAyMDE5NDMwNloXDTE4MTAyMDE5NDMwNlow -EjEQMA4GA1UEChMHQWNtZSBDbzBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABD0d -7VNhbWvZLWPuj/RtHFjvtJBEwOkhbN/BnnE8rnZR8+sbwnc/KhCk3FhnpHZnQz7B -5aETbbIgmuvewdjvSBSjYzBhMA4GA1UdDwEB/wQEAwICpDATBgNVHSUEDDAKBggr -BgEFBQcDATAPBgNVHRMBAf8EBTADAQH/MCkGA1UdEQQiMCCCDmxvY2FsaG9zdDo1 -NDUzgg4xMjcuMC4wLjE6NTQ1MzAKBggqhkjOPQQDAgNIADBFAiEA2zpJEPQyz6/l -Wf86aX6PepsntZv2GYlA5UpabfT2EZICICpJ5h/iI+i341gBmLiAFQOyTDT+/wQc -6MF9+Yw1Yy0t ------END CERTIFICATE-----` -const keyPEM = `-----BEGIN EC PRIVATE KEY----- -MHcCAQEEIIrYSSNQFaA2Hwf1duRSxKtLYX5CB04fSeQ6tF1aY/PuoAoGCCqGSM49 -AwEHoUQDQgAEPR3tU2Fta9ktY+6P9G0cWO+0kETA6SFs38GecTyudlHz6xvCdz8q -EKTcWGekdmdDPsHloRNtsiCa697B2O9IFA== ------END EC PRIVATE KEY-----` - -// caPEM is CA certificate of Let's Encrypt -// https://letsencrypt.org/certs/isrgrootx1.pem.txt -const caPEM = `-----BEGIN CERTIFICATE----- -MIIFazCCA1OgAwIBAgIRAIIQz7DSQONZRGPgu2OCiwAwDQYJKoZIhvcNAQELBQAw -TzELMAkGA1UEBhMCVVMxKTAnBgNVBAoTIEludGVybmV0IFNlY3VyaXR5IFJlc2Vh -cmNoIEdyb3VwMRUwEwYDVQQDEwxJU1JHIFJvb3QgWDEwHhcNMTUwNjA0MTEwNDM4 -WhcNMzUwNjA0MTEwNDM4WjBPMQswCQYDVQQGEwJVUzEpMCcGA1UEChMgSW50ZXJu -ZXQgU2VjdXJpdHkgUmVzZWFyY2ggR3JvdXAxFTATBgNVBAMTDElTUkcgUm9vdCBY -MTCCAiIwDQYJKoZIhvcNAQEBBQADggIPADCCAgoCggIBAK3oJHP0FDfzm54rVygc -h77ct984kIxuPOZXoHj3dcKi/vVqbvYATyjb3miGbESTtrFj/RQSa78f0uoxmyF+ -0TM8ukj13Xnfs7j/EvEhmkvBioZxaUpmZmyPfjxwv60pIgbz5MDmgK7iS4+3mX6U -A5/TR5d8mUgjU+g4rk8Kb4Mu0UlXjIB0ttov0DiNewNwIRt18jA8+o+u3dpjq+sW -T8KOEUt+zwvo/7V3LvSye0rgTBIlDHCNAymg4VMk7BPZ7hm/ELNKjD+Jo2FR3qyH -B5T0Y3HsLuJvW5iB4YlcNHlsdu87kGJ55tukmi8mxdAQ4Q7e2RCOFvu396j3x+UC -B5iPNgiV5+I3lg02dZ77DnKxHZu8A/lJBdiB3QW0KtZB6awBdpUKD9jf1b0SHzUv -KBds0pjBqAlkd25HN7rOrFleaJ1/ctaJxQZBKT5ZPt0m9STJEadao0xAH0ahmbWn -OlFuhjuefXKnEgV4We0+UXgVCwOPjdAvBbI+e0ocS3MFEvzG6uBQE3xDk3SzynTn -jh8BCNAw1FtxNrQHusEwMFxIt4I7mKZ9YIqioymCzLq9gwQbooMDQaHWBfEbwrbw -qHyGO0aoSCqI3Haadr8faqU9GY/rOPNk3sgrDQoo//fb4hVC1CLQJ13hef4Y53CI -rU7m2Ys6xt0nUW7/vGT1M0NPAgMBAAGjQjBAMA4GA1UdDwEB/wQEAwIBBjAPBgNV -HRMBAf8EBTADAQH/MB0GA1UdDgQWBBR5tFnme7bl5AFzgAiIyBpY9umbbjANBgkq -hkiG9w0BAQsFAAOCAgEAVR9YqbyyqFDQDLHYGmkgJykIrGF1XIpu+ILlaS/V9lZL -ubhzEFnTIZd+50xx+7LSYK05qAvqFyFWhfFQDlnrzuBZ6brJFe+GnY+EgPbk6ZGQ -3BebYhtF8GaV0nxvwuo77x/Py9auJ/GpsMiu/X1+mvoiBOv/2X/qkSsisRcOj/KK -NFtY2PwByVS5uCbMiogziUwthDyC3+6WVwW6LLv3xLfHTjuCvjHIInNzktHCgKQ5 -ORAzI4JMPJ+GslWYHb4phowim57iaztXOoJwTdwJx4nLCgdNbOhdjsnvzqvHu7Ur -TkXWStAmzOVyyghqpZXjFaH3pO3JLF+l+/+sKAIuvtd7u+Nxe5AW0wdeRlN8NwdC -jNPElpzVmbUq4JUagEiuTDkHzsxHpFKVK7q4+63SM1N95R1NbdWhscdCb+ZAJzVc -oyi3B43njTOQ5yOf+1CceWxG1bQVs5ZufpsMljq4Ui0/1lvh+wjChP4kqKOJ2qxq -4RgqsahDYVvTH9w7jXbyLeiNdd8XM2w9U/t7y0Ff/9yi0GE44Za4rF2LN9d11TPA -mRGunUHBcnWEvgJBQl9nJEiU0Zsnvgc/ubhPgXRR4Xq37Z0j4r7g1SgEEzwxA57d -emyPxgcYxn/eR44/KJ4EBs+lVDR3veyJm+kXQ99b21/+jh5Xos1AnX5iItreGCc= ------END CERTIFICATE-----` - -type x509Paths struct { - cert string - key string - ca string -} - -func newTestX509Files(t *testing.T, cert, key, ca []byte) x509Paths { - - // create empty file - certsPath, err := ioutil.TempDir("", "*-x509") - require.NoError(t, err) - - t.Cleanup(func() { - os.RemoveAll(certsPath) - }) - - paths := x509Paths{ - cert: fmt.Sprintf("%s/cert.pem", certsPath), - key: fmt.Sprintf("%s/key.pem", certsPath), - ca: fmt.Sprintf("%s/ca.pem", certsPath), - } - - if cert != nil { - err = ioutil.WriteFile(paths.cert, cert, 0600) - require.NoError(t, err) - } - - if key != nil { - err = ioutil.WriteFile(paths.key, key, 0600) - require.NoError(t, err) - } - - if ca != nil { - err = ioutil.WriteFile(paths.ca, ca, 0600) - require.NoError(t, err) - } - - return paths -} - -func TestGetTLSConfig_ClientCerts(t *testing.T) { - paths := newTestX509Files(t, []byte(certPEM), []byte(keyPEM), nil) - - // test working certificate passed - c := &ClientConfig{ - CertPath: paths.cert, - KeyPath: paths.key, - } - tlsConfig, err := c.GetTLSConfig() - assert.NoError(t, err) - assert.Equal(t, false, tlsConfig.InsecureSkipVerify, "make sure we default to not skip verification") - assert.Equal(t, 1, len(tlsConfig.Certificates), "ensure a certificate is returned") - - // expect error with key and cert swapped passed along - c = &ClientConfig{ - CertPath: paths.key, - KeyPath: paths.cert, - } - _, err = c.GetTLSConfig() - assert.Error(t, err) - assert.Contains(t, err.Error(), "failed to find certificate PEM data in certificate input, but did find a private key") - - // expect error with only key passed along - c = &ClientConfig{ - KeyPath: paths.key, - } - _, err = c.GetTLSConfig() - assert.EqualError(t, err, errCertMissing.Error()) - - // expect error with only cert passed along - c = &ClientConfig{ - CertPath: paths.cert, - } - _, err = c.GetTLSConfig() - assert.EqualError(t, err, errKeyMissing.Error()) -} - -func TestGetTLSConfig_CA(t *testing.T) { - paths := newTestX509Files(t, nil, nil, []byte(certPEM)) - - // test single ca passed - c := &ClientConfig{ - CAPath: paths.ca, - } - tlsConfig, err := c.GetTLSConfig() - assert.NoError(t, err) - assert.Equal(t, 1, len(tlsConfig.RootCAs.Subjects()), "ensure one CA is returned") - assert.Equal(t, false, tlsConfig.InsecureSkipVerify, "make sure we default to not skip verification") - - // test two cas passed - paths = newTestX509Files(t, nil, nil, []byte(certPEM+"\n"+caPEM)) - c = &ClientConfig{ - CAPath: paths.ca, - } - tlsConfig, err = c.GetTLSConfig() - assert.NoError(t, err) - assert.Equal(t, 2, len(tlsConfig.RootCAs.Subjects()), "ensure two CAs are returned") - assert.False(t, tlsConfig.InsecureSkipVerify, "make sure we default to not skip verification") - - // expect errors to be passed - c = &ClientConfig{ - CAPath: paths.ca + "not-existing", - } - _, err = c.GetTLSConfig() - assert.Error(t, err) - assert.Contains(t, err.Error(), "error loading ca cert") -} - -func TestGetTLSConfig_InsecureSkipVerify(t *testing.T) { - c := &ClientConfig{ - InsecureSkipVerify: true, - } - tlsConfig, err := c.GetTLSConfig() - assert.NoError(t, err) - assert.True(t, tlsConfig.InsecureSkipVerify) -} - -func TestGetTLSConfig_ServerName(t *testing.T) { - c := &ClientConfig{ - ServerName: "myserver.com", - } - tlsConfig, err := c.GetTLSConfig() - assert.NoError(t, err) - assert.Equal(t, "myserver.com", tlsConfig.ServerName) -} diff --git a/tools/blocksconvert/planprocessor/service.go b/tools/blocksconvert/planprocessor/service.go index 5b0bec17d1..db4474d4dd 100644 --- a/tools/blocksconvert/planprocessor/service.go +++ b/tools/blocksconvert/planprocessor/service.go @@ -14,6 +14,7 @@ import ( "github.com/go-kit/log" "github.com/go-kit/log/level" + "github.com/grafana/dskit/grpcclient" "github.com/grafana/dskit/services" "github.com/pkg/errors" "github.com/prometheus/client_golang/prometheus" @@ -22,7 +23,6 @@ import ( "golang.org/x/sync/errgroup" "google.golang.org/grpc" - "github.com/cortexproject/cortex/pkg/util/grpcclient" "github.com/cortexproject/cortex/tools/blocksconvert" ) diff --git a/vendor/github.com/coreos/etcd/pkg/fileutil/dir_unix.go b/vendor/github.com/coreos/etcd/pkg/fileutil/dir_unix.go index 58a77dfc1a..4ce15dc6bc 100644 --- a/vendor/github.com/coreos/etcd/pkg/fileutil/dir_unix.go +++ b/vendor/github.com/coreos/etcd/pkg/fileutil/dir_unix.go @@ -18,5 +18,10 @@ package fileutil import "os" +const ( + // PrivateDirMode grants owner to make/remove files inside the directory. + PrivateDirMode = 0700 +) + // OpenDir opens a directory for syncing. func OpenDir(path string) (*os.File, error) { return os.Open(path) } diff --git a/vendor/github.com/coreos/etcd/pkg/fileutil/dir_windows.go b/vendor/github.com/coreos/etcd/pkg/fileutil/dir_windows.go index c123395c00..a10a90583c 100644 --- a/vendor/github.com/coreos/etcd/pkg/fileutil/dir_windows.go +++ b/vendor/github.com/coreos/etcd/pkg/fileutil/dir_windows.go @@ -21,6 +21,11 @@ import ( "syscall" ) +const ( + // PrivateDirMode grants owner to make/remove files inside the directory. + PrivateDirMode = 0777 +) + // OpenDir opens a directory in windows with write access for syncing. func OpenDir(path string) (*os.File, error) { fd, err := openDir(path) diff --git a/vendor/github.com/coreos/etcd/pkg/fileutil/fileutil.go b/vendor/github.com/coreos/etcd/pkg/fileutil/fileutil.go index fce5126c69..3c73916a1e 100644 --- a/vendor/github.com/coreos/etcd/pkg/fileutil/fileutil.go +++ b/vendor/github.com/coreos/etcd/pkg/fileutil/fileutil.go @@ -29,8 +29,6 @@ import ( const ( // PrivateFileMode grants owner to read/write a file. PrivateFileMode = 0600 - // PrivateDirMode grants owner to make/remove files inside the directory. - PrivateDirMode = 0700 ) var ( @@ -65,14 +63,22 @@ func ReadDir(dirpath string) ([]string, error) { // TouchDirAll is similar to os.MkdirAll. It creates directories with 0700 permission if any directory // does not exists. TouchDirAll also ensures the given directory is writable. func TouchDirAll(dir string) error { - // If path is already a directory, MkdirAll does nothing - // and returns nil. - err := os.MkdirAll(dir, PrivateDirMode) - if err != nil { - // if mkdirAll("a/text") and "text" is not - // a directory, this will return syscall.ENOTDIR - return err + // If path is already a directory, MkdirAll does nothing and returns nil, so, + // first check if dir exist with an expected permission mode. + if Exist(dir) { + err := CheckDirPermission(dir, PrivateDirMode) + if err != nil { + plog.Warningf("check file permission: %v", err) + } + } else { + err := os.MkdirAll(dir, PrivateDirMode) + if err != nil { + // if mkdirAll("a/text") and "text" is not + // a directory, this will return syscall.ENOTDIR + return err + } } + return IsDirWriteable(dir) } @@ -120,3 +126,22 @@ func ZeroToEnd(f *os.File) error { _, err = f.Seek(off, io.SeekStart) return err } + +// CheckDirPermission checks permission on an existing dir. +// Returns error if dir is empty or exist with a different permission than specified. +func CheckDirPermission(dir string, perm os.FileMode) error { + if !Exist(dir) { + return fmt.Errorf("directory %q empty, cannot check permission.", dir) + } + //check the existing permission on the directory + dirInfo, err := os.Stat(dir) + if err != nil { + return err + } + dirMode := dirInfo.Mode().Perm() + if dirMode != perm { + err = fmt.Errorf("directory %q exist, but the permission is %q. The recommended permission is %q to prevent possible unprivileged access to the data.", dir, dirInfo.Mode(), os.FileMode(PrivateDirMode)) + return err + } + return nil +} diff --git a/vendor/github.com/coreos/etcd/pkg/fileutil/purge.go b/vendor/github.com/coreos/etcd/pkg/fileutil/purge.go index 92fceab017..c973680691 100644 --- a/vendor/github.com/coreos/etcd/pkg/fileutil/purge.go +++ b/vendor/github.com/coreos/etcd/pkg/fileutil/purge.go @@ -23,13 +23,23 @@ import ( ) func PurgeFile(dirname string, suffix string, max uint, interval time.Duration, stop <-chan struct{}) <-chan error { - return purgeFile(dirname, suffix, max, interval, stop, nil) + return purgeFile(dirname, suffix, max, interval, stop, nil, nil) +} + +func PurgeFileWithDoneNotify(dirname string, suffix string, max uint, interval time.Duration, stop <-chan struct{}) (<-chan struct{}, <-chan error) { + doneC := make(chan struct{}) + errC := purgeFile(dirname, suffix, max, interval, stop, nil, doneC) + return doneC, errC } // purgeFile is the internal implementation for PurgeFile which can post purged files to purgec if non-nil. -func purgeFile(dirname string, suffix string, max uint, interval time.Duration, stop <-chan struct{}, purgec chan<- string) <-chan error { +// if donec is non-nil, the function closes it to notify its exit. +func purgeFile(dirname string, suffix string, max uint, interval time.Duration, stop <-chan struct{}, purgec chan<- string, donec chan<- struct{}) <-chan error { errC := make(chan error, 1) go func() { + if donec != nil { + defer close(donec) + } for { fnames, err := ReadDir(dirname) if err != nil { diff --git a/vendor/github.com/form3tech-oss/jwt-go/.gitignore b/vendor/github.com/form3tech-oss/jwt-go/.gitignore deleted file mode 100644 index c0e81a8d92..0000000000 --- a/vendor/github.com/form3tech-oss/jwt-go/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -.DS_Store -bin -.idea/ - - diff --git a/vendor/github.com/form3tech-oss/jwt-go/.travis.yml b/vendor/github.com/form3tech-oss/jwt-go/.travis.yml deleted file mode 100644 index 3c7fb7e1ae..0000000000 --- a/vendor/github.com/form3tech-oss/jwt-go/.travis.yml +++ /dev/null @@ -1,12 +0,0 @@ -language: go - -script: - - go vet ./... - - go test -v ./... - -go: - - 1.12 - - 1.13 - - 1.14 - - 1.15 - - tip diff --git a/vendor/github.com/form3tech-oss/jwt-go/LICENSE b/vendor/github.com/form3tech-oss/jwt-go/LICENSE deleted file mode 100644 index df83a9c2f0..0000000000 --- a/vendor/github.com/form3tech-oss/jwt-go/LICENSE +++ /dev/null @@ -1,8 +0,0 @@ -Copyright (c) 2012 Dave Grijalva - -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: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -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. - diff --git a/vendor/github.com/form3tech-oss/jwt-go/MIGRATION_GUIDE.md b/vendor/github.com/form3tech-oss/jwt-go/MIGRATION_GUIDE.md deleted file mode 100644 index 7fc1f793cb..0000000000 --- a/vendor/github.com/form3tech-oss/jwt-go/MIGRATION_GUIDE.md +++ /dev/null @@ -1,97 +0,0 @@ -## Migration Guide from v2 -> v3 - -Version 3 adds several new, frequently requested features. To do so, it introduces a few breaking changes. We've worked to keep these as minimal as possible. This guide explains the breaking changes and how you can quickly update your code. - -### `Token.Claims` is now an interface type - -The most requested feature from the 2.0 verison of this library was the ability to provide a custom type to the JSON parser for claims. This was implemented by introducing a new interface, `Claims`, to replace `map[string]interface{}`. We also included two concrete implementations of `Claims`: `MapClaims` and `StandardClaims`. - -`MapClaims` is an alias for `map[string]interface{}` with built in validation behavior. It is the default claims type when using `Parse`. The usage is unchanged except you must type cast the claims property. - -The old example for parsing a token looked like this.. - -```go - if token, err := jwt.Parse(tokenString, keyLookupFunc); err == nil { - fmt.Printf("Token for user %v expires %v", token.Claims["user"], token.Claims["exp"]) - } -``` - -is now directly mapped to... - -```go - if token, err := jwt.Parse(tokenString, keyLookupFunc); err == nil { - claims := token.Claims.(jwt.MapClaims) - fmt.Printf("Token for user %v expires %v", claims["user"], claims["exp"]) - } -``` - -`StandardClaims` is designed to be embedded in your custom type. You can supply a custom claims type with the new `ParseWithClaims` function. Here's an example of using a custom claims type. - -```go - type MyCustomClaims struct { - User string - *StandardClaims - } - - if token, err := jwt.ParseWithClaims(tokenString, &MyCustomClaims{}, keyLookupFunc); err == nil { - claims := token.Claims.(*MyCustomClaims) - fmt.Printf("Token for user %v expires %v", claims.User, claims.StandardClaims.ExpiresAt) - } -``` - -### `ParseFromRequest` has been moved - -To keep this library focused on the tokens without becoming overburdened with complex request processing logic, `ParseFromRequest` and its new companion `ParseFromRequestWithClaims` have been moved to a subpackage, `request`. The method signatues have also been augmented to receive a new argument: `Extractor`. - -`Extractors` do the work of picking the token string out of a request. The interface is simple and composable. - -This simple parsing example: - -```go - if token, err := jwt.ParseFromRequest(tokenString, req, keyLookupFunc); err == nil { - fmt.Printf("Token for user %v expires %v", token.Claims["user"], token.Claims["exp"]) - } -``` - -is directly mapped to: - -```go - if token, err := request.ParseFromRequest(req, request.OAuth2Extractor, keyLookupFunc); err == nil { - claims := token.Claims.(jwt.MapClaims) - fmt.Printf("Token for user %v expires %v", claims["user"], claims["exp"]) - } -``` - -There are several concrete `Extractor` types provided for your convenience: - -* `HeaderExtractor` will search a list of headers until one contains content. -* `ArgumentExtractor` will search a list of keys in request query and form arguments until one contains content. -* `MultiExtractor` will try a list of `Extractors` in order until one returns content. -* `AuthorizationHeaderExtractor` will look in the `Authorization` header for a `Bearer` token. -* `OAuth2Extractor` searches the places an OAuth2 token would be specified (per the spec): `Authorization` header and `access_token` argument -* `PostExtractionFilter` wraps an `Extractor`, allowing you to process the content before it's parsed. A simple example is stripping the `Bearer ` text from a header - - -### RSA signing methods no longer accept `[]byte` keys - -Due to a [critical vulnerability](https://auth0.com/blog/2015/03/31/critical-vulnerabilities-in-json-web-token-libraries/), we've decided the convenience of accepting `[]byte` instead of `rsa.PublicKey` or `rsa.PrivateKey` isn't worth the risk of misuse. - -To replace this behavior, we've added two helper methods: `ParseRSAPrivateKeyFromPEM(key []byte) (*rsa.PrivateKey, error)` and `ParseRSAPublicKeyFromPEM(key []byte) (*rsa.PublicKey, error)`. These are just simple helpers for unpacking PEM encoded PKCS1 and PKCS8 keys. If your keys are encoded any other way, all you need to do is convert them to the `crypto/rsa` package's types. - -```go - func keyLookupFunc(*Token) (interface{}, error) { - // Don't forget to validate the alg is what you expect: - if _, ok := token.Method.(*jwt.SigningMethodRSA); !ok { - return nil, fmt.Errorf("Unexpected signing method: %v", token.Header["alg"]) - } - - // Look up key - key, err := lookupPublicKey(token.Header["kid"]) - if err != nil { - return nil, err - } - - // Unpack key from PEM encoded PKCS8 - return jwt.ParseRSAPublicKeyFromPEM(key) - } -``` diff --git a/vendor/github.com/form3tech-oss/jwt-go/README.md b/vendor/github.com/form3tech-oss/jwt-go/README.md deleted file mode 100644 index d7749077fd..0000000000 --- a/vendor/github.com/form3tech-oss/jwt-go/README.md +++ /dev/null @@ -1,104 +0,0 @@ -# jwt-go - -[![Build Status](https://travis-ci.org/dgrijalva/jwt-go.svg?branch=master)](https://travis-ci.org/dgrijalva/jwt-go) -[![GoDoc](https://godoc.org/github.com/dgrijalva/jwt-go?status.svg)](https://godoc.org/github.com/dgrijalva/jwt-go) - -A [go](http://www.golang.org) (or 'golang' for search engine friendliness) implementation of [JSON Web Tokens](http://self-issued.info/docs/draft-ietf-oauth-json-web-token.html) - -**NEW VERSION COMING:** There have been a lot of improvements suggested since the version 3.0.0 released in 2016. I'm working now on cutting two different releases: 3.2.0 will contain any non-breaking changes or enhancements. 4.0.0 will follow shortly which will include breaking changes. See the 4.0.0 milestone to get an idea of what's coming. If you have other ideas, or would like to participate in 4.0.0, now's the time. If you depend on this library and don't want to be interrupted, I recommend you use your dependency mangement tool to pin to version 3. - -**SECURITY NOTICE:** Some older versions of Go have a security issue in the cryotp/elliptic. Recommendation is to upgrade to at least 1.8.3. See issue #216 for more detail. - -**SECURITY NOTICE:** It's important that you [validate the `alg` presented is what you expect](https://auth0.com/blog/critical-vulnerabilities-in-json-web-token-libraries/). This library attempts to make it easy to do the right thing by requiring key types match the expected alg, but you should take the extra step to verify it in your usage. See the examples provided. - -## What the heck is a JWT? - -JWT.io has [a great introduction](https://jwt.io/introduction) to JSON Web Tokens. - -In short, it's a signed JSON object that does something useful (for example, authentication). It's commonly used for `Bearer` tokens in Oauth 2. A token is made of three parts, separated by `.`'s. The first two parts are JSON objects, that have been [base64url](http://tools.ietf.org/html/rfc4648) encoded. The last part is the signature, encoded the same way. - -The first part is called the header. It contains the necessary information for verifying the last part, the signature. For example, which encryption method was used for signing and what key was used. - -The part in the middle is the interesting bit. It's called the Claims and contains the actual stuff you care about. Refer to [the RFC](http://self-issued.info/docs/draft-ietf-oauth-json-web-token.html) for information about reserved keys and the proper way to add your own. - -## What's in the box? - -This library supports the parsing and verification as well as the generation and signing of JWTs. Current supported signing algorithms are HMAC SHA, RSA, RSA-PSS, and ECDSA, though hooks are present for adding your own. - -## Examples - -See [the project documentation](https://godoc.org/github.com/dgrijalva/jwt-go) for examples of usage: - -* [Simple example of parsing and validating a token](https://godoc.org/github.com/dgrijalva/jwt-go#example-Parse--Hmac) -* [Simple example of building and signing a token](https://godoc.org/github.com/dgrijalva/jwt-go#example-New--Hmac) -* [Directory of Examples](https://godoc.org/github.com/dgrijalva/jwt-go#pkg-examples) - -## Extensions - -This library publishes all the necessary components for adding your own signing methods. Simply implement the `SigningMethod` interface and register a factory method using `RegisterSigningMethod`. - -Here's an example of an extension that integrates with multiple Google Cloud Platform signing tools (AppEngine, IAM API, Cloud KMS): https://github.com/someone1/gcp-jwt-go - -## Compliance - -This library was last reviewed to comply with [RTF 7519](http://www.rfc-editor.org/info/rfc7519) dated May 2015 with a few notable differences: - -* In order to protect against accidental use of [Unsecured JWTs](http://self-issued.info/docs/draft-ietf-oauth-json-web-token.html#UnsecuredJWT), tokens using `alg=none` will only be accepted if the constant `jwt.UnsafeAllowNoneSignatureType` is provided as the key. - -## Project Status & Versioning - -This library is considered production ready. Feedback and feature requests are appreciated. The API should be considered stable. There should be very few backwards-incompatible changes outside of major version updates (and only with good reason). - -This project uses [Semantic Versioning 2.0.0](http://semver.org). Accepted pull requests will land on `master`. Periodically, versions will be tagged from `master`. You can find all the releases on [the project releases page](https://github.com/dgrijalva/jwt-go/releases). - -While we try to make it obvious when we make breaking changes, there isn't a great mechanism for pushing announcements out to users. You may want to use this alternative package include: `gopkg.in/dgrijalva/jwt-go.v3`. It will do the right thing WRT semantic versioning. - -**BREAKING CHANGES:*** -* Version 3.0.0 includes _a lot_ of changes from the 2.x line, including a few that break the API. We've tried to break as few things as possible, so there should just be a few type signature changes. A full list of breaking changes is available in `VERSION_HISTORY.md`. See `MIGRATION_GUIDE.md` for more information on updating your code. - -## Usage Tips - -### Signing vs Encryption - -A token is simply a JSON object that is signed by its author. this tells you exactly two things about the data: - -* The author of the token was in the possession of the signing secret -* The data has not been modified since it was signed - -It's important to know that JWT does not provide encryption, which means anyone who has access to the token can read its contents. If you need to protect (encrypt) the data, there is a companion spec, `JWE`, that provides this functionality. JWE is currently outside the scope of this library. - -### Choosing a Signing Method - -There are several signing methods available, and you should probably take the time to learn about the various options before choosing one. The principal design decision is most likely going to be symmetric vs asymmetric. - -Symmetric signing methods, such as HSA, use only a single secret. This is probably the simplest signing method to use since any `[]byte` can be used as a valid secret. They are also slightly computationally faster to use, though this rarely is enough to matter. Symmetric signing methods work the best when both producers and consumers of tokens are trusted, or even the same system. Since the same secret is used to both sign and validate tokens, you can't easily distribute the key for validation. - -Asymmetric signing methods, such as RSA, use different keys for signing and verifying tokens. This makes it possible to produce tokens with a private key, and allow any consumer to access the public key for verification. - -### Signing Methods and Key Types - -Each signing method expects a different object type for its signing keys. See the package documentation for details. Here are the most common ones: - -* The [HMAC signing method](https://godoc.org/github.com/dgrijalva/jwt-go#SigningMethodHMAC) (`HS256`,`HS384`,`HS512`) expect `[]byte` values for signing and validation -* The [RSA signing method](https://godoc.org/github.com/dgrijalva/jwt-go#SigningMethodRSA) (`RS256`,`RS384`,`RS512`) expect `*rsa.PrivateKey` for signing and `*rsa.PublicKey` for validation -* The [ECDSA signing method](https://godoc.org/github.com/dgrijalva/jwt-go#SigningMethodECDSA) (`ES256`,`ES384`,`ES512`) expect `*ecdsa.PrivateKey` for signing and `*ecdsa.PublicKey` for validation - -### JWT and OAuth - -It's worth mentioning that OAuth and JWT are not the same thing. A JWT token is simply a signed JSON object. It can be used anywhere such a thing is useful. There is some confusion, though, as JWT is the most common type of bearer token used in OAuth2 authentication. - -Without going too far down the rabbit hole, here's a description of the interaction of these technologies: - -* OAuth is a protocol for allowing an identity provider to be separate from the service a user is logging in to. For example, whenever you use Facebook to log into a different service (Yelp, Spotify, etc), you are using OAuth. -* OAuth defines several options for passing around authentication data. One popular method is called a "bearer token". A bearer token is simply a string that _should_ only be held by an authenticated user. Thus, simply presenting this token proves your identity. You can probably derive from here why a JWT might make a good bearer token. -* Because bearer tokens are used for authentication, it's important they're kept secret. This is why transactions that use bearer tokens typically happen over SSL. - -### Troubleshooting - -This library uses descriptive error messages whenever possible. If you are not getting the expected result, have a look at the errors. The most common place people get stuck is providing the correct type of key to the parser. See the above section on signing methods and key types. - -## More - -Documentation can be found [on godoc.org](http://godoc.org/github.com/dgrijalva/jwt-go). - -The command line utility included in this project (cmd/jwt) provides a straightforward example of token creation and parsing as well as a useful tool for debugging your own integration. You'll also find several implementation examples in the documentation. diff --git a/vendor/github.com/form3tech-oss/jwt-go/VERSION_HISTORY.md b/vendor/github.com/form3tech-oss/jwt-go/VERSION_HISTORY.md deleted file mode 100644 index 6370298313..0000000000 --- a/vendor/github.com/form3tech-oss/jwt-go/VERSION_HISTORY.md +++ /dev/null @@ -1,118 +0,0 @@ -## `jwt-go` Version History - -#### 3.2.0 - -* Added method `ParseUnverified` to allow users to split up the tasks of parsing and validation -* HMAC signing method returns `ErrInvalidKeyType` instead of `ErrInvalidKey` where appropriate -* Added options to `request.ParseFromRequest`, which allows for an arbitrary list of modifiers to parsing behavior. Initial set include `WithClaims` and `WithParser`. Existing usage of this function will continue to work as before. -* Deprecated `ParseFromRequestWithClaims` to simplify API in the future. - -#### 3.1.0 - -* Improvements to `jwt` command line tool -* Added `SkipClaimsValidation` option to `Parser` -* Documentation updates - -#### 3.0.0 - -* **Compatibility Breaking Changes**: See MIGRATION_GUIDE.md for tips on updating your code - * Dropped support for `[]byte` keys when using RSA signing methods. This convenience feature could contribute to security vulnerabilities involving mismatched key types with signing methods. - * `ParseFromRequest` has been moved to `request` subpackage and usage has changed - * The `Claims` property on `Token` is now type `Claims` instead of `map[string]interface{}`. The default value is type `MapClaims`, which is an alias to `map[string]interface{}`. This makes it possible to use a custom type when decoding claims. -* Other Additions and Changes - * Added `Claims` interface type to allow users to decode the claims into a custom type - * Added `ParseWithClaims`, which takes a third argument of type `Claims`. Use this function instead of `Parse` if you have a custom type you'd like to decode into. - * Dramatically improved the functionality and flexibility of `ParseFromRequest`, which is now in the `request` subpackage - * Added `ParseFromRequestWithClaims` which is the `FromRequest` equivalent of `ParseWithClaims` - * Added new interface type `Extractor`, which is used for extracting JWT strings from http requests. Used with `ParseFromRequest` and `ParseFromRequestWithClaims`. - * Added several new, more specific, validation errors to error type bitmask - * Moved examples from README to executable example files - * Signing method registry is now thread safe - * Added new property to `ValidationError`, which contains the raw error returned by calls made by parse/verify (such as those returned by keyfunc or json parser) - -#### 2.7.0 - -This will likely be the last backwards compatible release before 3.0.0, excluding essential bug fixes. - -* Added new option `-show` to the `jwt` command that will just output the decoded token without verifying -* Error text for expired tokens includes how long it's been expired -* Fixed incorrect error returned from `ParseRSAPublicKeyFromPEM` -* Documentation updates - -#### 2.6.0 - -* Exposed inner error within ValidationError -* Fixed validation errors when using UseJSONNumber flag -* Added several unit tests - -#### 2.5.0 - -* Added support for signing method none. You shouldn't use this. The API tries to make this clear. -* Updated/fixed some documentation -* Added more helpful error message when trying to parse tokens that begin with `BEARER ` - -#### 2.4.0 - -* Added new type, Parser, to allow for configuration of various parsing parameters - * You can now specify a list of valid signing methods. Anything outside this set will be rejected. - * You can now opt to use the `json.Number` type instead of `float64` when parsing token JSON -* Added support for [Travis CI](https://travis-ci.org/dgrijalva/jwt-go) -* Fixed some bugs with ECDSA parsing - -#### 2.3.0 - -* Added support for ECDSA signing methods -* Added support for RSA PSS signing methods (requires go v1.4) - -#### 2.2.0 - -* Gracefully handle a `nil` `Keyfunc` being passed to `Parse`. Result will now be the parsed token and an error, instead of a panic. - -#### 2.1.0 - -Backwards compatible API change that was missed in 2.0.0. - -* The `SignedString` method on `Token` now takes `interface{}` instead of `[]byte` - -#### 2.0.0 - -There were two major reasons for breaking backwards compatibility with this update. The first was a refactor required to expand the width of the RSA and HMAC-SHA signing implementations. There will likely be no required code changes to support this change. - -The second update, while unfortunately requiring a small change in integration, is required to open up this library to other signing methods. Not all keys used for all signing methods have a single standard on-disk representation. Requiring `[]byte` as the type for all keys proved too limiting. Additionally, this implementation allows for pre-parsed tokens to be reused, which might matter in an application that parses a high volume of tokens with a small set of keys. Backwards compatibilty has been maintained for passing `[]byte` to the RSA signing methods, but they will also accept `*rsa.PublicKey` and `*rsa.PrivateKey`. - -It is likely the only integration change required here will be to change `func(t *jwt.Token) ([]byte, error)` to `func(t *jwt.Token) (interface{}, error)` when calling `Parse`. - -* **Compatibility Breaking Changes** - * `SigningMethodHS256` is now `*SigningMethodHMAC` instead of `type struct` - * `SigningMethodRS256` is now `*SigningMethodRSA` instead of `type struct` - * `KeyFunc` now returns `interface{}` instead of `[]byte` - * `SigningMethod.Sign` now takes `interface{}` instead of `[]byte` for the key - * `SigningMethod.Verify` now takes `interface{}` instead of `[]byte` for the key -* Renamed type `SigningMethodHS256` to `SigningMethodHMAC`. Specific sizes are now just instances of this type. - * Added public package global `SigningMethodHS256` - * Added public package global `SigningMethodHS384` - * Added public package global `SigningMethodHS512` -* Renamed type `SigningMethodRS256` to `SigningMethodRSA`. Specific sizes are now just instances of this type. - * Added public package global `SigningMethodRS256` - * Added public package global `SigningMethodRS384` - * Added public package global `SigningMethodRS512` -* Moved sample private key for HMAC tests from an inline value to a file on disk. Value is unchanged. -* Refactored the RSA implementation to be easier to read -* Exposed helper methods `ParseRSAPrivateKeyFromPEM` and `ParseRSAPublicKeyFromPEM` - -#### 1.0.2 - -* Fixed bug in parsing public keys from certificates -* Added more tests around the parsing of keys for RS256 -* Code refactoring in RS256 implementation. No functional changes - -#### 1.0.1 - -* Fixed panic if RS256 signing method was passed an invalid key - -#### 1.0.0 - -* First versioned release -* API stabilized -* Supports creating, signing, parsing, and validating JWT tokens -* Supports RS256 and HS256 signing methods \ No newline at end of file diff --git a/vendor/github.com/form3tech-oss/jwt-go/claims.go b/vendor/github.com/form3tech-oss/jwt-go/claims.go deleted file mode 100644 index 624890666c..0000000000 --- a/vendor/github.com/form3tech-oss/jwt-go/claims.go +++ /dev/null @@ -1,136 +0,0 @@ -package jwt - -import ( - "crypto/subtle" - "fmt" - "time" -) - -// For a type to be a Claims object, it must just have a Valid method that determines -// if the token is invalid for any supported reason -type Claims interface { - Valid() error -} - -// Structured version of Claims Section, as referenced at -// https://tools.ietf.org/html/rfc7519#section-4.1 -// See examples for how to use this with your own claim types -type StandardClaims struct { - Audience []string `json:"aud,omitempty"` - ExpiresAt int64 `json:"exp,omitempty"` - Id string `json:"jti,omitempty"` - IssuedAt int64 `json:"iat,omitempty"` - Issuer string `json:"iss,omitempty"` - NotBefore int64 `json:"nbf,omitempty"` - Subject string `json:"sub,omitempty"` -} - -// Validates time based claims "exp, iat, nbf". -// There is no accounting for clock skew. -// As well, if any of the above claims are not in the token, it will still -// be considered a valid claim. -func (c StandardClaims) Valid() error { - vErr := new(ValidationError) - now := TimeFunc().Unix() - - // The claims below are optional, by default, so if they are set to the - // default value in Go, let's not fail the verification for them. - if c.VerifyExpiresAt(now, false) == false { - delta := time.Unix(now, 0).Sub(time.Unix(c.ExpiresAt, 0)) - vErr.Inner = fmt.Errorf("token is expired by %v", delta) - vErr.Errors |= ValidationErrorExpired - } - - if c.VerifyIssuedAt(now, false) == false { - vErr.Inner = fmt.Errorf("Token used before issued") - vErr.Errors |= ValidationErrorIssuedAt - } - - if c.VerifyNotBefore(now, false) == false { - vErr.Inner = fmt.Errorf("token is not valid yet") - vErr.Errors |= ValidationErrorNotValidYet - } - - if vErr.valid() { - return nil - } - - return vErr -} - -// Compares the aud claim against cmp. -// If required is false, this method will return true if the value matches or is unset -func (c *StandardClaims) VerifyAudience(cmp string, req bool) bool { - return verifyAud(c.Audience, cmp, req) -} - -// Compares the exp claim against cmp. -// If required is false, this method will return true if the value matches or is unset -func (c *StandardClaims) VerifyExpiresAt(cmp int64, req bool) bool { - return verifyExp(c.ExpiresAt, cmp, req) -} - -// Compares the iat claim against cmp. -// If required is false, this method will return true if the value matches or is unset -func (c *StandardClaims) VerifyIssuedAt(cmp int64, req bool) bool { - return verifyIat(c.IssuedAt, cmp, req) -} - -// Compares the iss claim against cmp. -// If required is false, this method will return true if the value matches or is unset -func (c *StandardClaims) VerifyIssuer(cmp string, req bool) bool { - return verifyIss(c.Issuer, cmp, req) -} - -// Compares the nbf claim against cmp. -// If required is false, this method will return true if the value matches or is unset -func (c *StandardClaims) VerifyNotBefore(cmp int64, req bool) bool { - return verifyNbf(c.NotBefore, cmp, req) -} - -// ----- helpers - -func verifyAud(aud []string, cmp string, required bool) bool { - if len(aud) == 0 { - return !required - } - - for _, a := range aud { - if subtle.ConstantTimeCompare([]byte(a), []byte(cmp)) != 0 { - return true - } - } - return false -} - -func verifyExp(exp int64, now int64, required bool) bool { - if exp == 0 { - return !required - } - return now <= exp -} - -func verifyIat(iat int64, now int64, required bool) bool { - if iat == 0 { - return !required - } - return now >= iat -} - -func verifyIss(iss string, cmp string, required bool) bool { - if iss == "" { - return !required - } - if subtle.ConstantTimeCompare([]byte(iss), []byte(cmp)) != 0 { - return true - } else { - return false - } -} - -func verifyNbf(nbf int64, now int64, required bool) bool { - if nbf == 0 { - return !required - } - return now >= nbf -} diff --git a/vendor/github.com/form3tech-oss/jwt-go/doc.go b/vendor/github.com/form3tech-oss/jwt-go/doc.go deleted file mode 100644 index a86dc1a3b3..0000000000 --- a/vendor/github.com/form3tech-oss/jwt-go/doc.go +++ /dev/null @@ -1,4 +0,0 @@ -// Package jwt is a Go implementation of JSON Web Tokens: http://self-issued.info/docs/draft-jones-json-web-token.html -// -// See README.md for more info. -package jwt diff --git a/vendor/github.com/form3tech-oss/jwt-go/ecdsa.go b/vendor/github.com/form3tech-oss/jwt-go/ecdsa.go deleted file mode 100644 index f977381240..0000000000 --- a/vendor/github.com/form3tech-oss/jwt-go/ecdsa.go +++ /dev/null @@ -1,148 +0,0 @@ -package jwt - -import ( - "crypto" - "crypto/ecdsa" - "crypto/rand" - "errors" - "math/big" -) - -var ( - // Sadly this is missing from crypto/ecdsa compared to crypto/rsa - ErrECDSAVerification = errors.New("crypto/ecdsa: verification error") -) - -// Implements the ECDSA family of signing methods signing methods -// Expects *ecdsa.PrivateKey for signing and *ecdsa.PublicKey for verification -type SigningMethodECDSA struct { - Name string - Hash crypto.Hash - KeySize int - CurveBits int -} - -// Specific instances for EC256 and company -var ( - SigningMethodES256 *SigningMethodECDSA - SigningMethodES384 *SigningMethodECDSA - SigningMethodES512 *SigningMethodECDSA -) - -func init() { - // ES256 - SigningMethodES256 = &SigningMethodECDSA{"ES256", crypto.SHA256, 32, 256} - RegisterSigningMethod(SigningMethodES256.Alg(), func() SigningMethod { - return SigningMethodES256 - }) - - // ES384 - SigningMethodES384 = &SigningMethodECDSA{"ES384", crypto.SHA384, 48, 384} - RegisterSigningMethod(SigningMethodES384.Alg(), func() SigningMethod { - return SigningMethodES384 - }) - - // ES512 - SigningMethodES512 = &SigningMethodECDSA{"ES512", crypto.SHA512, 66, 521} - RegisterSigningMethod(SigningMethodES512.Alg(), func() SigningMethod { - return SigningMethodES512 - }) -} - -func (m *SigningMethodECDSA) Alg() string { - return m.Name -} - -// Implements the Verify method from SigningMethod -// For this verify method, key must be an ecdsa.PublicKey struct -func (m *SigningMethodECDSA) Verify(signingString, signature string, key interface{}) error { - var err error - - // Decode the signature - var sig []byte - if sig, err = DecodeSegment(signature); err != nil { - return err - } - - // Get the key - var ecdsaKey *ecdsa.PublicKey - switch k := key.(type) { - case *ecdsa.PublicKey: - ecdsaKey = k - default: - return ErrInvalidKeyType - } - - if len(sig) != 2*m.KeySize { - return ErrECDSAVerification - } - - r := big.NewInt(0).SetBytes(sig[:m.KeySize]) - s := big.NewInt(0).SetBytes(sig[m.KeySize:]) - - // Create hasher - if !m.Hash.Available() { - return ErrHashUnavailable - } - hasher := m.Hash.New() - hasher.Write([]byte(signingString)) - - // Verify the signature - if verifystatus := ecdsa.Verify(ecdsaKey, hasher.Sum(nil), r, s); verifystatus == true { - return nil - } else { - return ErrECDSAVerification - } -} - -// Implements the Sign method from SigningMethod -// For this signing method, key must be an ecdsa.PrivateKey struct -func (m *SigningMethodECDSA) Sign(signingString string, key interface{}) (string, error) { - // Get the key - var ecdsaKey *ecdsa.PrivateKey - switch k := key.(type) { - case *ecdsa.PrivateKey: - ecdsaKey = k - default: - return "", ErrInvalidKeyType - } - - // Create the hasher - if !m.Hash.Available() { - return "", ErrHashUnavailable - } - - hasher := m.Hash.New() - hasher.Write([]byte(signingString)) - - // Sign the string and return r, s - if r, s, err := ecdsa.Sign(rand.Reader, ecdsaKey, hasher.Sum(nil)); err == nil { - curveBits := ecdsaKey.Curve.Params().BitSize - - if m.CurveBits != curveBits { - return "", ErrInvalidKey - } - - keyBytes := curveBits / 8 - if curveBits%8 > 0 { - keyBytes += 1 - } - - // We serialize the outpus (r and s) into big-endian byte arrays and pad - // them with zeros on the left to make sure the sizes work out. Both arrays - // must be keyBytes long, and the output must be 2*keyBytes long. - rBytes := r.Bytes() - rBytesPadded := make([]byte, keyBytes) - copy(rBytesPadded[keyBytes-len(rBytes):], rBytes) - - sBytes := s.Bytes() - sBytesPadded := make([]byte, keyBytes) - copy(sBytesPadded[keyBytes-len(sBytes):], sBytes) - - out := append(rBytesPadded, sBytesPadded...) - - return EncodeSegment(out), nil - } else { - return "", err - } -} diff --git a/vendor/github.com/form3tech-oss/jwt-go/ecdsa_utils.go b/vendor/github.com/form3tech-oss/jwt-go/ecdsa_utils.go deleted file mode 100644 index db9f4be7d8..0000000000 --- a/vendor/github.com/form3tech-oss/jwt-go/ecdsa_utils.go +++ /dev/null @@ -1,69 +0,0 @@ -package jwt - -import ( - "crypto/ecdsa" - "crypto/x509" - "encoding/pem" - "errors" -) - -var ( - ErrNotECPublicKey = errors.New("Key is not a valid ECDSA public key") - ErrNotECPrivateKey = errors.New("Key is not a valid ECDSA private key") -) - -// Parse PEM encoded Elliptic Curve Private Key Structure -func ParseECPrivateKeyFromPEM(key []byte) (*ecdsa.PrivateKey, error) { - var err error - - // Parse PEM block - var block *pem.Block - if block, _ = pem.Decode(key); block == nil { - return nil, ErrKeyMustBePEMEncoded - } - - // Parse the key - var parsedKey interface{} - if parsedKey, err = x509.ParseECPrivateKey(block.Bytes); err != nil { - if parsedKey, err = x509.ParsePKCS8PrivateKey(block.Bytes); err != nil { - return nil, err - } - } - - var pkey *ecdsa.PrivateKey - var ok bool - if pkey, ok = parsedKey.(*ecdsa.PrivateKey); !ok { - return nil, ErrNotECPrivateKey - } - - return pkey, nil -} - -// Parse PEM encoded PKCS1 or PKCS8 public key -func ParseECPublicKeyFromPEM(key []byte) (*ecdsa.PublicKey, error) { - var err error - - // Parse PEM block - var block *pem.Block - if block, _ = pem.Decode(key); block == nil { - return nil, ErrKeyMustBePEMEncoded - } - - // Parse the key - var parsedKey interface{} - if parsedKey, err = x509.ParsePKIXPublicKey(block.Bytes); err != nil { - if cert, err := x509.ParseCertificate(block.Bytes); err == nil { - parsedKey = cert.PublicKey - } else { - return nil, err - } - } - - var pkey *ecdsa.PublicKey - var ok bool - if pkey, ok = parsedKey.(*ecdsa.PublicKey); !ok { - return nil, ErrNotECPublicKey - } - - return pkey, nil -} diff --git a/vendor/github.com/form3tech-oss/jwt-go/errors.go b/vendor/github.com/form3tech-oss/jwt-go/errors.go deleted file mode 100644 index 1c93024aad..0000000000 --- a/vendor/github.com/form3tech-oss/jwt-go/errors.go +++ /dev/null @@ -1,59 +0,0 @@ -package jwt - -import ( - "errors" -) - -// Error constants -var ( - ErrInvalidKey = errors.New("key is invalid") - ErrInvalidKeyType = errors.New("key is of invalid type") - ErrHashUnavailable = errors.New("the requested hash function is unavailable") -) - -// The errors that might occur when parsing and validating a token -const ( - ValidationErrorMalformed uint32 = 1 << iota // Token is malformed - ValidationErrorUnverifiable // Token could not be verified because of signing problems - ValidationErrorSignatureInvalid // Signature validation failed - - // Standard Claim validation errors - ValidationErrorAudience // AUD validation failed - ValidationErrorExpired // EXP validation failed - ValidationErrorIssuedAt // IAT validation failed - ValidationErrorIssuer // ISS validation failed - ValidationErrorNotValidYet // NBF validation failed - ValidationErrorId // JTI validation failed - ValidationErrorClaimsInvalid // Generic claims validation error -) - -// Helper for constructing a ValidationError with a string error message -func NewValidationError(errorText string, errorFlags uint32) *ValidationError { - return &ValidationError{ - text: errorText, - Errors: errorFlags, - } -} - -// The error from Parse if token is not valid -type ValidationError struct { - Inner error // stores the error returned by external dependencies, i.e.: KeyFunc - Errors uint32 // bitfield. see ValidationError... constants - text string // errors that do not have a valid error just have text -} - -// Validation error is an error type -func (e ValidationError) Error() string { - if e.Inner != nil { - return e.Inner.Error() - } else if e.text != "" { - return e.text - } else { - return "token is invalid" - } -} - -// No errors -func (e *ValidationError) valid() bool { - return e.Errors == 0 -} diff --git a/vendor/github.com/form3tech-oss/jwt-go/hmac.go b/vendor/github.com/form3tech-oss/jwt-go/hmac.go deleted file mode 100644 index addbe5d401..0000000000 --- a/vendor/github.com/form3tech-oss/jwt-go/hmac.go +++ /dev/null @@ -1,95 +0,0 @@ -package jwt - -import ( - "crypto" - "crypto/hmac" - "errors" -) - -// Implements the HMAC-SHA family of signing methods signing methods -// Expects key type of []byte for both signing and validation -type SigningMethodHMAC struct { - Name string - Hash crypto.Hash -} - -// Specific instances for HS256 and company -var ( - SigningMethodHS256 *SigningMethodHMAC - SigningMethodHS384 *SigningMethodHMAC - SigningMethodHS512 *SigningMethodHMAC - ErrSignatureInvalid = errors.New("signature is invalid") -) - -func init() { - // HS256 - SigningMethodHS256 = &SigningMethodHMAC{"HS256", crypto.SHA256} - RegisterSigningMethod(SigningMethodHS256.Alg(), func() SigningMethod { - return SigningMethodHS256 - }) - - // HS384 - SigningMethodHS384 = &SigningMethodHMAC{"HS384", crypto.SHA384} - RegisterSigningMethod(SigningMethodHS384.Alg(), func() SigningMethod { - return SigningMethodHS384 - }) - - // HS512 - SigningMethodHS512 = &SigningMethodHMAC{"HS512", crypto.SHA512} - RegisterSigningMethod(SigningMethodHS512.Alg(), func() SigningMethod { - return SigningMethodHS512 - }) -} - -func (m *SigningMethodHMAC) Alg() string { - return m.Name -} - -// Verify the signature of HSXXX tokens. Returns nil if the signature is valid. -func (m *SigningMethodHMAC) Verify(signingString, signature string, key interface{}) error { - // Verify the key is the right type - keyBytes, ok := key.([]byte) - if !ok { - return ErrInvalidKeyType - } - - // Decode signature, for comparison - sig, err := DecodeSegment(signature) - if err != nil { - return err - } - - // Can we use the specified hashing method? - if !m.Hash.Available() { - return ErrHashUnavailable - } - - // This signing method is symmetric, so we validate the signature - // by reproducing the signature from the signing string and key, then - // comparing that against the provided signature. - hasher := hmac.New(m.Hash.New, keyBytes) - hasher.Write([]byte(signingString)) - if !hmac.Equal(sig, hasher.Sum(nil)) { - return ErrSignatureInvalid - } - - // No validation errors. Signature is good. - return nil -} - -// Implements the Sign method from SigningMethod for this signing method. -// Key must be []byte -func (m *SigningMethodHMAC) Sign(signingString string, key interface{}) (string, error) { - if keyBytes, ok := key.([]byte); ok { - if !m.Hash.Available() { - return "", ErrHashUnavailable - } - - hasher := hmac.New(m.Hash.New, keyBytes) - hasher.Write([]byte(signingString)) - - return EncodeSegment(hasher.Sum(nil)), nil - } - - return "", ErrInvalidKeyType -} diff --git a/vendor/github.com/form3tech-oss/jwt-go/map_claims.go b/vendor/github.com/form3tech-oss/jwt-go/map_claims.go deleted file mode 100644 index bcc37b15bf..0000000000 --- a/vendor/github.com/form3tech-oss/jwt-go/map_claims.go +++ /dev/null @@ -1,110 +0,0 @@ -package jwt - -import ( - "encoding/json" - "errors" - // "fmt" -) - -// Claims type that uses the map[string]interface{} for JSON decoding -// This is the default claims type if you don't supply one -type MapClaims map[string]interface{} - -// Compares the aud claim against cmp. -// If required is false, this method will return true if the value matches or is unset -func (m MapClaims) VerifyAudience(cmp string, req bool) bool { - var aud []string - switch v := m["aud"].(type) { - case []string: - aud = v - case []interface{}: - for _, a := range v { - vs, ok := a.(string) - if !ok { - return false - } - aud = append(aud, vs) - } - case string: - aud = append(aud, v) - default: - return false - } - return verifyAud(aud, cmp, req) -} - -// Compares the exp claim against cmp. -// If required is false, this method will return true if the value matches or is unset -func (m MapClaims) VerifyExpiresAt(cmp int64, req bool) bool { - switch exp := m["exp"].(type) { - case float64: - return verifyExp(int64(exp), cmp, req) - case json.Number: - v, _ := exp.Int64() - return verifyExp(v, cmp, req) - } - return req == false -} - -// Compares the iat claim against cmp. -// If required is false, this method will return true if the value matches or is unset -func (m MapClaims) VerifyIssuedAt(cmp int64, req bool) bool { - switch iat := m["iat"].(type) { - case float64: - return verifyIat(int64(iat), cmp, req) - case json.Number: - v, _ := iat.Int64() - return verifyIat(v, cmp, req) - } - return req == false -} - -// Compares the iss claim against cmp. -// If required is false, this method will return true if the value matches or is unset -func (m MapClaims) VerifyIssuer(cmp string, req bool) bool { - iss, _ := m["iss"].(string) - return verifyIss(iss, cmp, req) -} - -// Compares the nbf claim against cmp. -// If required is false, this method will return true if the value matches or is unset -func (m MapClaims) VerifyNotBefore(cmp int64, req bool) bool { - switch nbf := m["nbf"].(type) { - case float64: - return verifyNbf(int64(nbf), cmp, req) - case json.Number: - v, _ := nbf.Int64() - return verifyNbf(v, cmp, req) - } - return req == false -} - -// Validates time based claims "exp, iat, nbf". -// There is no accounting for clock skew. -// As well, if any of the above claims are not in the token, it will still -// be considered a valid claim. -func (m MapClaims) Valid() error { - vErr := new(ValidationError) - now := TimeFunc().Unix() - - if m.VerifyExpiresAt(now, false) == false { - vErr.Inner = errors.New("Token is expired") - vErr.Errors |= ValidationErrorExpired - } - - if m.VerifyIssuedAt(now, false) == false { - vErr.Inner = errors.New("Token used before issued") - vErr.Errors |= ValidationErrorIssuedAt - } - - if m.VerifyNotBefore(now, false) == false { - vErr.Inner = errors.New("Token is not valid yet") - vErr.Errors |= ValidationErrorNotValidYet - } - - if vErr.valid() { - return nil - } - - return vErr -} diff --git a/vendor/github.com/form3tech-oss/jwt-go/none.go b/vendor/github.com/form3tech-oss/jwt-go/none.go deleted file mode 100644 index f04d189d06..0000000000 --- a/vendor/github.com/form3tech-oss/jwt-go/none.go +++ /dev/null @@ -1,52 +0,0 @@ -package jwt - -// Implements the none signing method. This is required by the spec -// but you probably should never use it. -var SigningMethodNone *signingMethodNone - -const UnsafeAllowNoneSignatureType unsafeNoneMagicConstant = "none signing method allowed" - -var NoneSignatureTypeDisallowedError error - -type signingMethodNone struct{} -type unsafeNoneMagicConstant string - -func init() { - SigningMethodNone = &signingMethodNone{} - NoneSignatureTypeDisallowedError = NewValidationError("'none' signature type is not allowed", ValidationErrorSignatureInvalid) - - RegisterSigningMethod(SigningMethodNone.Alg(), func() SigningMethod { - return SigningMethodNone - }) -} - -func (m *signingMethodNone) Alg() string { - return "none" -} - -// Only allow 'none' alg type if UnsafeAllowNoneSignatureType is specified as the key -func (m *signingMethodNone) Verify(signingString, signature string, key interface{}) (err error) { - // Key must be UnsafeAllowNoneSignatureType to prevent accidentally - // accepting 'none' signing method - if _, ok := key.(unsafeNoneMagicConstant); !ok { - return NoneSignatureTypeDisallowedError - } - // If signing method is none, signature must be an empty string - if signature != "" { - return NewValidationError( - "'none' signing method with non-empty signature", - ValidationErrorSignatureInvalid, - ) - } - - // Accept 'none' signing method. - return nil -} - -// Only allow 'none' signing if UnsafeAllowNoneSignatureType is specified as the key -func (m *signingMethodNone) Sign(signingString string, key interface{}) (string, error) { - if _, ok := key.(unsafeNoneMagicConstant); ok { - return "", nil - } - return "", NoneSignatureTypeDisallowedError -} diff --git a/vendor/github.com/form3tech-oss/jwt-go/parser.go b/vendor/github.com/form3tech-oss/jwt-go/parser.go deleted file mode 100644 index d6901d9adb..0000000000 --- a/vendor/github.com/form3tech-oss/jwt-go/parser.go +++ /dev/null @@ -1,148 +0,0 @@ -package jwt - -import ( - "bytes" - "encoding/json" - "fmt" - "strings" -) - -type Parser struct { - ValidMethods []string // If populated, only these methods will be considered valid - UseJSONNumber bool // Use JSON Number format in JSON decoder - SkipClaimsValidation bool // Skip claims validation during token parsing -} - -// Parse, validate, and return a token. -// keyFunc will receive the parsed token and should return the key for validating. -// If everything is kosher, err will be nil -func (p *Parser) Parse(tokenString string, keyFunc Keyfunc) (*Token, error) { - return p.ParseWithClaims(tokenString, MapClaims{}, keyFunc) -} - -func (p *Parser) ParseWithClaims(tokenString string, claims Claims, keyFunc Keyfunc) (*Token, error) { - token, parts, err := p.ParseUnverified(tokenString, claims) - if err != nil { - return token, err - } - - // Verify signing method is in the required set - if p.ValidMethods != nil { - var signingMethodValid = false - var alg = token.Method.Alg() - for _, m := range p.ValidMethods { - if m == alg { - signingMethodValid = true - break - } - } - if !signingMethodValid { - // signing method is not in the listed set - return token, NewValidationError(fmt.Sprintf("signing method %v is invalid", alg), ValidationErrorSignatureInvalid) - } - } - - // Lookup key - var key interface{} - if keyFunc == nil { - // keyFunc was not provided. short circuiting validation - return token, NewValidationError("no Keyfunc was provided.", ValidationErrorUnverifiable) - } - if key, err = keyFunc(token); err != nil { - // keyFunc returned an error - if ve, ok := err.(*ValidationError); ok { - return token, ve - } - return token, &ValidationError{Inner: err, Errors: ValidationErrorUnverifiable} - } - - vErr := &ValidationError{} - - // Validate Claims - if !p.SkipClaimsValidation { - if err := token.Claims.Valid(); err != nil { - - // If the Claims Valid returned an error, check if it is a validation error, - // If it was another error type, create a ValidationError with a generic ClaimsInvalid flag set - if e, ok := err.(*ValidationError); !ok { - vErr = &ValidationError{Inner: err, Errors: ValidationErrorClaimsInvalid} - } else { - vErr = e - } - } - } - - // Perform validation - token.Signature = parts[2] - if err = token.Method.Verify(strings.Join(parts[0:2], "."), token.Signature, key); err != nil { - vErr.Inner = err - vErr.Errors |= ValidationErrorSignatureInvalid - } - - if vErr.valid() { - token.Valid = true - return token, nil - } - - return token, vErr -} - -// WARNING: Don't use this method unless you know what you're doing -// -// This method parses the token but doesn't validate the signature. It's only -// ever useful in cases where you know the signature is valid (because it has -// been checked previously in the stack) and you want to extract values from -// it. -func (p *Parser) ParseUnverified(tokenString string, claims Claims) (token *Token, parts []string, err error) { - parts = strings.Split(tokenString, ".") - if len(parts) != 3 { - return nil, parts, NewValidationError("token contains an invalid number of segments", ValidationErrorMalformed) - } - - token = &Token{Raw: tokenString} - - // parse Header - var headerBytes []byte - if headerBytes, err = DecodeSegment(parts[0]); err != nil { - if strings.HasPrefix(strings.ToLower(tokenString), "bearer ") { - return token, parts, NewValidationError("tokenstring should not contain 'bearer '", ValidationErrorMalformed) - } - return token, parts, &ValidationError{Inner: err, Errors: ValidationErrorMalformed} - } - if err = json.Unmarshal(headerBytes, &token.Header); err != nil { - return token, parts, &ValidationError{Inner: err, Errors: ValidationErrorMalformed} - } - - // parse Claims - var claimBytes []byte - token.Claims = claims - - if claimBytes, err = DecodeSegment(parts[1]); err != nil { - return token, parts, &ValidationError{Inner: err, Errors: ValidationErrorMalformed} - } - dec := json.NewDecoder(bytes.NewBuffer(claimBytes)) - if p.UseJSONNumber { - dec.UseNumber() - } - // JSON Decode. Special case for map type to avoid weird pointer behavior - if c, ok := token.Claims.(MapClaims); ok { - err = dec.Decode(&c) - } else { - err = dec.Decode(&claims) - } - // Handle decode error - if err != nil { - return token, parts, &ValidationError{Inner: err, Errors: ValidationErrorMalformed} - } - - // Lookup signature method - if method, ok := token.Header["alg"].(string); ok { - if token.Method = GetSigningMethod(method); token.Method == nil { - return token, parts, NewValidationError("signing method (alg) is unavailable.", ValidationErrorUnverifiable) - } - } else { - return token, parts, NewValidationError("signing method (alg) is unspecified.", ValidationErrorUnverifiable) - } - - return token, parts, nil -} diff --git a/vendor/github.com/form3tech-oss/jwt-go/rsa.go b/vendor/github.com/form3tech-oss/jwt-go/rsa.go deleted file mode 100644 index e4caf1ca4a..0000000000 --- a/vendor/github.com/form3tech-oss/jwt-go/rsa.go +++ /dev/null @@ -1,101 +0,0 @@ -package jwt - -import ( - "crypto" - "crypto/rand" - "crypto/rsa" -) - -// Implements the RSA family of signing methods signing methods -// Expects *rsa.PrivateKey for signing and *rsa.PublicKey for validation -type SigningMethodRSA struct { - Name string - Hash crypto.Hash -} - -// Specific instances for RS256 and company -var ( - SigningMethodRS256 *SigningMethodRSA - SigningMethodRS384 *SigningMethodRSA - SigningMethodRS512 *SigningMethodRSA -) - -func init() { - // RS256 - SigningMethodRS256 = &SigningMethodRSA{"RS256", crypto.SHA256} - RegisterSigningMethod(SigningMethodRS256.Alg(), func() SigningMethod { - return SigningMethodRS256 - }) - - // RS384 - SigningMethodRS384 = &SigningMethodRSA{"RS384", crypto.SHA384} - RegisterSigningMethod(SigningMethodRS384.Alg(), func() SigningMethod { - return SigningMethodRS384 - }) - - // RS512 - SigningMethodRS512 = &SigningMethodRSA{"RS512", crypto.SHA512} - RegisterSigningMethod(SigningMethodRS512.Alg(), func() SigningMethod { - return SigningMethodRS512 - }) -} - -func (m *SigningMethodRSA) Alg() string { - return m.Name -} - -// Implements the Verify method from SigningMethod -// For this signing method, must be an *rsa.PublicKey structure. -func (m *SigningMethodRSA) Verify(signingString, signature string, key interface{}) error { - var err error - - // Decode the signature - var sig []byte - if sig, err = DecodeSegment(signature); err != nil { - return err - } - - var rsaKey *rsa.PublicKey - var ok bool - - if rsaKey, ok = key.(*rsa.PublicKey); !ok { - return ErrInvalidKeyType - } - - // Create hasher - if !m.Hash.Available() { - return ErrHashUnavailable - } - hasher := m.Hash.New() - hasher.Write([]byte(signingString)) - - // Verify the signature - return rsa.VerifyPKCS1v15(rsaKey, m.Hash, hasher.Sum(nil), sig) -} - -// Implements the Sign method from SigningMethod -// For this signing method, must be an *rsa.PrivateKey structure. -func (m *SigningMethodRSA) Sign(signingString string, key interface{}) (string, error) { - var rsaKey *rsa.PrivateKey - var ok bool - - // Validate type of key - if rsaKey, ok = key.(*rsa.PrivateKey); !ok { - return "", ErrInvalidKey - } - - // Create the hasher - if !m.Hash.Available() { - return "", ErrHashUnavailable - } - - hasher := m.Hash.New() - hasher.Write([]byte(signingString)) - - // Sign the string and return the encoded bytes - if sigBytes, err := rsa.SignPKCS1v15(rand.Reader, rsaKey, m.Hash, hasher.Sum(nil)); err == nil { - return EncodeSegment(sigBytes), nil - } else { - return "", err - } -} diff --git a/vendor/github.com/form3tech-oss/jwt-go/rsa_pss.go b/vendor/github.com/form3tech-oss/jwt-go/rsa_pss.go deleted file mode 100644 index c014708648..0000000000 --- a/vendor/github.com/form3tech-oss/jwt-go/rsa_pss.go +++ /dev/null @@ -1,142 +0,0 @@ -// +build go1.4 - -package jwt - -import ( - "crypto" - "crypto/rand" - "crypto/rsa" -) - -// Implements the RSAPSS family of signing methods signing methods -type SigningMethodRSAPSS struct { - *SigningMethodRSA - Options *rsa.PSSOptions - // VerifyOptions is optional. If set overrides Options for rsa.VerifyPPS. - // Used to accept tokens signed with rsa.PSSSaltLengthAuto, what doesn't follow - // https://tools.ietf.org/html/rfc7518#section-3.5 but was used previously. - // See https://github.com/dgrijalva/jwt-go/issues/285#issuecomment-437451244 for details. - VerifyOptions *rsa.PSSOptions -} - -// Specific instances for RS/PS and company. -var ( - SigningMethodPS256 *SigningMethodRSAPSS - SigningMethodPS384 *SigningMethodRSAPSS - SigningMethodPS512 *SigningMethodRSAPSS -) - -func init() { - // PS256 - SigningMethodPS256 = &SigningMethodRSAPSS{ - SigningMethodRSA: &SigningMethodRSA{ - Name: "PS256", - Hash: crypto.SHA256, - }, - Options: &rsa.PSSOptions{ - SaltLength: rsa.PSSSaltLengthEqualsHash, - }, - VerifyOptions: &rsa.PSSOptions{ - SaltLength: rsa.PSSSaltLengthAuto, - }, - } - RegisterSigningMethod(SigningMethodPS256.Alg(), func() SigningMethod { - return SigningMethodPS256 - }) - - // PS384 - SigningMethodPS384 = &SigningMethodRSAPSS{ - SigningMethodRSA: &SigningMethodRSA{ - Name: "PS384", - Hash: crypto.SHA384, - }, - Options: &rsa.PSSOptions{ - SaltLength: rsa.PSSSaltLengthEqualsHash, - }, - VerifyOptions: &rsa.PSSOptions{ - SaltLength: rsa.PSSSaltLengthAuto, - }, - } - RegisterSigningMethod(SigningMethodPS384.Alg(), func() SigningMethod { - return SigningMethodPS384 - }) - - // PS512 - SigningMethodPS512 = &SigningMethodRSAPSS{ - SigningMethodRSA: &SigningMethodRSA{ - Name: "PS512", - Hash: crypto.SHA512, - }, - Options: &rsa.PSSOptions{ - SaltLength: rsa.PSSSaltLengthEqualsHash, - }, - VerifyOptions: &rsa.PSSOptions{ - SaltLength: rsa.PSSSaltLengthAuto, - }, - } - RegisterSigningMethod(SigningMethodPS512.Alg(), func() SigningMethod { - return SigningMethodPS512 - }) -} - -// Implements the Verify method from SigningMethod -// For this verify method, key must be an rsa.PublicKey struct -func (m *SigningMethodRSAPSS) Verify(signingString, signature string, key interface{}) error { - var err error - - // Decode the signature - var sig []byte - if sig, err = DecodeSegment(signature); err != nil { - return err - } - - var rsaKey *rsa.PublicKey - switch k := key.(type) { - case *rsa.PublicKey: - rsaKey = k - default: - return ErrInvalidKey - } - - // Create hasher - if !m.Hash.Available() { - return ErrHashUnavailable - } - hasher := m.Hash.New() - hasher.Write([]byte(signingString)) - - opts := m.Options - if m.VerifyOptions != nil { - opts = m.VerifyOptions - } - - return rsa.VerifyPSS(rsaKey, m.Hash, hasher.Sum(nil), sig, opts) -} - -// Implements the Sign method from SigningMethod -// For this signing method, key must be an rsa.PrivateKey struct -func (m *SigningMethodRSAPSS) Sign(signingString string, key interface{}) (string, error) { - var rsaKey *rsa.PrivateKey - - switch k := key.(type) { - case *rsa.PrivateKey: - rsaKey = k - default: - return "", ErrInvalidKeyType - } - - // Create the hasher - if !m.Hash.Available() { - return "", ErrHashUnavailable - } - - hasher := m.Hash.New() - hasher.Write([]byte(signingString)) - - // Sign the string and return the encoded bytes - if sigBytes, err := rsa.SignPSS(rand.Reader, rsaKey, m.Hash, hasher.Sum(nil), m.Options); err == nil { - return EncodeSegment(sigBytes), nil - } else { - return "", err - } -} diff --git a/vendor/github.com/form3tech-oss/jwt-go/rsa_utils.go b/vendor/github.com/form3tech-oss/jwt-go/rsa_utils.go deleted file mode 100644 index 14c78c292a..0000000000 --- a/vendor/github.com/form3tech-oss/jwt-go/rsa_utils.go +++ /dev/null @@ -1,101 +0,0 @@ -package jwt - -import ( - "crypto/rsa" - "crypto/x509" - "encoding/pem" - "errors" -) - -var ( - ErrKeyMustBePEMEncoded = errors.New("Invalid Key: Key must be a PEM encoded PKCS1 or PKCS8 key") - ErrNotRSAPrivateKey = errors.New("Key is not a valid RSA private key") - ErrNotRSAPublicKey = errors.New("Key is not a valid RSA public key") -) - -// Parse PEM encoded PKCS1 or PKCS8 private key -func ParseRSAPrivateKeyFromPEM(key []byte) (*rsa.PrivateKey, error) { - var err error - - // Parse PEM block - var block *pem.Block - if block, _ = pem.Decode(key); block == nil { - return nil, ErrKeyMustBePEMEncoded - } - - var parsedKey interface{} - if parsedKey, err = x509.ParsePKCS1PrivateKey(block.Bytes); err != nil { - if parsedKey, err = x509.ParsePKCS8PrivateKey(block.Bytes); err != nil { - return nil, err - } - } - - var pkey *rsa.PrivateKey - var ok bool - if pkey, ok = parsedKey.(*rsa.PrivateKey); !ok { - return nil, ErrNotRSAPrivateKey - } - - return pkey, nil -} - -// Parse PEM encoded PKCS1 or PKCS8 private key protected with password -func ParseRSAPrivateKeyFromPEMWithPassword(key []byte, password string) (*rsa.PrivateKey, error) { - var err error - - // Parse PEM block - var block *pem.Block - if block, _ = pem.Decode(key); block == nil { - return nil, ErrKeyMustBePEMEncoded - } - - var parsedKey interface{} - - var blockDecrypted []byte - if blockDecrypted, err = x509.DecryptPEMBlock(block, []byte(password)); err != nil { - return nil, err - } - - if parsedKey, err = x509.ParsePKCS1PrivateKey(blockDecrypted); err != nil { - if parsedKey, err = x509.ParsePKCS8PrivateKey(blockDecrypted); err != nil { - return nil, err - } - } - - var pkey *rsa.PrivateKey - var ok bool - if pkey, ok = parsedKey.(*rsa.PrivateKey); !ok { - return nil, ErrNotRSAPrivateKey - } - - return pkey, nil -} - -// Parse PEM encoded PKCS1 or PKCS8 public key -func ParseRSAPublicKeyFromPEM(key []byte) (*rsa.PublicKey, error) { - var err error - - // Parse PEM block - var block *pem.Block - if block, _ = pem.Decode(key); block == nil { - return nil, ErrKeyMustBePEMEncoded - } - - // Parse the key - var parsedKey interface{} - if parsedKey, err = x509.ParsePKIXPublicKey(block.Bytes); err != nil { - if cert, err := x509.ParseCertificate(block.Bytes); err == nil { - parsedKey = cert.PublicKey - } else { - return nil, err - } - } - - var pkey *rsa.PublicKey - var ok bool - if pkey, ok = parsedKey.(*rsa.PublicKey); !ok { - return nil, ErrNotRSAPublicKey - } - - return pkey, nil -} diff --git a/vendor/github.com/form3tech-oss/jwt-go/signing_method.go b/vendor/github.com/form3tech-oss/jwt-go/signing_method.go deleted file mode 100644 index ed1f212b21..0000000000 --- a/vendor/github.com/form3tech-oss/jwt-go/signing_method.go +++ /dev/null @@ -1,35 +0,0 @@ -package jwt - -import ( - "sync" -) - -var signingMethods = map[string]func() SigningMethod{} -var signingMethodLock = new(sync.RWMutex) - -// Implement SigningMethod to add new methods for signing or verifying tokens. -type SigningMethod interface { - Verify(signingString, signature string, key interface{}) error // Returns nil if signature is valid - Sign(signingString string, key interface{}) (string, error) // Returns encoded signature or error - Alg() string // returns the alg identifier for this method (example: 'HS256') -} - -// Register the "alg" name and a factory function for signing method. -// This is typically done during init() in the method's implementation -func RegisterSigningMethod(alg string, f func() SigningMethod) { - signingMethodLock.Lock() - defer signingMethodLock.Unlock() - - signingMethods[alg] = f -} - -// Get a signing method from an "alg" string -func GetSigningMethod(alg string) (method SigningMethod) { - signingMethodLock.RLock() - defer signingMethodLock.RUnlock() - - if methodF, ok := signingMethods[alg]; ok { - method = methodF() - } - return -} diff --git a/vendor/github.com/form3tech-oss/jwt-go/token.go b/vendor/github.com/form3tech-oss/jwt-go/token.go deleted file mode 100644 index d637e0867c..0000000000 --- a/vendor/github.com/form3tech-oss/jwt-go/token.go +++ /dev/null @@ -1,108 +0,0 @@ -package jwt - -import ( - "encoding/base64" - "encoding/json" - "strings" - "time" -) - -// TimeFunc provides the current time when parsing token to validate "exp" claim (expiration time). -// You can override it to use another time value. This is useful for testing or if your -// server uses a different time zone than your tokens. -var TimeFunc = time.Now - -// Parse methods use this callback function to supply -// the key for verification. The function receives the parsed, -// but unverified Token. This allows you to use properties in the -// Header of the token (such as `kid`) to identify which key to use. -type Keyfunc func(*Token) (interface{}, error) - -// A JWT Token. Different fields will be used depending on whether you're -// creating or parsing/verifying a token. -type Token struct { - Raw string // The raw token. Populated when you Parse a token - Method SigningMethod // The signing method used or to be used - Header map[string]interface{} // The first segment of the token - Claims Claims // The second segment of the token - Signature string // The third segment of the token. Populated when you Parse a token - Valid bool // Is the token valid? Populated when you Parse/Verify a token -} - -// Create a new Token. Takes a signing method -func New(method SigningMethod) *Token { - return NewWithClaims(method, MapClaims{}) -} - -func NewWithClaims(method SigningMethod, claims Claims) *Token { - return &Token{ - Header: map[string]interface{}{ - "typ": "JWT", - "alg": method.Alg(), - }, - Claims: claims, - Method: method, - } -} - -// Get the complete, signed token -func (t *Token) SignedString(key interface{}) (string, error) { - var sig, sstr string - var err error - if sstr, err = t.SigningString(); err != nil { - return "", err - } - if sig, err = t.Method.Sign(sstr, key); err != nil { - return "", err - } - return strings.Join([]string{sstr, sig}, "."), nil -} - -// Generate the signing string. This is the -// most expensive part of the whole deal. Unless you -// need this for something special, just go straight for -// the SignedString. -func (t *Token) SigningString() (string, error) { - var err error - parts := make([]string, 2) - for i, _ := range parts { - var jsonValue []byte - if i == 0 { - if jsonValue, err = json.Marshal(t.Header); err != nil { - return "", err - } - } else { - if jsonValue, err = json.Marshal(t.Claims); err != nil { - return "", err - } - } - - parts[i] = EncodeSegment(jsonValue) - } - return strings.Join(parts, "."), nil -} - -// Parse, validate, and return a token. -// keyFunc will receive the parsed token and should return the key for validating. -// If everything is kosher, err will be nil -func Parse(tokenString string, keyFunc Keyfunc) (*Token, error) { - return new(Parser).Parse(tokenString, keyFunc) -} - -func ParseWithClaims(tokenString string, claims Claims, keyFunc Keyfunc) (*Token, error) { - return new(Parser).ParseWithClaims(tokenString, claims, keyFunc) -} - -// Encode JWT specific base64url encoding with padding stripped -func EncodeSegment(seg []byte) string { - return strings.TrimRight(base64.URLEncoding.EncodeToString(seg), "=") -} - -// Decode JWT specific base64url encoding with padding stripped -func DecodeSegment(seg string) ([]byte, error) { - if l := len(seg) % 4; l > 0 { - seg += strings.Repeat("=", 4-l) - } - - return base64.URLEncoding.DecodeString(seg) -} diff --git a/vendor/github.com/golang/protobuf/descriptor/descriptor.go b/vendor/github.com/golang/protobuf/descriptor/descriptor.go deleted file mode 100644 index ffde8a6508..0000000000 --- a/vendor/github.com/golang/protobuf/descriptor/descriptor.go +++ /dev/null @@ -1,180 +0,0 @@ -// Copyright 2016 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// Package descriptor provides functions for obtaining the protocol buffer -// descriptors of generated Go types. -// -// Deprecated: See the "google.golang.org/protobuf/reflect/protoreflect" package -// for how to obtain an EnumDescriptor or MessageDescriptor in order to -// programatically interact with the protobuf type system. -package descriptor - -import ( - "bytes" - "compress/gzip" - "io/ioutil" - "sync" - - "github.com/golang/protobuf/proto" - "google.golang.org/protobuf/reflect/protodesc" - "google.golang.org/protobuf/reflect/protoreflect" - "google.golang.org/protobuf/runtime/protoimpl" - - descriptorpb "github.com/golang/protobuf/protoc-gen-go/descriptor" -) - -// Message is proto.Message with a method to return its descriptor. -// -// Deprecated: The Descriptor method may not be generated by future -// versions of protoc-gen-go, meaning that this interface may not -// be implemented by many concrete message types. -type Message interface { - proto.Message - Descriptor() ([]byte, []int) -} - -// ForMessage returns the file descriptor proto containing -// the message and the message descriptor proto for the message itself. -// The returned proto messages must not be mutated. -// -// Deprecated: Not all concrete message types satisfy the Message interface. -// Use MessageDescriptorProto instead. If possible, the calling code should -// be rewritten to use protobuf reflection instead. -// See package "google.golang.org/protobuf/reflect/protoreflect" for details. -func ForMessage(m Message) (*descriptorpb.FileDescriptorProto, *descriptorpb.DescriptorProto) { - return MessageDescriptorProto(m) -} - -type rawDesc struct { - fileDesc []byte - indexes []int -} - -var rawDescCache sync.Map // map[protoreflect.Descriptor]*rawDesc - -func deriveRawDescriptor(d protoreflect.Descriptor) ([]byte, []int) { - // Fast-path: check whether raw descriptors are already cached. - origDesc := d - if v, ok := rawDescCache.Load(origDesc); ok { - return v.(*rawDesc).fileDesc, v.(*rawDesc).indexes - } - - // Slow-path: derive the raw descriptor from the v2 descriptor. - - // Start with the leaf (a given enum or message declaration) and - // ascend upwards until we hit the parent file descriptor. - var idxs []int - for { - idxs = append(idxs, d.Index()) - d = d.Parent() - if d == nil { - // TODO: We could construct a FileDescriptor stub for standalone - // descriptors to satisfy the API. - return nil, nil - } - if _, ok := d.(protoreflect.FileDescriptor); ok { - break - } - } - - // Obtain the raw file descriptor. - fd := d.(protoreflect.FileDescriptor) - b, _ := proto.Marshal(protodesc.ToFileDescriptorProto(fd)) - file := protoimpl.X.CompressGZIP(b) - - // Reverse the indexes, since we populated it in reverse. - for i, j := 0, len(idxs)-1; i < j; i, j = i+1, j-1 { - idxs[i], idxs[j] = idxs[j], idxs[i] - } - - if v, ok := rawDescCache.LoadOrStore(origDesc, &rawDesc{file, idxs}); ok { - return v.(*rawDesc).fileDesc, v.(*rawDesc).indexes - } - return file, idxs -} - -// EnumRawDescriptor returns the GZIP'd raw file descriptor representing -// the enum and the index path to reach the enum declaration. -// The returned slices must not be mutated. -func EnumRawDescriptor(e proto.GeneratedEnum) ([]byte, []int) { - if ev, ok := e.(interface{ EnumDescriptor() ([]byte, []int) }); ok { - return ev.EnumDescriptor() - } - ed := protoimpl.X.EnumTypeOf(e) - return deriveRawDescriptor(ed.Descriptor()) -} - -// MessageRawDescriptor returns the GZIP'd raw file descriptor representing -// the message and the index path to reach the message declaration. -// The returned slices must not be mutated. -func MessageRawDescriptor(m proto.GeneratedMessage) ([]byte, []int) { - if mv, ok := m.(interface{ Descriptor() ([]byte, []int) }); ok { - return mv.Descriptor() - } - md := protoimpl.X.MessageTypeOf(m) - return deriveRawDescriptor(md.Descriptor()) -} - -var fileDescCache sync.Map // map[*byte]*descriptorpb.FileDescriptorProto - -func deriveFileDescriptor(rawDesc []byte) *descriptorpb.FileDescriptorProto { - // Fast-path: check whether descriptor protos are already cached. - if v, ok := fileDescCache.Load(&rawDesc[0]); ok { - return v.(*descriptorpb.FileDescriptorProto) - } - - // Slow-path: derive the descriptor proto from the GZIP'd message. - zr, err := gzip.NewReader(bytes.NewReader(rawDesc)) - if err != nil { - panic(err) - } - b, err := ioutil.ReadAll(zr) - if err != nil { - panic(err) - } - fd := new(descriptorpb.FileDescriptorProto) - if err := proto.Unmarshal(b, fd); err != nil { - panic(err) - } - if v, ok := fileDescCache.LoadOrStore(&rawDesc[0], fd); ok { - return v.(*descriptorpb.FileDescriptorProto) - } - return fd -} - -// EnumDescriptorProto returns the file descriptor proto representing -// the enum and the enum descriptor proto for the enum itself. -// The returned proto messages must not be mutated. -func EnumDescriptorProto(e proto.GeneratedEnum) (*descriptorpb.FileDescriptorProto, *descriptorpb.EnumDescriptorProto) { - rawDesc, idxs := EnumRawDescriptor(e) - if rawDesc == nil || idxs == nil { - return nil, nil - } - fd := deriveFileDescriptor(rawDesc) - if len(idxs) == 1 { - return fd, fd.EnumType[idxs[0]] - } - md := fd.MessageType[idxs[0]] - for _, i := range idxs[1 : len(idxs)-1] { - md = md.NestedType[i] - } - ed := md.EnumType[idxs[len(idxs)-1]] - return fd, ed -} - -// MessageDescriptorProto returns the file descriptor proto representing -// the message and the message descriptor proto for the message itself. -// The returned proto messages must not be mutated. -func MessageDescriptorProto(m proto.GeneratedMessage) (*descriptorpb.FileDescriptorProto, *descriptorpb.DescriptorProto) { - rawDesc, idxs := MessageRawDescriptor(m) - if rawDesc == nil || idxs == nil { - return nil, nil - } - fd := deriveFileDescriptor(rawDesc) - md := fd.MessageType[idxs[0]] - for _, i := range idxs[1:] { - md = md.NestedType[i] - } - return fd, md -} diff --git a/vendor/github.com/golang/protobuf/jsonpb/decode.go b/vendor/github.com/golang/protobuf/jsonpb/decode.go deleted file mode 100644 index 60e82caa9a..0000000000 --- a/vendor/github.com/golang/protobuf/jsonpb/decode.go +++ /dev/null @@ -1,524 +0,0 @@ -// Copyright 2015 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package jsonpb - -import ( - "encoding/json" - "errors" - "fmt" - "io" - "math" - "reflect" - "strconv" - "strings" - "time" - - "github.com/golang/protobuf/proto" - "google.golang.org/protobuf/encoding/protojson" - protoV2 "google.golang.org/protobuf/proto" - "google.golang.org/protobuf/reflect/protoreflect" - "google.golang.org/protobuf/reflect/protoregistry" -) - -const wrapJSONUnmarshalV2 = false - -// UnmarshalNext unmarshals the next JSON object from d into m. -func UnmarshalNext(d *json.Decoder, m proto.Message) error { - return new(Unmarshaler).UnmarshalNext(d, m) -} - -// Unmarshal unmarshals a JSON object from r into m. -func Unmarshal(r io.Reader, m proto.Message) error { - return new(Unmarshaler).Unmarshal(r, m) -} - -// UnmarshalString unmarshals a JSON object from s into m. -func UnmarshalString(s string, m proto.Message) error { - return new(Unmarshaler).Unmarshal(strings.NewReader(s), m) -} - -// Unmarshaler is a configurable object for converting from a JSON -// representation to a protocol buffer object. -type Unmarshaler struct { - // AllowUnknownFields specifies whether to allow messages to contain - // unknown JSON fields, as opposed to failing to unmarshal. - AllowUnknownFields bool - - // AnyResolver is used to resolve the google.protobuf.Any well-known type. - // If unset, the global registry is used by default. - AnyResolver AnyResolver -} - -// JSONPBUnmarshaler is implemented by protobuf messages that customize the way -// they are unmarshaled from JSON. Messages that implement this should also -// implement JSONPBMarshaler so that the custom format can be produced. -// -// The JSON unmarshaling must follow the JSON to proto specification: -// https://developers.google.com/protocol-buffers/docs/proto3#json -// -// Deprecated: Custom types should implement protobuf reflection instead. -type JSONPBUnmarshaler interface { - UnmarshalJSONPB(*Unmarshaler, []byte) error -} - -// Unmarshal unmarshals a JSON object from r into m. -func (u *Unmarshaler) Unmarshal(r io.Reader, m proto.Message) error { - return u.UnmarshalNext(json.NewDecoder(r), m) -} - -// UnmarshalNext unmarshals the next JSON object from d into m. -func (u *Unmarshaler) UnmarshalNext(d *json.Decoder, m proto.Message) error { - if m == nil { - return errors.New("invalid nil message") - } - - // Parse the next JSON object from the stream. - raw := json.RawMessage{} - if err := d.Decode(&raw); err != nil { - return err - } - - // Check for custom unmarshalers first since they may not properly - // implement protobuf reflection that the logic below relies on. - if jsu, ok := m.(JSONPBUnmarshaler); ok { - return jsu.UnmarshalJSONPB(u, raw) - } - - mr := proto.MessageReflect(m) - - // NOTE: For historical reasons, a top-level null is treated as a noop. - // This is incorrect, but kept for compatibility. - if string(raw) == "null" && mr.Descriptor().FullName() != "google.protobuf.Value" { - return nil - } - - if wrapJSONUnmarshalV2 { - // NOTE: If input message is non-empty, we need to preserve merge semantics - // of the old jsonpb implementation. These semantics are not supported by - // the protobuf JSON specification. - isEmpty := true - mr.Range(func(protoreflect.FieldDescriptor, protoreflect.Value) bool { - isEmpty = false // at least one iteration implies non-empty - return false - }) - if !isEmpty { - // Perform unmarshaling into a newly allocated, empty message. - mr = mr.New() - - // Use a defer to copy all unmarshaled fields into the original message. - dst := proto.MessageReflect(m) - defer mr.Range(func(fd protoreflect.FieldDescriptor, v protoreflect.Value) bool { - dst.Set(fd, v) - return true - }) - } - - // Unmarshal using the v2 JSON unmarshaler. - opts := protojson.UnmarshalOptions{ - DiscardUnknown: u.AllowUnknownFields, - } - if u.AnyResolver != nil { - opts.Resolver = anyResolver{u.AnyResolver} - } - return opts.Unmarshal(raw, mr.Interface()) - } else { - if err := u.unmarshalMessage(mr, raw); err != nil { - return err - } - return protoV2.CheckInitialized(mr.Interface()) - } -} - -func (u *Unmarshaler) unmarshalMessage(m protoreflect.Message, in []byte) error { - md := m.Descriptor() - fds := md.Fields() - - if jsu, ok := proto.MessageV1(m.Interface()).(JSONPBUnmarshaler); ok { - return jsu.UnmarshalJSONPB(u, in) - } - - if string(in) == "null" && md.FullName() != "google.protobuf.Value" { - return nil - } - - switch wellKnownType(md.FullName()) { - case "Any": - var jsonObject map[string]json.RawMessage - if err := json.Unmarshal(in, &jsonObject); err != nil { - return err - } - - rawTypeURL, ok := jsonObject["@type"] - if !ok { - return errors.New("Any JSON doesn't have '@type'") - } - typeURL, err := unquoteString(string(rawTypeURL)) - if err != nil { - return fmt.Errorf("can't unmarshal Any's '@type': %q", rawTypeURL) - } - m.Set(fds.ByNumber(1), protoreflect.ValueOfString(typeURL)) - - var m2 protoreflect.Message - if u.AnyResolver != nil { - mi, err := u.AnyResolver.Resolve(typeURL) - if err != nil { - return err - } - m2 = proto.MessageReflect(mi) - } else { - mt, err := protoregistry.GlobalTypes.FindMessageByURL(typeURL) - if err != nil { - if err == protoregistry.NotFound { - return fmt.Errorf("could not resolve Any message type: %v", typeURL) - } - return err - } - m2 = mt.New() - } - - if wellKnownType(m2.Descriptor().FullName()) != "" { - rawValue, ok := jsonObject["value"] - if !ok { - return errors.New("Any JSON doesn't have 'value'") - } - if err := u.unmarshalMessage(m2, rawValue); err != nil { - return fmt.Errorf("can't unmarshal Any nested proto %v: %v", typeURL, err) - } - } else { - delete(jsonObject, "@type") - rawJSON, err := json.Marshal(jsonObject) - if err != nil { - return fmt.Errorf("can't generate JSON for Any's nested proto to be unmarshaled: %v", err) - } - if err = u.unmarshalMessage(m2, rawJSON); err != nil { - return fmt.Errorf("can't unmarshal Any nested proto %v: %v", typeURL, err) - } - } - - rawWire, err := protoV2.Marshal(m2.Interface()) - if err != nil { - return fmt.Errorf("can't marshal proto %v into Any.Value: %v", typeURL, err) - } - m.Set(fds.ByNumber(2), protoreflect.ValueOfBytes(rawWire)) - return nil - case "BoolValue", "BytesValue", "StringValue", - "Int32Value", "UInt32Value", "FloatValue", - "Int64Value", "UInt64Value", "DoubleValue": - fd := fds.ByNumber(1) - v, err := u.unmarshalValue(m.NewField(fd), in, fd) - if err != nil { - return err - } - m.Set(fd, v) - return nil - case "Duration": - v, err := unquoteString(string(in)) - if err != nil { - return err - } - d, err := time.ParseDuration(v) - if err != nil { - return fmt.Errorf("bad Duration: %v", err) - } - - sec := d.Nanoseconds() / 1e9 - nsec := d.Nanoseconds() % 1e9 - m.Set(fds.ByNumber(1), protoreflect.ValueOfInt64(int64(sec))) - m.Set(fds.ByNumber(2), protoreflect.ValueOfInt32(int32(nsec))) - return nil - case "Timestamp": - v, err := unquoteString(string(in)) - if err != nil { - return err - } - t, err := time.Parse(time.RFC3339Nano, v) - if err != nil { - return fmt.Errorf("bad Timestamp: %v", err) - } - - sec := t.Unix() - nsec := t.Nanosecond() - m.Set(fds.ByNumber(1), protoreflect.ValueOfInt64(int64(sec))) - m.Set(fds.ByNumber(2), protoreflect.ValueOfInt32(int32(nsec))) - return nil - case "Value": - switch { - case string(in) == "null": - m.Set(fds.ByNumber(1), protoreflect.ValueOfEnum(0)) - case string(in) == "true": - m.Set(fds.ByNumber(4), protoreflect.ValueOfBool(true)) - case string(in) == "false": - m.Set(fds.ByNumber(4), protoreflect.ValueOfBool(false)) - case hasPrefixAndSuffix('"', in, '"'): - s, err := unquoteString(string(in)) - if err != nil { - return fmt.Errorf("unrecognized type for Value %q", in) - } - m.Set(fds.ByNumber(3), protoreflect.ValueOfString(s)) - case hasPrefixAndSuffix('[', in, ']'): - v := m.Mutable(fds.ByNumber(6)) - return u.unmarshalMessage(v.Message(), in) - case hasPrefixAndSuffix('{', in, '}'): - v := m.Mutable(fds.ByNumber(5)) - return u.unmarshalMessage(v.Message(), in) - default: - f, err := strconv.ParseFloat(string(in), 0) - if err != nil { - return fmt.Errorf("unrecognized type for Value %q", in) - } - m.Set(fds.ByNumber(2), protoreflect.ValueOfFloat64(f)) - } - return nil - case "ListValue": - var jsonArray []json.RawMessage - if err := json.Unmarshal(in, &jsonArray); err != nil { - return fmt.Errorf("bad ListValue: %v", err) - } - - lv := m.Mutable(fds.ByNumber(1)).List() - for _, raw := range jsonArray { - ve := lv.NewElement() - if err := u.unmarshalMessage(ve.Message(), raw); err != nil { - return err - } - lv.Append(ve) - } - return nil - case "Struct": - var jsonObject map[string]json.RawMessage - if err := json.Unmarshal(in, &jsonObject); err != nil { - return fmt.Errorf("bad StructValue: %v", err) - } - - mv := m.Mutable(fds.ByNumber(1)).Map() - for key, raw := range jsonObject { - kv := protoreflect.ValueOf(key).MapKey() - vv := mv.NewValue() - if err := u.unmarshalMessage(vv.Message(), raw); err != nil { - return fmt.Errorf("bad value in StructValue for key %q: %v", key, err) - } - mv.Set(kv, vv) - } - return nil - } - - var jsonObject map[string]json.RawMessage - if err := json.Unmarshal(in, &jsonObject); err != nil { - return err - } - - // Handle known fields. - for i := 0; i < fds.Len(); i++ { - fd := fds.Get(i) - if fd.IsWeak() && fd.Message().IsPlaceholder() { - continue // weak reference is not linked in - } - - // Search for any raw JSON value associated with this field. - var raw json.RawMessage - name := string(fd.Name()) - if fd.Kind() == protoreflect.GroupKind { - name = string(fd.Message().Name()) - } - if v, ok := jsonObject[name]; ok { - delete(jsonObject, name) - raw = v - } - name = string(fd.JSONName()) - if v, ok := jsonObject[name]; ok { - delete(jsonObject, name) - raw = v - } - - field := m.NewField(fd) - // Unmarshal the field value. - if raw == nil || (string(raw) == "null" && !isSingularWellKnownValue(fd) && !isSingularJSONPBUnmarshaler(field, fd)) { - continue - } - v, err := u.unmarshalValue(field, raw, fd) - if err != nil { - return err - } - m.Set(fd, v) - } - - // Handle extension fields. - for name, raw := range jsonObject { - if !strings.HasPrefix(name, "[") || !strings.HasSuffix(name, "]") { - continue - } - - // Resolve the extension field by name. - xname := protoreflect.FullName(name[len("[") : len(name)-len("]")]) - xt, _ := protoregistry.GlobalTypes.FindExtensionByName(xname) - if xt == nil && isMessageSet(md) { - xt, _ = protoregistry.GlobalTypes.FindExtensionByName(xname.Append("message_set_extension")) - } - if xt == nil { - continue - } - delete(jsonObject, name) - fd := xt.TypeDescriptor() - if fd.ContainingMessage().FullName() != m.Descriptor().FullName() { - return fmt.Errorf("extension field %q does not extend message %q", xname, m.Descriptor().FullName()) - } - - field := m.NewField(fd) - // Unmarshal the field value. - if raw == nil || (string(raw) == "null" && !isSingularWellKnownValue(fd) && !isSingularJSONPBUnmarshaler(field, fd)) { - continue - } - v, err := u.unmarshalValue(field, raw, fd) - if err != nil { - return err - } - m.Set(fd, v) - } - - if !u.AllowUnknownFields && len(jsonObject) > 0 { - for name := range jsonObject { - return fmt.Errorf("unknown field %q in %v", name, md.FullName()) - } - } - return nil -} - -func isSingularWellKnownValue(fd protoreflect.FieldDescriptor) bool { - if md := fd.Message(); md != nil { - return md.FullName() == "google.protobuf.Value" && fd.Cardinality() != protoreflect.Repeated - } - return false -} - -func isSingularJSONPBUnmarshaler(v protoreflect.Value, fd protoreflect.FieldDescriptor) bool { - if fd.Message() != nil && fd.Cardinality() != protoreflect.Repeated { - _, ok := proto.MessageV1(v.Interface()).(JSONPBUnmarshaler) - return ok - } - return false -} - -func (u *Unmarshaler) unmarshalValue(v protoreflect.Value, in []byte, fd protoreflect.FieldDescriptor) (protoreflect.Value, error) { - switch { - case fd.IsList(): - var jsonArray []json.RawMessage - if err := json.Unmarshal(in, &jsonArray); err != nil { - return v, err - } - lv := v.List() - for _, raw := range jsonArray { - ve, err := u.unmarshalSingularValue(lv.NewElement(), raw, fd) - if err != nil { - return v, err - } - lv.Append(ve) - } - return v, nil - case fd.IsMap(): - var jsonObject map[string]json.RawMessage - if err := json.Unmarshal(in, &jsonObject); err != nil { - return v, err - } - kfd := fd.MapKey() - vfd := fd.MapValue() - mv := v.Map() - for key, raw := range jsonObject { - var kv protoreflect.MapKey - if kfd.Kind() == protoreflect.StringKind { - kv = protoreflect.ValueOf(key).MapKey() - } else { - v, err := u.unmarshalSingularValue(kfd.Default(), []byte(key), kfd) - if err != nil { - return v, err - } - kv = v.MapKey() - } - - vv, err := u.unmarshalSingularValue(mv.NewValue(), raw, vfd) - if err != nil { - return v, err - } - mv.Set(kv, vv) - } - return v, nil - default: - return u.unmarshalSingularValue(v, in, fd) - } -} - -var nonFinite = map[string]float64{ - `"NaN"`: math.NaN(), - `"Infinity"`: math.Inf(+1), - `"-Infinity"`: math.Inf(-1), -} - -func (u *Unmarshaler) unmarshalSingularValue(v protoreflect.Value, in []byte, fd protoreflect.FieldDescriptor) (protoreflect.Value, error) { - switch fd.Kind() { - case protoreflect.BoolKind: - return unmarshalValue(in, new(bool)) - case protoreflect.Int32Kind, protoreflect.Sint32Kind, protoreflect.Sfixed32Kind: - return unmarshalValue(trimQuote(in), new(int32)) - case protoreflect.Int64Kind, protoreflect.Sint64Kind, protoreflect.Sfixed64Kind: - return unmarshalValue(trimQuote(in), new(int64)) - case protoreflect.Uint32Kind, protoreflect.Fixed32Kind: - return unmarshalValue(trimQuote(in), new(uint32)) - case protoreflect.Uint64Kind, protoreflect.Fixed64Kind: - return unmarshalValue(trimQuote(in), new(uint64)) - case protoreflect.FloatKind: - if f, ok := nonFinite[string(in)]; ok { - return protoreflect.ValueOfFloat32(float32(f)), nil - } - return unmarshalValue(trimQuote(in), new(float32)) - case protoreflect.DoubleKind: - if f, ok := nonFinite[string(in)]; ok { - return protoreflect.ValueOfFloat64(float64(f)), nil - } - return unmarshalValue(trimQuote(in), new(float64)) - case protoreflect.StringKind: - return unmarshalValue(in, new(string)) - case protoreflect.BytesKind: - return unmarshalValue(in, new([]byte)) - case protoreflect.EnumKind: - if hasPrefixAndSuffix('"', in, '"') { - vd := fd.Enum().Values().ByName(protoreflect.Name(trimQuote(in))) - if vd == nil { - return v, fmt.Errorf("unknown value %q for enum %s", in, fd.Enum().FullName()) - } - return protoreflect.ValueOfEnum(vd.Number()), nil - } - return unmarshalValue(in, new(protoreflect.EnumNumber)) - case protoreflect.MessageKind, protoreflect.GroupKind: - err := u.unmarshalMessage(v.Message(), in) - return v, err - default: - panic(fmt.Sprintf("invalid kind %v", fd.Kind())) - } -} - -func unmarshalValue(in []byte, v interface{}) (protoreflect.Value, error) { - err := json.Unmarshal(in, v) - return protoreflect.ValueOf(reflect.ValueOf(v).Elem().Interface()), err -} - -func unquoteString(in string) (out string, err error) { - err = json.Unmarshal([]byte(in), &out) - return out, err -} - -func hasPrefixAndSuffix(prefix byte, in []byte, suffix byte) bool { - if len(in) >= 2 && in[0] == prefix && in[len(in)-1] == suffix { - return true - } - return false -} - -// trimQuote is like unquoteString but simply strips surrounding quotes. -// This is incorrect, but is behavior done by the legacy implementation. -func trimQuote(in []byte) []byte { - if len(in) >= 2 && in[0] == '"' && in[len(in)-1] == '"' { - in = in[1 : len(in)-1] - } - return in -} diff --git a/vendor/github.com/golang/protobuf/jsonpb/encode.go b/vendor/github.com/golang/protobuf/jsonpb/encode.go deleted file mode 100644 index 685c80a62b..0000000000 --- a/vendor/github.com/golang/protobuf/jsonpb/encode.go +++ /dev/null @@ -1,559 +0,0 @@ -// Copyright 2015 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package jsonpb - -import ( - "encoding/json" - "errors" - "fmt" - "io" - "math" - "reflect" - "sort" - "strconv" - "strings" - "time" - - "github.com/golang/protobuf/proto" - "google.golang.org/protobuf/encoding/protojson" - protoV2 "google.golang.org/protobuf/proto" - "google.golang.org/protobuf/reflect/protoreflect" - "google.golang.org/protobuf/reflect/protoregistry" -) - -const wrapJSONMarshalV2 = false - -// Marshaler is a configurable object for marshaling protocol buffer messages -// to the specified JSON representation. -type Marshaler struct { - // OrigName specifies whether to use the original protobuf name for fields. - OrigName bool - - // EnumsAsInts specifies whether to render enum values as integers, - // as opposed to string values. - EnumsAsInts bool - - // EmitDefaults specifies whether to render fields with zero values. - EmitDefaults bool - - // Indent controls whether the output is compact or not. - // If empty, the output is compact JSON. Otherwise, every JSON object - // entry and JSON array value will be on its own line. - // Each line will be preceded by repeated copies of Indent, where the - // number of copies is the current indentation depth. - Indent string - - // AnyResolver is used to resolve the google.protobuf.Any well-known type. - // If unset, the global registry is used by default. - AnyResolver AnyResolver -} - -// JSONPBMarshaler is implemented by protobuf messages that customize the -// way they are marshaled to JSON. Messages that implement this should also -// implement JSONPBUnmarshaler so that the custom format can be parsed. -// -// The JSON marshaling must follow the proto to JSON specification: -// https://developers.google.com/protocol-buffers/docs/proto3#json -// -// Deprecated: Custom types should implement protobuf reflection instead. -type JSONPBMarshaler interface { - MarshalJSONPB(*Marshaler) ([]byte, error) -} - -// Marshal serializes a protobuf message as JSON into w. -func (jm *Marshaler) Marshal(w io.Writer, m proto.Message) error { - b, err := jm.marshal(m) - if len(b) > 0 { - if _, err := w.Write(b); err != nil { - return err - } - } - return err -} - -// MarshalToString serializes a protobuf message as JSON in string form. -func (jm *Marshaler) MarshalToString(m proto.Message) (string, error) { - b, err := jm.marshal(m) - if err != nil { - return "", err - } - return string(b), nil -} - -func (jm *Marshaler) marshal(m proto.Message) ([]byte, error) { - v := reflect.ValueOf(m) - if m == nil || (v.Kind() == reflect.Ptr && v.IsNil()) { - return nil, errors.New("Marshal called with nil") - } - - // Check for custom marshalers first since they may not properly - // implement protobuf reflection that the logic below relies on. - if jsm, ok := m.(JSONPBMarshaler); ok { - return jsm.MarshalJSONPB(jm) - } - - if wrapJSONMarshalV2 { - opts := protojson.MarshalOptions{ - UseProtoNames: jm.OrigName, - UseEnumNumbers: jm.EnumsAsInts, - EmitUnpopulated: jm.EmitDefaults, - Indent: jm.Indent, - } - if jm.AnyResolver != nil { - opts.Resolver = anyResolver{jm.AnyResolver} - } - return opts.Marshal(proto.MessageReflect(m).Interface()) - } else { - // Check for unpopulated required fields first. - m2 := proto.MessageReflect(m) - if err := protoV2.CheckInitialized(m2.Interface()); err != nil { - return nil, err - } - - w := jsonWriter{Marshaler: jm} - err := w.marshalMessage(m2, "", "") - return w.buf, err - } -} - -type jsonWriter struct { - *Marshaler - buf []byte -} - -func (w *jsonWriter) write(s string) { - w.buf = append(w.buf, s...) -} - -func (w *jsonWriter) marshalMessage(m protoreflect.Message, indent, typeURL string) error { - if jsm, ok := proto.MessageV1(m.Interface()).(JSONPBMarshaler); ok { - b, err := jsm.MarshalJSONPB(w.Marshaler) - if err != nil { - return err - } - if typeURL != "" { - // we are marshaling this object to an Any type - var js map[string]*json.RawMessage - if err = json.Unmarshal(b, &js); err != nil { - return fmt.Errorf("type %T produced invalid JSON: %v", m.Interface(), err) - } - turl, err := json.Marshal(typeURL) - if err != nil { - return fmt.Errorf("failed to marshal type URL %q to JSON: %v", typeURL, err) - } - js["@type"] = (*json.RawMessage)(&turl) - if b, err = json.Marshal(js); err != nil { - return err - } - } - w.write(string(b)) - return nil - } - - md := m.Descriptor() - fds := md.Fields() - - // Handle well-known types. - const secondInNanos = int64(time.Second / time.Nanosecond) - switch wellKnownType(md.FullName()) { - case "Any": - return w.marshalAny(m, indent) - case "BoolValue", "BytesValue", "StringValue", - "Int32Value", "UInt32Value", "FloatValue", - "Int64Value", "UInt64Value", "DoubleValue": - fd := fds.ByNumber(1) - return w.marshalValue(fd, m.Get(fd), indent) - case "Duration": - const maxSecondsInDuration = 315576000000 - // "Generated output always contains 0, 3, 6, or 9 fractional digits, - // depending on required precision." - s := m.Get(fds.ByNumber(1)).Int() - ns := m.Get(fds.ByNumber(2)).Int() - if s < -maxSecondsInDuration || s > maxSecondsInDuration { - return fmt.Errorf("seconds out of range %v", s) - } - if ns <= -secondInNanos || ns >= secondInNanos { - return fmt.Errorf("ns out of range (%v, %v)", -secondInNanos, secondInNanos) - } - if (s > 0 && ns < 0) || (s < 0 && ns > 0) { - return errors.New("signs of seconds and nanos do not match") - } - var sign string - if s < 0 || ns < 0 { - sign, s, ns = "-", -1*s, -1*ns - } - x := fmt.Sprintf("%s%d.%09d", sign, s, ns) - x = strings.TrimSuffix(x, "000") - x = strings.TrimSuffix(x, "000") - x = strings.TrimSuffix(x, ".000") - w.write(fmt.Sprintf(`"%vs"`, x)) - return nil - case "Timestamp": - // "RFC 3339, where generated output will always be Z-normalized - // and uses 0, 3, 6 or 9 fractional digits." - s := m.Get(fds.ByNumber(1)).Int() - ns := m.Get(fds.ByNumber(2)).Int() - if ns < 0 || ns >= secondInNanos { - return fmt.Errorf("ns out of range [0, %v)", secondInNanos) - } - t := time.Unix(s, ns).UTC() - // time.RFC3339Nano isn't exactly right (we need to get 3/6/9 fractional digits). - x := t.Format("2006-01-02T15:04:05.000000000") - x = strings.TrimSuffix(x, "000") - x = strings.TrimSuffix(x, "000") - x = strings.TrimSuffix(x, ".000") - w.write(fmt.Sprintf(`"%vZ"`, x)) - return nil - case "Value": - // JSON value; which is a null, number, string, bool, object, or array. - od := md.Oneofs().Get(0) - fd := m.WhichOneof(od) - if fd == nil { - return errors.New("nil Value") - } - return w.marshalValue(fd, m.Get(fd), indent) - case "Struct", "ListValue": - // JSON object or array. - fd := fds.ByNumber(1) - return w.marshalValue(fd, m.Get(fd), indent) - } - - w.write("{") - if w.Indent != "" { - w.write("\n") - } - - firstField := true - if typeURL != "" { - if err := w.marshalTypeURL(indent, typeURL); err != nil { - return err - } - firstField = false - } - - for i := 0; i < fds.Len(); { - fd := fds.Get(i) - if od := fd.ContainingOneof(); od != nil { - fd = m.WhichOneof(od) - i += od.Fields().Len() - if fd == nil { - continue - } - } else { - i++ - } - - v := m.Get(fd) - - if !m.Has(fd) { - if !w.EmitDefaults || fd.ContainingOneof() != nil { - continue - } - if fd.Cardinality() != protoreflect.Repeated && (fd.Message() != nil || fd.Syntax() == protoreflect.Proto2) { - v = protoreflect.Value{} // use "null" for singular messages or proto2 scalars - } - } - - if !firstField { - w.writeComma() - } - if err := w.marshalField(fd, v, indent); err != nil { - return err - } - firstField = false - } - - // Handle proto2 extensions. - if md.ExtensionRanges().Len() > 0 { - // Collect a sorted list of all extension descriptor and values. - type ext struct { - desc protoreflect.FieldDescriptor - val protoreflect.Value - } - var exts []ext - m.Range(func(fd protoreflect.FieldDescriptor, v protoreflect.Value) bool { - if fd.IsExtension() { - exts = append(exts, ext{fd, v}) - } - return true - }) - sort.Slice(exts, func(i, j int) bool { - return exts[i].desc.Number() < exts[j].desc.Number() - }) - - for _, ext := range exts { - if !firstField { - w.writeComma() - } - if err := w.marshalField(ext.desc, ext.val, indent); err != nil { - return err - } - firstField = false - } - } - - if w.Indent != "" { - w.write("\n") - w.write(indent) - } - w.write("}") - return nil -} - -func (w *jsonWriter) writeComma() { - if w.Indent != "" { - w.write(",\n") - } else { - w.write(",") - } -} - -func (w *jsonWriter) marshalAny(m protoreflect.Message, indent string) error { - // "If the Any contains a value that has a special JSON mapping, - // it will be converted as follows: {"@type": xxx, "value": yyy}. - // Otherwise, the value will be converted into a JSON object, - // and the "@type" field will be inserted to indicate the actual data type." - md := m.Descriptor() - typeURL := m.Get(md.Fields().ByNumber(1)).String() - rawVal := m.Get(md.Fields().ByNumber(2)).Bytes() - - var m2 protoreflect.Message - if w.AnyResolver != nil { - mi, err := w.AnyResolver.Resolve(typeURL) - if err != nil { - return err - } - m2 = proto.MessageReflect(mi) - } else { - mt, err := protoregistry.GlobalTypes.FindMessageByURL(typeURL) - if err != nil { - return err - } - m2 = mt.New() - } - - if err := protoV2.Unmarshal(rawVal, m2.Interface()); err != nil { - return err - } - - if wellKnownType(m2.Descriptor().FullName()) == "" { - return w.marshalMessage(m2, indent, typeURL) - } - - w.write("{") - if w.Indent != "" { - w.write("\n") - } - if err := w.marshalTypeURL(indent, typeURL); err != nil { - return err - } - w.writeComma() - if w.Indent != "" { - w.write(indent) - w.write(w.Indent) - w.write(`"value": `) - } else { - w.write(`"value":`) - } - if err := w.marshalMessage(m2, indent+w.Indent, ""); err != nil { - return err - } - if w.Indent != "" { - w.write("\n") - w.write(indent) - } - w.write("}") - return nil -} - -func (w *jsonWriter) marshalTypeURL(indent, typeURL string) error { - if w.Indent != "" { - w.write(indent) - w.write(w.Indent) - } - w.write(`"@type":`) - if w.Indent != "" { - w.write(" ") - } - b, err := json.Marshal(typeURL) - if err != nil { - return err - } - w.write(string(b)) - return nil -} - -// marshalField writes field description and value to the Writer. -func (w *jsonWriter) marshalField(fd protoreflect.FieldDescriptor, v protoreflect.Value, indent string) error { - if w.Indent != "" { - w.write(indent) - w.write(w.Indent) - } - w.write(`"`) - switch { - case fd.IsExtension(): - // For message set, use the fname of the message as the extension name. - name := string(fd.FullName()) - if isMessageSet(fd.ContainingMessage()) { - name = strings.TrimSuffix(name, ".message_set_extension") - } - - w.write("[" + name + "]") - case w.OrigName: - name := string(fd.Name()) - if fd.Kind() == protoreflect.GroupKind { - name = string(fd.Message().Name()) - } - w.write(name) - default: - w.write(string(fd.JSONName())) - } - w.write(`":`) - if w.Indent != "" { - w.write(" ") - } - return w.marshalValue(fd, v, indent) -} - -func (w *jsonWriter) marshalValue(fd protoreflect.FieldDescriptor, v protoreflect.Value, indent string) error { - switch { - case fd.IsList(): - w.write("[") - comma := "" - lv := v.List() - for i := 0; i < lv.Len(); i++ { - w.write(comma) - if w.Indent != "" { - w.write("\n") - w.write(indent) - w.write(w.Indent) - w.write(w.Indent) - } - if err := w.marshalSingularValue(fd, lv.Get(i), indent+w.Indent); err != nil { - return err - } - comma = "," - } - if w.Indent != "" { - w.write("\n") - w.write(indent) - w.write(w.Indent) - } - w.write("]") - return nil - case fd.IsMap(): - kfd := fd.MapKey() - vfd := fd.MapValue() - mv := v.Map() - - // Collect a sorted list of all map keys and values. - type entry struct{ key, val protoreflect.Value } - var entries []entry - mv.Range(func(k protoreflect.MapKey, v protoreflect.Value) bool { - entries = append(entries, entry{k.Value(), v}) - return true - }) - sort.Slice(entries, func(i, j int) bool { - switch kfd.Kind() { - case protoreflect.BoolKind: - return !entries[i].key.Bool() && entries[j].key.Bool() - case protoreflect.Int32Kind, protoreflect.Sint32Kind, protoreflect.Sfixed32Kind, protoreflect.Int64Kind, protoreflect.Sint64Kind, protoreflect.Sfixed64Kind: - return entries[i].key.Int() < entries[j].key.Int() - case protoreflect.Uint32Kind, protoreflect.Fixed32Kind, protoreflect.Uint64Kind, protoreflect.Fixed64Kind: - return entries[i].key.Uint() < entries[j].key.Uint() - case protoreflect.StringKind: - return entries[i].key.String() < entries[j].key.String() - default: - panic("invalid kind") - } - }) - - w.write(`{`) - comma := "" - for _, entry := range entries { - w.write(comma) - if w.Indent != "" { - w.write("\n") - w.write(indent) - w.write(w.Indent) - w.write(w.Indent) - } - - s := fmt.Sprint(entry.key.Interface()) - b, err := json.Marshal(s) - if err != nil { - return err - } - w.write(string(b)) - - w.write(`:`) - if w.Indent != "" { - w.write(` `) - } - - if err := w.marshalSingularValue(vfd, entry.val, indent+w.Indent); err != nil { - return err - } - comma = "," - } - if w.Indent != "" { - w.write("\n") - w.write(indent) - w.write(w.Indent) - } - w.write(`}`) - return nil - default: - return w.marshalSingularValue(fd, v, indent) - } -} - -func (w *jsonWriter) marshalSingularValue(fd protoreflect.FieldDescriptor, v protoreflect.Value, indent string) error { - switch { - case !v.IsValid(): - w.write("null") - return nil - case fd.Message() != nil: - return w.marshalMessage(v.Message(), indent+w.Indent, "") - case fd.Enum() != nil: - if fd.Enum().FullName() == "google.protobuf.NullValue" { - w.write("null") - return nil - } - - vd := fd.Enum().Values().ByNumber(v.Enum()) - if vd == nil || w.EnumsAsInts { - w.write(strconv.Itoa(int(v.Enum()))) - } else { - w.write(`"` + string(vd.Name()) + `"`) - } - return nil - default: - switch v.Interface().(type) { - case float32, float64: - switch { - case math.IsInf(v.Float(), +1): - w.write(`"Infinity"`) - return nil - case math.IsInf(v.Float(), -1): - w.write(`"-Infinity"`) - return nil - case math.IsNaN(v.Float()): - w.write(`"NaN"`) - return nil - } - case int64, uint64: - w.write(fmt.Sprintf(`"%d"`, v.Interface())) - return nil - } - - b, err := json.Marshal(v.Interface()) - if err != nil { - return err - } - w.write(string(b)) - return nil - } -} diff --git a/vendor/github.com/golang/protobuf/jsonpb/json.go b/vendor/github.com/golang/protobuf/jsonpb/json.go deleted file mode 100644 index 480e2448de..0000000000 --- a/vendor/github.com/golang/protobuf/jsonpb/json.go +++ /dev/null @@ -1,69 +0,0 @@ -// Copyright 2015 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// Package jsonpb provides functionality to marshal and unmarshal between a -// protocol buffer message and JSON. It follows the specification at -// https://developers.google.com/protocol-buffers/docs/proto3#json. -// -// Do not rely on the default behavior of the standard encoding/json package -// when called on generated message types as it does not operate correctly. -// -// Deprecated: Use the "google.golang.org/protobuf/encoding/protojson" -// package instead. -package jsonpb - -import ( - "github.com/golang/protobuf/proto" - "google.golang.org/protobuf/reflect/protoreflect" - "google.golang.org/protobuf/reflect/protoregistry" - "google.golang.org/protobuf/runtime/protoimpl" -) - -// AnyResolver takes a type URL, present in an Any message, -// and resolves it into an instance of the associated message. -type AnyResolver interface { - Resolve(typeURL string) (proto.Message, error) -} - -type anyResolver struct{ AnyResolver } - -func (r anyResolver) FindMessageByName(message protoreflect.FullName) (protoreflect.MessageType, error) { - return r.FindMessageByURL(string(message)) -} - -func (r anyResolver) FindMessageByURL(url string) (protoreflect.MessageType, error) { - m, err := r.Resolve(url) - if err != nil { - return nil, err - } - return protoimpl.X.MessageTypeOf(m), nil -} - -func (r anyResolver) FindExtensionByName(field protoreflect.FullName) (protoreflect.ExtensionType, error) { - return protoregistry.GlobalTypes.FindExtensionByName(field) -} - -func (r anyResolver) FindExtensionByNumber(message protoreflect.FullName, field protoreflect.FieldNumber) (protoreflect.ExtensionType, error) { - return protoregistry.GlobalTypes.FindExtensionByNumber(message, field) -} - -func wellKnownType(s protoreflect.FullName) string { - if s.Parent() == "google.protobuf" { - switch s.Name() { - case "Empty", "Any", - "BoolValue", "BytesValue", "StringValue", - "Int32Value", "UInt32Value", "FloatValue", - "Int64Value", "UInt64Value", "DoubleValue", - "Duration", "Timestamp", - "NullValue", "Struct", "Value", "ListValue": - return string(s.Name()) - } - } - return "" -} - -func isMessageSet(md protoreflect.MessageDescriptor) bool { - ms, ok := md.(interface{ IsMessageSet() bool }) - return ok && ms.IsMessageSet() -} diff --git a/vendor/github.com/golang/protobuf/protoc-gen-go/descriptor/descriptor.pb.go b/vendor/github.com/golang/protobuf/protoc-gen-go/descriptor/descriptor.pb.go deleted file mode 100644 index 63dc057851..0000000000 --- a/vendor/github.com/golang/protobuf/protoc-gen-go/descriptor/descriptor.pb.go +++ /dev/null @@ -1,200 +0,0 @@ -// Code generated by protoc-gen-go. DO NOT EDIT. -// source: github.com/golang/protobuf/protoc-gen-go/descriptor/descriptor.proto - -package descriptor - -import ( - protoreflect "google.golang.org/protobuf/reflect/protoreflect" - protoimpl "google.golang.org/protobuf/runtime/protoimpl" - descriptorpb "google.golang.org/protobuf/types/descriptorpb" - reflect "reflect" -) - -// Symbols defined in public import of google/protobuf/descriptor.proto. - -type FieldDescriptorProto_Type = descriptorpb.FieldDescriptorProto_Type - -const FieldDescriptorProto_TYPE_DOUBLE = descriptorpb.FieldDescriptorProto_TYPE_DOUBLE -const FieldDescriptorProto_TYPE_FLOAT = descriptorpb.FieldDescriptorProto_TYPE_FLOAT -const FieldDescriptorProto_TYPE_INT64 = descriptorpb.FieldDescriptorProto_TYPE_INT64 -const FieldDescriptorProto_TYPE_UINT64 = descriptorpb.FieldDescriptorProto_TYPE_UINT64 -const FieldDescriptorProto_TYPE_INT32 = descriptorpb.FieldDescriptorProto_TYPE_INT32 -const FieldDescriptorProto_TYPE_FIXED64 = descriptorpb.FieldDescriptorProto_TYPE_FIXED64 -const FieldDescriptorProto_TYPE_FIXED32 = descriptorpb.FieldDescriptorProto_TYPE_FIXED32 -const FieldDescriptorProto_TYPE_BOOL = descriptorpb.FieldDescriptorProto_TYPE_BOOL -const FieldDescriptorProto_TYPE_STRING = descriptorpb.FieldDescriptorProto_TYPE_STRING -const FieldDescriptorProto_TYPE_GROUP = descriptorpb.FieldDescriptorProto_TYPE_GROUP -const FieldDescriptorProto_TYPE_MESSAGE = descriptorpb.FieldDescriptorProto_TYPE_MESSAGE -const FieldDescriptorProto_TYPE_BYTES = descriptorpb.FieldDescriptorProto_TYPE_BYTES -const FieldDescriptorProto_TYPE_UINT32 = descriptorpb.FieldDescriptorProto_TYPE_UINT32 -const FieldDescriptorProto_TYPE_ENUM = descriptorpb.FieldDescriptorProto_TYPE_ENUM -const FieldDescriptorProto_TYPE_SFIXED32 = descriptorpb.FieldDescriptorProto_TYPE_SFIXED32 -const FieldDescriptorProto_TYPE_SFIXED64 = descriptorpb.FieldDescriptorProto_TYPE_SFIXED64 -const FieldDescriptorProto_TYPE_SINT32 = descriptorpb.FieldDescriptorProto_TYPE_SINT32 -const FieldDescriptorProto_TYPE_SINT64 = descriptorpb.FieldDescriptorProto_TYPE_SINT64 - -var FieldDescriptorProto_Type_name = descriptorpb.FieldDescriptorProto_Type_name -var FieldDescriptorProto_Type_value = descriptorpb.FieldDescriptorProto_Type_value - -type FieldDescriptorProto_Label = descriptorpb.FieldDescriptorProto_Label - -const FieldDescriptorProto_LABEL_OPTIONAL = descriptorpb.FieldDescriptorProto_LABEL_OPTIONAL -const FieldDescriptorProto_LABEL_REQUIRED = descriptorpb.FieldDescriptorProto_LABEL_REQUIRED -const FieldDescriptorProto_LABEL_REPEATED = descriptorpb.FieldDescriptorProto_LABEL_REPEATED - -var FieldDescriptorProto_Label_name = descriptorpb.FieldDescriptorProto_Label_name -var FieldDescriptorProto_Label_value = descriptorpb.FieldDescriptorProto_Label_value - -type FileOptions_OptimizeMode = descriptorpb.FileOptions_OptimizeMode - -const FileOptions_SPEED = descriptorpb.FileOptions_SPEED -const FileOptions_CODE_SIZE = descriptorpb.FileOptions_CODE_SIZE -const FileOptions_LITE_RUNTIME = descriptorpb.FileOptions_LITE_RUNTIME - -var FileOptions_OptimizeMode_name = descriptorpb.FileOptions_OptimizeMode_name -var FileOptions_OptimizeMode_value = descriptorpb.FileOptions_OptimizeMode_value - -type FieldOptions_CType = descriptorpb.FieldOptions_CType - -const FieldOptions_STRING = descriptorpb.FieldOptions_STRING -const FieldOptions_CORD = descriptorpb.FieldOptions_CORD -const FieldOptions_STRING_PIECE = descriptorpb.FieldOptions_STRING_PIECE - -var FieldOptions_CType_name = descriptorpb.FieldOptions_CType_name -var FieldOptions_CType_value = descriptorpb.FieldOptions_CType_value - -type FieldOptions_JSType = descriptorpb.FieldOptions_JSType - -const FieldOptions_JS_NORMAL = descriptorpb.FieldOptions_JS_NORMAL -const FieldOptions_JS_STRING = descriptorpb.FieldOptions_JS_STRING -const FieldOptions_JS_NUMBER = descriptorpb.FieldOptions_JS_NUMBER - -var FieldOptions_JSType_name = descriptorpb.FieldOptions_JSType_name -var FieldOptions_JSType_value = descriptorpb.FieldOptions_JSType_value - -type MethodOptions_IdempotencyLevel = descriptorpb.MethodOptions_IdempotencyLevel - -const MethodOptions_IDEMPOTENCY_UNKNOWN = descriptorpb.MethodOptions_IDEMPOTENCY_UNKNOWN -const MethodOptions_NO_SIDE_EFFECTS = descriptorpb.MethodOptions_NO_SIDE_EFFECTS -const MethodOptions_IDEMPOTENT = descriptorpb.MethodOptions_IDEMPOTENT - -var MethodOptions_IdempotencyLevel_name = descriptorpb.MethodOptions_IdempotencyLevel_name -var MethodOptions_IdempotencyLevel_value = descriptorpb.MethodOptions_IdempotencyLevel_value - -type FileDescriptorSet = descriptorpb.FileDescriptorSet -type FileDescriptorProto = descriptorpb.FileDescriptorProto -type DescriptorProto = descriptorpb.DescriptorProto -type ExtensionRangeOptions = descriptorpb.ExtensionRangeOptions -type FieldDescriptorProto = descriptorpb.FieldDescriptorProto -type OneofDescriptorProto = descriptorpb.OneofDescriptorProto -type EnumDescriptorProto = descriptorpb.EnumDescriptorProto -type EnumValueDescriptorProto = descriptorpb.EnumValueDescriptorProto -type ServiceDescriptorProto = descriptorpb.ServiceDescriptorProto -type MethodDescriptorProto = descriptorpb.MethodDescriptorProto - -const Default_MethodDescriptorProto_ClientStreaming = descriptorpb.Default_MethodDescriptorProto_ClientStreaming -const Default_MethodDescriptorProto_ServerStreaming = descriptorpb.Default_MethodDescriptorProto_ServerStreaming - -type FileOptions = descriptorpb.FileOptions - -const Default_FileOptions_JavaMultipleFiles = descriptorpb.Default_FileOptions_JavaMultipleFiles -const Default_FileOptions_JavaStringCheckUtf8 = descriptorpb.Default_FileOptions_JavaStringCheckUtf8 -const Default_FileOptions_OptimizeFor = descriptorpb.Default_FileOptions_OptimizeFor -const Default_FileOptions_CcGenericServices = descriptorpb.Default_FileOptions_CcGenericServices -const Default_FileOptions_JavaGenericServices = descriptorpb.Default_FileOptions_JavaGenericServices -const Default_FileOptions_PyGenericServices = descriptorpb.Default_FileOptions_PyGenericServices -const Default_FileOptions_PhpGenericServices = descriptorpb.Default_FileOptions_PhpGenericServices -const Default_FileOptions_Deprecated = descriptorpb.Default_FileOptions_Deprecated -const Default_FileOptions_CcEnableArenas = descriptorpb.Default_FileOptions_CcEnableArenas - -type MessageOptions = descriptorpb.MessageOptions - -const Default_MessageOptions_MessageSetWireFormat = descriptorpb.Default_MessageOptions_MessageSetWireFormat -const Default_MessageOptions_NoStandardDescriptorAccessor = descriptorpb.Default_MessageOptions_NoStandardDescriptorAccessor -const Default_MessageOptions_Deprecated = descriptorpb.Default_MessageOptions_Deprecated - -type FieldOptions = descriptorpb.FieldOptions - -const Default_FieldOptions_Ctype = descriptorpb.Default_FieldOptions_Ctype -const Default_FieldOptions_Jstype = descriptorpb.Default_FieldOptions_Jstype -const Default_FieldOptions_Lazy = descriptorpb.Default_FieldOptions_Lazy -const Default_FieldOptions_Deprecated = descriptorpb.Default_FieldOptions_Deprecated -const Default_FieldOptions_Weak = descriptorpb.Default_FieldOptions_Weak - -type OneofOptions = descriptorpb.OneofOptions -type EnumOptions = descriptorpb.EnumOptions - -const Default_EnumOptions_Deprecated = descriptorpb.Default_EnumOptions_Deprecated - -type EnumValueOptions = descriptorpb.EnumValueOptions - -const Default_EnumValueOptions_Deprecated = descriptorpb.Default_EnumValueOptions_Deprecated - -type ServiceOptions = descriptorpb.ServiceOptions - -const Default_ServiceOptions_Deprecated = descriptorpb.Default_ServiceOptions_Deprecated - -type MethodOptions = descriptorpb.MethodOptions - -const Default_MethodOptions_Deprecated = descriptorpb.Default_MethodOptions_Deprecated -const Default_MethodOptions_IdempotencyLevel = descriptorpb.Default_MethodOptions_IdempotencyLevel - -type UninterpretedOption = descriptorpb.UninterpretedOption -type SourceCodeInfo = descriptorpb.SourceCodeInfo -type GeneratedCodeInfo = descriptorpb.GeneratedCodeInfo -type DescriptorProto_ExtensionRange = descriptorpb.DescriptorProto_ExtensionRange -type DescriptorProto_ReservedRange = descriptorpb.DescriptorProto_ReservedRange -type EnumDescriptorProto_EnumReservedRange = descriptorpb.EnumDescriptorProto_EnumReservedRange -type UninterpretedOption_NamePart = descriptorpb.UninterpretedOption_NamePart -type SourceCodeInfo_Location = descriptorpb.SourceCodeInfo_Location -type GeneratedCodeInfo_Annotation = descriptorpb.GeneratedCodeInfo_Annotation - -var File_github_com_golang_protobuf_protoc_gen_go_descriptor_descriptor_proto protoreflect.FileDescriptor - -var file_github_com_golang_protobuf_protoc_gen_go_descriptor_descriptor_proto_rawDesc = []byte{ - 0x0a, 0x44, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x67, 0x6f, 0x6c, - 0x61, 0x6e, 0x67, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x70, 0x72, 0x6f, - 0x74, 0x6f, 0x63, 0x2d, 0x67, 0x65, 0x6e, 0x2d, 0x67, 0x6f, 0x2f, 0x64, 0x65, 0x73, 0x63, 0x72, - 0x69, 0x70, 0x74, 0x6f, 0x72, 0x2f, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x6f, 0x72, - 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x20, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, - 0x6f, 0x72, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x42, 0x40, 0x5a, 0x3e, 0x67, 0x69, 0x74, 0x68, - 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x67, 0x6f, 0x6c, 0x61, 0x6e, 0x67, 0x2f, 0x70, 0x72, - 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x2d, 0x67, 0x65, - 0x6e, 0x2d, 0x67, 0x6f, 0x2f, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x6f, 0x72, 0x3b, - 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x6f, 0x72, 0x50, 0x00, 0x62, 0x06, 0x70, 0x72, - 0x6f, 0x74, 0x6f, 0x32, -} - -var file_github_com_golang_protobuf_protoc_gen_go_descriptor_descriptor_proto_goTypes = []interface{}{} -var file_github_com_golang_protobuf_protoc_gen_go_descriptor_descriptor_proto_depIdxs = []int32{ - 0, // [0:0] is the sub-list for method output_type - 0, // [0:0] is the sub-list for method input_type - 0, // [0:0] is the sub-list for extension type_name - 0, // [0:0] is the sub-list for extension extendee - 0, // [0:0] is the sub-list for field type_name -} - -func init() { file_github_com_golang_protobuf_protoc_gen_go_descriptor_descriptor_proto_init() } -func file_github_com_golang_protobuf_protoc_gen_go_descriptor_descriptor_proto_init() { - if File_github_com_golang_protobuf_protoc_gen_go_descriptor_descriptor_proto != nil { - return - } - type x struct{} - out := protoimpl.TypeBuilder{ - File: protoimpl.DescBuilder{ - GoPackagePath: reflect.TypeOf(x{}).PkgPath(), - RawDescriptor: file_github_com_golang_protobuf_protoc_gen_go_descriptor_descriptor_proto_rawDesc, - NumEnums: 0, - NumMessages: 0, - NumExtensions: 0, - NumServices: 0, - }, - GoTypes: file_github_com_golang_protobuf_protoc_gen_go_descriptor_descriptor_proto_goTypes, - DependencyIndexes: file_github_com_golang_protobuf_protoc_gen_go_descriptor_descriptor_proto_depIdxs, - }.Build() - File_github_com_golang_protobuf_protoc_gen_go_descriptor_descriptor_proto = out.File - file_github_com_golang_protobuf_protoc_gen_go_descriptor_descriptor_proto_rawDesc = nil - file_github_com_golang_protobuf_protoc_gen_go_descriptor_descriptor_proto_goTypes = nil - file_github_com_golang_protobuf_protoc_gen_go_descriptor_descriptor_proto_depIdxs = nil -} diff --git a/vendor/github.com/gorilla/websocket/.gitignore b/vendor/github.com/gorilla/websocket/.gitignore deleted file mode 100644 index cd3fcd1ef7..0000000000 --- a/vendor/github.com/gorilla/websocket/.gitignore +++ /dev/null @@ -1,25 +0,0 @@ -# Compiled Object files, Static and Dynamic libs (Shared Objects) -*.o -*.a -*.so - -# Folders -_obj -_test - -# Architecture specific extensions/prefixes -*.[568vq] -[568vq].out - -*.cgo1.go -*.cgo2.c -_cgo_defun.c -_cgo_gotypes.go -_cgo_export.* - -_testmain.go - -*.exe - -.idea/ -*.iml diff --git a/vendor/github.com/gorilla/websocket/AUTHORS b/vendor/github.com/gorilla/websocket/AUTHORS deleted file mode 100644 index 1931f40068..0000000000 --- a/vendor/github.com/gorilla/websocket/AUTHORS +++ /dev/null @@ -1,9 +0,0 @@ -# This is the official list of Gorilla WebSocket authors for copyright -# purposes. -# -# Please keep the list sorted. - -Gary Burd -Google LLC (https://opensource.google.com/) -Joachim Bauch - diff --git a/vendor/github.com/gorilla/websocket/LICENSE b/vendor/github.com/gorilla/websocket/LICENSE deleted file mode 100644 index 9171c97225..0000000000 --- a/vendor/github.com/gorilla/websocket/LICENSE +++ /dev/null @@ -1,22 +0,0 @@ -Copyright (c) 2013 The Gorilla WebSocket Authors. All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - - Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/vendor/github.com/gorilla/websocket/README.md b/vendor/github.com/gorilla/websocket/README.md deleted file mode 100644 index 19aa2e75c8..0000000000 --- a/vendor/github.com/gorilla/websocket/README.md +++ /dev/null @@ -1,64 +0,0 @@ -# Gorilla WebSocket - -[![GoDoc](https://godoc.org/github.com/gorilla/websocket?status.svg)](https://godoc.org/github.com/gorilla/websocket) -[![CircleCI](https://circleci.com/gh/gorilla/websocket.svg?style=svg)](https://circleci.com/gh/gorilla/websocket) - -Gorilla WebSocket is a [Go](http://golang.org/) implementation of the -[WebSocket](http://www.rfc-editor.org/rfc/rfc6455.txt) protocol. - -### Documentation - -* [API Reference](https://pkg.go.dev/github.com/gorilla/websocket?tab=doc) -* [Chat example](https://github.com/gorilla/websocket/tree/master/examples/chat) -* [Command example](https://github.com/gorilla/websocket/tree/master/examples/command) -* [Client and server example](https://github.com/gorilla/websocket/tree/master/examples/echo) -* [File watch example](https://github.com/gorilla/websocket/tree/master/examples/filewatch) - -### Status - -The Gorilla WebSocket package provides a complete and tested implementation of -the [WebSocket](http://www.rfc-editor.org/rfc/rfc6455.txt) protocol. The -package API is stable. - -### Installation - - go get github.com/gorilla/websocket - -### Protocol Compliance - -The Gorilla WebSocket package passes the server tests in the [Autobahn Test -Suite](https://github.com/crossbario/autobahn-testsuite) using the application in the [examples/autobahn -subdirectory](https://github.com/gorilla/websocket/tree/master/examples/autobahn). - -### Gorilla WebSocket compared with other packages - - - - - - - - - - - - - - - - - - -
github.com/gorillagolang.org/x/net
RFC 6455 Features
Passes Autobahn Test SuiteYesNo
Receive fragmented messageYesNo, see note 1
Send close messageYesNo
Send pings and receive pongsYesNo
Get the type of a received data messageYesYes, see note 2
Other Features
Compression ExtensionsExperimentalNo
Read message using io.ReaderYesNo, see note 3
Write message using io.WriteCloserYesNo, see note 3
- -Notes: - -1. Large messages are fragmented in [Chrome's new WebSocket implementation](http://www.ietf.org/mail-archive/web/hybi/current/msg10503.html). -2. The application can get the type of a received data message by implementing - a [Codec marshal](http://godoc.org/golang.org/x/net/websocket#Codec.Marshal) - function. -3. The go.net io.Reader and io.Writer operate across WebSocket frame boundaries. - Read returns when the input buffer is full or a frame boundary is - encountered. Each call to Write sends a single frame message. The Gorilla - io.Reader and io.WriteCloser operate on a single WebSocket message. - diff --git a/vendor/github.com/gorilla/websocket/client.go b/vendor/github.com/gorilla/websocket/client.go deleted file mode 100644 index 962c06a391..0000000000 --- a/vendor/github.com/gorilla/websocket/client.go +++ /dev/null @@ -1,395 +0,0 @@ -// Copyright 2013 The Gorilla WebSocket Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package websocket - -import ( - "bytes" - "context" - "crypto/tls" - "errors" - "io" - "io/ioutil" - "net" - "net/http" - "net/http/httptrace" - "net/url" - "strings" - "time" -) - -// ErrBadHandshake is returned when the server response to opening handshake is -// invalid. -var ErrBadHandshake = errors.New("websocket: bad handshake") - -var errInvalidCompression = errors.New("websocket: invalid compression negotiation") - -// NewClient creates a new client connection using the given net connection. -// The URL u specifies the host and request URI. Use requestHeader to specify -// the origin (Origin), subprotocols (Sec-WebSocket-Protocol) and cookies -// (Cookie). Use the response.Header to get the selected subprotocol -// (Sec-WebSocket-Protocol) and cookies (Set-Cookie). -// -// If the WebSocket handshake fails, ErrBadHandshake is returned along with a -// non-nil *http.Response so that callers can handle redirects, authentication, -// etc. -// -// Deprecated: Use Dialer instead. -func NewClient(netConn net.Conn, u *url.URL, requestHeader http.Header, readBufSize, writeBufSize int) (c *Conn, response *http.Response, err error) { - d := Dialer{ - ReadBufferSize: readBufSize, - WriteBufferSize: writeBufSize, - NetDial: func(net, addr string) (net.Conn, error) { - return netConn, nil - }, - } - return d.Dial(u.String(), requestHeader) -} - -// A Dialer contains options for connecting to WebSocket server. -type Dialer struct { - // NetDial specifies the dial function for creating TCP connections. If - // NetDial is nil, net.Dial is used. - NetDial func(network, addr string) (net.Conn, error) - - // NetDialContext specifies the dial function for creating TCP connections. If - // NetDialContext is nil, net.DialContext is used. - NetDialContext func(ctx context.Context, network, addr string) (net.Conn, error) - - // Proxy specifies a function to return a proxy for a given - // Request. If the function returns a non-nil error, the - // request is aborted with the provided error. - // If Proxy is nil or returns a nil *URL, no proxy is used. - Proxy func(*http.Request) (*url.URL, error) - - // TLSClientConfig specifies the TLS configuration to use with tls.Client. - // If nil, the default configuration is used. - TLSClientConfig *tls.Config - - // HandshakeTimeout specifies the duration for the handshake to complete. - HandshakeTimeout time.Duration - - // ReadBufferSize and WriteBufferSize specify I/O buffer sizes in bytes. If a buffer - // size is zero, then a useful default size is used. The I/O buffer sizes - // do not limit the size of the messages that can be sent or received. - ReadBufferSize, WriteBufferSize int - - // WriteBufferPool is a pool of buffers for write operations. If the value - // is not set, then write buffers are allocated to the connection for the - // lifetime of the connection. - // - // A pool is most useful when the application has a modest volume of writes - // across a large number of connections. - // - // Applications should use a single pool for each unique value of - // WriteBufferSize. - WriteBufferPool BufferPool - - // Subprotocols specifies the client's requested subprotocols. - Subprotocols []string - - // EnableCompression specifies if the client should attempt to negotiate - // per message compression (RFC 7692). Setting this value to true does not - // guarantee that compression will be supported. Currently only "no context - // takeover" modes are supported. - EnableCompression bool - - // Jar specifies the cookie jar. - // If Jar is nil, cookies are not sent in requests and ignored - // in responses. - Jar http.CookieJar -} - -// Dial creates a new client connection by calling DialContext with a background context. -func (d *Dialer) Dial(urlStr string, requestHeader http.Header) (*Conn, *http.Response, error) { - return d.DialContext(context.Background(), urlStr, requestHeader) -} - -var errMalformedURL = errors.New("malformed ws or wss URL") - -func hostPortNoPort(u *url.URL) (hostPort, hostNoPort string) { - hostPort = u.Host - hostNoPort = u.Host - if i := strings.LastIndex(u.Host, ":"); i > strings.LastIndex(u.Host, "]") { - hostNoPort = hostNoPort[:i] - } else { - switch u.Scheme { - case "wss": - hostPort += ":443" - case "https": - hostPort += ":443" - default: - hostPort += ":80" - } - } - return hostPort, hostNoPort -} - -// DefaultDialer is a dialer with all fields set to the default values. -var DefaultDialer = &Dialer{ - Proxy: http.ProxyFromEnvironment, - HandshakeTimeout: 45 * time.Second, -} - -// nilDialer is dialer to use when receiver is nil. -var nilDialer = *DefaultDialer - -// DialContext creates a new client connection. Use requestHeader to specify the -// origin (Origin), subprotocols (Sec-WebSocket-Protocol) and cookies (Cookie). -// Use the response.Header to get the selected subprotocol -// (Sec-WebSocket-Protocol) and cookies (Set-Cookie). -// -// The context will be used in the request and in the Dialer. -// -// If the WebSocket handshake fails, ErrBadHandshake is returned along with a -// non-nil *http.Response so that callers can handle redirects, authentication, -// etcetera. The response body may not contain the entire response and does not -// need to be closed by the application. -func (d *Dialer) DialContext(ctx context.Context, urlStr string, requestHeader http.Header) (*Conn, *http.Response, error) { - if d == nil { - d = &nilDialer - } - - challengeKey, err := generateChallengeKey() - if err != nil { - return nil, nil, err - } - - u, err := url.Parse(urlStr) - if err != nil { - return nil, nil, err - } - - switch u.Scheme { - case "ws": - u.Scheme = "http" - case "wss": - u.Scheme = "https" - default: - return nil, nil, errMalformedURL - } - - if u.User != nil { - // User name and password are not allowed in websocket URIs. - return nil, nil, errMalformedURL - } - - req := &http.Request{ - Method: "GET", - URL: u, - Proto: "HTTP/1.1", - ProtoMajor: 1, - ProtoMinor: 1, - Header: make(http.Header), - Host: u.Host, - } - req = req.WithContext(ctx) - - // Set the cookies present in the cookie jar of the dialer - if d.Jar != nil { - for _, cookie := range d.Jar.Cookies(u) { - req.AddCookie(cookie) - } - } - - // Set the request headers using the capitalization for names and values in - // RFC examples. Although the capitalization shouldn't matter, there are - // servers that depend on it. The Header.Set method is not used because the - // method canonicalizes the header names. - req.Header["Upgrade"] = []string{"websocket"} - req.Header["Connection"] = []string{"Upgrade"} - req.Header["Sec-WebSocket-Key"] = []string{challengeKey} - req.Header["Sec-WebSocket-Version"] = []string{"13"} - if len(d.Subprotocols) > 0 { - req.Header["Sec-WebSocket-Protocol"] = []string{strings.Join(d.Subprotocols, ", ")} - } - for k, vs := range requestHeader { - switch { - case k == "Host": - if len(vs) > 0 { - req.Host = vs[0] - } - case k == "Upgrade" || - k == "Connection" || - k == "Sec-Websocket-Key" || - k == "Sec-Websocket-Version" || - k == "Sec-Websocket-Extensions" || - (k == "Sec-Websocket-Protocol" && len(d.Subprotocols) > 0): - return nil, nil, errors.New("websocket: duplicate header not allowed: " + k) - case k == "Sec-Websocket-Protocol": - req.Header["Sec-WebSocket-Protocol"] = vs - default: - req.Header[k] = vs - } - } - - if d.EnableCompression { - req.Header["Sec-WebSocket-Extensions"] = []string{"permessage-deflate; server_no_context_takeover; client_no_context_takeover"} - } - - if d.HandshakeTimeout != 0 { - var cancel func() - ctx, cancel = context.WithTimeout(ctx, d.HandshakeTimeout) - defer cancel() - } - - // Get network dial function. - var netDial func(network, add string) (net.Conn, error) - - if d.NetDialContext != nil { - netDial = func(network, addr string) (net.Conn, error) { - return d.NetDialContext(ctx, network, addr) - } - } else if d.NetDial != nil { - netDial = d.NetDial - } else { - netDialer := &net.Dialer{} - netDial = func(network, addr string) (net.Conn, error) { - return netDialer.DialContext(ctx, network, addr) - } - } - - // If needed, wrap the dial function to set the connection deadline. - if deadline, ok := ctx.Deadline(); ok { - forwardDial := netDial - netDial = func(network, addr string) (net.Conn, error) { - c, err := forwardDial(network, addr) - if err != nil { - return nil, err - } - err = c.SetDeadline(deadline) - if err != nil { - c.Close() - return nil, err - } - return c, nil - } - } - - // If needed, wrap the dial function to connect through a proxy. - if d.Proxy != nil { - proxyURL, err := d.Proxy(req) - if err != nil { - return nil, nil, err - } - if proxyURL != nil { - dialer, err := proxy_FromURL(proxyURL, netDialerFunc(netDial)) - if err != nil { - return nil, nil, err - } - netDial = dialer.Dial - } - } - - hostPort, hostNoPort := hostPortNoPort(u) - trace := httptrace.ContextClientTrace(ctx) - if trace != nil && trace.GetConn != nil { - trace.GetConn(hostPort) - } - - netConn, err := netDial("tcp", hostPort) - if trace != nil && trace.GotConn != nil { - trace.GotConn(httptrace.GotConnInfo{ - Conn: netConn, - }) - } - if err != nil { - return nil, nil, err - } - - defer func() { - if netConn != nil { - netConn.Close() - } - }() - - if u.Scheme == "https" { - cfg := cloneTLSConfig(d.TLSClientConfig) - if cfg.ServerName == "" { - cfg.ServerName = hostNoPort - } - tlsConn := tls.Client(netConn, cfg) - netConn = tlsConn - - var err error - if trace != nil { - err = doHandshakeWithTrace(trace, tlsConn, cfg) - } else { - err = doHandshake(tlsConn, cfg) - } - - if err != nil { - return nil, nil, err - } - } - - conn := newConn(netConn, false, d.ReadBufferSize, d.WriteBufferSize, d.WriteBufferPool, nil, nil) - - if err := req.Write(netConn); err != nil { - return nil, nil, err - } - - if trace != nil && trace.GotFirstResponseByte != nil { - if peek, err := conn.br.Peek(1); err == nil && len(peek) == 1 { - trace.GotFirstResponseByte() - } - } - - resp, err := http.ReadResponse(conn.br, req) - if err != nil { - return nil, nil, err - } - - if d.Jar != nil { - if rc := resp.Cookies(); len(rc) > 0 { - d.Jar.SetCookies(u, rc) - } - } - - if resp.StatusCode != 101 || - !strings.EqualFold(resp.Header.Get("Upgrade"), "websocket") || - !strings.EqualFold(resp.Header.Get("Connection"), "upgrade") || - resp.Header.Get("Sec-Websocket-Accept") != computeAcceptKey(challengeKey) { - // Before closing the network connection on return from this - // function, slurp up some of the response to aid application - // debugging. - buf := make([]byte, 1024) - n, _ := io.ReadFull(resp.Body, buf) - resp.Body = ioutil.NopCloser(bytes.NewReader(buf[:n])) - return nil, resp, ErrBadHandshake - } - - for _, ext := range parseExtensions(resp.Header) { - if ext[""] != "permessage-deflate" { - continue - } - _, snct := ext["server_no_context_takeover"] - _, cnct := ext["client_no_context_takeover"] - if !snct || !cnct { - return nil, resp, errInvalidCompression - } - conn.newCompressionWriter = compressNoContextTakeover - conn.newDecompressionReader = decompressNoContextTakeover - break - } - - resp.Body = ioutil.NopCloser(bytes.NewReader([]byte{})) - conn.subprotocol = resp.Header.Get("Sec-Websocket-Protocol") - - netConn.SetDeadline(time.Time{}) - netConn = nil // to avoid close in defer. - return conn, resp, nil -} - -func doHandshake(tlsConn *tls.Conn, cfg *tls.Config) error { - if err := tlsConn.Handshake(); err != nil { - return err - } - if !cfg.InsecureSkipVerify { - if err := tlsConn.VerifyHostname(cfg.ServerName); err != nil { - return err - } - } - return nil -} diff --git a/vendor/github.com/gorilla/websocket/client_clone.go b/vendor/github.com/gorilla/websocket/client_clone.go deleted file mode 100644 index 4f0d943723..0000000000 --- a/vendor/github.com/gorilla/websocket/client_clone.go +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2013 The Gorilla WebSocket Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// +build go1.8 - -package websocket - -import "crypto/tls" - -func cloneTLSConfig(cfg *tls.Config) *tls.Config { - if cfg == nil { - return &tls.Config{} - } - return cfg.Clone() -} diff --git a/vendor/github.com/gorilla/websocket/client_clone_legacy.go b/vendor/github.com/gorilla/websocket/client_clone_legacy.go deleted file mode 100644 index babb007fb4..0000000000 --- a/vendor/github.com/gorilla/websocket/client_clone_legacy.go +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright 2013 The Gorilla WebSocket Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// +build !go1.8 - -package websocket - -import "crypto/tls" - -// cloneTLSConfig clones all public fields except the fields -// SessionTicketsDisabled and SessionTicketKey. This avoids copying the -// sync.Mutex in the sync.Once and makes it safe to call cloneTLSConfig on a -// config in active use. -func cloneTLSConfig(cfg *tls.Config) *tls.Config { - if cfg == nil { - return &tls.Config{} - } - return &tls.Config{ - Rand: cfg.Rand, - Time: cfg.Time, - Certificates: cfg.Certificates, - NameToCertificate: cfg.NameToCertificate, - GetCertificate: cfg.GetCertificate, - RootCAs: cfg.RootCAs, - NextProtos: cfg.NextProtos, - ServerName: cfg.ServerName, - ClientAuth: cfg.ClientAuth, - ClientCAs: cfg.ClientCAs, - InsecureSkipVerify: cfg.InsecureSkipVerify, - CipherSuites: cfg.CipherSuites, - PreferServerCipherSuites: cfg.PreferServerCipherSuites, - ClientSessionCache: cfg.ClientSessionCache, - MinVersion: cfg.MinVersion, - MaxVersion: cfg.MaxVersion, - CurvePreferences: cfg.CurvePreferences, - } -} diff --git a/vendor/github.com/gorilla/websocket/compression.go b/vendor/github.com/gorilla/websocket/compression.go deleted file mode 100644 index 813ffb1e84..0000000000 --- a/vendor/github.com/gorilla/websocket/compression.go +++ /dev/null @@ -1,148 +0,0 @@ -// Copyright 2017 The Gorilla WebSocket Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package websocket - -import ( - "compress/flate" - "errors" - "io" - "strings" - "sync" -) - -const ( - minCompressionLevel = -2 // flate.HuffmanOnly not defined in Go < 1.6 - maxCompressionLevel = flate.BestCompression - defaultCompressionLevel = 1 -) - -var ( - flateWriterPools [maxCompressionLevel - minCompressionLevel + 1]sync.Pool - flateReaderPool = sync.Pool{New: func() interface{} { - return flate.NewReader(nil) - }} -) - -func decompressNoContextTakeover(r io.Reader) io.ReadCloser { - const tail = - // Add four bytes as specified in RFC - "\x00\x00\xff\xff" + - // Add final block to squelch unexpected EOF error from flate reader. - "\x01\x00\x00\xff\xff" - - fr, _ := flateReaderPool.Get().(io.ReadCloser) - fr.(flate.Resetter).Reset(io.MultiReader(r, strings.NewReader(tail)), nil) - return &flateReadWrapper{fr} -} - -func isValidCompressionLevel(level int) bool { - return minCompressionLevel <= level && level <= maxCompressionLevel -} - -func compressNoContextTakeover(w io.WriteCloser, level int) io.WriteCloser { - p := &flateWriterPools[level-minCompressionLevel] - tw := &truncWriter{w: w} - fw, _ := p.Get().(*flate.Writer) - if fw == nil { - fw, _ = flate.NewWriter(tw, level) - } else { - fw.Reset(tw) - } - return &flateWriteWrapper{fw: fw, tw: tw, p: p} -} - -// truncWriter is an io.Writer that writes all but the last four bytes of the -// stream to another io.Writer. -type truncWriter struct { - w io.WriteCloser - n int - p [4]byte -} - -func (w *truncWriter) Write(p []byte) (int, error) { - n := 0 - - // fill buffer first for simplicity. - if w.n < len(w.p) { - n = copy(w.p[w.n:], p) - p = p[n:] - w.n += n - if len(p) == 0 { - return n, nil - } - } - - m := len(p) - if m > len(w.p) { - m = len(w.p) - } - - if nn, err := w.w.Write(w.p[:m]); err != nil { - return n + nn, err - } - - copy(w.p[:], w.p[m:]) - copy(w.p[len(w.p)-m:], p[len(p)-m:]) - nn, err := w.w.Write(p[:len(p)-m]) - return n + nn, err -} - -type flateWriteWrapper struct { - fw *flate.Writer - tw *truncWriter - p *sync.Pool -} - -func (w *flateWriteWrapper) Write(p []byte) (int, error) { - if w.fw == nil { - return 0, errWriteClosed - } - return w.fw.Write(p) -} - -func (w *flateWriteWrapper) Close() error { - if w.fw == nil { - return errWriteClosed - } - err1 := w.fw.Flush() - w.p.Put(w.fw) - w.fw = nil - if w.tw.p != [4]byte{0, 0, 0xff, 0xff} { - return errors.New("websocket: internal error, unexpected bytes at end of flate stream") - } - err2 := w.tw.w.Close() - if err1 != nil { - return err1 - } - return err2 -} - -type flateReadWrapper struct { - fr io.ReadCloser -} - -func (r *flateReadWrapper) Read(p []byte) (int, error) { - if r.fr == nil { - return 0, io.ErrClosedPipe - } - n, err := r.fr.Read(p) - if err == io.EOF { - // Preemptively place the reader back in the pool. This helps with - // scenarios where the application does not call NextReader() soon after - // this final read. - r.Close() - } - return n, err -} - -func (r *flateReadWrapper) Close() error { - if r.fr == nil { - return io.ErrClosedPipe - } - err := r.fr.Close() - flateReaderPool.Put(r.fr) - r.fr = nil - return err -} diff --git a/vendor/github.com/gorilla/websocket/conn.go b/vendor/github.com/gorilla/websocket/conn.go deleted file mode 100644 index ca46d2f793..0000000000 --- a/vendor/github.com/gorilla/websocket/conn.go +++ /dev/null @@ -1,1201 +0,0 @@ -// Copyright 2013 The Gorilla WebSocket Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package websocket - -import ( - "bufio" - "encoding/binary" - "errors" - "io" - "io/ioutil" - "math/rand" - "net" - "strconv" - "sync" - "time" - "unicode/utf8" -) - -const ( - // Frame header byte 0 bits from Section 5.2 of RFC 6455 - finalBit = 1 << 7 - rsv1Bit = 1 << 6 - rsv2Bit = 1 << 5 - rsv3Bit = 1 << 4 - - // Frame header byte 1 bits from Section 5.2 of RFC 6455 - maskBit = 1 << 7 - - maxFrameHeaderSize = 2 + 8 + 4 // Fixed header + length + mask - maxControlFramePayloadSize = 125 - - writeWait = time.Second - - defaultReadBufferSize = 4096 - defaultWriteBufferSize = 4096 - - continuationFrame = 0 - noFrame = -1 -) - -// Close codes defined in RFC 6455, section 11.7. -const ( - CloseNormalClosure = 1000 - CloseGoingAway = 1001 - CloseProtocolError = 1002 - CloseUnsupportedData = 1003 - CloseNoStatusReceived = 1005 - CloseAbnormalClosure = 1006 - CloseInvalidFramePayloadData = 1007 - ClosePolicyViolation = 1008 - CloseMessageTooBig = 1009 - CloseMandatoryExtension = 1010 - CloseInternalServerErr = 1011 - CloseServiceRestart = 1012 - CloseTryAgainLater = 1013 - CloseTLSHandshake = 1015 -) - -// The message types are defined in RFC 6455, section 11.8. -const ( - // TextMessage denotes a text data message. The text message payload is - // interpreted as UTF-8 encoded text data. - TextMessage = 1 - - // BinaryMessage denotes a binary data message. - BinaryMessage = 2 - - // CloseMessage denotes a close control message. The optional message - // payload contains a numeric code and text. Use the FormatCloseMessage - // function to format a close message payload. - CloseMessage = 8 - - // PingMessage denotes a ping control message. The optional message payload - // is UTF-8 encoded text. - PingMessage = 9 - - // PongMessage denotes a pong control message. The optional message payload - // is UTF-8 encoded text. - PongMessage = 10 -) - -// ErrCloseSent is returned when the application writes a message to the -// connection after sending a close message. -var ErrCloseSent = errors.New("websocket: close sent") - -// ErrReadLimit is returned when reading a message that is larger than the -// read limit set for the connection. -var ErrReadLimit = errors.New("websocket: read limit exceeded") - -// netError satisfies the net Error interface. -type netError struct { - msg string - temporary bool - timeout bool -} - -func (e *netError) Error() string { return e.msg } -func (e *netError) Temporary() bool { return e.temporary } -func (e *netError) Timeout() bool { return e.timeout } - -// CloseError represents a close message. -type CloseError struct { - // Code is defined in RFC 6455, section 11.7. - Code int - - // Text is the optional text payload. - Text string -} - -func (e *CloseError) Error() string { - s := []byte("websocket: close ") - s = strconv.AppendInt(s, int64(e.Code), 10) - switch e.Code { - case CloseNormalClosure: - s = append(s, " (normal)"...) - case CloseGoingAway: - s = append(s, " (going away)"...) - case CloseProtocolError: - s = append(s, " (protocol error)"...) - case CloseUnsupportedData: - s = append(s, " (unsupported data)"...) - case CloseNoStatusReceived: - s = append(s, " (no status)"...) - case CloseAbnormalClosure: - s = append(s, " (abnormal closure)"...) - case CloseInvalidFramePayloadData: - s = append(s, " (invalid payload data)"...) - case ClosePolicyViolation: - s = append(s, " (policy violation)"...) - case CloseMessageTooBig: - s = append(s, " (message too big)"...) - case CloseMandatoryExtension: - s = append(s, " (mandatory extension missing)"...) - case CloseInternalServerErr: - s = append(s, " (internal server error)"...) - case CloseTLSHandshake: - s = append(s, " (TLS handshake error)"...) - } - if e.Text != "" { - s = append(s, ": "...) - s = append(s, e.Text...) - } - return string(s) -} - -// IsCloseError returns boolean indicating whether the error is a *CloseError -// with one of the specified codes. -func IsCloseError(err error, codes ...int) bool { - if e, ok := err.(*CloseError); ok { - for _, code := range codes { - if e.Code == code { - return true - } - } - } - return false -} - -// IsUnexpectedCloseError returns boolean indicating whether the error is a -// *CloseError with a code not in the list of expected codes. -func IsUnexpectedCloseError(err error, expectedCodes ...int) bool { - if e, ok := err.(*CloseError); ok { - for _, code := range expectedCodes { - if e.Code == code { - return false - } - } - return true - } - return false -} - -var ( - errWriteTimeout = &netError{msg: "websocket: write timeout", timeout: true, temporary: true} - errUnexpectedEOF = &CloseError{Code: CloseAbnormalClosure, Text: io.ErrUnexpectedEOF.Error()} - errBadWriteOpCode = errors.New("websocket: bad write message type") - errWriteClosed = errors.New("websocket: write closed") - errInvalidControlFrame = errors.New("websocket: invalid control frame") -) - -func newMaskKey() [4]byte { - n := rand.Uint32() - return [4]byte{byte(n), byte(n >> 8), byte(n >> 16), byte(n >> 24)} -} - -func hideTempErr(err error) error { - if e, ok := err.(net.Error); ok && e.Temporary() { - err = &netError{msg: e.Error(), timeout: e.Timeout()} - } - return err -} - -func isControl(frameType int) bool { - return frameType == CloseMessage || frameType == PingMessage || frameType == PongMessage -} - -func isData(frameType int) bool { - return frameType == TextMessage || frameType == BinaryMessage -} - -var validReceivedCloseCodes = map[int]bool{ - // see http://www.iana.org/assignments/websocket/websocket.xhtml#close-code-number - - CloseNormalClosure: true, - CloseGoingAway: true, - CloseProtocolError: true, - CloseUnsupportedData: true, - CloseNoStatusReceived: false, - CloseAbnormalClosure: false, - CloseInvalidFramePayloadData: true, - ClosePolicyViolation: true, - CloseMessageTooBig: true, - CloseMandatoryExtension: true, - CloseInternalServerErr: true, - CloseServiceRestart: true, - CloseTryAgainLater: true, - CloseTLSHandshake: false, -} - -func isValidReceivedCloseCode(code int) bool { - return validReceivedCloseCodes[code] || (code >= 3000 && code <= 4999) -} - -// BufferPool represents a pool of buffers. The *sync.Pool type satisfies this -// interface. The type of the value stored in a pool is not specified. -type BufferPool interface { - // Get gets a value from the pool or returns nil if the pool is empty. - Get() interface{} - // Put adds a value to the pool. - Put(interface{}) -} - -// writePoolData is the type added to the write buffer pool. This wrapper is -// used to prevent applications from peeking at and depending on the values -// added to the pool. -type writePoolData struct{ buf []byte } - -// The Conn type represents a WebSocket connection. -type Conn struct { - conn net.Conn - isServer bool - subprotocol string - - // Write fields - mu chan struct{} // used as mutex to protect write to conn - writeBuf []byte // frame is constructed in this buffer. - writePool BufferPool - writeBufSize int - writeDeadline time.Time - writer io.WriteCloser // the current writer returned to the application - isWriting bool // for best-effort concurrent write detection - - writeErrMu sync.Mutex - writeErr error - - enableWriteCompression bool - compressionLevel int - newCompressionWriter func(io.WriteCloser, int) io.WriteCloser - - // Read fields - reader io.ReadCloser // the current reader returned to the application - readErr error - br *bufio.Reader - // bytes remaining in current frame. - // set setReadRemaining to safely update this value and prevent overflow - readRemaining int64 - readFinal bool // true the current message has more frames. - readLength int64 // Message size. - readLimit int64 // Maximum message size. - readMaskPos int - readMaskKey [4]byte - handlePong func(string) error - handlePing func(string) error - handleClose func(int, string) error - readErrCount int - messageReader *messageReader // the current low-level reader - - readDecompress bool // whether last read frame had RSV1 set - newDecompressionReader func(io.Reader) io.ReadCloser -} - -func newConn(conn net.Conn, isServer bool, readBufferSize, writeBufferSize int, writeBufferPool BufferPool, br *bufio.Reader, writeBuf []byte) *Conn { - - if br == nil { - if readBufferSize == 0 { - readBufferSize = defaultReadBufferSize - } else if readBufferSize < maxControlFramePayloadSize { - // must be large enough for control frame - readBufferSize = maxControlFramePayloadSize - } - br = bufio.NewReaderSize(conn, readBufferSize) - } - - if writeBufferSize <= 0 { - writeBufferSize = defaultWriteBufferSize - } - writeBufferSize += maxFrameHeaderSize - - if writeBuf == nil && writeBufferPool == nil { - writeBuf = make([]byte, writeBufferSize) - } - - mu := make(chan struct{}, 1) - mu <- struct{}{} - c := &Conn{ - isServer: isServer, - br: br, - conn: conn, - mu: mu, - readFinal: true, - writeBuf: writeBuf, - writePool: writeBufferPool, - writeBufSize: writeBufferSize, - enableWriteCompression: true, - compressionLevel: defaultCompressionLevel, - } - c.SetCloseHandler(nil) - c.SetPingHandler(nil) - c.SetPongHandler(nil) - return c -} - -// setReadRemaining tracks the number of bytes remaining on the connection. If n -// overflows, an ErrReadLimit is returned. -func (c *Conn) setReadRemaining(n int64) error { - if n < 0 { - return ErrReadLimit - } - - c.readRemaining = n - return nil -} - -// Subprotocol returns the negotiated protocol for the connection. -func (c *Conn) Subprotocol() string { - return c.subprotocol -} - -// Close closes the underlying network connection without sending or waiting -// for a close message. -func (c *Conn) Close() error { - return c.conn.Close() -} - -// LocalAddr returns the local network address. -func (c *Conn) LocalAddr() net.Addr { - return c.conn.LocalAddr() -} - -// RemoteAddr returns the remote network address. -func (c *Conn) RemoteAddr() net.Addr { - return c.conn.RemoteAddr() -} - -// Write methods - -func (c *Conn) writeFatal(err error) error { - err = hideTempErr(err) - c.writeErrMu.Lock() - if c.writeErr == nil { - c.writeErr = err - } - c.writeErrMu.Unlock() - return err -} - -func (c *Conn) read(n int) ([]byte, error) { - p, err := c.br.Peek(n) - if err == io.EOF { - err = errUnexpectedEOF - } - c.br.Discard(len(p)) - return p, err -} - -func (c *Conn) write(frameType int, deadline time.Time, buf0, buf1 []byte) error { - <-c.mu - defer func() { c.mu <- struct{}{} }() - - c.writeErrMu.Lock() - err := c.writeErr - c.writeErrMu.Unlock() - if err != nil { - return err - } - - c.conn.SetWriteDeadline(deadline) - if len(buf1) == 0 { - _, err = c.conn.Write(buf0) - } else { - err = c.writeBufs(buf0, buf1) - } - if err != nil { - return c.writeFatal(err) - } - if frameType == CloseMessage { - c.writeFatal(ErrCloseSent) - } - return nil -} - -// WriteControl writes a control message with the given deadline. The allowed -// message types are CloseMessage, PingMessage and PongMessage. -func (c *Conn) WriteControl(messageType int, data []byte, deadline time.Time) error { - if !isControl(messageType) { - return errBadWriteOpCode - } - if len(data) > maxControlFramePayloadSize { - return errInvalidControlFrame - } - - b0 := byte(messageType) | finalBit - b1 := byte(len(data)) - if !c.isServer { - b1 |= maskBit - } - - buf := make([]byte, 0, maxFrameHeaderSize+maxControlFramePayloadSize) - buf = append(buf, b0, b1) - - if c.isServer { - buf = append(buf, data...) - } else { - key := newMaskKey() - buf = append(buf, key[:]...) - buf = append(buf, data...) - maskBytes(key, 0, buf[6:]) - } - - d := 1000 * time.Hour - if !deadline.IsZero() { - d = deadline.Sub(time.Now()) - if d < 0 { - return errWriteTimeout - } - } - - timer := time.NewTimer(d) - select { - case <-c.mu: - timer.Stop() - case <-timer.C: - return errWriteTimeout - } - defer func() { c.mu <- struct{}{} }() - - c.writeErrMu.Lock() - err := c.writeErr - c.writeErrMu.Unlock() - if err != nil { - return err - } - - c.conn.SetWriteDeadline(deadline) - _, err = c.conn.Write(buf) - if err != nil { - return c.writeFatal(err) - } - if messageType == CloseMessage { - c.writeFatal(ErrCloseSent) - } - return err -} - -// beginMessage prepares a connection and message writer for a new message. -func (c *Conn) beginMessage(mw *messageWriter, messageType int) error { - // Close previous writer if not already closed by the application. It's - // probably better to return an error in this situation, but we cannot - // change this without breaking existing applications. - if c.writer != nil { - c.writer.Close() - c.writer = nil - } - - if !isControl(messageType) && !isData(messageType) { - return errBadWriteOpCode - } - - c.writeErrMu.Lock() - err := c.writeErr - c.writeErrMu.Unlock() - if err != nil { - return err - } - - mw.c = c - mw.frameType = messageType - mw.pos = maxFrameHeaderSize - - if c.writeBuf == nil { - wpd, ok := c.writePool.Get().(writePoolData) - if ok { - c.writeBuf = wpd.buf - } else { - c.writeBuf = make([]byte, c.writeBufSize) - } - } - return nil -} - -// NextWriter returns a writer for the next message to send. The writer's Close -// method flushes the complete message to the network. -// -// There can be at most one open writer on a connection. NextWriter closes the -// previous writer if the application has not already done so. -// -// All message types (TextMessage, BinaryMessage, CloseMessage, PingMessage and -// PongMessage) are supported. -func (c *Conn) NextWriter(messageType int) (io.WriteCloser, error) { - var mw messageWriter - if err := c.beginMessage(&mw, messageType); err != nil { - return nil, err - } - c.writer = &mw - if c.newCompressionWriter != nil && c.enableWriteCompression && isData(messageType) { - w := c.newCompressionWriter(c.writer, c.compressionLevel) - mw.compress = true - c.writer = w - } - return c.writer, nil -} - -type messageWriter struct { - c *Conn - compress bool // whether next call to flushFrame should set RSV1 - pos int // end of data in writeBuf. - frameType int // type of the current frame. - err error -} - -func (w *messageWriter) endMessage(err error) error { - if w.err != nil { - return err - } - c := w.c - w.err = err - c.writer = nil - if c.writePool != nil { - c.writePool.Put(writePoolData{buf: c.writeBuf}) - c.writeBuf = nil - } - return err -} - -// flushFrame writes buffered data and extra as a frame to the network. The -// final argument indicates that this is the last frame in the message. -func (w *messageWriter) flushFrame(final bool, extra []byte) error { - c := w.c - length := w.pos - maxFrameHeaderSize + len(extra) - - // Check for invalid control frames. - if isControl(w.frameType) && - (!final || length > maxControlFramePayloadSize) { - return w.endMessage(errInvalidControlFrame) - } - - b0 := byte(w.frameType) - if final { - b0 |= finalBit - } - if w.compress { - b0 |= rsv1Bit - } - w.compress = false - - b1 := byte(0) - if !c.isServer { - b1 |= maskBit - } - - // Assume that the frame starts at beginning of c.writeBuf. - framePos := 0 - if c.isServer { - // Adjust up if mask not included in the header. - framePos = 4 - } - - switch { - case length >= 65536: - c.writeBuf[framePos] = b0 - c.writeBuf[framePos+1] = b1 | 127 - binary.BigEndian.PutUint64(c.writeBuf[framePos+2:], uint64(length)) - case length > 125: - framePos += 6 - c.writeBuf[framePos] = b0 - c.writeBuf[framePos+1] = b1 | 126 - binary.BigEndian.PutUint16(c.writeBuf[framePos+2:], uint16(length)) - default: - framePos += 8 - c.writeBuf[framePos] = b0 - c.writeBuf[framePos+1] = b1 | byte(length) - } - - if !c.isServer { - key := newMaskKey() - copy(c.writeBuf[maxFrameHeaderSize-4:], key[:]) - maskBytes(key, 0, c.writeBuf[maxFrameHeaderSize:w.pos]) - if len(extra) > 0 { - return w.endMessage(c.writeFatal(errors.New("websocket: internal error, extra used in client mode"))) - } - } - - // Write the buffers to the connection with best-effort detection of - // concurrent writes. See the concurrency section in the package - // documentation for more info. - - if c.isWriting { - panic("concurrent write to websocket connection") - } - c.isWriting = true - - err := c.write(w.frameType, c.writeDeadline, c.writeBuf[framePos:w.pos], extra) - - if !c.isWriting { - panic("concurrent write to websocket connection") - } - c.isWriting = false - - if err != nil { - return w.endMessage(err) - } - - if final { - w.endMessage(errWriteClosed) - return nil - } - - // Setup for next frame. - w.pos = maxFrameHeaderSize - w.frameType = continuationFrame - return nil -} - -func (w *messageWriter) ncopy(max int) (int, error) { - n := len(w.c.writeBuf) - w.pos - if n <= 0 { - if err := w.flushFrame(false, nil); err != nil { - return 0, err - } - n = len(w.c.writeBuf) - w.pos - } - if n > max { - n = max - } - return n, nil -} - -func (w *messageWriter) Write(p []byte) (int, error) { - if w.err != nil { - return 0, w.err - } - - if len(p) > 2*len(w.c.writeBuf) && w.c.isServer { - // Don't buffer large messages. - err := w.flushFrame(false, p) - if err != nil { - return 0, err - } - return len(p), nil - } - - nn := len(p) - for len(p) > 0 { - n, err := w.ncopy(len(p)) - if err != nil { - return 0, err - } - copy(w.c.writeBuf[w.pos:], p[:n]) - w.pos += n - p = p[n:] - } - return nn, nil -} - -func (w *messageWriter) WriteString(p string) (int, error) { - if w.err != nil { - return 0, w.err - } - - nn := len(p) - for len(p) > 0 { - n, err := w.ncopy(len(p)) - if err != nil { - return 0, err - } - copy(w.c.writeBuf[w.pos:], p[:n]) - w.pos += n - p = p[n:] - } - return nn, nil -} - -func (w *messageWriter) ReadFrom(r io.Reader) (nn int64, err error) { - if w.err != nil { - return 0, w.err - } - for { - if w.pos == len(w.c.writeBuf) { - err = w.flushFrame(false, nil) - if err != nil { - break - } - } - var n int - n, err = r.Read(w.c.writeBuf[w.pos:]) - w.pos += n - nn += int64(n) - if err != nil { - if err == io.EOF { - err = nil - } - break - } - } - return nn, err -} - -func (w *messageWriter) Close() error { - if w.err != nil { - return w.err - } - return w.flushFrame(true, nil) -} - -// WritePreparedMessage writes prepared message into connection. -func (c *Conn) WritePreparedMessage(pm *PreparedMessage) error { - frameType, frameData, err := pm.frame(prepareKey{ - isServer: c.isServer, - compress: c.newCompressionWriter != nil && c.enableWriteCompression && isData(pm.messageType), - compressionLevel: c.compressionLevel, - }) - if err != nil { - return err - } - if c.isWriting { - panic("concurrent write to websocket connection") - } - c.isWriting = true - err = c.write(frameType, c.writeDeadline, frameData, nil) - if !c.isWriting { - panic("concurrent write to websocket connection") - } - c.isWriting = false - return err -} - -// WriteMessage is a helper method for getting a writer using NextWriter, -// writing the message and closing the writer. -func (c *Conn) WriteMessage(messageType int, data []byte) error { - - if c.isServer && (c.newCompressionWriter == nil || !c.enableWriteCompression) { - // Fast path with no allocations and single frame. - - var mw messageWriter - if err := c.beginMessage(&mw, messageType); err != nil { - return err - } - n := copy(c.writeBuf[mw.pos:], data) - mw.pos += n - data = data[n:] - return mw.flushFrame(true, data) - } - - w, err := c.NextWriter(messageType) - if err != nil { - return err - } - if _, err = w.Write(data); err != nil { - return err - } - return w.Close() -} - -// SetWriteDeadline sets the write deadline on the underlying network -// connection. After a write has timed out, the websocket state is corrupt and -// all future writes will return an error. A zero value for t means writes will -// not time out. -func (c *Conn) SetWriteDeadline(t time.Time) error { - c.writeDeadline = t - return nil -} - -// Read methods - -func (c *Conn) advanceFrame() (int, error) { - // 1. Skip remainder of previous frame. - - if c.readRemaining > 0 { - if _, err := io.CopyN(ioutil.Discard, c.br, c.readRemaining); err != nil { - return noFrame, err - } - } - - // 2. Read and parse first two bytes of frame header. - - p, err := c.read(2) - if err != nil { - return noFrame, err - } - - final := p[0]&finalBit != 0 - frameType := int(p[0] & 0xf) - mask := p[1]&maskBit != 0 - c.setReadRemaining(int64(p[1] & 0x7f)) - - c.readDecompress = false - if c.newDecompressionReader != nil && (p[0]&rsv1Bit) != 0 { - c.readDecompress = true - p[0] &^= rsv1Bit - } - - if rsv := p[0] & (rsv1Bit | rsv2Bit | rsv3Bit); rsv != 0 { - return noFrame, c.handleProtocolError("unexpected reserved bits 0x" + strconv.FormatInt(int64(rsv), 16)) - } - - switch frameType { - case CloseMessage, PingMessage, PongMessage: - if c.readRemaining > maxControlFramePayloadSize { - return noFrame, c.handleProtocolError("control frame length > 125") - } - if !final { - return noFrame, c.handleProtocolError("control frame not final") - } - case TextMessage, BinaryMessage: - if !c.readFinal { - return noFrame, c.handleProtocolError("message start before final message frame") - } - c.readFinal = final - case continuationFrame: - if c.readFinal { - return noFrame, c.handleProtocolError("continuation after final message frame") - } - c.readFinal = final - default: - return noFrame, c.handleProtocolError("unknown opcode " + strconv.Itoa(frameType)) - } - - // 3. Read and parse frame length as per - // https://tools.ietf.org/html/rfc6455#section-5.2 - // - // The length of the "Payload data", in bytes: if 0-125, that is the payload - // length. - // - If 126, the following 2 bytes interpreted as a 16-bit unsigned - // integer are the payload length. - // - If 127, the following 8 bytes interpreted as - // a 64-bit unsigned integer (the most significant bit MUST be 0) are the - // payload length. Multibyte length quantities are expressed in network byte - // order. - - switch c.readRemaining { - case 126: - p, err := c.read(2) - if err != nil { - return noFrame, err - } - - if err := c.setReadRemaining(int64(binary.BigEndian.Uint16(p))); err != nil { - return noFrame, err - } - case 127: - p, err := c.read(8) - if err != nil { - return noFrame, err - } - - if err := c.setReadRemaining(int64(binary.BigEndian.Uint64(p))); err != nil { - return noFrame, err - } - } - - // 4. Handle frame masking. - - if mask != c.isServer { - return noFrame, c.handleProtocolError("incorrect mask flag") - } - - if mask { - c.readMaskPos = 0 - p, err := c.read(len(c.readMaskKey)) - if err != nil { - return noFrame, err - } - copy(c.readMaskKey[:], p) - } - - // 5. For text and binary messages, enforce read limit and return. - - if frameType == continuationFrame || frameType == TextMessage || frameType == BinaryMessage { - - c.readLength += c.readRemaining - // Don't allow readLength to overflow in the presence of a large readRemaining - // counter. - if c.readLength < 0 { - return noFrame, ErrReadLimit - } - - if c.readLimit > 0 && c.readLength > c.readLimit { - c.WriteControl(CloseMessage, FormatCloseMessage(CloseMessageTooBig, ""), time.Now().Add(writeWait)) - return noFrame, ErrReadLimit - } - - return frameType, nil - } - - // 6. Read control frame payload. - - var payload []byte - if c.readRemaining > 0 { - payload, err = c.read(int(c.readRemaining)) - c.setReadRemaining(0) - if err != nil { - return noFrame, err - } - if c.isServer { - maskBytes(c.readMaskKey, 0, payload) - } - } - - // 7. Process control frame payload. - - switch frameType { - case PongMessage: - if err := c.handlePong(string(payload)); err != nil { - return noFrame, err - } - case PingMessage: - if err := c.handlePing(string(payload)); err != nil { - return noFrame, err - } - case CloseMessage: - closeCode := CloseNoStatusReceived - closeText := "" - if len(payload) >= 2 { - closeCode = int(binary.BigEndian.Uint16(payload)) - if !isValidReceivedCloseCode(closeCode) { - return noFrame, c.handleProtocolError("invalid close code") - } - closeText = string(payload[2:]) - if !utf8.ValidString(closeText) { - return noFrame, c.handleProtocolError("invalid utf8 payload in close frame") - } - } - if err := c.handleClose(closeCode, closeText); err != nil { - return noFrame, err - } - return noFrame, &CloseError{Code: closeCode, Text: closeText} - } - - return frameType, nil -} - -func (c *Conn) handleProtocolError(message string) error { - c.WriteControl(CloseMessage, FormatCloseMessage(CloseProtocolError, message), time.Now().Add(writeWait)) - return errors.New("websocket: " + message) -} - -// NextReader returns the next data message received from the peer. The -// returned messageType is either TextMessage or BinaryMessage. -// -// There can be at most one open reader on a connection. NextReader discards -// the previous message if the application has not already consumed it. -// -// Applications must break out of the application's read loop when this method -// returns a non-nil error value. Errors returned from this method are -// permanent. Once this method returns a non-nil error, all subsequent calls to -// this method return the same error. -func (c *Conn) NextReader() (messageType int, r io.Reader, err error) { - // Close previous reader, only relevant for decompression. - if c.reader != nil { - c.reader.Close() - c.reader = nil - } - - c.messageReader = nil - c.readLength = 0 - - for c.readErr == nil { - frameType, err := c.advanceFrame() - if err != nil { - c.readErr = hideTempErr(err) - break - } - - if frameType == TextMessage || frameType == BinaryMessage { - c.messageReader = &messageReader{c} - c.reader = c.messageReader - if c.readDecompress { - c.reader = c.newDecompressionReader(c.reader) - } - return frameType, c.reader, nil - } - } - - // Applications that do handle the error returned from this method spin in - // tight loop on connection failure. To help application developers detect - // this error, panic on repeated reads to the failed connection. - c.readErrCount++ - if c.readErrCount >= 1000 { - panic("repeated read on failed websocket connection") - } - - return noFrame, nil, c.readErr -} - -type messageReader struct{ c *Conn } - -func (r *messageReader) Read(b []byte) (int, error) { - c := r.c - if c.messageReader != r { - return 0, io.EOF - } - - for c.readErr == nil { - - if c.readRemaining > 0 { - if int64(len(b)) > c.readRemaining { - b = b[:c.readRemaining] - } - n, err := c.br.Read(b) - c.readErr = hideTempErr(err) - if c.isServer { - c.readMaskPos = maskBytes(c.readMaskKey, c.readMaskPos, b[:n]) - } - rem := c.readRemaining - rem -= int64(n) - c.setReadRemaining(rem) - if c.readRemaining > 0 && c.readErr == io.EOF { - c.readErr = errUnexpectedEOF - } - return n, c.readErr - } - - if c.readFinal { - c.messageReader = nil - return 0, io.EOF - } - - frameType, err := c.advanceFrame() - switch { - case err != nil: - c.readErr = hideTempErr(err) - case frameType == TextMessage || frameType == BinaryMessage: - c.readErr = errors.New("websocket: internal error, unexpected text or binary in Reader") - } - } - - err := c.readErr - if err == io.EOF && c.messageReader == r { - err = errUnexpectedEOF - } - return 0, err -} - -func (r *messageReader) Close() error { - return nil -} - -// ReadMessage is a helper method for getting a reader using NextReader and -// reading from that reader to a buffer. -func (c *Conn) ReadMessage() (messageType int, p []byte, err error) { - var r io.Reader - messageType, r, err = c.NextReader() - if err != nil { - return messageType, nil, err - } - p, err = ioutil.ReadAll(r) - return messageType, p, err -} - -// SetReadDeadline sets the read deadline on the underlying network connection. -// After a read has timed out, the websocket connection state is corrupt and -// all future reads will return an error. A zero value for t means reads will -// not time out. -func (c *Conn) SetReadDeadline(t time.Time) error { - return c.conn.SetReadDeadline(t) -} - -// SetReadLimit sets the maximum size in bytes for a message read from the peer. If a -// message exceeds the limit, the connection sends a close message to the peer -// and returns ErrReadLimit to the application. -func (c *Conn) SetReadLimit(limit int64) { - c.readLimit = limit -} - -// CloseHandler returns the current close handler -func (c *Conn) CloseHandler() func(code int, text string) error { - return c.handleClose -} - -// SetCloseHandler sets the handler for close messages received from the peer. -// The code argument to h is the received close code or CloseNoStatusReceived -// if the close message is empty. The default close handler sends a close -// message back to the peer. -// -// The handler function is called from the NextReader, ReadMessage and message -// reader Read methods. The application must read the connection to process -// close messages as described in the section on Control Messages above. -// -// The connection read methods return a CloseError when a close message is -// received. Most applications should handle close messages as part of their -// normal error handling. Applications should only set a close handler when the -// application must perform some action before sending a close message back to -// the peer. -func (c *Conn) SetCloseHandler(h func(code int, text string) error) { - if h == nil { - h = func(code int, text string) error { - message := FormatCloseMessage(code, "") - c.WriteControl(CloseMessage, message, time.Now().Add(writeWait)) - return nil - } - } - c.handleClose = h -} - -// PingHandler returns the current ping handler -func (c *Conn) PingHandler() func(appData string) error { - return c.handlePing -} - -// SetPingHandler sets the handler for ping messages received from the peer. -// The appData argument to h is the PING message application data. The default -// ping handler sends a pong to the peer. -// -// The handler function is called from the NextReader, ReadMessage and message -// reader Read methods. The application must read the connection to process -// ping messages as described in the section on Control Messages above. -func (c *Conn) SetPingHandler(h func(appData string) error) { - if h == nil { - h = func(message string) error { - err := c.WriteControl(PongMessage, []byte(message), time.Now().Add(writeWait)) - if err == ErrCloseSent { - return nil - } else if e, ok := err.(net.Error); ok && e.Temporary() { - return nil - } - return err - } - } - c.handlePing = h -} - -// PongHandler returns the current pong handler -func (c *Conn) PongHandler() func(appData string) error { - return c.handlePong -} - -// SetPongHandler sets the handler for pong messages received from the peer. -// The appData argument to h is the PONG message application data. The default -// pong handler does nothing. -// -// The handler function is called from the NextReader, ReadMessage and message -// reader Read methods. The application must read the connection to process -// pong messages as described in the section on Control Messages above. -func (c *Conn) SetPongHandler(h func(appData string) error) { - if h == nil { - h = func(string) error { return nil } - } - c.handlePong = h -} - -// UnderlyingConn returns the internal net.Conn. This can be used to further -// modifications to connection specific flags. -func (c *Conn) UnderlyingConn() net.Conn { - return c.conn -} - -// EnableWriteCompression enables and disables write compression of -// subsequent text and binary messages. This function is a noop if -// compression was not negotiated with the peer. -func (c *Conn) EnableWriteCompression(enable bool) { - c.enableWriteCompression = enable -} - -// SetCompressionLevel sets the flate compression level for subsequent text and -// binary messages. This function is a noop if compression was not negotiated -// with the peer. See the compress/flate package for a description of -// compression levels. -func (c *Conn) SetCompressionLevel(level int) error { - if !isValidCompressionLevel(level) { - return errors.New("websocket: invalid compression level") - } - c.compressionLevel = level - return nil -} - -// FormatCloseMessage formats closeCode and text as a WebSocket close message. -// An empty message is returned for code CloseNoStatusReceived. -func FormatCloseMessage(closeCode int, text string) []byte { - if closeCode == CloseNoStatusReceived { - // Return empty message because it's illegal to send - // CloseNoStatusReceived. Return non-nil value in case application - // checks for nil. - return []byte{} - } - buf := make([]byte, 2+len(text)) - binary.BigEndian.PutUint16(buf, uint16(closeCode)) - copy(buf[2:], text) - return buf -} diff --git a/vendor/github.com/gorilla/websocket/conn_write.go b/vendor/github.com/gorilla/websocket/conn_write.go deleted file mode 100644 index a509a21f87..0000000000 --- a/vendor/github.com/gorilla/websocket/conn_write.go +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2016 The Gorilla WebSocket Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// +build go1.8 - -package websocket - -import "net" - -func (c *Conn) writeBufs(bufs ...[]byte) error { - b := net.Buffers(bufs) - _, err := b.WriteTo(c.conn) - return err -} diff --git a/vendor/github.com/gorilla/websocket/conn_write_legacy.go b/vendor/github.com/gorilla/websocket/conn_write_legacy.go deleted file mode 100644 index 37edaff5a5..0000000000 --- a/vendor/github.com/gorilla/websocket/conn_write_legacy.go +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright 2016 The Gorilla WebSocket Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// +build !go1.8 - -package websocket - -func (c *Conn) writeBufs(bufs ...[]byte) error { - for _, buf := range bufs { - if len(buf) > 0 { - if _, err := c.conn.Write(buf); err != nil { - return err - } - } - } - return nil -} diff --git a/vendor/github.com/gorilla/websocket/doc.go b/vendor/github.com/gorilla/websocket/doc.go deleted file mode 100644 index 8db0cef95a..0000000000 --- a/vendor/github.com/gorilla/websocket/doc.go +++ /dev/null @@ -1,227 +0,0 @@ -// Copyright 2013 The Gorilla WebSocket Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// Package websocket implements the WebSocket protocol defined in RFC 6455. -// -// Overview -// -// The Conn type represents a WebSocket connection. A server application calls -// the Upgrader.Upgrade method from an HTTP request handler to get a *Conn: -// -// var upgrader = websocket.Upgrader{ -// ReadBufferSize: 1024, -// WriteBufferSize: 1024, -// } -// -// func handler(w http.ResponseWriter, r *http.Request) { -// conn, err := upgrader.Upgrade(w, r, nil) -// if err != nil { -// log.Println(err) -// return -// } -// ... Use conn to send and receive messages. -// } -// -// Call the connection's WriteMessage and ReadMessage methods to send and -// receive messages as a slice of bytes. This snippet of code shows how to echo -// messages using these methods: -// -// for { -// messageType, p, err := conn.ReadMessage() -// if err != nil { -// log.Println(err) -// return -// } -// if err := conn.WriteMessage(messageType, p); err != nil { -// log.Println(err) -// return -// } -// } -// -// In above snippet of code, p is a []byte and messageType is an int with value -// websocket.BinaryMessage or websocket.TextMessage. -// -// An application can also send and receive messages using the io.WriteCloser -// and io.Reader interfaces. To send a message, call the connection NextWriter -// method to get an io.WriteCloser, write the message to the writer and close -// the writer when done. To receive a message, call the connection NextReader -// method to get an io.Reader and read until io.EOF is returned. This snippet -// shows how to echo messages using the NextWriter and NextReader methods: -// -// for { -// messageType, r, err := conn.NextReader() -// if err != nil { -// return -// } -// w, err := conn.NextWriter(messageType) -// if err != nil { -// return err -// } -// if _, err := io.Copy(w, r); err != nil { -// return err -// } -// if err := w.Close(); err != nil { -// return err -// } -// } -// -// Data Messages -// -// The WebSocket protocol distinguishes between text and binary data messages. -// Text messages are interpreted as UTF-8 encoded text. The interpretation of -// binary messages is left to the application. -// -// This package uses the TextMessage and BinaryMessage integer constants to -// identify the two data message types. The ReadMessage and NextReader methods -// return the type of the received message. The messageType argument to the -// WriteMessage and NextWriter methods specifies the type of a sent message. -// -// It is the application's responsibility to ensure that text messages are -// valid UTF-8 encoded text. -// -// Control Messages -// -// The WebSocket protocol defines three types of control messages: close, ping -// and pong. Call the connection WriteControl, WriteMessage or NextWriter -// methods to send a control message to the peer. -// -// Connections handle received close messages by calling the handler function -// set with the SetCloseHandler method and by returning a *CloseError from the -// NextReader, ReadMessage or the message Read method. The default close -// handler sends a close message to the peer. -// -// Connections handle received ping messages by calling the handler function -// set with the SetPingHandler method. The default ping handler sends a pong -// message to the peer. -// -// Connections handle received pong messages by calling the handler function -// set with the SetPongHandler method. The default pong handler does nothing. -// If an application sends ping messages, then the application should set a -// pong handler to receive the corresponding pong. -// -// The control message handler functions are called from the NextReader, -// ReadMessage and message reader Read methods. The default close and ping -// handlers can block these methods for a short time when the handler writes to -// the connection. -// -// The application must read the connection to process close, ping and pong -// messages sent from the peer. If the application is not otherwise interested -// in messages from the peer, then the application should start a goroutine to -// read and discard messages from the peer. A simple example is: -// -// func readLoop(c *websocket.Conn) { -// for { -// if _, _, err := c.NextReader(); err != nil { -// c.Close() -// break -// } -// } -// } -// -// Concurrency -// -// Connections support one concurrent reader and one concurrent writer. -// -// Applications are responsible for ensuring that no more than one goroutine -// calls the write methods (NextWriter, SetWriteDeadline, WriteMessage, -// WriteJSON, EnableWriteCompression, SetCompressionLevel) concurrently and -// that no more than one goroutine calls the read methods (NextReader, -// SetReadDeadline, ReadMessage, ReadJSON, SetPongHandler, SetPingHandler) -// concurrently. -// -// The Close and WriteControl methods can be called concurrently with all other -// methods. -// -// Origin Considerations -// -// Web browsers allow Javascript applications to open a WebSocket connection to -// any host. It's up to the server to enforce an origin policy using the Origin -// request header sent by the browser. -// -// The Upgrader calls the function specified in the CheckOrigin field to check -// the origin. If the CheckOrigin function returns false, then the Upgrade -// method fails the WebSocket handshake with HTTP status 403. -// -// If the CheckOrigin field is nil, then the Upgrader uses a safe default: fail -// the handshake if the Origin request header is present and the Origin host is -// not equal to the Host request header. -// -// The deprecated package-level Upgrade function does not perform origin -// checking. The application is responsible for checking the Origin header -// before calling the Upgrade function. -// -// Buffers -// -// Connections buffer network input and output to reduce the number -// of system calls when reading or writing messages. -// -// Write buffers are also used for constructing WebSocket frames. See RFC 6455, -// Section 5 for a discussion of message framing. A WebSocket frame header is -// written to the network each time a write buffer is flushed to the network. -// Decreasing the size of the write buffer can increase the amount of framing -// overhead on the connection. -// -// The buffer sizes in bytes are specified by the ReadBufferSize and -// WriteBufferSize fields in the Dialer and Upgrader. The Dialer uses a default -// size of 4096 when a buffer size field is set to zero. The Upgrader reuses -// buffers created by the HTTP server when a buffer size field is set to zero. -// The HTTP server buffers have a size of 4096 at the time of this writing. -// -// The buffer sizes do not limit the size of a message that can be read or -// written by a connection. -// -// Buffers are held for the lifetime of the connection by default. If the -// Dialer or Upgrader WriteBufferPool field is set, then a connection holds the -// write buffer only when writing a message. -// -// Applications should tune the buffer sizes to balance memory use and -// performance. Increasing the buffer size uses more memory, but can reduce the -// number of system calls to read or write the network. In the case of writing, -// increasing the buffer size can reduce the number of frame headers written to -// the network. -// -// Some guidelines for setting buffer parameters are: -// -// Limit the buffer sizes to the maximum expected message size. Buffers larger -// than the largest message do not provide any benefit. -// -// Depending on the distribution of message sizes, setting the buffer size to -// a value less than the maximum expected message size can greatly reduce memory -// use with a small impact on performance. Here's an example: If 99% of the -// messages are smaller than 256 bytes and the maximum message size is 512 -// bytes, then a buffer size of 256 bytes will result in 1.01 more system calls -// than a buffer size of 512 bytes. The memory savings is 50%. -// -// A write buffer pool is useful when the application has a modest number -// writes over a large number of connections. when buffers are pooled, a larger -// buffer size has a reduced impact on total memory use and has the benefit of -// reducing system calls and frame overhead. -// -// Compression EXPERIMENTAL -// -// Per message compression extensions (RFC 7692) are experimentally supported -// by this package in a limited capacity. Setting the EnableCompression option -// to true in Dialer or Upgrader will attempt to negotiate per message deflate -// support. -// -// var upgrader = websocket.Upgrader{ -// EnableCompression: true, -// } -// -// If compression was successfully negotiated with the connection's peer, any -// message received in compressed form will be automatically decompressed. -// All Read methods will return uncompressed bytes. -// -// Per message compression of messages written to a connection can be enabled -// or disabled by calling the corresponding Conn method: -// -// conn.EnableWriteCompression(false) -// -// Currently this package does not support compression with "context takeover". -// This means that messages must be compressed and decompressed in isolation, -// without retaining sliding window or dictionary state across messages. For -// more details refer to RFC 7692. -// -// Use of compression is experimental and may result in decreased performance. -package websocket diff --git a/vendor/github.com/gorilla/websocket/go.mod b/vendor/github.com/gorilla/websocket/go.mod deleted file mode 100644 index 1a7afd5028..0000000000 --- a/vendor/github.com/gorilla/websocket/go.mod +++ /dev/null @@ -1,3 +0,0 @@ -module github.com/gorilla/websocket - -go 1.12 diff --git a/vendor/github.com/gorilla/websocket/go.sum b/vendor/github.com/gorilla/websocket/go.sum deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/vendor/github.com/gorilla/websocket/join.go b/vendor/github.com/gorilla/websocket/join.go deleted file mode 100644 index c64f8c8290..0000000000 --- a/vendor/github.com/gorilla/websocket/join.go +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright 2019 The Gorilla WebSocket Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package websocket - -import ( - "io" - "strings" -) - -// JoinMessages concatenates received messages to create a single io.Reader. -// The string term is appended to each message. The returned reader does not -// support concurrent calls to the Read method. -func JoinMessages(c *Conn, term string) io.Reader { - return &joinReader{c: c, term: term} -} - -type joinReader struct { - c *Conn - term string - r io.Reader -} - -func (r *joinReader) Read(p []byte) (int, error) { - if r.r == nil { - var err error - _, r.r, err = r.c.NextReader() - if err != nil { - return 0, err - } - if r.term != "" { - r.r = io.MultiReader(r.r, strings.NewReader(r.term)) - } - } - n, err := r.r.Read(p) - if err == io.EOF { - err = nil - r.r = nil - } - return n, err -} diff --git a/vendor/github.com/gorilla/websocket/json.go b/vendor/github.com/gorilla/websocket/json.go deleted file mode 100644 index dc2c1f6415..0000000000 --- a/vendor/github.com/gorilla/websocket/json.go +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright 2013 The Gorilla WebSocket Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package websocket - -import ( - "encoding/json" - "io" -) - -// WriteJSON writes the JSON encoding of v as a message. -// -// Deprecated: Use c.WriteJSON instead. -func WriteJSON(c *Conn, v interface{}) error { - return c.WriteJSON(v) -} - -// WriteJSON writes the JSON encoding of v as a message. -// -// See the documentation for encoding/json Marshal for details about the -// conversion of Go values to JSON. -func (c *Conn) WriteJSON(v interface{}) error { - w, err := c.NextWriter(TextMessage) - if err != nil { - return err - } - err1 := json.NewEncoder(w).Encode(v) - err2 := w.Close() - if err1 != nil { - return err1 - } - return err2 -} - -// ReadJSON reads the next JSON-encoded message from the connection and stores -// it in the value pointed to by v. -// -// Deprecated: Use c.ReadJSON instead. -func ReadJSON(c *Conn, v interface{}) error { - return c.ReadJSON(v) -} - -// ReadJSON reads the next JSON-encoded message from the connection and stores -// it in the value pointed to by v. -// -// See the documentation for the encoding/json Unmarshal function for details -// about the conversion of JSON to a Go value. -func (c *Conn) ReadJSON(v interface{}) error { - _, r, err := c.NextReader() - if err != nil { - return err - } - err = json.NewDecoder(r).Decode(v) - if err == io.EOF { - // One value is expected in the message. - err = io.ErrUnexpectedEOF - } - return err -} diff --git a/vendor/github.com/gorilla/websocket/mask.go b/vendor/github.com/gorilla/websocket/mask.go deleted file mode 100644 index 577fce9efd..0000000000 --- a/vendor/github.com/gorilla/websocket/mask.go +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright 2016 The Gorilla WebSocket Authors. All rights reserved. Use of -// this source code is governed by a BSD-style license that can be found in the -// LICENSE file. - -// +build !appengine - -package websocket - -import "unsafe" - -const wordSize = int(unsafe.Sizeof(uintptr(0))) - -func maskBytes(key [4]byte, pos int, b []byte) int { - // Mask one byte at a time for small buffers. - if len(b) < 2*wordSize { - for i := range b { - b[i] ^= key[pos&3] - pos++ - } - return pos & 3 - } - - // Mask one byte at a time to word boundary. - if n := int(uintptr(unsafe.Pointer(&b[0]))) % wordSize; n != 0 { - n = wordSize - n - for i := range b[:n] { - b[i] ^= key[pos&3] - pos++ - } - b = b[n:] - } - - // Create aligned word size key. - var k [wordSize]byte - for i := range k { - k[i] = key[(pos+i)&3] - } - kw := *(*uintptr)(unsafe.Pointer(&k)) - - // Mask one word at a time. - n := (len(b) / wordSize) * wordSize - for i := 0; i < n; i += wordSize { - *(*uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&b[0])) + uintptr(i))) ^= kw - } - - // Mask one byte at a time for remaining bytes. - b = b[n:] - for i := range b { - b[i] ^= key[pos&3] - pos++ - } - - return pos & 3 -} diff --git a/vendor/github.com/gorilla/websocket/mask_safe.go b/vendor/github.com/gorilla/websocket/mask_safe.go deleted file mode 100644 index 2aac060e52..0000000000 --- a/vendor/github.com/gorilla/websocket/mask_safe.go +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2016 The Gorilla WebSocket Authors. All rights reserved. Use of -// this source code is governed by a BSD-style license that can be found in the -// LICENSE file. - -// +build appengine - -package websocket - -func maskBytes(key [4]byte, pos int, b []byte) int { - for i := range b { - b[i] ^= key[pos&3] - pos++ - } - return pos & 3 -} diff --git a/vendor/github.com/gorilla/websocket/prepared.go b/vendor/github.com/gorilla/websocket/prepared.go deleted file mode 100644 index c854225e96..0000000000 --- a/vendor/github.com/gorilla/websocket/prepared.go +++ /dev/null @@ -1,102 +0,0 @@ -// Copyright 2017 The Gorilla WebSocket Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package websocket - -import ( - "bytes" - "net" - "sync" - "time" -) - -// PreparedMessage caches on the wire representations of a message payload. -// Use PreparedMessage to efficiently send a message payload to multiple -// connections. PreparedMessage is especially useful when compression is used -// because the CPU and memory expensive compression operation can be executed -// once for a given set of compression options. -type PreparedMessage struct { - messageType int - data []byte - mu sync.Mutex - frames map[prepareKey]*preparedFrame -} - -// prepareKey defines a unique set of options to cache prepared frames in PreparedMessage. -type prepareKey struct { - isServer bool - compress bool - compressionLevel int -} - -// preparedFrame contains data in wire representation. -type preparedFrame struct { - once sync.Once - data []byte -} - -// NewPreparedMessage returns an initialized PreparedMessage. You can then send -// it to connection using WritePreparedMessage method. Valid wire -// representation will be calculated lazily only once for a set of current -// connection options. -func NewPreparedMessage(messageType int, data []byte) (*PreparedMessage, error) { - pm := &PreparedMessage{ - messageType: messageType, - frames: make(map[prepareKey]*preparedFrame), - data: data, - } - - // Prepare a plain server frame. - _, frameData, err := pm.frame(prepareKey{isServer: true, compress: false}) - if err != nil { - return nil, err - } - - // To protect against caller modifying the data argument, remember the data - // copied to the plain server frame. - pm.data = frameData[len(frameData)-len(data):] - return pm, nil -} - -func (pm *PreparedMessage) frame(key prepareKey) (int, []byte, error) { - pm.mu.Lock() - frame, ok := pm.frames[key] - if !ok { - frame = &preparedFrame{} - pm.frames[key] = frame - } - pm.mu.Unlock() - - var err error - frame.once.Do(func() { - // Prepare a frame using a 'fake' connection. - // TODO: Refactor code in conn.go to allow more direct construction of - // the frame. - mu := make(chan struct{}, 1) - mu <- struct{}{} - var nc prepareConn - c := &Conn{ - conn: &nc, - mu: mu, - isServer: key.isServer, - compressionLevel: key.compressionLevel, - enableWriteCompression: true, - writeBuf: make([]byte, defaultWriteBufferSize+maxFrameHeaderSize), - } - if key.compress { - c.newCompressionWriter = compressNoContextTakeover - } - err = c.WriteMessage(pm.messageType, pm.data) - frame.data = nc.buf.Bytes() - }) - return pm.messageType, frame.data, err -} - -type prepareConn struct { - buf bytes.Buffer - net.Conn -} - -func (pc *prepareConn) Write(p []byte) (int, error) { return pc.buf.Write(p) } -func (pc *prepareConn) SetWriteDeadline(t time.Time) error { return nil } diff --git a/vendor/github.com/gorilla/websocket/proxy.go b/vendor/github.com/gorilla/websocket/proxy.go deleted file mode 100644 index e87a8c9f0c..0000000000 --- a/vendor/github.com/gorilla/websocket/proxy.go +++ /dev/null @@ -1,77 +0,0 @@ -// Copyright 2017 The Gorilla WebSocket Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package websocket - -import ( - "bufio" - "encoding/base64" - "errors" - "net" - "net/http" - "net/url" - "strings" -) - -type netDialerFunc func(network, addr string) (net.Conn, error) - -func (fn netDialerFunc) Dial(network, addr string) (net.Conn, error) { - return fn(network, addr) -} - -func init() { - proxy_RegisterDialerType("http", func(proxyURL *url.URL, forwardDialer proxy_Dialer) (proxy_Dialer, error) { - return &httpProxyDialer{proxyURL: proxyURL, forwardDial: forwardDialer.Dial}, nil - }) -} - -type httpProxyDialer struct { - proxyURL *url.URL - forwardDial func(network, addr string) (net.Conn, error) -} - -func (hpd *httpProxyDialer) Dial(network string, addr string) (net.Conn, error) { - hostPort, _ := hostPortNoPort(hpd.proxyURL) - conn, err := hpd.forwardDial(network, hostPort) - if err != nil { - return nil, err - } - - connectHeader := make(http.Header) - if user := hpd.proxyURL.User; user != nil { - proxyUser := user.Username() - if proxyPassword, passwordSet := user.Password(); passwordSet { - credential := base64.StdEncoding.EncodeToString([]byte(proxyUser + ":" + proxyPassword)) - connectHeader.Set("Proxy-Authorization", "Basic "+credential) - } - } - - connectReq := &http.Request{ - Method: "CONNECT", - URL: &url.URL{Opaque: addr}, - Host: addr, - Header: connectHeader, - } - - if err := connectReq.Write(conn); err != nil { - conn.Close() - return nil, err - } - - // Read response. It's OK to use and discard buffered reader here becaue - // the remote server does not speak until spoken to. - br := bufio.NewReader(conn) - resp, err := http.ReadResponse(br, connectReq) - if err != nil { - conn.Close() - return nil, err - } - - if resp.StatusCode != 200 { - conn.Close() - f := strings.SplitN(resp.Status, " ", 2) - return nil, errors.New(f[1]) - } - return conn, nil -} diff --git a/vendor/github.com/gorilla/websocket/server.go b/vendor/github.com/gorilla/websocket/server.go deleted file mode 100644 index 887d558918..0000000000 --- a/vendor/github.com/gorilla/websocket/server.go +++ /dev/null @@ -1,363 +0,0 @@ -// Copyright 2013 The Gorilla WebSocket Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package websocket - -import ( - "bufio" - "errors" - "io" - "net/http" - "net/url" - "strings" - "time" -) - -// HandshakeError describes an error with the handshake from the peer. -type HandshakeError struct { - message string -} - -func (e HandshakeError) Error() string { return e.message } - -// Upgrader specifies parameters for upgrading an HTTP connection to a -// WebSocket connection. -type Upgrader struct { - // HandshakeTimeout specifies the duration for the handshake to complete. - HandshakeTimeout time.Duration - - // ReadBufferSize and WriteBufferSize specify I/O buffer sizes in bytes. If a buffer - // size is zero, then buffers allocated by the HTTP server are used. The - // I/O buffer sizes do not limit the size of the messages that can be sent - // or received. - ReadBufferSize, WriteBufferSize int - - // WriteBufferPool is a pool of buffers for write operations. If the value - // is not set, then write buffers are allocated to the connection for the - // lifetime of the connection. - // - // A pool is most useful when the application has a modest volume of writes - // across a large number of connections. - // - // Applications should use a single pool for each unique value of - // WriteBufferSize. - WriteBufferPool BufferPool - - // Subprotocols specifies the server's supported protocols in order of - // preference. If this field is not nil, then the Upgrade method negotiates a - // subprotocol by selecting the first match in this list with a protocol - // requested by the client. If there's no match, then no protocol is - // negotiated (the Sec-Websocket-Protocol header is not included in the - // handshake response). - Subprotocols []string - - // Error specifies the function for generating HTTP error responses. If Error - // is nil, then http.Error is used to generate the HTTP response. - Error func(w http.ResponseWriter, r *http.Request, status int, reason error) - - // CheckOrigin returns true if the request Origin header is acceptable. If - // CheckOrigin is nil, then a safe default is used: return false if the - // Origin request header is present and the origin host is not equal to - // request Host header. - // - // A CheckOrigin function should carefully validate the request origin to - // prevent cross-site request forgery. - CheckOrigin func(r *http.Request) bool - - // EnableCompression specify if the server should attempt to negotiate per - // message compression (RFC 7692). Setting this value to true does not - // guarantee that compression will be supported. Currently only "no context - // takeover" modes are supported. - EnableCompression bool -} - -func (u *Upgrader) returnError(w http.ResponseWriter, r *http.Request, status int, reason string) (*Conn, error) { - err := HandshakeError{reason} - if u.Error != nil { - u.Error(w, r, status, err) - } else { - w.Header().Set("Sec-Websocket-Version", "13") - http.Error(w, http.StatusText(status), status) - } - return nil, err -} - -// checkSameOrigin returns true if the origin is not set or is equal to the request host. -func checkSameOrigin(r *http.Request) bool { - origin := r.Header["Origin"] - if len(origin) == 0 { - return true - } - u, err := url.Parse(origin[0]) - if err != nil { - return false - } - return equalASCIIFold(u.Host, r.Host) -} - -func (u *Upgrader) selectSubprotocol(r *http.Request, responseHeader http.Header) string { - if u.Subprotocols != nil { - clientProtocols := Subprotocols(r) - for _, serverProtocol := range u.Subprotocols { - for _, clientProtocol := range clientProtocols { - if clientProtocol == serverProtocol { - return clientProtocol - } - } - } - } else if responseHeader != nil { - return responseHeader.Get("Sec-Websocket-Protocol") - } - return "" -} - -// Upgrade upgrades the HTTP server connection to the WebSocket protocol. -// -// The responseHeader is included in the response to the client's upgrade -// request. Use the responseHeader to specify cookies (Set-Cookie) and the -// application negotiated subprotocol (Sec-WebSocket-Protocol). -// -// If the upgrade fails, then Upgrade replies to the client with an HTTP error -// response. -func (u *Upgrader) Upgrade(w http.ResponseWriter, r *http.Request, responseHeader http.Header) (*Conn, error) { - const badHandshake = "websocket: the client is not using the websocket protocol: " - - if !tokenListContainsValue(r.Header, "Connection", "upgrade") { - return u.returnError(w, r, http.StatusBadRequest, badHandshake+"'upgrade' token not found in 'Connection' header") - } - - if !tokenListContainsValue(r.Header, "Upgrade", "websocket") { - return u.returnError(w, r, http.StatusBadRequest, badHandshake+"'websocket' token not found in 'Upgrade' header") - } - - if r.Method != "GET" { - return u.returnError(w, r, http.StatusMethodNotAllowed, badHandshake+"request method is not GET") - } - - if !tokenListContainsValue(r.Header, "Sec-Websocket-Version", "13") { - return u.returnError(w, r, http.StatusBadRequest, "websocket: unsupported version: 13 not found in 'Sec-Websocket-Version' header") - } - - if _, ok := responseHeader["Sec-Websocket-Extensions"]; ok { - return u.returnError(w, r, http.StatusInternalServerError, "websocket: application specific 'Sec-WebSocket-Extensions' headers are unsupported") - } - - checkOrigin := u.CheckOrigin - if checkOrigin == nil { - checkOrigin = checkSameOrigin - } - if !checkOrigin(r) { - return u.returnError(w, r, http.StatusForbidden, "websocket: request origin not allowed by Upgrader.CheckOrigin") - } - - challengeKey := r.Header.Get("Sec-Websocket-Key") - if challengeKey == "" { - return u.returnError(w, r, http.StatusBadRequest, "websocket: not a websocket handshake: 'Sec-WebSocket-Key' header is missing or blank") - } - - subprotocol := u.selectSubprotocol(r, responseHeader) - - // Negotiate PMCE - var compress bool - if u.EnableCompression { - for _, ext := range parseExtensions(r.Header) { - if ext[""] != "permessage-deflate" { - continue - } - compress = true - break - } - } - - h, ok := w.(http.Hijacker) - if !ok { - return u.returnError(w, r, http.StatusInternalServerError, "websocket: response does not implement http.Hijacker") - } - var brw *bufio.ReadWriter - netConn, brw, err := h.Hijack() - if err != nil { - return u.returnError(w, r, http.StatusInternalServerError, err.Error()) - } - - if brw.Reader.Buffered() > 0 { - netConn.Close() - return nil, errors.New("websocket: client sent data before handshake is complete") - } - - var br *bufio.Reader - if u.ReadBufferSize == 0 && bufioReaderSize(netConn, brw.Reader) > 256 { - // Reuse hijacked buffered reader as connection reader. - br = brw.Reader - } - - buf := bufioWriterBuffer(netConn, brw.Writer) - - var writeBuf []byte - if u.WriteBufferPool == nil && u.WriteBufferSize == 0 && len(buf) >= maxFrameHeaderSize+256 { - // Reuse hijacked write buffer as connection buffer. - writeBuf = buf - } - - c := newConn(netConn, true, u.ReadBufferSize, u.WriteBufferSize, u.WriteBufferPool, br, writeBuf) - c.subprotocol = subprotocol - - if compress { - c.newCompressionWriter = compressNoContextTakeover - c.newDecompressionReader = decompressNoContextTakeover - } - - // Use larger of hijacked buffer and connection write buffer for header. - p := buf - if len(c.writeBuf) > len(p) { - p = c.writeBuf - } - p = p[:0] - - p = append(p, "HTTP/1.1 101 Switching Protocols\r\nUpgrade: websocket\r\nConnection: Upgrade\r\nSec-WebSocket-Accept: "...) - p = append(p, computeAcceptKey(challengeKey)...) - p = append(p, "\r\n"...) - if c.subprotocol != "" { - p = append(p, "Sec-WebSocket-Protocol: "...) - p = append(p, c.subprotocol...) - p = append(p, "\r\n"...) - } - if compress { - p = append(p, "Sec-WebSocket-Extensions: permessage-deflate; server_no_context_takeover; client_no_context_takeover\r\n"...) - } - for k, vs := range responseHeader { - if k == "Sec-Websocket-Protocol" { - continue - } - for _, v := range vs { - p = append(p, k...) - p = append(p, ": "...) - for i := 0; i < len(v); i++ { - b := v[i] - if b <= 31 { - // prevent response splitting. - b = ' ' - } - p = append(p, b) - } - p = append(p, "\r\n"...) - } - } - p = append(p, "\r\n"...) - - // Clear deadlines set by HTTP server. - netConn.SetDeadline(time.Time{}) - - if u.HandshakeTimeout > 0 { - netConn.SetWriteDeadline(time.Now().Add(u.HandshakeTimeout)) - } - if _, err = netConn.Write(p); err != nil { - netConn.Close() - return nil, err - } - if u.HandshakeTimeout > 0 { - netConn.SetWriteDeadline(time.Time{}) - } - - return c, nil -} - -// Upgrade upgrades the HTTP server connection to the WebSocket protocol. -// -// Deprecated: Use websocket.Upgrader instead. -// -// Upgrade does not perform origin checking. The application is responsible for -// checking the Origin header before calling Upgrade. An example implementation -// of the same origin policy check is: -// -// if req.Header.Get("Origin") != "http://"+req.Host { -// http.Error(w, "Origin not allowed", http.StatusForbidden) -// return -// } -// -// If the endpoint supports subprotocols, then the application is responsible -// for negotiating the protocol used on the connection. Use the Subprotocols() -// function to get the subprotocols requested by the client. Use the -// Sec-Websocket-Protocol response header to specify the subprotocol selected -// by the application. -// -// The responseHeader is included in the response to the client's upgrade -// request. Use the responseHeader to specify cookies (Set-Cookie) and the -// negotiated subprotocol (Sec-Websocket-Protocol). -// -// The connection buffers IO to the underlying network connection. The -// readBufSize and writeBufSize parameters specify the size of the buffers to -// use. Messages can be larger than the buffers. -// -// If the request is not a valid WebSocket handshake, then Upgrade returns an -// error of type HandshakeError. Applications should handle this error by -// replying to the client with an HTTP error response. -func Upgrade(w http.ResponseWriter, r *http.Request, responseHeader http.Header, readBufSize, writeBufSize int) (*Conn, error) { - u := Upgrader{ReadBufferSize: readBufSize, WriteBufferSize: writeBufSize} - u.Error = func(w http.ResponseWriter, r *http.Request, status int, reason error) { - // don't return errors to maintain backwards compatibility - } - u.CheckOrigin = func(r *http.Request) bool { - // allow all connections by default - return true - } - return u.Upgrade(w, r, responseHeader) -} - -// Subprotocols returns the subprotocols requested by the client in the -// Sec-Websocket-Protocol header. -func Subprotocols(r *http.Request) []string { - h := strings.TrimSpace(r.Header.Get("Sec-Websocket-Protocol")) - if h == "" { - return nil - } - protocols := strings.Split(h, ",") - for i := range protocols { - protocols[i] = strings.TrimSpace(protocols[i]) - } - return protocols -} - -// IsWebSocketUpgrade returns true if the client requested upgrade to the -// WebSocket protocol. -func IsWebSocketUpgrade(r *http.Request) bool { - return tokenListContainsValue(r.Header, "Connection", "upgrade") && - tokenListContainsValue(r.Header, "Upgrade", "websocket") -} - -// bufioReaderSize size returns the size of a bufio.Reader. -func bufioReaderSize(originalReader io.Reader, br *bufio.Reader) int { - // This code assumes that peek on a reset reader returns - // bufio.Reader.buf[:0]. - // TODO: Use bufio.Reader.Size() after Go 1.10 - br.Reset(originalReader) - if p, err := br.Peek(0); err == nil { - return cap(p) - } - return 0 -} - -// writeHook is an io.Writer that records the last slice passed to it vio -// io.Writer.Write. -type writeHook struct { - p []byte -} - -func (wh *writeHook) Write(p []byte) (int, error) { - wh.p = p - return len(p), nil -} - -// bufioWriterBuffer grabs the buffer from a bufio.Writer. -func bufioWriterBuffer(originalWriter io.Writer, bw *bufio.Writer) []byte { - // This code assumes that bufio.Writer.buf[:1] is passed to the - // bufio.Writer's underlying writer. - var wh writeHook - bw.Reset(&wh) - bw.WriteByte(0) - bw.Flush() - - bw.Reset(originalWriter) - - return wh.p[:cap(wh.p)] -} diff --git a/vendor/github.com/gorilla/websocket/trace.go b/vendor/github.com/gorilla/websocket/trace.go deleted file mode 100644 index 834f122a00..0000000000 --- a/vendor/github.com/gorilla/websocket/trace.go +++ /dev/null @@ -1,19 +0,0 @@ -// +build go1.8 - -package websocket - -import ( - "crypto/tls" - "net/http/httptrace" -) - -func doHandshakeWithTrace(trace *httptrace.ClientTrace, tlsConn *tls.Conn, cfg *tls.Config) error { - if trace.TLSHandshakeStart != nil { - trace.TLSHandshakeStart() - } - err := doHandshake(tlsConn, cfg) - if trace.TLSHandshakeDone != nil { - trace.TLSHandshakeDone(tlsConn.ConnectionState(), err) - } - return err -} diff --git a/vendor/github.com/gorilla/websocket/trace_17.go b/vendor/github.com/gorilla/websocket/trace_17.go deleted file mode 100644 index 77d05a0b57..0000000000 --- a/vendor/github.com/gorilla/websocket/trace_17.go +++ /dev/null @@ -1,12 +0,0 @@ -// +build !go1.8 - -package websocket - -import ( - "crypto/tls" - "net/http/httptrace" -) - -func doHandshakeWithTrace(trace *httptrace.ClientTrace, tlsConn *tls.Conn, cfg *tls.Config) error { - return doHandshake(tlsConn, cfg) -} diff --git a/vendor/github.com/gorilla/websocket/util.go b/vendor/github.com/gorilla/websocket/util.go deleted file mode 100644 index 7bf2f66c67..0000000000 --- a/vendor/github.com/gorilla/websocket/util.go +++ /dev/null @@ -1,283 +0,0 @@ -// Copyright 2013 The Gorilla WebSocket Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package websocket - -import ( - "crypto/rand" - "crypto/sha1" - "encoding/base64" - "io" - "net/http" - "strings" - "unicode/utf8" -) - -var keyGUID = []byte("258EAFA5-E914-47DA-95CA-C5AB0DC85B11") - -func computeAcceptKey(challengeKey string) string { - h := sha1.New() - h.Write([]byte(challengeKey)) - h.Write(keyGUID) - return base64.StdEncoding.EncodeToString(h.Sum(nil)) -} - -func generateChallengeKey() (string, error) { - p := make([]byte, 16) - if _, err := io.ReadFull(rand.Reader, p); err != nil { - return "", err - } - return base64.StdEncoding.EncodeToString(p), nil -} - -// Token octets per RFC 2616. -var isTokenOctet = [256]bool{ - '!': true, - '#': true, - '$': true, - '%': true, - '&': true, - '\'': true, - '*': true, - '+': true, - '-': true, - '.': true, - '0': true, - '1': true, - '2': true, - '3': true, - '4': true, - '5': true, - '6': true, - '7': true, - '8': true, - '9': true, - 'A': true, - 'B': true, - 'C': true, - 'D': true, - 'E': true, - 'F': true, - 'G': true, - 'H': true, - 'I': true, - 'J': true, - 'K': true, - 'L': true, - 'M': true, - 'N': true, - 'O': true, - 'P': true, - 'Q': true, - 'R': true, - 'S': true, - 'T': true, - 'U': true, - 'W': true, - 'V': true, - 'X': true, - 'Y': true, - 'Z': true, - '^': true, - '_': true, - '`': true, - 'a': true, - 'b': true, - 'c': true, - 'd': true, - 'e': true, - 'f': true, - 'g': true, - 'h': true, - 'i': true, - 'j': true, - 'k': true, - 'l': true, - 'm': true, - 'n': true, - 'o': true, - 'p': true, - 'q': true, - 'r': true, - 's': true, - 't': true, - 'u': true, - 'v': true, - 'w': true, - 'x': true, - 'y': true, - 'z': true, - '|': true, - '~': true, -} - -// skipSpace returns a slice of the string s with all leading RFC 2616 linear -// whitespace removed. -func skipSpace(s string) (rest string) { - i := 0 - for ; i < len(s); i++ { - if b := s[i]; b != ' ' && b != '\t' { - break - } - } - return s[i:] -} - -// nextToken returns the leading RFC 2616 token of s and the string following -// the token. -func nextToken(s string) (token, rest string) { - i := 0 - for ; i < len(s); i++ { - if !isTokenOctet[s[i]] { - break - } - } - return s[:i], s[i:] -} - -// nextTokenOrQuoted returns the leading token or quoted string per RFC 2616 -// and the string following the token or quoted string. -func nextTokenOrQuoted(s string) (value string, rest string) { - if !strings.HasPrefix(s, "\"") { - return nextToken(s) - } - s = s[1:] - for i := 0; i < len(s); i++ { - switch s[i] { - case '"': - return s[:i], s[i+1:] - case '\\': - p := make([]byte, len(s)-1) - j := copy(p, s[:i]) - escape := true - for i = i + 1; i < len(s); i++ { - b := s[i] - switch { - case escape: - escape = false - p[j] = b - j++ - case b == '\\': - escape = true - case b == '"': - return string(p[:j]), s[i+1:] - default: - p[j] = b - j++ - } - } - return "", "" - } - } - return "", "" -} - -// equalASCIIFold returns true if s is equal to t with ASCII case folding as -// defined in RFC 4790. -func equalASCIIFold(s, t string) bool { - for s != "" && t != "" { - sr, size := utf8.DecodeRuneInString(s) - s = s[size:] - tr, size := utf8.DecodeRuneInString(t) - t = t[size:] - if sr == tr { - continue - } - if 'A' <= sr && sr <= 'Z' { - sr = sr + 'a' - 'A' - } - if 'A' <= tr && tr <= 'Z' { - tr = tr + 'a' - 'A' - } - if sr != tr { - return false - } - } - return s == t -} - -// tokenListContainsValue returns true if the 1#token header with the given -// name contains a token equal to value with ASCII case folding. -func tokenListContainsValue(header http.Header, name string, value string) bool { -headers: - for _, s := range header[name] { - for { - var t string - t, s = nextToken(skipSpace(s)) - if t == "" { - continue headers - } - s = skipSpace(s) - if s != "" && s[0] != ',' { - continue headers - } - if equalASCIIFold(t, value) { - return true - } - if s == "" { - continue headers - } - s = s[1:] - } - } - return false -} - -// parseExtensions parses WebSocket extensions from a header. -func parseExtensions(header http.Header) []map[string]string { - // From RFC 6455: - // - // Sec-WebSocket-Extensions = extension-list - // extension-list = 1#extension - // extension = extension-token *( ";" extension-param ) - // extension-token = registered-token - // registered-token = token - // extension-param = token [ "=" (token | quoted-string) ] - // ;When using the quoted-string syntax variant, the value - // ;after quoted-string unescaping MUST conform to the - // ;'token' ABNF. - - var result []map[string]string -headers: - for _, s := range header["Sec-Websocket-Extensions"] { - for { - var t string - t, s = nextToken(skipSpace(s)) - if t == "" { - continue headers - } - ext := map[string]string{"": t} - for { - s = skipSpace(s) - if !strings.HasPrefix(s, ";") { - break - } - var k string - k, s = nextToken(skipSpace(s[1:])) - if k == "" { - continue headers - } - s = skipSpace(s) - var v string - if strings.HasPrefix(s, "=") { - v, s = nextTokenOrQuoted(skipSpace(s[1:])) - s = skipSpace(s) - } - if s != "" && s[0] != ',' && s[0] != ';' { - continue headers - } - ext[k] = v - } - if s != "" && s[0] != ',' { - continue headers - } - result = append(result, ext) - if s == "" { - continue headers - } - s = s[1:] - } - } - return result -} diff --git a/vendor/github.com/gorilla/websocket/x_net_proxy.go b/vendor/github.com/gorilla/websocket/x_net_proxy.go deleted file mode 100644 index 2e668f6b88..0000000000 --- a/vendor/github.com/gorilla/websocket/x_net_proxy.go +++ /dev/null @@ -1,473 +0,0 @@ -// Code generated by golang.org/x/tools/cmd/bundle. DO NOT EDIT. -//go:generate bundle -o x_net_proxy.go golang.org/x/net/proxy - -// Package proxy provides support for a variety of protocols to proxy network -// data. -// - -package websocket - -import ( - "errors" - "io" - "net" - "net/url" - "os" - "strconv" - "strings" - "sync" -) - -type proxy_direct struct{} - -// Direct is a direct proxy: one that makes network connections directly. -var proxy_Direct = proxy_direct{} - -func (proxy_direct) Dial(network, addr string) (net.Conn, error) { - return net.Dial(network, addr) -} - -// A PerHost directs connections to a default Dialer unless the host name -// requested matches one of a number of exceptions. -type proxy_PerHost struct { - def, bypass proxy_Dialer - - bypassNetworks []*net.IPNet - bypassIPs []net.IP - bypassZones []string - bypassHosts []string -} - -// NewPerHost returns a PerHost Dialer that directs connections to either -// defaultDialer or bypass, depending on whether the connection matches one of -// the configured rules. -func proxy_NewPerHost(defaultDialer, bypass proxy_Dialer) *proxy_PerHost { - return &proxy_PerHost{ - def: defaultDialer, - bypass: bypass, - } -} - -// Dial connects to the address addr on the given network through either -// defaultDialer or bypass. -func (p *proxy_PerHost) Dial(network, addr string) (c net.Conn, err error) { - host, _, err := net.SplitHostPort(addr) - if err != nil { - return nil, err - } - - return p.dialerForRequest(host).Dial(network, addr) -} - -func (p *proxy_PerHost) dialerForRequest(host string) proxy_Dialer { - if ip := net.ParseIP(host); ip != nil { - for _, net := range p.bypassNetworks { - if net.Contains(ip) { - return p.bypass - } - } - for _, bypassIP := range p.bypassIPs { - if bypassIP.Equal(ip) { - return p.bypass - } - } - return p.def - } - - for _, zone := range p.bypassZones { - if strings.HasSuffix(host, zone) { - return p.bypass - } - if host == zone[1:] { - // For a zone ".example.com", we match "example.com" - // too. - return p.bypass - } - } - for _, bypassHost := range p.bypassHosts { - if bypassHost == host { - return p.bypass - } - } - return p.def -} - -// AddFromString parses a string that contains comma-separated values -// specifying hosts that should use the bypass proxy. Each value is either an -// IP address, a CIDR range, a zone (*.example.com) or a host name -// (localhost). A best effort is made to parse the string and errors are -// ignored. -func (p *proxy_PerHost) AddFromString(s string) { - hosts := strings.Split(s, ",") - for _, host := range hosts { - host = strings.TrimSpace(host) - if len(host) == 0 { - continue - } - if strings.Contains(host, "/") { - // We assume that it's a CIDR address like 127.0.0.0/8 - if _, net, err := net.ParseCIDR(host); err == nil { - p.AddNetwork(net) - } - continue - } - if ip := net.ParseIP(host); ip != nil { - p.AddIP(ip) - continue - } - if strings.HasPrefix(host, "*.") { - p.AddZone(host[1:]) - continue - } - p.AddHost(host) - } -} - -// AddIP specifies an IP address that will use the bypass proxy. Note that -// this will only take effect if a literal IP address is dialed. A connection -// to a named host will never match an IP. -func (p *proxy_PerHost) AddIP(ip net.IP) { - p.bypassIPs = append(p.bypassIPs, ip) -} - -// AddNetwork specifies an IP range that will use the bypass proxy. Note that -// this will only take effect if a literal IP address is dialed. A connection -// to a named host will never match. -func (p *proxy_PerHost) AddNetwork(net *net.IPNet) { - p.bypassNetworks = append(p.bypassNetworks, net) -} - -// AddZone specifies a DNS suffix that will use the bypass proxy. A zone of -// "example.com" matches "example.com" and all of its subdomains. -func (p *proxy_PerHost) AddZone(zone string) { - if strings.HasSuffix(zone, ".") { - zone = zone[:len(zone)-1] - } - if !strings.HasPrefix(zone, ".") { - zone = "." + zone - } - p.bypassZones = append(p.bypassZones, zone) -} - -// AddHost specifies a host name that will use the bypass proxy. -func (p *proxy_PerHost) AddHost(host string) { - if strings.HasSuffix(host, ".") { - host = host[:len(host)-1] - } - p.bypassHosts = append(p.bypassHosts, host) -} - -// A Dialer is a means to establish a connection. -type proxy_Dialer interface { - // Dial connects to the given address via the proxy. - Dial(network, addr string) (c net.Conn, err error) -} - -// Auth contains authentication parameters that specific Dialers may require. -type proxy_Auth struct { - User, Password string -} - -// FromEnvironment returns the dialer specified by the proxy related variables in -// the environment. -func proxy_FromEnvironment() proxy_Dialer { - allProxy := proxy_allProxyEnv.Get() - if len(allProxy) == 0 { - return proxy_Direct - } - - proxyURL, err := url.Parse(allProxy) - if err != nil { - return proxy_Direct - } - proxy, err := proxy_FromURL(proxyURL, proxy_Direct) - if err != nil { - return proxy_Direct - } - - noProxy := proxy_noProxyEnv.Get() - if len(noProxy) == 0 { - return proxy - } - - perHost := proxy_NewPerHost(proxy, proxy_Direct) - perHost.AddFromString(noProxy) - return perHost -} - -// proxySchemes is a map from URL schemes to a function that creates a Dialer -// from a URL with such a scheme. -var proxy_proxySchemes map[string]func(*url.URL, proxy_Dialer) (proxy_Dialer, error) - -// RegisterDialerType takes a URL scheme and a function to generate Dialers from -// a URL with that scheme and a forwarding Dialer. Registered schemes are used -// by FromURL. -func proxy_RegisterDialerType(scheme string, f func(*url.URL, proxy_Dialer) (proxy_Dialer, error)) { - if proxy_proxySchemes == nil { - proxy_proxySchemes = make(map[string]func(*url.URL, proxy_Dialer) (proxy_Dialer, error)) - } - proxy_proxySchemes[scheme] = f -} - -// FromURL returns a Dialer given a URL specification and an underlying -// Dialer for it to make network requests. -func proxy_FromURL(u *url.URL, forward proxy_Dialer) (proxy_Dialer, error) { - var auth *proxy_Auth - if u.User != nil { - auth = new(proxy_Auth) - auth.User = u.User.Username() - if p, ok := u.User.Password(); ok { - auth.Password = p - } - } - - switch u.Scheme { - case "socks5": - return proxy_SOCKS5("tcp", u.Host, auth, forward) - } - - // If the scheme doesn't match any of the built-in schemes, see if it - // was registered by another package. - if proxy_proxySchemes != nil { - if f, ok := proxy_proxySchemes[u.Scheme]; ok { - return f(u, forward) - } - } - - return nil, errors.New("proxy: unknown scheme: " + u.Scheme) -} - -var ( - proxy_allProxyEnv = &proxy_envOnce{ - names: []string{"ALL_PROXY", "all_proxy"}, - } - proxy_noProxyEnv = &proxy_envOnce{ - names: []string{"NO_PROXY", "no_proxy"}, - } -) - -// envOnce looks up an environment variable (optionally by multiple -// names) once. It mitigates expensive lookups on some platforms -// (e.g. Windows). -// (Borrowed from net/http/transport.go) -type proxy_envOnce struct { - names []string - once sync.Once - val string -} - -func (e *proxy_envOnce) Get() string { - e.once.Do(e.init) - return e.val -} - -func (e *proxy_envOnce) init() { - for _, n := range e.names { - e.val = os.Getenv(n) - if e.val != "" { - return - } - } -} - -// SOCKS5 returns a Dialer that makes SOCKSv5 connections to the given address -// with an optional username and password. See RFC 1928 and RFC 1929. -func proxy_SOCKS5(network, addr string, auth *proxy_Auth, forward proxy_Dialer) (proxy_Dialer, error) { - s := &proxy_socks5{ - network: network, - addr: addr, - forward: forward, - } - if auth != nil { - s.user = auth.User - s.password = auth.Password - } - - return s, nil -} - -type proxy_socks5 struct { - user, password string - network, addr string - forward proxy_Dialer -} - -const proxy_socks5Version = 5 - -const ( - proxy_socks5AuthNone = 0 - proxy_socks5AuthPassword = 2 -) - -const proxy_socks5Connect = 1 - -const ( - proxy_socks5IP4 = 1 - proxy_socks5Domain = 3 - proxy_socks5IP6 = 4 -) - -var proxy_socks5Errors = []string{ - "", - "general failure", - "connection forbidden", - "network unreachable", - "host unreachable", - "connection refused", - "TTL expired", - "command not supported", - "address type not supported", -} - -// Dial connects to the address addr on the given network via the SOCKS5 proxy. -func (s *proxy_socks5) Dial(network, addr string) (net.Conn, error) { - switch network { - case "tcp", "tcp6", "tcp4": - default: - return nil, errors.New("proxy: no support for SOCKS5 proxy connections of type " + network) - } - - conn, err := s.forward.Dial(s.network, s.addr) - if err != nil { - return nil, err - } - if err := s.connect(conn, addr); err != nil { - conn.Close() - return nil, err - } - return conn, nil -} - -// connect takes an existing connection to a socks5 proxy server, -// and commands the server to extend that connection to target, -// which must be a canonical address with a host and port. -func (s *proxy_socks5) connect(conn net.Conn, target string) error { - host, portStr, err := net.SplitHostPort(target) - if err != nil { - return err - } - - port, err := strconv.Atoi(portStr) - if err != nil { - return errors.New("proxy: failed to parse port number: " + portStr) - } - if port < 1 || port > 0xffff { - return errors.New("proxy: port number out of range: " + portStr) - } - - // the size here is just an estimate - buf := make([]byte, 0, 6+len(host)) - - buf = append(buf, proxy_socks5Version) - if len(s.user) > 0 && len(s.user) < 256 && len(s.password) < 256 { - buf = append(buf, 2 /* num auth methods */, proxy_socks5AuthNone, proxy_socks5AuthPassword) - } else { - buf = append(buf, 1 /* num auth methods */, proxy_socks5AuthNone) - } - - if _, err := conn.Write(buf); err != nil { - return errors.New("proxy: failed to write greeting to SOCKS5 proxy at " + s.addr + ": " + err.Error()) - } - - if _, err := io.ReadFull(conn, buf[:2]); err != nil { - return errors.New("proxy: failed to read greeting from SOCKS5 proxy at " + s.addr + ": " + err.Error()) - } - if buf[0] != 5 { - return errors.New("proxy: SOCKS5 proxy at " + s.addr + " has unexpected version " + strconv.Itoa(int(buf[0]))) - } - if buf[1] == 0xff { - return errors.New("proxy: SOCKS5 proxy at " + s.addr + " requires authentication") - } - - // See RFC 1929 - if buf[1] == proxy_socks5AuthPassword { - buf = buf[:0] - buf = append(buf, 1 /* password protocol version */) - buf = append(buf, uint8(len(s.user))) - buf = append(buf, s.user...) - buf = append(buf, uint8(len(s.password))) - buf = append(buf, s.password...) - - if _, err := conn.Write(buf); err != nil { - return errors.New("proxy: failed to write authentication request to SOCKS5 proxy at " + s.addr + ": " + err.Error()) - } - - if _, err := io.ReadFull(conn, buf[:2]); err != nil { - return errors.New("proxy: failed to read authentication reply from SOCKS5 proxy at " + s.addr + ": " + err.Error()) - } - - if buf[1] != 0 { - return errors.New("proxy: SOCKS5 proxy at " + s.addr + " rejected username/password") - } - } - - buf = buf[:0] - buf = append(buf, proxy_socks5Version, proxy_socks5Connect, 0 /* reserved */) - - if ip := net.ParseIP(host); ip != nil { - if ip4 := ip.To4(); ip4 != nil { - buf = append(buf, proxy_socks5IP4) - ip = ip4 - } else { - buf = append(buf, proxy_socks5IP6) - } - buf = append(buf, ip...) - } else { - if len(host) > 255 { - return errors.New("proxy: destination host name too long: " + host) - } - buf = append(buf, proxy_socks5Domain) - buf = append(buf, byte(len(host))) - buf = append(buf, host...) - } - buf = append(buf, byte(port>>8), byte(port)) - - if _, err := conn.Write(buf); err != nil { - return errors.New("proxy: failed to write connect request to SOCKS5 proxy at " + s.addr + ": " + err.Error()) - } - - if _, err := io.ReadFull(conn, buf[:4]); err != nil { - return errors.New("proxy: failed to read connect reply from SOCKS5 proxy at " + s.addr + ": " + err.Error()) - } - - failure := "unknown error" - if int(buf[1]) < len(proxy_socks5Errors) { - failure = proxy_socks5Errors[buf[1]] - } - - if len(failure) > 0 { - return errors.New("proxy: SOCKS5 proxy at " + s.addr + " failed to connect: " + failure) - } - - bytesToDiscard := 0 - switch buf[3] { - case proxy_socks5IP4: - bytesToDiscard = net.IPv4len - case proxy_socks5IP6: - bytesToDiscard = net.IPv6len - case proxy_socks5Domain: - _, err := io.ReadFull(conn, buf[:1]) - if err != nil { - return errors.New("proxy: failed to read domain length from SOCKS5 proxy at " + s.addr + ": " + err.Error()) - } - bytesToDiscard = int(buf[0]) - default: - return errors.New("proxy: got unknown address type " + strconv.Itoa(int(buf[3])) + " from SOCKS5 proxy at " + s.addr) - } - - if cap(buf) < bytesToDiscard { - buf = make([]byte, bytesToDiscard) - } else { - buf = buf[:bytesToDiscard] - } - if _, err := io.ReadFull(conn, buf); err != nil { - return errors.New("proxy: failed to read address from SOCKS5 proxy at " + s.addr + ": " + err.Error()) - } - - // Also need to discard the port number - if _, err := io.ReadFull(conn, buf[:2]); err != nil { - return errors.New("proxy: failed to read port from SOCKS5 proxy at " + s.addr + ": " + err.Error()) - } - - return nil -} diff --git a/pkg/util/tls/tls.go b/vendor/github.com/grafana/dskit/crypto/tls/tls.go similarity index 100% rename from pkg/util/tls/tls.go rename to vendor/github.com/grafana/dskit/crypto/tls/tls.go diff --git a/vendor/github.com/grafana/dskit/flagext/deprecated.go b/vendor/github.com/grafana/dskit/flagext/deprecated.go index 0a6913ab69..188be2b043 100644 --- a/vendor/github.com/grafana/dskit/flagext/deprecated.go +++ b/vendor/github.com/grafana/dskit/flagext/deprecated.go @@ -3,8 +3,8 @@ package flagext import ( "flag" - "github.com/go-kit/kit/log" - "github.com/go-kit/kit/log/level" + "github.com/go-kit/log" + "github.com/go-kit/log/level" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promauto" ) diff --git a/pkg/util/grpcclient/backoff_retry.go b/vendor/github.com/grafana/dskit/grpcclient/backoff_retry.go similarity index 99% rename from pkg/util/grpcclient/backoff_retry.go rename to vendor/github.com/grafana/dskit/grpcclient/backoff_retry.go index 70ab38c6b7..21abbb7865 100644 --- a/pkg/util/grpcclient/backoff_retry.go +++ b/vendor/github.com/grafana/dskit/grpcclient/backoff_retry.go @@ -3,10 +3,11 @@ package grpcclient import ( "context" - "github.com/grafana/dskit/backoff" "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" + + "github.com/grafana/dskit/backoff" ) // NewBackoffRetry gRPC middleware. diff --git a/pkg/util/grpcclient/grpcclient.go b/vendor/github.com/grafana/dskit/grpcclient/grpcclient.go similarity index 91% rename from pkg/util/grpcclient/grpcclient.go rename to vendor/github.com/grafana/dskit/grpcclient/grpcclient.go index e5568b70c6..094337f5d2 100644 --- a/pkg/util/grpcclient/grpcclient.go +++ b/vendor/github.com/grafana/dskit/grpcclient/grpcclient.go @@ -5,15 +5,15 @@ import ( "time" "github.com/go-kit/log" - "github.com/grafana/dskit/backoff" - grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware" + middleware "github.com/grpc-ecosystem/go-grpc-middleware" "github.com/pkg/errors" "google.golang.org/grpc" "google.golang.org/grpc/encoding/gzip" "google.golang.org/grpc/keepalive" - "github.com/cortexproject/cortex/pkg/util/grpc/encoding/snappy" - "github.com/cortexproject/cortex/pkg/util/tls" + "github.com/grafana/dskit/backoff" + "github.com/grafana/dskit/crypto/tls" + "github.com/grafana/dskit/grpcencoding/snappy" ) // Config for a gRPC client. @@ -92,8 +92,8 @@ func (cfg *Config) DialOption(unaryClientInterceptors []grpc.UnaryClientIntercep return append( opts, grpc.WithDefaultCallOptions(cfg.CallOptions()...), - grpc.WithUnaryInterceptor(grpc_middleware.ChainUnaryClient(unaryClientInterceptors...)), - grpc.WithStreamInterceptor(grpc_middleware.ChainStreamClient(streamClientInterceptors...)), + grpc.WithUnaryInterceptor(middleware.ChainUnaryClient(unaryClientInterceptors...)), + grpc.WithStreamInterceptor(middleware.ChainStreamClient(streamClientInterceptors...)), grpc.WithKeepaliveParams(keepalive.ClientParameters{ Time: time.Second * 20, Timeout: time.Second * 10, diff --git a/pkg/util/grpcclient/instrumentation.go b/vendor/github.com/grafana/dskit/grpcclient/instrumentation.go similarity index 75% rename from pkg/util/grpcclient/instrumentation.go rename to vendor/github.com/grafana/dskit/grpcclient/instrumentation.go index b80101af77..b22a588340 100644 --- a/pkg/util/grpcclient/instrumentation.go +++ b/vendor/github.com/grafana/dskit/grpcclient/instrumentation.go @@ -7,17 +7,17 @@ import ( "github.com/weaveworks/common/middleware" "google.golang.org/grpc" - cortex_middleware "github.com/cortexproject/cortex/pkg/util/middleware" + dsmiddleware "github.com/grafana/dskit/middleware" ) func Instrument(requestDuration *prometheus.HistogramVec) ([]grpc.UnaryClientInterceptor, []grpc.StreamClientInterceptor) { return []grpc.UnaryClientInterceptor{ otgrpc.OpenTracingClientInterceptor(opentracing.GlobalTracer()), middleware.ClientUserHeaderInterceptor, - cortex_middleware.PrometheusGRPCUnaryInstrumentation(requestDuration), + dsmiddleware.PrometheusGRPCUnaryInstrumentation(requestDuration), }, []grpc.StreamClientInterceptor{ otgrpc.OpenTracingStreamClientInterceptor(opentracing.GlobalTracer()), middleware.StreamClientUserHeaderInterceptor, - cortex_middleware.PrometheusGRPCStreamInstrumentation(requestDuration), + dsmiddleware.PrometheusGRPCStreamInstrumentation(requestDuration), } } diff --git a/pkg/util/grpcclient/ratelimit.go b/vendor/github.com/grafana/dskit/grpcclient/ratelimit.go similarity index 100% rename from pkg/util/grpcclient/ratelimit.go rename to vendor/github.com/grafana/dskit/grpcclient/ratelimit.go diff --git a/pkg/util/grpc/encoding/snappy/snappy.go b/vendor/github.com/grafana/dskit/grpcencoding/snappy/snappy.go similarity index 100% rename from pkg/util/grpc/encoding/snappy/snappy.go rename to vendor/github.com/grafana/dskit/grpcencoding/snappy/snappy.go diff --git a/pkg/util/grpc/naming/dns_resolver.go b/vendor/github.com/grafana/dskit/grpcutil/dns_resolver.go similarity index 90% rename from pkg/util/grpc/naming/dns_resolver.go rename to vendor/github.com/grafana/dskit/grpcutil/dns_resolver.go index a583f7a521..ad9f17c782 100644 --- a/pkg/util/grpc/naming/dns_resolver.go +++ b/vendor/github.com/grafana/dskit/grpcutil/dns_resolver.go @@ -1,4 +1,4 @@ -package naming +package grpcutil // Copied from https://github.com/grpc/grpc-go/tree/v1.29.x/naming. @@ -10,7 +10,8 @@ import ( "strconv" "time" - "google.golang.org/grpc/grpclog" + "github.com/go-kit/log" + "github.com/go-kit/log/level" ) const ( @@ -28,18 +29,22 @@ var ( // NewDNSResolverWithFreq creates a DNS Resolver that can resolve DNS names, and // create watchers that poll the DNS server using the frequency set by freq. -func NewDNSResolverWithFreq(freq time.Duration) (Resolver, error) { - return &dnsResolver{freq: freq}, nil +func NewDNSResolverWithFreq(freq time.Duration, logger log.Logger) (Resolver, error) { + return &dnsResolver{ + logger: logger, + freq: freq, + }, nil } // NewDNSResolver creates a DNS Resolver that can resolve DNS names, and create // watchers that poll the DNS server using the default frequency defined by defaultFreq. -func NewDNSResolver() (Resolver, error) { - return NewDNSResolverWithFreq(defaultFreq) +func NewDNSResolver(logger log.Logger) (Resolver, error) { + return NewDNSResolverWithFreq(defaultFreq, logger) } // dnsResolver handles name resolution for names following the DNS scheme type dnsResolver struct { + logger log.Logger // frequency of polling the DNS server that the watchers created by this resolver will use. freq time.Duration } @@ -115,6 +120,7 @@ func (r *dnsResolver) Resolve(target string) (Watcher, error) { ctx, cancel := context.WithCancel(context.Background()) return &dnsWatcher{ r: r, + logger: r.logger, host: host, port: port, ctx: ctx, @@ -125,9 +131,10 @@ func (r *dnsResolver) Resolve(target string) (Watcher, error) { // dnsWatcher watches for the name resolution update for a specific target type dnsWatcher struct { - r *dnsResolver - host string - port string + r *dnsResolver + logger log.Logger + host string + port string // The latest resolved address set curAddrs map[string]*Update ctx context.Context @@ -199,19 +206,19 @@ func (w *dnsWatcher) lookupSRV() map[string]*Update { newAddrs := make(map[string]*Update) _, srvs, err := lookupSRV(w.ctx, "grpclb", "tcp", w.host) if err != nil { - grpclog.Infof("grpc: failed dns SRV record lookup due to %v.\n", err) + level.Info(w.logger).Log("msg", "failed DNS SRV record lookup", "err", err) return nil } for _, s := range srvs { lbAddrs, err := lookupHost(w.ctx, s.Target) if err != nil { - grpclog.Warningf("grpc: failed load balancer address dns lookup due to %v.\n", err) + level.Warn(w.logger).Log("msg", "failed load balancer address DNS lookup", "err", err) continue } for _, a := range lbAddrs { a, ok := formatIP(a) if !ok { - grpclog.Errorf("grpc: failed IP parsing due to %v.\n", err) + level.Error(w.logger).Log("failed IP parsing", "err", err) continue } addr := a + ":" + strconv.Itoa(int(s.Port)) @@ -226,13 +233,13 @@ func (w *dnsWatcher) lookupHost() map[string]*Update { newAddrs := make(map[string]*Update) addrs, err := lookupHost(w.ctx, w.host) if err != nil { - grpclog.Warningf("grpc: failed dns A record lookup due to %v.\n", err) + level.Warn(w.logger).Log("msg", "failed DNS A record lookup", "err", err) return nil } for _, a := range addrs { a, ok := formatIP(a) if !ok { - grpclog.Errorf("grpc: failed IP parsing due to %v.\n", err) + level.Error(w.logger).Log("msg", "failed IP parsing", "err", err) continue } addr := a + ":" + w.port diff --git a/pkg/util/grpc/healthcheck/health_check.go b/vendor/github.com/grafana/dskit/grpcutil/health_check.go similarity index 87% rename from pkg/util/grpc/healthcheck/health_check.go rename to vendor/github.com/grafana/dskit/grpcutil/health_check.go index 09bc608b21..2b567b3680 100644 --- a/pkg/util/grpc/healthcheck/health_check.go +++ b/vendor/github.com/grafana/dskit/grpcutil/health_check.go @@ -1,12 +1,13 @@ -package healthcheck +package grpcutil import ( "context" "github.com/gogo/status" - "github.com/grafana/dskit/services" "google.golang.org/grpc/codes" "google.golang.org/grpc/health/grpc_health_v1" + + "github.com/grafana/dskit/services" ) // HealthCheck fulfills the grpc_health_v1.HealthServer interface by ensuring @@ -15,8 +16,8 @@ type HealthCheck struct { sm *services.Manager } -// New returns a new HealthCheck for the provided service manager. -func New(sm *services.Manager) *HealthCheck { +// NewHealthCheck returns a new HealthCheck for the provided service manager. +func NewHealthCheck(sm *services.Manager) *HealthCheck { return &HealthCheck{ sm: sm, } @@ -36,7 +37,7 @@ func (h *HealthCheck) Watch(_ *grpc_health_v1.HealthCheckRequest, _ grpc_health_ return status.Error(codes.Unimplemented, "Watching is not supported") } -// isHealthy returns whether the Cortex instance should be considered healthy. +// isHealthy returns whether the instance should be considered healthy. func (h *HealthCheck) isHealthy() bool { states := h.sm.ServicesByState() diff --git a/pkg/util/grpc/naming/naming.go b/vendor/github.com/grafana/dskit/grpcutil/naming.go similarity index 98% rename from pkg/util/grpc/naming/naming.go rename to vendor/github.com/grafana/dskit/grpcutil/naming.go index d086bd317b..441b3ad9fc 100644 --- a/pkg/util/grpc/naming/naming.go +++ b/vendor/github.com/grafana/dskit/grpcutil/naming.go @@ -1,9 +1,8 @@ -package naming +package grpcutil // Copied from https://github.com/grpc/grpc-go/tree/v1.29.x/naming. // Operation defines the corresponding operations for a name resolution change. -// type Operation uint8 const ( @@ -26,7 +25,6 @@ type Update struct { } // Resolver creates a Watcher for a target to track its resolution changes. -// type Resolver interface { // Resolve creates a Watcher for target. Resolve(target string) (Watcher, error) diff --git a/pkg/util/grpc/util.go b/vendor/github.com/grafana/dskit/grpcutil/util.go similarity index 95% rename from pkg/util/grpc/util.go rename to vendor/github.com/grafana/dskit/grpcutil/util.go index 19ef615e62..858a0e8620 100644 --- a/pkg/util/grpc/util.go +++ b/vendor/github.com/grafana/dskit/grpcutil/util.go @@ -1,4 +1,4 @@ -package grpc +package grpcutil import ( "github.com/gogo/status" diff --git a/vendor/github.com/grafana/dskit/kv/client.go b/vendor/github.com/grafana/dskit/kv/client.go index 3a8f410b8e..b73620dfd6 100644 --- a/vendor/github.com/grafana/dskit/kv/client.go +++ b/vendor/github.com/grafana/dskit/kv/client.go @@ -6,7 +6,7 @@ import ( "fmt" "sync" - "github.com/go-kit/kit/log" + "github.com/go-kit/log" "github.com/prometheus/client_golang/prometheus" "github.com/grafana/dskit/kv/codec" diff --git a/vendor/github.com/grafana/dskit/kv/consul/client.go b/vendor/github.com/grafana/dskit/kv/consul/client.go index 9ce6d91c52..b3391c9cda 100644 --- a/vendor/github.com/grafana/dskit/kv/consul/client.go +++ b/vendor/github.com/grafana/dskit/kv/consul/client.go @@ -9,8 +9,8 @@ import ( "net/http" "time" - "github.com/go-kit/kit/log" - "github.com/go-kit/kit/log/level" + "github.com/go-kit/log" + "github.com/go-kit/log/level" consul "github.com/hashicorp/consul/api" "github.com/hashicorp/go-cleanhttp" "github.com/prometheus/client_golang/prometheus" diff --git a/vendor/github.com/grafana/dskit/kv/consul/mock.go b/vendor/github.com/grafana/dskit/kv/consul/mock.go index a5ed43df93..ae9c768f9f 100644 --- a/vendor/github.com/grafana/dskit/kv/consul/mock.go +++ b/vendor/github.com/grafana/dskit/kv/consul/mock.go @@ -7,8 +7,8 @@ import ( "sync" "time" - "github.com/go-kit/kit/log" - "github.com/go-kit/kit/log/level" + "github.com/go-kit/log" + "github.com/go-kit/log/level" consul "github.com/hashicorp/consul/api" "github.com/prometheus/client_golang/prometheus" diff --git a/vendor/github.com/grafana/dskit/kv/etcd/etcd.go b/vendor/github.com/grafana/dskit/kv/etcd/etcd.go index 6690f822fb..b08fb6a9dd 100644 --- a/vendor/github.com/grafana/dskit/kv/etcd/etcd.go +++ b/vendor/github.com/grafana/dskit/kv/etcd/etcd.go @@ -7,16 +7,16 @@ import ( "fmt" "time" - "github.com/go-kit/kit/log" - "github.com/go-kit/kit/log/level" + "github.com/go-kit/log" + "github.com/go-kit/log/level" "github.com/pkg/errors" clientv3 "go.etcd.io/etcd/client/v3" "go.etcd.io/etcd/pkg/transport" "github.com/grafana/dskit/backoff" + dstls "github.com/grafana/dskit/crypto/tls" "github.com/grafana/dskit/flagext" "github.com/grafana/dskit/kv/codec" - "github.com/grafana/dskit/kv/kvtls" ) // Config for a new etcd.Client. @@ -25,20 +25,31 @@ type Config struct { DialTimeout time.Duration `yaml:"dial_timeout"` MaxRetries int `yaml:"max_retries"` EnableTLS bool `yaml:"tls_enabled"` - TLS kvtls.ClientConfig `yaml:",inline"` + TLS dstls.ClientConfig `yaml:",inline"` UserName string `yaml:"username"` Password string `yaml:"password"` } +// Clientv3Facade is a subset of all Etcd client operations that are required +// to implement an Etcd version of kv.Client +type Clientv3Facade interface { + clientv3.KV + clientv3.Watcher +} + // Client implements ring.KVClient for etcd. type Client struct { cfg Config codec codec.Codec - cli *clientv3.Client + cli Clientv3Facade logger log.Logger } +func (cfg *Config) RegisterFlags(f *flag.FlagSet) { + cfg.RegisterFlagsWithPrefix(f, "") +} + // RegisterFlagsWithPrefix adds the flags required to config this to the given FlagSet. func (cfg *Config) RegisterFlagsWithPrefix(f *flag.FlagSet, prefix string) { cfg.Endpoints = []string{} diff --git a/vendor/github.com/grafana/dskit/kv/etcd/mock.go b/vendor/github.com/grafana/dskit/kv/etcd/mock.go index 27ad71f2ef..b7ee276455 100644 --- a/vendor/github.com/grafana/dskit/kv/etcd/mock.go +++ b/vendor/github.com/grafana/dskit/kv/etcd/mock.go @@ -1,71 +1,499 @@ package etcd import ( - "flag" + "bytes" + "context" "fmt" "io" - "io/ioutil" - "net/url" - "time" + "sync" - "github.com/go-kit/kit/log" - "go.etcd.io/etcd/server/v3/embed" - "go.etcd.io/etcd/server/v3/etcdserver/api/v3client" + "github.com/go-kit/log" + "go.etcd.io/etcd/api/v3/etcdserverpb" + "go.etcd.io/etcd/api/v3/mvccpb" + clientv3 "go.etcd.io/etcd/client/v3" - "github.com/grafana/dskit/closer" "github.com/grafana/dskit/flagext" "github.com/grafana/dskit/kv/codec" ) -const etcdStartTimeout = 30 * time.Second +// channelBufferSize is the size of the channels used to send events from Put, Delete, +// and transactions as well as the channel used to send filtered events to watchers. +const channelBufferSize = 10 + +// NewInMemoryClient creates an Etcd Client implementation that uses an in-memory +// version of the underlying Etcd client. +func NewInMemoryClient(codec codec.Codec, logger log.Logger) (*Client, io.Closer) { + // Make sure to set default values for the config including number of retries, + // otherwise the client won't even attempt a CAS operation + cfg := Config{} + flagext.DefaultValues(&cfg) + + kv := newMockKV() + client := &Client{ + cfg: cfg, + codec: codec, + cli: kv, + logger: logger, + } + + return client, kv +} + +// newMockKV creates an in-memory implementation of an etcd client +func newMockKV() *mockKV { + kv := &mockKV{ + values: make(map[string]mvccpb.KeyValue), + valuesMtx: sync.Mutex{}, + close: make(chan struct{}), + events: make(map[chan clientv3.Event]struct{}), + eventsMtx: sync.Mutex{}, + } + + return kv +} + +// mockKV is an in-memory implementation of an Etcd client. +// +// This implementation has many limitations compared to the real client since it +// only exists to be used by the Etcd kv.Client implementation during unit tests. As +// such some behavior may be missing or incorrect compared to the real client. This +// is determined to be an acceptable tradeoff to avoid needing to depend on an entire +// Etcd server for unit tests. +// +// Known limitations: +// +// * Compact is not implemented and will panic +// * RequestProgress is not implemented and will panic +// * Only exact and prefix matching is supported for Get, Put, and Delete +// * There may be inconsistencies with how various version numbers are adjusted +// but none that are exposed by kv.Client unit tests +type mockKV struct { + // Key-value pairs created by put calls or transactions + values map[string]mvccpb.KeyValue + valuesMtx sync.Mutex + + // Channel for stopping all running watch goroutines and closing + // and cleaning up all channels used for sending events to watchers + close chan struct{} + + // Channels that should receive events in response to Put or Delete + // calls. These channels are in turn read by goroutines that apply + // filtering before sending watch responses to their callers. + events map[chan clientv3.Event]struct{} + eventsMtx sync.Mutex +} + +// Watch implements the Clientv3Facade interface +func (m *mockKV) Watch(ctx context.Context, key string, opts ...clientv3.OpOption) clientv3.WatchChan { + watcher := make(chan clientv3.WatchResponse, channelBufferSize) + consumer := m.createEventConsumer(channelBufferSize) + + go func() { + defer func() { + // When this goroutine ends, remove and close the channel written to by the + // Put and Delete methods as well as closing the channel read by the caller + // of the Watch method + m.destroyEventConsumer(consumer) + + // non-blocking send + select { + case watcher <- clientv3.WatchResponse{Canceled: true}: + default: + } + + close(watcher) + }() + + for { + select { + case <-ctx.Done(): + // Context cancelled for this watcher, run cleanup logic and exit + return + case <-m.close: + // Close method called for all watchers, run cleanup logic and exit + return + case e := <-consumer: + op := clientv3.OpGet(key, opts...) + match := m.isMatch(op, *e.Kv) + + if match { + // non-blocking send + select { + case watcher <- clientv3.WatchResponse{Events: []*clientv3.Event{&e}}: + default: + } + } + } + } + }() + + return watcher +} + +// createEventConsumer creates and returns a new channel that is registered to receive +// events for Puts and Deletes. +func (m *mockKV) createEventConsumer(bufSz int) chan clientv3.Event { + ch := make(chan clientv3.Event, bufSz) + m.eventsMtx.Lock() + m.events[ch] = struct{}{} + m.eventsMtx.Unlock() + return ch +} + +// destroyEventConsumer removes the given channel from the list of channels that events +// should be sent to and closes it. +func (m *mockKV) destroyEventConsumer(ch chan clientv3.Event) { + m.eventsMtx.Lock() + delete(m.events, ch) + m.eventsMtx.Unlock() + close(ch) +} + +// sendEvent writes an event to all currently registered events. The consumer +// channels are each read by a goroutine that filters the event and sends it to +// the caller of the Watch method. +func (m *mockKV) sendEvent(e clientv3.Event) { + m.eventsMtx.Lock() + for ch := range m.events { + // non-blocking send + select { + case ch <- e: + default: + } + } + m.eventsMtx.Unlock() +} + +// RequestProgress implements the Clientv3Facade interface +func (m *mockKV) RequestProgress(context.Context) error { + panic("RequestProgress unimplemented") +} + +// Close implements the Clientv3Facade interface +func (m *mockKV) Close() error { + close(m.close) + return nil +} + +// Get implements the Clientv3Facade interface +func (m *mockKV) Get(ctx context.Context, key string, opts ...clientv3.OpOption) (*clientv3.GetResponse, error) { + op := clientv3.OpGet(key, opts...) + res, err := m.Do(ctx, op) -// Mock returns a Mock Etcd client. -// Inspired by https://github.com/ligato/cn-infra/blob/master/db/keyval/etcd/mocks/embeded_etcd.go. -func Mock(codec codec.Codec, logger log.Logger) (*Client, io.Closer, error) { - dir, err := ioutil.TempDir("", "etcd") if err != nil { - return nil, nil, err + return nil, err } - cfg := embed.NewConfig() - cfg.Logger = "zap" - cfg.Dir = dir - lpurl, _ := url.Parse("http://localhost:0") - lcurl, _ := url.Parse("http://localhost:0") - cfg.LPUrls = []url.URL{*lpurl} - cfg.LCUrls = []url.URL{*lcurl} + return res.Get(), nil +} + +// Delete implements the Clientv3Facade interface +func (m *mockKV) Delete(ctx context.Context, key string, opts ...clientv3.OpOption) (*clientv3.DeleteResponse, error) { + op := clientv3.OpDelete(key, opts...) + res, err := m.Do(ctx, op) + + if err != nil { + return nil, err + } + + return res.Del(), nil +} + +// Put implements the Clientv3Facade interface +func (m *mockKV) Put(ctx context.Context, key, val string, opts ...clientv3.OpOption) (*clientv3.PutResponse, error) { + op := clientv3.OpPut(key, val, opts...) + res, err := m.Do(ctx, op) - etcd, err := embed.StartEtcd(cfg) if err != nil { - return nil, nil, err + return nil, err + } + + return res.Put(), nil +} + +// Txn implements the Clientv3Facade interface +func (m *mockKV) Txn(ctx context.Context) clientv3.Txn { + return &mockTxn{ + ctx: ctx, + kv: m, + } +} + +// Compact implements the Clientv3Facade interface +func (m *mockKV) Compact(context.Context, int64, ...clientv3.CompactOption) (*clientv3.CompactResponse, error) { + panic("Compact unimplemented") +} + +// Do implements the Clientv3Facade interface +func (m *mockKV) Do(_ context.Context, op clientv3.Op) (clientv3.OpResponse, error) { + m.valuesMtx.Lock() + defer m.valuesMtx.Unlock() + return m.doInternal(op) +} + +func (m *mockKV) doInternal(op clientv3.Op) (clientv3.OpResponse, error) { + if op.IsGet() { + return m.doGet(op) + } else if op.IsPut() { + return m.doPut(op) + } else if op.IsDelete() { + return m.doDelete(op) + } else if op.IsTxn() { + return m.doTxn(op) + } else { + panic(fmt.Sprintf("unsupported operation: %+v", op)) + } +} + +func (m *mockKV) doGet(op clientv3.Op) (clientv3.OpResponse, error) { + matching := m.matchingKeys(op, m.values) + kvs := make([]*mvccpb.KeyValue, 0, len(matching)) + + for _, k := range matching { + kv := m.values[k] + kvs = append(kvs, &kv) + } + + res := clientv3.GetResponse{ + Kvs: kvs, + Count: int64(len(kvs)), } - select { - case <-etcd.Server.ReadyNotify(): - case <-time.After(etcdStartTimeout): - etcd.Server.Stop() // trigger a shutdown - return nil, nil, fmt.Errorf("server took too long to start") + return res.OpResponse(), nil +} + +func (m *mockKV) doDelete(op clientv3.Op) (clientv3.OpResponse, error) { + matching := m.matchingKeys(op, m.values) + + for _, k := range matching { + kv := m.values[k] + kv.ModRevision = kv.Version + + m.sendEvent(clientv3.Event{ + Type: mvccpb.DELETE, + Kv: &kv, + }) + + delete(m.values, k) } - closer := closer.Func(func() error { - etcd.Server.Stop() - return nil + res := clientv3.DeleteResponse{Deleted: int64(len(matching))} + return res.OpResponse(), nil +} + +func (m *mockKV) doPut(op clientv3.Op) (clientv3.OpResponse, error) { + keyBytes := op.KeyBytes() + valBytes := op.ValueBytes() + key := string(keyBytes) + + var newVal mvccpb.KeyValue + oldVal, ok := m.values[key] + + if ok { + newVal = oldVal + newVal.Version = newVal.Version + 1 + newVal.ModRevision = newVal.ModRevision + 1 + newVal.Value = valBytes + } else { + newVal = mvccpb.KeyValue{ + Key: keyBytes, + Value: valBytes, + Version: 1, + CreateRevision: 1, + ModRevision: 1, + } + } + + m.values[key] = newVal + m.sendEvent(clientv3.Event{ + Type: mvccpb.PUT, + Kv: &newVal, }) - var config Config - flagext.DefaultValues(&config) + res := clientv3.PutResponse{} + return res.OpResponse(), nil +} - client := &Client{ - cfg: config, - codec: codec, - cli: v3client.New(etcd.Server), - logger: logger, +func (m *mockKV) doTxn(op clientv3.Op) (clientv3.OpResponse, error) { + cmps, thens, elses := op.Txn() + succeeded := m.evalCmps(cmps) + + var toRun []clientv3.Op + if succeeded { + toRun = thens + } else { + toRun = elses + } + + responses := make([]*etcdserverpb.ResponseOp, 0, len(toRun)) + for _, o := range toRun { + _, err := m.doInternal(o) + if err != nil { + panic(fmt.Sprintf("unexpected error running transaction: %s", err)) + } + + responses = append(responses, &etcdserverpb.ResponseOp{Response: nil}) + } + + res := clientv3.TxnResponse{ + Succeeded: succeeded, + Responses: responses, + } + return res.OpResponse(), nil +} + +// matchingKeys returns the keys of elements that match the given Op +func (m *mockKV) matchingKeys(op clientv3.Op, kvps map[string]mvccpb.KeyValue) []string { + // NOTE that even when Op is a prefix match, the key bytes will be the same + // as they would be for an exact match. We use the fact that RangeBytes will + // be non-nil for prefix matches to understand how to select keys. + keyBytes := op.KeyBytes() + rangeBytes := op.RangeBytes() + keys := make([]string, 0) + + if keyBytes != nil && rangeBytes == nil { + // Exact match + k := string(keyBytes) + + if _, ok := kvps[k]; ok { + keys = append(keys, k) + } + } else if keyBytes != nil { + // Prefix match + emptyPrefix := len(keyBytes) == 1 && keyBytes[0] == byte(0) + for k := range kvps { + if emptyPrefix || bytes.HasPrefix([]byte(k), keyBytes) { + keys = append(keys, k) + } + } } - return client, closer, nil + return keys } -// RegisterFlags adds the flags required to config this to the given FlagSet. -func (cfg *Config) RegisterFlags(f *flag.FlagSet) { - cfg.RegisterFlagsWithPrefix(f, "") +// isMatch returns true if the provided key-value pair matches the given Op +func (m *mockKV) isMatch(op clientv3.Op, kvp mvccpb.KeyValue) bool { + keys := m.matchingKeys(op, map[string]mvccpb.KeyValue{string(kvp.Key): kvp}) + return len(keys) != 0 +} + +// evalCmps executes the given comparisons, stopping as soon as the first one +// evaluates to false. +func (m *mockKV) evalCmps(cmps []clientv3.Cmp) bool { + for _, c := range cmps { + if !m.evalCmp(c) { + return false + } + } + + return true +} + +// evalCmp executes the given comparison between some field of a key-value +// pair stored in mockKV and a provided value. The field may be the value +// stored or one of the various version numbers associated with it. +func (m *mockKV) evalCmp(cmp clientv3.Cmp) bool { + // Note that we're not checking if there was an existing entry for this + // key/value pair since we'll get one with all zero values in that case. + // This allows transactions to compare a '0' version so that they can be + // used to only create an entry if there previously was none. + entry := m.values[string(cmp.KeyBytes())] + + switch cmp.Target { + case etcdserverpb.Compare_VALUE: + v, _ := cmp.TargetUnion.(*etcdserverpb.Compare_Value) + return m.evalEntryBytes(entry.Value, v.Value, cmp) + case etcdserverpb.Compare_CREATE: + v, _ := cmp.TargetUnion.(*etcdserverpb.Compare_CreateRevision) + return m.evalEntryInt64(entry.CreateRevision, v.CreateRevision, cmp) + case etcdserverpb.Compare_LEASE: + v, _ := cmp.TargetUnion.(*etcdserverpb.Compare_Lease) + return m.evalEntryInt64(entry.Lease, v.Lease, cmp) + case etcdserverpb.Compare_VERSION: + v, _ := cmp.TargetUnion.(*etcdserverpb.Compare_Version) + return m.evalEntryInt64(entry.Version, v.Version, cmp) + case etcdserverpb.Compare_MOD: + v, _ := cmp.TargetUnion.(*etcdserverpb.Compare_ModRevision) + return m.evalEntryInt64(entry.ModRevision, v.ModRevision, cmp) + default: + panic(fmt.Sprintf("unsupported target for cmp: %+v", cmp)) + } +} + +// evalEntryBytes returns true if the provided comparison between two +// byte slices is true, false otherwise. This is used to compare values +// stored by the mockKV as part of transactions. +func (m *mockKV) evalEntryBytes(v1 []byte, v2 []byte, cmp clientv3.Cmp) bool { + res := bytes.Compare(v1, v2) + + switch cmp.Result { + case etcdserverpb.Compare_EQUAL: + return res == 0 + case etcdserverpb.Compare_GREATER: + return res > 0 + case etcdserverpb.Compare_LESS: + return res < 0 + case etcdserverpb.Compare_NOT_EQUAL: + return res != 0 + default: + panic(fmt.Sprintf("unsupported result for cmp: %+v", cmp)) + } +} + +// evalEntryInt64 returns true if the provided comparison between two ints +// is true, false otherwise. This is used to compared various version numbers +// of key-value pairs stored by the mockKV as part of a transaction. +func (m *mockKV) evalEntryInt64(v1 int64, v2 int64, cmp clientv3.Cmp) bool { + switch cmp.Result { + case etcdserverpb.Compare_EQUAL: + return v1 == v2 + case etcdserverpb.Compare_GREATER: + return v1 > v2 + case etcdserverpb.Compare_LESS: + return v1 < v2 + case etcdserverpb.Compare_NOT_EQUAL: + return v1 != v2 + default: + panic(fmt.Sprintf("unsupported result for cmp: %+v", cmp)) + } +} + +// mockTxn builds up comparisons, success actions and fallback actions to +// be run as part of a transaction. Once the transaction is ready to be +// executed, all the comparisons and actions are run by the mockKV instance +// that started this transaction. +type mockTxn struct { + kv *mockKV + ctx context.Context + cmps []clientv3.Cmp + thenOps []clientv3.Op + elseOps []clientv3.Op +} + +func (m *mockTxn) If(cs ...clientv3.Cmp) clientv3.Txn { + m.cmps = append(m.cmps, cs...) + return m +} + +func (m *mockTxn) Then(ops ...clientv3.Op) clientv3.Txn { + m.thenOps = append(m.thenOps, ops...) + return m +} + +func (m *mockTxn) Else(ops ...clientv3.Op) clientv3.Txn { + m.elseOps = append(m.elseOps, ops...) + return m +} + +func (m *mockTxn) Commit() (*clientv3.TxnResponse, error) { + op := clientv3.OpTxn(m.cmps, m.thenOps, m.elseOps) + // Note that we're using the Do method here instead of doInternal since we didn't + // acquire the data lock when starting this transaction. + res, err := m.kv.Do(m.ctx, op) + + if err != nil { + return nil, err + } + + return res.Txn(), nil } diff --git a/vendor/github.com/grafana/dskit/kv/kvtls/tls.go b/vendor/github.com/grafana/dskit/kv/kvtls/tls.go deleted file mode 100644 index 2338e02ba5..0000000000 --- a/vendor/github.com/grafana/dskit/kv/kvtls/tls.go +++ /dev/null @@ -1,87 +0,0 @@ -package kvtls - -import ( - "crypto/tls" - "crypto/x509" - "flag" - "io/ioutil" - - "github.com/pkg/errors" - "google.golang.org/grpc" - "google.golang.org/grpc/credentials" -) - -// ClientConfig is the config for client TLS. -type ClientConfig struct { - CertPath string `yaml:"tls_cert_path"` - KeyPath string `yaml:"tls_key_path"` - CAPath string `yaml:"tls_ca_path"` - ServerName string `yaml:"tls_server_name"` - InsecureSkipVerify bool `yaml:"tls_insecure_skip_verify"` -} - -var ( - errKeyMissing = errors.New("certificate given but no key configured") - errCertMissing = errors.New("key given but no certificate configured") -) - -// RegisterFlagsWithPrefix registers flags with prefix. -func (cfg *ClientConfig) RegisterFlagsWithPrefix(prefix string, f *flag.FlagSet) { - f.StringVar(&cfg.CertPath, prefix+".tls-cert-path", "", "Path to the client certificate file, which will be used for authenticating with the server. Also requires the key path to be configured.") - f.StringVar(&cfg.KeyPath, prefix+".tls-key-path", "", "Path to the key file for the client certificate. Also requires the client certificate to be configured.") - f.StringVar(&cfg.CAPath, prefix+".tls-ca-path", "", "Path to the CA certificates file to validate server certificate against. If not set, the host's root CA certificates are used.") - f.StringVar(&cfg.ServerName, prefix+".tls-server-name", "", "Override the expected name on the server certificate.") - f.BoolVar(&cfg.InsecureSkipVerify, prefix+".tls-insecure-skip-verify", false, "Skip validating server certificate.") -} - -// GetTLSConfig initialises tls.Config from config options -func (cfg *ClientConfig) GetTLSConfig() (*tls.Config, error) { - config := &tls.Config{ - InsecureSkipVerify: cfg.InsecureSkipVerify, - ServerName: cfg.ServerName, - } - - // read ca certificates - if cfg.CAPath != "" { - var caCertPool *x509.CertPool - caCert, err := ioutil.ReadFile(cfg.CAPath) - if err != nil { - return nil, errors.Wrapf(err, "error loading ca cert: %s", cfg.CAPath) - } - caCertPool = x509.NewCertPool() - caCertPool.AppendCertsFromPEM(caCert) - - config.RootCAs = caCertPool - } - - // read client certificate - if cfg.CertPath != "" || cfg.KeyPath != "" { - if cfg.CertPath == "" { - return nil, errCertMissing - } - if cfg.KeyPath == "" { - return nil, errKeyMissing - } - clientCert, err := tls.LoadX509KeyPair(cfg.CertPath, cfg.KeyPath) - if err != nil { - return nil, errors.Wrapf(err, "failed to load TLS certificate %s,%s", cfg.CertPath, cfg.KeyPath) - } - config.Certificates = []tls.Certificate{clientCert} - } - - return config, nil -} - -// GetGRPCDialOptions creates GRPC DialOptions for TLS -func (cfg *ClientConfig) GetGRPCDialOptions(enabled bool) ([]grpc.DialOption, error) { - if !enabled { - return []grpc.DialOption{grpc.WithInsecure()}, nil - } - - tlsConfig, err := cfg.GetTLSConfig() - if err != nil { - return nil, errors.Wrap(err, "error creating grpc dial options") - } - - return []grpc.DialOption{grpc.WithTransportCredentials(credentials.NewTLS(tlsConfig))}, nil -} diff --git a/vendor/github.com/grafana/dskit/kv/memberlist/broadcast.go b/vendor/github.com/grafana/dskit/kv/memberlist/broadcast.go index 7c0a72cf8b..6657b73a51 100644 --- a/vendor/github.com/grafana/dskit/kv/memberlist/broadcast.go +++ b/vendor/github.com/grafana/dskit/kv/memberlist/broadcast.go @@ -3,8 +3,8 @@ package memberlist import ( "fmt" - "github.com/go-kit/kit/log" - "github.com/go-kit/kit/log/level" + "github.com/go-kit/log" + "github.com/go-kit/log/level" "github.com/hashicorp/memberlist" ) diff --git a/vendor/github.com/grafana/dskit/kv/memberlist/kv_init_service.go b/vendor/github.com/grafana/dskit/kv/memberlist/kv_init_service.go index c137bc786d..e63aac2f43 100644 --- a/vendor/github.com/grafana/dskit/kv/memberlist/kv_init_service.go +++ b/vendor/github.com/grafana/dskit/kv/memberlist/kv_init_service.go @@ -12,7 +12,7 @@ import ( "sync" "time" - "github.com/go-kit/kit/log" + "github.com/go-kit/log" "github.com/hashicorp/memberlist" "github.com/prometheus/client_golang/prometheus" "go.uber.org/atomic" diff --git a/vendor/github.com/grafana/dskit/kv/memberlist/memberlist_client.go b/vendor/github.com/grafana/dskit/kv/memberlist/memberlist_client.go index d5c1c7e74c..1b21fa5c42 100644 --- a/vendor/github.com/grafana/dskit/kv/memberlist/memberlist_client.go +++ b/vendor/github.com/grafana/dskit/kv/memberlist/memberlist_client.go @@ -13,8 +13,8 @@ import ( "sync" "time" - "github.com/go-kit/kit/log" - "github.com/go-kit/kit/log/level" + "github.com/go-kit/log" + "github.com/go-kit/log/level" "github.com/hashicorp/memberlist" "github.com/prometheus/client_golang/prometheus" @@ -135,6 +135,10 @@ type KVConfig struct { DeadNodeReclaimTime time.Duration `yaml:"dead_node_reclaim_time"` EnableCompression bool `yaml:"compression_enabled"` + // ip:port to advertise other cluster members. Used for NAT traversal + AdvertiseAddr string `yaml:"advertise_addr"` + AdvertisePort int `yaml:"advertise_port"` + // List of members to join JoinMembers flagext.StringSlice `yaml:"join_members"` MinJoinBackoff time.Duration `yaml:"min_join_backoff"` @@ -186,6 +190,8 @@ func (cfg *KVConfig) RegisterFlagsWithPrefix(f *flag.FlagSet, prefix string) { f.DurationVar(&cfg.DeadNodeReclaimTime, prefix+"memberlist.dead-node-reclaim-time", mlDefaults.DeadNodeReclaimTime, "How soon can dead node's name be reclaimed with new address. 0 to disable.") f.IntVar(&cfg.MessageHistoryBufferBytes, prefix+"memberlist.message-history-buffer-bytes", 0, "How much space to use for keeping received and sent messages in memory for troubleshooting (two buffers). 0 to disable.") f.BoolVar(&cfg.EnableCompression, prefix+"memberlist.compression-enabled", mlDefaults.EnableCompression, "Enable message compression. This can be used to reduce bandwidth usage at the cost of slightly more CPU utilization.") + f.StringVar(&cfg.AdvertiseAddr, prefix+"memberlist.advertise-addr", mlDefaults.AdvertiseAddr, "Gossip address to advertise to other members in the cluster. Used for NAT traversal.") + f.IntVar(&cfg.AdvertisePort, prefix+"memberlist.advertise-port", mlDefaults.AdvertisePort, "Gossip port to advertise to other members in the cluster. Used for NAT traversal.") cfg.TCPTransport.RegisterFlags(f, prefix) } @@ -377,6 +383,9 @@ func (m *KV) buildMemberlistConfig() (*memberlist.Config, error) { mlCfg.DeadNodeReclaimTime = m.cfg.DeadNodeReclaimTime mlCfg.EnableCompression = m.cfg.EnableCompression + mlCfg.AdvertiseAddr = m.cfg.AdvertiseAddr + mlCfg.AdvertisePort = m.cfg.AdvertisePort + if m.cfg.NodeName != "" { mlCfg.Name = m.cfg.NodeName } diff --git a/vendor/github.com/grafana/dskit/kv/memberlist/memberlist_logger.go b/vendor/github.com/grafana/dskit/kv/memberlist/memberlist_logger.go index 36e59306a1..6ccb469b67 100644 --- a/vendor/github.com/grafana/dskit/kv/memberlist/memberlist_logger.go +++ b/vendor/github.com/grafana/dskit/kv/memberlist/memberlist_logger.go @@ -5,8 +5,8 @@ import ( "regexp" "strings" - "github.com/go-kit/kit/log" - "github.com/go-kit/kit/log/level" + "github.com/go-kit/log" + "github.com/go-kit/log/level" ) // loggerAdapter wraps a Logger and allows it to be passed to the stdlib diff --git a/vendor/github.com/grafana/dskit/kv/memberlist/metrics.go b/vendor/github.com/grafana/dskit/kv/memberlist/metrics.go index 26fd905fb7..c7d3f01c27 100644 --- a/vendor/github.com/grafana/dskit/kv/memberlist/metrics.go +++ b/vendor/github.com/grafana/dskit/kv/memberlist/metrics.go @@ -5,7 +5,7 @@ import ( armonmetrics "github.com/armon/go-metrics" armonprometheus "github.com/armon/go-metrics/prometheus" - "github.com/go-kit/kit/log/level" + "github.com/go-kit/log/level" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promauto" diff --git a/vendor/github.com/grafana/dskit/kv/memberlist/tcp_transport.go b/vendor/github.com/grafana/dskit/kv/memberlist/tcp_transport.go index 4c6badee01..dc6f9a0ac1 100644 --- a/vendor/github.com/grafana/dskit/kv/memberlist/tcp_transport.go +++ b/vendor/github.com/grafana/dskit/kv/memberlist/tcp_transport.go @@ -12,8 +12,8 @@ import ( "sync" "time" - "github.com/go-kit/kit/log" - "github.com/go-kit/kit/log/level" + "github.com/go-kit/log" + "github.com/go-kit/log/level" "github.com/hashicorp/go-sockaddr" "github.com/hashicorp/memberlist" "github.com/pkg/errors" @@ -21,8 +21,8 @@ import ( "github.com/prometheus/client_golang/prometheus/promauto" "go.uber.org/atomic" + dstls "github.com/grafana/dskit/crypto/tls" "github.com/grafana/dskit/flagext" - "github.com/grafana/dskit/kv/kvtls" ) type messageType uint8 @@ -58,7 +58,7 @@ type TCPTransportConfig struct { MetricsNamespace string `yaml:"-"` TLSEnabled bool `yaml:"tls_enabled"` - TLS kvtls.ClientConfig `yaml:",inline"` + TLS dstls.ClientConfig `yaml:",inline"` } // RegisterFlags registers flags. diff --git a/vendor/github.com/grafana/dskit/kv/mock.go b/vendor/github.com/grafana/dskit/kv/mock.go index 0854913fbf..5b446d854d 100644 --- a/vendor/github.com/grafana/dskit/kv/mock.go +++ b/vendor/github.com/grafana/dskit/kv/mock.go @@ -3,8 +3,8 @@ package kv import ( "context" - "github.com/go-kit/kit/log" - "github.com/go-kit/kit/log/level" + "github.com/go-kit/log" + "github.com/go-kit/log/level" ) // The mockClient does not anything. diff --git a/vendor/github.com/grafana/dskit/kv/multi.go b/vendor/github.com/grafana/dskit/kv/multi.go index 233b3a1aa9..8a3382e985 100644 --- a/vendor/github.com/grafana/dskit/kv/multi.go +++ b/vendor/github.com/grafana/dskit/kv/multi.go @@ -7,8 +7,8 @@ import ( "sync" "time" - "github.com/go-kit/kit/log" - "github.com/go-kit/kit/log/level" + "github.com/go-kit/log" + "github.com/go-kit/log/level" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promauto" "go.uber.org/atomic" diff --git a/vendor/github.com/grafana/dskit/middleware/grpc.go b/vendor/github.com/grafana/dskit/middleware/grpc.go new file mode 100644 index 0000000000..b0d9d31ba7 --- /dev/null +++ b/vendor/github.com/grafana/dskit/middleware/grpc.go @@ -0,0 +1,83 @@ +package middleware + +import ( + "context" + "io" + "time" + + "github.com/prometheus/client_golang/prometheus" + "github.com/weaveworks/common/instrument" + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" +) + +// PrometheusGRPCUnaryInstrumentation records duration of gRPC requests client side. +func PrometheusGRPCUnaryInstrumentation(metric *prometheus.HistogramVec) grpc.UnaryClientInterceptor { + return func(ctx context.Context, method string, req, resp interface{}, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error { + start := time.Now() + err := invoker(ctx, method, req, resp, cc, opts...) + metric.WithLabelValues(method, instrument.ErrorCode(err)).Observe(time.Since(start).Seconds()) + return err + } +} + +// PrometheusGRPCStreamInstrumentation records duration of streaming gRPC requests client side. +func PrometheusGRPCStreamInstrumentation(metric *prometheus.HistogramVec) grpc.StreamClientInterceptor { + return func(ctx context.Context, desc *grpc.StreamDesc, cc *grpc.ClientConn, method string, + streamer grpc.Streamer, opts ...grpc.CallOption, + ) (grpc.ClientStream, error) { + start := time.Now() + stream, err := streamer(ctx, desc, cc, method, opts...) + return &instrumentedClientStream{ + metric: metric, + start: start, + method: method, + ClientStream: stream, + }, err + } +} + +type instrumentedClientStream struct { + metric *prometheus.HistogramVec + start time.Time + method string + grpc.ClientStream +} + +func (s *instrumentedClientStream) SendMsg(m interface{}) error { + err := s.ClientStream.SendMsg(m) + if err == nil { + return err + } + + if err == io.EOF { + s.metric.WithLabelValues(s.method, instrument.ErrorCode(nil)).Observe(time.Since(s.start).Seconds()) + } else { + s.metric.WithLabelValues(s.method, instrument.ErrorCode(err)).Observe(time.Since(s.start).Seconds()) + } + + return err +} + +func (s *instrumentedClientStream) RecvMsg(m interface{}) error { + err := s.ClientStream.RecvMsg(m) + if err == nil { + return err + } + + if err == io.EOF { + s.metric.WithLabelValues(s.method, instrument.ErrorCode(nil)).Observe(time.Since(s.start).Seconds()) + } else { + s.metric.WithLabelValues(s.method, instrument.ErrorCode(err)).Observe(time.Since(s.start).Seconds()) + } + + return err +} + +func (s *instrumentedClientStream) Header() (metadata.MD, error) { + md, err := s.ClientStream.Header() + if err != nil { + s.metric.WithLabelValues(s.method, instrument.ErrorCode(err)).Observe(time.Since(s.start).Seconds()) + } + return md, err +} diff --git a/vendor/github.com/grafana/dskit/modules/module_service.go b/vendor/github.com/grafana/dskit/modules/module_service.go index 5efe48d03b..b27d0244ab 100644 --- a/vendor/github.com/grafana/dskit/modules/module_service.go +++ b/vendor/github.com/grafana/dskit/modules/module_service.go @@ -4,8 +4,8 @@ import ( "context" "fmt" - "github.com/go-kit/kit/log" - "github.com/go-kit/kit/log/level" + "github.com/go-kit/log" + "github.com/go-kit/log/level" "github.com/pkg/errors" "github.com/grafana/dskit/services" diff --git a/vendor/github.com/grafana/dskit/modules/module_service_wrapper.go b/vendor/github.com/grafana/dskit/modules/module_service_wrapper.go index 4560830d6c..39057d8370 100644 --- a/vendor/github.com/grafana/dskit/modules/module_service_wrapper.go +++ b/vendor/github.com/grafana/dskit/modules/module_service_wrapper.go @@ -1,7 +1,7 @@ package modules import ( - "github.com/go-kit/kit/log" + "github.com/go-kit/log" "github.com/grafana/dskit/services" ) diff --git a/vendor/github.com/grafana/dskit/modules/modules.go b/vendor/github.com/grafana/dskit/modules/modules.go index 648ba392df..4aee08d213 100644 --- a/vendor/github.com/grafana/dskit/modules/modules.go +++ b/vendor/github.com/grafana/dskit/modules/modules.go @@ -4,7 +4,7 @@ import ( "fmt" "sort" - "github.com/go-kit/kit/log" + "github.com/go-kit/log" "github.com/pkg/errors" "github.com/grafana/dskit/services" diff --git a/vendor/github.com/grafana/dskit/runtimeconfig/manager.go b/vendor/github.com/grafana/dskit/runtimeconfig/manager.go index f650663694..dbe5643526 100644 --- a/vendor/github.com/grafana/dskit/runtimeconfig/manager.go +++ b/vendor/github.com/grafana/dskit/runtimeconfig/manager.go @@ -11,8 +11,8 @@ import ( "sync" "time" - "github.com/go-kit/kit/log" - "github.com/go-kit/kit/log/level" + "github.com/go-kit/log" + "github.com/go-kit/log/level" "github.com/pkg/errors" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promauto" diff --git a/vendor/github.com/grpc-ecosystem/go-grpc-prometheus/.gitignore b/vendor/github.com/grpc-ecosystem/go-grpc-prometheus/.gitignore deleted file mode 100644 index 2233cff9d1..0000000000 --- a/vendor/github.com/grpc-ecosystem/go-grpc-prometheus/.gitignore +++ /dev/null @@ -1,201 +0,0 @@ -#vendor -vendor/ - -# Created by .ignore support plugin (hsz.mobi) -coverage.txt -### Go template -# Compiled Object files, Static and Dynamic libs (Shared Objects) -*.o -*.a -*.so - -# Folders -_obj -_test - -# Architecture specific extensions/prefixes -*.[568vq] -[568vq].out - -*.cgo1.go -*.cgo2.c -_cgo_defun.c -_cgo_gotypes.go -_cgo_export.* - -_testmain.go - -*.exe -*.test -*.prof -### Windows template -# Windows image file caches -Thumbs.db -ehthumbs.db - -# Folder config file -Desktop.ini - -# Recycle Bin used on file shares -$RECYCLE.BIN/ - -# Windows Installer files -*.cab -*.msi -*.msm -*.msp - -# Windows shortcuts -*.lnk -### Kate template -# Swap Files # -.*.kate-swp -.swp.* -### SublimeText template -# cache files for sublime text -*.tmlanguage.cache -*.tmPreferences.cache -*.stTheme.cache - -# workspace files are user-specific -*.sublime-workspace - -# project files should be checked into the repository, unless a significant -# proportion of contributors will probably not be using SublimeText -# *.sublime-project - -# sftp configuration file -sftp-config.json -### Linux template -*~ - -# temporary files which can be created if a process still has a handle open of a deleted file -.fuse_hidden* - -# KDE directory preferences -.directory - -# Linux trash folder which might appear on any partition or disk -.Trash-* -### JetBrains template -# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm -# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 - -# User-specific stuff: -.idea -.idea/tasks.xml -.idea/dictionaries -.idea/vcs.xml -.idea/jsLibraryMappings.xml - -# Sensitive or high-churn files: -.idea/dataSources.ids -.idea/dataSources.xml -.idea/dataSources.local.xml -.idea/sqlDataSources.xml -.idea/dynamic.xml -.idea/uiDesigner.xml - -# Gradle: -.idea/gradle.xml -.idea/libraries - -# Mongo Explorer plugin: -.idea/mongoSettings.xml - -## File-based project format: -*.iws - -## Plugin-specific files: - -# IntelliJ -/out/ - -# mpeltonen/sbt-idea plugin -.idea_modules/ - -# JIRA plugin -atlassian-ide-plugin.xml - -# Crashlytics plugin (for Android Studio and IntelliJ) -com_crashlytics_export_strings.xml -crashlytics.properties -crashlytics-build.properties -fabric.properties -### Xcode template -# Xcode -# -# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore - -## Build generated -build/ -DerivedData/ - -## Various settings -*.pbxuser -!default.pbxuser -*.mode1v3 -!default.mode1v3 -*.mode2v3 -!default.mode2v3 -*.perspectivev3 -!default.perspectivev3 -xcuserdata/ - -## Other -*.moved-aside -*.xccheckout -*.xcscmblueprint -### Eclipse template - -.metadata -bin/ -tmp/ -*.tmp -*.bak -*.swp -*~.nib -local.properties -.settings/ -.loadpath -.recommenders - -# Eclipse Core -.project - -# External tool builders -.externalToolBuilders/ - -# Locally stored "Eclipse launch configurations" -*.launch - -# PyDev specific (Python IDE for Eclipse) -*.pydevproject - -# CDT-specific (C/C++ Development Tooling) -.cproject - -# JDT-specific (Eclipse Java Development Tools) -.classpath - -# Java annotation processor (APT) -.factorypath - -# PDT-specific (PHP Development Tools) -.buildpath - -# sbteclipse plugin -.target - -# Tern plugin -.tern-project - -# TeXlipse plugin -.texlipse - -# STS (Spring Tool Suite) -.springBeans - -# Code Recommenders -.recommenders/ - diff --git a/vendor/github.com/grpc-ecosystem/go-grpc-prometheus/.travis.yml b/vendor/github.com/grpc-ecosystem/go-grpc-prometheus/.travis.yml deleted file mode 100644 index 2a845b96ae..0000000000 --- a/vendor/github.com/grpc-ecosystem/go-grpc-prometheus/.travis.yml +++ /dev/null @@ -1,25 +0,0 @@ -sudo: false -language: go -# * github.com/grpc/grpc-go still supports go1.6 -# - When we drop support for go1.6 we can remove golang.org/x/net/context -# below as it is part of the Go std library since go1.7 -# * github.com/prometheus/client_golang already requires at least go1.7 since -# September 2017 -go: - - 1.6.x - - 1.7.x - - 1.8.x - - 1.9.x - - 1.10.x - - master - -install: - - go get github.com/prometheus/client_golang/prometheus - - go get google.golang.org/grpc - - go get golang.org/x/net/context - - go get github.com/stretchr/testify -script: - - make test - -after_success: - - bash <(curl -s https://codecov.io/bash) diff --git a/vendor/github.com/grpc-ecosystem/go-grpc-prometheus/CHANGELOG.md b/vendor/github.com/grpc-ecosystem/go-grpc-prometheus/CHANGELOG.md deleted file mode 100644 index 19a8059e1b..0000000000 --- a/vendor/github.com/grpc-ecosystem/go-grpc-prometheus/CHANGELOG.md +++ /dev/null @@ -1,24 +0,0 @@ -# Changelog -All notable changes to this project will be documented in this file. - -The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) -and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). - -## [Unreleased] - -## [1.2.0](https://github.com/grpc-ecosystem/go-grpc-prometheus/releases/tag/v1.2.0) - 2018-06-04 - -### Added - -* Provide metrics object as `prometheus.Collector`, for conventional metric registration. -* Support non-default/global Prometheus registry. -* Allow configuring counters with `prometheus.CounterOpts`. - -### Changed - -* Remove usage of deprecated `grpc.Code()`. -* Remove usage of deprecated `grpc.Errorf` and replace with `status.Errorf`. - ---- - -This changelog was started with version `v1.2.0`, for earlier versions refer to the respective [GitHub releases](https://github.com/grpc-ecosystem/go-grpc-prometheus/releases). diff --git a/vendor/github.com/grpc-ecosystem/go-grpc-prometheus/LICENSE b/vendor/github.com/grpc-ecosystem/go-grpc-prometheus/LICENSE deleted file mode 100644 index b2b065037f..0000000000 --- a/vendor/github.com/grpc-ecosystem/go-grpc-prometheus/LICENSE +++ /dev/null @@ -1,201 +0,0 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. \ No newline at end of file diff --git a/vendor/github.com/grpc-ecosystem/go-grpc-prometheus/README.md b/vendor/github.com/grpc-ecosystem/go-grpc-prometheus/README.md deleted file mode 100644 index 499c583553..0000000000 --- a/vendor/github.com/grpc-ecosystem/go-grpc-prometheus/README.md +++ /dev/null @@ -1,247 +0,0 @@ -# Go gRPC Interceptors for Prometheus monitoring - -[![Travis Build](https://travis-ci.org/grpc-ecosystem/go-grpc-prometheus.svg)](https://travis-ci.org/grpc-ecosystem/go-grpc-prometheus) -[![Go Report Card](https://goreportcard.com/badge/github.com/grpc-ecosystem/go-grpc-prometheus)](http://goreportcard.com/report/grpc-ecosystem/go-grpc-prometheus) -[![GoDoc](http://img.shields.io/badge/GoDoc-Reference-blue.svg)](https://godoc.org/github.com/grpc-ecosystem/go-grpc-prometheus) -[![SourceGraph](https://sourcegraph.com/github.com/grpc-ecosystem/go-grpc-prometheus/-/badge.svg)](https://sourcegraph.com/github.com/grpc-ecosystem/go-grpc-prometheus/?badge) -[![codecov](https://codecov.io/gh/grpc-ecosystem/go-grpc-prometheus/branch/master/graph/badge.svg)](https://codecov.io/gh/grpc-ecosystem/go-grpc-prometheus) -[![Apache 2.0 License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](LICENSE) - -[Prometheus](https://prometheus.io/) monitoring for your [gRPC Go](https://github.com/grpc/grpc-go) servers and clients. - -A sister implementation for [gRPC Java](https://github.com/grpc/grpc-java) (same metrics, same semantics) is in [grpc-ecosystem/java-grpc-prometheus](https://github.com/grpc-ecosystem/java-grpc-prometheus). - -## Interceptors - -[gRPC Go](https://github.com/grpc/grpc-go) recently acquired support for Interceptors, i.e. middleware that is executed -by a gRPC Server before the request is passed onto the user's application logic. It is a perfect way to implement -common patterns: auth, logging and... monitoring. - -To use Interceptors in chains, please see [`go-grpc-middleware`](https://github.com/mwitkow/go-grpc-middleware). - -## Usage - -There are two types of interceptors: client-side and server-side. This package provides monitoring Interceptors for both. - -### Server-side - -```go -import "github.com/grpc-ecosystem/go-grpc-prometheus" -... - // Initialize your gRPC server's interceptor. - myServer := grpc.NewServer( - grpc.StreamInterceptor(grpc_prometheus.StreamServerInterceptor), - grpc.UnaryInterceptor(grpc_prometheus.UnaryServerInterceptor), - ) - // Register your gRPC service implementations. - myservice.RegisterMyServiceServer(s.server, &myServiceImpl{}) - // After all your registrations, make sure all of the Prometheus metrics are initialized. - grpc_prometheus.Register(myServer) - // Register Prometheus metrics handler. - http.Handle("/metrics", promhttp.Handler()) -... -``` - -### Client-side - -```go -import "github.com/grpc-ecosystem/go-grpc-prometheus" -... - clientConn, err = grpc.Dial( - address, - grpc.WithUnaryInterceptor(grpc_prometheus.UnaryClientInterceptor), - grpc.WithStreamInterceptor(grpc_prometheus.StreamClientInterceptor) - ) - client = pb_testproto.NewTestServiceClient(clientConn) - resp, err := client.PingEmpty(s.ctx, &myservice.Request{Msg: "hello"}) -... -``` - -# Metrics - -## Labels - -All server-side metrics start with `grpc_server` as Prometheus subsystem name. All client-side metrics start with `grpc_client`. Both of them have mirror-concepts. Similarly all methods -contain the same rich labels: - - * `grpc_service` - the [gRPC service](http://www.grpc.io/docs/#defining-a-service) name, which is the combination of protobuf `package` and - the `grpc_service` section name. E.g. for `package = mwitkow.testproto` and - `service TestService` the label will be `grpc_service="mwitkow.testproto.TestService"` - * `grpc_method` - the name of the method called on the gRPC service. E.g. - `grpc_method="Ping"` - * `grpc_type` - the gRPC [type of request](http://www.grpc.io/docs/guides/concepts.html#rpc-life-cycle). - Differentiating between the two is important especially for latency measurements. - - - `unary` is single request, single response RPC - - `client_stream` is a multi-request, single response RPC - - `server_stream` is a single request, multi-response RPC - - `bidi_stream` is a multi-request, multi-response RPC - - -Additionally for completed RPCs, the following labels are used: - - * `grpc_code` - the human-readable [gRPC status code](https://github.com/grpc/grpc-go/blob/master/codes/codes.go). - The list of all statuses is to long, but here are some common ones: - - - `OK` - means the RPC was successful - - `IllegalArgument` - RPC contained bad values - - `Internal` - server-side error not disclosed to the clients - -## Counters - -The counters and their up to date documentation is in [server_reporter.go](server_reporter.go) and [client_reporter.go](client_reporter.go) -the respective Prometheus handler (usually `/metrics`). - -For the purpose of this documentation we will only discuss `grpc_server` metrics. The `grpc_client` ones contain mirror concepts. - -For simplicity, let's assume we're tracking a single server-side RPC call of [`mwitkow.testproto.TestService`](examples/testproto/test.proto), -calling the method `PingList`. The call succeeds and returns 20 messages in the stream. - -First, immediately after the server receives the call it will increment the -`grpc_server_started_total` and start the handling time clock (if histograms are enabled). - -```jsoniq -grpc_server_started_total{grpc_method="PingList",grpc_service="mwitkow.testproto.TestService",grpc_type="server_stream"} 1 -``` - -Then the user logic gets invoked. It receives one message from the client containing the request -(it's a `server_stream`): - -```jsoniq -grpc_server_msg_received_total{grpc_method="PingList",grpc_service="mwitkow.testproto.TestService",grpc_type="server_stream"} 1 -``` - -The user logic may return an error, or send multiple messages back to the client. In this case, on -each of the 20 messages sent back, a counter will be incremented: - -```jsoniq -grpc_server_msg_sent_total{grpc_method="PingList",grpc_service="mwitkow.testproto.TestService",grpc_type="server_stream"} 20 -``` - -After the call completes, its status (`OK` or other [gRPC status code](https://github.com/grpc/grpc-go/blob/master/codes/codes.go)) -and the relevant call labels increment the `grpc_server_handled_total` counter. - -```jsoniq -grpc_server_handled_total{grpc_code="OK",grpc_method="PingList",grpc_service="mwitkow.testproto.TestService",grpc_type="server_stream"} 1 -``` - -## Histograms - -[Prometheus histograms](https://prometheus.io/docs/concepts/metric_types/#histogram) are a great way -to measure latency distributions of your RPCs. However, since it is bad practice to have metrics -of [high cardinality](https://prometheus.io/docs/practices/instrumentation/#do-not-overuse-labels) -the latency monitoring metrics are disabled by default. To enable them please call the following -in your server initialization code: - -```jsoniq -grpc_prometheus.EnableHandlingTimeHistogram() -``` - -After the call completes, its handling time will be recorded in a [Prometheus histogram](https://prometheus.io/docs/concepts/metric_types/#histogram) -variable `grpc_server_handling_seconds`. The histogram variable contains three sub-metrics: - - * `grpc_server_handling_seconds_count` - the count of all completed RPCs by status and method - * `grpc_server_handling_seconds_sum` - cumulative time of RPCs by status and method, useful for - calculating average handling times - * `grpc_server_handling_seconds_bucket` - contains the counts of RPCs by status and method in respective - handling-time buckets. These buckets can be used by Prometheus to estimate SLAs (see [here](https://prometheus.io/docs/practices/histograms/)) - -The counter values will look as follows: - -```jsoniq -grpc_server_handling_seconds_bucket{grpc_code="OK",grpc_method="PingList",grpc_service="mwitkow.testproto.TestService",grpc_type="server_stream",le="0.005"} 1 -grpc_server_handling_seconds_bucket{grpc_code="OK",grpc_method="PingList",grpc_service="mwitkow.testproto.TestService",grpc_type="server_stream",le="0.01"} 1 -grpc_server_handling_seconds_bucket{grpc_code="OK",grpc_method="PingList",grpc_service="mwitkow.testproto.TestService",grpc_type="server_stream",le="0.025"} 1 -grpc_server_handling_seconds_bucket{grpc_code="OK",grpc_method="PingList",grpc_service="mwitkow.testproto.TestService",grpc_type="server_stream",le="0.05"} 1 -grpc_server_handling_seconds_bucket{grpc_code="OK",grpc_method="PingList",grpc_service="mwitkow.testproto.TestService",grpc_type="server_stream",le="0.1"} 1 -grpc_server_handling_seconds_bucket{grpc_code="OK",grpc_method="PingList",grpc_service="mwitkow.testproto.TestService",grpc_type="server_stream",le="0.25"} 1 -grpc_server_handling_seconds_bucket{grpc_code="OK",grpc_method="PingList",grpc_service="mwitkow.testproto.TestService",grpc_type="server_stream",le="0.5"} 1 -grpc_server_handling_seconds_bucket{grpc_code="OK",grpc_method="PingList",grpc_service="mwitkow.testproto.TestService",grpc_type="server_stream",le="1"} 1 -grpc_server_handling_seconds_bucket{grpc_code="OK",grpc_method="PingList",grpc_service="mwitkow.testproto.TestService",grpc_type="server_stream",le="2.5"} 1 -grpc_server_handling_seconds_bucket{grpc_code="OK",grpc_method="PingList",grpc_service="mwitkow.testproto.TestService",grpc_type="server_stream",le="5"} 1 -grpc_server_handling_seconds_bucket{grpc_code="OK",grpc_method="PingList",grpc_service="mwitkow.testproto.TestService",grpc_type="server_stream",le="10"} 1 -grpc_server_handling_seconds_bucket{grpc_code="OK",grpc_method="PingList",grpc_service="mwitkow.testproto.TestService",grpc_type="server_stream",le="+Inf"} 1 -grpc_server_handling_seconds_sum{grpc_code="OK",grpc_method="PingList",grpc_service="mwitkow.testproto.TestService",grpc_type="server_stream"} 0.0003866430000000001 -grpc_server_handling_seconds_count{grpc_code="OK",grpc_method="PingList",grpc_service="mwitkow.testproto.TestService",grpc_type="server_stream"} 1 -``` - - -## Useful query examples - -Prometheus philosophy is to provide raw metrics to the monitoring system, and -let the aggregations be handled there. The verbosity of above metrics make it possible to have that -flexibility. Here's a couple of useful monitoring queries: - - -### request inbound rate -```jsoniq -sum(rate(grpc_server_started_total{job="foo"}[1m])) by (grpc_service) -``` -For `job="foo"` (common label to differentiate between Prometheus monitoring targets), calculate the -rate of requests per second (1 minute window) for each gRPC `grpc_service` that the job has. Please note -how the `grpc_method` is being omitted here: all methods of a given gRPC service will be summed together. - -### unary request error rate -```jsoniq -sum(rate(grpc_server_handled_total{job="foo",grpc_type="unary",grpc_code!="OK"}[1m])) by (grpc_service) -``` -For `job="foo"`, calculate the per-`grpc_service` rate of `unary` (1:1) RPCs that failed, i.e. the -ones that didn't finish with `OK` code. - -### unary request error percentage -```jsoniq -sum(rate(grpc_server_handled_total{job="foo",grpc_type="unary",grpc_code!="OK"}[1m])) by (grpc_service) - / -sum(rate(grpc_server_started_total{job="foo",grpc_type="unary"}[1m])) by (grpc_service) - * 100.0 -``` -For `job="foo"`, calculate the percentage of failed requests by service. It's easy to notice that -this is a combination of the two above examples. This is an example of a query you would like to -[alert on](https://prometheus.io/docs/alerting/rules/) in your system for SLA violations, e.g. -"no more than 1% requests should fail". - -### average response stream size -```jsoniq -sum(rate(grpc_server_msg_sent_total{job="foo",grpc_type="server_stream"}[10m])) by (grpc_service) - / -sum(rate(grpc_server_started_total{job="foo",grpc_type="server_stream"}[10m])) by (grpc_service) -``` -For `job="foo"` what is the `grpc_service`-wide `10m` average of messages returned for all ` -server_stream` RPCs. This allows you to track the stream sizes returned by your system, e.g. allows -you to track when clients started to send "wide" queries that ret -Note the divisor is the number of started RPCs, in order to account for in-flight requests. - -### 99%-tile latency of unary requests -```jsoniq -histogram_quantile(0.99, - sum(rate(grpc_server_handling_seconds_bucket{job="foo",grpc_type="unary"}[5m])) by (grpc_service,le) -) -``` -For `job="foo"`, returns an 99%-tile [quantile estimation](https://prometheus.io/docs/practices/histograms/#quantiles) -of the handling time of RPCs per service. Please note the `5m` rate, this means that the quantile -estimation will take samples in a rolling `5m` window. When combined with other quantiles -(e.g. 50%, 90%), this query gives you tremendous insight into the responsiveness of your system -(e.g. impact of caching). - -### percentage of slow unary queries (>250ms) -```jsoniq -100.0 - ( -sum(rate(grpc_server_handling_seconds_bucket{job="foo",grpc_type="unary",le="0.25"}[5m])) by (grpc_service) - / -sum(rate(grpc_server_handling_seconds_count{job="foo",grpc_type="unary"}[5m])) by (grpc_service) -) * 100.0 -``` -For `job="foo"` calculate the by-`grpc_service` fraction of slow requests that took longer than `0.25` -seconds. This query is relatively complex, since the Prometheus aggregations use `le` (less or equal) -buckets, meaning that counting "fast" requests fractions is easier. However, simple maths helps. -This is an example of a query you would like to alert on in your system for SLA violations, -e.g. "less than 1% of requests are slower than 250ms". - - -## Status - -This code has been used since August 2015 as the basis for monitoring of *production* gRPC micro services at [Improbable](https://improbable.io). - -## License - -`go-grpc-prometheus` is released under the Apache 2.0 license. See the [LICENSE](LICENSE) file for details. diff --git a/vendor/github.com/grpc-ecosystem/go-grpc-prometheus/client.go b/vendor/github.com/grpc-ecosystem/go-grpc-prometheus/client.go deleted file mode 100644 index 751a4c72d7..0000000000 --- a/vendor/github.com/grpc-ecosystem/go-grpc-prometheus/client.go +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright 2016 Michal Witkowski. All Rights Reserved. -// See LICENSE for licensing terms. - -// gRPC Prometheus monitoring interceptors for client-side gRPC. - -package grpc_prometheus - -import ( - prom "github.com/prometheus/client_golang/prometheus" -) - -var ( - // DefaultClientMetrics is the default instance of ClientMetrics. It is - // intended to be used in conjunction the default Prometheus metrics - // registry. - DefaultClientMetrics = NewClientMetrics() - - // UnaryClientInterceptor is a gRPC client-side interceptor that provides Prometheus monitoring for Unary RPCs. - UnaryClientInterceptor = DefaultClientMetrics.UnaryClientInterceptor() - - // StreamClientInterceptor is a gRPC client-side interceptor that provides Prometheus monitoring for Streaming RPCs. - StreamClientInterceptor = DefaultClientMetrics.StreamClientInterceptor() -) - -func init() { - prom.MustRegister(DefaultClientMetrics.clientStartedCounter) - prom.MustRegister(DefaultClientMetrics.clientHandledCounter) - prom.MustRegister(DefaultClientMetrics.clientStreamMsgReceived) - prom.MustRegister(DefaultClientMetrics.clientStreamMsgSent) -} - -// EnableClientHandlingTimeHistogram turns on recording of handling time of -// RPCs. Histogram metrics can be very expensive for Prometheus to retain and -// query. This function acts on the DefaultClientMetrics variable and the -// default Prometheus metrics registry. -func EnableClientHandlingTimeHistogram(opts ...HistogramOption) { - DefaultClientMetrics.EnableClientHandlingTimeHistogram(opts...) - prom.Register(DefaultClientMetrics.clientHandledHistogram) -} diff --git a/vendor/github.com/grpc-ecosystem/go-grpc-prometheus/client_metrics.go b/vendor/github.com/grpc-ecosystem/go-grpc-prometheus/client_metrics.go deleted file mode 100644 index 9b476f9832..0000000000 --- a/vendor/github.com/grpc-ecosystem/go-grpc-prometheus/client_metrics.go +++ /dev/null @@ -1,170 +0,0 @@ -package grpc_prometheus - -import ( - "io" - - prom "github.com/prometheus/client_golang/prometheus" - "golang.org/x/net/context" - "google.golang.org/grpc" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/status" -) - -// ClientMetrics represents a collection of metrics to be registered on a -// Prometheus metrics registry for a gRPC client. -type ClientMetrics struct { - clientStartedCounter *prom.CounterVec - clientHandledCounter *prom.CounterVec - clientStreamMsgReceived *prom.CounterVec - clientStreamMsgSent *prom.CounterVec - clientHandledHistogramEnabled bool - clientHandledHistogramOpts prom.HistogramOpts - clientHandledHistogram *prom.HistogramVec -} - -// NewClientMetrics returns a ClientMetrics object. Use a new instance of -// ClientMetrics when not using the default Prometheus metrics registry, for -// example when wanting to control which metrics are added to a registry as -// opposed to automatically adding metrics via init functions. -func NewClientMetrics(counterOpts ...CounterOption) *ClientMetrics { - opts := counterOptions(counterOpts) - return &ClientMetrics{ - clientStartedCounter: prom.NewCounterVec( - opts.apply(prom.CounterOpts{ - Name: "grpc_client_started_total", - Help: "Total number of RPCs started on the client.", - }), []string{"grpc_type", "grpc_service", "grpc_method"}), - - clientHandledCounter: prom.NewCounterVec( - opts.apply(prom.CounterOpts{ - Name: "grpc_client_handled_total", - Help: "Total number of RPCs completed by the client, regardless of success or failure.", - }), []string{"grpc_type", "grpc_service", "grpc_method", "grpc_code"}), - - clientStreamMsgReceived: prom.NewCounterVec( - opts.apply(prom.CounterOpts{ - Name: "grpc_client_msg_received_total", - Help: "Total number of RPC stream messages received by the client.", - }), []string{"grpc_type", "grpc_service", "grpc_method"}), - - clientStreamMsgSent: prom.NewCounterVec( - opts.apply(prom.CounterOpts{ - Name: "grpc_client_msg_sent_total", - Help: "Total number of gRPC stream messages sent by the client.", - }), []string{"grpc_type", "grpc_service", "grpc_method"}), - - clientHandledHistogramEnabled: false, - clientHandledHistogramOpts: prom.HistogramOpts{ - Name: "grpc_client_handling_seconds", - Help: "Histogram of response latency (seconds) of the gRPC until it is finished by the application.", - Buckets: prom.DefBuckets, - }, - clientHandledHistogram: nil, - } -} - -// Describe sends the super-set of all possible descriptors of metrics -// collected by this Collector to the provided channel and returns once -// the last descriptor has been sent. -func (m *ClientMetrics) Describe(ch chan<- *prom.Desc) { - m.clientStartedCounter.Describe(ch) - m.clientHandledCounter.Describe(ch) - m.clientStreamMsgReceived.Describe(ch) - m.clientStreamMsgSent.Describe(ch) - if m.clientHandledHistogramEnabled { - m.clientHandledHistogram.Describe(ch) - } -} - -// Collect is called by the Prometheus registry when collecting -// metrics. The implementation sends each collected metric via the -// provided channel and returns once the last metric has been sent. -func (m *ClientMetrics) Collect(ch chan<- prom.Metric) { - m.clientStartedCounter.Collect(ch) - m.clientHandledCounter.Collect(ch) - m.clientStreamMsgReceived.Collect(ch) - m.clientStreamMsgSent.Collect(ch) - if m.clientHandledHistogramEnabled { - m.clientHandledHistogram.Collect(ch) - } -} - -// EnableClientHandlingTimeHistogram turns on recording of handling time of RPCs. -// Histogram metrics can be very expensive for Prometheus to retain and query. -func (m *ClientMetrics) EnableClientHandlingTimeHistogram(opts ...HistogramOption) { - for _, o := range opts { - o(&m.clientHandledHistogramOpts) - } - if !m.clientHandledHistogramEnabled { - m.clientHandledHistogram = prom.NewHistogramVec( - m.clientHandledHistogramOpts, - []string{"grpc_type", "grpc_service", "grpc_method"}, - ) - } - m.clientHandledHistogramEnabled = true -} - -// UnaryClientInterceptor is a gRPC client-side interceptor that provides Prometheus monitoring for Unary RPCs. -func (m *ClientMetrics) UnaryClientInterceptor() func(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error { - return func(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error { - monitor := newClientReporter(m, Unary, method) - monitor.SentMessage() - err := invoker(ctx, method, req, reply, cc, opts...) - if err != nil { - monitor.ReceivedMessage() - } - st, _ := status.FromError(err) - monitor.Handled(st.Code()) - return err - } -} - -// StreamClientInterceptor is a gRPC client-side interceptor that provides Prometheus monitoring for Streaming RPCs. -func (m *ClientMetrics) StreamClientInterceptor() func(ctx context.Context, desc *grpc.StreamDesc, cc *grpc.ClientConn, method string, streamer grpc.Streamer, opts ...grpc.CallOption) (grpc.ClientStream, error) { - return func(ctx context.Context, desc *grpc.StreamDesc, cc *grpc.ClientConn, method string, streamer grpc.Streamer, opts ...grpc.CallOption) (grpc.ClientStream, error) { - monitor := newClientReporter(m, clientStreamType(desc), method) - clientStream, err := streamer(ctx, desc, cc, method, opts...) - if err != nil { - st, _ := status.FromError(err) - monitor.Handled(st.Code()) - return nil, err - } - return &monitoredClientStream{clientStream, monitor}, nil - } -} - -func clientStreamType(desc *grpc.StreamDesc) grpcType { - if desc.ClientStreams && !desc.ServerStreams { - return ClientStream - } else if !desc.ClientStreams && desc.ServerStreams { - return ServerStream - } - return BidiStream -} - -// monitoredClientStream wraps grpc.ClientStream allowing each Sent/Recv of message to increment counters. -type monitoredClientStream struct { - grpc.ClientStream - monitor *clientReporter -} - -func (s *monitoredClientStream) SendMsg(m interface{}) error { - err := s.ClientStream.SendMsg(m) - if err == nil { - s.monitor.SentMessage() - } - return err -} - -func (s *monitoredClientStream) RecvMsg(m interface{}) error { - err := s.ClientStream.RecvMsg(m) - if err == nil { - s.monitor.ReceivedMessage() - } else if err == io.EOF { - s.monitor.Handled(codes.OK) - } else { - st, _ := status.FromError(err) - s.monitor.Handled(st.Code()) - } - return err -} diff --git a/vendor/github.com/grpc-ecosystem/go-grpc-prometheus/client_reporter.go b/vendor/github.com/grpc-ecosystem/go-grpc-prometheus/client_reporter.go deleted file mode 100644 index cbf1532299..0000000000 --- a/vendor/github.com/grpc-ecosystem/go-grpc-prometheus/client_reporter.go +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright 2016 Michal Witkowski. All Rights Reserved. -// See LICENSE for licensing terms. - -package grpc_prometheus - -import ( - "time" - - "google.golang.org/grpc/codes" -) - -type clientReporter struct { - metrics *ClientMetrics - rpcType grpcType - serviceName string - methodName string - startTime time.Time -} - -func newClientReporter(m *ClientMetrics, rpcType grpcType, fullMethod string) *clientReporter { - r := &clientReporter{ - metrics: m, - rpcType: rpcType, - } - if r.metrics.clientHandledHistogramEnabled { - r.startTime = time.Now() - } - r.serviceName, r.methodName = splitMethodName(fullMethod) - r.metrics.clientStartedCounter.WithLabelValues(string(r.rpcType), r.serviceName, r.methodName).Inc() - return r -} - -func (r *clientReporter) ReceivedMessage() { - r.metrics.clientStreamMsgReceived.WithLabelValues(string(r.rpcType), r.serviceName, r.methodName).Inc() -} - -func (r *clientReporter) SentMessage() { - r.metrics.clientStreamMsgSent.WithLabelValues(string(r.rpcType), r.serviceName, r.methodName).Inc() -} - -func (r *clientReporter) Handled(code codes.Code) { - r.metrics.clientHandledCounter.WithLabelValues(string(r.rpcType), r.serviceName, r.methodName, code.String()).Inc() - if r.metrics.clientHandledHistogramEnabled { - r.metrics.clientHandledHistogram.WithLabelValues(string(r.rpcType), r.serviceName, r.methodName).Observe(time.Since(r.startTime).Seconds()) - } -} diff --git a/vendor/github.com/grpc-ecosystem/go-grpc-prometheus/makefile b/vendor/github.com/grpc-ecosystem/go-grpc-prometheus/makefile deleted file mode 100644 index 74c0842230..0000000000 --- a/vendor/github.com/grpc-ecosystem/go-grpc-prometheus/makefile +++ /dev/null @@ -1,16 +0,0 @@ -SHELL="/bin/bash" - -GOFILES_NOVENDOR = $(shell go list ./... | grep -v /vendor/) - -all: vet fmt test - -fmt: - go fmt $(GOFILES_NOVENDOR) - -vet: - go vet $(GOFILES_NOVENDOR) - -test: vet - ./scripts/test_all.sh - -.PHONY: all vet test diff --git a/vendor/github.com/grpc-ecosystem/go-grpc-prometheus/metric_options.go b/vendor/github.com/grpc-ecosystem/go-grpc-prometheus/metric_options.go deleted file mode 100644 index 9d51aec981..0000000000 --- a/vendor/github.com/grpc-ecosystem/go-grpc-prometheus/metric_options.go +++ /dev/null @@ -1,41 +0,0 @@ -package grpc_prometheus - -import ( - prom "github.com/prometheus/client_golang/prometheus" -) - -// A CounterOption lets you add options to Counter metrics using With* funcs. -type CounterOption func(*prom.CounterOpts) - -type counterOptions []CounterOption - -func (co counterOptions) apply(o prom.CounterOpts) prom.CounterOpts { - for _, f := range co { - f(&o) - } - return o -} - -// WithConstLabels allows you to add ConstLabels to Counter metrics. -func WithConstLabels(labels prom.Labels) CounterOption { - return func(o *prom.CounterOpts) { - o.ConstLabels = labels - } -} - -// A HistogramOption lets you add options to Histogram metrics using With* -// funcs. -type HistogramOption func(*prom.HistogramOpts) - -// WithHistogramBuckets allows you to specify custom bucket ranges for histograms if EnableHandlingTimeHistogram is on. -func WithHistogramBuckets(buckets []float64) HistogramOption { - return func(o *prom.HistogramOpts) { o.Buckets = buckets } -} - -// WithHistogramConstLabels allows you to add custom ConstLabels to -// histograms metrics. -func WithHistogramConstLabels(labels prom.Labels) HistogramOption { - return func(o *prom.HistogramOpts) { - o.ConstLabels = labels - } -} diff --git a/vendor/github.com/grpc-ecosystem/go-grpc-prometheus/server.go b/vendor/github.com/grpc-ecosystem/go-grpc-prometheus/server.go deleted file mode 100644 index 322f99046f..0000000000 --- a/vendor/github.com/grpc-ecosystem/go-grpc-prometheus/server.go +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright 2016 Michal Witkowski. All Rights Reserved. -// See LICENSE for licensing terms. - -// gRPC Prometheus monitoring interceptors for server-side gRPC. - -package grpc_prometheus - -import ( - prom "github.com/prometheus/client_golang/prometheus" - "google.golang.org/grpc" -) - -var ( - // DefaultServerMetrics is the default instance of ServerMetrics. It is - // intended to be used in conjunction the default Prometheus metrics - // registry. - DefaultServerMetrics = NewServerMetrics() - - // UnaryServerInterceptor is a gRPC server-side interceptor that provides Prometheus monitoring for Unary RPCs. - UnaryServerInterceptor = DefaultServerMetrics.UnaryServerInterceptor() - - // StreamServerInterceptor is a gRPC server-side interceptor that provides Prometheus monitoring for Streaming RPCs. - StreamServerInterceptor = DefaultServerMetrics.StreamServerInterceptor() -) - -func init() { - prom.MustRegister(DefaultServerMetrics.serverStartedCounter) - prom.MustRegister(DefaultServerMetrics.serverHandledCounter) - prom.MustRegister(DefaultServerMetrics.serverStreamMsgReceived) - prom.MustRegister(DefaultServerMetrics.serverStreamMsgSent) -} - -// Register takes a gRPC server and pre-initializes all counters to 0. This -// allows for easier monitoring in Prometheus (no missing metrics), and should -// be called *after* all services have been registered with the server. This -// function acts on the DefaultServerMetrics variable. -func Register(server *grpc.Server) { - DefaultServerMetrics.InitializeMetrics(server) -} - -// EnableHandlingTimeHistogram turns on recording of handling time -// of RPCs. Histogram metrics can be very expensive for Prometheus -// to retain and query. This function acts on the DefaultServerMetrics -// variable and the default Prometheus metrics registry. -func EnableHandlingTimeHistogram(opts ...HistogramOption) { - DefaultServerMetrics.EnableHandlingTimeHistogram(opts...) - prom.Register(DefaultServerMetrics.serverHandledHistogram) -} diff --git a/vendor/github.com/grpc-ecosystem/go-grpc-prometheus/server_metrics.go b/vendor/github.com/grpc-ecosystem/go-grpc-prometheus/server_metrics.go deleted file mode 100644 index 5b1467e7aa..0000000000 --- a/vendor/github.com/grpc-ecosystem/go-grpc-prometheus/server_metrics.go +++ /dev/null @@ -1,185 +0,0 @@ -package grpc_prometheus - -import ( - prom "github.com/prometheus/client_golang/prometheus" - "golang.org/x/net/context" - "google.golang.org/grpc" - "google.golang.org/grpc/status" -) - -// ServerMetrics represents a collection of metrics to be registered on a -// Prometheus metrics registry for a gRPC server. -type ServerMetrics struct { - serverStartedCounter *prom.CounterVec - serverHandledCounter *prom.CounterVec - serverStreamMsgReceived *prom.CounterVec - serverStreamMsgSent *prom.CounterVec - serverHandledHistogramEnabled bool - serverHandledHistogramOpts prom.HistogramOpts - serverHandledHistogram *prom.HistogramVec -} - -// NewServerMetrics returns a ServerMetrics object. Use a new instance of -// ServerMetrics when not using the default Prometheus metrics registry, for -// example when wanting to control which metrics are added to a registry as -// opposed to automatically adding metrics via init functions. -func NewServerMetrics(counterOpts ...CounterOption) *ServerMetrics { - opts := counterOptions(counterOpts) - return &ServerMetrics{ - serverStartedCounter: prom.NewCounterVec( - opts.apply(prom.CounterOpts{ - Name: "grpc_server_started_total", - Help: "Total number of RPCs started on the server.", - }), []string{"grpc_type", "grpc_service", "grpc_method"}), - serverHandledCounter: prom.NewCounterVec( - opts.apply(prom.CounterOpts{ - Name: "grpc_server_handled_total", - Help: "Total number of RPCs completed on the server, regardless of success or failure.", - }), []string{"grpc_type", "grpc_service", "grpc_method", "grpc_code"}), - serverStreamMsgReceived: prom.NewCounterVec( - opts.apply(prom.CounterOpts{ - Name: "grpc_server_msg_received_total", - Help: "Total number of RPC stream messages received on the server.", - }), []string{"grpc_type", "grpc_service", "grpc_method"}), - serverStreamMsgSent: prom.NewCounterVec( - opts.apply(prom.CounterOpts{ - Name: "grpc_server_msg_sent_total", - Help: "Total number of gRPC stream messages sent by the server.", - }), []string{"grpc_type", "grpc_service", "grpc_method"}), - serverHandledHistogramEnabled: false, - serverHandledHistogramOpts: prom.HistogramOpts{ - Name: "grpc_server_handling_seconds", - Help: "Histogram of response latency (seconds) of gRPC that had been application-level handled by the server.", - Buckets: prom.DefBuckets, - }, - serverHandledHistogram: nil, - } -} - -// EnableHandlingTimeHistogram enables histograms being registered when -// registering the ServerMetrics on a Prometheus registry. Histograms can be -// expensive on Prometheus servers. It takes options to configure histogram -// options such as the defined buckets. -func (m *ServerMetrics) EnableHandlingTimeHistogram(opts ...HistogramOption) { - for _, o := range opts { - o(&m.serverHandledHistogramOpts) - } - if !m.serverHandledHistogramEnabled { - m.serverHandledHistogram = prom.NewHistogramVec( - m.serverHandledHistogramOpts, - []string{"grpc_type", "grpc_service", "grpc_method"}, - ) - } - m.serverHandledHistogramEnabled = true -} - -// Describe sends the super-set of all possible descriptors of metrics -// collected by this Collector to the provided channel and returns once -// the last descriptor has been sent. -func (m *ServerMetrics) Describe(ch chan<- *prom.Desc) { - m.serverStartedCounter.Describe(ch) - m.serverHandledCounter.Describe(ch) - m.serverStreamMsgReceived.Describe(ch) - m.serverStreamMsgSent.Describe(ch) - if m.serverHandledHistogramEnabled { - m.serverHandledHistogram.Describe(ch) - } -} - -// Collect is called by the Prometheus registry when collecting -// metrics. The implementation sends each collected metric via the -// provided channel and returns once the last metric has been sent. -func (m *ServerMetrics) Collect(ch chan<- prom.Metric) { - m.serverStartedCounter.Collect(ch) - m.serverHandledCounter.Collect(ch) - m.serverStreamMsgReceived.Collect(ch) - m.serverStreamMsgSent.Collect(ch) - if m.serverHandledHistogramEnabled { - m.serverHandledHistogram.Collect(ch) - } -} - -// UnaryServerInterceptor is a gRPC server-side interceptor that provides Prometheus monitoring for Unary RPCs. -func (m *ServerMetrics) UnaryServerInterceptor() func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) { - return func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) { - monitor := newServerReporter(m, Unary, info.FullMethod) - monitor.ReceivedMessage() - resp, err := handler(ctx, req) - st, _ := status.FromError(err) - monitor.Handled(st.Code()) - if err == nil { - monitor.SentMessage() - } - return resp, err - } -} - -// StreamServerInterceptor is a gRPC server-side interceptor that provides Prometheus monitoring for Streaming RPCs. -func (m *ServerMetrics) StreamServerInterceptor() func(srv interface{}, ss grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) error { - return func(srv interface{}, ss grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) error { - monitor := newServerReporter(m, streamRPCType(info), info.FullMethod) - err := handler(srv, &monitoredServerStream{ss, monitor}) - st, _ := status.FromError(err) - monitor.Handled(st.Code()) - return err - } -} - -// InitializeMetrics initializes all metrics, with their appropriate null -// value, for all gRPC methods registered on a gRPC server. This is useful, to -// ensure that all metrics exist when collecting and querying. -func (m *ServerMetrics) InitializeMetrics(server *grpc.Server) { - serviceInfo := server.GetServiceInfo() - for serviceName, info := range serviceInfo { - for _, mInfo := range info.Methods { - preRegisterMethod(m, serviceName, &mInfo) - } - } -} - -func streamRPCType(info *grpc.StreamServerInfo) grpcType { - if info.IsClientStream && !info.IsServerStream { - return ClientStream - } else if !info.IsClientStream && info.IsServerStream { - return ServerStream - } - return BidiStream -} - -// monitoredStream wraps grpc.ServerStream allowing each Sent/Recv of message to increment counters. -type monitoredServerStream struct { - grpc.ServerStream - monitor *serverReporter -} - -func (s *monitoredServerStream) SendMsg(m interface{}) error { - err := s.ServerStream.SendMsg(m) - if err == nil { - s.monitor.SentMessage() - } - return err -} - -func (s *monitoredServerStream) RecvMsg(m interface{}) error { - err := s.ServerStream.RecvMsg(m) - if err == nil { - s.monitor.ReceivedMessage() - } - return err -} - -// preRegisterMethod is invoked on Register of a Server, allowing all gRPC services labels to be pre-populated. -func preRegisterMethod(metrics *ServerMetrics, serviceName string, mInfo *grpc.MethodInfo) { - methodName := mInfo.Name - methodType := string(typeFromMethodInfo(mInfo)) - // These are just references (no increments), as just referencing will create the labels but not set values. - metrics.serverStartedCounter.GetMetricWithLabelValues(methodType, serviceName, methodName) - metrics.serverStreamMsgReceived.GetMetricWithLabelValues(methodType, serviceName, methodName) - metrics.serverStreamMsgSent.GetMetricWithLabelValues(methodType, serviceName, methodName) - if metrics.serverHandledHistogramEnabled { - metrics.serverHandledHistogram.GetMetricWithLabelValues(methodType, serviceName, methodName) - } - for _, code := range allCodes { - metrics.serverHandledCounter.GetMetricWithLabelValues(methodType, serviceName, methodName, code.String()) - } -} diff --git a/vendor/github.com/grpc-ecosystem/go-grpc-prometheus/server_reporter.go b/vendor/github.com/grpc-ecosystem/go-grpc-prometheus/server_reporter.go deleted file mode 100644 index aa9db5401a..0000000000 --- a/vendor/github.com/grpc-ecosystem/go-grpc-prometheus/server_reporter.go +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright 2016 Michal Witkowski. All Rights Reserved. -// See LICENSE for licensing terms. - -package grpc_prometheus - -import ( - "time" - - "google.golang.org/grpc/codes" -) - -type serverReporter struct { - metrics *ServerMetrics - rpcType grpcType - serviceName string - methodName string - startTime time.Time -} - -func newServerReporter(m *ServerMetrics, rpcType grpcType, fullMethod string) *serverReporter { - r := &serverReporter{ - metrics: m, - rpcType: rpcType, - } - if r.metrics.serverHandledHistogramEnabled { - r.startTime = time.Now() - } - r.serviceName, r.methodName = splitMethodName(fullMethod) - r.metrics.serverStartedCounter.WithLabelValues(string(r.rpcType), r.serviceName, r.methodName).Inc() - return r -} - -func (r *serverReporter) ReceivedMessage() { - r.metrics.serverStreamMsgReceived.WithLabelValues(string(r.rpcType), r.serviceName, r.methodName).Inc() -} - -func (r *serverReporter) SentMessage() { - r.metrics.serverStreamMsgSent.WithLabelValues(string(r.rpcType), r.serviceName, r.methodName).Inc() -} - -func (r *serverReporter) Handled(code codes.Code) { - r.metrics.serverHandledCounter.WithLabelValues(string(r.rpcType), r.serviceName, r.methodName, code.String()).Inc() - if r.metrics.serverHandledHistogramEnabled { - r.metrics.serverHandledHistogram.WithLabelValues(string(r.rpcType), r.serviceName, r.methodName).Observe(time.Since(r.startTime).Seconds()) - } -} diff --git a/vendor/github.com/grpc-ecosystem/go-grpc-prometheus/util.go b/vendor/github.com/grpc-ecosystem/go-grpc-prometheus/util.go deleted file mode 100644 index 7987de35f4..0000000000 --- a/vendor/github.com/grpc-ecosystem/go-grpc-prometheus/util.go +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright 2016 Michal Witkowski. All Rights Reserved. -// See LICENSE for licensing terms. - -package grpc_prometheus - -import ( - "strings" - - "google.golang.org/grpc" - "google.golang.org/grpc/codes" -) - -type grpcType string - -const ( - Unary grpcType = "unary" - ClientStream grpcType = "client_stream" - ServerStream grpcType = "server_stream" - BidiStream grpcType = "bidi_stream" -) - -var ( - allCodes = []codes.Code{ - codes.OK, codes.Canceled, codes.Unknown, codes.InvalidArgument, codes.DeadlineExceeded, codes.NotFound, - codes.AlreadyExists, codes.PermissionDenied, codes.Unauthenticated, codes.ResourceExhausted, - codes.FailedPrecondition, codes.Aborted, codes.OutOfRange, codes.Unimplemented, codes.Internal, - codes.Unavailable, codes.DataLoss, - } -) - -func splitMethodName(fullMethodName string) (string, string) { - fullMethodName = strings.TrimPrefix(fullMethodName, "/") // remove leading slash - if i := strings.Index(fullMethodName, "/"); i >= 0 { - return fullMethodName[:i], fullMethodName[i+1:] - } - return "unknown", "unknown" -} - -func typeFromMethodInfo(mInfo *grpc.MethodInfo) grpcType { - if !mInfo.IsClientStream && !mInfo.IsServerStream { - return Unary - } - if mInfo.IsClientStream && !mInfo.IsServerStream { - return ClientStream - } - if !mInfo.IsClientStream && mInfo.IsServerStream { - return ServerStream - } - return BidiStream -} diff --git a/vendor/github.com/grpc-ecosystem/grpc-gateway/LICENSE.txt b/vendor/github.com/grpc-ecosystem/grpc-gateway/LICENSE.txt deleted file mode 100644 index 364516251b..0000000000 --- a/vendor/github.com/grpc-ecosystem/grpc-gateway/LICENSE.txt +++ /dev/null @@ -1,27 +0,0 @@ -Copyright (c) 2015, Gengo, Inc. -All rights reserved. - -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - * Neither the name of Gengo, Inc. nor the names of its - contributors may be used to endorse or promote products derived from this - software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR -ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/vendor/github.com/grpc-ecosystem/grpc-gateway/internal/BUILD.bazel b/vendor/github.com/grpc-ecosystem/grpc-gateway/internal/BUILD.bazel deleted file mode 100644 index 5242751fb2..0000000000 --- a/vendor/github.com/grpc-ecosystem/grpc-gateway/internal/BUILD.bazel +++ /dev/null @@ -1,23 +0,0 @@ -load("@rules_proto//proto:defs.bzl", "proto_library") -load("@io_bazel_rules_go//go:def.bzl", "go_library") -load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library") - -package(default_visibility = ["//visibility:public"]) - -proto_library( - name = "internal_proto", - srcs = ["errors.proto"], - deps = ["@com_google_protobuf//:any_proto"], -) - -go_proto_library( - name = "internal_go_proto", - importpath = "github.com/grpc-ecosystem/grpc-gateway/internal", - proto = ":internal_proto", -) - -go_library( - name = "go_default_library", - embed = [":internal_go_proto"], - importpath = "github.com/grpc-ecosystem/grpc-gateway/internal", -) diff --git a/vendor/github.com/grpc-ecosystem/grpc-gateway/internal/errors.pb.go b/vendor/github.com/grpc-ecosystem/grpc-gateway/internal/errors.pb.go deleted file mode 100644 index 61101d7177..0000000000 --- a/vendor/github.com/grpc-ecosystem/grpc-gateway/internal/errors.pb.go +++ /dev/null @@ -1,189 +0,0 @@ -// Code generated by protoc-gen-go. DO NOT EDIT. -// source: internal/errors.proto - -package internal - -import ( - fmt "fmt" - proto "github.com/golang/protobuf/proto" - any "github.com/golang/protobuf/ptypes/any" - math "math" -) - -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package - -// Error is the generic error returned from unary RPCs. -type Error struct { - Error string `protobuf:"bytes,1,opt,name=error,proto3" json:"error,omitempty"` - // This is to make the error more compatible with users that expect errors to be Status objects: - // https://github.com/grpc/grpc/blob/master/src/proto/grpc/status/status.proto - // It should be the exact same message as the Error field. - Code int32 `protobuf:"varint,2,opt,name=code,proto3" json:"code,omitempty"` - Message string `protobuf:"bytes,3,opt,name=message,proto3" json:"message,omitempty"` - Details []*any.Any `protobuf:"bytes,4,rep,name=details,proto3" json:"details,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *Error) Reset() { *m = Error{} } -func (m *Error) String() string { return proto.CompactTextString(m) } -func (*Error) ProtoMessage() {} -func (*Error) Descriptor() ([]byte, []int) { - return fileDescriptor_9b093362ca6d1e03, []int{0} -} - -func (m *Error) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_Error.Unmarshal(m, b) -} -func (m *Error) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_Error.Marshal(b, m, deterministic) -} -func (m *Error) XXX_Merge(src proto.Message) { - xxx_messageInfo_Error.Merge(m, src) -} -func (m *Error) XXX_Size() int { - return xxx_messageInfo_Error.Size(m) -} -func (m *Error) XXX_DiscardUnknown() { - xxx_messageInfo_Error.DiscardUnknown(m) -} - -var xxx_messageInfo_Error proto.InternalMessageInfo - -func (m *Error) GetError() string { - if m != nil { - return m.Error - } - return "" -} - -func (m *Error) GetCode() int32 { - if m != nil { - return m.Code - } - return 0 -} - -func (m *Error) GetMessage() string { - if m != nil { - return m.Message - } - return "" -} - -func (m *Error) GetDetails() []*any.Any { - if m != nil { - return m.Details - } - return nil -} - -// StreamError is a response type which is returned when -// streaming rpc returns an error. -type StreamError struct { - GrpcCode int32 `protobuf:"varint,1,opt,name=grpc_code,json=grpcCode,proto3" json:"grpc_code,omitempty"` - HttpCode int32 `protobuf:"varint,2,opt,name=http_code,json=httpCode,proto3" json:"http_code,omitempty"` - Message string `protobuf:"bytes,3,opt,name=message,proto3" json:"message,omitempty"` - HttpStatus string `protobuf:"bytes,4,opt,name=http_status,json=httpStatus,proto3" json:"http_status,omitempty"` - Details []*any.Any `protobuf:"bytes,5,rep,name=details,proto3" json:"details,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *StreamError) Reset() { *m = StreamError{} } -func (m *StreamError) String() string { return proto.CompactTextString(m) } -func (*StreamError) ProtoMessage() {} -func (*StreamError) Descriptor() ([]byte, []int) { - return fileDescriptor_9b093362ca6d1e03, []int{1} -} - -func (m *StreamError) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_StreamError.Unmarshal(m, b) -} -func (m *StreamError) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_StreamError.Marshal(b, m, deterministic) -} -func (m *StreamError) XXX_Merge(src proto.Message) { - xxx_messageInfo_StreamError.Merge(m, src) -} -func (m *StreamError) XXX_Size() int { - return xxx_messageInfo_StreamError.Size(m) -} -func (m *StreamError) XXX_DiscardUnknown() { - xxx_messageInfo_StreamError.DiscardUnknown(m) -} - -var xxx_messageInfo_StreamError proto.InternalMessageInfo - -func (m *StreamError) GetGrpcCode() int32 { - if m != nil { - return m.GrpcCode - } - return 0 -} - -func (m *StreamError) GetHttpCode() int32 { - if m != nil { - return m.HttpCode - } - return 0 -} - -func (m *StreamError) GetMessage() string { - if m != nil { - return m.Message - } - return "" -} - -func (m *StreamError) GetHttpStatus() string { - if m != nil { - return m.HttpStatus - } - return "" -} - -func (m *StreamError) GetDetails() []*any.Any { - if m != nil { - return m.Details - } - return nil -} - -func init() { - proto.RegisterType((*Error)(nil), "grpc.gateway.runtime.Error") - proto.RegisterType((*StreamError)(nil), "grpc.gateway.runtime.StreamError") -} - -func init() { proto.RegisterFile("internal/errors.proto", fileDescriptor_9b093362ca6d1e03) } - -var fileDescriptor_9b093362ca6d1e03 = []byte{ - // 252 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x90, 0xc1, 0x4a, 0xc4, 0x30, - 0x10, 0x86, 0x89, 0xbb, 0x75, 0xdb, 0xe9, 0x2d, 0x54, 0x88, 0xee, 0xc1, 0xb2, 0xa7, 0x9e, 0x52, - 0xd0, 0x27, 0xd0, 0xc5, 0x17, 0xe8, 0xde, 0xbc, 0x2c, 0xd9, 0xdd, 0x31, 0x16, 0xda, 0xa4, 0x24, - 0x53, 0xa4, 0xf8, 0x56, 0x3e, 0xa1, 0x24, 0xa5, 0xb0, 0x27, 0xf1, 0xd6, 0xf9, 0xfb, 0xcf, 0x7c, - 0x1f, 0x81, 0xbb, 0xd6, 0x10, 0x3a, 0xa3, 0xba, 0x1a, 0x9d, 0xb3, 0xce, 0xcb, 0xc1, 0x59, 0xb2, - 0xbc, 0xd0, 0x6e, 0x38, 0x4b, 0xad, 0x08, 0xbf, 0xd4, 0x24, 0xdd, 0x68, 0xa8, 0xed, 0xf1, 0xe1, - 0x5e, 0x5b, 0xab, 0x3b, 0xac, 0x63, 0xe7, 0x34, 0x7e, 0xd4, 0xca, 0x4c, 0xf3, 0xc2, 0xee, 0x1b, - 0x92, 0xb7, 0x70, 0x80, 0x17, 0x90, 0xc4, 0x4b, 0x82, 0x95, 0xac, 0xca, 0x9a, 0x79, 0xe0, 0x1c, - 0xd6, 0x67, 0x7b, 0x41, 0x71, 0x53, 0xb2, 0x2a, 0x69, 0xe2, 0x37, 0x17, 0xb0, 0xe9, 0xd1, 0x7b, - 0xa5, 0x51, 0xac, 0x62, 0x77, 0x19, 0xb9, 0x84, 0xcd, 0x05, 0x49, 0xb5, 0x9d, 0x17, 0xeb, 0x72, - 0x55, 0xe5, 0x4f, 0x85, 0x9c, 0xc9, 0x72, 0x21, 0xcb, 0x17, 0x33, 0x35, 0x4b, 0x69, 0xf7, 0xc3, - 0x20, 0x3f, 0x90, 0x43, 0xd5, 0xcf, 0x0e, 0x5b, 0xc8, 0x82, 0xff, 0x31, 0x22, 0x59, 0x44, 0xa6, - 0x21, 0xd8, 0x07, 0xec, 0x16, 0xb2, 0x4f, 0xa2, 0xe1, 0x78, 0xe5, 0x93, 0x86, 0x60, 0xff, 0xb7, - 0xd3, 0x23, 0xe4, 0x71, 0xcd, 0x93, 0xa2, 0x31, 0x78, 0x85, 0xbf, 0x10, 0xa2, 0x43, 0x4c, 0xae, - 0xa5, 0x93, 0x7f, 0x48, 0xbf, 0xc2, 0x7b, 0xba, 0xbc, 0xfd, 0xe9, 0x36, 0x56, 0x9e, 0x7f, 0x03, - 0x00, 0x00, 0xff, 0xff, 0xde, 0x72, 0x6b, 0x83, 0x8e, 0x01, 0x00, 0x00, -} diff --git a/vendor/github.com/grpc-ecosystem/grpc-gateway/internal/errors.proto b/vendor/github.com/grpc-ecosystem/grpc-gateway/internal/errors.proto deleted file mode 100644 index 4fb212c6b6..0000000000 --- a/vendor/github.com/grpc-ecosystem/grpc-gateway/internal/errors.proto +++ /dev/null @@ -1,26 +0,0 @@ -syntax = "proto3"; -package grpc.gateway.runtime; -option go_package = "internal"; - -import "google/protobuf/any.proto"; - -// Error is the generic error returned from unary RPCs. -message Error { - string error = 1; - // This is to make the error more compatible with users that expect errors to be Status objects: - // https://github.com/grpc/grpc/blob/master/src/proto/grpc/status/status.proto - // It should be the exact same message as the Error field. - int32 code = 2; - string message = 3; - repeated google.protobuf.Any details = 4; -} - -// StreamError is a response type which is returned when -// streaming rpc returns an error. -message StreamError { - int32 grpc_code = 1; - int32 http_code = 2; - string message = 3; - string http_status = 4; - repeated google.protobuf.Any details = 5; -} diff --git a/vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/BUILD.bazel b/vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/BUILD.bazel deleted file mode 100644 index 58b72b9cf7..0000000000 --- a/vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/BUILD.bazel +++ /dev/null @@ -1,85 +0,0 @@ -load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") - -package(default_visibility = ["//visibility:public"]) - -go_library( - name = "go_default_library", - srcs = [ - "context.go", - "convert.go", - "doc.go", - "errors.go", - "fieldmask.go", - "handler.go", - "marshal_httpbodyproto.go", - "marshal_json.go", - "marshal_jsonpb.go", - "marshal_proto.go", - "marshaler.go", - "marshaler_registry.go", - "mux.go", - "pattern.go", - "proto2_convert.go", - "proto_errors.go", - "query.go", - ], - importpath = "github.com/grpc-ecosystem/grpc-gateway/runtime", - deps = [ - "//internal:go_default_library", - "//utilities:go_default_library", - "@com_github_golang_protobuf//descriptor:go_default_library_gen", - "@com_github_golang_protobuf//jsonpb:go_default_library_gen", - "@com_github_golang_protobuf//proto:go_default_library", - "@go_googleapis//google/api:httpbody_go_proto", - "@io_bazel_rules_go//proto/wkt:any_go_proto", - "@io_bazel_rules_go//proto/wkt:descriptor_go_proto", - "@io_bazel_rules_go//proto/wkt:duration_go_proto", - "@io_bazel_rules_go//proto/wkt:field_mask_go_proto", - "@io_bazel_rules_go//proto/wkt:timestamp_go_proto", - "@io_bazel_rules_go//proto/wkt:wrappers_go_proto", - "@org_golang_google_grpc//codes:go_default_library", - "@org_golang_google_grpc//grpclog:go_default_library", - "@org_golang_google_grpc//metadata:go_default_library", - "@org_golang_google_grpc//status:go_default_library", - ], -) - -go_test( - name = "go_default_test", - size = "small", - srcs = [ - "context_test.go", - "convert_test.go", - "errors_test.go", - "fieldmask_test.go", - "handler_test.go", - "marshal_httpbodyproto_test.go", - "marshal_json_test.go", - "marshal_jsonpb_test.go", - "marshal_proto_test.go", - "marshaler_registry_test.go", - "mux_test.go", - "pattern_test.go", - "query_test.go", - ], - embed = [":go_default_library"], - deps = [ - "//internal:go_default_library", - "//runtime/internal/examplepb:go_default_library", - "//utilities:go_default_library", - "@com_github_golang_protobuf//jsonpb:go_default_library_gen", - "@com_github_golang_protobuf//proto:go_default_library", - "@com_github_golang_protobuf//ptypes:go_default_library_gen", - "@go_googleapis//google/api:httpbody_go_proto", - "@go_googleapis//google/rpc:errdetails_go_proto", - "@io_bazel_rules_go//proto/wkt:duration_go_proto", - "@io_bazel_rules_go//proto/wkt:empty_go_proto", - "@io_bazel_rules_go//proto/wkt:field_mask_go_proto", - "@io_bazel_rules_go//proto/wkt:struct_go_proto", - "@io_bazel_rules_go//proto/wkt:timestamp_go_proto", - "@io_bazel_rules_go//proto/wkt:wrappers_go_proto", - "@org_golang_google_grpc//codes:go_default_library", - "@org_golang_google_grpc//metadata:go_default_library", - "@org_golang_google_grpc//status:go_default_library", - ], -) diff --git a/vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/context.go b/vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/context.go deleted file mode 100644 index d8cbd4cc96..0000000000 --- a/vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/context.go +++ /dev/null @@ -1,291 +0,0 @@ -package runtime - -import ( - "context" - "encoding/base64" - "fmt" - "net" - "net/http" - "net/textproto" - "strconv" - "strings" - "sync" - "time" - - "google.golang.org/grpc/codes" - "google.golang.org/grpc/metadata" - "google.golang.org/grpc/status" -) - -// MetadataHeaderPrefix is the http prefix that represents custom metadata -// parameters to or from a gRPC call. -const MetadataHeaderPrefix = "Grpc-Metadata-" - -// MetadataPrefix is prepended to permanent HTTP header keys (as specified -// by the IANA) when added to the gRPC context. -const MetadataPrefix = "grpcgateway-" - -// MetadataTrailerPrefix is prepended to gRPC metadata as it is converted to -// HTTP headers in a response handled by grpc-gateway -const MetadataTrailerPrefix = "Grpc-Trailer-" - -const metadataGrpcTimeout = "Grpc-Timeout" -const metadataHeaderBinarySuffix = "-Bin" - -const xForwardedFor = "X-Forwarded-For" -const xForwardedHost = "X-Forwarded-Host" - -var ( - // DefaultContextTimeout is used for gRPC call context.WithTimeout whenever a Grpc-Timeout inbound - // header isn't present. If the value is 0 the sent `context` will not have a timeout. - DefaultContextTimeout = 0 * time.Second -) - -func decodeBinHeader(v string) ([]byte, error) { - if len(v)%4 == 0 { - // Input was padded, or padding was not necessary. - return base64.StdEncoding.DecodeString(v) - } - return base64.RawStdEncoding.DecodeString(v) -} - -/* -AnnotateContext adds context information such as metadata from the request. - -At a minimum, the RemoteAddr is included in the fashion of "X-Forwarded-For", -except that the forwarded destination is not another HTTP service but rather -a gRPC service. -*/ -func AnnotateContext(ctx context.Context, mux *ServeMux, req *http.Request) (context.Context, error) { - ctx, md, err := annotateContext(ctx, mux, req) - if err != nil { - return nil, err - } - if md == nil { - return ctx, nil - } - - return metadata.NewOutgoingContext(ctx, md), nil -} - -// AnnotateIncomingContext adds context information such as metadata from the request. -// Attach metadata as incoming context. -func AnnotateIncomingContext(ctx context.Context, mux *ServeMux, req *http.Request) (context.Context, error) { - ctx, md, err := annotateContext(ctx, mux, req) - if err != nil { - return nil, err - } - if md == nil { - return ctx, nil - } - - return metadata.NewIncomingContext(ctx, md), nil -} - -func annotateContext(ctx context.Context, mux *ServeMux, req *http.Request) (context.Context, metadata.MD, error) { - var pairs []string - timeout := DefaultContextTimeout - if tm := req.Header.Get(metadataGrpcTimeout); tm != "" { - var err error - timeout, err = timeoutDecode(tm) - if err != nil { - return nil, nil, status.Errorf(codes.InvalidArgument, "invalid grpc-timeout: %s", tm) - } - } - - for key, vals := range req.Header { - key = textproto.CanonicalMIMEHeaderKey(key) - for _, val := range vals { - // For backwards-compatibility, pass through 'authorization' header with no prefix. - if key == "Authorization" { - pairs = append(pairs, "authorization", val) - } - if h, ok := mux.incomingHeaderMatcher(key); ok { - // Handles "-bin" metadata in grpc, since grpc will do another base64 - // encode before sending to server, we need to decode it first. - if strings.HasSuffix(key, metadataHeaderBinarySuffix) { - b, err := decodeBinHeader(val) - if err != nil { - return nil, nil, status.Errorf(codes.InvalidArgument, "invalid binary header %s: %s", key, err) - } - - val = string(b) - } - pairs = append(pairs, h, val) - } - } - } - if host := req.Header.Get(xForwardedHost); host != "" { - pairs = append(pairs, strings.ToLower(xForwardedHost), host) - } else if req.Host != "" { - pairs = append(pairs, strings.ToLower(xForwardedHost), req.Host) - } - - if addr := req.RemoteAddr; addr != "" { - if remoteIP, _, err := net.SplitHostPort(addr); err == nil { - if fwd := req.Header.Get(xForwardedFor); fwd == "" { - pairs = append(pairs, strings.ToLower(xForwardedFor), remoteIP) - } else { - pairs = append(pairs, strings.ToLower(xForwardedFor), fmt.Sprintf("%s, %s", fwd, remoteIP)) - } - } - } - - if timeout != 0 { - ctx, _ = context.WithTimeout(ctx, timeout) - } - if len(pairs) == 0 { - return ctx, nil, nil - } - md := metadata.Pairs(pairs...) - for _, mda := range mux.metadataAnnotators { - md = metadata.Join(md, mda(ctx, req)) - } - return ctx, md, nil -} - -// ServerMetadata consists of metadata sent from gRPC server. -type ServerMetadata struct { - HeaderMD metadata.MD - TrailerMD metadata.MD -} - -type serverMetadataKey struct{} - -// NewServerMetadataContext creates a new context with ServerMetadata -func NewServerMetadataContext(ctx context.Context, md ServerMetadata) context.Context { - return context.WithValue(ctx, serverMetadataKey{}, md) -} - -// ServerMetadataFromContext returns the ServerMetadata in ctx -func ServerMetadataFromContext(ctx context.Context) (md ServerMetadata, ok bool) { - md, ok = ctx.Value(serverMetadataKey{}).(ServerMetadata) - return -} - -// ServerTransportStream implements grpc.ServerTransportStream. -// It should only be used by the generated files to support grpc.SendHeader -// outside of gRPC server use. -type ServerTransportStream struct { - mu sync.Mutex - header metadata.MD - trailer metadata.MD -} - -// Method returns the method for the stream. -func (s *ServerTransportStream) Method() string { - return "" -} - -// Header returns the header metadata of the stream. -func (s *ServerTransportStream) Header() metadata.MD { - s.mu.Lock() - defer s.mu.Unlock() - return s.header.Copy() -} - -// SetHeader sets the header metadata. -func (s *ServerTransportStream) SetHeader(md metadata.MD) error { - if md.Len() == 0 { - return nil - } - - s.mu.Lock() - s.header = metadata.Join(s.header, md) - s.mu.Unlock() - return nil -} - -// SendHeader sets the header metadata. -func (s *ServerTransportStream) SendHeader(md metadata.MD) error { - return s.SetHeader(md) -} - -// Trailer returns the cached trailer metadata. -func (s *ServerTransportStream) Trailer() metadata.MD { - s.mu.Lock() - defer s.mu.Unlock() - return s.trailer.Copy() -} - -// SetTrailer sets the trailer metadata. -func (s *ServerTransportStream) SetTrailer(md metadata.MD) error { - if md.Len() == 0 { - return nil - } - - s.mu.Lock() - s.trailer = metadata.Join(s.trailer, md) - s.mu.Unlock() - return nil -} - -func timeoutDecode(s string) (time.Duration, error) { - size := len(s) - if size < 2 { - return 0, fmt.Errorf("timeout string is too short: %q", s) - } - d, ok := timeoutUnitToDuration(s[size-1]) - if !ok { - return 0, fmt.Errorf("timeout unit is not recognized: %q", s) - } - t, err := strconv.ParseInt(s[:size-1], 10, 64) - if err != nil { - return 0, err - } - return d * time.Duration(t), nil -} - -func timeoutUnitToDuration(u uint8) (d time.Duration, ok bool) { - switch u { - case 'H': - return time.Hour, true - case 'M': - return time.Minute, true - case 'S': - return time.Second, true - case 'm': - return time.Millisecond, true - case 'u': - return time.Microsecond, true - case 'n': - return time.Nanosecond, true - default: - } - return -} - -// isPermanentHTTPHeader checks whether hdr belongs to the list of -// permanent request headers maintained by IANA. -// http://www.iana.org/assignments/message-headers/message-headers.xml -func isPermanentHTTPHeader(hdr string) bool { - switch hdr { - case - "Accept", - "Accept-Charset", - "Accept-Language", - "Accept-Ranges", - "Authorization", - "Cache-Control", - "Content-Type", - "Cookie", - "Date", - "Expect", - "From", - "Host", - "If-Match", - "If-Modified-Since", - "If-None-Match", - "If-Schedule-Tag-Match", - "If-Unmodified-Since", - "Max-Forwards", - "Origin", - "Pragma", - "Referer", - "User-Agent", - "Via", - "Warning": - return true - } - return false -} diff --git a/vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/convert.go b/vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/convert.go deleted file mode 100644 index 2c279344dc..0000000000 --- a/vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/convert.go +++ /dev/null @@ -1,318 +0,0 @@ -package runtime - -import ( - "encoding/base64" - "fmt" - "strconv" - "strings" - - "github.com/golang/protobuf/jsonpb" - "github.com/golang/protobuf/ptypes/duration" - "github.com/golang/protobuf/ptypes/timestamp" - "github.com/golang/protobuf/ptypes/wrappers" -) - -// String just returns the given string. -// It is just for compatibility to other types. -func String(val string) (string, error) { - return val, nil -} - -// StringSlice converts 'val' where individual strings are separated by -// 'sep' into a string slice. -func StringSlice(val, sep string) ([]string, error) { - return strings.Split(val, sep), nil -} - -// Bool converts the given string representation of a boolean value into bool. -func Bool(val string) (bool, error) { - return strconv.ParseBool(val) -} - -// BoolSlice converts 'val' where individual booleans are separated by -// 'sep' into a bool slice. -func BoolSlice(val, sep string) ([]bool, error) { - s := strings.Split(val, sep) - values := make([]bool, len(s)) - for i, v := range s { - value, err := Bool(v) - if err != nil { - return values, err - } - values[i] = value - } - return values, nil -} - -// Float64 converts the given string representation into representation of a floating point number into float64. -func Float64(val string) (float64, error) { - return strconv.ParseFloat(val, 64) -} - -// Float64Slice converts 'val' where individual floating point numbers are separated by -// 'sep' into a float64 slice. -func Float64Slice(val, sep string) ([]float64, error) { - s := strings.Split(val, sep) - values := make([]float64, len(s)) - for i, v := range s { - value, err := Float64(v) - if err != nil { - return values, err - } - values[i] = value - } - return values, nil -} - -// Float32 converts the given string representation of a floating point number into float32. -func Float32(val string) (float32, error) { - f, err := strconv.ParseFloat(val, 32) - if err != nil { - return 0, err - } - return float32(f), nil -} - -// Float32Slice converts 'val' where individual floating point numbers are separated by -// 'sep' into a float32 slice. -func Float32Slice(val, sep string) ([]float32, error) { - s := strings.Split(val, sep) - values := make([]float32, len(s)) - for i, v := range s { - value, err := Float32(v) - if err != nil { - return values, err - } - values[i] = value - } - return values, nil -} - -// Int64 converts the given string representation of an integer into int64. -func Int64(val string) (int64, error) { - return strconv.ParseInt(val, 0, 64) -} - -// Int64Slice converts 'val' where individual integers are separated by -// 'sep' into a int64 slice. -func Int64Slice(val, sep string) ([]int64, error) { - s := strings.Split(val, sep) - values := make([]int64, len(s)) - for i, v := range s { - value, err := Int64(v) - if err != nil { - return values, err - } - values[i] = value - } - return values, nil -} - -// Int32 converts the given string representation of an integer into int32. -func Int32(val string) (int32, error) { - i, err := strconv.ParseInt(val, 0, 32) - if err != nil { - return 0, err - } - return int32(i), nil -} - -// Int32Slice converts 'val' where individual integers are separated by -// 'sep' into a int32 slice. -func Int32Slice(val, sep string) ([]int32, error) { - s := strings.Split(val, sep) - values := make([]int32, len(s)) - for i, v := range s { - value, err := Int32(v) - if err != nil { - return values, err - } - values[i] = value - } - return values, nil -} - -// Uint64 converts the given string representation of an integer into uint64. -func Uint64(val string) (uint64, error) { - return strconv.ParseUint(val, 0, 64) -} - -// Uint64Slice converts 'val' where individual integers are separated by -// 'sep' into a uint64 slice. -func Uint64Slice(val, sep string) ([]uint64, error) { - s := strings.Split(val, sep) - values := make([]uint64, len(s)) - for i, v := range s { - value, err := Uint64(v) - if err != nil { - return values, err - } - values[i] = value - } - return values, nil -} - -// Uint32 converts the given string representation of an integer into uint32. -func Uint32(val string) (uint32, error) { - i, err := strconv.ParseUint(val, 0, 32) - if err != nil { - return 0, err - } - return uint32(i), nil -} - -// Uint32Slice converts 'val' where individual integers are separated by -// 'sep' into a uint32 slice. -func Uint32Slice(val, sep string) ([]uint32, error) { - s := strings.Split(val, sep) - values := make([]uint32, len(s)) - for i, v := range s { - value, err := Uint32(v) - if err != nil { - return values, err - } - values[i] = value - } - return values, nil -} - -// Bytes converts the given string representation of a byte sequence into a slice of bytes -// A bytes sequence is encoded in URL-safe base64 without padding -func Bytes(val string) ([]byte, error) { - b, err := base64.StdEncoding.DecodeString(val) - if err != nil { - b, err = base64.URLEncoding.DecodeString(val) - if err != nil { - return nil, err - } - } - return b, nil -} - -// BytesSlice converts 'val' where individual bytes sequences, encoded in URL-safe -// base64 without padding, are separated by 'sep' into a slice of bytes slices slice. -func BytesSlice(val, sep string) ([][]byte, error) { - s := strings.Split(val, sep) - values := make([][]byte, len(s)) - for i, v := range s { - value, err := Bytes(v) - if err != nil { - return values, err - } - values[i] = value - } - return values, nil -} - -// Timestamp converts the given RFC3339 formatted string into a timestamp.Timestamp. -func Timestamp(val string) (*timestamp.Timestamp, error) { - var r timestamp.Timestamp - err := jsonpb.UnmarshalString(val, &r) - if err != nil { - return nil, err - } - return &r, nil -} - -// Duration converts the given string into a timestamp.Duration. -func Duration(val string) (*duration.Duration, error) { - var r duration.Duration - err := jsonpb.UnmarshalString(val, &r) - if err != nil { - return nil, err - } - return &r, nil -} - -// Enum converts the given string into an int32 that should be type casted into the -// correct enum proto type. -func Enum(val string, enumValMap map[string]int32) (int32, error) { - e, ok := enumValMap[val] - if ok { - return e, nil - } - - i, err := Int32(val) - if err != nil { - return 0, fmt.Errorf("%s is not valid", val) - } - for _, v := range enumValMap { - if v == i { - return i, nil - } - } - return 0, fmt.Errorf("%s is not valid", val) -} - -// EnumSlice converts 'val' where individual enums are separated by 'sep' -// into a int32 slice. Each individual int32 should be type casted into the -// correct enum proto type. -func EnumSlice(val, sep string, enumValMap map[string]int32) ([]int32, error) { - s := strings.Split(val, sep) - values := make([]int32, len(s)) - for i, v := range s { - value, err := Enum(v, enumValMap) - if err != nil { - return values, err - } - values[i] = value - } - return values, nil -} - -/* - Support fot google.protobuf.wrappers on top of primitive types -*/ - -// StringValue well-known type support as wrapper around string type -func StringValue(val string) (*wrappers.StringValue, error) { - return &wrappers.StringValue{Value: val}, nil -} - -// FloatValue well-known type support as wrapper around float32 type -func FloatValue(val string) (*wrappers.FloatValue, error) { - parsedVal, err := Float32(val) - return &wrappers.FloatValue{Value: parsedVal}, err -} - -// DoubleValue well-known type support as wrapper around float64 type -func DoubleValue(val string) (*wrappers.DoubleValue, error) { - parsedVal, err := Float64(val) - return &wrappers.DoubleValue{Value: parsedVal}, err -} - -// BoolValue well-known type support as wrapper around bool type -func BoolValue(val string) (*wrappers.BoolValue, error) { - parsedVal, err := Bool(val) - return &wrappers.BoolValue{Value: parsedVal}, err -} - -// Int32Value well-known type support as wrapper around int32 type -func Int32Value(val string) (*wrappers.Int32Value, error) { - parsedVal, err := Int32(val) - return &wrappers.Int32Value{Value: parsedVal}, err -} - -// UInt32Value well-known type support as wrapper around uint32 type -func UInt32Value(val string) (*wrappers.UInt32Value, error) { - parsedVal, err := Uint32(val) - return &wrappers.UInt32Value{Value: parsedVal}, err -} - -// Int64Value well-known type support as wrapper around int64 type -func Int64Value(val string) (*wrappers.Int64Value, error) { - parsedVal, err := Int64(val) - return &wrappers.Int64Value{Value: parsedVal}, err -} - -// UInt64Value well-known type support as wrapper around uint64 type -func UInt64Value(val string) (*wrappers.UInt64Value, error) { - parsedVal, err := Uint64(val) - return &wrappers.UInt64Value{Value: parsedVal}, err -} - -// BytesValue well-known type support as wrapper around bytes[] type -func BytesValue(val string) (*wrappers.BytesValue, error) { - parsedVal, err := Bytes(val) - return &wrappers.BytesValue{Value: parsedVal}, err -} diff --git a/vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/doc.go b/vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/doc.go deleted file mode 100644 index b6e5ddf7a9..0000000000 --- a/vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/doc.go +++ /dev/null @@ -1,5 +0,0 @@ -/* -Package runtime contains runtime helper functions used by -servers which protoc-gen-grpc-gateway generates. -*/ -package runtime diff --git a/vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/errors.go b/vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/errors.go deleted file mode 100644 index b2ce743bdd..0000000000 --- a/vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/errors.go +++ /dev/null @@ -1,186 +0,0 @@ -package runtime - -import ( - "context" - "io" - "net/http" - "strings" - - "github.com/grpc-ecosystem/grpc-gateway/internal" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/grpclog" - "google.golang.org/grpc/status" -) - -// HTTPStatusFromCode converts a gRPC error code into the corresponding HTTP response status. -// See: https://github.com/googleapis/googleapis/blob/master/google/rpc/code.proto -func HTTPStatusFromCode(code codes.Code) int { - switch code { - case codes.OK: - return http.StatusOK - case codes.Canceled: - return http.StatusRequestTimeout - case codes.Unknown: - return http.StatusInternalServerError - case codes.InvalidArgument: - return http.StatusBadRequest - case codes.DeadlineExceeded: - return http.StatusGatewayTimeout - case codes.NotFound: - return http.StatusNotFound - case codes.AlreadyExists: - return http.StatusConflict - case codes.PermissionDenied: - return http.StatusForbidden - case codes.Unauthenticated: - return http.StatusUnauthorized - case codes.ResourceExhausted: - return http.StatusTooManyRequests - case codes.FailedPrecondition: - // Note, this deliberately doesn't translate to the similarly named '412 Precondition Failed' HTTP response status. - return http.StatusBadRequest - case codes.Aborted: - return http.StatusConflict - case codes.OutOfRange: - return http.StatusBadRequest - case codes.Unimplemented: - return http.StatusNotImplemented - case codes.Internal: - return http.StatusInternalServerError - case codes.Unavailable: - return http.StatusServiceUnavailable - case codes.DataLoss: - return http.StatusInternalServerError - } - - grpclog.Infof("Unknown gRPC error code: %v", code) - return http.StatusInternalServerError -} - -var ( - // HTTPError replies to the request with an error. - // - // HTTPError is called: - // - From generated per-endpoint gateway handler code, when calling the backend results in an error. - // - From gateway runtime code, when forwarding the response message results in an error. - // - // The default value for HTTPError calls the custom error handler configured on the ServeMux via the - // WithProtoErrorHandler serve option if that option was used, calling GlobalHTTPErrorHandler otherwise. - // - // To customize the error handling of a particular ServeMux instance, use the WithProtoErrorHandler - // serve option. - // - // To customize the error format for all ServeMux instances not using the WithProtoErrorHandler serve - // option, set GlobalHTTPErrorHandler to a custom function. - // - // Setting this variable directly to customize error format is deprecated. - HTTPError = MuxOrGlobalHTTPError - - // GlobalHTTPErrorHandler is the HTTPError handler for all ServeMux instances not using the - // WithProtoErrorHandler serve option. - // - // You can set a custom function to this variable to customize error format. - GlobalHTTPErrorHandler = DefaultHTTPError - - // OtherErrorHandler handles gateway errors from parsing and routing client requests for all - // ServeMux instances not using the WithProtoErrorHandler serve option. - // - // It returns the following error codes: StatusMethodNotAllowed StatusNotFound StatusBadRequest - // - // To customize parsing and routing error handling of a particular ServeMux instance, use the - // WithProtoErrorHandler serve option. - // - // To customize parsing and routing error handling of all ServeMux instances not using the - // WithProtoErrorHandler serve option, set a custom function to this variable. - OtherErrorHandler = DefaultOtherErrorHandler -) - -// MuxOrGlobalHTTPError uses the mux-configured error handler, falling back to GlobalErrorHandler. -func MuxOrGlobalHTTPError(ctx context.Context, mux *ServeMux, marshaler Marshaler, w http.ResponseWriter, r *http.Request, err error) { - if mux.protoErrorHandler != nil { - mux.protoErrorHandler(ctx, mux, marshaler, w, r, err) - } else { - GlobalHTTPErrorHandler(ctx, mux, marshaler, w, r, err) - } -} - -// DefaultHTTPError is the default implementation of HTTPError. -// If "err" is an error from gRPC system, the function replies with the status code mapped by HTTPStatusFromCode. -// If otherwise, it replies with http.StatusInternalServerError. -// -// The response body returned by this function is a JSON object, -// which contains a member whose key is "error" and whose value is err.Error(). -func DefaultHTTPError(ctx context.Context, mux *ServeMux, marshaler Marshaler, w http.ResponseWriter, r *http.Request, err error) { - const fallback = `{"error": "failed to marshal error message"}` - - s, ok := status.FromError(err) - if !ok { - s = status.New(codes.Unknown, err.Error()) - } - - w.Header().Del("Trailer") - w.Header().Del("Transfer-Encoding") - - contentType := marshaler.ContentType() - // Check marshaler on run time in order to keep backwards compatibility - // An interface param needs to be added to the ContentType() function on - // the Marshal interface to be able to remove this check - if typeMarshaler, ok := marshaler.(contentTypeMarshaler); ok { - pb := s.Proto() - contentType = typeMarshaler.ContentTypeFromMessage(pb) - } - w.Header().Set("Content-Type", contentType) - - body := &internal.Error{ - Error: s.Message(), - Message: s.Message(), - Code: int32(s.Code()), - Details: s.Proto().GetDetails(), - } - - buf, merr := marshaler.Marshal(body) - if merr != nil { - grpclog.Infof("Failed to marshal error message %q: %v", body, merr) - w.WriteHeader(http.StatusInternalServerError) - if _, err := io.WriteString(w, fallback); err != nil { - grpclog.Infof("Failed to write response: %v", err) - } - return - } - - md, ok := ServerMetadataFromContext(ctx) - if !ok { - grpclog.Infof("Failed to extract ServerMetadata from context") - } - - handleForwardResponseServerMetadata(w, mux, md) - - // RFC 7230 https://tools.ietf.org/html/rfc7230#section-4.1.2 - // Unless the request includes a TE header field indicating "trailers" - // is acceptable, as described in Section 4.3, a server SHOULD NOT - // generate trailer fields that it believes are necessary for the user - // agent to receive. - var wantsTrailers bool - - if te := r.Header.Get("TE"); strings.Contains(strings.ToLower(te), "trailers") { - wantsTrailers = true - handleForwardResponseTrailerHeader(w, md) - w.Header().Set("Transfer-Encoding", "chunked") - } - - st := HTTPStatusFromCode(s.Code()) - w.WriteHeader(st) - if _, err := w.Write(buf); err != nil { - grpclog.Infof("Failed to write response: %v", err) - } - - if wantsTrailers { - handleForwardResponseTrailer(w, md) - } -} - -// DefaultOtherErrorHandler is the default implementation of OtherErrorHandler. -// It simply writes a string representation of the given error into "w". -func DefaultOtherErrorHandler(w http.ResponseWriter, _ *http.Request, msg string, code int) { - http.Error(w, msg, code) -} diff --git a/vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/fieldmask.go b/vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/fieldmask.go deleted file mode 100644 index aef645e40b..0000000000 --- a/vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/fieldmask.go +++ /dev/null @@ -1,89 +0,0 @@ -package runtime - -import ( - "encoding/json" - "io" - "strings" - - descriptor2 "github.com/golang/protobuf/descriptor" - "github.com/golang/protobuf/protoc-gen-go/descriptor" - "google.golang.org/genproto/protobuf/field_mask" -) - -func translateName(name string, md *descriptor.DescriptorProto) (string, *descriptor.DescriptorProto) { - // TODO - should really gate this with a test that the marshaller has used json names - if md != nil { - for _, f := range md.Field { - if f.JsonName != nil && f.Name != nil && *f.JsonName == name { - var subType *descriptor.DescriptorProto - - // If the field has a TypeName then we retrieve the nested type for translating the embedded message names. - if f.TypeName != nil { - typeSplit := strings.Split(*f.TypeName, ".") - typeName := typeSplit[len(typeSplit)-1] - for _, t := range md.NestedType { - if typeName == *t.Name { - subType = t - } - } - } - return *f.Name, subType - } - } - } - return name, nil -} - -// FieldMaskFromRequestBody creates a FieldMask printing all complete paths from the JSON body. -func FieldMaskFromRequestBody(r io.Reader, md *descriptor.DescriptorProto) (*field_mask.FieldMask, error) { - fm := &field_mask.FieldMask{} - var root interface{} - if err := json.NewDecoder(r).Decode(&root); err != nil { - if err == io.EOF { - return fm, nil - } - return nil, err - } - - queue := []fieldMaskPathItem{{node: root, md: md}} - for len(queue) > 0 { - // dequeue an item - item := queue[0] - queue = queue[1:] - - if m, ok := item.node.(map[string]interface{}); ok { - // if the item is an object, then enqueue all of its children - for k, v := range m { - protoName, subMd := translateName(k, item.md) - if subMsg, ok := v.(descriptor2.Message); ok { - _, subMd = descriptor2.ForMessage(subMsg) - } - - var path string - if item.path == "" { - path = protoName - } else { - path = item.path + "." + protoName - } - queue = append(queue, fieldMaskPathItem{path: path, node: v, md: subMd}) - } - } else if len(item.path) > 0 { - // otherwise, it's a leaf node so print its path - fm.Paths = append(fm.Paths, item.path) - } - } - - return fm, nil -} - -// fieldMaskPathItem stores a in-progress deconstruction of a path for a fieldmask -type fieldMaskPathItem struct { - // the list of prior fields leading up to node connected by dots - path string - - // a generic decoded json object the current item to inspect for further path extraction - node interface{} - - // descriptor for parent message - md *descriptor.DescriptorProto -} diff --git a/vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/handler.go b/vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/handler.go deleted file mode 100644 index e6e8f286e1..0000000000 --- a/vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/handler.go +++ /dev/null @@ -1,212 +0,0 @@ -package runtime - -import ( - "context" - "errors" - "fmt" - "io" - "net/http" - "net/textproto" - - "github.com/golang/protobuf/proto" - "github.com/grpc-ecosystem/grpc-gateway/internal" - "google.golang.org/grpc/grpclog" -) - -var errEmptyResponse = errors.New("empty response") - -// ForwardResponseStream forwards the stream from gRPC server to REST client. -func ForwardResponseStream(ctx context.Context, mux *ServeMux, marshaler Marshaler, w http.ResponseWriter, req *http.Request, recv func() (proto.Message, error), opts ...func(context.Context, http.ResponseWriter, proto.Message) error) { - f, ok := w.(http.Flusher) - if !ok { - grpclog.Infof("Flush not supported in %T", w) - http.Error(w, "unexpected type of web server", http.StatusInternalServerError) - return - } - - md, ok := ServerMetadataFromContext(ctx) - if !ok { - grpclog.Infof("Failed to extract ServerMetadata from context") - http.Error(w, "unexpected error", http.StatusInternalServerError) - return - } - handleForwardResponseServerMetadata(w, mux, md) - - w.Header().Set("Transfer-Encoding", "chunked") - w.Header().Set("Content-Type", marshaler.ContentType()) - if err := handleForwardResponseOptions(ctx, w, nil, opts); err != nil { - HTTPError(ctx, mux, marshaler, w, req, err) - return - } - - var delimiter []byte - if d, ok := marshaler.(Delimited); ok { - delimiter = d.Delimiter() - } else { - delimiter = []byte("\n") - } - - var wroteHeader bool - for { - resp, err := recv() - if err == io.EOF { - return - } - if err != nil { - handleForwardResponseStreamError(ctx, wroteHeader, marshaler, w, req, mux, err) - return - } - if err := handleForwardResponseOptions(ctx, w, resp, opts); err != nil { - handleForwardResponseStreamError(ctx, wroteHeader, marshaler, w, req, mux, err) - return - } - - var buf []byte - switch { - case resp == nil: - buf, err = marshaler.Marshal(errorChunk(streamError(ctx, mux.streamErrorHandler, errEmptyResponse))) - default: - result := map[string]interface{}{"result": resp} - if rb, ok := resp.(responseBody); ok { - result["result"] = rb.XXX_ResponseBody() - } - - buf, err = marshaler.Marshal(result) - } - - if err != nil { - grpclog.Infof("Failed to marshal response chunk: %v", err) - handleForwardResponseStreamError(ctx, wroteHeader, marshaler, w, req, mux, err) - return - } - if _, err = w.Write(buf); err != nil { - grpclog.Infof("Failed to send response chunk: %v", err) - return - } - wroteHeader = true - if _, err = w.Write(delimiter); err != nil { - grpclog.Infof("Failed to send delimiter chunk: %v", err) - return - } - f.Flush() - } -} - -func handleForwardResponseServerMetadata(w http.ResponseWriter, mux *ServeMux, md ServerMetadata) { - for k, vs := range md.HeaderMD { - if h, ok := mux.outgoingHeaderMatcher(k); ok { - for _, v := range vs { - w.Header().Add(h, v) - } - } - } -} - -func handleForwardResponseTrailerHeader(w http.ResponseWriter, md ServerMetadata) { - for k := range md.TrailerMD { - tKey := textproto.CanonicalMIMEHeaderKey(fmt.Sprintf("%s%s", MetadataTrailerPrefix, k)) - w.Header().Add("Trailer", tKey) - } -} - -func handleForwardResponseTrailer(w http.ResponseWriter, md ServerMetadata) { - for k, vs := range md.TrailerMD { - tKey := fmt.Sprintf("%s%s", MetadataTrailerPrefix, k) - for _, v := range vs { - w.Header().Add(tKey, v) - } - } -} - -// responseBody interface contains method for getting field for marshaling to the response body -// this method is generated for response struct from the value of `response_body` in the `google.api.HttpRule` -type responseBody interface { - XXX_ResponseBody() interface{} -} - -// ForwardResponseMessage forwards the message "resp" from gRPC server to REST client. -func ForwardResponseMessage(ctx context.Context, mux *ServeMux, marshaler Marshaler, w http.ResponseWriter, req *http.Request, resp proto.Message, opts ...func(context.Context, http.ResponseWriter, proto.Message) error) { - md, ok := ServerMetadataFromContext(ctx) - if !ok { - grpclog.Infof("Failed to extract ServerMetadata from context") - } - - handleForwardResponseServerMetadata(w, mux, md) - handleForwardResponseTrailerHeader(w, md) - - contentType := marshaler.ContentType() - // Check marshaler on run time in order to keep backwards compatibility - // An interface param needs to be added to the ContentType() function on - // the Marshal interface to be able to remove this check - if typeMarshaler, ok := marshaler.(contentTypeMarshaler); ok { - contentType = typeMarshaler.ContentTypeFromMessage(resp) - } - w.Header().Set("Content-Type", contentType) - - if err := handleForwardResponseOptions(ctx, w, resp, opts); err != nil { - HTTPError(ctx, mux, marshaler, w, req, err) - return - } - var buf []byte - var err error - if rb, ok := resp.(responseBody); ok { - buf, err = marshaler.Marshal(rb.XXX_ResponseBody()) - } else { - buf, err = marshaler.Marshal(resp) - } - if err != nil { - grpclog.Infof("Marshal error: %v", err) - HTTPError(ctx, mux, marshaler, w, req, err) - return - } - - if _, err = w.Write(buf); err != nil { - grpclog.Infof("Failed to write response: %v", err) - } - - handleForwardResponseTrailer(w, md) -} - -func handleForwardResponseOptions(ctx context.Context, w http.ResponseWriter, resp proto.Message, opts []func(context.Context, http.ResponseWriter, proto.Message) error) error { - if len(opts) == 0 { - return nil - } - for _, opt := range opts { - if err := opt(ctx, w, resp); err != nil { - grpclog.Infof("Error handling ForwardResponseOptions: %v", err) - return err - } - } - return nil -} - -func handleForwardResponseStreamError(ctx context.Context, wroteHeader bool, marshaler Marshaler, w http.ResponseWriter, req *http.Request, mux *ServeMux, err error) { - serr := streamError(ctx, mux.streamErrorHandler, err) - if !wroteHeader { - w.WriteHeader(int(serr.HttpCode)) - } - buf, merr := marshaler.Marshal(errorChunk(serr)) - if merr != nil { - grpclog.Infof("Failed to marshal an error: %v", merr) - return - } - if _, werr := w.Write(buf); werr != nil { - grpclog.Infof("Failed to notify error to client: %v", werr) - return - } -} - -// streamError returns the payload for the final message in a response stream -// that represents the given err. -func streamError(ctx context.Context, errHandler StreamErrorHandlerFunc, err error) *StreamError { - serr := errHandler(ctx, err) - if serr != nil { - return serr - } - // TODO: log about misbehaving stream error handler? - return DefaultHTTPStreamErrorHandler(ctx, err) -} - -func errorChunk(err *StreamError) map[string]proto.Message { - return map[string]proto.Message{"error": (*internal.StreamError)(err)} -} diff --git a/vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/marshal_httpbodyproto.go b/vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/marshal_httpbodyproto.go deleted file mode 100644 index 525b0338c7..0000000000 --- a/vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/marshal_httpbodyproto.go +++ /dev/null @@ -1,43 +0,0 @@ -package runtime - -import ( - "google.golang.org/genproto/googleapis/api/httpbody" -) - -// SetHTTPBodyMarshaler overwrite the default marshaler with the HTTPBodyMarshaler -func SetHTTPBodyMarshaler(serveMux *ServeMux) { - serveMux.marshalers.mimeMap[MIMEWildcard] = &HTTPBodyMarshaler{ - Marshaler: &JSONPb{OrigName: true}, - } -} - -// HTTPBodyMarshaler is a Marshaler which supports marshaling of a -// google.api.HttpBody message as the full response body if it is -// the actual message used as the response. If not, then this will -// simply fallback to the Marshaler specified as its default Marshaler. -type HTTPBodyMarshaler struct { - Marshaler -} - -// ContentType implementation to keep backwards compatibility with marshal interface -func (h *HTTPBodyMarshaler) ContentType() string { - return h.ContentTypeFromMessage(nil) -} - -// ContentTypeFromMessage in case v is a google.api.HttpBody message it returns -// its specified content type otherwise fall back to the default Marshaler. -func (h *HTTPBodyMarshaler) ContentTypeFromMessage(v interface{}) string { - if httpBody, ok := v.(*httpbody.HttpBody); ok { - return httpBody.GetContentType() - } - return h.Marshaler.ContentType() -} - -// Marshal marshals "v" by returning the body bytes if v is a -// google.api.HttpBody message, otherwise it falls back to the default Marshaler. -func (h *HTTPBodyMarshaler) Marshal(v interface{}) ([]byte, error) { - if httpBody, ok := v.(*httpbody.HttpBody); ok { - return httpBody.Data, nil - } - return h.Marshaler.Marshal(v) -} diff --git a/vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/marshal_json.go b/vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/marshal_json.go deleted file mode 100644 index f9d3a585a4..0000000000 --- a/vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/marshal_json.go +++ /dev/null @@ -1,45 +0,0 @@ -package runtime - -import ( - "encoding/json" - "io" -) - -// JSONBuiltin is a Marshaler which marshals/unmarshals into/from JSON -// with the standard "encoding/json" package of Golang. -// Although it is generally faster for simple proto messages than JSONPb, -// it does not support advanced features of protobuf, e.g. map, oneof, .... -// -// The NewEncoder and NewDecoder types return *json.Encoder and -// *json.Decoder respectively. -type JSONBuiltin struct{} - -// ContentType always Returns "application/json". -func (*JSONBuiltin) ContentType() string { - return "application/json" -} - -// Marshal marshals "v" into JSON -func (j *JSONBuiltin) Marshal(v interface{}) ([]byte, error) { - return json.Marshal(v) -} - -// Unmarshal unmarshals JSON data into "v". -func (j *JSONBuiltin) Unmarshal(data []byte, v interface{}) error { - return json.Unmarshal(data, v) -} - -// NewDecoder returns a Decoder which reads JSON stream from "r". -func (j *JSONBuiltin) NewDecoder(r io.Reader) Decoder { - return json.NewDecoder(r) -} - -// NewEncoder returns an Encoder which writes JSON stream into "w". -func (j *JSONBuiltin) NewEncoder(w io.Writer) Encoder { - return json.NewEncoder(w) -} - -// Delimiter for newline encoded JSON streams. -func (j *JSONBuiltin) Delimiter() []byte { - return []byte("\n") -} diff --git a/vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/marshal_jsonpb.go b/vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/marshal_jsonpb.go deleted file mode 100644 index f0de351b21..0000000000 --- a/vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/marshal_jsonpb.go +++ /dev/null @@ -1,262 +0,0 @@ -package runtime - -import ( - "bytes" - "encoding/json" - "fmt" - "io" - "reflect" - - "github.com/golang/protobuf/jsonpb" - "github.com/golang/protobuf/proto" -) - -// JSONPb is a Marshaler which marshals/unmarshals into/from JSON -// with the "github.com/golang/protobuf/jsonpb". -// It supports fully functionality of protobuf unlike JSONBuiltin. -// -// The NewDecoder method returns a DecoderWrapper, so the underlying -// *json.Decoder methods can be used. -type JSONPb jsonpb.Marshaler - -// ContentType always returns "application/json". -func (*JSONPb) ContentType() string { - return "application/json" -} - -// Marshal marshals "v" into JSON. -func (j *JSONPb) Marshal(v interface{}) ([]byte, error) { - if _, ok := v.(proto.Message); !ok { - return j.marshalNonProtoField(v) - } - - var buf bytes.Buffer - if err := j.marshalTo(&buf, v); err != nil { - return nil, err - } - return buf.Bytes(), nil -} - -func (j *JSONPb) marshalTo(w io.Writer, v interface{}) error { - p, ok := v.(proto.Message) - if !ok { - buf, err := j.marshalNonProtoField(v) - if err != nil { - return err - } - _, err = w.Write(buf) - return err - } - return (*jsonpb.Marshaler)(j).Marshal(w, p) -} - -var ( - // protoMessageType is stored to prevent constant lookup of the same type at runtime. - protoMessageType = reflect.TypeOf((*proto.Message)(nil)).Elem() -) - -// marshalNonProto marshals a non-message field of a protobuf message. -// This function does not correctly marshals arbitrary data structure into JSON, -// but it is only capable of marshaling non-message field values of protobuf, -// i.e. primitive types, enums; pointers to primitives or enums; maps from -// integer/string types to primitives/enums/pointers to messages. -func (j *JSONPb) marshalNonProtoField(v interface{}) ([]byte, error) { - if v == nil { - return []byte("null"), nil - } - rv := reflect.ValueOf(v) - for rv.Kind() == reflect.Ptr { - if rv.IsNil() { - return []byte("null"), nil - } - rv = rv.Elem() - } - - if rv.Kind() == reflect.Slice { - if rv.IsNil() { - if j.EmitDefaults { - return []byte("[]"), nil - } - return []byte("null"), nil - } - - if rv.Type().Elem().Implements(protoMessageType) { - var buf bytes.Buffer - err := buf.WriteByte('[') - if err != nil { - return nil, err - } - for i := 0; i < rv.Len(); i++ { - if i != 0 { - err = buf.WriteByte(',') - if err != nil { - return nil, err - } - } - if err = (*jsonpb.Marshaler)(j).Marshal(&buf, rv.Index(i).Interface().(proto.Message)); err != nil { - return nil, err - } - } - err = buf.WriteByte(']') - if err != nil { - return nil, err - } - - return buf.Bytes(), nil - } - } - - if rv.Kind() == reflect.Map { - m := make(map[string]*json.RawMessage) - for _, k := range rv.MapKeys() { - buf, err := j.Marshal(rv.MapIndex(k).Interface()) - if err != nil { - return nil, err - } - m[fmt.Sprintf("%v", k.Interface())] = (*json.RawMessage)(&buf) - } - if j.Indent != "" { - return json.MarshalIndent(m, "", j.Indent) - } - return json.Marshal(m) - } - if enum, ok := rv.Interface().(protoEnum); ok && !j.EnumsAsInts { - return json.Marshal(enum.String()) - } - return json.Marshal(rv.Interface()) -} - -// Unmarshal unmarshals JSON "data" into "v" -func (j *JSONPb) Unmarshal(data []byte, v interface{}) error { - return unmarshalJSONPb(data, v) -} - -// NewDecoder returns a Decoder which reads JSON stream from "r". -func (j *JSONPb) NewDecoder(r io.Reader) Decoder { - d := json.NewDecoder(r) - return DecoderWrapper{Decoder: d} -} - -// DecoderWrapper is a wrapper around a *json.Decoder that adds -// support for protos to the Decode method. -type DecoderWrapper struct { - *json.Decoder -} - -// Decode wraps the embedded decoder's Decode method to support -// protos using a jsonpb.Unmarshaler. -func (d DecoderWrapper) Decode(v interface{}) error { - return decodeJSONPb(d.Decoder, v) -} - -// NewEncoder returns an Encoder which writes JSON stream into "w". -func (j *JSONPb) NewEncoder(w io.Writer) Encoder { - return EncoderFunc(func(v interface{}) error { - if err := j.marshalTo(w, v); err != nil { - return err - } - // mimic json.Encoder by adding a newline (makes output - // easier to read when it contains multiple encoded items) - _, err := w.Write(j.Delimiter()) - return err - }) -} - -func unmarshalJSONPb(data []byte, v interface{}) error { - d := json.NewDecoder(bytes.NewReader(data)) - return decodeJSONPb(d, v) -} - -func decodeJSONPb(d *json.Decoder, v interface{}) error { - p, ok := v.(proto.Message) - if !ok { - return decodeNonProtoField(d, v) - } - unmarshaler := &jsonpb.Unmarshaler{AllowUnknownFields: allowUnknownFields} - return unmarshaler.UnmarshalNext(d, p) -} - -func decodeNonProtoField(d *json.Decoder, v interface{}) error { - rv := reflect.ValueOf(v) - if rv.Kind() != reflect.Ptr { - return fmt.Errorf("%T is not a pointer", v) - } - for rv.Kind() == reflect.Ptr { - if rv.IsNil() { - rv.Set(reflect.New(rv.Type().Elem())) - } - if rv.Type().ConvertibleTo(typeProtoMessage) { - unmarshaler := &jsonpb.Unmarshaler{AllowUnknownFields: allowUnknownFields} - return unmarshaler.UnmarshalNext(d, rv.Interface().(proto.Message)) - } - rv = rv.Elem() - } - if rv.Kind() == reflect.Map { - if rv.IsNil() { - rv.Set(reflect.MakeMap(rv.Type())) - } - conv, ok := convFromType[rv.Type().Key().Kind()] - if !ok { - return fmt.Errorf("unsupported type of map field key: %v", rv.Type().Key()) - } - - m := make(map[string]*json.RawMessage) - if err := d.Decode(&m); err != nil { - return err - } - for k, v := range m { - result := conv.Call([]reflect.Value{reflect.ValueOf(k)}) - if err := result[1].Interface(); err != nil { - return err.(error) - } - bk := result[0] - bv := reflect.New(rv.Type().Elem()) - if err := unmarshalJSONPb([]byte(*v), bv.Interface()); err != nil { - return err - } - rv.SetMapIndex(bk, bv.Elem()) - } - return nil - } - if _, ok := rv.Interface().(protoEnum); ok { - var repr interface{} - if err := d.Decode(&repr); err != nil { - return err - } - switch repr.(type) { - case string: - // TODO(yugui) Should use proto.StructProperties? - return fmt.Errorf("unmarshaling of symbolic enum %q not supported: %T", repr, rv.Interface()) - case float64: - rv.Set(reflect.ValueOf(int32(repr.(float64))).Convert(rv.Type())) - return nil - default: - return fmt.Errorf("cannot assign %#v into Go type %T", repr, rv.Interface()) - } - } - return d.Decode(v) -} - -type protoEnum interface { - fmt.Stringer - EnumDescriptor() ([]byte, []int) -} - -var typeProtoMessage = reflect.TypeOf((*proto.Message)(nil)).Elem() - -// Delimiter for newline encoded JSON streams. -func (j *JSONPb) Delimiter() []byte { - return []byte("\n") -} - -// allowUnknownFields helps not to return an error when the destination -// is a struct and the input contains object keys which do not match any -// non-ignored, exported fields in the destination. -var allowUnknownFields = true - -// DisallowUnknownFields enables option in decoder (unmarshaller) to -// return an error when it finds an unknown field. This function must be -// called before using the JSON marshaller. -func DisallowUnknownFields() { - allowUnknownFields = false -} diff --git a/vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/marshal_proto.go b/vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/marshal_proto.go deleted file mode 100644 index f65d1a2676..0000000000 --- a/vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/marshal_proto.go +++ /dev/null @@ -1,62 +0,0 @@ -package runtime - -import ( - "io" - - "errors" - "github.com/golang/protobuf/proto" - "io/ioutil" -) - -// ProtoMarshaller is a Marshaller which marshals/unmarshals into/from serialize proto bytes -type ProtoMarshaller struct{} - -// ContentType always returns "application/octet-stream". -func (*ProtoMarshaller) ContentType() string { - return "application/octet-stream" -} - -// Marshal marshals "value" into Proto -func (*ProtoMarshaller) Marshal(value interface{}) ([]byte, error) { - message, ok := value.(proto.Message) - if !ok { - return nil, errors.New("unable to marshal non proto field") - } - return proto.Marshal(message) -} - -// Unmarshal unmarshals proto "data" into "value" -func (*ProtoMarshaller) Unmarshal(data []byte, value interface{}) error { - message, ok := value.(proto.Message) - if !ok { - return errors.New("unable to unmarshal non proto field") - } - return proto.Unmarshal(data, message) -} - -// NewDecoder returns a Decoder which reads proto stream from "reader". -func (marshaller *ProtoMarshaller) NewDecoder(reader io.Reader) Decoder { - return DecoderFunc(func(value interface{}) error { - buffer, err := ioutil.ReadAll(reader) - if err != nil { - return err - } - return marshaller.Unmarshal(buffer, value) - }) -} - -// NewEncoder returns an Encoder which writes proto stream into "writer". -func (marshaller *ProtoMarshaller) NewEncoder(writer io.Writer) Encoder { - return EncoderFunc(func(value interface{}) error { - buffer, err := marshaller.Marshal(value) - if err != nil { - return err - } - _, err = writer.Write(buffer) - if err != nil { - return err - } - - return nil - }) -} diff --git a/vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/marshaler.go b/vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/marshaler.go deleted file mode 100644 index 4615329421..0000000000 --- a/vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/marshaler.go +++ /dev/null @@ -1,55 +0,0 @@ -package runtime - -import ( - "io" -) - -// Marshaler defines a conversion between byte sequence and gRPC payloads / fields. -type Marshaler interface { - // Marshal marshals "v" into byte sequence. - Marshal(v interface{}) ([]byte, error) - // Unmarshal unmarshals "data" into "v". - // "v" must be a pointer value. - Unmarshal(data []byte, v interface{}) error - // NewDecoder returns a Decoder which reads byte sequence from "r". - NewDecoder(r io.Reader) Decoder - // NewEncoder returns an Encoder which writes bytes sequence into "w". - NewEncoder(w io.Writer) Encoder - // ContentType returns the Content-Type which this marshaler is responsible for. - ContentType() string -} - -// Marshalers that implement contentTypeMarshaler will have their ContentTypeFromMessage method called -// to set the Content-Type header on the response -type contentTypeMarshaler interface { - // ContentTypeFromMessage returns the Content-Type this marshaler produces from the provided message - ContentTypeFromMessage(v interface{}) string -} - -// Decoder decodes a byte sequence -type Decoder interface { - Decode(v interface{}) error -} - -// Encoder encodes gRPC payloads / fields into byte sequence. -type Encoder interface { - Encode(v interface{}) error -} - -// DecoderFunc adapts an decoder function into Decoder. -type DecoderFunc func(v interface{}) error - -// Decode delegates invocations to the underlying function itself. -func (f DecoderFunc) Decode(v interface{}) error { return f(v) } - -// EncoderFunc adapts an encoder function into Encoder -type EncoderFunc func(v interface{}) error - -// Encode delegates invocations to the underlying function itself. -func (f EncoderFunc) Encode(v interface{}) error { return f(v) } - -// Delimited defines the streaming delimiter. -type Delimited interface { - // Delimiter returns the record separator for the stream. - Delimiter() []byte -} diff --git a/vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/marshaler_registry.go b/vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/marshaler_registry.go deleted file mode 100644 index 8dd5c24db4..0000000000 --- a/vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/marshaler_registry.go +++ /dev/null @@ -1,99 +0,0 @@ -package runtime - -import ( - "errors" - "mime" - "net/http" - - "google.golang.org/grpc/grpclog" -) - -// MIMEWildcard is the fallback MIME type used for requests which do not match -// a registered MIME type. -const MIMEWildcard = "*" - -var ( - acceptHeader = http.CanonicalHeaderKey("Accept") - contentTypeHeader = http.CanonicalHeaderKey("Content-Type") - - defaultMarshaler = &JSONPb{OrigName: true} -) - -// MarshalerForRequest returns the inbound/outbound marshalers for this request. -// It checks the registry on the ServeMux for the MIME type set by the Content-Type header. -// If it isn't set (or the request Content-Type is empty), checks for "*". -// If there are multiple Content-Type headers set, choose the first one that it can -// exactly match in the registry. -// Otherwise, it follows the above logic for "*"/InboundMarshaler/OutboundMarshaler. -func MarshalerForRequest(mux *ServeMux, r *http.Request) (inbound Marshaler, outbound Marshaler) { - for _, acceptVal := range r.Header[acceptHeader] { - if m, ok := mux.marshalers.mimeMap[acceptVal]; ok { - outbound = m - break - } - } - - for _, contentTypeVal := range r.Header[contentTypeHeader] { - contentType, _, err := mime.ParseMediaType(contentTypeVal) - if err != nil { - grpclog.Infof("Failed to parse Content-Type %s: %v", contentTypeVal, err) - continue - } - if m, ok := mux.marshalers.mimeMap[contentType]; ok { - inbound = m - break - } - } - - if inbound == nil { - inbound = mux.marshalers.mimeMap[MIMEWildcard] - } - if outbound == nil { - outbound = inbound - } - - return inbound, outbound -} - -// marshalerRegistry is a mapping from MIME types to Marshalers. -type marshalerRegistry struct { - mimeMap map[string]Marshaler -} - -// add adds a marshaler for a case-sensitive MIME type string ("*" to match any -// MIME type). -func (m marshalerRegistry) add(mime string, marshaler Marshaler) error { - if len(mime) == 0 { - return errors.New("empty MIME type") - } - - m.mimeMap[mime] = marshaler - - return nil -} - -// makeMarshalerMIMERegistry returns a new registry of marshalers. -// It allows for a mapping of case-sensitive Content-Type MIME type string to runtime.Marshaler interfaces. -// -// For example, you could allow the client to specify the use of the runtime.JSONPb marshaler -// with a "application/jsonpb" Content-Type and the use of the runtime.JSONBuiltin marshaler -// with a "application/json" Content-Type. -// "*" can be used to match any Content-Type. -// This can be attached to a ServerMux with the marshaler option. -func makeMarshalerMIMERegistry() marshalerRegistry { - return marshalerRegistry{ - mimeMap: map[string]Marshaler{ - MIMEWildcard: defaultMarshaler, - }, - } -} - -// WithMarshalerOption returns a ServeMuxOption which associates inbound and outbound -// Marshalers to a MIME type in mux. -func WithMarshalerOption(mime string, marshaler Marshaler) ServeMuxOption { - return func(mux *ServeMux) { - if err := mux.marshalers.add(mime, marshaler); err != nil { - panic(err) - } - } -} diff --git a/vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/mux.go b/vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/mux.go deleted file mode 100644 index 523a9cb43c..0000000000 --- a/vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/mux.go +++ /dev/null @@ -1,300 +0,0 @@ -package runtime - -import ( - "context" - "fmt" - "net/http" - "net/textproto" - "strings" - - "github.com/golang/protobuf/proto" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/metadata" - "google.golang.org/grpc/status" -) - -// A HandlerFunc handles a specific pair of path pattern and HTTP method. -type HandlerFunc func(w http.ResponseWriter, r *http.Request, pathParams map[string]string) - -// ErrUnknownURI is the error supplied to a custom ProtoErrorHandlerFunc when -// a request is received with a URI path that does not match any registered -// service method. -// -// Since gRPC servers return an "Unimplemented" code for requests with an -// unrecognized URI path, this error also has a gRPC "Unimplemented" code. -var ErrUnknownURI = status.Error(codes.Unimplemented, http.StatusText(http.StatusNotImplemented)) - -// ServeMux is a request multiplexer for grpc-gateway. -// It matches http requests to patterns and invokes the corresponding handler. -type ServeMux struct { - // handlers maps HTTP method to a list of handlers. - handlers map[string][]handler - forwardResponseOptions []func(context.Context, http.ResponseWriter, proto.Message) error - marshalers marshalerRegistry - incomingHeaderMatcher HeaderMatcherFunc - outgoingHeaderMatcher HeaderMatcherFunc - metadataAnnotators []func(context.Context, *http.Request) metadata.MD - streamErrorHandler StreamErrorHandlerFunc - protoErrorHandler ProtoErrorHandlerFunc - disablePathLengthFallback bool - lastMatchWins bool -} - -// ServeMuxOption is an option that can be given to a ServeMux on construction. -type ServeMuxOption func(*ServeMux) - -// WithForwardResponseOption returns a ServeMuxOption representing the forwardResponseOption. -// -// forwardResponseOption is an option that will be called on the relevant context.Context, -// http.ResponseWriter, and proto.Message before every forwarded response. -// -// The message may be nil in the case where just a header is being sent. -func WithForwardResponseOption(forwardResponseOption func(context.Context, http.ResponseWriter, proto.Message) error) ServeMuxOption { - return func(serveMux *ServeMux) { - serveMux.forwardResponseOptions = append(serveMux.forwardResponseOptions, forwardResponseOption) - } -} - -// SetQueryParameterParser sets the query parameter parser, used to populate message from query parameters. -// Configuring this will mean the generated swagger output is no longer correct, and it should be -// done with careful consideration. -func SetQueryParameterParser(queryParameterParser QueryParameterParser) ServeMuxOption { - return func(serveMux *ServeMux) { - currentQueryParser = queryParameterParser - } -} - -// HeaderMatcherFunc checks whether a header key should be forwarded to/from gRPC context. -type HeaderMatcherFunc func(string) (string, bool) - -// DefaultHeaderMatcher is used to pass http request headers to/from gRPC context. This adds permanent HTTP header -// keys (as specified by the IANA) to gRPC context with grpcgateway- prefix. HTTP headers that start with -// 'Grpc-Metadata-' are mapped to gRPC metadata after removing prefix 'Grpc-Metadata-'. -func DefaultHeaderMatcher(key string) (string, bool) { - key = textproto.CanonicalMIMEHeaderKey(key) - if isPermanentHTTPHeader(key) { - return MetadataPrefix + key, true - } else if strings.HasPrefix(key, MetadataHeaderPrefix) { - return key[len(MetadataHeaderPrefix):], true - } - return "", false -} - -// WithIncomingHeaderMatcher returns a ServeMuxOption representing a headerMatcher for incoming request to gateway. -// -// This matcher will be called with each header in http.Request. If matcher returns true, that header will be -// passed to gRPC context. To transform the header before passing to gRPC context, matcher should return modified header. -func WithIncomingHeaderMatcher(fn HeaderMatcherFunc) ServeMuxOption { - return func(mux *ServeMux) { - mux.incomingHeaderMatcher = fn - } -} - -// WithOutgoingHeaderMatcher returns a ServeMuxOption representing a headerMatcher for outgoing response from gateway. -// -// This matcher will be called with each header in response header metadata. If matcher returns true, that header will be -// passed to http response returned from gateway. To transform the header before passing to response, -// matcher should return modified header. -func WithOutgoingHeaderMatcher(fn HeaderMatcherFunc) ServeMuxOption { - return func(mux *ServeMux) { - mux.outgoingHeaderMatcher = fn - } -} - -// WithMetadata returns a ServeMuxOption for passing metadata to a gRPC context. -// -// This can be used by services that need to read from http.Request and modify gRPC context. A common use case -// is reading token from cookie and adding it in gRPC context. -func WithMetadata(annotator func(context.Context, *http.Request) metadata.MD) ServeMuxOption { - return func(serveMux *ServeMux) { - serveMux.metadataAnnotators = append(serveMux.metadataAnnotators, annotator) - } -} - -// WithProtoErrorHandler returns a ServeMuxOption for configuring a custom error handler. -// -// This can be used to handle an error as general proto message defined by gRPC. -// When this option is used, the mux uses the configured error handler instead of HTTPError and -// OtherErrorHandler. -func WithProtoErrorHandler(fn ProtoErrorHandlerFunc) ServeMuxOption { - return func(serveMux *ServeMux) { - serveMux.protoErrorHandler = fn - } -} - -// WithDisablePathLengthFallback returns a ServeMuxOption for disable path length fallback. -func WithDisablePathLengthFallback() ServeMuxOption { - return func(serveMux *ServeMux) { - serveMux.disablePathLengthFallback = true - } -} - -// WithStreamErrorHandler returns a ServeMuxOption that will use the given custom stream -// error handler, which allows for customizing the error trailer for server-streaming -// calls. -// -// For stream errors that occur before any response has been written, the mux's -// ProtoErrorHandler will be invoked. However, once data has been written, the errors must -// be handled differently: they must be included in the response body. The response body's -// final message will include the error details returned by the stream error handler. -func WithStreamErrorHandler(fn StreamErrorHandlerFunc) ServeMuxOption { - return func(serveMux *ServeMux) { - serveMux.streamErrorHandler = fn - } -} - -// WithLastMatchWins returns a ServeMuxOption that will enable "last -// match wins" behavior, where if multiple path patterns match a -// request path, the last one defined in the .proto file will be used. -func WithLastMatchWins() ServeMuxOption { - return func(serveMux *ServeMux) { - serveMux.lastMatchWins = true - } -} - -// NewServeMux returns a new ServeMux whose internal mapping is empty. -func NewServeMux(opts ...ServeMuxOption) *ServeMux { - serveMux := &ServeMux{ - handlers: make(map[string][]handler), - forwardResponseOptions: make([]func(context.Context, http.ResponseWriter, proto.Message) error, 0), - marshalers: makeMarshalerMIMERegistry(), - streamErrorHandler: DefaultHTTPStreamErrorHandler, - } - - for _, opt := range opts { - opt(serveMux) - } - - if serveMux.incomingHeaderMatcher == nil { - serveMux.incomingHeaderMatcher = DefaultHeaderMatcher - } - - if serveMux.outgoingHeaderMatcher == nil { - serveMux.outgoingHeaderMatcher = func(key string) (string, bool) { - return fmt.Sprintf("%s%s", MetadataHeaderPrefix, key), true - } - } - - return serveMux -} - -// Handle associates "h" to the pair of HTTP method and path pattern. -func (s *ServeMux) Handle(meth string, pat Pattern, h HandlerFunc) { - if s.lastMatchWins { - s.handlers[meth] = append([]handler{handler{pat: pat, h: h}}, s.handlers[meth]...) - } else { - s.handlers[meth] = append(s.handlers[meth], handler{pat: pat, h: h}) - } -} - -// ServeHTTP dispatches the request to the first handler whose pattern matches to r.Method and r.Path. -func (s *ServeMux) ServeHTTP(w http.ResponseWriter, r *http.Request) { - ctx := r.Context() - - path := r.URL.Path - if !strings.HasPrefix(path, "/") { - if s.protoErrorHandler != nil { - _, outboundMarshaler := MarshalerForRequest(s, r) - sterr := status.Error(codes.InvalidArgument, http.StatusText(http.StatusBadRequest)) - s.protoErrorHandler(ctx, s, outboundMarshaler, w, r, sterr) - } else { - OtherErrorHandler(w, r, http.StatusText(http.StatusBadRequest), http.StatusBadRequest) - } - return - } - - components := strings.Split(path[1:], "/") - l := len(components) - var verb string - if idx := strings.LastIndex(components[l-1], ":"); idx == 0 { - if s.protoErrorHandler != nil { - _, outboundMarshaler := MarshalerForRequest(s, r) - s.protoErrorHandler(ctx, s, outboundMarshaler, w, r, ErrUnknownURI) - } else { - OtherErrorHandler(w, r, http.StatusText(http.StatusNotFound), http.StatusNotFound) - } - return - } else if idx > 0 { - c := components[l-1] - components[l-1], verb = c[:idx], c[idx+1:] - } - - if override := r.Header.Get("X-HTTP-Method-Override"); override != "" && s.isPathLengthFallback(r) { - r.Method = strings.ToUpper(override) - if err := r.ParseForm(); err != nil { - if s.protoErrorHandler != nil { - _, outboundMarshaler := MarshalerForRequest(s, r) - sterr := status.Error(codes.InvalidArgument, err.Error()) - s.protoErrorHandler(ctx, s, outboundMarshaler, w, r, sterr) - } else { - OtherErrorHandler(w, r, err.Error(), http.StatusBadRequest) - } - return - } - } - for _, h := range s.handlers[r.Method] { - pathParams, err := h.pat.Match(components, verb) - if err != nil { - continue - } - h.h(w, r, pathParams) - return - } - - // lookup other methods to handle fallback from GET to POST and - // to determine if it is MethodNotAllowed or NotFound. - for m, handlers := range s.handlers { - if m == r.Method { - continue - } - for _, h := range handlers { - pathParams, err := h.pat.Match(components, verb) - if err != nil { - continue - } - // X-HTTP-Method-Override is optional. Always allow fallback to POST. - if s.isPathLengthFallback(r) { - if err := r.ParseForm(); err != nil { - if s.protoErrorHandler != nil { - _, outboundMarshaler := MarshalerForRequest(s, r) - sterr := status.Error(codes.InvalidArgument, err.Error()) - s.protoErrorHandler(ctx, s, outboundMarshaler, w, r, sterr) - } else { - OtherErrorHandler(w, r, err.Error(), http.StatusBadRequest) - } - return - } - h.h(w, r, pathParams) - return - } - if s.protoErrorHandler != nil { - _, outboundMarshaler := MarshalerForRequest(s, r) - s.protoErrorHandler(ctx, s, outboundMarshaler, w, r, ErrUnknownURI) - } else { - OtherErrorHandler(w, r, http.StatusText(http.StatusMethodNotAllowed), http.StatusMethodNotAllowed) - } - return - } - } - - if s.protoErrorHandler != nil { - _, outboundMarshaler := MarshalerForRequest(s, r) - s.protoErrorHandler(ctx, s, outboundMarshaler, w, r, ErrUnknownURI) - } else { - OtherErrorHandler(w, r, http.StatusText(http.StatusNotFound), http.StatusNotFound) - } -} - -// GetForwardResponseOptions returns the ForwardResponseOptions associated with this ServeMux. -func (s *ServeMux) GetForwardResponseOptions() []func(context.Context, http.ResponseWriter, proto.Message) error { - return s.forwardResponseOptions -} - -func (s *ServeMux) isPathLengthFallback(r *http.Request) bool { - return !s.disablePathLengthFallback && r.Method == "POST" && r.Header.Get("Content-Type") == "application/x-www-form-urlencoded" -} - -type handler struct { - pat Pattern - h HandlerFunc -} diff --git a/vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/pattern.go b/vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/pattern.go deleted file mode 100644 index 09053695da..0000000000 --- a/vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/pattern.go +++ /dev/null @@ -1,262 +0,0 @@ -package runtime - -import ( - "errors" - "fmt" - "strings" - - "github.com/grpc-ecosystem/grpc-gateway/utilities" - "google.golang.org/grpc/grpclog" -) - -var ( - // ErrNotMatch indicates that the given HTTP request path does not match to the pattern. - ErrNotMatch = errors.New("not match to the path pattern") - // ErrInvalidPattern indicates that the given definition of Pattern is not valid. - ErrInvalidPattern = errors.New("invalid pattern") -) - -type op struct { - code utilities.OpCode - operand int -} - -// Pattern is a template pattern of http request paths defined in github.com/googleapis/googleapis/google/api/http.proto. -type Pattern struct { - // ops is a list of operations - ops []op - // pool is a constant pool indexed by the operands or vars. - pool []string - // vars is a list of variables names to be bound by this pattern - vars []string - // stacksize is the max depth of the stack - stacksize int - // tailLen is the length of the fixed-size segments after a deep wildcard - tailLen int - // verb is the VERB part of the path pattern. It is empty if the pattern does not have VERB part. - verb string - // assumeColonVerb indicates whether a path suffix after a final - // colon may only be interpreted as a verb. - assumeColonVerb bool -} - -type patternOptions struct { - assumeColonVerb bool -} - -// PatternOpt is an option for creating Patterns. -type PatternOpt func(*patternOptions) - -// NewPattern returns a new Pattern from the given definition values. -// "ops" is a sequence of op codes. "pool" is a constant pool. -// "verb" is the verb part of the pattern. It is empty if the pattern does not have the part. -// "version" must be 1 for now. -// It returns an error if the given definition is invalid. -func NewPattern(version int, ops []int, pool []string, verb string, opts ...PatternOpt) (Pattern, error) { - options := patternOptions{ - assumeColonVerb: true, - } - for _, o := range opts { - o(&options) - } - - if version != 1 { - grpclog.Infof("unsupported version: %d", version) - return Pattern{}, ErrInvalidPattern - } - - l := len(ops) - if l%2 != 0 { - grpclog.Infof("odd number of ops codes: %d", l) - return Pattern{}, ErrInvalidPattern - } - - var ( - typedOps []op - stack, maxstack int - tailLen int - pushMSeen bool - vars []string - ) - for i := 0; i < l; i += 2 { - op := op{code: utilities.OpCode(ops[i]), operand: ops[i+1]} - switch op.code { - case utilities.OpNop: - continue - case utilities.OpPush: - if pushMSeen { - tailLen++ - } - stack++ - case utilities.OpPushM: - if pushMSeen { - grpclog.Infof("pushM appears twice") - return Pattern{}, ErrInvalidPattern - } - pushMSeen = true - stack++ - case utilities.OpLitPush: - if op.operand < 0 || len(pool) <= op.operand { - grpclog.Infof("negative literal index: %d", op.operand) - return Pattern{}, ErrInvalidPattern - } - if pushMSeen { - tailLen++ - } - stack++ - case utilities.OpConcatN: - if op.operand <= 0 { - grpclog.Infof("negative concat size: %d", op.operand) - return Pattern{}, ErrInvalidPattern - } - stack -= op.operand - if stack < 0 { - grpclog.Print("stack underflow") - return Pattern{}, ErrInvalidPattern - } - stack++ - case utilities.OpCapture: - if op.operand < 0 || len(pool) <= op.operand { - grpclog.Infof("variable name index out of bound: %d", op.operand) - return Pattern{}, ErrInvalidPattern - } - v := pool[op.operand] - op.operand = len(vars) - vars = append(vars, v) - stack-- - if stack < 0 { - grpclog.Infof("stack underflow") - return Pattern{}, ErrInvalidPattern - } - default: - grpclog.Infof("invalid opcode: %d", op.code) - return Pattern{}, ErrInvalidPattern - } - - if maxstack < stack { - maxstack = stack - } - typedOps = append(typedOps, op) - } - return Pattern{ - ops: typedOps, - pool: pool, - vars: vars, - stacksize: maxstack, - tailLen: tailLen, - verb: verb, - assumeColonVerb: options.assumeColonVerb, - }, nil -} - -// MustPattern is a helper function which makes it easier to call NewPattern in variable initialization. -func MustPattern(p Pattern, err error) Pattern { - if err != nil { - grpclog.Fatalf("Pattern initialization failed: %v", err) - } - return p -} - -// Match examines components if it matches to the Pattern. -// If it matches, the function returns a mapping from field paths to their captured values. -// If otherwise, the function returns an error. -func (p Pattern) Match(components []string, verb string) (map[string]string, error) { - if p.verb != verb { - if p.assumeColonVerb || p.verb != "" { - return nil, ErrNotMatch - } - if len(components) == 0 { - components = []string{":" + verb} - } else { - components = append([]string{}, components...) - components[len(components)-1] += ":" + verb - } - verb = "" - } - - var pos int - stack := make([]string, 0, p.stacksize) - captured := make([]string, len(p.vars)) - l := len(components) - for _, op := range p.ops { - switch op.code { - case utilities.OpNop: - continue - case utilities.OpPush, utilities.OpLitPush: - if pos >= l { - return nil, ErrNotMatch - } - c := components[pos] - if op.code == utilities.OpLitPush { - if lit := p.pool[op.operand]; c != lit { - return nil, ErrNotMatch - } - } - stack = append(stack, c) - pos++ - case utilities.OpPushM: - end := len(components) - if end < pos+p.tailLen { - return nil, ErrNotMatch - } - end -= p.tailLen - stack = append(stack, strings.Join(components[pos:end], "/")) - pos = end - case utilities.OpConcatN: - n := op.operand - l := len(stack) - n - stack = append(stack[:l], strings.Join(stack[l:], "/")) - case utilities.OpCapture: - n := len(stack) - 1 - captured[op.operand] = stack[n] - stack = stack[:n] - } - } - if pos < l { - return nil, ErrNotMatch - } - bindings := make(map[string]string) - for i, val := range captured { - bindings[p.vars[i]] = val - } - return bindings, nil -} - -// Verb returns the verb part of the Pattern. -func (p Pattern) Verb() string { return p.verb } - -func (p Pattern) String() string { - var stack []string - for _, op := range p.ops { - switch op.code { - case utilities.OpNop: - continue - case utilities.OpPush: - stack = append(stack, "*") - case utilities.OpLitPush: - stack = append(stack, p.pool[op.operand]) - case utilities.OpPushM: - stack = append(stack, "**") - case utilities.OpConcatN: - n := op.operand - l := len(stack) - n - stack = append(stack[:l], strings.Join(stack[l:], "/")) - case utilities.OpCapture: - n := len(stack) - 1 - stack[n] = fmt.Sprintf("{%s=%s}", p.vars[op.operand], stack[n]) - } - } - segs := strings.Join(stack, "/") - if p.verb != "" { - return fmt.Sprintf("/%s:%s", segs, p.verb) - } - return "/" + segs -} - -// AssumeColonVerbOpt indicates whether a path suffix after a final -// colon may only be interpreted as a verb. -func AssumeColonVerbOpt(val bool) PatternOpt { - return PatternOpt(func(o *patternOptions) { - o.assumeColonVerb = val - }) -} diff --git a/vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/proto2_convert.go b/vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/proto2_convert.go deleted file mode 100644 index a3151e2a55..0000000000 --- a/vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/proto2_convert.go +++ /dev/null @@ -1,80 +0,0 @@ -package runtime - -import ( - "github.com/golang/protobuf/proto" -) - -// StringP returns a pointer to a string whose pointee is same as the given string value. -func StringP(val string) (*string, error) { - return proto.String(val), nil -} - -// BoolP parses the given string representation of a boolean value, -// and returns a pointer to a bool whose value is same as the parsed value. -func BoolP(val string) (*bool, error) { - b, err := Bool(val) - if err != nil { - return nil, err - } - return proto.Bool(b), nil -} - -// Float64P parses the given string representation of a floating point number, -// and returns a pointer to a float64 whose value is same as the parsed number. -func Float64P(val string) (*float64, error) { - f, err := Float64(val) - if err != nil { - return nil, err - } - return proto.Float64(f), nil -} - -// Float32P parses the given string representation of a floating point number, -// and returns a pointer to a float32 whose value is same as the parsed number. -func Float32P(val string) (*float32, error) { - f, err := Float32(val) - if err != nil { - return nil, err - } - return proto.Float32(f), nil -} - -// Int64P parses the given string representation of an integer -// and returns a pointer to a int64 whose value is same as the parsed integer. -func Int64P(val string) (*int64, error) { - i, err := Int64(val) - if err != nil { - return nil, err - } - return proto.Int64(i), nil -} - -// Int32P parses the given string representation of an integer -// and returns a pointer to a int32 whose value is same as the parsed integer. -func Int32P(val string) (*int32, error) { - i, err := Int32(val) - if err != nil { - return nil, err - } - return proto.Int32(i), err -} - -// Uint64P parses the given string representation of an integer -// and returns a pointer to a uint64 whose value is same as the parsed integer. -func Uint64P(val string) (*uint64, error) { - i, err := Uint64(val) - if err != nil { - return nil, err - } - return proto.Uint64(i), err -} - -// Uint32P parses the given string representation of an integer -// and returns a pointer to a uint32 whose value is same as the parsed integer. -func Uint32P(val string) (*uint32, error) { - i, err := Uint32(val) - if err != nil { - return nil, err - } - return proto.Uint32(i), err -} diff --git a/vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/proto_errors.go b/vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/proto_errors.go deleted file mode 100644 index 3fd30da22a..0000000000 --- a/vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/proto_errors.go +++ /dev/null @@ -1,106 +0,0 @@ -package runtime - -import ( - "context" - "io" - "net/http" - - "github.com/golang/protobuf/ptypes/any" - "github.com/grpc-ecosystem/grpc-gateway/internal" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/grpclog" - "google.golang.org/grpc/status" -) - -// StreamErrorHandlerFunc accepts an error as a gRPC error generated via status package and translates it into a -// a proto struct used to represent error at the end of a stream. -type StreamErrorHandlerFunc func(context.Context, error) *StreamError - -// StreamError is the payload for the final message in a server stream in the event that the server returns an -// error after a response message has already been sent. -type StreamError internal.StreamError - -// ProtoErrorHandlerFunc handles the error as a gRPC error generated via status package and replies to the request. -type ProtoErrorHandlerFunc func(context.Context, *ServeMux, Marshaler, http.ResponseWriter, *http.Request, error) - -var _ ProtoErrorHandlerFunc = DefaultHTTPProtoErrorHandler - -// DefaultHTTPProtoErrorHandler is an implementation of HTTPError. -// If "err" is an error from gRPC system, the function replies with the status code mapped by HTTPStatusFromCode. -// If otherwise, it replies with http.StatusInternalServerError. -// -// The response body returned by this function is a Status message marshaled by a Marshaler. -// -// Do not set this function to HTTPError variable directly, use WithProtoErrorHandler option instead. -func DefaultHTTPProtoErrorHandler(ctx context.Context, mux *ServeMux, marshaler Marshaler, w http.ResponseWriter, _ *http.Request, err error) { - // return Internal when Marshal failed - const fallback = `{"code": 13, "message": "failed to marshal error message"}` - - s, ok := status.FromError(err) - if !ok { - s = status.New(codes.Unknown, err.Error()) - } - - w.Header().Del("Trailer") - - contentType := marshaler.ContentType() - // Check marshaler on run time in order to keep backwards compatibility - // An interface param needs to be added to the ContentType() function on - // the Marshal interface to be able to remove this check - if typeMarshaler, ok := marshaler.(contentTypeMarshaler); ok { - pb := s.Proto() - contentType = typeMarshaler.ContentTypeFromMessage(pb) - } - w.Header().Set("Content-Type", contentType) - - buf, merr := marshaler.Marshal(s.Proto()) - if merr != nil { - grpclog.Infof("Failed to marshal error message %q: %v", s.Proto(), merr) - w.WriteHeader(http.StatusInternalServerError) - if _, err := io.WriteString(w, fallback); err != nil { - grpclog.Infof("Failed to write response: %v", err) - } - return - } - - md, ok := ServerMetadataFromContext(ctx) - if !ok { - grpclog.Infof("Failed to extract ServerMetadata from context") - } - - handleForwardResponseServerMetadata(w, mux, md) - handleForwardResponseTrailerHeader(w, md) - st := HTTPStatusFromCode(s.Code()) - w.WriteHeader(st) - if _, err := w.Write(buf); err != nil { - grpclog.Infof("Failed to write response: %v", err) - } - - handleForwardResponseTrailer(w, md) -} - -// DefaultHTTPStreamErrorHandler converts the given err into a *StreamError via -// default logic. -// -// It extracts the gRPC status from err if possible. The fields of the status are -// used to populate the returned StreamError, and the HTTP status code is derived -// from the gRPC code via HTTPStatusFromCode. If the given err does not contain a -// gRPC status, an "Unknown" gRPC code is used and "Internal Server Error" HTTP code. -func DefaultHTTPStreamErrorHandler(_ context.Context, err error) *StreamError { - grpcCode := codes.Unknown - grpcMessage := err.Error() - var grpcDetails []*any.Any - if s, ok := status.FromError(err); ok { - grpcCode = s.Code() - grpcMessage = s.Message() - grpcDetails = s.Proto().GetDetails() - } - httpCode := HTTPStatusFromCode(grpcCode) - return &StreamError{ - GrpcCode: int32(grpcCode), - HttpCode: int32(httpCode), - Message: grpcMessage, - HttpStatus: http.StatusText(httpCode), - Details: grpcDetails, - } -} diff --git a/vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/query.go b/vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/query.go deleted file mode 100644 index ba66842c33..0000000000 --- a/vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/query.go +++ /dev/null @@ -1,406 +0,0 @@ -package runtime - -import ( - "encoding/base64" - "fmt" - "net/url" - "reflect" - "regexp" - "strconv" - "strings" - "time" - - "github.com/golang/protobuf/proto" - "github.com/grpc-ecosystem/grpc-gateway/utilities" - "google.golang.org/grpc/grpclog" -) - -var valuesKeyRegexp = regexp.MustCompile("^(.*)\\[(.*)\\]$") - -var currentQueryParser QueryParameterParser = &defaultQueryParser{} - -// QueryParameterParser defines interface for all query parameter parsers -type QueryParameterParser interface { - Parse(msg proto.Message, values url.Values, filter *utilities.DoubleArray) error -} - -// PopulateQueryParameters parses query parameters -// into "msg" using current query parser -func PopulateQueryParameters(msg proto.Message, values url.Values, filter *utilities.DoubleArray) error { - return currentQueryParser.Parse(msg, values, filter) -} - -type defaultQueryParser struct{} - -// Parse populates "values" into "msg". -// A value is ignored if its key starts with one of the elements in "filter". -func (*defaultQueryParser) Parse(msg proto.Message, values url.Values, filter *utilities.DoubleArray) error { - for key, values := range values { - match := valuesKeyRegexp.FindStringSubmatch(key) - if len(match) == 3 { - key = match[1] - values = append([]string{match[2]}, values...) - } - fieldPath := strings.Split(key, ".") - if filter.HasCommonPrefix(fieldPath) { - continue - } - if err := populateFieldValueFromPath(msg, fieldPath, values); err != nil { - return err - } - } - return nil -} - -// PopulateFieldFromPath sets a value in a nested Protobuf structure. -// It instantiates missing protobuf fields as it goes. -func PopulateFieldFromPath(msg proto.Message, fieldPathString string, value string) error { - fieldPath := strings.Split(fieldPathString, ".") - return populateFieldValueFromPath(msg, fieldPath, []string{value}) -} - -func populateFieldValueFromPath(msg proto.Message, fieldPath []string, values []string) error { - m := reflect.ValueOf(msg) - if m.Kind() != reflect.Ptr { - return fmt.Errorf("unexpected type %T: %v", msg, msg) - } - var props *proto.Properties - m = m.Elem() - for i, fieldName := range fieldPath { - isLast := i == len(fieldPath)-1 - if !isLast && m.Kind() != reflect.Struct { - return fmt.Errorf("non-aggregate type in the mid of path: %s", strings.Join(fieldPath, ".")) - } - var f reflect.Value - var err error - f, props, err = fieldByProtoName(m, fieldName) - if err != nil { - return err - } else if !f.IsValid() { - grpclog.Infof("field not found in %T: %s", msg, strings.Join(fieldPath, ".")) - return nil - } - - switch f.Kind() { - case reflect.Bool, reflect.Float32, reflect.Float64, reflect.Int32, reflect.Int64, reflect.String, reflect.Uint32, reflect.Uint64: - if !isLast { - return fmt.Errorf("unexpected nested field %s in %s", fieldPath[i+1], strings.Join(fieldPath[:i+1], ".")) - } - m = f - case reflect.Slice: - if !isLast { - return fmt.Errorf("unexpected repeated field in %s", strings.Join(fieldPath, ".")) - } - // Handle []byte - if f.Type().Elem().Kind() == reflect.Uint8 { - m = f - break - } - return populateRepeatedField(f, values, props) - case reflect.Ptr: - if f.IsNil() { - m = reflect.New(f.Type().Elem()) - f.Set(m.Convert(f.Type())) - } - m = f.Elem() - continue - case reflect.Struct: - m = f - continue - case reflect.Map: - if !isLast { - return fmt.Errorf("unexpected nested field %s in %s", fieldPath[i+1], strings.Join(fieldPath[:i+1], ".")) - } - return populateMapField(f, values, props) - default: - return fmt.Errorf("unexpected type %s in %T", f.Type(), msg) - } - } - switch len(values) { - case 0: - return fmt.Errorf("no value of field: %s", strings.Join(fieldPath, ".")) - case 1: - default: - grpclog.Infof("too many field values: %s", strings.Join(fieldPath, ".")) - } - return populateField(m, values[0], props) -} - -// fieldByProtoName looks up a field whose corresponding protobuf field name is "name". -// "m" must be a struct value. It returns zero reflect.Value if no such field found. -func fieldByProtoName(m reflect.Value, name string) (reflect.Value, *proto.Properties, error) { - props := proto.GetProperties(m.Type()) - - // look up field name in oneof map - for _, op := range props.OneofTypes { - if name == op.Prop.OrigName || name == op.Prop.JSONName { - v := reflect.New(op.Type.Elem()) - field := m.Field(op.Field) - if !field.IsNil() { - return reflect.Value{}, nil, fmt.Errorf("field already set for %s oneof", props.Prop[op.Field].OrigName) - } - field.Set(v) - return v.Elem().Field(0), op.Prop, nil - } - } - - for _, p := range props.Prop { - if p.OrigName == name { - return m.FieldByName(p.Name), p, nil - } - if p.JSONName == name { - return m.FieldByName(p.Name), p, nil - } - } - return reflect.Value{}, nil, nil -} - -func populateMapField(f reflect.Value, values []string, props *proto.Properties) error { - if len(values) != 2 { - return fmt.Errorf("more than one value provided for key %s in map %s", values[0], props.Name) - } - - key, value := values[0], values[1] - keyType := f.Type().Key() - valueType := f.Type().Elem() - if f.IsNil() { - f.Set(reflect.MakeMap(f.Type())) - } - - keyConv, ok := convFromType[keyType.Kind()] - if !ok { - return fmt.Errorf("unsupported key type %s in map %s", keyType, props.Name) - } - valueConv, ok := convFromType[valueType.Kind()] - if !ok { - return fmt.Errorf("unsupported value type %s in map %s", valueType, props.Name) - } - - keyV := keyConv.Call([]reflect.Value{reflect.ValueOf(key)}) - if err := keyV[1].Interface(); err != nil { - return err.(error) - } - valueV := valueConv.Call([]reflect.Value{reflect.ValueOf(value)}) - if err := valueV[1].Interface(); err != nil { - return err.(error) - } - - f.SetMapIndex(keyV[0].Convert(keyType), valueV[0].Convert(valueType)) - - return nil -} - -func populateRepeatedField(f reflect.Value, values []string, props *proto.Properties) error { - elemType := f.Type().Elem() - - // is the destination field a slice of an enumeration type? - if enumValMap := proto.EnumValueMap(props.Enum); enumValMap != nil { - return populateFieldEnumRepeated(f, values, enumValMap) - } - - conv, ok := convFromType[elemType.Kind()] - if !ok { - return fmt.Errorf("unsupported field type %s", elemType) - } - f.Set(reflect.MakeSlice(f.Type(), len(values), len(values)).Convert(f.Type())) - for i, v := range values { - result := conv.Call([]reflect.Value{reflect.ValueOf(v)}) - if err := result[1].Interface(); err != nil { - return err.(error) - } - f.Index(i).Set(result[0].Convert(f.Index(i).Type())) - } - return nil -} - -func populateField(f reflect.Value, value string, props *proto.Properties) error { - i := f.Addr().Interface() - - // Handle protobuf well known types - var name string - switch m := i.(type) { - case interface{ XXX_WellKnownType() string }: - name = m.XXX_WellKnownType() - case proto.Message: - const wktPrefix = "google.protobuf." - if fullName := proto.MessageName(m); strings.HasPrefix(fullName, wktPrefix) { - name = fullName[len(wktPrefix):] - } - } - switch name { - case "Timestamp": - if value == "null" { - f.FieldByName("Seconds").SetInt(0) - f.FieldByName("Nanos").SetInt(0) - return nil - } - - t, err := time.Parse(time.RFC3339Nano, value) - if err != nil { - return fmt.Errorf("bad Timestamp: %v", err) - } - f.FieldByName("Seconds").SetInt(int64(t.Unix())) - f.FieldByName("Nanos").SetInt(int64(t.Nanosecond())) - return nil - case "Duration": - if value == "null" { - f.FieldByName("Seconds").SetInt(0) - f.FieldByName("Nanos").SetInt(0) - return nil - } - d, err := time.ParseDuration(value) - if err != nil { - return fmt.Errorf("bad Duration: %v", err) - } - - ns := d.Nanoseconds() - s := ns / 1e9 - ns %= 1e9 - f.FieldByName("Seconds").SetInt(s) - f.FieldByName("Nanos").SetInt(ns) - return nil - case "DoubleValue": - fallthrough - case "FloatValue": - float64Val, err := strconv.ParseFloat(value, 64) - if err != nil { - return fmt.Errorf("bad DoubleValue: %s", value) - } - f.FieldByName("Value").SetFloat(float64Val) - return nil - case "Int64Value": - fallthrough - case "Int32Value": - int64Val, err := strconv.ParseInt(value, 10, 64) - if err != nil { - return fmt.Errorf("bad DoubleValue: %s", value) - } - f.FieldByName("Value").SetInt(int64Val) - return nil - case "UInt64Value": - fallthrough - case "UInt32Value": - uint64Val, err := strconv.ParseUint(value, 10, 64) - if err != nil { - return fmt.Errorf("bad DoubleValue: %s", value) - } - f.FieldByName("Value").SetUint(uint64Val) - return nil - case "BoolValue": - if value == "true" { - f.FieldByName("Value").SetBool(true) - } else if value == "false" { - f.FieldByName("Value").SetBool(false) - } else { - return fmt.Errorf("bad BoolValue: %s", value) - } - return nil - case "StringValue": - f.FieldByName("Value").SetString(value) - return nil - case "BytesValue": - bytesVal, err := base64.StdEncoding.DecodeString(value) - if err != nil { - return fmt.Errorf("bad BytesValue: %s", value) - } - f.FieldByName("Value").SetBytes(bytesVal) - return nil - case "FieldMask": - p := f.FieldByName("Paths") - for _, v := range strings.Split(value, ",") { - if v != "" { - p.Set(reflect.Append(p, reflect.ValueOf(v))) - } - } - return nil - } - - // Handle Time and Duration stdlib types - switch t := i.(type) { - case *time.Time: - pt, err := time.Parse(time.RFC3339Nano, value) - if err != nil { - return fmt.Errorf("bad Timestamp: %v", err) - } - *t = pt - return nil - case *time.Duration: - d, err := time.ParseDuration(value) - if err != nil { - return fmt.Errorf("bad Duration: %v", err) - } - *t = d - return nil - } - - // is the destination field an enumeration type? - if enumValMap := proto.EnumValueMap(props.Enum); enumValMap != nil { - return populateFieldEnum(f, value, enumValMap) - } - - conv, ok := convFromType[f.Kind()] - if !ok { - return fmt.Errorf("field type %T is not supported in query parameters", i) - } - result := conv.Call([]reflect.Value{reflect.ValueOf(value)}) - if err := result[1].Interface(); err != nil { - return err.(error) - } - f.Set(result[0].Convert(f.Type())) - return nil -} - -func convertEnum(value string, t reflect.Type, enumValMap map[string]int32) (reflect.Value, error) { - // see if it's an enumeration string - if enumVal, ok := enumValMap[value]; ok { - return reflect.ValueOf(enumVal).Convert(t), nil - } - - // check for an integer that matches an enumeration value - eVal, err := strconv.Atoi(value) - if err != nil { - return reflect.Value{}, fmt.Errorf("%s is not a valid %s", value, t) - } - for _, v := range enumValMap { - if v == int32(eVal) { - return reflect.ValueOf(eVal).Convert(t), nil - } - } - return reflect.Value{}, fmt.Errorf("%s is not a valid %s", value, t) -} - -func populateFieldEnum(f reflect.Value, value string, enumValMap map[string]int32) error { - cval, err := convertEnum(value, f.Type(), enumValMap) - if err != nil { - return err - } - f.Set(cval) - return nil -} - -func populateFieldEnumRepeated(f reflect.Value, values []string, enumValMap map[string]int32) error { - elemType := f.Type().Elem() - f.Set(reflect.MakeSlice(f.Type(), len(values), len(values)).Convert(f.Type())) - for i, v := range values { - result, err := convertEnum(v, elemType, enumValMap) - if err != nil { - return err - } - f.Index(i).Set(result) - } - return nil -} - -var ( - convFromType = map[reflect.Kind]reflect.Value{ - reflect.String: reflect.ValueOf(String), - reflect.Bool: reflect.ValueOf(Bool), - reflect.Float64: reflect.ValueOf(Float64), - reflect.Float32: reflect.ValueOf(Float32), - reflect.Int64: reflect.ValueOf(Int64), - reflect.Int32: reflect.ValueOf(Int32), - reflect.Uint64: reflect.ValueOf(Uint64), - reflect.Uint32: reflect.ValueOf(Uint32), - reflect.Slice: reflect.ValueOf(Bytes), - } -) diff --git a/vendor/github.com/grpc-ecosystem/grpc-gateway/utilities/BUILD.bazel b/vendor/github.com/grpc-ecosystem/grpc-gateway/utilities/BUILD.bazel deleted file mode 100644 index 7109d79323..0000000000 --- a/vendor/github.com/grpc-ecosystem/grpc-gateway/utilities/BUILD.bazel +++ /dev/null @@ -1,21 +0,0 @@ -load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") - -package(default_visibility = ["//visibility:public"]) - -go_library( - name = "go_default_library", - srcs = [ - "doc.go", - "pattern.go", - "readerfactory.go", - "trie.go", - ], - importpath = "github.com/grpc-ecosystem/grpc-gateway/utilities", -) - -go_test( - name = "go_default_test", - size = "small", - srcs = ["trie_test.go"], - embed = [":go_default_library"], -) diff --git a/vendor/github.com/grpc-ecosystem/grpc-gateway/utilities/doc.go b/vendor/github.com/grpc-ecosystem/grpc-gateway/utilities/doc.go deleted file mode 100644 index cf79a4d588..0000000000 --- a/vendor/github.com/grpc-ecosystem/grpc-gateway/utilities/doc.go +++ /dev/null @@ -1,2 +0,0 @@ -// Package utilities provides members for internal use in grpc-gateway. -package utilities diff --git a/vendor/github.com/grpc-ecosystem/grpc-gateway/utilities/pattern.go b/vendor/github.com/grpc-ecosystem/grpc-gateway/utilities/pattern.go deleted file mode 100644 index dfe7de4864..0000000000 --- a/vendor/github.com/grpc-ecosystem/grpc-gateway/utilities/pattern.go +++ /dev/null @@ -1,22 +0,0 @@ -package utilities - -// An OpCode is a opcode of compiled path patterns. -type OpCode int - -// These constants are the valid values of OpCode. -const ( - // OpNop does nothing - OpNop = OpCode(iota) - // OpPush pushes a component to stack - OpPush - // OpLitPush pushes a component to stack if it matches to the literal - OpLitPush - // OpPushM concatenates the remaining components and pushes it to stack - OpPushM - // OpConcatN pops N items from stack, concatenates them and pushes it back to stack - OpConcatN - // OpCapture pops an item and binds it to the variable - OpCapture - // OpEnd is the least positive invalid opcode. - OpEnd -) diff --git a/vendor/github.com/grpc-ecosystem/grpc-gateway/utilities/readerfactory.go b/vendor/github.com/grpc-ecosystem/grpc-gateway/utilities/readerfactory.go deleted file mode 100644 index 6dd3854665..0000000000 --- a/vendor/github.com/grpc-ecosystem/grpc-gateway/utilities/readerfactory.go +++ /dev/null @@ -1,20 +0,0 @@ -package utilities - -import ( - "bytes" - "io" - "io/ioutil" -) - -// IOReaderFactory takes in an io.Reader and returns a function that will allow you to create a new reader that begins -// at the start of the stream -func IOReaderFactory(r io.Reader) (func() io.Reader, error) { - b, err := ioutil.ReadAll(r) - if err != nil { - return nil, err - } - - return func() io.Reader { - return bytes.NewReader(b) - }, nil -} diff --git a/vendor/github.com/grpc-ecosystem/grpc-gateway/utilities/trie.go b/vendor/github.com/grpc-ecosystem/grpc-gateway/utilities/trie.go deleted file mode 100644 index c2b7b30dd9..0000000000 --- a/vendor/github.com/grpc-ecosystem/grpc-gateway/utilities/trie.go +++ /dev/null @@ -1,177 +0,0 @@ -package utilities - -import ( - "sort" -) - -// DoubleArray is a Double Array implementation of trie on sequences of strings. -type DoubleArray struct { - // Encoding keeps an encoding from string to int - Encoding map[string]int - // Base is the base array of Double Array - Base []int - // Check is the check array of Double Array - Check []int -} - -// NewDoubleArray builds a DoubleArray from a set of sequences of strings. -func NewDoubleArray(seqs [][]string) *DoubleArray { - da := &DoubleArray{Encoding: make(map[string]int)} - if len(seqs) == 0 { - return da - } - - encoded := registerTokens(da, seqs) - sort.Sort(byLex(encoded)) - - root := node{row: -1, col: -1, left: 0, right: len(encoded)} - addSeqs(da, encoded, 0, root) - - for i := len(da.Base); i > 0; i-- { - if da.Check[i-1] != 0 { - da.Base = da.Base[:i] - da.Check = da.Check[:i] - break - } - } - return da -} - -func registerTokens(da *DoubleArray, seqs [][]string) [][]int { - var result [][]int - for _, seq := range seqs { - var encoded []int - for _, token := range seq { - if _, ok := da.Encoding[token]; !ok { - da.Encoding[token] = len(da.Encoding) - } - encoded = append(encoded, da.Encoding[token]) - } - result = append(result, encoded) - } - for i := range result { - result[i] = append(result[i], len(da.Encoding)) - } - return result -} - -type node struct { - row, col int - left, right int -} - -func (n node) value(seqs [][]int) int { - return seqs[n.row][n.col] -} - -func (n node) children(seqs [][]int) []*node { - var result []*node - lastVal := int(-1) - last := new(node) - for i := n.left; i < n.right; i++ { - if lastVal == seqs[i][n.col+1] { - continue - } - last.right = i - last = &node{ - row: i, - col: n.col + 1, - left: i, - } - result = append(result, last) - } - last.right = n.right - return result -} - -func addSeqs(da *DoubleArray, seqs [][]int, pos int, n node) { - ensureSize(da, pos) - - children := n.children(seqs) - var i int - for i = 1; ; i++ { - ok := func() bool { - for _, child := range children { - code := child.value(seqs) - j := i + code - ensureSize(da, j) - if da.Check[j] != 0 { - return false - } - } - return true - }() - if ok { - break - } - } - da.Base[pos] = i - for _, child := range children { - code := child.value(seqs) - j := i + code - da.Check[j] = pos + 1 - } - terminator := len(da.Encoding) - for _, child := range children { - code := child.value(seqs) - if code == terminator { - continue - } - j := i + code - addSeqs(da, seqs, j, *child) - } -} - -func ensureSize(da *DoubleArray, i int) { - for i >= len(da.Base) { - da.Base = append(da.Base, make([]int, len(da.Base)+1)...) - da.Check = append(da.Check, make([]int, len(da.Check)+1)...) - } -} - -type byLex [][]int - -func (l byLex) Len() int { return len(l) } -func (l byLex) Swap(i, j int) { l[i], l[j] = l[j], l[i] } -func (l byLex) Less(i, j int) bool { - si := l[i] - sj := l[j] - var k int - for k = 0; k < len(si) && k < len(sj); k++ { - if si[k] < sj[k] { - return true - } - if si[k] > sj[k] { - return false - } - } - if k < len(sj) { - return true - } - return false -} - -// HasCommonPrefix determines if any sequence in the DoubleArray is a prefix of the given sequence. -func (da *DoubleArray) HasCommonPrefix(seq []string) bool { - if len(da.Base) == 0 { - return false - } - - var i int - for _, t := range seq { - code, ok := da.Encoding[t] - if !ok { - break - } - j := da.Base[i] + code - if len(da.Check) <= j || da.Check[j] != i+1 { - break - } - i = j - } - j := da.Base[i] + len(da.Encoding) - if len(da.Check) <= j || da.Check[j] != i+1 { - return false - } - return true -} diff --git a/vendor/github.com/jonboulle/clockwork/.editorconfig b/vendor/github.com/jonboulle/clockwork/.editorconfig deleted file mode 100644 index 4492e9f9fe..0000000000 --- a/vendor/github.com/jonboulle/clockwork/.editorconfig +++ /dev/null @@ -1,12 +0,0 @@ -root = true - -[*] -charset = utf-8 -end_of_line = lf -indent_size = 4 -indent_style = space -insert_final_newline = true -trim_trailing_whitespace = true - -[*.go] -indent_style = tab diff --git a/vendor/github.com/jonboulle/clockwork/.gitignore b/vendor/github.com/jonboulle/clockwork/.gitignore deleted file mode 100644 index 00852bd942..0000000000 --- a/vendor/github.com/jonboulle/clockwork/.gitignore +++ /dev/null @@ -1,27 +0,0 @@ -/.idea/ - -# Compiled Object files, Static and Dynamic libs (Shared Objects) -*.o -*.a -*.so - -# Folders -_obj -_test - -# Architecture specific extensions/prefixes -*.[568vq] -[568vq].out - -*.cgo1.go -*.cgo2.c -_cgo_defun.c -_cgo_gotypes.go -_cgo_export.* - -_testmain.go - -*.exe -*.test - -*.swp diff --git a/vendor/github.com/jonboulle/clockwork/LICENSE b/vendor/github.com/jonboulle/clockwork/LICENSE deleted file mode 100644 index 5c304d1a4a..0000000000 --- a/vendor/github.com/jonboulle/clockwork/LICENSE +++ /dev/null @@ -1,201 +0,0 @@ -Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "{}" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright {yyyy} {name of copyright owner} - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. diff --git a/vendor/github.com/jonboulle/clockwork/README.md b/vendor/github.com/jonboulle/clockwork/README.md deleted file mode 100644 index cad6083572..0000000000 --- a/vendor/github.com/jonboulle/clockwork/README.md +++ /dev/null @@ -1,80 +0,0 @@ -# clockwork - -[![Mentioned in Awesome Go](https://awesome.re/mentioned-badge-flat.svg)](https://github.com/avelino/awesome-go#utilities) - -[![GitHub Workflow Status](https://img.shields.io/github/workflow/status/jonboulle/clockwork/CI?style=flat-square)](https://github.com/jonboulle/clockwork/actions?query=workflow%3ACI) -[![Go Report Card](https://goreportcard.com/badge/github.com/jonboulle/clockwork?style=flat-square)](https://goreportcard.com/report/github.com/jonboulle/clockwork) -![Go Version](https://img.shields.io/badge/go%20version-%3E=1.11-61CFDD.svg?style=flat-square) -[![go.dev reference](https://img.shields.io/badge/go.dev-reference-007d9c?logo=go&logoColor=white&style=flat-square)](https://pkg.go.dev/mod/github.com/jonboulle/clockwork) - -**A simple fake clock for Go.** - - -## Usage - -Replace uses of the `time` package with the `clockwork.Clock` interface instead. - -For example, instead of using `time.Sleep` directly: - -```go -func myFunc() { - time.Sleep(3 * time.Second) - doSomething() -} -``` - -Inject a clock and use its `Sleep` method instead: - -```go -func myFunc(clock clockwork.Clock) { - clock.Sleep(3 * time.Second) - doSomething() -} -``` - -Now you can easily test `myFunc` with a `FakeClock`: - -```go -func TestMyFunc(t *testing.T) { - c := clockwork.NewFakeClock() - - // Start our sleepy function - var wg sync.WaitGroup - wg.Add(1) - go func() { - myFunc(c) - wg.Done() - }() - - // Ensure we wait until myFunc is sleeping - c.BlockUntil(1) - - assertState() - - // Advance the FakeClock forward in time - c.Advance(3 * time.Second) - - // Wait until the function completes - wg.Wait() - - assertState() -} -``` - -and in production builds, simply inject the real clock instead: - -```go -myFunc(clockwork.NewRealClock()) -``` - -See [example_test.go](example_test.go) for a full example. - - -# Credits - -clockwork is inspired by @wickman's [threaded fake clock](https://gist.github.com/wickman/3840816), and the [Golang playground](https://blog.golang.org/playground#TOC_3.1.) - - -## License - -Apache License, Version 2.0. Please see [License File](LICENSE) for more information. diff --git a/vendor/github.com/jonboulle/clockwork/clockwork.go b/vendor/github.com/jonboulle/clockwork/clockwork.go deleted file mode 100644 index 1018051f4a..0000000000 --- a/vendor/github.com/jonboulle/clockwork/clockwork.go +++ /dev/null @@ -1,195 +0,0 @@ -package clockwork - -import ( - "sync" - "time" -) - -// Clock provides an interface that packages can use instead of directly -// using the time module, so that chronology-related behavior can be tested -type Clock interface { - After(d time.Duration) <-chan time.Time - Sleep(d time.Duration) - Now() time.Time - Since(t time.Time) time.Duration - NewTicker(d time.Duration) Ticker -} - -// FakeClock provides an interface for a clock which can be -// manually advanced through time -type FakeClock interface { - Clock - // Advance advances the FakeClock to a new point in time, ensuring any existing - // sleepers are notified appropriately before returning - Advance(d time.Duration) - // BlockUntil will block until the FakeClock has the given number of - // sleepers (callers of Sleep or After) - BlockUntil(n int) -} - -// NewRealClock returns a Clock which simply delegates calls to the actual time -// package; it should be used by packages in production. -func NewRealClock() Clock { - return &realClock{} -} - -// NewFakeClock returns a FakeClock implementation which can be -// manually advanced through time for testing. The initial time of the -// FakeClock will be an arbitrary non-zero time. -func NewFakeClock() FakeClock { - // use a fixture that does not fulfill Time.IsZero() - return NewFakeClockAt(time.Date(1984, time.April, 4, 0, 0, 0, 0, time.UTC)) -} - -// NewFakeClockAt returns a FakeClock initialised at the given time.Time. -func NewFakeClockAt(t time.Time) FakeClock { - return &fakeClock{ - time: t, - } -} - -type realClock struct{} - -func (rc *realClock) After(d time.Duration) <-chan time.Time { - return time.After(d) -} - -func (rc *realClock) Sleep(d time.Duration) { - time.Sleep(d) -} - -func (rc *realClock) Now() time.Time { - return time.Now() -} - -func (rc *realClock) Since(t time.Time) time.Duration { - return rc.Now().Sub(t) -} - -func (rc *realClock) NewTicker(d time.Duration) Ticker { - return &realTicker{time.NewTicker(d)} -} - -type fakeClock struct { - sleepers []*sleeper - blockers []*blocker - time time.Time - - l sync.RWMutex -} - -// sleeper represents a caller of After or Sleep -type sleeper struct { - until time.Time - done chan time.Time -} - -// blocker represents a caller of BlockUntil -type blocker struct { - count int - ch chan struct{} -} - -// After mimics time.After; it waits for the given duration to elapse on the -// fakeClock, then sends the current time on the returned channel. -func (fc *fakeClock) After(d time.Duration) <-chan time.Time { - fc.l.Lock() - defer fc.l.Unlock() - now := fc.time - done := make(chan time.Time, 1) - if d.Nanoseconds() <= 0 { - // special case - trigger immediately - done <- now - } else { - // otherwise, add to the set of sleepers - s := &sleeper{ - until: now.Add(d), - done: done, - } - fc.sleepers = append(fc.sleepers, s) - // and notify any blockers - fc.blockers = notifyBlockers(fc.blockers, len(fc.sleepers)) - } - return done -} - -// notifyBlockers notifies all the blockers waiting until the -// given number of sleepers are waiting on the fakeClock. It -// returns an updated slice of blockers (i.e. those still waiting) -func notifyBlockers(blockers []*blocker, count int) (newBlockers []*blocker) { - for _, b := range blockers { - if b.count == count { - close(b.ch) - } else { - newBlockers = append(newBlockers, b) - } - } - return -} - -// Sleep blocks until the given duration has passed on the fakeClock -func (fc *fakeClock) Sleep(d time.Duration) { - <-fc.After(d) -} - -// Time returns the current time of the fakeClock -func (fc *fakeClock) Now() time.Time { - fc.l.RLock() - t := fc.time - fc.l.RUnlock() - return t -} - -// Since returns the duration that has passed since the given time on the fakeClock -func (fc *fakeClock) Since(t time.Time) time.Duration { - return fc.Now().Sub(t) -} - -func (fc *fakeClock) NewTicker(d time.Duration) Ticker { - ft := &fakeTicker{ - c: make(chan time.Time, 1), - stop: make(chan bool, 1), - clock: fc, - period: d, - } - ft.runTickThread() - return ft -} - -// Advance advances fakeClock to a new point in time, ensuring channels from any -// previous invocations of After are notified appropriately before returning -func (fc *fakeClock) Advance(d time.Duration) { - fc.l.Lock() - defer fc.l.Unlock() - end := fc.time.Add(d) - var newSleepers []*sleeper - for _, s := range fc.sleepers { - if end.Sub(s.until) >= 0 { - s.done <- end - } else { - newSleepers = append(newSleepers, s) - } - } - fc.sleepers = newSleepers - fc.blockers = notifyBlockers(fc.blockers, len(fc.sleepers)) - fc.time = end -} - -// BlockUntil will block until the fakeClock has the given number of sleepers -// (callers of Sleep or After) -func (fc *fakeClock) BlockUntil(n int) { - fc.l.Lock() - // Fast path: current number of sleepers is what we're looking for - if len(fc.sleepers) == n { - fc.l.Unlock() - return - } - // Otherwise, set up a new blocker - b := &blocker{ - count: n, - ch: make(chan struct{}), - } - fc.blockers = append(fc.blockers, b) - fc.l.Unlock() - <-b.ch -} diff --git a/vendor/github.com/jonboulle/clockwork/go.mod b/vendor/github.com/jonboulle/clockwork/go.mod deleted file mode 100644 index 4f4bb16587..0000000000 --- a/vendor/github.com/jonboulle/clockwork/go.mod +++ /dev/null @@ -1,3 +0,0 @@ -module github.com/jonboulle/clockwork - -go 1.13 diff --git a/vendor/github.com/jonboulle/clockwork/ticker.go b/vendor/github.com/jonboulle/clockwork/ticker.go deleted file mode 100644 index 32b5d01e75..0000000000 --- a/vendor/github.com/jonboulle/clockwork/ticker.go +++ /dev/null @@ -1,72 +0,0 @@ -package clockwork - -import ( - "time" -) - -// Ticker provides an interface which can be used instead of directly -// using the ticker within the time module. The real-time ticker t -// provides ticks through t.C which becomes now t.Chan() to make -// this channel requirement definable in this interface. -type Ticker interface { - Chan() <-chan time.Time - Stop() -} - -type realTicker struct{ *time.Ticker } - -func (rt *realTicker) Chan() <-chan time.Time { - return rt.C -} - -type fakeTicker struct { - c chan time.Time - stop chan bool - clock FakeClock - period time.Duration -} - -func (ft *fakeTicker) Chan() <-chan time.Time { - return ft.c -} - -func (ft *fakeTicker) Stop() { - ft.stop <- true -} - -// runTickThread initializes a background goroutine to send the tick time to the ticker channel -// after every period. Tick events are discarded if the underlying ticker channel does not have -// enough capacity. -func (ft *fakeTicker) runTickThread() { - nextTick := ft.clock.Now().Add(ft.period) - next := ft.clock.After(ft.period) - go func() { - for { - select { - case <-ft.stop: - return - case <-next: - // We send the time that the tick was supposed to occur at. - tick := nextTick - // Before sending the tick, we'll compute the next tick time and star the clock.After call. - now := ft.clock.Now() - // First, figure out how many periods there have been between "now" and the time we were - // supposed to have trigged, then advance over all of those. - skipTicks := (now.Sub(tick) + ft.period - 1) / ft.period - nextTick = nextTick.Add(skipTicks * ft.period) - // Now, keep advancing until we are past now. This should happen at most once. - for !nextTick.After(now) { - nextTick = nextTick.Add(ft.period) - } - // Figure out how long between now and the next scheduled tick, then wait that long. - remaining := nextTick.Sub(now) - next = ft.clock.After(remaining) - // Finally, we can actually send the tick. - select { - case ft.c <- tick: - default: - } - } - } - }() -} diff --git a/vendor/github.com/soheilhy/cmux/.gitignore b/vendor/github.com/soheilhy/cmux/.gitignore deleted file mode 100644 index daf913b1b3..0000000000 --- a/vendor/github.com/soheilhy/cmux/.gitignore +++ /dev/null @@ -1,24 +0,0 @@ -# Compiled Object files, Static and Dynamic libs (Shared Objects) -*.o -*.a -*.so - -# Folders -_obj -_test - -# Architecture specific extensions/prefixes -*.[568vq] -[568vq].out - -*.cgo1.go -*.cgo2.c -_cgo_defun.c -_cgo_gotypes.go -_cgo_export.* - -_testmain.go - -*.exe -*.test -*.prof diff --git a/vendor/github.com/soheilhy/cmux/.travis.yml b/vendor/github.com/soheilhy/cmux/.travis.yml deleted file mode 100644 index 4d78a519fe..0000000000 --- a/vendor/github.com/soheilhy/cmux/.travis.yml +++ /dev/null @@ -1,29 +0,0 @@ -language: go - -go: - - 1.6 - - 1.7 - - 1.8 - - tip - -matrix: - allow_failures: - - go: tip - -gobuild_args: -race - -before_install: - - if [[ $TRAVIS_GO_VERSION == 1.6* ]]; then go get -u github.com/kisielk/errcheck; fi - - if [[ $TRAVIS_GO_VERSION == 1.6* ]]; then go get -u golang.org/x/lint/golint; fi - -before_script: - - '! gofmt -s -l . | read' - - echo $TRAVIS_GO_VERSION - - if [[ $TRAVIS_GO_VERSION == 1.6* ]]; then golint ./...; fi - - if [[ $TRAVIS_GO_VERSION == 1.6* ]]; then errcheck ./...; fi - - if [[ $TRAVIS_GO_VERSION == 1.6* ]]; then go tool vet .; fi - - if [[ $TRAVIS_GO_VERSION == 1.6* ]]; then go tool vet --shadow .; fi - -script: - - go test -bench . -v ./... - - go test -race -bench . -v ./... diff --git a/vendor/github.com/soheilhy/cmux/CONTRIBUTORS b/vendor/github.com/soheilhy/cmux/CONTRIBUTORS deleted file mode 100644 index 49878f228a..0000000000 --- a/vendor/github.com/soheilhy/cmux/CONTRIBUTORS +++ /dev/null @@ -1,12 +0,0 @@ -# The list of people who have contributed code to the cmux repository. -# -# Auto-generated with: -# git log --oneline --pretty=format:'%an <%aE>' | sort -u -# -Andreas Jaekle -Dmitri Shuralyov -Ethan Mosbaugh -Soheil Hassas Yeganeh -Soheil Hassas Yeganeh -Tamir Duberstein -Tamir Duberstein diff --git a/vendor/github.com/soheilhy/cmux/LICENSE b/vendor/github.com/soheilhy/cmux/LICENSE deleted file mode 100644 index d645695673..0000000000 --- a/vendor/github.com/soheilhy/cmux/LICENSE +++ /dev/null @@ -1,202 +0,0 @@ - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. diff --git a/vendor/github.com/soheilhy/cmux/README.md b/vendor/github.com/soheilhy/cmux/README.md deleted file mode 100644 index c4191b70b0..0000000000 --- a/vendor/github.com/soheilhy/cmux/README.md +++ /dev/null @@ -1,83 +0,0 @@ -# cmux: Connection Mux ![Travis Build Status](https://api.travis-ci.org/soheilhy/args.svg?branch=master "Travis Build Status") [![GoDoc](https://godoc.org/github.com/soheilhy/cmux?status.svg)](http://godoc.org/github.com/soheilhy/cmux) - -cmux is a generic Go library to multiplex connections based on -their payload. Using cmux, you can serve gRPC, SSH, HTTPS, HTTP, -Go RPC, and pretty much any other protocol on the same TCP listener. - -## How-To -Simply create your main listener, create a cmux for that listener, -and then match connections: -```go -// Create the main listener. -l, err := net.Listen("tcp", ":23456") -if err != nil { - log.Fatal(err) -} - -// Create a cmux. -m := cmux.New(l) - -// Match connections in order: -// First grpc, then HTTP, and otherwise Go RPC/TCP. -grpcL := m.Match(cmux.HTTP2HeaderField("content-type", "application/grpc")) -httpL := m.Match(cmux.HTTP1Fast()) -trpcL := m.Match(cmux.Any()) // Any means anything that is not yet matched. - -// Create your protocol servers. -grpcS := grpc.NewServer() -grpchello.RegisterGreeterServer(grpcS, &server{}) - -httpS := &http.Server{ - Handler: &helloHTTP1Handler{}, -} - -trpcS := rpc.NewServer() -trpcS.Register(&ExampleRPCRcvr{}) - -// Use the muxed listeners for your servers. -go grpcS.Serve(grpcL) -go httpS.Serve(httpL) -go trpcS.Accept(trpcL) - -// Start serving! -m.Serve() -``` - -Take a look at [other examples in the GoDoc](http://godoc.org/github.com/soheilhy/cmux/#pkg-examples). - -## Docs -* [GoDocs](https://godoc.org/github.com/soheilhy/cmux) - -## Performance -There is room for improvment but, since we are only matching -the very first bytes of a connection, the performance overheads on -long-lived connections (i.e., RPCs and pipelined HTTP streams) -is negligible. - -*TODO(soheil)*: Add benchmarks. - -## Limitations -* *TLS*: `net/http` uses a type assertion to identify TLS connections; since -cmux's lookahead-implementing connection wraps the underlying TLS connection, -this type assertion fails. -Because of that, you can serve HTTPS using cmux but `http.Request.TLS` -would not be set in your handlers. - -* *Different Protocols on The Same Connection*: `cmux` matches the connection -when it's accepted. For example, one connection can be either gRPC or REST, but -not both. That is, we assume that a client connection is either used for gRPC -or REST. - -* *Java gRPC Clients*: Java gRPC client blocks until it receives a SETTINGS -frame from the server. If you are using the Java client to connect to a cmux'ed -gRPC server please match with writers: -```go -grpcl := m.MatchWithWriters(cmux.HTTP2MatchHeaderFieldSendSettings("content-type", "application/grpc")) -``` - -# Copyright and License -Copyright 2016 The CMux Authors. All rights reserved. - -See [CONTRIBUTORS](https://github.com/soheilhy/cmux/blob/master/CONTRIBUTORS) -for the CMux Authors. Code is released under -[the Apache 2 license](https://github.com/soheilhy/cmux/blob/master/LICENSE). diff --git a/vendor/github.com/soheilhy/cmux/buffer.go b/vendor/github.com/soheilhy/cmux/buffer.go deleted file mode 100644 index f8cf30a1e6..0000000000 --- a/vendor/github.com/soheilhy/cmux/buffer.go +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright 2016 The CMux Authors. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -// implied. See the License for the specific language governing -// permissions and limitations under the License. - -package cmux - -import ( - "bytes" - "io" -) - -// bufferedReader is an optimized implementation of io.Reader that behaves like -// ``` -// io.MultiReader(bytes.NewReader(buffer.Bytes()), io.TeeReader(source, buffer)) -// ``` -// without allocating. -type bufferedReader struct { - source io.Reader - buffer bytes.Buffer - bufferRead int - bufferSize int - sniffing bool - lastErr error -} - -func (s *bufferedReader) Read(p []byte) (int, error) { - if s.bufferSize > s.bufferRead { - // If we have already read something from the buffer before, we return the - // same data and the last error if any. We need to immediately return, - // otherwise we may block for ever, if we try to be smart and call - // source.Read() seeking a little bit of more data. - bn := copy(p, s.buffer.Bytes()[s.bufferRead:s.bufferSize]) - s.bufferRead += bn - return bn, s.lastErr - } else if !s.sniffing && s.buffer.Cap() != 0 { - // We don't need the buffer anymore. - // Reset it to release the internal slice. - s.buffer = bytes.Buffer{} - } - - // If there is nothing more to return in the sniffed buffer, read from the - // source. - sn, sErr := s.source.Read(p) - if sn > 0 && s.sniffing { - s.lastErr = sErr - if wn, wErr := s.buffer.Write(p[:sn]); wErr != nil { - return wn, wErr - } - } - return sn, sErr -} - -func (s *bufferedReader) reset(snif bool) { - s.sniffing = snif - s.bufferRead = 0 - s.bufferSize = s.buffer.Len() -} diff --git a/vendor/github.com/soheilhy/cmux/cmux.go b/vendor/github.com/soheilhy/cmux/cmux.go deleted file mode 100644 index 5ba921e72d..0000000000 --- a/vendor/github.com/soheilhy/cmux/cmux.go +++ /dev/null @@ -1,307 +0,0 @@ -// Copyright 2016 The CMux Authors. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -// implied. See the License for the specific language governing -// permissions and limitations under the License. - -package cmux - -import ( - "errors" - "fmt" - "io" - "net" - "sync" - "time" -) - -// Matcher matches a connection based on its content. -type Matcher func(io.Reader) bool - -// MatchWriter is a match that can also write response (say to do handshake). -type MatchWriter func(io.Writer, io.Reader) bool - -// ErrorHandler handles an error and returns whether -// the mux should continue serving the listener. -type ErrorHandler func(error) bool - -var _ net.Error = ErrNotMatched{} - -// ErrNotMatched is returned whenever a connection is not matched by any of -// the matchers registered in the multiplexer. -type ErrNotMatched struct { - c net.Conn -} - -func (e ErrNotMatched) Error() string { - return fmt.Sprintf("mux: connection %v not matched by an matcher", - e.c.RemoteAddr()) -} - -// Temporary implements the net.Error interface. -func (e ErrNotMatched) Temporary() bool { return true } - -// Timeout implements the net.Error interface. -func (e ErrNotMatched) Timeout() bool { return false } - -type errListenerClosed string - -func (e errListenerClosed) Error() string { return string(e) } -func (e errListenerClosed) Temporary() bool { return false } -func (e errListenerClosed) Timeout() bool { return false } - -// ErrListenerClosed is returned from muxListener.Accept when the underlying -// listener is closed. -var ErrListenerClosed = errListenerClosed("mux: listener closed") - -// ErrServerClosed is returned from muxListener.Accept when mux server is closed. -var ErrServerClosed = errors.New("mux: server closed") - -// for readability of readTimeout -var noTimeout time.Duration - -// New instantiates a new connection multiplexer. -func New(l net.Listener) CMux { - return &cMux{ - root: l, - bufLen: 1024, - errh: func(_ error) bool { return true }, - donec: make(chan struct{}), - readTimeout: noTimeout, - } -} - -// CMux is a multiplexer for network connections. -type CMux interface { - // Match returns a net.Listener that sees (i.e., accepts) only - // the connections matched by at least one of the matcher. - // - // The order used to call Match determines the priority of matchers. - Match(...Matcher) net.Listener - // MatchWithWriters returns a net.Listener that accepts only the - // connections that matched by at least of the matcher writers. - // - // Prefer Matchers over MatchWriters, since the latter can write on the - // connection before the actual handler. - // - // The order used to call Match determines the priority of matchers. - MatchWithWriters(...MatchWriter) net.Listener - // Serve starts multiplexing the listener. Serve blocks and perhaps - // should be invoked concurrently within a go routine. - Serve() error - // Closes cmux server and stops accepting any connections on listener - Close() - // HandleError registers an error handler that handles listener errors. - HandleError(ErrorHandler) - // sets a timeout for the read of matchers - SetReadTimeout(time.Duration) -} - -type matchersListener struct { - ss []MatchWriter - l muxListener -} - -type cMux struct { - root net.Listener - bufLen int - errh ErrorHandler - sls []matchersListener - readTimeout time.Duration - donec chan struct{} - mu sync.Mutex -} - -func matchersToMatchWriters(matchers []Matcher) []MatchWriter { - mws := make([]MatchWriter, 0, len(matchers)) - for _, m := range matchers { - cm := m - mws = append(mws, func(w io.Writer, r io.Reader) bool { - return cm(r) - }) - } - return mws -} - -func (m *cMux) Match(matchers ...Matcher) net.Listener { - mws := matchersToMatchWriters(matchers) - return m.MatchWithWriters(mws...) -} - -func (m *cMux) MatchWithWriters(matchers ...MatchWriter) net.Listener { - ml := muxListener{ - Listener: m.root, - connc: make(chan net.Conn, m.bufLen), - donec: make(chan struct{}), - } - m.sls = append(m.sls, matchersListener{ss: matchers, l: ml}) - return ml -} - -func (m *cMux) SetReadTimeout(t time.Duration) { - m.readTimeout = t -} - -func (m *cMux) Serve() error { - var wg sync.WaitGroup - - defer func() { - m.closeDoneChans() - wg.Wait() - - for _, sl := range m.sls { - close(sl.l.connc) - // Drain the connections enqueued for the listener. - for c := range sl.l.connc { - _ = c.Close() - } - } - }() - - for { - c, err := m.root.Accept() - if err != nil { - if !m.handleErr(err) { - return err - } - continue - } - - wg.Add(1) - go m.serve(c, m.donec, &wg) - } -} - -func (m *cMux) serve(c net.Conn, donec <-chan struct{}, wg *sync.WaitGroup) { - defer wg.Done() - - muc := newMuxConn(c) - if m.readTimeout > noTimeout { - _ = c.SetReadDeadline(time.Now().Add(m.readTimeout)) - } - for _, sl := range m.sls { - for _, s := range sl.ss { - matched := s(muc.Conn, muc.startSniffing()) - if matched { - muc.doneSniffing() - if m.readTimeout > noTimeout { - _ = c.SetReadDeadline(time.Time{}) - } - select { - case sl.l.connc <- muc: - case <-donec: - _ = c.Close() - } - return - } - } - } - - _ = c.Close() - err := ErrNotMatched{c: c} - if !m.handleErr(err) { - _ = m.root.Close() - } -} - -func (m *cMux) Close() { - m.closeDoneChans() -} - -func (m *cMux) closeDoneChans() { - m.mu.Lock() - defer m.mu.Unlock() - - select { - case <-m.donec: - // Already closed. Don't close again - default: - close(m.donec) - } - for _, sl := range m.sls { - select { - case <-sl.l.donec: - // Already closed. Don't close again - default: - close(sl.l.donec) - } - } -} - -func (m *cMux) HandleError(h ErrorHandler) { - m.errh = h -} - -func (m *cMux) handleErr(err error) bool { - if !m.errh(err) { - return false - } - - if ne, ok := err.(net.Error); ok { - return ne.Temporary() - } - - return false -} - -type muxListener struct { - net.Listener - connc chan net.Conn - donec chan struct{} -} - -func (l muxListener) Accept() (net.Conn, error) { - select { - case c, ok := <-l.connc: - if !ok { - return nil, ErrListenerClosed - } - return c, nil - case <-l.donec: - return nil, ErrServerClosed - } -} - -// MuxConn wraps a net.Conn and provides transparent sniffing of connection data. -type MuxConn struct { - net.Conn - buf bufferedReader -} - -func newMuxConn(c net.Conn) *MuxConn { - return &MuxConn{ - Conn: c, - buf: bufferedReader{source: c}, - } -} - -// From the io.Reader documentation: -// -// When Read encounters an error or end-of-file condition after -// successfully reading n > 0 bytes, it returns the number of -// bytes read. It may return the (non-nil) error from the same call -// or return the error (and n == 0) from a subsequent call. -// An instance of this general case is that a Reader returning -// a non-zero number of bytes at the end of the input stream may -// return either err == EOF or err == nil. The next Read should -// return 0, EOF. -func (m *MuxConn) Read(p []byte) (int, error) { - return m.buf.Read(p) -} - -func (m *MuxConn) startSniffing() io.Reader { - m.buf.reset(true) - return &m.buf -} - -func (m *MuxConn) doneSniffing() { - m.buf.reset(false) -} diff --git a/vendor/github.com/soheilhy/cmux/doc.go b/vendor/github.com/soheilhy/cmux/doc.go deleted file mode 100644 index aaa8f31589..0000000000 --- a/vendor/github.com/soheilhy/cmux/doc.go +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright 2016 The CMux Authors. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -// implied. See the License for the specific language governing -// permissions and limitations under the License. - -// Package cmux is a library to multiplex network connections based on -// their payload. Using cmux, you can serve different protocols from the -// same listener. -package cmux diff --git a/vendor/github.com/soheilhy/cmux/go.mod b/vendor/github.com/soheilhy/cmux/go.mod deleted file mode 100644 index 2be915f121..0000000000 --- a/vendor/github.com/soheilhy/cmux/go.mod +++ /dev/null @@ -1,5 +0,0 @@ -module github.com/soheilhy/cmux - -go 1.11 - -require golang.org/x/net v0.0.0-20201202161906-c7110b5ffcbb diff --git a/vendor/github.com/soheilhy/cmux/go.sum b/vendor/github.com/soheilhy/cmux/go.sum deleted file mode 100644 index bfa1676094..0000000000 --- a/vendor/github.com/soheilhy/cmux/go.sum +++ /dev/null @@ -1,12 +0,0 @@ -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20201202161906-c7110b5ffcbb h1:eBmm0M9fYhWpKZLjQUUKka/LtIxf46G4fxeEz5KJr9U= -golang.org/x/net v0.0.0-20201202161906-c7110b5ffcbb/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k= -golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= diff --git a/vendor/github.com/soheilhy/cmux/matchers.go b/vendor/github.com/soheilhy/cmux/matchers.go deleted file mode 100644 index 878ae98cc3..0000000000 --- a/vendor/github.com/soheilhy/cmux/matchers.go +++ /dev/null @@ -1,267 +0,0 @@ -// Copyright 2016 The CMux Authors. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -// implied. See the License for the specific language governing -// permissions and limitations under the License. - -package cmux - -import ( - "bufio" - "crypto/tls" - "io" - "io/ioutil" - "net/http" - "strings" - - "golang.org/x/net/http2" - "golang.org/x/net/http2/hpack" -) - -// Any is a Matcher that matches any connection. -func Any() Matcher { - return func(r io.Reader) bool { return true } -} - -// PrefixMatcher returns a matcher that matches a connection if it -// starts with any of the strings in strs. -func PrefixMatcher(strs ...string) Matcher { - pt := newPatriciaTreeString(strs...) - return pt.matchPrefix -} - -func prefixByteMatcher(list ...[]byte) Matcher { - pt := newPatriciaTree(list...) - return pt.matchPrefix -} - -var defaultHTTPMethods = []string{ - "OPTIONS", - "GET", - "HEAD", - "POST", - "PUT", - "DELETE", - "TRACE", - "CONNECT", -} - -// HTTP1Fast only matches the methods in the HTTP request. -// -// This matcher is very optimistic: if it returns true, it does not mean that -// the request is a valid HTTP response. If you want a correct but slower HTTP1 -// matcher, use HTTP1 instead. -func HTTP1Fast(extMethods ...string) Matcher { - return PrefixMatcher(append(defaultHTTPMethods, extMethods...)...) -} - -// TLS matches HTTPS requests. -// -// By default, any TLS handshake packet is matched. An optional whitelist -// of versions can be passed in to restrict the matcher, for example: -// TLS(tls.VersionTLS11, tls.VersionTLS12) -func TLS(versions ...int) Matcher { - if len(versions) == 0 { - versions = []int{ - tls.VersionSSL30, - tls.VersionTLS10, - tls.VersionTLS11, - tls.VersionTLS12, - } - } - prefixes := [][]byte{} - for _, v := range versions { - prefixes = append(prefixes, []byte{22, byte(v >> 8 & 0xff), byte(v & 0xff)}) - } - return prefixByteMatcher(prefixes...) -} - -const maxHTTPRead = 4096 - -// HTTP1 parses the first line or upto 4096 bytes of the request to see if -// the conection contains an HTTP request. -func HTTP1() Matcher { - return func(r io.Reader) bool { - br := bufio.NewReader(&io.LimitedReader{R: r, N: maxHTTPRead}) - l, part, err := br.ReadLine() - if err != nil || part { - return false - } - - _, _, proto, ok := parseRequestLine(string(l)) - if !ok { - return false - } - - v, _, ok := http.ParseHTTPVersion(proto) - return ok && v == 1 - } -} - -// grabbed from net/http. -func parseRequestLine(line string) (method, uri, proto string, ok bool) { - s1 := strings.Index(line, " ") - s2 := strings.Index(line[s1+1:], " ") - if s1 < 0 || s2 < 0 { - return - } - s2 += s1 + 1 - return line[:s1], line[s1+1 : s2], line[s2+1:], true -} - -// HTTP2 parses the frame header of the first frame to detect whether the -// connection is an HTTP2 connection. -func HTTP2() Matcher { - return hasHTTP2Preface -} - -// HTTP1HeaderField returns a matcher matching the header fields of the first -// request of an HTTP 1 connection. -func HTTP1HeaderField(name, value string) Matcher { - return func(r io.Reader) bool { - return matchHTTP1Field(r, name, func(gotValue string) bool { - return gotValue == value - }) - } -} - -// HTTP1HeaderFieldPrefix returns a matcher matching the header fields of the -// first request of an HTTP 1 connection. If the header with key name has a -// value prefixed with valuePrefix, this will match. -func HTTP1HeaderFieldPrefix(name, valuePrefix string) Matcher { - return func(r io.Reader) bool { - return matchHTTP1Field(r, name, func(gotValue string) bool { - return strings.HasPrefix(gotValue, valuePrefix) - }) - } -} - -// HTTP2HeaderField returns a matcher matching the header fields of the first -// headers frame. -func HTTP2HeaderField(name, value string) Matcher { - return func(r io.Reader) bool { - return matchHTTP2Field(ioutil.Discard, r, name, func(gotValue string) bool { - return gotValue == value - }) - } -} - -// HTTP2HeaderFieldPrefix returns a matcher matching the header fields of the -// first headers frame. If the header with key name has a value prefixed with -// valuePrefix, this will match. -func HTTP2HeaderFieldPrefix(name, valuePrefix string) Matcher { - return func(r io.Reader) bool { - return matchHTTP2Field(ioutil.Discard, r, name, func(gotValue string) bool { - return strings.HasPrefix(gotValue, valuePrefix) - }) - } -} - -// HTTP2MatchHeaderFieldSendSettings matches the header field and writes the -// settings to the server. Prefer HTTP2HeaderField over this one, if the client -// does not block on receiving a SETTING frame. -func HTTP2MatchHeaderFieldSendSettings(name, value string) MatchWriter { - return func(w io.Writer, r io.Reader) bool { - return matchHTTP2Field(w, r, name, func(gotValue string) bool { - return gotValue == value - }) - } -} - -// HTTP2MatchHeaderFieldPrefixSendSettings matches the header field prefix -// and writes the settings to the server. Prefer HTTP2HeaderFieldPrefix over -// this one, if the client does not block on receiving a SETTING frame. -func HTTP2MatchHeaderFieldPrefixSendSettings(name, valuePrefix string) MatchWriter { - return func(w io.Writer, r io.Reader) bool { - return matchHTTP2Field(w, r, name, func(gotValue string) bool { - return strings.HasPrefix(gotValue, valuePrefix) - }) - } -} - -func hasHTTP2Preface(r io.Reader) bool { - var b [len(http2.ClientPreface)]byte - last := 0 - - for { - n, err := r.Read(b[last:]) - if err != nil { - return false - } - - last += n - eq := string(b[:last]) == http2.ClientPreface[:last] - if last == len(http2.ClientPreface) { - return eq - } - if !eq { - return false - } - } -} - -func matchHTTP1Field(r io.Reader, name string, matches func(string) bool) (matched bool) { - req, err := http.ReadRequest(bufio.NewReader(r)) - if err != nil { - return false - } - - return matches(req.Header.Get(name)) -} - -func matchHTTP2Field(w io.Writer, r io.Reader, name string, matches func(string) bool) (matched bool) { - if !hasHTTP2Preface(r) { - return false - } - - done := false - framer := http2.NewFramer(w, r) - hdec := hpack.NewDecoder(uint32(4<<10), func(hf hpack.HeaderField) { - if hf.Name == name { - done = true - if matches(hf.Value) { - matched = true - } - } - }) - for { - f, err := framer.ReadFrame() - if err != nil { - return false - } - - switch f := f.(type) { - case *http2.SettingsFrame: - // Sender acknoweldged the SETTINGS frame. No need to write - // SETTINGS again. - if f.IsAck() { - break - } - if err := framer.WriteSettings(); err != nil { - return false - } - case *http2.ContinuationFrame: - if _, err := hdec.Write(f.HeaderBlockFragment()); err != nil { - return false - } - done = done || f.FrameHeader.Flags&http2.FlagHeadersEndHeaders != 0 - case *http2.HeadersFrame: - if _, err := hdec.Write(f.HeaderBlockFragment()); err != nil { - return false - } - done = done || f.FrameHeader.Flags&http2.FlagHeadersEndHeaders != 0 - } - - if done { - return matched - } - } -} diff --git a/vendor/github.com/soheilhy/cmux/patricia.go b/vendor/github.com/soheilhy/cmux/patricia.go deleted file mode 100644 index c3e3d85bde..0000000000 --- a/vendor/github.com/soheilhy/cmux/patricia.go +++ /dev/null @@ -1,179 +0,0 @@ -// Copyright 2016 The CMux Authors. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -// implied. See the License for the specific language governing -// permissions and limitations under the License. - -package cmux - -import ( - "bytes" - "io" -) - -// patriciaTree is a simple patricia tree that handles []byte instead of string -// and cannot be changed after instantiation. -type patriciaTree struct { - root *ptNode - maxDepth int // max depth of the tree. -} - -func newPatriciaTree(bs ...[]byte) *patriciaTree { - max := 0 - for _, b := range bs { - if max < len(b) { - max = len(b) - } - } - return &patriciaTree{ - root: newNode(bs), - maxDepth: max + 1, - } -} - -func newPatriciaTreeString(strs ...string) *patriciaTree { - b := make([][]byte, len(strs)) - for i, s := range strs { - b[i] = []byte(s) - } - return newPatriciaTree(b...) -} - -func (t *patriciaTree) matchPrefix(r io.Reader) bool { - buf := make([]byte, t.maxDepth) - n, _ := io.ReadFull(r, buf) - return t.root.match(buf[:n], true) -} - -func (t *patriciaTree) match(r io.Reader) bool { - buf := make([]byte, t.maxDepth) - n, _ := io.ReadFull(r, buf) - return t.root.match(buf[:n], false) -} - -type ptNode struct { - prefix []byte - next map[byte]*ptNode - terminal bool -} - -func newNode(strs [][]byte) *ptNode { - if len(strs) == 0 { - return &ptNode{ - prefix: []byte{}, - terminal: true, - } - } - - if len(strs) == 1 { - return &ptNode{ - prefix: strs[0], - terminal: true, - } - } - - p, strs := splitPrefix(strs) - n := &ptNode{ - prefix: p, - } - - nexts := make(map[byte][][]byte) - for _, s := range strs { - if len(s) == 0 { - n.terminal = true - continue - } - nexts[s[0]] = append(nexts[s[0]], s[1:]) - } - - n.next = make(map[byte]*ptNode) - for first, rests := range nexts { - n.next[first] = newNode(rests) - } - - return n -} - -func splitPrefix(bss [][]byte) (prefix []byte, rest [][]byte) { - if len(bss) == 0 || len(bss[0]) == 0 { - return prefix, bss - } - - if len(bss) == 1 { - return bss[0], [][]byte{{}} - } - - for i := 0; ; i++ { - var cur byte - eq := true - for j, b := range bss { - if len(b) <= i { - eq = false - break - } - - if j == 0 { - cur = b[i] - continue - } - - if cur != b[i] { - eq = false - break - } - } - - if !eq { - break - } - - prefix = append(prefix, cur) - } - - rest = make([][]byte, 0, len(bss)) - for _, b := range bss { - rest = append(rest, b[len(prefix):]) - } - - return prefix, rest -} - -func (n *ptNode) match(b []byte, prefix bool) bool { - l := len(n.prefix) - if l > 0 { - if l > len(b) { - l = len(b) - } - if !bytes.Equal(b[:l], n.prefix) { - return false - } - } - - if n.terminal && (prefix || len(n.prefix) == len(b)) { - return true - } - - if l >= len(b) { - return false - } - - nextN, ok := n.next[b[l]] - if !ok { - return false - } - - if l == len(b) { - b = b[l:l] - } else { - b = b[l+1:] - } - return nextN.match(b, prefix) -} diff --git a/vendor/github.com/spf13/pflag/.gitignore b/vendor/github.com/spf13/pflag/.gitignore deleted file mode 100644 index c3da290134..0000000000 --- a/vendor/github.com/spf13/pflag/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -.idea/* - diff --git a/vendor/github.com/spf13/pflag/.travis.yml b/vendor/github.com/spf13/pflag/.travis.yml deleted file mode 100644 index 00d04cb9b0..0000000000 --- a/vendor/github.com/spf13/pflag/.travis.yml +++ /dev/null @@ -1,22 +0,0 @@ -sudo: false - -language: go - -go: - - 1.9.x - - 1.10.x - - 1.11.x - - tip - -matrix: - allow_failures: - - go: tip - -install: - - go get golang.org/x/lint/golint - - export PATH=$GOPATH/bin:$PATH - - go install ./... - -script: - - verify/all.sh -v - - go test ./... diff --git a/vendor/github.com/spf13/pflag/LICENSE b/vendor/github.com/spf13/pflag/LICENSE deleted file mode 100644 index 63ed1cfea1..0000000000 --- a/vendor/github.com/spf13/pflag/LICENSE +++ /dev/null @@ -1,28 +0,0 @@ -Copyright (c) 2012 Alex Ogier. All rights reserved. -Copyright (c) 2012 The Go Authors. All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are -met: - - * Redistributions of source code must retain the above copyright -notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above -copyright notice, this list of conditions and the following disclaimer -in the documentation and/or other materials provided with the -distribution. - * Neither the name of Google Inc. nor the names of its -contributors may be used to endorse or promote products derived from -this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/vendor/github.com/spf13/pflag/README.md b/vendor/github.com/spf13/pflag/README.md deleted file mode 100644 index 7eacc5bdbe..0000000000 --- a/vendor/github.com/spf13/pflag/README.md +++ /dev/null @@ -1,296 +0,0 @@ -[![Build Status](https://travis-ci.org/spf13/pflag.svg?branch=master)](https://travis-ci.org/spf13/pflag) -[![Go Report Card](https://goreportcard.com/badge/github.com/spf13/pflag)](https://goreportcard.com/report/github.com/spf13/pflag) -[![GoDoc](https://godoc.org/github.com/spf13/pflag?status.svg)](https://godoc.org/github.com/spf13/pflag) - -## Description - -pflag is a drop-in replacement for Go's flag package, implementing -POSIX/GNU-style --flags. - -pflag is compatible with the [GNU extensions to the POSIX recommendations -for command-line options][1]. For a more precise description, see the -"Command-line flag syntax" section below. - -[1]: http://www.gnu.org/software/libc/manual/html_node/Argument-Syntax.html - -pflag is available under the same style of BSD license as the Go language, -which can be found in the LICENSE file. - -## Installation - -pflag is available using the standard `go get` command. - -Install by running: - - go get github.com/spf13/pflag - -Run tests by running: - - go test github.com/spf13/pflag - -## Usage - -pflag is a drop-in replacement of Go's native flag package. If you import -pflag under the name "flag" then all code should continue to function -with no changes. - -``` go -import flag "github.com/spf13/pflag" -``` - -There is one exception to this: if you directly instantiate the Flag struct -there is one more field "Shorthand" that you will need to set. -Most code never instantiates this struct directly, and instead uses -functions such as String(), BoolVar(), and Var(), and is therefore -unaffected. - -Define flags using flag.String(), Bool(), Int(), etc. - -This declares an integer flag, -flagname, stored in the pointer ip, with type *int. - -``` go -var ip *int = flag.Int("flagname", 1234, "help message for flagname") -``` - -If you like, you can bind the flag to a variable using the Var() functions. - -``` go -var flagvar int -func init() { - flag.IntVar(&flagvar, "flagname", 1234, "help message for flagname") -} -``` - -Or you can create custom flags that satisfy the Value interface (with -pointer receivers) and couple them to flag parsing by - -``` go -flag.Var(&flagVal, "name", "help message for flagname") -``` - -For such flags, the default value is just the initial value of the variable. - -After all flags are defined, call - -``` go -flag.Parse() -``` - -to parse the command line into the defined flags. - -Flags may then be used directly. If you're using the flags themselves, -they are all pointers; if you bind to variables, they're values. - -``` go -fmt.Println("ip has value ", *ip) -fmt.Println("flagvar has value ", flagvar) -``` - -There are helper functions available to get the value stored in a Flag if you have a FlagSet but find -it difficult to keep up with all of the pointers in your code. -If you have a pflag.FlagSet with a flag called 'flagname' of type int you -can use GetInt() to get the int value. But notice that 'flagname' must exist -and it must be an int. GetString("flagname") will fail. - -``` go -i, err := flagset.GetInt("flagname") -``` - -After parsing, the arguments after the flag are available as the -slice flag.Args() or individually as flag.Arg(i). -The arguments are indexed from 0 through flag.NArg()-1. - -The pflag package also defines some new functions that are not in flag, -that give one-letter shorthands for flags. You can use these by appending -'P' to the name of any function that defines a flag. - -``` go -var ip = flag.IntP("flagname", "f", 1234, "help message") -var flagvar bool -func init() { - flag.BoolVarP(&flagvar, "boolname", "b", true, "help message") -} -flag.VarP(&flagVal, "varname", "v", "help message") -``` - -Shorthand letters can be used with single dashes on the command line. -Boolean shorthand flags can be combined with other shorthand flags. - -The default set of command-line flags is controlled by -top-level functions. The FlagSet type allows one to define -independent sets of flags, such as to implement subcommands -in a command-line interface. The methods of FlagSet are -analogous to the top-level functions for the command-line -flag set. - -## Setting no option default values for flags - -After you create a flag it is possible to set the pflag.NoOptDefVal for -the given flag. Doing this changes the meaning of the flag slightly. If -a flag has a NoOptDefVal and the flag is set on the command line without -an option the flag will be set to the NoOptDefVal. For example given: - -``` go -var ip = flag.IntP("flagname", "f", 1234, "help message") -flag.Lookup("flagname").NoOptDefVal = "4321" -``` - -Would result in something like - -| Parsed Arguments | Resulting Value | -| ------------- | ------------- | -| --flagname=1357 | ip=1357 | -| --flagname | ip=4321 | -| [nothing] | ip=1234 | - -## Command line flag syntax - -``` ---flag // boolean flags, or flags with no option default values ---flag x // only on flags without a default value ---flag=x -``` - -Unlike the flag package, a single dash before an option means something -different than a double dash. Single dashes signify a series of shorthand -letters for flags. All but the last shorthand letter must be boolean flags -or a flag with a default value - -``` -// boolean or flags where the 'no option default value' is set --f --f=true --abc -but --b true is INVALID - -// non-boolean and flags without a 'no option default value' --n 1234 --n=1234 --n1234 - -// mixed --abcs "hello" --absd="hello" --abcs1234 -``` - -Flag parsing stops after the terminator "--". Unlike the flag package, -flags can be interspersed with arguments anywhere on the command line -before this terminator. - -Integer flags accept 1234, 0664, 0x1234 and may be negative. -Boolean flags (in their long form) accept 1, 0, t, f, true, false, -TRUE, FALSE, True, False. -Duration flags accept any input valid for time.ParseDuration. - -## Mutating or "Normalizing" Flag names - -It is possible to set a custom flag name 'normalization function.' It allows flag names to be mutated both when created in the code and when used on the command line to some 'normalized' form. The 'normalized' form is used for comparison. Two examples of using the custom normalization func follow. - -**Example #1**: You want -, _, and . in flags to compare the same. aka --my-flag == --my_flag == --my.flag - -``` go -func wordSepNormalizeFunc(f *pflag.FlagSet, name string) pflag.NormalizedName { - from := []string{"-", "_"} - to := "." - for _, sep := range from { - name = strings.Replace(name, sep, to, -1) - } - return pflag.NormalizedName(name) -} - -myFlagSet.SetNormalizeFunc(wordSepNormalizeFunc) -``` - -**Example #2**: You want to alias two flags. aka --old-flag-name == --new-flag-name - -``` go -func aliasNormalizeFunc(f *pflag.FlagSet, name string) pflag.NormalizedName { - switch name { - case "old-flag-name": - name = "new-flag-name" - break - } - return pflag.NormalizedName(name) -} - -myFlagSet.SetNormalizeFunc(aliasNormalizeFunc) -``` - -## Deprecating a flag or its shorthand -It is possible to deprecate a flag, or just its shorthand. Deprecating a flag/shorthand hides it from help text and prints a usage message when the deprecated flag/shorthand is used. - -**Example #1**: You want to deprecate a flag named "badflag" as well as inform the users what flag they should use instead. -```go -// deprecate a flag by specifying its name and a usage message -flags.MarkDeprecated("badflag", "please use --good-flag instead") -``` -This hides "badflag" from help text, and prints `Flag --badflag has been deprecated, please use --good-flag instead` when "badflag" is used. - -**Example #2**: You want to keep a flag name "noshorthandflag" but deprecate its shortname "n". -```go -// deprecate a flag shorthand by specifying its flag name and a usage message -flags.MarkShorthandDeprecated("noshorthandflag", "please use --noshorthandflag only") -``` -This hides the shortname "n" from help text, and prints `Flag shorthand -n has been deprecated, please use --noshorthandflag only` when the shorthand "n" is used. - -Note that usage message is essential here, and it should not be empty. - -## Hidden flags -It is possible to mark a flag as hidden, meaning it will still function as normal, however will not show up in usage/help text. - -**Example**: You have a flag named "secretFlag" that you need for internal use only and don't want it showing up in help text, or for its usage text to be available. -```go -// hide a flag by specifying its name -flags.MarkHidden("secretFlag") -``` - -## Disable sorting of flags -`pflag` allows you to disable sorting of flags for help and usage message. - -**Example**: -```go -flags.BoolP("verbose", "v", false, "verbose output") -flags.String("coolflag", "yeaah", "it's really cool flag") -flags.Int("usefulflag", 777, "sometimes it's very useful") -flags.SortFlags = false -flags.PrintDefaults() -``` -**Output**: -``` - -v, --verbose verbose output - --coolflag string it's really cool flag (default "yeaah") - --usefulflag int sometimes it's very useful (default 777) -``` - - -## Supporting Go flags when using pflag -In order to support flags defined using Go's `flag` package, they must be added to the `pflag` flagset. This is usually necessary -to support flags defined by third-party dependencies (e.g. `golang/glog`). - -**Example**: You want to add the Go flags to the `CommandLine` flagset -```go -import ( - goflag "flag" - flag "github.com/spf13/pflag" -) - -var ip *int = flag.Int("flagname", 1234, "help message for flagname") - -func main() { - flag.CommandLine.AddGoFlagSet(goflag.CommandLine) - flag.Parse() -} -``` - -## More info - -You can see the full reference documentation of the pflag package -[at godoc.org][3], or through go's standard documentation system by -running `godoc -http=:6060` and browsing to -[http://localhost:6060/pkg/github.com/spf13/pflag][2] after -installation. - -[2]: http://localhost:6060/pkg/github.com/spf13/pflag -[3]: http://godoc.org/github.com/spf13/pflag diff --git a/vendor/github.com/spf13/pflag/bool.go b/vendor/github.com/spf13/pflag/bool.go deleted file mode 100644 index c4c5c0bfda..0000000000 --- a/vendor/github.com/spf13/pflag/bool.go +++ /dev/null @@ -1,94 +0,0 @@ -package pflag - -import "strconv" - -// optional interface to indicate boolean flags that can be -// supplied without "=value" text -type boolFlag interface { - Value - IsBoolFlag() bool -} - -// -- bool Value -type boolValue bool - -func newBoolValue(val bool, p *bool) *boolValue { - *p = val - return (*boolValue)(p) -} - -func (b *boolValue) Set(s string) error { - v, err := strconv.ParseBool(s) - *b = boolValue(v) - return err -} - -func (b *boolValue) Type() string { - return "bool" -} - -func (b *boolValue) String() string { return strconv.FormatBool(bool(*b)) } - -func (b *boolValue) IsBoolFlag() bool { return true } - -func boolConv(sval string) (interface{}, error) { - return strconv.ParseBool(sval) -} - -// GetBool return the bool value of a flag with the given name -func (f *FlagSet) GetBool(name string) (bool, error) { - val, err := f.getFlagType(name, "bool", boolConv) - if err != nil { - return false, err - } - return val.(bool), nil -} - -// BoolVar defines a bool flag with specified name, default value, and usage string. -// The argument p points to a bool variable in which to store the value of the flag. -func (f *FlagSet) BoolVar(p *bool, name string, value bool, usage string) { - f.BoolVarP(p, name, "", value, usage) -} - -// BoolVarP is like BoolVar, but accepts a shorthand letter that can be used after a single dash. -func (f *FlagSet) BoolVarP(p *bool, name, shorthand string, value bool, usage string) { - flag := f.VarPF(newBoolValue(value, p), name, shorthand, usage) - flag.NoOptDefVal = "true" -} - -// BoolVar defines a bool flag with specified name, default value, and usage string. -// The argument p points to a bool variable in which to store the value of the flag. -func BoolVar(p *bool, name string, value bool, usage string) { - BoolVarP(p, name, "", value, usage) -} - -// BoolVarP is like BoolVar, but accepts a shorthand letter that can be used after a single dash. -func BoolVarP(p *bool, name, shorthand string, value bool, usage string) { - flag := CommandLine.VarPF(newBoolValue(value, p), name, shorthand, usage) - flag.NoOptDefVal = "true" -} - -// Bool defines a bool flag with specified name, default value, and usage string. -// The return value is the address of a bool variable that stores the value of the flag. -func (f *FlagSet) Bool(name string, value bool, usage string) *bool { - return f.BoolP(name, "", value, usage) -} - -// BoolP is like Bool, but accepts a shorthand letter that can be used after a single dash. -func (f *FlagSet) BoolP(name, shorthand string, value bool, usage string) *bool { - p := new(bool) - f.BoolVarP(p, name, shorthand, value, usage) - return p -} - -// Bool defines a bool flag with specified name, default value, and usage string. -// The return value is the address of a bool variable that stores the value of the flag. -func Bool(name string, value bool, usage string) *bool { - return BoolP(name, "", value, usage) -} - -// BoolP is like Bool, but accepts a shorthand letter that can be used after a single dash. -func BoolP(name, shorthand string, value bool, usage string) *bool { - b := CommandLine.BoolP(name, shorthand, value, usage) - return b -} diff --git a/vendor/github.com/spf13/pflag/bool_slice.go b/vendor/github.com/spf13/pflag/bool_slice.go deleted file mode 100644 index 3731370d6a..0000000000 --- a/vendor/github.com/spf13/pflag/bool_slice.go +++ /dev/null @@ -1,185 +0,0 @@ -package pflag - -import ( - "io" - "strconv" - "strings" -) - -// -- boolSlice Value -type boolSliceValue struct { - value *[]bool - changed bool -} - -func newBoolSliceValue(val []bool, p *[]bool) *boolSliceValue { - bsv := new(boolSliceValue) - bsv.value = p - *bsv.value = val - return bsv -} - -// Set converts, and assigns, the comma-separated boolean argument string representation as the []bool value of this flag. -// If Set is called on a flag that already has a []bool assigned, the newly converted values will be appended. -func (s *boolSliceValue) Set(val string) error { - - // remove all quote characters - rmQuote := strings.NewReplacer(`"`, "", `'`, "", "`", "") - - // read flag arguments with CSV parser - boolStrSlice, err := readAsCSV(rmQuote.Replace(val)) - if err != nil && err != io.EOF { - return err - } - - // parse boolean values into slice - out := make([]bool, 0, len(boolStrSlice)) - for _, boolStr := range boolStrSlice { - b, err := strconv.ParseBool(strings.TrimSpace(boolStr)) - if err != nil { - return err - } - out = append(out, b) - } - - if !s.changed { - *s.value = out - } else { - *s.value = append(*s.value, out...) - } - - s.changed = true - - return nil -} - -// Type returns a string that uniquely represents this flag's type. -func (s *boolSliceValue) Type() string { - return "boolSlice" -} - -// String defines a "native" format for this boolean slice flag value. -func (s *boolSliceValue) String() string { - - boolStrSlice := make([]string, len(*s.value)) - for i, b := range *s.value { - boolStrSlice[i] = strconv.FormatBool(b) - } - - out, _ := writeAsCSV(boolStrSlice) - - return "[" + out + "]" -} - -func (s *boolSliceValue) fromString(val string) (bool, error) { - return strconv.ParseBool(val) -} - -func (s *boolSliceValue) toString(val bool) string { - return strconv.FormatBool(val) -} - -func (s *boolSliceValue) Append(val string) error { - i, err := s.fromString(val) - if err != nil { - return err - } - *s.value = append(*s.value, i) - return nil -} - -func (s *boolSliceValue) Replace(val []string) error { - out := make([]bool, len(val)) - for i, d := range val { - var err error - out[i], err = s.fromString(d) - if err != nil { - return err - } - } - *s.value = out - return nil -} - -func (s *boolSliceValue) GetSlice() []string { - out := make([]string, len(*s.value)) - for i, d := range *s.value { - out[i] = s.toString(d) - } - return out -} - -func boolSliceConv(val string) (interface{}, error) { - val = strings.Trim(val, "[]") - // Empty string would cause a slice with one (empty) entry - if len(val) == 0 { - return []bool{}, nil - } - ss := strings.Split(val, ",") - out := make([]bool, len(ss)) - for i, t := range ss { - var err error - out[i], err = strconv.ParseBool(t) - if err != nil { - return nil, err - } - } - return out, nil -} - -// GetBoolSlice returns the []bool value of a flag with the given name. -func (f *FlagSet) GetBoolSlice(name string) ([]bool, error) { - val, err := f.getFlagType(name, "boolSlice", boolSliceConv) - if err != nil { - return []bool{}, err - } - return val.([]bool), nil -} - -// BoolSliceVar defines a boolSlice flag with specified name, default value, and usage string. -// The argument p points to a []bool variable in which to store the value of the flag. -func (f *FlagSet) BoolSliceVar(p *[]bool, name string, value []bool, usage string) { - f.VarP(newBoolSliceValue(value, p), name, "", usage) -} - -// BoolSliceVarP is like BoolSliceVar, but accepts a shorthand letter that can be used after a single dash. -func (f *FlagSet) BoolSliceVarP(p *[]bool, name, shorthand string, value []bool, usage string) { - f.VarP(newBoolSliceValue(value, p), name, shorthand, usage) -} - -// BoolSliceVar defines a []bool flag with specified name, default value, and usage string. -// The argument p points to a []bool variable in which to store the value of the flag. -func BoolSliceVar(p *[]bool, name string, value []bool, usage string) { - CommandLine.VarP(newBoolSliceValue(value, p), name, "", usage) -} - -// BoolSliceVarP is like BoolSliceVar, but accepts a shorthand letter that can be used after a single dash. -func BoolSliceVarP(p *[]bool, name, shorthand string, value []bool, usage string) { - CommandLine.VarP(newBoolSliceValue(value, p), name, shorthand, usage) -} - -// BoolSlice defines a []bool flag with specified name, default value, and usage string. -// The return value is the address of a []bool variable that stores the value of the flag. -func (f *FlagSet) BoolSlice(name string, value []bool, usage string) *[]bool { - p := []bool{} - f.BoolSliceVarP(&p, name, "", value, usage) - return &p -} - -// BoolSliceP is like BoolSlice, but accepts a shorthand letter that can be used after a single dash. -func (f *FlagSet) BoolSliceP(name, shorthand string, value []bool, usage string) *[]bool { - p := []bool{} - f.BoolSliceVarP(&p, name, shorthand, value, usage) - return &p -} - -// BoolSlice defines a []bool flag with specified name, default value, and usage string. -// The return value is the address of a []bool variable that stores the value of the flag. -func BoolSlice(name string, value []bool, usage string) *[]bool { - return CommandLine.BoolSliceP(name, "", value, usage) -} - -// BoolSliceP is like BoolSlice, but accepts a shorthand letter that can be used after a single dash. -func BoolSliceP(name, shorthand string, value []bool, usage string) *[]bool { - return CommandLine.BoolSliceP(name, shorthand, value, usage) -} diff --git a/vendor/github.com/spf13/pflag/bytes.go b/vendor/github.com/spf13/pflag/bytes.go deleted file mode 100644 index 67d5304570..0000000000 --- a/vendor/github.com/spf13/pflag/bytes.go +++ /dev/null @@ -1,209 +0,0 @@ -package pflag - -import ( - "encoding/base64" - "encoding/hex" - "fmt" - "strings" -) - -// BytesHex adapts []byte for use as a flag. Value of flag is HEX encoded -type bytesHexValue []byte - -// String implements pflag.Value.String. -func (bytesHex bytesHexValue) String() string { - return fmt.Sprintf("%X", []byte(bytesHex)) -} - -// Set implements pflag.Value.Set. -func (bytesHex *bytesHexValue) Set(value string) error { - bin, err := hex.DecodeString(strings.TrimSpace(value)) - - if err != nil { - return err - } - - *bytesHex = bin - - return nil -} - -// Type implements pflag.Value.Type. -func (*bytesHexValue) Type() string { - return "bytesHex" -} - -func newBytesHexValue(val []byte, p *[]byte) *bytesHexValue { - *p = val - return (*bytesHexValue)(p) -} - -func bytesHexConv(sval string) (interface{}, error) { - - bin, err := hex.DecodeString(sval) - - if err == nil { - return bin, nil - } - - return nil, fmt.Errorf("invalid string being converted to Bytes: %s %s", sval, err) -} - -// GetBytesHex return the []byte value of a flag with the given name -func (f *FlagSet) GetBytesHex(name string) ([]byte, error) { - val, err := f.getFlagType(name, "bytesHex", bytesHexConv) - - if err != nil { - return []byte{}, err - } - - return val.([]byte), nil -} - -// BytesHexVar defines an []byte flag with specified name, default value, and usage string. -// The argument p points to an []byte variable in which to store the value of the flag. -func (f *FlagSet) BytesHexVar(p *[]byte, name string, value []byte, usage string) { - f.VarP(newBytesHexValue(value, p), name, "", usage) -} - -// BytesHexVarP is like BytesHexVar, but accepts a shorthand letter that can be used after a single dash. -func (f *FlagSet) BytesHexVarP(p *[]byte, name, shorthand string, value []byte, usage string) { - f.VarP(newBytesHexValue(value, p), name, shorthand, usage) -} - -// BytesHexVar defines an []byte flag with specified name, default value, and usage string. -// The argument p points to an []byte variable in which to store the value of the flag. -func BytesHexVar(p *[]byte, name string, value []byte, usage string) { - CommandLine.VarP(newBytesHexValue(value, p), name, "", usage) -} - -// BytesHexVarP is like BytesHexVar, but accepts a shorthand letter that can be used after a single dash. -func BytesHexVarP(p *[]byte, name, shorthand string, value []byte, usage string) { - CommandLine.VarP(newBytesHexValue(value, p), name, shorthand, usage) -} - -// BytesHex defines an []byte flag with specified name, default value, and usage string. -// The return value is the address of an []byte variable that stores the value of the flag. -func (f *FlagSet) BytesHex(name string, value []byte, usage string) *[]byte { - p := new([]byte) - f.BytesHexVarP(p, name, "", value, usage) - return p -} - -// BytesHexP is like BytesHex, but accepts a shorthand letter that can be used after a single dash. -func (f *FlagSet) BytesHexP(name, shorthand string, value []byte, usage string) *[]byte { - p := new([]byte) - f.BytesHexVarP(p, name, shorthand, value, usage) - return p -} - -// BytesHex defines an []byte flag with specified name, default value, and usage string. -// The return value is the address of an []byte variable that stores the value of the flag. -func BytesHex(name string, value []byte, usage string) *[]byte { - return CommandLine.BytesHexP(name, "", value, usage) -} - -// BytesHexP is like BytesHex, but accepts a shorthand letter that can be used after a single dash. -func BytesHexP(name, shorthand string, value []byte, usage string) *[]byte { - return CommandLine.BytesHexP(name, shorthand, value, usage) -} - -// BytesBase64 adapts []byte for use as a flag. Value of flag is Base64 encoded -type bytesBase64Value []byte - -// String implements pflag.Value.String. -func (bytesBase64 bytesBase64Value) String() string { - return base64.StdEncoding.EncodeToString([]byte(bytesBase64)) -} - -// Set implements pflag.Value.Set. -func (bytesBase64 *bytesBase64Value) Set(value string) error { - bin, err := base64.StdEncoding.DecodeString(strings.TrimSpace(value)) - - if err != nil { - return err - } - - *bytesBase64 = bin - - return nil -} - -// Type implements pflag.Value.Type. -func (*bytesBase64Value) Type() string { - return "bytesBase64" -} - -func newBytesBase64Value(val []byte, p *[]byte) *bytesBase64Value { - *p = val - return (*bytesBase64Value)(p) -} - -func bytesBase64ValueConv(sval string) (interface{}, error) { - - bin, err := base64.StdEncoding.DecodeString(sval) - if err == nil { - return bin, nil - } - - return nil, fmt.Errorf("invalid string being converted to Bytes: %s %s", sval, err) -} - -// GetBytesBase64 return the []byte value of a flag with the given name -func (f *FlagSet) GetBytesBase64(name string) ([]byte, error) { - val, err := f.getFlagType(name, "bytesBase64", bytesBase64ValueConv) - - if err != nil { - return []byte{}, err - } - - return val.([]byte), nil -} - -// BytesBase64Var defines an []byte flag with specified name, default value, and usage string. -// The argument p points to an []byte variable in which to store the value of the flag. -func (f *FlagSet) BytesBase64Var(p *[]byte, name string, value []byte, usage string) { - f.VarP(newBytesBase64Value(value, p), name, "", usage) -} - -// BytesBase64VarP is like BytesBase64Var, but accepts a shorthand letter that can be used after a single dash. -func (f *FlagSet) BytesBase64VarP(p *[]byte, name, shorthand string, value []byte, usage string) { - f.VarP(newBytesBase64Value(value, p), name, shorthand, usage) -} - -// BytesBase64Var defines an []byte flag with specified name, default value, and usage string. -// The argument p points to an []byte variable in which to store the value of the flag. -func BytesBase64Var(p *[]byte, name string, value []byte, usage string) { - CommandLine.VarP(newBytesBase64Value(value, p), name, "", usage) -} - -// BytesBase64VarP is like BytesBase64Var, but accepts a shorthand letter that can be used after a single dash. -func BytesBase64VarP(p *[]byte, name, shorthand string, value []byte, usage string) { - CommandLine.VarP(newBytesBase64Value(value, p), name, shorthand, usage) -} - -// BytesBase64 defines an []byte flag with specified name, default value, and usage string. -// The return value is the address of an []byte variable that stores the value of the flag. -func (f *FlagSet) BytesBase64(name string, value []byte, usage string) *[]byte { - p := new([]byte) - f.BytesBase64VarP(p, name, "", value, usage) - return p -} - -// BytesBase64P is like BytesBase64, but accepts a shorthand letter that can be used after a single dash. -func (f *FlagSet) BytesBase64P(name, shorthand string, value []byte, usage string) *[]byte { - p := new([]byte) - f.BytesBase64VarP(p, name, shorthand, value, usage) - return p -} - -// BytesBase64 defines an []byte flag with specified name, default value, and usage string. -// The return value is the address of an []byte variable that stores the value of the flag. -func BytesBase64(name string, value []byte, usage string) *[]byte { - return CommandLine.BytesBase64P(name, "", value, usage) -} - -// BytesBase64P is like BytesBase64, but accepts a shorthand letter that can be used after a single dash. -func BytesBase64P(name, shorthand string, value []byte, usage string) *[]byte { - return CommandLine.BytesBase64P(name, shorthand, value, usage) -} diff --git a/vendor/github.com/spf13/pflag/count.go b/vendor/github.com/spf13/pflag/count.go deleted file mode 100644 index a0b2679f71..0000000000 --- a/vendor/github.com/spf13/pflag/count.go +++ /dev/null @@ -1,96 +0,0 @@ -package pflag - -import "strconv" - -// -- count Value -type countValue int - -func newCountValue(val int, p *int) *countValue { - *p = val - return (*countValue)(p) -} - -func (i *countValue) Set(s string) error { - // "+1" means that no specific value was passed, so increment - if s == "+1" { - *i = countValue(*i + 1) - return nil - } - v, err := strconv.ParseInt(s, 0, 0) - *i = countValue(v) - return err -} - -func (i *countValue) Type() string { - return "count" -} - -func (i *countValue) String() string { return strconv.Itoa(int(*i)) } - -func countConv(sval string) (interface{}, error) { - i, err := strconv.Atoi(sval) - if err != nil { - return nil, err - } - return i, nil -} - -// GetCount return the int value of a flag with the given name -func (f *FlagSet) GetCount(name string) (int, error) { - val, err := f.getFlagType(name, "count", countConv) - if err != nil { - return 0, err - } - return val.(int), nil -} - -// CountVar defines a count flag with specified name, default value, and usage string. -// The argument p points to an int variable in which to store the value of the flag. -// A count flag will add 1 to its value every time it is found on the command line -func (f *FlagSet) CountVar(p *int, name string, usage string) { - f.CountVarP(p, name, "", usage) -} - -// CountVarP is like CountVar only take a shorthand for the flag name. -func (f *FlagSet) CountVarP(p *int, name, shorthand string, usage string) { - flag := f.VarPF(newCountValue(0, p), name, shorthand, usage) - flag.NoOptDefVal = "+1" -} - -// CountVar like CountVar only the flag is placed on the CommandLine instead of a given flag set -func CountVar(p *int, name string, usage string) { - CommandLine.CountVar(p, name, usage) -} - -// CountVarP is like CountVar only take a shorthand for the flag name. -func CountVarP(p *int, name, shorthand string, usage string) { - CommandLine.CountVarP(p, name, shorthand, usage) -} - -// Count defines a count flag with specified name, default value, and usage string. -// The return value is the address of an int variable that stores the value of the flag. -// A count flag will add 1 to its value every time it is found on the command line -func (f *FlagSet) Count(name string, usage string) *int { - p := new(int) - f.CountVarP(p, name, "", usage) - return p -} - -// CountP is like Count only takes a shorthand for the flag name. -func (f *FlagSet) CountP(name, shorthand string, usage string) *int { - p := new(int) - f.CountVarP(p, name, shorthand, usage) - return p -} - -// Count defines a count flag with specified name, default value, and usage string. -// The return value is the address of an int variable that stores the value of the flag. -// A count flag will add 1 to its value evey time it is found on the command line -func Count(name string, usage string) *int { - return CommandLine.CountP(name, "", usage) -} - -// CountP is like Count only takes a shorthand for the flag name. -func CountP(name, shorthand string, usage string) *int { - return CommandLine.CountP(name, shorthand, usage) -} diff --git a/vendor/github.com/spf13/pflag/duration.go b/vendor/github.com/spf13/pflag/duration.go deleted file mode 100644 index e9debef88e..0000000000 --- a/vendor/github.com/spf13/pflag/duration.go +++ /dev/null @@ -1,86 +0,0 @@ -package pflag - -import ( - "time" -) - -// -- time.Duration Value -type durationValue time.Duration - -func newDurationValue(val time.Duration, p *time.Duration) *durationValue { - *p = val - return (*durationValue)(p) -} - -func (d *durationValue) Set(s string) error { - v, err := time.ParseDuration(s) - *d = durationValue(v) - return err -} - -func (d *durationValue) Type() string { - return "duration" -} - -func (d *durationValue) String() string { return (*time.Duration)(d).String() } - -func durationConv(sval string) (interface{}, error) { - return time.ParseDuration(sval) -} - -// GetDuration return the duration value of a flag with the given name -func (f *FlagSet) GetDuration(name string) (time.Duration, error) { - val, err := f.getFlagType(name, "duration", durationConv) - if err != nil { - return 0, err - } - return val.(time.Duration), nil -} - -// DurationVar defines a time.Duration flag with specified name, default value, and usage string. -// The argument p points to a time.Duration variable in which to store the value of the flag. -func (f *FlagSet) DurationVar(p *time.Duration, name string, value time.Duration, usage string) { - f.VarP(newDurationValue(value, p), name, "", usage) -} - -// DurationVarP is like DurationVar, but accepts a shorthand letter that can be used after a single dash. -func (f *FlagSet) DurationVarP(p *time.Duration, name, shorthand string, value time.Duration, usage string) { - f.VarP(newDurationValue(value, p), name, shorthand, usage) -} - -// DurationVar defines a time.Duration flag with specified name, default value, and usage string. -// The argument p points to a time.Duration variable in which to store the value of the flag. -func DurationVar(p *time.Duration, name string, value time.Duration, usage string) { - CommandLine.VarP(newDurationValue(value, p), name, "", usage) -} - -// DurationVarP is like DurationVar, but accepts a shorthand letter that can be used after a single dash. -func DurationVarP(p *time.Duration, name, shorthand string, value time.Duration, usage string) { - CommandLine.VarP(newDurationValue(value, p), name, shorthand, usage) -} - -// Duration defines a time.Duration flag with specified name, default value, and usage string. -// The return value is the address of a time.Duration variable that stores the value of the flag. -func (f *FlagSet) Duration(name string, value time.Duration, usage string) *time.Duration { - p := new(time.Duration) - f.DurationVarP(p, name, "", value, usage) - return p -} - -// DurationP is like Duration, but accepts a shorthand letter that can be used after a single dash. -func (f *FlagSet) DurationP(name, shorthand string, value time.Duration, usage string) *time.Duration { - p := new(time.Duration) - f.DurationVarP(p, name, shorthand, value, usage) - return p -} - -// Duration defines a time.Duration flag with specified name, default value, and usage string. -// The return value is the address of a time.Duration variable that stores the value of the flag. -func Duration(name string, value time.Duration, usage string) *time.Duration { - return CommandLine.DurationP(name, "", value, usage) -} - -// DurationP is like Duration, but accepts a shorthand letter that can be used after a single dash. -func DurationP(name, shorthand string, value time.Duration, usage string) *time.Duration { - return CommandLine.DurationP(name, shorthand, value, usage) -} diff --git a/vendor/github.com/spf13/pflag/duration_slice.go b/vendor/github.com/spf13/pflag/duration_slice.go deleted file mode 100644 index badadda53f..0000000000 --- a/vendor/github.com/spf13/pflag/duration_slice.go +++ /dev/null @@ -1,166 +0,0 @@ -package pflag - -import ( - "fmt" - "strings" - "time" -) - -// -- durationSlice Value -type durationSliceValue struct { - value *[]time.Duration - changed bool -} - -func newDurationSliceValue(val []time.Duration, p *[]time.Duration) *durationSliceValue { - dsv := new(durationSliceValue) - dsv.value = p - *dsv.value = val - return dsv -} - -func (s *durationSliceValue) Set(val string) error { - ss := strings.Split(val, ",") - out := make([]time.Duration, len(ss)) - for i, d := range ss { - var err error - out[i], err = time.ParseDuration(d) - if err != nil { - return err - } - - } - if !s.changed { - *s.value = out - } else { - *s.value = append(*s.value, out...) - } - s.changed = true - return nil -} - -func (s *durationSliceValue) Type() string { - return "durationSlice" -} - -func (s *durationSliceValue) String() string { - out := make([]string, len(*s.value)) - for i, d := range *s.value { - out[i] = fmt.Sprintf("%s", d) - } - return "[" + strings.Join(out, ",") + "]" -} - -func (s *durationSliceValue) fromString(val string) (time.Duration, error) { - return time.ParseDuration(val) -} - -func (s *durationSliceValue) toString(val time.Duration) string { - return fmt.Sprintf("%s", val) -} - -func (s *durationSliceValue) Append(val string) error { - i, err := s.fromString(val) - if err != nil { - return err - } - *s.value = append(*s.value, i) - return nil -} - -func (s *durationSliceValue) Replace(val []string) error { - out := make([]time.Duration, len(val)) - for i, d := range val { - var err error - out[i], err = s.fromString(d) - if err != nil { - return err - } - } - *s.value = out - return nil -} - -func (s *durationSliceValue) GetSlice() []string { - out := make([]string, len(*s.value)) - for i, d := range *s.value { - out[i] = s.toString(d) - } - return out -} - -func durationSliceConv(val string) (interface{}, error) { - val = strings.Trim(val, "[]") - // Empty string would cause a slice with one (empty) entry - if len(val) == 0 { - return []time.Duration{}, nil - } - ss := strings.Split(val, ",") - out := make([]time.Duration, len(ss)) - for i, d := range ss { - var err error - out[i], err = time.ParseDuration(d) - if err != nil { - return nil, err - } - - } - return out, nil -} - -// GetDurationSlice returns the []time.Duration value of a flag with the given name -func (f *FlagSet) GetDurationSlice(name string) ([]time.Duration, error) { - val, err := f.getFlagType(name, "durationSlice", durationSliceConv) - if err != nil { - return []time.Duration{}, err - } - return val.([]time.Duration), nil -} - -// DurationSliceVar defines a durationSlice flag with specified name, default value, and usage string. -// The argument p points to a []time.Duration variable in which to store the value of the flag. -func (f *FlagSet) DurationSliceVar(p *[]time.Duration, name string, value []time.Duration, usage string) { - f.VarP(newDurationSliceValue(value, p), name, "", usage) -} - -// DurationSliceVarP is like DurationSliceVar, but accepts a shorthand letter that can be used after a single dash. -func (f *FlagSet) DurationSliceVarP(p *[]time.Duration, name, shorthand string, value []time.Duration, usage string) { - f.VarP(newDurationSliceValue(value, p), name, shorthand, usage) -} - -// DurationSliceVar defines a duration[] flag with specified name, default value, and usage string. -// The argument p points to a duration[] variable in which to store the value of the flag. -func DurationSliceVar(p *[]time.Duration, name string, value []time.Duration, usage string) { - CommandLine.VarP(newDurationSliceValue(value, p), name, "", usage) -} - -// DurationSliceVarP is like DurationSliceVar, but accepts a shorthand letter that can be used after a single dash. -func DurationSliceVarP(p *[]time.Duration, name, shorthand string, value []time.Duration, usage string) { - CommandLine.VarP(newDurationSliceValue(value, p), name, shorthand, usage) -} - -// DurationSlice defines a []time.Duration flag with specified name, default value, and usage string. -// The return value is the address of a []time.Duration variable that stores the value of the flag. -func (f *FlagSet) DurationSlice(name string, value []time.Duration, usage string) *[]time.Duration { - p := []time.Duration{} - f.DurationSliceVarP(&p, name, "", value, usage) - return &p -} - -// DurationSliceP is like DurationSlice, but accepts a shorthand letter that can be used after a single dash. -func (f *FlagSet) DurationSliceP(name, shorthand string, value []time.Duration, usage string) *[]time.Duration { - p := []time.Duration{} - f.DurationSliceVarP(&p, name, shorthand, value, usage) - return &p -} - -// DurationSlice defines a []time.Duration flag with specified name, default value, and usage string. -// The return value is the address of a []time.Duration variable that stores the value of the flag. -func DurationSlice(name string, value []time.Duration, usage string) *[]time.Duration { - return CommandLine.DurationSliceP(name, "", value, usage) -} - -// DurationSliceP is like DurationSlice, but accepts a shorthand letter that can be used after a single dash. -func DurationSliceP(name, shorthand string, value []time.Duration, usage string) *[]time.Duration { - return CommandLine.DurationSliceP(name, shorthand, value, usage) -} diff --git a/vendor/github.com/spf13/pflag/flag.go b/vendor/github.com/spf13/pflag/flag.go deleted file mode 100644 index 24a5036e95..0000000000 --- a/vendor/github.com/spf13/pflag/flag.go +++ /dev/null @@ -1,1239 +0,0 @@ -// Copyright 2009 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -/* -Package pflag is a drop-in replacement for Go's flag package, implementing -POSIX/GNU-style --flags. - -pflag is compatible with the GNU extensions to the POSIX recommendations -for command-line options. See -http://www.gnu.org/software/libc/manual/html_node/Argument-Syntax.html - -Usage: - -pflag is a drop-in replacement of Go's native flag package. If you import -pflag under the name "flag" then all code should continue to function -with no changes. - - import flag "github.com/spf13/pflag" - -There is one exception to this: if you directly instantiate the Flag struct -there is one more field "Shorthand" that you will need to set. -Most code never instantiates this struct directly, and instead uses -functions such as String(), BoolVar(), and Var(), and is therefore -unaffected. - -Define flags using flag.String(), Bool(), Int(), etc. - -This declares an integer flag, -flagname, stored in the pointer ip, with type *int. - var ip = flag.Int("flagname", 1234, "help message for flagname") -If you like, you can bind the flag to a variable using the Var() functions. - var flagvar int - func init() { - flag.IntVar(&flagvar, "flagname", 1234, "help message for flagname") - } -Or you can create custom flags that satisfy the Value interface (with -pointer receivers) and couple them to flag parsing by - flag.Var(&flagVal, "name", "help message for flagname") -For such flags, the default value is just the initial value of the variable. - -After all flags are defined, call - flag.Parse() -to parse the command line into the defined flags. - -Flags may then be used directly. If you're using the flags themselves, -they are all pointers; if you bind to variables, they're values. - fmt.Println("ip has value ", *ip) - fmt.Println("flagvar has value ", flagvar) - -After parsing, the arguments after the flag are available as the -slice flag.Args() or individually as flag.Arg(i). -The arguments are indexed from 0 through flag.NArg()-1. - -The pflag package also defines some new functions that are not in flag, -that give one-letter shorthands for flags. You can use these by appending -'P' to the name of any function that defines a flag. - var ip = flag.IntP("flagname", "f", 1234, "help message") - var flagvar bool - func init() { - flag.BoolVarP(&flagvar, "boolname", "b", true, "help message") - } - flag.VarP(&flagval, "varname", "v", "help message") -Shorthand letters can be used with single dashes on the command line. -Boolean shorthand flags can be combined with other shorthand flags. - -Command line flag syntax: - --flag // boolean flags only - --flag=x - -Unlike the flag package, a single dash before an option means something -different than a double dash. Single dashes signify a series of shorthand -letters for flags. All but the last shorthand letter must be boolean flags. - // boolean flags - -f - -abc - // non-boolean flags - -n 1234 - -Ifile - // mixed - -abcs "hello" - -abcn1234 - -Flag parsing stops after the terminator "--". Unlike the flag package, -flags can be interspersed with arguments anywhere on the command line -before this terminator. - -Integer flags accept 1234, 0664, 0x1234 and may be negative. -Boolean flags (in their long form) accept 1, 0, t, f, true, false, -TRUE, FALSE, True, False. -Duration flags accept any input valid for time.ParseDuration. - -The default set of command-line flags is controlled by -top-level functions. The FlagSet type allows one to define -independent sets of flags, such as to implement subcommands -in a command-line interface. The methods of FlagSet are -analogous to the top-level functions for the command-line -flag set. -*/ -package pflag - -import ( - "bytes" - "errors" - goflag "flag" - "fmt" - "io" - "os" - "sort" - "strings" -) - -// ErrHelp is the error returned if the flag -help is invoked but no such flag is defined. -var ErrHelp = errors.New("pflag: help requested") - -// ErrorHandling defines how to handle flag parsing errors. -type ErrorHandling int - -const ( - // ContinueOnError will return an err from Parse() if an error is found - ContinueOnError ErrorHandling = iota - // ExitOnError will call os.Exit(2) if an error is found when parsing - ExitOnError - // PanicOnError will panic() if an error is found when parsing flags - PanicOnError -) - -// ParseErrorsWhitelist defines the parsing errors that can be ignored -type ParseErrorsWhitelist struct { - // UnknownFlags will ignore unknown flags errors and continue parsing rest of the flags - UnknownFlags bool -} - -// NormalizedName is a flag name that has been normalized according to rules -// for the FlagSet (e.g. making '-' and '_' equivalent). -type NormalizedName string - -// A FlagSet represents a set of defined flags. -type FlagSet struct { - // Usage is the function called when an error occurs while parsing flags. - // The field is a function (not a method) that may be changed to point to - // a custom error handler. - Usage func() - - // SortFlags is used to indicate, if user wants to have sorted flags in - // help/usage messages. - SortFlags bool - - // ParseErrorsWhitelist is used to configure a whitelist of errors - ParseErrorsWhitelist ParseErrorsWhitelist - - name string - parsed bool - actual map[NormalizedName]*Flag - orderedActual []*Flag - sortedActual []*Flag - formal map[NormalizedName]*Flag - orderedFormal []*Flag - sortedFormal []*Flag - shorthands map[byte]*Flag - args []string // arguments after flags - argsLenAtDash int // len(args) when a '--' was located when parsing, or -1 if no -- - errorHandling ErrorHandling - output io.Writer // nil means stderr; use out() accessor - interspersed bool // allow interspersed option/non-option args - normalizeNameFunc func(f *FlagSet, name string) NormalizedName - - addedGoFlagSets []*goflag.FlagSet -} - -// A Flag represents the state of a flag. -type Flag struct { - Name string // name as it appears on command line - Shorthand string // one-letter abbreviated flag - Usage string // help message - Value Value // value as set - DefValue string // default value (as text); for usage message - Changed bool // If the user set the value (or if left to default) - NoOptDefVal string // default value (as text); if the flag is on the command line without any options - Deprecated string // If this flag is deprecated, this string is the new or now thing to use - Hidden bool // used by cobra.Command to allow flags to be hidden from help/usage text - ShorthandDeprecated string // If the shorthand of this flag is deprecated, this string is the new or now thing to use - Annotations map[string][]string // used by cobra.Command bash autocomple code -} - -// Value is the interface to the dynamic value stored in a flag. -// (The default value is represented as a string.) -type Value interface { - String() string - Set(string) error - Type() string -} - -// SliceValue is a secondary interface to all flags which hold a list -// of values. This allows full control over the value of list flags, -// and avoids complicated marshalling and unmarshalling to csv. -type SliceValue interface { - // Append adds the specified value to the end of the flag value list. - Append(string) error - // Replace will fully overwrite any data currently in the flag value list. - Replace([]string) error - // GetSlice returns the flag value list as an array of strings. - GetSlice() []string -} - -// sortFlags returns the flags as a slice in lexicographical sorted order. -func sortFlags(flags map[NormalizedName]*Flag) []*Flag { - list := make(sort.StringSlice, len(flags)) - i := 0 - for k := range flags { - list[i] = string(k) - i++ - } - list.Sort() - result := make([]*Flag, len(list)) - for i, name := range list { - result[i] = flags[NormalizedName(name)] - } - return result -} - -// SetNormalizeFunc allows you to add a function which can translate flag names. -// Flags added to the FlagSet will be translated and then when anything tries to -// look up the flag that will also be translated. So it would be possible to create -// a flag named "getURL" and have it translated to "geturl". A user could then pass -// "--getUrl" which may also be translated to "geturl" and everything will work. -func (f *FlagSet) SetNormalizeFunc(n func(f *FlagSet, name string) NormalizedName) { - f.normalizeNameFunc = n - f.sortedFormal = f.sortedFormal[:0] - for fname, flag := range f.formal { - nname := f.normalizeFlagName(flag.Name) - if fname == nname { - continue - } - flag.Name = string(nname) - delete(f.formal, fname) - f.formal[nname] = flag - if _, set := f.actual[fname]; set { - delete(f.actual, fname) - f.actual[nname] = flag - } - } -} - -// GetNormalizeFunc returns the previously set NormalizeFunc of a function which -// does no translation, if not set previously. -func (f *FlagSet) GetNormalizeFunc() func(f *FlagSet, name string) NormalizedName { - if f.normalizeNameFunc != nil { - return f.normalizeNameFunc - } - return func(f *FlagSet, name string) NormalizedName { return NormalizedName(name) } -} - -func (f *FlagSet) normalizeFlagName(name string) NormalizedName { - n := f.GetNormalizeFunc() - return n(f, name) -} - -func (f *FlagSet) out() io.Writer { - if f.output == nil { - return os.Stderr - } - return f.output -} - -// SetOutput sets the destination for usage and error messages. -// If output is nil, os.Stderr is used. -func (f *FlagSet) SetOutput(output io.Writer) { - f.output = output -} - -// VisitAll visits the flags in lexicographical order or -// in primordial order if f.SortFlags is false, calling fn for each. -// It visits all flags, even those not set. -func (f *FlagSet) VisitAll(fn func(*Flag)) { - if len(f.formal) == 0 { - return - } - - var flags []*Flag - if f.SortFlags { - if len(f.formal) != len(f.sortedFormal) { - f.sortedFormal = sortFlags(f.formal) - } - flags = f.sortedFormal - } else { - flags = f.orderedFormal - } - - for _, flag := range flags { - fn(flag) - } -} - -// HasFlags returns a bool to indicate if the FlagSet has any flags defined. -func (f *FlagSet) HasFlags() bool { - return len(f.formal) > 0 -} - -// HasAvailableFlags returns a bool to indicate if the FlagSet has any flags -// that are not hidden. -func (f *FlagSet) HasAvailableFlags() bool { - for _, flag := range f.formal { - if !flag.Hidden { - return true - } - } - return false -} - -// VisitAll visits the command-line flags in lexicographical order or -// in primordial order if f.SortFlags is false, calling fn for each. -// It visits all flags, even those not set. -func VisitAll(fn func(*Flag)) { - CommandLine.VisitAll(fn) -} - -// Visit visits the flags in lexicographical order or -// in primordial order if f.SortFlags is false, calling fn for each. -// It visits only those flags that have been set. -func (f *FlagSet) Visit(fn func(*Flag)) { - if len(f.actual) == 0 { - return - } - - var flags []*Flag - if f.SortFlags { - if len(f.actual) != len(f.sortedActual) { - f.sortedActual = sortFlags(f.actual) - } - flags = f.sortedActual - } else { - flags = f.orderedActual - } - - for _, flag := range flags { - fn(flag) - } -} - -// Visit visits the command-line flags in lexicographical order or -// in primordial order if f.SortFlags is false, calling fn for each. -// It visits only those flags that have been set. -func Visit(fn func(*Flag)) { - CommandLine.Visit(fn) -} - -// Lookup returns the Flag structure of the named flag, returning nil if none exists. -func (f *FlagSet) Lookup(name string) *Flag { - return f.lookup(f.normalizeFlagName(name)) -} - -// ShorthandLookup returns the Flag structure of the short handed flag, -// returning nil if none exists. -// It panics, if len(name) > 1. -func (f *FlagSet) ShorthandLookup(name string) *Flag { - if name == "" { - return nil - } - if len(name) > 1 { - msg := fmt.Sprintf("can not look up shorthand which is more than one ASCII character: %q", name) - fmt.Fprintf(f.out(), msg) - panic(msg) - } - c := name[0] - return f.shorthands[c] -} - -// lookup returns the Flag structure of the named flag, returning nil if none exists. -func (f *FlagSet) lookup(name NormalizedName) *Flag { - return f.formal[name] -} - -// func to return a given type for a given flag name -func (f *FlagSet) getFlagType(name string, ftype string, convFunc func(sval string) (interface{}, error)) (interface{}, error) { - flag := f.Lookup(name) - if flag == nil { - err := fmt.Errorf("flag accessed but not defined: %s", name) - return nil, err - } - - if flag.Value.Type() != ftype { - err := fmt.Errorf("trying to get %s value of flag of type %s", ftype, flag.Value.Type()) - return nil, err - } - - sval := flag.Value.String() - result, err := convFunc(sval) - if err != nil { - return nil, err - } - return result, nil -} - -// ArgsLenAtDash will return the length of f.Args at the moment when a -- was -// found during arg parsing. This allows your program to know which args were -// before the -- and which came after. -func (f *FlagSet) ArgsLenAtDash() int { - return f.argsLenAtDash -} - -// MarkDeprecated indicated that a flag is deprecated in your program. It will -// continue to function but will not show up in help or usage messages. Using -// this flag will also print the given usageMessage. -func (f *FlagSet) MarkDeprecated(name string, usageMessage string) error { - flag := f.Lookup(name) - if flag == nil { - return fmt.Errorf("flag %q does not exist", name) - } - if usageMessage == "" { - return fmt.Errorf("deprecated message for flag %q must be set", name) - } - flag.Deprecated = usageMessage - flag.Hidden = true - return nil -} - -// MarkShorthandDeprecated will mark the shorthand of a flag deprecated in your -// program. It will continue to function but will not show up in help or usage -// messages. Using this flag will also print the given usageMessage. -func (f *FlagSet) MarkShorthandDeprecated(name string, usageMessage string) error { - flag := f.Lookup(name) - if flag == nil { - return fmt.Errorf("flag %q does not exist", name) - } - if usageMessage == "" { - return fmt.Errorf("deprecated message for flag %q must be set", name) - } - flag.ShorthandDeprecated = usageMessage - return nil -} - -// MarkHidden sets a flag to 'hidden' in your program. It will continue to -// function but will not show up in help or usage messages. -func (f *FlagSet) MarkHidden(name string) error { - flag := f.Lookup(name) - if flag == nil { - return fmt.Errorf("flag %q does not exist", name) - } - flag.Hidden = true - return nil -} - -// Lookup returns the Flag structure of the named command-line flag, -// returning nil if none exists. -func Lookup(name string) *Flag { - return CommandLine.Lookup(name) -} - -// ShorthandLookup returns the Flag structure of the short handed flag, -// returning nil if none exists. -func ShorthandLookup(name string) *Flag { - return CommandLine.ShorthandLookup(name) -} - -// Set sets the value of the named flag. -func (f *FlagSet) Set(name, value string) error { - normalName := f.normalizeFlagName(name) - flag, ok := f.formal[normalName] - if !ok { - return fmt.Errorf("no such flag -%v", name) - } - - err := flag.Value.Set(value) - if err != nil { - var flagName string - if flag.Shorthand != "" && flag.ShorthandDeprecated == "" { - flagName = fmt.Sprintf("-%s, --%s", flag.Shorthand, flag.Name) - } else { - flagName = fmt.Sprintf("--%s", flag.Name) - } - return fmt.Errorf("invalid argument %q for %q flag: %v", value, flagName, err) - } - - if !flag.Changed { - if f.actual == nil { - f.actual = make(map[NormalizedName]*Flag) - } - f.actual[normalName] = flag - f.orderedActual = append(f.orderedActual, flag) - - flag.Changed = true - } - - if flag.Deprecated != "" { - fmt.Fprintf(f.out(), "Flag --%s has been deprecated, %s\n", flag.Name, flag.Deprecated) - } - return nil -} - -// SetAnnotation allows one to set arbitrary annotations on a flag in the FlagSet. -// This is sometimes used by spf13/cobra programs which want to generate additional -// bash completion information. -func (f *FlagSet) SetAnnotation(name, key string, values []string) error { - normalName := f.normalizeFlagName(name) - flag, ok := f.formal[normalName] - if !ok { - return fmt.Errorf("no such flag -%v", name) - } - if flag.Annotations == nil { - flag.Annotations = map[string][]string{} - } - flag.Annotations[key] = values - return nil -} - -// Changed returns true if the flag was explicitly set during Parse() and false -// otherwise -func (f *FlagSet) Changed(name string) bool { - flag := f.Lookup(name) - // If a flag doesn't exist, it wasn't changed.... - if flag == nil { - return false - } - return flag.Changed -} - -// Set sets the value of the named command-line flag. -func Set(name, value string) error { - return CommandLine.Set(name, value) -} - -// PrintDefaults prints, to standard error unless configured -// otherwise, the default values of all defined flags in the set. -func (f *FlagSet) PrintDefaults() { - usages := f.FlagUsages() - fmt.Fprint(f.out(), usages) -} - -// defaultIsZeroValue returns true if the default value for this flag represents -// a zero value. -func (f *Flag) defaultIsZeroValue() bool { - switch f.Value.(type) { - case boolFlag: - return f.DefValue == "false" - case *durationValue: - // Beginning in Go 1.7, duration zero values are "0s" - return f.DefValue == "0" || f.DefValue == "0s" - case *intValue, *int8Value, *int32Value, *int64Value, *uintValue, *uint8Value, *uint16Value, *uint32Value, *uint64Value, *countValue, *float32Value, *float64Value: - return f.DefValue == "0" - case *stringValue: - return f.DefValue == "" - case *ipValue, *ipMaskValue, *ipNetValue: - return f.DefValue == "" - case *intSliceValue, *stringSliceValue, *stringArrayValue: - return f.DefValue == "[]" - default: - switch f.Value.String() { - case "false": - return true - case "": - return true - case "": - return true - case "0": - return true - } - return false - } -} - -// UnquoteUsage extracts a back-quoted name from the usage -// string for a flag and returns it and the un-quoted usage. -// Given "a `name` to show" it returns ("name", "a name to show"). -// If there are no back quotes, the name is an educated guess of the -// type of the flag's value, or the empty string if the flag is boolean. -func UnquoteUsage(flag *Flag) (name string, usage string) { - // Look for a back-quoted name, but avoid the strings package. - usage = flag.Usage - for i := 0; i < len(usage); i++ { - if usage[i] == '`' { - for j := i + 1; j < len(usage); j++ { - if usage[j] == '`' { - name = usage[i+1 : j] - usage = usage[:i] + name + usage[j+1:] - return name, usage - } - } - break // Only one back quote; use type name. - } - } - - name = flag.Value.Type() - switch name { - case "bool": - name = "" - case "float64": - name = "float" - case "int64": - name = "int" - case "uint64": - name = "uint" - case "stringSlice": - name = "strings" - case "intSlice": - name = "ints" - case "uintSlice": - name = "uints" - case "boolSlice": - name = "bools" - } - - return -} - -// Splits the string `s` on whitespace into an initial substring up to -// `i` runes in length and the remainder. Will go `slop` over `i` if -// that encompasses the entire string (which allows the caller to -// avoid short orphan words on the final line). -func wrapN(i, slop int, s string) (string, string) { - if i+slop > len(s) { - return s, "" - } - - w := strings.LastIndexAny(s[:i], " \t\n") - if w <= 0 { - return s, "" - } - nlPos := strings.LastIndex(s[:i], "\n") - if nlPos > 0 && nlPos < w { - return s[:nlPos], s[nlPos+1:] - } - return s[:w], s[w+1:] -} - -// Wraps the string `s` to a maximum width `w` with leading indent -// `i`. The first line is not indented (this is assumed to be done by -// caller). Pass `w` == 0 to do no wrapping -func wrap(i, w int, s string) string { - if w == 0 { - return strings.Replace(s, "\n", "\n"+strings.Repeat(" ", i), -1) - } - - // space between indent i and end of line width w into which - // we should wrap the text. - wrap := w - i - - var r, l string - - // Not enough space for sensible wrapping. Wrap as a block on - // the next line instead. - if wrap < 24 { - i = 16 - wrap = w - i - r += "\n" + strings.Repeat(" ", i) - } - // If still not enough space then don't even try to wrap. - if wrap < 24 { - return strings.Replace(s, "\n", r, -1) - } - - // Try to avoid short orphan words on the final line, by - // allowing wrapN to go a bit over if that would fit in the - // remainder of the line. - slop := 5 - wrap = wrap - slop - - // Handle first line, which is indented by the caller (or the - // special case above) - l, s = wrapN(wrap, slop, s) - r = r + strings.Replace(l, "\n", "\n"+strings.Repeat(" ", i), -1) - - // Now wrap the rest - for s != "" { - var t string - - t, s = wrapN(wrap, slop, s) - r = r + "\n" + strings.Repeat(" ", i) + strings.Replace(t, "\n", "\n"+strings.Repeat(" ", i), -1) - } - - return r - -} - -// FlagUsagesWrapped returns a string containing the usage information -// for all flags in the FlagSet. Wrapped to `cols` columns (0 for no -// wrapping) -func (f *FlagSet) FlagUsagesWrapped(cols int) string { - buf := new(bytes.Buffer) - - lines := make([]string, 0, len(f.formal)) - - maxlen := 0 - f.VisitAll(func(flag *Flag) { - if flag.Hidden { - return - } - - line := "" - if flag.Shorthand != "" && flag.ShorthandDeprecated == "" { - line = fmt.Sprintf(" -%s, --%s", flag.Shorthand, flag.Name) - } else { - line = fmt.Sprintf(" --%s", flag.Name) - } - - varname, usage := UnquoteUsage(flag) - if varname != "" { - line += " " + varname - } - if flag.NoOptDefVal != "" { - switch flag.Value.Type() { - case "string": - line += fmt.Sprintf("[=\"%s\"]", flag.NoOptDefVal) - case "bool": - if flag.NoOptDefVal != "true" { - line += fmt.Sprintf("[=%s]", flag.NoOptDefVal) - } - case "count": - if flag.NoOptDefVal != "+1" { - line += fmt.Sprintf("[=%s]", flag.NoOptDefVal) - } - default: - line += fmt.Sprintf("[=%s]", flag.NoOptDefVal) - } - } - - // This special character will be replaced with spacing once the - // correct alignment is calculated - line += "\x00" - if len(line) > maxlen { - maxlen = len(line) - } - - line += usage - if !flag.defaultIsZeroValue() { - if flag.Value.Type() == "string" { - line += fmt.Sprintf(" (default %q)", flag.DefValue) - } else { - line += fmt.Sprintf(" (default %s)", flag.DefValue) - } - } - if len(flag.Deprecated) != 0 { - line += fmt.Sprintf(" (DEPRECATED: %s)", flag.Deprecated) - } - - lines = append(lines, line) - }) - - for _, line := range lines { - sidx := strings.Index(line, "\x00") - spacing := strings.Repeat(" ", maxlen-sidx) - // maxlen + 2 comes from + 1 for the \x00 and + 1 for the (deliberate) off-by-one in maxlen-sidx - fmt.Fprintln(buf, line[:sidx], spacing, wrap(maxlen+2, cols, line[sidx+1:])) - } - - return buf.String() -} - -// FlagUsages returns a string containing the usage information for all flags in -// the FlagSet -func (f *FlagSet) FlagUsages() string { - return f.FlagUsagesWrapped(0) -} - -// PrintDefaults prints to standard error the default values of all defined command-line flags. -func PrintDefaults() { - CommandLine.PrintDefaults() -} - -// defaultUsage is the default function to print a usage message. -func defaultUsage(f *FlagSet) { - fmt.Fprintf(f.out(), "Usage of %s:\n", f.name) - f.PrintDefaults() -} - -// NOTE: Usage is not just defaultUsage(CommandLine) -// because it serves (via godoc flag Usage) as the example -// for how to write your own usage function. - -// Usage prints to standard error a usage message documenting all defined command-line flags. -// The function is a variable that may be changed to point to a custom function. -// By default it prints a simple header and calls PrintDefaults; for details about the -// format of the output and how to control it, see the documentation for PrintDefaults. -var Usage = func() { - fmt.Fprintf(os.Stderr, "Usage of %s:\n", os.Args[0]) - PrintDefaults() -} - -// NFlag returns the number of flags that have been set. -func (f *FlagSet) NFlag() int { return len(f.actual) } - -// NFlag returns the number of command-line flags that have been set. -func NFlag() int { return len(CommandLine.actual) } - -// Arg returns the i'th argument. Arg(0) is the first remaining argument -// after flags have been processed. -func (f *FlagSet) Arg(i int) string { - if i < 0 || i >= len(f.args) { - return "" - } - return f.args[i] -} - -// Arg returns the i'th command-line argument. Arg(0) is the first remaining argument -// after flags have been processed. -func Arg(i int) string { - return CommandLine.Arg(i) -} - -// NArg is the number of arguments remaining after flags have been processed. -func (f *FlagSet) NArg() int { return len(f.args) } - -// NArg is the number of arguments remaining after flags have been processed. -func NArg() int { return len(CommandLine.args) } - -// Args returns the non-flag arguments. -func (f *FlagSet) Args() []string { return f.args } - -// Args returns the non-flag command-line arguments. -func Args() []string { return CommandLine.args } - -// Var defines a flag with the specified name and usage string. The type and -// value of the flag are represented by the first argument, of type Value, which -// typically holds a user-defined implementation of Value. For instance, the -// caller could create a flag that turns a comma-separated string into a slice -// of strings by giving the slice the methods of Value; in particular, Set would -// decompose the comma-separated string into the slice. -func (f *FlagSet) Var(value Value, name string, usage string) { - f.VarP(value, name, "", usage) -} - -// VarPF is like VarP, but returns the flag created -func (f *FlagSet) VarPF(value Value, name, shorthand, usage string) *Flag { - // Remember the default value as a string; it won't change. - flag := &Flag{ - Name: name, - Shorthand: shorthand, - Usage: usage, - Value: value, - DefValue: value.String(), - } - f.AddFlag(flag) - return flag -} - -// VarP is like Var, but accepts a shorthand letter that can be used after a single dash. -func (f *FlagSet) VarP(value Value, name, shorthand, usage string) { - f.VarPF(value, name, shorthand, usage) -} - -// AddFlag will add the flag to the FlagSet -func (f *FlagSet) AddFlag(flag *Flag) { - normalizedFlagName := f.normalizeFlagName(flag.Name) - - _, alreadyThere := f.formal[normalizedFlagName] - if alreadyThere { - msg := fmt.Sprintf("%s flag redefined: %s", f.name, flag.Name) - fmt.Fprintln(f.out(), msg) - panic(msg) // Happens only if flags are declared with identical names - } - if f.formal == nil { - f.formal = make(map[NormalizedName]*Flag) - } - - flag.Name = string(normalizedFlagName) - f.formal[normalizedFlagName] = flag - f.orderedFormal = append(f.orderedFormal, flag) - - if flag.Shorthand == "" { - return - } - if len(flag.Shorthand) > 1 { - msg := fmt.Sprintf("%q shorthand is more than one ASCII character", flag.Shorthand) - fmt.Fprintf(f.out(), msg) - panic(msg) - } - if f.shorthands == nil { - f.shorthands = make(map[byte]*Flag) - } - c := flag.Shorthand[0] - used, alreadyThere := f.shorthands[c] - if alreadyThere { - msg := fmt.Sprintf("unable to redefine %q shorthand in %q flagset: it's already used for %q flag", c, f.name, used.Name) - fmt.Fprintf(f.out(), msg) - panic(msg) - } - f.shorthands[c] = flag -} - -// AddFlagSet adds one FlagSet to another. If a flag is already present in f -// the flag from newSet will be ignored. -func (f *FlagSet) AddFlagSet(newSet *FlagSet) { - if newSet == nil { - return - } - newSet.VisitAll(func(flag *Flag) { - if f.Lookup(flag.Name) == nil { - f.AddFlag(flag) - } - }) -} - -// Var defines a flag with the specified name and usage string. The type and -// value of the flag are represented by the first argument, of type Value, which -// typically holds a user-defined implementation of Value. For instance, the -// caller could create a flag that turns a comma-separated string into a slice -// of strings by giving the slice the methods of Value; in particular, Set would -// decompose the comma-separated string into the slice. -func Var(value Value, name string, usage string) { - CommandLine.VarP(value, name, "", usage) -} - -// VarP is like Var, but accepts a shorthand letter that can be used after a single dash. -func VarP(value Value, name, shorthand, usage string) { - CommandLine.VarP(value, name, shorthand, usage) -} - -// failf prints to standard error a formatted error and usage message and -// returns the error. -func (f *FlagSet) failf(format string, a ...interface{}) error { - err := fmt.Errorf(format, a...) - if f.errorHandling != ContinueOnError { - fmt.Fprintln(f.out(), err) - f.usage() - } - return err -} - -// usage calls the Usage method for the flag set, or the usage function if -// the flag set is CommandLine. -func (f *FlagSet) usage() { - if f == CommandLine { - Usage() - } else if f.Usage == nil { - defaultUsage(f) - } else { - f.Usage() - } -} - -//--unknown (args will be empty) -//--unknown --next-flag ... (args will be --next-flag ...) -//--unknown arg ... (args will be arg ...) -func stripUnknownFlagValue(args []string) []string { - if len(args) == 0 { - //--unknown - return args - } - - first := args[0] - if len(first) > 0 && first[0] == '-' { - //--unknown --next-flag ... - return args - } - - //--unknown arg ... (args will be arg ...) - if len(args) > 1 { - return args[1:] - } - return nil -} - -func (f *FlagSet) parseLongArg(s string, args []string, fn parseFunc) (a []string, err error) { - a = args - name := s[2:] - if len(name) == 0 || name[0] == '-' || name[0] == '=' { - err = f.failf("bad flag syntax: %s", s) - return - } - - split := strings.SplitN(name, "=", 2) - name = split[0] - flag, exists := f.formal[f.normalizeFlagName(name)] - - if !exists { - switch { - case name == "help": - f.usage() - return a, ErrHelp - case f.ParseErrorsWhitelist.UnknownFlags: - // --unknown=unknownval arg ... - // we do not want to lose arg in this case - if len(split) >= 2 { - return a, nil - } - - return stripUnknownFlagValue(a), nil - default: - err = f.failf("unknown flag: --%s", name) - return - } - } - - var value string - if len(split) == 2 { - // '--flag=arg' - value = split[1] - } else if flag.NoOptDefVal != "" { - // '--flag' (arg was optional) - value = flag.NoOptDefVal - } else if len(a) > 0 { - // '--flag arg' - value = a[0] - a = a[1:] - } else { - // '--flag' (arg was required) - err = f.failf("flag needs an argument: %s", s) - return - } - - err = fn(flag, value) - if err != nil { - f.failf(err.Error()) - } - return -} - -func (f *FlagSet) parseSingleShortArg(shorthands string, args []string, fn parseFunc) (outShorts string, outArgs []string, err error) { - outArgs = args - - if strings.HasPrefix(shorthands, "test.") { - return - } - - outShorts = shorthands[1:] - c := shorthands[0] - - flag, exists := f.shorthands[c] - if !exists { - switch { - case c == 'h': - f.usage() - err = ErrHelp - return - case f.ParseErrorsWhitelist.UnknownFlags: - // '-f=arg arg ...' - // we do not want to lose arg in this case - if len(shorthands) > 2 && shorthands[1] == '=' { - outShorts = "" - return - } - - outArgs = stripUnknownFlagValue(outArgs) - return - default: - err = f.failf("unknown shorthand flag: %q in -%s", c, shorthands) - return - } - } - - var value string - if len(shorthands) > 2 && shorthands[1] == '=' { - // '-f=arg' - value = shorthands[2:] - outShorts = "" - } else if flag.NoOptDefVal != "" { - // '-f' (arg was optional) - value = flag.NoOptDefVal - } else if len(shorthands) > 1 { - // '-farg' - value = shorthands[1:] - outShorts = "" - } else if len(args) > 0 { - // '-f arg' - value = args[0] - outArgs = args[1:] - } else { - // '-f' (arg was required) - err = f.failf("flag needs an argument: %q in -%s", c, shorthands) - return - } - - if flag.ShorthandDeprecated != "" { - fmt.Fprintf(f.out(), "Flag shorthand -%s has been deprecated, %s\n", flag.Shorthand, flag.ShorthandDeprecated) - } - - err = fn(flag, value) - if err != nil { - f.failf(err.Error()) - } - return -} - -func (f *FlagSet) parseShortArg(s string, args []string, fn parseFunc) (a []string, err error) { - a = args - shorthands := s[1:] - - // "shorthands" can be a series of shorthand letters of flags (e.g. "-vvv"). - for len(shorthands) > 0 { - shorthands, a, err = f.parseSingleShortArg(shorthands, args, fn) - if err != nil { - return - } - } - - return -} - -func (f *FlagSet) parseArgs(args []string, fn parseFunc) (err error) { - for len(args) > 0 { - s := args[0] - args = args[1:] - if len(s) == 0 || s[0] != '-' || len(s) == 1 { - if !f.interspersed { - f.args = append(f.args, s) - f.args = append(f.args, args...) - return nil - } - f.args = append(f.args, s) - continue - } - - if s[1] == '-' { - if len(s) == 2 { // "--" terminates the flags - f.argsLenAtDash = len(f.args) - f.args = append(f.args, args...) - break - } - args, err = f.parseLongArg(s, args, fn) - } else { - args, err = f.parseShortArg(s, args, fn) - } - if err != nil { - return - } - } - return -} - -// Parse parses flag definitions from the argument list, which should not -// include the command name. Must be called after all flags in the FlagSet -// are defined and before flags are accessed by the program. -// The return value will be ErrHelp if -help was set but not defined. -func (f *FlagSet) Parse(arguments []string) error { - if f.addedGoFlagSets != nil { - for _, goFlagSet := range f.addedGoFlagSets { - goFlagSet.Parse(nil) - } - } - f.parsed = true - - if len(arguments) < 0 { - return nil - } - - f.args = make([]string, 0, len(arguments)) - - set := func(flag *Flag, value string) error { - return f.Set(flag.Name, value) - } - - err := f.parseArgs(arguments, set) - if err != nil { - switch f.errorHandling { - case ContinueOnError: - return err - case ExitOnError: - fmt.Println(err) - os.Exit(2) - case PanicOnError: - panic(err) - } - } - return nil -} - -type parseFunc func(flag *Flag, value string) error - -// ParseAll parses flag definitions from the argument list, which should not -// include the command name. The arguments for fn are flag and value. Must be -// called after all flags in the FlagSet are defined and before flags are -// accessed by the program. The return value will be ErrHelp if -help was set -// but not defined. -func (f *FlagSet) ParseAll(arguments []string, fn func(flag *Flag, value string) error) error { - f.parsed = true - f.args = make([]string, 0, len(arguments)) - - err := f.parseArgs(arguments, fn) - if err != nil { - switch f.errorHandling { - case ContinueOnError: - return err - case ExitOnError: - os.Exit(2) - case PanicOnError: - panic(err) - } - } - return nil -} - -// Parsed reports whether f.Parse has been called. -func (f *FlagSet) Parsed() bool { - return f.parsed -} - -// Parse parses the command-line flags from os.Args[1:]. Must be called -// after all flags are defined and before flags are accessed by the program. -func Parse() { - // Ignore errors; CommandLine is set for ExitOnError. - CommandLine.Parse(os.Args[1:]) -} - -// ParseAll parses the command-line flags from os.Args[1:] and called fn for each. -// The arguments for fn are flag and value. Must be called after all flags are -// defined and before flags are accessed by the program. -func ParseAll(fn func(flag *Flag, value string) error) { - // Ignore errors; CommandLine is set for ExitOnError. - CommandLine.ParseAll(os.Args[1:], fn) -} - -// SetInterspersed sets whether to support interspersed option/non-option arguments. -func SetInterspersed(interspersed bool) { - CommandLine.SetInterspersed(interspersed) -} - -// Parsed returns true if the command-line flags have been parsed. -func Parsed() bool { - return CommandLine.Parsed() -} - -// CommandLine is the default set of command-line flags, parsed from os.Args. -var CommandLine = NewFlagSet(os.Args[0], ExitOnError) - -// NewFlagSet returns a new, empty flag set with the specified name, -// error handling property and SortFlags set to true. -func NewFlagSet(name string, errorHandling ErrorHandling) *FlagSet { - f := &FlagSet{ - name: name, - errorHandling: errorHandling, - argsLenAtDash: -1, - interspersed: true, - SortFlags: true, - } - return f -} - -// SetInterspersed sets whether to support interspersed option/non-option arguments. -func (f *FlagSet) SetInterspersed(interspersed bool) { - f.interspersed = interspersed -} - -// Init sets the name and error handling property for a flag set. -// By default, the zero FlagSet uses an empty name and the -// ContinueOnError error handling policy. -func (f *FlagSet) Init(name string, errorHandling ErrorHandling) { - f.name = name - f.errorHandling = errorHandling - f.argsLenAtDash = -1 -} diff --git a/vendor/github.com/spf13/pflag/float32.go b/vendor/github.com/spf13/pflag/float32.go deleted file mode 100644 index a243f81f7f..0000000000 --- a/vendor/github.com/spf13/pflag/float32.go +++ /dev/null @@ -1,88 +0,0 @@ -package pflag - -import "strconv" - -// -- float32 Value -type float32Value float32 - -func newFloat32Value(val float32, p *float32) *float32Value { - *p = val - return (*float32Value)(p) -} - -func (f *float32Value) Set(s string) error { - v, err := strconv.ParseFloat(s, 32) - *f = float32Value(v) - return err -} - -func (f *float32Value) Type() string { - return "float32" -} - -func (f *float32Value) String() string { return strconv.FormatFloat(float64(*f), 'g', -1, 32) } - -func float32Conv(sval string) (interface{}, error) { - v, err := strconv.ParseFloat(sval, 32) - if err != nil { - return 0, err - } - return float32(v), nil -} - -// GetFloat32 return the float32 value of a flag with the given name -func (f *FlagSet) GetFloat32(name string) (float32, error) { - val, err := f.getFlagType(name, "float32", float32Conv) - if err != nil { - return 0, err - } - return val.(float32), nil -} - -// Float32Var defines a float32 flag with specified name, default value, and usage string. -// The argument p points to a float32 variable in which to store the value of the flag. -func (f *FlagSet) Float32Var(p *float32, name string, value float32, usage string) { - f.VarP(newFloat32Value(value, p), name, "", usage) -} - -// Float32VarP is like Float32Var, but accepts a shorthand letter that can be used after a single dash. -func (f *FlagSet) Float32VarP(p *float32, name, shorthand string, value float32, usage string) { - f.VarP(newFloat32Value(value, p), name, shorthand, usage) -} - -// Float32Var defines a float32 flag with specified name, default value, and usage string. -// The argument p points to a float32 variable in which to store the value of the flag. -func Float32Var(p *float32, name string, value float32, usage string) { - CommandLine.VarP(newFloat32Value(value, p), name, "", usage) -} - -// Float32VarP is like Float32Var, but accepts a shorthand letter that can be used after a single dash. -func Float32VarP(p *float32, name, shorthand string, value float32, usage string) { - CommandLine.VarP(newFloat32Value(value, p), name, shorthand, usage) -} - -// Float32 defines a float32 flag with specified name, default value, and usage string. -// The return value is the address of a float32 variable that stores the value of the flag. -func (f *FlagSet) Float32(name string, value float32, usage string) *float32 { - p := new(float32) - f.Float32VarP(p, name, "", value, usage) - return p -} - -// Float32P is like Float32, but accepts a shorthand letter that can be used after a single dash. -func (f *FlagSet) Float32P(name, shorthand string, value float32, usage string) *float32 { - p := new(float32) - f.Float32VarP(p, name, shorthand, value, usage) - return p -} - -// Float32 defines a float32 flag with specified name, default value, and usage string. -// The return value is the address of a float32 variable that stores the value of the flag. -func Float32(name string, value float32, usage string) *float32 { - return CommandLine.Float32P(name, "", value, usage) -} - -// Float32P is like Float32, but accepts a shorthand letter that can be used after a single dash. -func Float32P(name, shorthand string, value float32, usage string) *float32 { - return CommandLine.Float32P(name, shorthand, value, usage) -} diff --git a/vendor/github.com/spf13/pflag/float32_slice.go b/vendor/github.com/spf13/pflag/float32_slice.go deleted file mode 100644 index caa352741a..0000000000 --- a/vendor/github.com/spf13/pflag/float32_slice.go +++ /dev/null @@ -1,174 +0,0 @@ -package pflag - -import ( - "fmt" - "strconv" - "strings" -) - -// -- float32Slice Value -type float32SliceValue struct { - value *[]float32 - changed bool -} - -func newFloat32SliceValue(val []float32, p *[]float32) *float32SliceValue { - isv := new(float32SliceValue) - isv.value = p - *isv.value = val - return isv -} - -func (s *float32SliceValue) Set(val string) error { - ss := strings.Split(val, ",") - out := make([]float32, len(ss)) - for i, d := range ss { - var err error - var temp64 float64 - temp64, err = strconv.ParseFloat(d, 32) - if err != nil { - return err - } - out[i] = float32(temp64) - - } - if !s.changed { - *s.value = out - } else { - *s.value = append(*s.value, out...) - } - s.changed = true - return nil -} - -func (s *float32SliceValue) Type() string { - return "float32Slice" -} - -func (s *float32SliceValue) String() string { - out := make([]string, len(*s.value)) - for i, d := range *s.value { - out[i] = fmt.Sprintf("%f", d) - } - return "[" + strings.Join(out, ",") + "]" -} - -func (s *float32SliceValue) fromString(val string) (float32, error) { - t64, err := strconv.ParseFloat(val, 32) - if err != nil { - return 0, err - } - return float32(t64), nil -} - -func (s *float32SliceValue) toString(val float32) string { - return fmt.Sprintf("%f", val) -} - -func (s *float32SliceValue) Append(val string) error { - i, err := s.fromString(val) - if err != nil { - return err - } - *s.value = append(*s.value, i) - return nil -} - -func (s *float32SliceValue) Replace(val []string) error { - out := make([]float32, len(val)) - for i, d := range val { - var err error - out[i], err = s.fromString(d) - if err != nil { - return err - } - } - *s.value = out - return nil -} - -func (s *float32SliceValue) GetSlice() []string { - out := make([]string, len(*s.value)) - for i, d := range *s.value { - out[i] = s.toString(d) - } - return out -} - -func float32SliceConv(val string) (interface{}, error) { - val = strings.Trim(val, "[]") - // Empty string would cause a slice with one (empty) entry - if len(val) == 0 { - return []float32{}, nil - } - ss := strings.Split(val, ",") - out := make([]float32, len(ss)) - for i, d := range ss { - var err error - var temp64 float64 - temp64, err = strconv.ParseFloat(d, 32) - if err != nil { - return nil, err - } - out[i] = float32(temp64) - - } - return out, nil -} - -// GetFloat32Slice return the []float32 value of a flag with the given name -func (f *FlagSet) GetFloat32Slice(name string) ([]float32, error) { - val, err := f.getFlagType(name, "float32Slice", float32SliceConv) - if err != nil { - return []float32{}, err - } - return val.([]float32), nil -} - -// Float32SliceVar defines a float32Slice flag with specified name, default value, and usage string. -// The argument p points to a []float32 variable in which to store the value of the flag. -func (f *FlagSet) Float32SliceVar(p *[]float32, name string, value []float32, usage string) { - f.VarP(newFloat32SliceValue(value, p), name, "", usage) -} - -// Float32SliceVarP is like Float32SliceVar, but accepts a shorthand letter that can be used after a single dash. -func (f *FlagSet) Float32SliceVarP(p *[]float32, name, shorthand string, value []float32, usage string) { - f.VarP(newFloat32SliceValue(value, p), name, shorthand, usage) -} - -// Float32SliceVar defines a float32[] flag with specified name, default value, and usage string. -// The argument p points to a float32[] variable in which to store the value of the flag. -func Float32SliceVar(p *[]float32, name string, value []float32, usage string) { - CommandLine.VarP(newFloat32SliceValue(value, p), name, "", usage) -} - -// Float32SliceVarP is like Float32SliceVar, but accepts a shorthand letter that can be used after a single dash. -func Float32SliceVarP(p *[]float32, name, shorthand string, value []float32, usage string) { - CommandLine.VarP(newFloat32SliceValue(value, p), name, shorthand, usage) -} - -// Float32Slice defines a []float32 flag with specified name, default value, and usage string. -// The return value is the address of a []float32 variable that stores the value of the flag. -func (f *FlagSet) Float32Slice(name string, value []float32, usage string) *[]float32 { - p := []float32{} - f.Float32SliceVarP(&p, name, "", value, usage) - return &p -} - -// Float32SliceP is like Float32Slice, but accepts a shorthand letter that can be used after a single dash. -func (f *FlagSet) Float32SliceP(name, shorthand string, value []float32, usage string) *[]float32 { - p := []float32{} - f.Float32SliceVarP(&p, name, shorthand, value, usage) - return &p -} - -// Float32Slice defines a []float32 flag with specified name, default value, and usage string. -// The return value is the address of a []float32 variable that stores the value of the flag. -func Float32Slice(name string, value []float32, usage string) *[]float32 { - return CommandLine.Float32SliceP(name, "", value, usage) -} - -// Float32SliceP is like Float32Slice, but accepts a shorthand letter that can be used after a single dash. -func Float32SliceP(name, shorthand string, value []float32, usage string) *[]float32 { - return CommandLine.Float32SliceP(name, shorthand, value, usage) -} diff --git a/vendor/github.com/spf13/pflag/float64.go b/vendor/github.com/spf13/pflag/float64.go deleted file mode 100644 index 04b5492a7d..0000000000 --- a/vendor/github.com/spf13/pflag/float64.go +++ /dev/null @@ -1,84 +0,0 @@ -package pflag - -import "strconv" - -// -- float64 Value -type float64Value float64 - -func newFloat64Value(val float64, p *float64) *float64Value { - *p = val - return (*float64Value)(p) -} - -func (f *float64Value) Set(s string) error { - v, err := strconv.ParseFloat(s, 64) - *f = float64Value(v) - return err -} - -func (f *float64Value) Type() string { - return "float64" -} - -func (f *float64Value) String() string { return strconv.FormatFloat(float64(*f), 'g', -1, 64) } - -func float64Conv(sval string) (interface{}, error) { - return strconv.ParseFloat(sval, 64) -} - -// GetFloat64 return the float64 value of a flag with the given name -func (f *FlagSet) GetFloat64(name string) (float64, error) { - val, err := f.getFlagType(name, "float64", float64Conv) - if err != nil { - return 0, err - } - return val.(float64), nil -} - -// Float64Var defines a float64 flag with specified name, default value, and usage string. -// The argument p points to a float64 variable in which to store the value of the flag. -func (f *FlagSet) Float64Var(p *float64, name string, value float64, usage string) { - f.VarP(newFloat64Value(value, p), name, "", usage) -} - -// Float64VarP is like Float64Var, but accepts a shorthand letter that can be used after a single dash. -func (f *FlagSet) Float64VarP(p *float64, name, shorthand string, value float64, usage string) { - f.VarP(newFloat64Value(value, p), name, shorthand, usage) -} - -// Float64Var defines a float64 flag with specified name, default value, and usage string. -// The argument p points to a float64 variable in which to store the value of the flag. -func Float64Var(p *float64, name string, value float64, usage string) { - CommandLine.VarP(newFloat64Value(value, p), name, "", usage) -} - -// Float64VarP is like Float64Var, but accepts a shorthand letter that can be used after a single dash. -func Float64VarP(p *float64, name, shorthand string, value float64, usage string) { - CommandLine.VarP(newFloat64Value(value, p), name, shorthand, usage) -} - -// Float64 defines a float64 flag with specified name, default value, and usage string. -// The return value is the address of a float64 variable that stores the value of the flag. -func (f *FlagSet) Float64(name string, value float64, usage string) *float64 { - p := new(float64) - f.Float64VarP(p, name, "", value, usage) - return p -} - -// Float64P is like Float64, but accepts a shorthand letter that can be used after a single dash. -func (f *FlagSet) Float64P(name, shorthand string, value float64, usage string) *float64 { - p := new(float64) - f.Float64VarP(p, name, shorthand, value, usage) - return p -} - -// Float64 defines a float64 flag with specified name, default value, and usage string. -// The return value is the address of a float64 variable that stores the value of the flag. -func Float64(name string, value float64, usage string) *float64 { - return CommandLine.Float64P(name, "", value, usage) -} - -// Float64P is like Float64, but accepts a shorthand letter that can be used after a single dash. -func Float64P(name, shorthand string, value float64, usage string) *float64 { - return CommandLine.Float64P(name, shorthand, value, usage) -} diff --git a/vendor/github.com/spf13/pflag/float64_slice.go b/vendor/github.com/spf13/pflag/float64_slice.go deleted file mode 100644 index 85bf3073d5..0000000000 --- a/vendor/github.com/spf13/pflag/float64_slice.go +++ /dev/null @@ -1,166 +0,0 @@ -package pflag - -import ( - "fmt" - "strconv" - "strings" -) - -// -- float64Slice Value -type float64SliceValue struct { - value *[]float64 - changed bool -} - -func newFloat64SliceValue(val []float64, p *[]float64) *float64SliceValue { - isv := new(float64SliceValue) - isv.value = p - *isv.value = val - return isv -} - -func (s *float64SliceValue) Set(val string) error { - ss := strings.Split(val, ",") - out := make([]float64, len(ss)) - for i, d := range ss { - var err error - out[i], err = strconv.ParseFloat(d, 64) - if err != nil { - return err - } - - } - if !s.changed { - *s.value = out - } else { - *s.value = append(*s.value, out...) - } - s.changed = true - return nil -} - -func (s *float64SliceValue) Type() string { - return "float64Slice" -} - -func (s *float64SliceValue) String() string { - out := make([]string, len(*s.value)) - for i, d := range *s.value { - out[i] = fmt.Sprintf("%f", d) - } - return "[" + strings.Join(out, ",") + "]" -} - -func (s *float64SliceValue) fromString(val string) (float64, error) { - return strconv.ParseFloat(val, 64) -} - -func (s *float64SliceValue) toString(val float64) string { - return fmt.Sprintf("%f", val) -} - -func (s *float64SliceValue) Append(val string) error { - i, err := s.fromString(val) - if err != nil { - return err - } - *s.value = append(*s.value, i) - return nil -} - -func (s *float64SliceValue) Replace(val []string) error { - out := make([]float64, len(val)) - for i, d := range val { - var err error - out[i], err = s.fromString(d) - if err != nil { - return err - } - } - *s.value = out - return nil -} - -func (s *float64SliceValue) GetSlice() []string { - out := make([]string, len(*s.value)) - for i, d := range *s.value { - out[i] = s.toString(d) - } - return out -} - -func float64SliceConv(val string) (interface{}, error) { - val = strings.Trim(val, "[]") - // Empty string would cause a slice with one (empty) entry - if len(val) == 0 { - return []float64{}, nil - } - ss := strings.Split(val, ",") - out := make([]float64, len(ss)) - for i, d := range ss { - var err error - out[i], err = strconv.ParseFloat(d, 64) - if err != nil { - return nil, err - } - - } - return out, nil -} - -// GetFloat64Slice return the []float64 value of a flag with the given name -func (f *FlagSet) GetFloat64Slice(name string) ([]float64, error) { - val, err := f.getFlagType(name, "float64Slice", float64SliceConv) - if err != nil { - return []float64{}, err - } - return val.([]float64), nil -} - -// Float64SliceVar defines a float64Slice flag with specified name, default value, and usage string. -// The argument p points to a []float64 variable in which to store the value of the flag. -func (f *FlagSet) Float64SliceVar(p *[]float64, name string, value []float64, usage string) { - f.VarP(newFloat64SliceValue(value, p), name, "", usage) -} - -// Float64SliceVarP is like Float64SliceVar, but accepts a shorthand letter that can be used after a single dash. -func (f *FlagSet) Float64SliceVarP(p *[]float64, name, shorthand string, value []float64, usage string) { - f.VarP(newFloat64SliceValue(value, p), name, shorthand, usage) -} - -// Float64SliceVar defines a float64[] flag with specified name, default value, and usage string. -// The argument p points to a float64[] variable in which to store the value of the flag. -func Float64SliceVar(p *[]float64, name string, value []float64, usage string) { - CommandLine.VarP(newFloat64SliceValue(value, p), name, "", usage) -} - -// Float64SliceVarP is like Float64SliceVar, but accepts a shorthand letter that can be used after a single dash. -func Float64SliceVarP(p *[]float64, name, shorthand string, value []float64, usage string) { - CommandLine.VarP(newFloat64SliceValue(value, p), name, shorthand, usage) -} - -// Float64Slice defines a []float64 flag with specified name, default value, and usage string. -// The return value is the address of a []float64 variable that stores the value of the flag. -func (f *FlagSet) Float64Slice(name string, value []float64, usage string) *[]float64 { - p := []float64{} - f.Float64SliceVarP(&p, name, "", value, usage) - return &p -} - -// Float64SliceP is like Float64Slice, but accepts a shorthand letter that can be used after a single dash. -func (f *FlagSet) Float64SliceP(name, shorthand string, value []float64, usage string) *[]float64 { - p := []float64{} - f.Float64SliceVarP(&p, name, shorthand, value, usage) - return &p -} - -// Float64Slice defines a []float64 flag with specified name, default value, and usage string. -// The return value is the address of a []float64 variable that stores the value of the flag. -func Float64Slice(name string, value []float64, usage string) *[]float64 { - return CommandLine.Float64SliceP(name, "", value, usage) -} - -// Float64SliceP is like Float64Slice, but accepts a shorthand letter that can be used after a single dash. -func Float64SliceP(name, shorthand string, value []float64, usage string) *[]float64 { - return CommandLine.Float64SliceP(name, shorthand, value, usage) -} diff --git a/vendor/github.com/spf13/pflag/go.mod b/vendor/github.com/spf13/pflag/go.mod deleted file mode 100644 index b2287eec13..0000000000 --- a/vendor/github.com/spf13/pflag/go.mod +++ /dev/null @@ -1,3 +0,0 @@ -module github.com/spf13/pflag - -go 1.12 diff --git a/vendor/github.com/spf13/pflag/go.sum b/vendor/github.com/spf13/pflag/go.sum deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/vendor/github.com/spf13/pflag/golangflag.go b/vendor/github.com/spf13/pflag/golangflag.go deleted file mode 100644 index d3dd72b7fe..0000000000 --- a/vendor/github.com/spf13/pflag/golangflag.go +++ /dev/null @@ -1,105 +0,0 @@ -// Copyright 2009 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package pflag - -import ( - goflag "flag" - "reflect" - "strings" -) - -// flagValueWrapper implements pflag.Value around a flag.Value. The main -// difference here is the addition of the Type method that returns a string -// name of the type. As this is generally unknown, we approximate that with -// reflection. -type flagValueWrapper struct { - inner goflag.Value - flagType string -} - -// We are just copying the boolFlag interface out of goflag as that is what -// they use to decide if a flag should get "true" when no arg is given. -type goBoolFlag interface { - goflag.Value - IsBoolFlag() bool -} - -func wrapFlagValue(v goflag.Value) Value { - // If the flag.Value happens to also be a pflag.Value, just use it directly. - if pv, ok := v.(Value); ok { - return pv - } - - pv := &flagValueWrapper{ - inner: v, - } - - t := reflect.TypeOf(v) - if t.Kind() == reflect.Interface || t.Kind() == reflect.Ptr { - t = t.Elem() - } - - pv.flagType = strings.TrimSuffix(t.Name(), "Value") - return pv -} - -func (v *flagValueWrapper) String() string { - return v.inner.String() -} - -func (v *flagValueWrapper) Set(s string) error { - return v.inner.Set(s) -} - -func (v *flagValueWrapper) Type() string { - return v.flagType -} - -// PFlagFromGoFlag will return a *pflag.Flag given a *flag.Flag -// If the *flag.Flag.Name was a single character (ex: `v`) it will be accessiblei -// with both `-v` and `--v` in flags. If the golang flag was more than a single -// character (ex: `verbose`) it will only be accessible via `--verbose` -func PFlagFromGoFlag(goflag *goflag.Flag) *Flag { - // Remember the default value as a string; it won't change. - flag := &Flag{ - Name: goflag.Name, - Usage: goflag.Usage, - Value: wrapFlagValue(goflag.Value), - // Looks like golang flags don't set DefValue correctly :-( - //DefValue: goflag.DefValue, - DefValue: goflag.Value.String(), - } - // Ex: if the golang flag was -v, allow both -v and --v to work - if len(flag.Name) == 1 { - flag.Shorthand = flag.Name - } - if fv, ok := goflag.Value.(goBoolFlag); ok && fv.IsBoolFlag() { - flag.NoOptDefVal = "true" - } - return flag -} - -// AddGoFlag will add the given *flag.Flag to the pflag.FlagSet -func (f *FlagSet) AddGoFlag(goflag *goflag.Flag) { - if f.Lookup(goflag.Name) != nil { - return - } - newflag := PFlagFromGoFlag(goflag) - f.AddFlag(newflag) -} - -// AddGoFlagSet will add the given *flag.FlagSet to the pflag.FlagSet -func (f *FlagSet) AddGoFlagSet(newSet *goflag.FlagSet) { - if newSet == nil { - return - } - newSet.VisitAll(func(goflag *goflag.Flag) { - f.AddGoFlag(goflag) - }) - if f.addedGoFlagSets == nil { - f.addedGoFlagSets = make([]*goflag.FlagSet, 0) - } - f.addedGoFlagSets = append(f.addedGoFlagSets, newSet) -} diff --git a/vendor/github.com/spf13/pflag/int.go b/vendor/github.com/spf13/pflag/int.go deleted file mode 100644 index 1474b89df6..0000000000 --- a/vendor/github.com/spf13/pflag/int.go +++ /dev/null @@ -1,84 +0,0 @@ -package pflag - -import "strconv" - -// -- int Value -type intValue int - -func newIntValue(val int, p *int) *intValue { - *p = val - return (*intValue)(p) -} - -func (i *intValue) Set(s string) error { - v, err := strconv.ParseInt(s, 0, 64) - *i = intValue(v) - return err -} - -func (i *intValue) Type() string { - return "int" -} - -func (i *intValue) String() string { return strconv.Itoa(int(*i)) } - -func intConv(sval string) (interface{}, error) { - return strconv.Atoi(sval) -} - -// GetInt return the int value of a flag with the given name -func (f *FlagSet) GetInt(name string) (int, error) { - val, err := f.getFlagType(name, "int", intConv) - if err != nil { - return 0, err - } - return val.(int), nil -} - -// IntVar defines an int flag with specified name, default value, and usage string. -// The argument p points to an int variable in which to store the value of the flag. -func (f *FlagSet) IntVar(p *int, name string, value int, usage string) { - f.VarP(newIntValue(value, p), name, "", usage) -} - -// IntVarP is like IntVar, but accepts a shorthand letter that can be used after a single dash. -func (f *FlagSet) IntVarP(p *int, name, shorthand string, value int, usage string) { - f.VarP(newIntValue(value, p), name, shorthand, usage) -} - -// IntVar defines an int flag with specified name, default value, and usage string. -// The argument p points to an int variable in which to store the value of the flag. -func IntVar(p *int, name string, value int, usage string) { - CommandLine.VarP(newIntValue(value, p), name, "", usage) -} - -// IntVarP is like IntVar, but accepts a shorthand letter that can be used after a single dash. -func IntVarP(p *int, name, shorthand string, value int, usage string) { - CommandLine.VarP(newIntValue(value, p), name, shorthand, usage) -} - -// Int defines an int flag with specified name, default value, and usage string. -// The return value is the address of an int variable that stores the value of the flag. -func (f *FlagSet) Int(name string, value int, usage string) *int { - p := new(int) - f.IntVarP(p, name, "", value, usage) - return p -} - -// IntP is like Int, but accepts a shorthand letter that can be used after a single dash. -func (f *FlagSet) IntP(name, shorthand string, value int, usage string) *int { - p := new(int) - f.IntVarP(p, name, shorthand, value, usage) - return p -} - -// Int defines an int flag with specified name, default value, and usage string. -// The return value is the address of an int variable that stores the value of the flag. -func Int(name string, value int, usage string) *int { - return CommandLine.IntP(name, "", value, usage) -} - -// IntP is like Int, but accepts a shorthand letter that can be used after a single dash. -func IntP(name, shorthand string, value int, usage string) *int { - return CommandLine.IntP(name, shorthand, value, usage) -} diff --git a/vendor/github.com/spf13/pflag/int16.go b/vendor/github.com/spf13/pflag/int16.go deleted file mode 100644 index f1a01d05e6..0000000000 --- a/vendor/github.com/spf13/pflag/int16.go +++ /dev/null @@ -1,88 +0,0 @@ -package pflag - -import "strconv" - -// -- int16 Value -type int16Value int16 - -func newInt16Value(val int16, p *int16) *int16Value { - *p = val - return (*int16Value)(p) -} - -func (i *int16Value) Set(s string) error { - v, err := strconv.ParseInt(s, 0, 16) - *i = int16Value(v) - return err -} - -func (i *int16Value) Type() string { - return "int16" -} - -func (i *int16Value) String() string { return strconv.FormatInt(int64(*i), 10) } - -func int16Conv(sval string) (interface{}, error) { - v, err := strconv.ParseInt(sval, 0, 16) - if err != nil { - return 0, err - } - return int16(v), nil -} - -// GetInt16 returns the int16 value of a flag with the given name -func (f *FlagSet) GetInt16(name string) (int16, error) { - val, err := f.getFlagType(name, "int16", int16Conv) - if err != nil { - return 0, err - } - return val.(int16), nil -} - -// Int16Var defines an int16 flag with specified name, default value, and usage string. -// The argument p points to an int16 variable in which to store the value of the flag. -func (f *FlagSet) Int16Var(p *int16, name string, value int16, usage string) { - f.VarP(newInt16Value(value, p), name, "", usage) -} - -// Int16VarP is like Int16Var, but accepts a shorthand letter that can be used after a single dash. -func (f *FlagSet) Int16VarP(p *int16, name, shorthand string, value int16, usage string) { - f.VarP(newInt16Value(value, p), name, shorthand, usage) -} - -// Int16Var defines an int16 flag with specified name, default value, and usage string. -// The argument p points to an int16 variable in which to store the value of the flag. -func Int16Var(p *int16, name string, value int16, usage string) { - CommandLine.VarP(newInt16Value(value, p), name, "", usage) -} - -// Int16VarP is like Int16Var, but accepts a shorthand letter that can be used after a single dash. -func Int16VarP(p *int16, name, shorthand string, value int16, usage string) { - CommandLine.VarP(newInt16Value(value, p), name, shorthand, usage) -} - -// Int16 defines an int16 flag with specified name, default value, and usage string. -// The return value is the address of an int16 variable that stores the value of the flag. -func (f *FlagSet) Int16(name string, value int16, usage string) *int16 { - p := new(int16) - f.Int16VarP(p, name, "", value, usage) - return p -} - -// Int16P is like Int16, but accepts a shorthand letter that can be used after a single dash. -func (f *FlagSet) Int16P(name, shorthand string, value int16, usage string) *int16 { - p := new(int16) - f.Int16VarP(p, name, shorthand, value, usage) - return p -} - -// Int16 defines an int16 flag with specified name, default value, and usage string. -// The return value is the address of an int16 variable that stores the value of the flag. -func Int16(name string, value int16, usage string) *int16 { - return CommandLine.Int16P(name, "", value, usage) -} - -// Int16P is like Int16, but accepts a shorthand letter that can be used after a single dash. -func Int16P(name, shorthand string, value int16, usage string) *int16 { - return CommandLine.Int16P(name, shorthand, value, usage) -} diff --git a/vendor/github.com/spf13/pflag/int32.go b/vendor/github.com/spf13/pflag/int32.go deleted file mode 100644 index 9b95944f0f..0000000000 --- a/vendor/github.com/spf13/pflag/int32.go +++ /dev/null @@ -1,88 +0,0 @@ -package pflag - -import "strconv" - -// -- int32 Value -type int32Value int32 - -func newInt32Value(val int32, p *int32) *int32Value { - *p = val - return (*int32Value)(p) -} - -func (i *int32Value) Set(s string) error { - v, err := strconv.ParseInt(s, 0, 32) - *i = int32Value(v) - return err -} - -func (i *int32Value) Type() string { - return "int32" -} - -func (i *int32Value) String() string { return strconv.FormatInt(int64(*i), 10) } - -func int32Conv(sval string) (interface{}, error) { - v, err := strconv.ParseInt(sval, 0, 32) - if err != nil { - return 0, err - } - return int32(v), nil -} - -// GetInt32 return the int32 value of a flag with the given name -func (f *FlagSet) GetInt32(name string) (int32, error) { - val, err := f.getFlagType(name, "int32", int32Conv) - if err != nil { - return 0, err - } - return val.(int32), nil -} - -// Int32Var defines an int32 flag with specified name, default value, and usage string. -// The argument p points to an int32 variable in which to store the value of the flag. -func (f *FlagSet) Int32Var(p *int32, name string, value int32, usage string) { - f.VarP(newInt32Value(value, p), name, "", usage) -} - -// Int32VarP is like Int32Var, but accepts a shorthand letter that can be used after a single dash. -func (f *FlagSet) Int32VarP(p *int32, name, shorthand string, value int32, usage string) { - f.VarP(newInt32Value(value, p), name, shorthand, usage) -} - -// Int32Var defines an int32 flag with specified name, default value, and usage string. -// The argument p points to an int32 variable in which to store the value of the flag. -func Int32Var(p *int32, name string, value int32, usage string) { - CommandLine.VarP(newInt32Value(value, p), name, "", usage) -} - -// Int32VarP is like Int32Var, but accepts a shorthand letter that can be used after a single dash. -func Int32VarP(p *int32, name, shorthand string, value int32, usage string) { - CommandLine.VarP(newInt32Value(value, p), name, shorthand, usage) -} - -// Int32 defines an int32 flag with specified name, default value, and usage string. -// The return value is the address of an int32 variable that stores the value of the flag. -func (f *FlagSet) Int32(name string, value int32, usage string) *int32 { - p := new(int32) - f.Int32VarP(p, name, "", value, usage) - return p -} - -// Int32P is like Int32, but accepts a shorthand letter that can be used after a single dash. -func (f *FlagSet) Int32P(name, shorthand string, value int32, usage string) *int32 { - p := new(int32) - f.Int32VarP(p, name, shorthand, value, usage) - return p -} - -// Int32 defines an int32 flag with specified name, default value, and usage string. -// The return value is the address of an int32 variable that stores the value of the flag. -func Int32(name string, value int32, usage string) *int32 { - return CommandLine.Int32P(name, "", value, usage) -} - -// Int32P is like Int32, but accepts a shorthand letter that can be used after a single dash. -func Int32P(name, shorthand string, value int32, usage string) *int32 { - return CommandLine.Int32P(name, shorthand, value, usage) -} diff --git a/vendor/github.com/spf13/pflag/int32_slice.go b/vendor/github.com/spf13/pflag/int32_slice.go deleted file mode 100644 index ff128ff06d..0000000000 --- a/vendor/github.com/spf13/pflag/int32_slice.go +++ /dev/null @@ -1,174 +0,0 @@ -package pflag - -import ( - "fmt" - "strconv" - "strings" -) - -// -- int32Slice Value -type int32SliceValue struct { - value *[]int32 - changed bool -} - -func newInt32SliceValue(val []int32, p *[]int32) *int32SliceValue { - isv := new(int32SliceValue) - isv.value = p - *isv.value = val - return isv -} - -func (s *int32SliceValue) Set(val string) error { - ss := strings.Split(val, ",") - out := make([]int32, len(ss)) - for i, d := range ss { - var err error - var temp64 int64 - temp64, err = strconv.ParseInt(d, 0, 32) - if err != nil { - return err - } - out[i] = int32(temp64) - - } - if !s.changed { - *s.value = out - } else { - *s.value = append(*s.value, out...) - } - s.changed = true - return nil -} - -func (s *int32SliceValue) Type() string { - return "int32Slice" -} - -func (s *int32SliceValue) String() string { - out := make([]string, len(*s.value)) - for i, d := range *s.value { - out[i] = fmt.Sprintf("%d", d) - } - return "[" + strings.Join(out, ",") + "]" -} - -func (s *int32SliceValue) fromString(val string) (int32, error) { - t64, err := strconv.ParseInt(val, 0, 32) - if err != nil { - return 0, err - } - return int32(t64), nil -} - -func (s *int32SliceValue) toString(val int32) string { - return fmt.Sprintf("%d", val) -} - -func (s *int32SliceValue) Append(val string) error { - i, err := s.fromString(val) - if err != nil { - return err - } - *s.value = append(*s.value, i) - return nil -} - -func (s *int32SliceValue) Replace(val []string) error { - out := make([]int32, len(val)) - for i, d := range val { - var err error - out[i], err = s.fromString(d) - if err != nil { - return err - } - } - *s.value = out - return nil -} - -func (s *int32SliceValue) GetSlice() []string { - out := make([]string, len(*s.value)) - for i, d := range *s.value { - out[i] = s.toString(d) - } - return out -} - -func int32SliceConv(val string) (interface{}, error) { - val = strings.Trim(val, "[]") - // Empty string would cause a slice with one (empty) entry - if len(val) == 0 { - return []int32{}, nil - } - ss := strings.Split(val, ",") - out := make([]int32, len(ss)) - for i, d := range ss { - var err error - var temp64 int64 - temp64, err = strconv.ParseInt(d, 0, 32) - if err != nil { - return nil, err - } - out[i] = int32(temp64) - - } - return out, nil -} - -// GetInt32Slice return the []int32 value of a flag with the given name -func (f *FlagSet) GetInt32Slice(name string) ([]int32, error) { - val, err := f.getFlagType(name, "int32Slice", int32SliceConv) - if err != nil { - return []int32{}, err - } - return val.([]int32), nil -} - -// Int32SliceVar defines a int32Slice flag with specified name, default value, and usage string. -// The argument p points to a []int32 variable in which to store the value of the flag. -func (f *FlagSet) Int32SliceVar(p *[]int32, name string, value []int32, usage string) { - f.VarP(newInt32SliceValue(value, p), name, "", usage) -} - -// Int32SliceVarP is like Int32SliceVar, but accepts a shorthand letter that can be used after a single dash. -func (f *FlagSet) Int32SliceVarP(p *[]int32, name, shorthand string, value []int32, usage string) { - f.VarP(newInt32SliceValue(value, p), name, shorthand, usage) -} - -// Int32SliceVar defines a int32[] flag with specified name, default value, and usage string. -// The argument p points to a int32[] variable in which to store the value of the flag. -func Int32SliceVar(p *[]int32, name string, value []int32, usage string) { - CommandLine.VarP(newInt32SliceValue(value, p), name, "", usage) -} - -// Int32SliceVarP is like Int32SliceVar, but accepts a shorthand letter that can be used after a single dash. -func Int32SliceVarP(p *[]int32, name, shorthand string, value []int32, usage string) { - CommandLine.VarP(newInt32SliceValue(value, p), name, shorthand, usage) -} - -// Int32Slice defines a []int32 flag with specified name, default value, and usage string. -// The return value is the address of a []int32 variable that stores the value of the flag. -func (f *FlagSet) Int32Slice(name string, value []int32, usage string) *[]int32 { - p := []int32{} - f.Int32SliceVarP(&p, name, "", value, usage) - return &p -} - -// Int32SliceP is like Int32Slice, but accepts a shorthand letter that can be used after a single dash. -func (f *FlagSet) Int32SliceP(name, shorthand string, value []int32, usage string) *[]int32 { - p := []int32{} - f.Int32SliceVarP(&p, name, shorthand, value, usage) - return &p -} - -// Int32Slice defines a []int32 flag with specified name, default value, and usage string. -// The return value is the address of a []int32 variable that stores the value of the flag. -func Int32Slice(name string, value []int32, usage string) *[]int32 { - return CommandLine.Int32SliceP(name, "", value, usage) -} - -// Int32SliceP is like Int32Slice, but accepts a shorthand letter that can be used after a single dash. -func Int32SliceP(name, shorthand string, value []int32, usage string) *[]int32 { - return CommandLine.Int32SliceP(name, shorthand, value, usage) -} diff --git a/vendor/github.com/spf13/pflag/int64.go b/vendor/github.com/spf13/pflag/int64.go deleted file mode 100644 index 0026d781d9..0000000000 --- a/vendor/github.com/spf13/pflag/int64.go +++ /dev/null @@ -1,84 +0,0 @@ -package pflag - -import "strconv" - -// -- int64 Value -type int64Value int64 - -func newInt64Value(val int64, p *int64) *int64Value { - *p = val - return (*int64Value)(p) -} - -func (i *int64Value) Set(s string) error { - v, err := strconv.ParseInt(s, 0, 64) - *i = int64Value(v) - return err -} - -func (i *int64Value) Type() string { - return "int64" -} - -func (i *int64Value) String() string { return strconv.FormatInt(int64(*i), 10) } - -func int64Conv(sval string) (interface{}, error) { - return strconv.ParseInt(sval, 0, 64) -} - -// GetInt64 return the int64 value of a flag with the given name -func (f *FlagSet) GetInt64(name string) (int64, error) { - val, err := f.getFlagType(name, "int64", int64Conv) - if err != nil { - return 0, err - } - return val.(int64), nil -} - -// Int64Var defines an int64 flag with specified name, default value, and usage string. -// The argument p points to an int64 variable in which to store the value of the flag. -func (f *FlagSet) Int64Var(p *int64, name string, value int64, usage string) { - f.VarP(newInt64Value(value, p), name, "", usage) -} - -// Int64VarP is like Int64Var, but accepts a shorthand letter that can be used after a single dash. -func (f *FlagSet) Int64VarP(p *int64, name, shorthand string, value int64, usage string) { - f.VarP(newInt64Value(value, p), name, shorthand, usage) -} - -// Int64Var defines an int64 flag with specified name, default value, and usage string. -// The argument p points to an int64 variable in which to store the value of the flag. -func Int64Var(p *int64, name string, value int64, usage string) { - CommandLine.VarP(newInt64Value(value, p), name, "", usage) -} - -// Int64VarP is like Int64Var, but accepts a shorthand letter that can be used after a single dash. -func Int64VarP(p *int64, name, shorthand string, value int64, usage string) { - CommandLine.VarP(newInt64Value(value, p), name, shorthand, usage) -} - -// Int64 defines an int64 flag with specified name, default value, and usage string. -// The return value is the address of an int64 variable that stores the value of the flag. -func (f *FlagSet) Int64(name string, value int64, usage string) *int64 { - p := new(int64) - f.Int64VarP(p, name, "", value, usage) - return p -} - -// Int64P is like Int64, but accepts a shorthand letter that can be used after a single dash. -func (f *FlagSet) Int64P(name, shorthand string, value int64, usage string) *int64 { - p := new(int64) - f.Int64VarP(p, name, shorthand, value, usage) - return p -} - -// Int64 defines an int64 flag with specified name, default value, and usage string. -// The return value is the address of an int64 variable that stores the value of the flag. -func Int64(name string, value int64, usage string) *int64 { - return CommandLine.Int64P(name, "", value, usage) -} - -// Int64P is like Int64, but accepts a shorthand letter that can be used after a single dash. -func Int64P(name, shorthand string, value int64, usage string) *int64 { - return CommandLine.Int64P(name, shorthand, value, usage) -} diff --git a/vendor/github.com/spf13/pflag/int64_slice.go b/vendor/github.com/spf13/pflag/int64_slice.go deleted file mode 100644 index 25464638f3..0000000000 --- a/vendor/github.com/spf13/pflag/int64_slice.go +++ /dev/null @@ -1,166 +0,0 @@ -package pflag - -import ( - "fmt" - "strconv" - "strings" -) - -// -- int64Slice Value -type int64SliceValue struct { - value *[]int64 - changed bool -} - -func newInt64SliceValue(val []int64, p *[]int64) *int64SliceValue { - isv := new(int64SliceValue) - isv.value = p - *isv.value = val - return isv -} - -func (s *int64SliceValue) Set(val string) error { - ss := strings.Split(val, ",") - out := make([]int64, len(ss)) - for i, d := range ss { - var err error - out[i], err = strconv.ParseInt(d, 0, 64) - if err != nil { - return err - } - - } - if !s.changed { - *s.value = out - } else { - *s.value = append(*s.value, out...) - } - s.changed = true - return nil -} - -func (s *int64SliceValue) Type() string { - return "int64Slice" -} - -func (s *int64SliceValue) String() string { - out := make([]string, len(*s.value)) - for i, d := range *s.value { - out[i] = fmt.Sprintf("%d", d) - } - return "[" + strings.Join(out, ",") + "]" -} - -func (s *int64SliceValue) fromString(val string) (int64, error) { - return strconv.ParseInt(val, 0, 64) -} - -func (s *int64SliceValue) toString(val int64) string { - return fmt.Sprintf("%d", val) -} - -func (s *int64SliceValue) Append(val string) error { - i, err := s.fromString(val) - if err != nil { - return err - } - *s.value = append(*s.value, i) - return nil -} - -func (s *int64SliceValue) Replace(val []string) error { - out := make([]int64, len(val)) - for i, d := range val { - var err error - out[i], err = s.fromString(d) - if err != nil { - return err - } - } - *s.value = out - return nil -} - -func (s *int64SliceValue) GetSlice() []string { - out := make([]string, len(*s.value)) - for i, d := range *s.value { - out[i] = s.toString(d) - } - return out -} - -func int64SliceConv(val string) (interface{}, error) { - val = strings.Trim(val, "[]") - // Empty string would cause a slice with one (empty) entry - if len(val) == 0 { - return []int64{}, nil - } - ss := strings.Split(val, ",") - out := make([]int64, len(ss)) - for i, d := range ss { - var err error - out[i], err = strconv.ParseInt(d, 0, 64) - if err != nil { - return nil, err - } - - } - return out, nil -} - -// GetInt64Slice return the []int64 value of a flag with the given name -func (f *FlagSet) GetInt64Slice(name string) ([]int64, error) { - val, err := f.getFlagType(name, "int64Slice", int64SliceConv) - if err != nil { - return []int64{}, err - } - return val.([]int64), nil -} - -// Int64SliceVar defines a int64Slice flag with specified name, default value, and usage string. -// The argument p points to a []int64 variable in which to store the value of the flag. -func (f *FlagSet) Int64SliceVar(p *[]int64, name string, value []int64, usage string) { - f.VarP(newInt64SliceValue(value, p), name, "", usage) -} - -// Int64SliceVarP is like Int64SliceVar, but accepts a shorthand letter that can be used after a single dash. -func (f *FlagSet) Int64SliceVarP(p *[]int64, name, shorthand string, value []int64, usage string) { - f.VarP(newInt64SliceValue(value, p), name, shorthand, usage) -} - -// Int64SliceVar defines a int64[] flag with specified name, default value, and usage string. -// The argument p points to a int64[] variable in which to store the value of the flag. -func Int64SliceVar(p *[]int64, name string, value []int64, usage string) { - CommandLine.VarP(newInt64SliceValue(value, p), name, "", usage) -} - -// Int64SliceVarP is like Int64SliceVar, but accepts a shorthand letter that can be used after a single dash. -func Int64SliceVarP(p *[]int64, name, shorthand string, value []int64, usage string) { - CommandLine.VarP(newInt64SliceValue(value, p), name, shorthand, usage) -} - -// Int64Slice defines a []int64 flag with specified name, default value, and usage string. -// The return value is the address of a []int64 variable that stores the value of the flag. -func (f *FlagSet) Int64Slice(name string, value []int64, usage string) *[]int64 { - p := []int64{} - f.Int64SliceVarP(&p, name, "", value, usage) - return &p -} - -// Int64SliceP is like Int64Slice, but accepts a shorthand letter that can be used after a single dash. -func (f *FlagSet) Int64SliceP(name, shorthand string, value []int64, usage string) *[]int64 { - p := []int64{} - f.Int64SliceVarP(&p, name, shorthand, value, usage) - return &p -} - -// Int64Slice defines a []int64 flag with specified name, default value, and usage string. -// The return value is the address of a []int64 variable that stores the value of the flag. -func Int64Slice(name string, value []int64, usage string) *[]int64 { - return CommandLine.Int64SliceP(name, "", value, usage) -} - -// Int64SliceP is like Int64Slice, but accepts a shorthand letter that can be used after a single dash. -func Int64SliceP(name, shorthand string, value []int64, usage string) *[]int64 { - return CommandLine.Int64SliceP(name, shorthand, value, usage) -} diff --git a/vendor/github.com/spf13/pflag/int8.go b/vendor/github.com/spf13/pflag/int8.go deleted file mode 100644 index 4da92228e6..0000000000 --- a/vendor/github.com/spf13/pflag/int8.go +++ /dev/null @@ -1,88 +0,0 @@ -package pflag - -import "strconv" - -// -- int8 Value -type int8Value int8 - -func newInt8Value(val int8, p *int8) *int8Value { - *p = val - return (*int8Value)(p) -} - -func (i *int8Value) Set(s string) error { - v, err := strconv.ParseInt(s, 0, 8) - *i = int8Value(v) - return err -} - -func (i *int8Value) Type() string { - return "int8" -} - -func (i *int8Value) String() string { return strconv.FormatInt(int64(*i), 10) } - -func int8Conv(sval string) (interface{}, error) { - v, err := strconv.ParseInt(sval, 0, 8) - if err != nil { - return 0, err - } - return int8(v), nil -} - -// GetInt8 return the int8 value of a flag with the given name -func (f *FlagSet) GetInt8(name string) (int8, error) { - val, err := f.getFlagType(name, "int8", int8Conv) - if err != nil { - return 0, err - } - return val.(int8), nil -} - -// Int8Var defines an int8 flag with specified name, default value, and usage string. -// The argument p points to an int8 variable in which to store the value of the flag. -func (f *FlagSet) Int8Var(p *int8, name string, value int8, usage string) { - f.VarP(newInt8Value(value, p), name, "", usage) -} - -// Int8VarP is like Int8Var, but accepts a shorthand letter that can be used after a single dash. -func (f *FlagSet) Int8VarP(p *int8, name, shorthand string, value int8, usage string) { - f.VarP(newInt8Value(value, p), name, shorthand, usage) -} - -// Int8Var defines an int8 flag with specified name, default value, and usage string. -// The argument p points to an int8 variable in which to store the value of the flag. -func Int8Var(p *int8, name string, value int8, usage string) { - CommandLine.VarP(newInt8Value(value, p), name, "", usage) -} - -// Int8VarP is like Int8Var, but accepts a shorthand letter that can be used after a single dash. -func Int8VarP(p *int8, name, shorthand string, value int8, usage string) { - CommandLine.VarP(newInt8Value(value, p), name, shorthand, usage) -} - -// Int8 defines an int8 flag with specified name, default value, and usage string. -// The return value is the address of an int8 variable that stores the value of the flag. -func (f *FlagSet) Int8(name string, value int8, usage string) *int8 { - p := new(int8) - f.Int8VarP(p, name, "", value, usage) - return p -} - -// Int8P is like Int8, but accepts a shorthand letter that can be used after a single dash. -func (f *FlagSet) Int8P(name, shorthand string, value int8, usage string) *int8 { - p := new(int8) - f.Int8VarP(p, name, shorthand, value, usage) - return p -} - -// Int8 defines an int8 flag with specified name, default value, and usage string. -// The return value is the address of an int8 variable that stores the value of the flag. -func Int8(name string, value int8, usage string) *int8 { - return CommandLine.Int8P(name, "", value, usage) -} - -// Int8P is like Int8, but accepts a shorthand letter that can be used after a single dash. -func Int8P(name, shorthand string, value int8, usage string) *int8 { - return CommandLine.Int8P(name, shorthand, value, usage) -} diff --git a/vendor/github.com/spf13/pflag/int_slice.go b/vendor/github.com/spf13/pflag/int_slice.go deleted file mode 100644 index e71c39d91a..0000000000 --- a/vendor/github.com/spf13/pflag/int_slice.go +++ /dev/null @@ -1,158 +0,0 @@ -package pflag - -import ( - "fmt" - "strconv" - "strings" -) - -// -- intSlice Value -type intSliceValue struct { - value *[]int - changed bool -} - -func newIntSliceValue(val []int, p *[]int) *intSliceValue { - isv := new(intSliceValue) - isv.value = p - *isv.value = val - return isv -} - -func (s *intSliceValue) Set(val string) error { - ss := strings.Split(val, ",") - out := make([]int, len(ss)) - for i, d := range ss { - var err error - out[i], err = strconv.Atoi(d) - if err != nil { - return err - } - - } - if !s.changed { - *s.value = out - } else { - *s.value = append(*s.value, out...) - } - s.changed = true - return nil -} - -func (s *intSliceValue) Type() string { - return "intSlice" -} - -func (s *intSliceValue) String() string { - out := make([]string, len(*s.value)) - for i, d := range *s.value { - out[i] = fmt.Sprintf("%d", d) - } - return "[" + strings.Join(out, ",") + "]" -} - -func (s *intSliceValue) Append(val string) error { - i, err := strconv.Atoi(val) - if err != nil { - return err - } - *s.value = append(*s.value, i) - return nil -} - -func (s *intSliceValue) Replace(val []string) error { - out := make([]int, len(val)) - for i, d := range val { - var err error - out[i], err = strconv.Atoi(d) - if err != nil { - return err - } - } - *s.value = out - return nil -} - -func (s *intSliceValue) GetSlice() []string { - out := make([]string, len(*s.value)) - for i, d := range *s.value { - out[i] = strconv.Itoa(d) - } - return out -} - -func intSliceConv(val string) (interface{}, error) { - val = strings.Trim(val, "[]") - // Empty string would cause a slice with one (empty) entry - if len(val) == 0 { - return []int{}, nil - } - ss := strings.Split(val, ",") - out := make([]int, len(ss)) - for i, d := range ss { - var err error - out[i], err = strconv.Atoi(d) - if err != nil { - return nil, err - } - - } - return out, nil -} - -// GetIntSlice return the []int value of a flag with the given name -func (f *FlagSet) GetIntSlice(name string) ([]int, error) { - val, err := f.getFlagType(name, "intSlice", intSliceConv) - if err != nil { - return []int{}, err - } - return val.([]int), nil -} - -// IntSliceVar defines a intSlice flag with specified name, default value, and usage string. -// The argument p points to a []int variable in which to store the value of the flag. -func (f *FlagSet) IntSliceVar(p *[]int, name string, value []int, usage string) { - f.VarP(newIntSliceValue(value, p), name, "", usage) -} - -// IntSliceVarP is like IntSliceVar, but accepts a shorthand letter that can be used after a single dash. -func (f *FlagSet) IntSliceVarP(p *[]int, name, shorthand string, value []int, usage string) { - f.VarP(newIntSliceValue(value, p), name, shorthand, usage) -} - -// IntSliceVar defines a int[] flag with specified name, default value, and usage string. -// The argument p points to a int[] variable in which to store the value of the flag. -func IntSliceVar(p *[]int, name string, value []int, usage string) { - CommandLine.VarP(newIntSliceValue(value, p), name, "", usage) -} - -// IntSliceVarP is like IntSliceVar, but accepts a shorthand letter that can be used after a single dash. -func IntSliceVarP(p *[]int, name, shorthand string, value []int, usage string) { - CommandLine.VarP(newIntSliceValue(value, p), name, shorthand, usage) -} - -// IntSlice defines a []int flag with specified name, default value, and usage string. -// The return value is the address of a []int variable that stores the value of the flag. -func (f *FlagSet) IntSlice(name string, value []int, usage string) *[]int { - p := []int{} - f.IntSliceVarP(&p, name, "", value, usage) - return &p -} - -// IntSliceP is like IntSlice, but accepts a shorthand letter that can be used after a single dash. -func (f *FlagSet) IntSliceP(name, shorthand string, value []int, usage string) *[]int { - p := []int{} - f.IntSliceVarP(&p, name, shorthand, value, usage) - return &p -} - -// IntSlice defines a []int flag with specified name, default value, and usage string. -// The return value is the address of a []int variable that stores the value of the flag. -func IntSlice(name string, value []int, usage string) *[]int { - return CommandLine.IntSliceP(name, "", value, usage) -} - -// IntSliceP is like IntSlice, but accepts a shorthand letter that can be used after a single dash. -func IntSliceP(name, shorthand string, value []int, usage string) *[]int { - return CommandLine.IntSliceP(name, shorthand, value, usage) -} diff --git a/vendor/github.com/spf13/pflag/ip.go b/vendor/github.com/spf13/pflag/ip.go deleted file mode 100644 index 3d414ba69f..0000000000 --- a/vendor/github.com/spf13/pflag/ip.go +++ /dev/null @@ -1,94 +0,0 @@ -package pflag - -import ( - "fmt" - "net" - "strings" -) - -// -- net.IP value -type ipValue net.IP - -func newIPValue(val net.IP, p *net.IP) *ipValue { - *p = val - return (*ipValue)(p) -} - -func (i *ipValue) String() string { return net.IP(*i).String() } -func (i *ipValue) Set(s string) error { - ip := net.ParseIP(strings.TrimSpace(s)) - if ip == nil { - return fmt.Errorf("failed to parse IP: %q", s) - } - *i = ipValue(ip) - return nil -} - -func (i *ipValue) Type() string { - return "ip" -} - -func ipConv(sval string) (interface{}, error) { - ip := net.ParseIP(sval) - if ip != nil { - return ip, nil - } - return nil, fmt.Errorf("invalid string being converted to IP address: %s", sval) -} - -// GetIP return the net.IP value of a flag with the given name -func (f *FlagSet) GetIP(name string) (net.IP, error) { - val, err := f.getFlagType(name, "ip", ipConv) - if err != nil { - return nil, err - } - return val.(net.IP), nil -} - -// IPVar defines an net.IP flag with specified name, default value, and usage string. -// The argument p points to an net.IP variable in which to store the value of the flag. -func (f *FlagSet) IPVar(p *net.IP, name string, value net.IP, usage string) { - f.VarP(newIPValue(value, p), name, "", usage) -} - -// IPVarP is like IPVar, but accepts a shorthand letter that can be used after a single dash. -func (f *FlagSet) IPVarP(p *net.IP, name, shorthand string, value net.IP, usage string) { - f.VarP(newIPValue(value, p), name, shorthand, usage) -} - -// IPVar defines an net.IP flag with specified name, default value, and usage string. -// The argument p points to an net.IP variable in which to store the value of the flag. -func IPVar(p *net.IP, name string, value net.IP, usage string) { - CommandLine.VarP(newIPValue(value, p), name, "", usage) -} - -// IPVarP is like IPVar, but accepts a shorthand letter that can be used after a single dash. -func IPVarP(p *net.IP, name, shorthand string, value net.IP, usage string) { - CommandLine.VarP(newIPValue(value, p), name, shorthand, usage) -} - -// IP defines an net.IP flag with specified name, default value, and usage string. -// The return value is the address of an net.IP variable that stores the value of the flag. -func (f *FlagSet) IP(name string, value net.IP, usage string) *net.IP { - p := new(net.IP) - f.IPVarP(p, name, "", value, usage) - return p -} - -// IPP is like IP, but accepts a shorthand letter that can be used after a single dash. -func (f *FlagSet) IPP(name, shorthand string, value net.IP, usage string) *net.IP { - p := new(net.IP) - f.IPVarP(p, name, shorthand, value, usage) - return p -} - -// IP defines an net.IP flag with specified name, default value, and usage string. -// The return value is the address of an net.IP variable that stores the value of the flag. -func IP(name string, value net.IP, usage string) *net.IP { - return CommandLine.IPP(name, "", value, usage) -} - -// IPP is like IP, but accepts a shorthand letter that can be used after a single dash. -func IPP(name, shorthand string, value net.IP, usage string) *net.IP { - return CommandLine.IPP(name, shorthand, value, usage) -} diff --git a/vendor/github.com/spf13/pflag/ip_slice.go b/vendor/github.com/spf13/pflag/ip_slice.go deleted file mode 100644 index 775faae4fd..0000000000 --- a/vendor/github.com/spf13/pflag/ip_slice.go +++ /dev/null @@ -1,186 +0,0 @@ -package pflag - -import ( - "fmt" - "io" - "net" - "strings" -) - -// -- ipSlice Value -type ipSliceValue struct { - value *[]net.IP - changed bool -} - -func newIPSliceValue(val []net.IP, p *[]net.IP) *ipSliceValue { - ipsv := new(ipSliceValue) - ipsv.value = p - *ipsv.value = val - return ipsv -} - -// Set converts, and assigns, the comma-separated IP argument string representation as the []net.IP value of this flag. -// If Set is called on a flag that already has a []net.IP assigned, the newly converted values will be appended. -func (s *ipSliceValue) Set(val string) error { - - // remove all quote characters - rmQuote := strings.NewReplacer(`"`, "", `'`, "", "`", "") - - // read flag arguments with CSV parser - ipStrSlice, err := readAsCSV(rmQuote.Replace(val)) - if err != nil && err != io.EOF { - return err - } - - // parse ip values into slice - out := make([]net.IP, 0, len(ipStrSlice)) - for _, ipStr := range ipStrSlice { - ip := net.ParseIP(strings.TrimSpace(ipStr)) - if ip == nil { - return fmt.Errorf("invalid string being converted to IP address: %s", ipStr) - } - out = append(out, ip) - } - - if !s.changed { - *s.value = out - } else { - *s.value = append(*s.value, out...) - } - - s.changed = true - - return nil -} - -// Type returns a string that uniquely represents this flag's type. -func (s *ipSliceValue) Type() string { - return "ipSlice" -} - -// String defines a "native" format for this net.IP slice flag value. -func (s *ipSliceValue) String() string { - - ipStrSlice := make([]string, len(*s.value)) - for i, ip := range *s.value { - ipStrSlice[i] = ip.String() - } - - out, _ := writeAsCSV(ipStrSlice) - - return "[" + out + "]" -} - -func (s *ipSliceValue) fromString(val string) (net.IP, error) { - return net.ParseIP(strings.TrimSpace(val)), nil -} - -func (s *ipSliceValue) toString(val net.IP) string { - return val.String() -} - -func (s *ipSliceValue) Append(val string) error { - i, err := s.fromString(val) - if err != nil { - return err - } - *s.value = append(*s.value, i) - return nil -} - -func (s *ipSliceValue) Replace(val []string) error { - out := make([]net.IP, len(val)) - for i, d := range val { - var err error - out[i], err = s.fromString(d) - if err != nil { - return err - } - } - *s.value = out - return nil -} - -func (s *ipSliceValue) GetSlice() []string { - out := make([]string, len(*s.value)) - for i, d := range *s.value { - out[i] = s.toString(d) - } - return out -} - -func ipSliceConv(val string) (interface{}, error) { - val = strings.Trim(val, "[]") - // Empty string would cause a slice with one (empty) entry - if len(val) == 0 { - return []net.IP{}, nil - } - ss := strings.Split(val, ",") - out := make([]net.IP, len(ss)) - for i, sval := range ss { - ip := net.ParseIP(strings.TrimSpace(sval)) - if ip == nil { - return nil, fmt.Errorf("invalid string being converted to IP address: %s", sval) - } - out[i] = ip - } - return out, nil -} - -// GetIPSlice returns the []net.IP value of a flag with the given name -func (f *FlagSet) GetIPSlice(name string) ([]net.IP, error) { - val, err := f.getFlagType(name, "ipSlice", ipSliceConv) - if err != nil { - return []net.IP{}, err - } - return val.([]net.IP), nil -} - -// IPSliceVar defines a ipSlice flag with specified name, default value, and usage string. -// The argument p points to a []net.IP variable in which to store the value of the flag. -func (f *FlagSet) IPSliceVar(p *[]net.IP, name string, value []net.IP, usage string) { - f.VarP(newIPSliceValue(value, p), name, "", usage) -} - -// IPSliceVarP is like IPSliceVar, but accepts a shorthand letter that can be used after a single dash. -func (f *FlagSet) IPSliceVarP(p *[]net.IP, name, shorthand string, value []net.IP, usage string) { - f.VarP(newIPSliceValue(value, p), name, shorthand, usage) -} - -// IPSliceVar defines a []net.IP flag with specified name, default value, and usage string. -// The argument p points to a []net.IP variable in which to store the value of the flag. -func IPSliceVar(p *[]net.IP, name string, value []net.IP, usage string) { - CommandLine.VarP(newIPSliceValue(value, p), name, "", usage) -} - -// IPSliceVarP is like IPSliceVar, but accepts a shorthand letter that can be used after a single dash. -func IPSliceVarP(p *[]net.IP, name, shorthand string, value []net.IP, usage string) { - CommandLine.VarP(newIPSliceValue(value, p), name, shorthand, usage) -} - -// IPSlice defines a []net.IP flag with specified name, default value, and usage string. -// The return value is the address of a []net.IP variable that stores the value of that flag. -func (f *FlagSet) IPSlice(name string, value []net.IP, usage string) *[]net.IP { - p := []net.IP{} - f.IPSliceVarP(&p, name, "", value, usage) - return &p -} - -// IPSliceP is like IPSlice, but accepts a shorthand letter that can be used after a single dash. -func (f *FlagSet) IPSliceP(name, shorthand string, value []net.IP, usage string) *[]net.IP { - p := []net.IP{} - f.IPSliceVarP(&p, name, shorthand, value, usage) - return &p -} - -// IPSlice defines a []net.IP flag with specified name, default value, and usage string. -// The return value is the address of a []net.IP variable that stores the value of the flag. -func IPSlice(name string, value []net.IP, usage string) *[]net.IP { - return CommandLine.IPSliceP(name, "", value, usage) -} - -// IPSliceP is like IPSlice, but accepts a shorthand letter that can be used after a single dash. -func IPSliceP(name, shorthand string, value []net.IP, usage string) *[]net.IP { - return CommandLine.IPSliceP(name, shorthand, value, usage) -} diff --git a/vendor/github.com/spf13/pflag/ipmask.go b/vendor/github.com/spf13/pflag/ipmask.go deleted file mode 100644 index 5bd44bd21d..0000000000 --- a/vendor/github.com/spf13/pflag/ipmask.go +++ /dev/null @@ -1,122 +0,0 @@ -package pflag - -import ( - "fmt" - "net" - "strconv" -) - -// -- net.IPMask value -type ipMaskValue net.IPMask - -func newIPMaskValue(val net.IPMask, p *net.IPMask) *ipMaskValue { - *p = val - return (*ipMaskValue)(p) -} - -func (i *ipMaskValue) String() string { return net.IPMask(*i).String() } -func (i *ipMaskValue) Set(s string) error { - ip := ParseIPv4Mask(s) - if ip == nil { - return fmt.Errorf("failed to parse IP mask: %q", s) - } - *i = ipMaskValue(ip) - return nil -} - -func (i *ipMaskValue) Type() string { - return "ipMask" -} - -// ParseIPv4Mask written in IP form (e.g. 255.255.255.0). -// This function should really belong to the net package. -func ParseIPv4Mask(s string) net.IPMask { - mask := net.ParseIP(s) - if mask == nil { - if len(s) != 8 { - return nil - } - // net.IPMask.String() actually outputs things like ffffff00 - // so write a horrible parser for that as well :-( - m := []int{} - for i := 0; i < 4; i++ { - b := "0x" + s[2*i:2*i+2] - d, err := strconv.ParseInt(b, 0, 0) - if err != nil { - return nil - } - m = append(m, int(d)) - } - s := fmt.Sprintf("%d.%d.%d.%d", m[0], m[1], m[2], m[3]) - mask = net.ParseIP(s) - if mask == nil { - return nil - } - } - return net.IPv4Mask(mask[12], mask[13], mask[14], mask[15]) -} - -func parseIPv4Mask(sval string) (interface{}, error) { - mask := ParseIPv4Mask(sval) - if mask == nil { - return nil, fmt.Errorf("unable to parse %s as net.IPMask", sval) - } - return mask, nil -} - -// GetIPv4Mask return the net.IPv4Mask value of a flag with the given name -func (f *FlagSet) GetIPv4Mask(name string) (net.IPMask, error) { - val, err := f.getFlagType(name, "ipMask", parseIPv4Mask) - if err != nil { - return nil, err - } - return val.(net.IPMask), nil -} - -// IPMaskVar defines an net.IPMask flag with specified name, default value, and usage string. -// The argument p points to an net.IPMask variable in which to store the value of the flag. -func (f *FlagSet) IPMaskVar(p *net.IPMask, name string, value net.IPMask, usage string) { - f.VarP(newIPMaskValue(value, p), name, "", usage) -} - -// IPMaskVarP is like IPMaskVar, but accepts a shorthand letter that can be used after a single dash. -func (f *FlagSet) IPMaskVarP(p *net.IPMask, name, shorthand string, value net.IPMask, usage string) { - f.VarP(newIPMaskValue(value, p), name, shorthand, usage) -} - -// IPMaskVar defines an net.IPMask flag with specified name, default value, and usage string. -// The argument p points to an net.IPMask variable in which to store the value of the flag. -func IPMaskVar(p *net.IPMask, name string, value net.IPMask, usage string) { - CommandLine.VarP(newIPMaskValue(value, p), name, "", usage) -} - -// IPMaskVarP is like IPMaskVar, but accepts a shorthand letter that can be used after a single dash. -func IPMaskVarP(p *net.IPMask, name, shorthand string, value net.IPMask, usage string) { - CommandLine.VarP(newIPMaskValue(value, p), name, shorthand, usage) -} - -// IPMask defines an net.IPMask flag with specified name, default value, and usage string. -// The return value is the address of an net.IPMask variable that stores the value of the flag. -func (f *FlagSet) IPMask(name string, value net.IPMask, usage string) *net.IPMask { - p := new(net.IPMask) - f.IPMaskVarP(p, name, "", value, usage) - return p -} - -// IPMaskP is like IPMask, but accepts a shorthand letter that can be used after a single dash. -func (f *FlagSet) IPMaskP(name, shorthand string, value net.IPMask, usage string) *net.IPMask { - p := new(net.IPMask) - f.IPMaskVarP(p, name, shorthand, value, usage) - return p -} - -// IPMask defines an net.IPMask flag with specified name, default value, and usage string. -// The return value is the address of an net.IPMask variable that stores the value of the flag. -func IPMask(name string, value net.IPMask, usage string) *net.IPMask { - return CommandLine.IPMaskP(name, "", value, usage) -} - -// IPMaskP is like IP, but accepts a shorthand letter that can be used after a single dash. -func IPMaskP(name, shorthand string, value net.IPMask, usage string) *net.IPMask { - return CommandLine.IPMaskP(name, shorthand, value, usage) -} diff --git a/vendor/github.com/spf13/pflag/ipnet.go b/vendor/github.com/spf13/pflag/ipnet.go deleted file mode 100644 index e2c1b8bcd5..0000000000 --- a/vendor/github.com/spf13/pflag/ipnet.go +++ /dev/null @@ -1,98 +0,0 @@ -package pflag - -import ( - "fmt" - "net" - "strings" -) - -// IPNet adapts net.IPNet for use as a flag. -type ipNetValue net.IPNet - -func (ipnet ipNetValue) String() string { - n := net.IPNet(ipnet) - return n.String() -} - -func (ipnet *ipNetValue) Set(value string) error { - _, n, err := net.ParseCIDR(strings.TrimSpace(value)) - if err != nil { - return err - } - *ipnet = ipNetValue(*n) - return nil -} - -func (*ipNetValue) Type() string { - return "ipNet" -} - -func newIPNetValue(val net.IPNet, p *net.IPNet) *ipNetValue { - *p = val - return (*ipNetValue)(p) -} - -func ipNetConv(sval string) (interface{}, error) { - _, n, err := net.ParseCIDR(strings.TrimSpace(sval)) - if err == nil { - return *n, nil - } - return nil, fmt.Errorf("invalid string being converted to IPNet: %s", sval) -} - -// GetIPNet return the net.IPNet value of a flag with the given name -func (f *FlagSet) GetIPNet(name string) (net.IPNet, error) { - val, err := f.getFlagType(name, "ipNet", ipNetConv) - if err != nil { - return net.IPNet{}, err - } - return val.(net.IPNet), nil -} - -// IPNetVar defines an net.IPNet flag with specified name, default value, and usage string. -// The argument p points to an net.IPNet variable in which to store the value of the flag. -func (f *FlagSet) IPNetVar(p *net.IPNet, name string, value net.IPNet, usage string) { - f.VarP(newIPNetValue(value, p), name, "", usage) -} - -// IPNetVarP is like IPNetVar, but accepts a shorthand letter that can be used after a single dash. -func (f *FlagSet) IPNetVarP(p *net.IPNet, name, shorthand string, value net.IPNet, usage string) { - f.VarP(newIPNetValue(value, p), name, shorthand, usage) -} - -// IPNetVar defines an net.IPNet flag with specified name, default value, and usage string. -// The argument p points to an net.IPNet variable in which to store the value of the flag. -func IPNetVar(p *net.IPNet, name string, value net.IPNet, usage string) { - CommandLine.VarP(newIPNetValue(value, p), name, "", usage) -} - -// IPNetVarP is like IPNetVar, but accepts a shorthand letter that can be used after a single dash. -func IPNetVarP(p *net.IPNet, name, shorthand string, value net.IPNet, usage string) { - CommandLine.VarP(newIPNetValue(value, p), name, shorthand, usage) -} - -// IPNet defines an net.IPNet flag with specified name, default value, and usage string. -// The return value is the address of an net.IPNet variable that stores the value of the flag. -func (f *FlagSet) IPNet(name string, value net.IPNet, usage string) *net.IPNet { - p := new(net.IPNet) - f.IPNetVarP(p, name, "", value, usage) - return p -} - -// IPNetP is like IPNet, but accepts a shorthand letter that can be used after a single dash. -func (f *FlagSet) IPNetP(name, shorthand string, value net.IPNet, usage string) *net.IPNet { - p := new(net.IPNet) - f.IPNetVarP(p, name, shorthand, value, usage) - return p -} - -// IPNet defines an net.IPNet flag with specified name, default value, and usage string. -// The return value is the address of an net.IPNet variable that stores the value of the flag. -func IPNet(name string, value net.IPNet, usage string) *net.IPNet { - return CommandLine.IPNetP(name, "", value, usage) -} - -// IPNetP is like IPNet, but accepts a shorthand letter that can be used after a single dash. -func IPNetP(name, shorthand string, value net.IPNet, usage string) *net.IPNet { - return CommandLine.IPNetP(name, shorthand, value, usage) -} diff --git a/vendor/github.com/spf13/pflag/string.go b/vendor/github.com/spf13/pflag/string.go deleted file mode 100644 index 04e0a26ff7..0000000000 --- a/vendor/github.com/spf13/pflag/string.go +++ /dev/null @@ -1,80 +0,0 @@ -package pflag - -// -- string Value -type stringValue string - -func newStringValue(val string, p *string) *stringValue { - *p = val - return (*stringValue)(p) -} - -func (s *stringValue) Set(val string) error { - *s = stringValue(val) - return nil -} -func (s *stringValue) Type() string { - return "string" -} - -func (s *stringValue) String() string { return string(*s) } - -func stringConv(sval string) (interface{}, error) { - return sval, nil -} - -// GetString return the string value of a flag with the given name -func (f *FlagSet) GetString(name string) (string, error) { - val, err := f.getFlagType(name, "string", stringConv) - if err != nil { - return "", err - } - return val.(string), nil -} - -// StringVar defines a string flag with specified name, default value, and usage string. -// The argument p points to a string variable in which to store the value of the flag. -func (f *FlagSet) StringVar(p *string, name string, value string, usage string) { - f.VarP(newStringValue(value, p), name, "", usage) -} - -// StringVarP is like StringVar, but accepts a shorthand letter that can be used after a single dash. -func (f *FlagSet) StringVarP(p *string, name, shorthand string, value string, usage string) { - f.VarP(newStringValue(value, p), name, shorthand, usage) -} - -// StringVar defines a string flag with specified name, default value, and usage string. -// The argument p points to a string variable in which to store the value of the flag. -func StringVar(p *string, name string, value string, usage string) { - CommandLine.VarP(newStringValue(value, p), name, "", usage) -} - -// StringVarP is like StringVar, but accepts a shorthand letter that can be used after a single dash. -func StringVarP(p *string, name, shorthand string, value string, usage string) { - CommandLine.VarP(newStringValue(value, p), name, shorthand, usage) -} - -// String defines a string flag with specified name, default value, and usage string. -// The return value is the address of a string variable that stores the value of the flag. -func (f *FlagSet) String(name string, value string, usage string) *string { - p := new(string) - f.StringVarP(p, name, "", value, usage) - return p -} - -// StringP is like String, but accepts a shorthand letter that can be used after a single dash. -func (f *FlagSet) StringP(name, shorthand string, value string, usage string) *string { - p := new(string) - f.StringVarP(p, name, shorthand, value, usage) - return p -} - -// String defines a string flag with specified name, default value, and usage string. -// The return value is the address of a string variable that stores the value of the flag. -func String(name string, value string, usage string) *string { - return CommandLine.StringP(name, "", value, usage) -} - -// StringP is like String, but accepts a shorthand letter that can be used after a single dash. -func StringP(name, shorthand string, value string, usage string) *string { - return CommandLine.StringP(name, shorthand, value, usage) -} diff --git a/vendor/github.com/spf13/pflag/string_array.go b/vendor/github.com/spf13/pflag/string_array.go deleted file mode 100644 index 4894af8180..0000000000 --- a/vendor/github.com/spf13/pflag/string_array.go +++ /dev/null @@ -1,129 +0,0 @@ -package pflag - -// -- stringArray Value -type stringArrayValue struct { - value *[]string - changed bool -} - -func newStringArrayValue(val []string, p *[]string) *stringArrayValue { - ssv := new(stringArrayValue) - ssv.value = p - *ssv.value = val - return ssv -} - -func (s *stringArrayValue) Set(val string) error { - if !s.changed { - *s.value = []string{val} - s.changed = true - } else { - *s.value = append(*s.value, val) - } - return nil -} - -func (s *stringArrayValue) Append(val string) error { - *s.value = append(*s.value, val) - return nil -} - -func (s *stringArrayValue) Replace(val []string) error { - out := make([]string, len(val)) - for i, d := range val { - var err error - out[i] = d - if err != nil { - return err - } - } - *s.value = out - return nil -} - -func (s *stringArrayValue) GetSlice() []string { - out := make([]string, len(*s.value)) - for i, d := range *s.value { - out[i] = d - } - return out -} - -func (s *stringArrayValue) Type() string { - return "stringArray" -} - -func (s *stringArrayValue) String() string { - str, _ := writeAsCSV(*s.value) - return "[" + str + "]" -} - -func stringArrayConv(sval string) (interface{}, error) { - sval = sval[1 : len(sval)-1] - // An empty string would cause a array with one (empty) string - if len(sval) == 0 { - return []string{}, nil - } - return readAsCSV(sval) -} - -// GetStringArray return the []string value of a flag with the given name -func (f *FlagSet) GetStringArray(name string) ([]string, error) { - val, err := f.getFlagType(name, "stringArray", stringArrayConv) - if err != nil { - return []string{}, err - } - return val.([]string), nil -} - -// StringArrayVar defines a string flag with specified name, default value, and usage string. -// The argument p points to a []string variable in which to store the values of the multiple flags. -// The value of each argument will not try to be separated by comma. Use a StringSlice for that. -func (f *FlagSet) StringArrayVar(p *[]string, name string, value []string, usage string) { - f.VarP(newStringArrayValue(value, p), name, "", usage) -} - -// StringArrayVarP is like StringArrayVar, but accepts a shorthand letter that can be used after a single dash. -func (f *FlagSet) StringArrayVarP(p *[]string, name, shorthand string, value []string, usage string) { - f.VarP(newStringArrayValue(value, p), name, shorthand, usage) -} - -// StringArrayVar defines a string flag with specified name, default value, and usage string. -// The argument p points to a []string variable in which to store the value of the flag. -// The value of each argument will not try to be separated by comma. Use a StringSlice for that. -func StringArrayVar(p *[]string, name string, value []string, usage string) { - CommandLine.VarP(newStringArrayValue(value, p), name, "", usage) -} - -// StringArrayVarP is like StringArrayVar, but accepts a shorthand letter that can be used after a single dash. -func StringArrayVarP(p *[]string, name, shorthand string, value []string, usage string) { - CommandLine.VarP(newStringArrayValue(value, p), name, shorthand, usage) -} - -// StringArray defines a string flag with specified name, default value, and usage string. -// The return value is the address of a []string variable that stores the value of the flag. -// The value of each argument will not try to be separated by comma. Use a StringSlice for that. -func (f *FlagSet) StringArray(name string, value []string, usage string) *[]string { - p := []string{} - f.StringArrayVarP(&p, name, "", value, usage) - return &p -} - -// StringArrayP is like StringArray, but accepts a shorthand letter that can be used after a single dash. -func (f *FlagSet) StringArrayP(name, shorthand string, value []string, usage string) *[]string { - p := []string{} - f.StringArrayVarP(&p, name, shorthand, value, usage) - return &p -} - -// StringArray defines a string flag with specified name, default value, and usage string. -// The return value is the address of a []string variable that stores the value of the flag. -// The value of each argument will not try to be separated by comma. Use a StringSlice for that. -func StringArray(name string, value []string, usage string) *[]string { - return CommandLine.StringArrayP(name, "", value, usage) -} - -// StringArrayP is like StringArray, but accepts a shorthand letter that can be used after a single dash. -func StringArrayP(name, shorthand string, value []string, usage string) *[]string { - return CommandLine.StringArrayP(name, shorthand, value, usage) -} diff --git a/vendor/github.com/spf13/pflag/string_slice.go b/vendor/github.com/spf13/pflag/string_slice.go deleted file mode 100644 index 3cb2e69dba..0000000000 --- a/vendor/github.com/spf13/pflag/string_slice.go +++ /dev/null @@ -1,163 +0,0 @@ -package pflag - -import ( - "bytes" - "encoding/csv" - "strings" -) - -// -- stringSlice Value -type stringSliceValue struct { - value *[]string - changed bool -} - -func newStringSliceValue(val []string, p *[]string) *stringSliceValue { - ssv := new(stringSliceValue) - ssv.value = p - *ssv.value = val - return ssv -} - -func readAsCSV(val string) ([]string, error) { - if val == "" { - return []string{}, nil - } - stringReader := strings.NewReader(val) - csvReader := csv.NewReader(stringReader) - return csvReader.Read() -} - -func writeAsCSV(vals []string) (string, error) { - b := &bytes.Buffer{} - w := csv.NewWriter(b) - err := w.Write(vals) - if err != nil { - return "", err - } - w.Flush() - return strings.TrimSuffix(b.String(), "\n"), nil -} - -func (s *stringSliceValue) Set(val string) error { - v, err := readAsCSV(val) - if err != nil { - return err - } - if !s.changed { - *s.value = v - } else { - *s.value = append(*s.value, v...) - } - s.changed = true - return nil -} - -func (s *stringSliceValue) Type() string { - return "stringSlice" -} - -func (s *stringSliceValue) String() string { - str, _ := writeAsCSV(*s.value) - return "[" + str + "]" -} - -func (s *stringSliceValue) Append(val string) error { - *s.value = append(*s.value, val) - return nil -} - -func (s *stringSliceValue) Replace(val []string) error { - *s.value = val - return nil -} - -func (s *stringSliceValue) GetSlice() []string { - return *s.value -} - -func stringSliceConv(sval string) (interface{}, error) { - sval = sval[1 : len(sval)-1] - // An empty string would cause a slice with one (empty) string - if len(sval) == 0 { - return []string{}, nil - } - return readAsCSV(sval) -} - -// GetStringSlice return the []string value of a flag with the given name -func (f *FlagSet) GetStringSlice(name string) ([]string, error) { - val, err := f.getFlagType(name, "stringSlice", stringSliceConv) - if err != nil { - return []string{}, err - } - return val.([]string), nil -} - -// StringSliceVar defines a string flag with specified name, default value, and usage string. -// The argument p points to a []string variable in which to store the value of the flag. -// Compared to StringArray flags, StringSlice flags take comma-separated value as arguments and split them accordingly. -// For example: -// --ss="v1,v2" --ss="v3" -// will result in -// []string{"v1", "v2", "v3"} -func (f *FlagSet) StringSliceVar(p *[]string, name string, value []string, usage string) { - f.VarP(newStringSliceValue(value, p), name, "", usage) -} - -// StringSliceVarP is like StringSliceVar, but accepts a shorthand letter that can be used after a single dash. -func (f *FlagSet) StringSliceVarP(p *[]string, name, shorthand string, value []string, usage string) { - f.VarP(newStringSliceValue(value, p), name, shorthand, usage) -} - -// StringSliceVar defines a string flag with specified name, default value, and usage string. -// The argument p points to a []string variable in which to store the value of the flag. -// Compared to StringArray flags, StringSlice flags take comma-separated value as arguments and split them accordingly. -// For example: -// --ss="v1,v2" --ss="v3" -// will result in -// []string{"v1", "v2", "v3"} -func StringSliceVar(p *[]string, name string, value []string, usage string) { - CommandLine.VarP(newStringSliceValue(value, p), name, "", usage) -} - -// StringSliceVarP is like StringSliceVar, but accepts a shorthand letter that can be used after a single dash. -func StringSliceVarP(p *[]string, name, shorthand string, value []string, usage string) { - CommandLine.VarP(newStringSliceValue(value, p), name, shorthand, usage) -} - -// StringSlice defines a string flag with specified name, default value, and usage string. -// The return value is the address of a []string variable that stores the value of the flag. -// Compared to StringArray flags, StringSlice flags take comma-separated value as arguments and split them accordingly. -// For example: -// --ss="v1,v2" --ss="v3" -// will result in -// []string{"v1", "v2", "v3"} -func (f *FlagSet) StringSlice(name string, value []string, usage string) *[]string { - p := []string{} - f.StringSliceVarP(&p, name, "", value, usage) - return &p -} - -// StringSliceP is like StringSlice, but accepts a shorthand letter that can be used after a single dash. -func (f *FlagSet) StringSliceP(name, shorthand string, value []string, usage string) *[]string { - p := []string{} - f.StringSliceVarP(&p, name, shorthand, value, usage) - return &p -} - -// StringSlice defines a string flag with specified name, default value, and usage string. -// The return value is the address of a []string variable that stores the value of the flag. -// Compared to StringArray flags, StringSlice flags take comma-separated value as arguments and split them accordingly. -// For example: -// --ss="v1,v2" --ss="v3" -// will result in -// []string{"v1", "v2", "v3"} -func StringSlice(name string, value []string, usage string) *[]string { - return CommandLine.StringSliceP(name, "", value, usage) -} - -// StringSliceP is like StringSlice, but accepts a shorthand letter that can be used after a single dash. -func StringSliceP(name, shorthand string, value []string, usage string) *[]string { - return CommandLine.StringSliceP(name, shorthand, value, usage) -} diff --git a/vendor/github.com/spf13/pflag/string_to_int.go b/vendor/github.com/spf13/pflag/string_to_int.go deleted file mode 100644 index 5ceda3965d..0000000000 --- a/vendor/github.com/spf13/pflag/string_to_int.go +++ /dev/null @@ -1,149 +0,0 @@ -package pflag - -import ( - "bytes" - "fmt" - "strconv" - "strings" -) - -// -- stringToInt Value -type stringToIntValue struct { - value *map[string]int - changed bool -} - -func newStringToIntValue(val map[string]int, p *map[string]int) *stringToIntValue { - ssv := new(stringToIntValue) - ssv.value = p - *ssv.value = val - return ssv -} - -// Format: a=1,b=2 -func (s *stringToIntValue) Set(val string) error { - ss := strings.Split(val, ",") - out := make(map[string]int, len(ss)) - for _, pair := range ss { - kv := strings.SplitN(pair, "=", 2) - if len(kv) != 2 { - return fmt.Errorf("%s must be formatted as key=value", pair) - } - var err error - out[kv[0]], err = strconv.Atoi(kv[1]) - if err != nil { - return err - } - } - if !s.changed { - *s.value = out - } else { - for k, v := range out { - (*s.value)[k] = v - } - } - s.changed = true - return nil -} - -func (s *stringToIntValue) Type() string { - return "stringToInt" -} - -func (s *stringToIntValue) String() string { - var buf bytes.Buffer - i := 0 - for k, v := range *s.value { - if i > 0 { - buf.WriteRune(',') - } - buf.WriteString(k) - buf.WriteRune('=') - buf.WriteString(strconv.Itoa(v)) - i++ - } - return "[" + buf.String() + "]" -} - -func stringToIntConv(val string) (interface{}, error) { - val = strings.Trim(val, "[]") - // An empty string would cause an empty map - if len(val) == 0 { - return map[string]int{}, nil - } - ss := strings.Split(val, ",") - out := make(map[string]int, len(ss)) - for _, pair := range ss { - kv := strings.SplitN(pair, "=", 2) - if len(kv) != 2 { - return nil, fmt.Errorf("%s must be formatted as key=value", pair) - } - var err error - out[kv[0]], err = strconv.Atoi(kv[1]) - if err != nil { - return nil, err - } - } - return out, nil -} - -// GetStringToInt return the map[string]int value of a flag with the given name -func (f *FlagSet) GetStringToInt(name string) (map[string]int, error) { - val, err := f.getFlagType(name, "stringToInt", stringToIntConv) - if err != nil { - return map[string]int{}, err - } - return val.(map[string]int), nil -} - -// StringToIntVar defines a string flag with specified name, default value, and usage string. -// The argument p points to a map[string]int variable in which to store the values of the multiple flags. -// The value of each argument will not try to be separated by comma -func (f *FlagSet) StringToIntVar(p *map[string]int, name string, value map[string]int, usage string) { - f.VarP(newStringToIntValue(value, p), name, "", usage) -} - -// StringToIntVarP is like StringToIntVar, but accepts a shorthand letter that can be used after a single dash. -func (f *FlagSet) StringToIntVarP(p *map[string]int, name, shorthand string, value map[string]int, usage string) { - f.VarP(newStringToIntValue(value, p), name, shorthand, usage) -} - -// StringToIntVar defines a string flag with specified name, default value, and usage string. -// The argument p points to a map[string]int variable in which to store the value of the flag. -// The value of each argument will not try to be separated by comma -func StringToIntVar(p *map[string]int, name string, value map[string]int, usage string) { - CommandLine.VarP(newStringToIntValue(value, p), name, "", usage) -} - -// StringToIntVarP is like StringToIntVar, but accepts a shorthand letter that can be used after a single dash. -func StringToIntVarP(p *map[string]int, name, shorthand string, value map[string]int, usage string) { - CommandLine.VarP(newStringToIntValue(value, p), name, shorthand, usage) -} - -// StringToInt defines a string flag with specified name, default value, and usage string. -// The return value is the address of a map[string]int variable that stores the value of the flag. -// The value of each argument will not try to be separated by comma -func (f *FlagSet) StringToInt(name string, value map[string]int, usage string) *map[string]int { - p := map[string]int{} - f.StringToIntVarP(&p, name, "", value, usage) - return &p -} - -// StringToIntP is like StringToInt, but accepts a shorthand letter that can be used after a single dash. -func (f *FlagSet) StringToIntP(name, shorthand string, value map[string]int, usage string) *map[string]int { - p := map[string]int{} - f.StringToIntVarP(&p, name, shorthand, value, usage) - return &p -} - -// StringToInt defines a string flag with specified name, default value, and usage string. -// The return value is the address of a map[string]int variable that stores the value of the flag. -// The value of each argument will not try to be separated by comma -func StringToInt(name string, value map[string]int, usage string) *map[string]int { - return CommandLine.StringToIntP(name, "", value, usage) -} - -// StringToIntP is like StringToInt, but accepts a shorthand letter that can be used after a single dash. -func StringToIntP(name, shorthand string, value map[string]int, usage string) *map[string]int { - return CommandLine.StringToIntP(name, shorthand, value, usage) -} diff --git a/vendor/github.com/spf13/pflag/string_to_int64.go b/vendor/github.com/spf13/pflag/string_to_int64.go deleted file mode 100644 index a807a04a0b..0000000000 --- a/vendor/github.com/spf13/pflag/string_to_int64.go +++ /dev/null @@ -1,149 +0,0 @@ -package pflag - -import ( - "bytes" - "fmt" - "strconv" - "strings" -) - -// -- stringToInt64 Value -type stringToInt64Value struct { - value *map[string]int64 - changed bool -} - -func newStringToInt64Value(val map[string]int64, p *map[string]int64) *stringToInt64Value { - ssv := new(stringToInt64Value) - ssv.value = p - *ssv.value = val - return ssv -} - -// Format: a=1,b=2 -func (s *stringToInt64Value) Set(val string) error { - ss := strings.Split(val, ",") - out := make(map[string]int64, len(ss)) - for _, pair := range ss { - kv := strings.SplitN(pair, "=", 2) - if len(kv) != 2 { - return fmt.Errorf("%s must be formatted as key=value", pair) - } - var err error - out[kv[0]], err = strconv.ParseInt(kv[1], 10, 64) - if err != nil { - return err - } - } - if !s.changed { - *s.value = out - } else { - for k, v := range out { - (*s.value)[k] = v - } - } - s.changed = true - return nil -} - -func (s *stringToInt64Value) Type() string { - return "stringToInt64" -} - -func (s *stringToInt64Value) String() string { - var buf bytes.Buffer - i := 0 - for k, v := range *s.value { - if i > 0 { - buf.WriteRune(',') - } - buf.WriteString(k) - buf.WriteRune('=') - buf.WriteString(strconv.FormatInt(v, 10)) - i++ - } - return "[" + buf.String() + "]" -} - -func stringToInt64Conv(val string) (interface{}, error) { - val = strings.Trim(val, "[]") - // An empty string would cause an empty map - if len(val) == 0 { - return map[string]int64{}, nil - } - ss := strings.Split(val, ",") - out := make(map[string]int64, len(ss)) - for _, pair := range ss { - kv := strings.SplitN(pair, "=", 2) - if len(kv) != 2 { - return nil, fmt.Errorf("%s must be formatted as key=value", pair) - } - var err error - out[kv[0]], err = strconv.ParseInt(kv[1], 10, 64) - if err != nil { - return nil, err - } - } - return out, nil -} - -// GetStringToInt64 return the map[string]int64 value of a flag with the given name -func (f *FlagSet) GetStringToInt64(name string) (map[string]int64, error) { - val, err := f.getFlagType(name, "stringToInt64", stringToInt64Conv) - if err != nil { - return map[string]int64{}, err - } - return val.(map[string]int64), nil -} - -// StringToInt64Var defines a string flag with specified name, default value, and usage string. -// The argument p point64s to a map[string]int64 variable in which to store the values of the multiple flags. -// The value of each argument will not try to be separated by comma -func (f *FlagSet) StringToInt64Var(p *map[string]int64, name string, value map[string]int64, usage string) { - f.VarP(newStringToInt64Value(value, p), name, "", usage) -} - -// StringToInt64VarP is like StringToInt64Var, but accepts a shorthand letter that can be used after a single dash. -func (f *FlagSet) StringToInt64VarP(p *map[string]int64, name, shorthand string, value map[string]int64, usage string) { - f.VarP(newStringToInt64Value(value, p), name, shorthand, usage) -} - -// StringToInt64Var defines a string flag with specified name, default value, and usage string. -// The argument p point64s to a map[string]int64 variable in which to store the value of the flag. -// The value of each argument will not try to be separated by comma -func StringToInt64Var(p *map[string]int64, name string, value map[string]int64, usage string) { - CommandLine.VarP(newStringToInt64Value(value, p), name, "", usage) -} - -// StringToInt64VarP is like StringToInt64Var, but accepts a shorthand letter that can be used after a single dash. -func StringToInt64VarP(p *map[string]int64, name, shorthand string, value map[string]int64, usage string) { - CommandLine.VarP(newStringToInt64Value(value, p), name, shorthand, usage) -} - -// StringToInt64 defines a string flag with specified name, default value, and usage string. -// The return value is the address of a map[string]int64 variable that stores the value of the flag. -// The value of each argument will not try to be separated by comma -func (f *FlagSet) StringToInt64(name string, value map[string]int64, usage string) *map[string]int64 { - p := map[string]int64{} - f.StringToInt64VarP(&p, name, "", value, usage) - return &p -} - -// StringToInt64P is like StringToInt64, but accepts a shorthand letter that can be used after a single dash. -func (f *FlagSet) StringToInt64P(name, shorthand string, value map[string]int64, usage string) *map[string]int64 { - p := map[string]int64{} - f.StringToInt64VarP(&p, name, shorthand, value, usage) - return &p -} - -// StringToInt64 defines a string flag with specified name, default value, and usage string. -// The return value is the address of a map[string]int64 variable that stores the value of the flag. -// The value of each argument will not try to be separated by comma -func StringToInt64(name string, value map[string]int64, usage string) *map[string]int64 { - return CommandLine.StringToInt64P(name, "", value, usage) -} - -// StringToInt64P is like StringToInt64, but accepts a shorthand letter that can be used after a single dash. -func StringToInt64P(name, shorthand string, value map[string]int64, usage string) *map[string]int64 { - return CommandLine.StringToInt64P(name, shorthand, value, usage) -} diff --git a/vendor/github.com/spf13/pflag/string_to_string.go b/vendor/github.com/spf13/pflag/string_to_string.go deleted file mode 100644 index 890a01afc0..0000000000 --- a/vendor/github.com/spf13/pflag/string_to_string.go +++ /dev/null @@ -1,160 +0,0 @@ -package pflag - -import ( - "bytes" - "encoding/csv" - "fmt" - "strings" -) - -// -- stringToString Value -type stringToStringValue struct { - value *map[string]string - changed bool -} - -func newStringToStringValue(val map[string]string, p *map[string]string) *stringToStringValue { - ssv := new(stringToStringValue) - ssv.value = p - *ssv.value = val - return ssv -} - -// Format: a=1,b=2 -func (s *stringToStringValue) Set(val string) error { - var ss []string - n := strings.Count(val, "=") - switch n { - case 0: - return fmt.Errorf("%s must be formatted as key=value", val) - case 1: - ss = append(ss, strings.Trim(val, `"`)) - default: - r := csv.NewReader(strings.NewReader(val)) - var err error - ss, err = r.Read() - if err != nil { - return err - } - } - - out := make(map[string]string, len(ss)) - for _, pair := range ss { - kv := strings.SplitN(pair, "=", 2) - if len(kv) != 2 { - return fmt.Errorf("%s must be formatted as key=value", pair) - } - out[kv[0]] = kv[1] - } - if !s.changed { - *s.value = out - } else { - for k, v := range out { - (*s.value)[k] = v - } - } - s.changed = true - return nil -} - -func (s *stringToStringValue) Type() string { - return "stringToString" -} - -func (s *stringToStringValue) String() string { - records := make([]string, 0, len(*s.value)>>1) - for k, v := range *s.value { - records = append(records, k+"="+v) - } - - var buf bytes.Buffer - w := csv.NewWriter(&buf) - if err := w.Write(records); err != nil { - panic(err) - } - w.Flush() - return "[" + strings.TrimSpace(buf.String()) + "]" -} - -func stringToStringConv(val string) (interface{}, error) { - val = strings.Trim(val, "[]") - // An empty string would cause an empty map - if len(val) == 0 { - return map[string]string{}, nil - } - r := csv.NewReader(strings.NewReader(val)) - ss, err := r.Read() - if err != nil { - return nil, err - } - out := make(map[string]string, len(ss)) - for _, pair := range ss { - kv := strings.SplitN(pair, "=", 2) - if len(kv) != 2 { - return nil, fmt.Errorf("%s must be formatted as key=value", pair) - } - out[kv[0]] = kv[1] - } - return out, nil -} - -// GetStringToString return the map[string]string value of a flag with the given name -func (f *FlagSet) GetStringToString(name string) (map[string]string, error) { - val, err := f.getFlagType(name, "stringToString", stringToStringConv) - if err != nil { - return map[string]string{}, err - } - return val.(map[string]string), nil -} - -// StringToStringVar defines a string flag with specified name, default value, and usage string. -// The argument p points to a map[string]string variable in which to store the values of the multiple flags. -// The value of each argument will not try to be separated by comma -func (f *FlagSet) StringToStringVar(p *map[string]string, name string, value map[string]string, usage string) { - f.VarP(newStringToStringValue(value, p), name, "", usage) -} - -// StringToStringVarP is like StringToStringVar, but accepts a shorthand letter that can be used after a single dash. -func (f *FlagSet) StringToStringVarP(p *map[string]string, name, shorthand string, value map[string]string, usage string) { - f.VarP(newStringToStringValue(value, p), name, shorthand, usage) -} - -// StringToStringVar defines a string flag with specified name, default value, and usage string. -// The argument p points to a map[string]string variable in which to store the value of the flag. -// The value of each argument will not try to be separated by comma -func StringToStringVar(p *map[string]string, name string, value map[string]string, usage string) { - CommandLine.VarP(newStringToStringValue(value, p), name, "", usage) -} - -// StringToStringVarP is like StringToStringVar, but accepts a shorthand letter that can be used after a single dash. -func StringToStringVarP(p *map[string]string, name, shorthand string, value map[string]string, usage string) { - CommandLine.VarP(newStringToStringValue(value, p), name, shorthand, usage) -} - -// StringToString defines a string flag with specified name, default value, and usage string. -// The return value is the address of a map[string]string variable that stores the value of the flag. -// The value of each argument will not try to be separated by comma -func (f *FlagSet) StringToString(name string, value map[string]string, usage string) *map[string]string { - p := map[string]string{} - f.StringToStringVarP(&p, name, "", value, usage) - return &p -} - -// StringToStringP is like StringToString, but accepts a shorthand letter that can be used after a single dash. -func (f *FlagSet) StringToStringP(name, shorthand string, value map[string]string, usage string) *map[string]string { - p := map[string]string{} - f.StringToStringVarP(&p, name, shorthand, value, usage) - return &p -} - -// StringToString defines a string flag with specified name, default value, and usage string. -// The return value is the address of a map[string]string variable that stores the value of the flag. -// The value of each argument will not try to be separated by comma -func StringToString(name string, value map[string]string, usage string) *map[string]string { - return CommandLine.StringToStringP(name, "", value, usage) -} - -// StringToStringP is like StringToString, but accepts a shorthand letter that can be used after a single dash. -func StringToStringP(name, shorthand string, value map[string]string, usage string) *map[string]string { - return CommandLine.StringToStringP(name, shorthand, value, usage) -} diff --git a/vendor/github.com/spf13/pflag/uint.go b/vendor/github.com/spf13/pflag/uint.go deleted file mode 100644 index dcbc2b758c..0000000000 --- a/vendor/github.com/spf13/pflag/uint.go +++ /dev/null @@ -1,88 +0,0 @@ -package pflag - -import "strconv" - -// -- uint Value -type uintValue uint - -func newUintValue(val uint, p *uint) *uintValue { - *p = val - return (*uintValue)(p) -} - -func (i *uintValue) Set(s string) error { - v, err := strconv.ParseUint(s, 0, 64) - *i = uintValue(v) - return err -} - -func (i *uintValue) Type() string { - return "uint" -} - -func (i *uintValue) String() string { return strconv.FormatUint(uint64(*i), 10) } - -func uintConv(sval string) (interface{}, error) { - v, err := strconv.ParseUint(sval, 0, 0) - if err != nil { - return 0, err - } - return uint(v), nil -} - -// GetUint return the uint value of a flag with the given name -func (f *FlagSet) GetUint(name string) (uint, error) { - val, err := f.getFlagType(name, "uint", uintConv) - if err != nil { - return 0, err - } - return val.(uint), nil -} - -// UintVar defines a uint flag with specified name, default value, and usage string. -// The argument p points to a uint variable in which to store the value of the flag. -func (f *FlagSet) UintVar(p *uint, name string, value uint, usage string) { - f.VarP(newUintValue(value, p), name, "", usage) -} - -// UintVarP is like UintVar, but accepts a shorthand letter that can be used after a single dash. -func (f *FlagSet) UintVarP(p *uint, name, shorthand string, value uint, usage string) { - f.VarP(newUintValue(value, p), name, shorthand, usage) -} - -// UintVar defines a uint flag with specified name, default value, and usage string. -// The argument p points to a uint variable in which to store the value of the flag. -func UintVar(p *uint, name string, value uint, usage string) { - CommandLine.VarP(newUintValue(value, p), name, "", usage) -} - -// UintVarP is like UintVar, but accepts a shorthand letter that can be used after a single dash. -func UintVarP(p *uint, name, shorthand string, value uint, usage string) { - CommandLine.VarP(newUintValue(value, p), name, shorthand, usage) -} - -// Uint defines a uint flag with specified name, default value, and usage string. -// The return value is the address of a uint variable that stores the value of the flag. -func (f *FlagSet) Uint(name string, value uint, usage string) *uint { - p := new(uint) - f.UintVarP(p, name, "", value, usage) - return p -} - -// UintP is like Uint, but accepts a shorthand letter that can be used after a single dash. -func (f *FlagSet) UintP(name, shorthand string, value uint, usage string) *uint { - p := new(uint) - f.UintVarP(p, name, shorthand, value, usage) - return p -} - -// Uint defines a uint flag with specified name, default value, and usage string. -// The return value is the address of a uint variable that stores the value of the flag. -func Uint(name string, value uint, usage string) *uint { - return CommandLine.UintP(name, "", value, usage) -} - -// UintP is like Uint, but accepts a shorthand letter that can be used after a single dash. -func UintP(name, shorthand string, value uint, usage string) *uint { - return CommandLine.UintP(name, shorthand, value, usage) -} diff --git a/vendor/github.com/spf13/pflag/uint16.go b/vendor/github.com/spf13/pflag/uint16.go deleted file mode 100644 index 7e9914eddd..0000000000 --- a/vendor/github.com/spf13/pflag/uint16.go +++ /dev/null @@ -1,88 +0,0 @@ -package pflag - -import "strconv" - -// -- uint16 value -type uint16Value uint16 - -func newUint16Value(val uint16, p *uint16) *uint16Value { - *p = val - return (*uint16Value)(p) -} - -func (i *uint16Value) Set(s string) error { - v, err := strconv.ParseUint(s, 0, 16) - *i = uint16Value(v) - return err -} - -func (i *uint16Value) Type() string { - return "uint16" -} - -func (i *uint16Value) String() string { return strconv.FormatUint(uint64(*i), 10) } - -func uint16Conv(sval string) (interface{}, error) { - v, err := strconv.ParseUint(sval, 0, 16) - if err != nil { - return 0, err - } - return uint16(v), nil -} - -// GetUint16 return the uint16 value of a flag with the given name -func (f *FlagSet) GetUint16(name string) (uint16, error) { - val, err := f.getFlagType(name, "uint16", uint16Conv) - if err != nil { - return 0, err - } - return val.(uint16), nil -} - -// Uint16Var defines a uint flag with specified name, default value, and usage string. -// The argument p points to a uint variable in which to store the value of the flag. -func (f *FlagSet) Uint16Var(p *uint16, name string, value uint16, usage string) { - f.VarP(newUint16Value(value, p), name, "", usage) -} - -// Uint16VarP is like Uint16Var, but accepts a shorthand letter that can be used after a single dash. -func (f *FlagSet) Uint16VarP(p *uint16, name, shorthand string, value uint16, usage string) { - f.VarP(newUint16Value(value, p), name, shorthand, usage) -} - -// Uint16Var defines a uint flag with specified name, default value, and usage string. -// The argument p points to a uint variable in which to store the value of the flag. -func Uint16Var(p *uint16, name string, value uint16, usage string) { - CommandLine.VarP(newUint16Value(value, p), name, "", usage) -} - -// Uint16VarP is like Uint16Var, but accepts a shorthand letter that can be used after a single dash. -func Uint16VarP(p *uint16, name, shorthand string, value uint16, usage string) { - CommandLine.VarP(newUint16Value(value, p), name, shorthand, usage) -} - -// Uint16 defines a uint flag with specified name, default value, and usage string. -// The return value is the address of a uint variable that stores the value of the flag. -func (f *FlagSet) Uint16(name string, value uint16, usage string) *uint16 { - p := new(uint16) - f.Uint16VarP(p, name, "", value, usage) - return p -} - -// Uint16P is like Uint16, but accepts a shorthand letter that can be used after a single dash. -func (f *FlagSet) Uint16P(name, shorthand string, value uint16, usage string) *uint16 { - p := new(uint16) - f.Uint16VarP(p, name, shorthand, value, usage) - return p -} - -// Uint16 defines a uint flag with specified name, default value, and usage string. -// The return value is the address of a uint variable that stores the value of the flag. -func Uint16(name string, value uint16, usage string) *uint16 { - return CommandLine.Uint16P(name, "", value, usage) -} - -// Uint16P is like Uint16, but accepts a shorthand letter that can be used after a single dash. -func Uint16P(name, shorthand string, value uint16, usage string) *uint16 { - return CommandLine.Uint16P(name, shorthand, value, usage) -} diff --git a/vendor/github.com/spf13/pflag/uint32.go b/vendor/github.com/spf13/pflag/uint32.go deleted file mode 100644 index d8024539bf..0000000000 --- a/vendor/github.com/spf13/pflag/uint32.go +++ /dev/null @@ -1,88 +0,0 @@ -package pflag - -import "strconv" - -// -- uint32 value -type uint32Value uint32 - -func newUint32Value(val uint32, p *uint32) *uint32Value { - *p = val - return (*uint32Value)(p) -} - -func (i *uint32Value) Set(s string) error { - v, err := strconv.ParseUint(s, 0, 32) - *i = uint32Value(v) - return err -} - -func (i *uint32Value) Type() string { - return "uint32" -} - -func (i *uint32Value) String() string { return strconv.FormatUint(uint64(*i), 10) } - -func uint32Conv(sval string) (interface{}, error) { - v, err := strconv.ParseUint(sval, 0, 32) - if err != nil { - return 0, err - } - return uint32(v), nil -} - -// GetUint32 return the uint32 value of a flag with the given name -func (f *FlagSet) GetUint32(name string) (uint32, error) { - val, err := f.getFlagType(name, "uint32", uint32Conv) - if err != nil { - return 0, err - } - return val.(uint32), nil -} - -// Uint32Var defines a uint32 flag with specified name, default value, and usage string. -// The argument p points to a uint32 variable in which to store the value of the flag. -func (f *FlagSet) Uint32Var(p *uint32, name string, value uint32, usage string) { - f.VarP(newUint32Value(value, p), name, "", usage) -} - -// Uint32VarP is like Uint32Var, but accepts a shorthand letter that can be used after a single dash. -func (f *FlagSet) Uint32VarP(p *uint32, name, shorthand string, value uint32, usage string) { - f.VarP(newUint32Value(value, p), name, shorthand, usage) -} - -// Uint32Var defines a uint32 flag with specified name, default value, and usage string. -// The argument p points to a uint32 variable in which to store the value of the flag. -func Uint32Var(p *uint32, name string, value uint32, usage string) { - CommandLine.VarP(newUint32Value(value, p), name, "", usage) -} - -// Uint32VarP is like Uint32Var, but accepts a shorthand letter that can be used after a single dash. -func Uint32VarP(p *uint32, name, shorthand string, value uint32, usage string) { - CommandLine.VarP(newUint32Value(value, p), name, shorthand, usage) -} - -// Uint32 defines a uint32 flag with specified name, default value, and usage string. -// The return value is the address of a uint32 variable that stores the value of the flag. -func (f *FlagSet) Uint32(name string, value uint32, usage string) *uint32 { - p := new(uint32) - f.Uint32VarP(p, name, "", value, usage) - return p -} - -// Uint32P is like Uint32, but accepts a shorthand letter that can be used after a single dash. -func (f *FlagSet) Uint32P(name, shorthand string, value uint32, usage string) *uint32 { - p := new(uint32) - f.Uint32VarP(p, name, shorthand, value, usage) - return p -} - -// Uint32 defines a uint32 flag with specified name, default value, and usage string. -// The return value is the address of a uint32 variable that stores the value of the flag. -func Uint32(name string, value uint32, usage string) *uint32 { - return CommandLine.Uint32P(name, "", value, usage) -} - -// Uint32P is like Uint32, but accepts a shorthand letter that can be used after a single dash. -func Uint32P(name, shorthand string, value uint32, usage string) *uint32 { - return CommandLine.Uint32P(name, shorthand, value, usage) -} diff --git a/vendor/github.com/spf13/pflag/uint64.go b/vendor/github.com/spf13/pflag/uint64.go deleted file mode 100644 index f62240f2ce..0000000000 --- a/vendor/github.com/spf13/pflag/uint64.go +++ /dev/null @@ -1,88 +0,0 @@ -package pflag - -import "strconv" - -// -- uint64 Value -type uint64Value uint64 - -func newUint64Value(val uint64, p *uint64) *uint64Value { - *p = val - return (*uint64Value)(p) -} - -func (i *uint64Value) Set(s string) error { - v, err := strconv.ParseUint(s, 0, 64) - *i = uint64Value(v) - return err -} - -func (i *uint64Value) Type() string { - return "uint64" -} - -func (i *uint64Value) String() string { return strconv.FormatUint(uint64(*i), 10) } - -func uint64Conv(sval string) (interface{}, error) { - v, err := strconv.ParseUint(sval, 0, 64) - if err != nil { - return 0, err - } - return uint64(v), nil -} - -// GetUint64 return the uint64 value of a flag with the given name -func (f *FlagSet) GetUint64(name string) (uint64, error) { - val, err := f.getFlagType(name, "uint64", uint64Conv) - if err != nil { - return 0, err - } - return val.(uint64), nil -} - -// Uint64Var defines a uint64 flag with specified name, default value, and usage string. -// The argument p points to a uint64 variable in which to store the value of the flag. -func (f *FlagSet) Uint64Var(p *uint64, name string, value uint64, usage string) { - f.VarP(newUint64Value(value, p), name, "", usage) -} - -// Uint64VarP is like Uint64Var, but accepts a shorthand letter that can be used after a single dash. -func (f *FlagSet) Uint64VarP(p *uint64, name, shorthand string, value uint64, usage string) { - f.VarP(newUint64Value(value, p), name, shorthand, usage) -} - -// Uint64Var defines a uint64 flag with specified name, default value, and usage string. -// The argument p points to a uint64 variable in which to store the value of the flag. -func Uint64Var(p *uint64, name string, value uint64, usage string) { - CommandLine.VarP(newUint64Value(value, p), name, "", usage) -} - -// Uint64VarP is like Uint64Var, but accepts a shorthand letter that can be used after a single dash. -func Uint64VarP(p *uint64, name, shorthand string, value uint64, usage string) { - CommandLine.VarP(newUint64Value(value, p), name, shorthand, usage) -} - -// Uint64 defines a uint64 flag with specified name, default value, and usage string. -// The return value is the address of a uint64 variable that stores the value of the flag. -func (f *FlagSet) Uint64(name string, value uint64, usage string) *uint64 { - p := new(uint64) - f.Uint64VarP(p, name, "", value, usage) - return p -} - -// Uint64P is like Uint64, but accepts a shorthand letter that can be used after a single dash. -func (f *FlagSet) Uint64P(name, shorthand string, value uint64, usage string) *uint64 { - p := new(uint64) - f.Uint64VarP(p, name, shorthand, value, usage) - return p -} - -// Uint64 defines a uint64 flag with specified name, default value, and usage string. -// The return value is the address of a uint64 variable that stores the value of the flag. -func Uint64(name string, value uint64, usage string) *uint64 { - return CommandLine.Uint64P(name, "", value, usage) -} - -// Uint64P is like Uint64, but accepts a shorthand letter that can be used after a single dash. -func Uint64P(name, shorthand string, value uint64, usage string) *uint64 { - return CommandLine.Uint64P(name, shorthand, value, usage) -} diff --git a/vendor/github.com/spf13/pflag/uint8.go b/vendor/github.com/spf13/pflag/uint8.go deleted file mode 100644 index bb0e83c1f6..0000000000 --- a/vendor/github.com/spf13/pflag/uint8.go +++ /dev/null @@ -1,88 +0,0 @@ -package pflag - -import "strconv" - -// -- uint8 Value -type uint8Value uint8 - -func newUint8Value(val uint8, p *uint8) *uint8Value { - *p = val - return (*uint8Value)(p) -} - -func (i *uint8Value) Set(s string) error { - v, err := strconv.ParseUint(s, 0, 8) - *i = uint8Value(v) - return err -} - -func (i *uint8Value) Type() string { - return "uint8" -} - -func (i *uint8Value) String() string { return strconv.FormatUint(uint64(*i), 10) } - -func uint8Conv(sval string) (interface{}, error) { - v, err := strconv.ParseUint(sval, 0, 8) - if err != nil { - return 0, err - } - return uint8(v), nil -} - -// GetUint8 return the uint8 value of a flag with the given name -func (f *FlagSet) GetUint8(name string) (uint8, error) { - val, err := f.getFlagType(name, "uint8", uint8Conv) - if err != nil { - return 0, err - } - return val.(uint8), nil -} - -// Uint8Var defines a uint8 flag with specified name, default value, and usage string. -// The argument p points to a uint8 variable in which to store the value of the flag. -func (f *FlagSet) Uint8Var(p *uint8, name string, value uint8, usage string) { - f.VarP(newUint8Value(value, p), name, "", usage) -} - -// Uint8VarP is like Uint8Var, but accepts a shorthand letter that can be used after a single dash. -func (f *FlagSet) Uint8VarP(p *uint8, name, shorthand string, value uint8, usage string) { - f.VarP(newUint8Value(value, p), name, shorthand, usage) -} - -// Uint8Var defines a uint8 flag with specified name, default value, and usage string. -// The argument p points to a uint8 variable in which to store the value of the flag. -func Uint8Var(p *uint8, name string, value uint8, usage string) { - CommandLine.VarP(newUint8Value(value, p), name, "", usage) -} - -// Uint8VarP is like Uint8Var, but accepts a shorthand letter that can be used after a single dash. -func Uint8VarP(p *uint8, name, shorthand string, value uint8, usage string) { - CommandLine.VarP(newUint8Value(value, p), name, shorthand, usage) -} - -// Uint8 defines a uint8 flag with specified name, default value, and usage string. -// The return value is the address of a uint8 variable that stores the value of the flag. -func (f *FlagSet) Uint8(name string, value uint8, usage string) *uint8 { - p := new(uint8) - f.Uint8VarP(p, name, "", value, usage) - return p -} - -// Uint8P is like Uint8, but accepts a shorthand letter that can be used after a single dash. -func (f *FlagSet) Uint8P(name, shorthand string, value uint8, usage string) *uint8 { - p := new(uint8) - f.Uint8VarP(p, name, shorthand, value, usage) - return p -} - -// Uint8 defines a uint8 flag with specified name, default value, and usage string. -// The return value is the address of a uint8 variable that stores the value of the flag. -func Uint8(name string, value uint8, usage string) *uint8 { - return CommandLine.Uint8P(name, "", value, usage) -} - -// Uint8P is like Uint8, but accepts a shorthand letter that can be used after a single dash. -func Uint8P(name, shorthand string, value uint8, usage string) *uint8 { - return CommandLine.Uint8P(name, shorthand, value, usage) -} diff --git a/vendor/github.com/spf13/pflag/uint_slice.go b/vendor/github.com/spf13/pflag/uint_slice.go deleted file mode 100644 index 5fa924835e..0000000000 --- a/vendor/github.com/spf13/pflag/uint_slice.go +++ /dev/null @@ -1,168 +0,0 @@ -package pflag - -import ( - "fmt" - "strconv" - "strings" -) - -// -- uintSlice Value -type uintSliceValue struct { - value *[]uint - changed bool -} - -func newUintSliceValue(val []uint, p *[]uint) *uintSliceValue { - uisv := new(uintSliceValue) - uisv.value = p - *uisv.value = val - return uisv -} - -func (s *uintSliceValue) Set(val string) error { - ss := strings.Split(val, ",") - out := make([]uint, len(ss)) - for i, d := range ss { - u, err := strconv.ParseUint(d, 10, 0) - if err != nil { - return err - } - out[i] = uint(u) - } - if !s.changed { - *s.value = out - } else { - *s.value = append(*s.value, out...) - } - s.changed = true - return nil -} - -func (s *uintSliceValue) Type() string { - return "uintSlice" -} - -func (s *uintSliceValue) String() string { - out := make([]string, len(*s.value)) - for i, d := range *s.value { - out[i] = fmt.Sprintf("%d", d) - } - return "[" + strings.Join(out, ",") + "]" -} - -func (s *uintSliceValue) fromString(val string) (uint, error) { - t, err := strconv.ParseUint(val, 10, 0) - if err != nil { - return 0, err - } - return uint(t), nil -} - -func (s *uintSliceValue) toString(val uint) string { - return fmt.Sprintf("%d", val) -} - -func (s *uintSliceValue) Append(val string) error { - i, err := s.fromString(val) - if err != nil { - return err - } - *s.value = append(*s.value, i) - return nil -} - -func (s *uintSliceValue) Replace(val []string) error { - out := make([]uint, len(val)) - for i, d := range val { - var err error - out[i], err = s.fromString(d) - if err != nil { - return err - } - } - *s.value = out - return nil -} - -func (s *uintSliceValue) GetSlice() []string { - out := make([]string, len(*s.value)) - for i, d := range *s.value { - out[i] = s.toString(d) - } - return out -} - -func uintSliceConv(val string) (interface{}, error) { - val = strings.Trim(val, "[]") - // Empty string would cause a slice with one (empty) entry - if len(val) == 0 { - return []uint{}, nil - } - ss := strings.Split(val, ",") - out := make([]uint, len(ss)) - for i, d := range ss { - u, err := strconv.ParseUint(d, 10, 0) - if err != nil { - return nil, err - } - out[i] = uint(u) - } - return out, nil -} - -// GetUintSlice returns the []uint value of a flag with the given name. -func (f *FlagSet) GetUintSlice(name string) ([]uint, error) { - val, err := f.getFlagType(name, "uintSlice", uintSliceConv) - if err != nil { - return []uint{}, err - } - return val.([]uint), nil -} - -// UintSliceVar defines a uintSlice flag with specified name, default value, and usage string. -// The argument p points to a []uint variable in which to store the value of the flag. -func (f *FlagSet) UintSliceVar(p *[]uint, name string, value []uint, usage string) { - f.VarP(newUintSliceValue(value, p), name, "", usage) -} - -// UintSliceVarP is like UintSliceVar, but accepts a shorthand letter that can be used after a single dash. -func (f *FlagSet) UintSliceVarP(p *[]uint, name, shorthand string, value []uint, usage string) { - f.VarP(newUintSliceValue(value, p), name, shorthand, usage) -} - -// UintSliceVar defines a uint[] flag with specified name, default value, and usage string. -// The argument p points to a uint[] variable in which to store the value of the flag. -func UintSliceVar(p *[]uint, name string, value []uint, usage string) { - CommandLine.VarP(newUintSliceValue(value, p), name, "", usage) -} - -// UintSliceVarP is like the UintSliceVar, but accepts a shorthand letter that can be used after a single dash. -func UintSliceVarP(p *[]uint, name, shorthand string, value []uint, usage string) { - CommandLine.VarP(newUintSliceValue(value, p), name, shorthand, usage) -} - -// UintSlice defines a []uint flag with specified name, default value, and usage string. -// The return value is the address of a []uint variable that stores the value of the flag. -func (f *FlagSet) UintSlice(name string, value []uint, usage string) *[]uint { - p := []uint{} - f.UintSliceVarP(&p, name, "", value, usage) - return &p -} - -// UintSliceP is like UintSlice, but accepts a shorthand letter that can be used after a single dash. -func (f *FlagSet) UintSliceP(name, shorthand string, value []uint, usage string) *[]uint { - p := []uint{} - f.UintSliceVarP(&p, name, shorthand, value, usage) - return &p -} - -// UintSlice defines a []uint flag with specified name, default value, and usage string. -// The return value is the address of a []uint variable that stores the value of the flag. -func UintSlice(name string, value []uint, usage string) *[]uint { - return CommandLine.UintSliceP(name, "", value, usage) -} - -// UintSliceP is like UintSlice, but accepts a shorthand letter that can be used after a single dash. -func UintSliceP(name, shorthand string, value []uint, usage string) *[]uint { - return CommandLine.UintSliceP(name, shorthand, value, usage) -} diff --git a/vendor/github.com/tmc/grpc-websocket-proxy/LICENSE b/vendor/github.com/tmc/grpc-websocket-proxy/LICENSE deleted file mode 100644 index 95d0bc81f1..0000000000 --- a/vendor/github.com/tmc/grpc-websocket-proxy/LICENSE +++ /dev/null @@ -1,7 +0,0 @@ -Copyright (C) 2016 Travis Cline - -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: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -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. diff --git a/vendor/github.com/tmc/grpc-websocket-proxy/wsproxy/doc.go b/vendor/github.com/tmc/grpc-websocket-proxy/wsproxy/doc.go deleted file mode 100644 index baf9545e28..0000000000 --- a/vendor/github.com/tmc/grpc-websocket-proxy/wsproxy/doc.go +++ /dev/null @@ -1,2 +0,0 @@ -// Package wsproxy implements a websocket proxy for grpc-gateway backed services -package wsproxy diff --git a/vendor/github.com/tmc/grpc-websocket-proxy/wsproxy/websocket_proxy.go b/vendor/github.com/tmc/grpc-websocket-proxy/wsproxy/websocket_proxy.go deleted file mode 100644 index 70921627af..0000000000 --- a/vendor/github.com/tmc/grpc-websocket-proxy/wsproxy/websocket_proxy.go +++ /dev/null @@ -1,350 +0,0 @@ -package wsproxy - -import ( - "bufio" - "fmt" - "io" - "net/http" - "strings" - "time" - - "github.com/gorilla/websocket" - "github.com/sirupsen/logrus" - "golang.org/x/net/context" -) - -// MethodOverrideParam defines the special URL parameter that is translated into the subsequent proxied streaming http request's method. -// -// Deprecated: it is preferable to use the Options parameters to WebSocketProxy to supply parameters. -var MethodOverrideParam = "method" - -// TokenCookieName defines the cookie name that is translated to an 'Authorization: Bearer' header in the streaming http request's headers. -// -// Deprecated: it is preferable to use the Options parameters to WebSocketProxy to supply parameters. -var TokenCookieName = "token" - -// RequestMutatorFunc can supply an alternate outgoing request. -type RequestMutatorFunc func(incoming *http.Request, outgoing *http.Request) *http.Request - -// Proxy provides websocket transport upgrade to compatible endpoints. -type Proxy struct { - h http.Handler - logger Logger - maxRespBodyBufferBytes int - methodOverrideParam string - tokenCookieName string - requestMutator RequestMutatorFunc - headerForwarder func(header string) bool - pingInterval time.Duration - pingWait time.Duration - pongWait time.Duration -} - -// Logger collects log messages. -type Logger interface { - Warnln(...interface{}) - Debugln(...interface{}) -} - -func (p *Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request) { - if !websocket.IsWebSocketUpgrade(r) { - p.h.ServeHTTP(w, r) - return - } - p.proxy(w, r) -} - -// Option allows customization of the proxy. -type Option func(*Proxy) - -// WithMaxRespBodyBufferSize allows specification of a custom size for the -// buffer used while reading the response body. By default, the bufio.Scanner -// used to read the response body sets the maximum token size to MaxScanTokenSize. -func WithMaxRespBodyBufferSize(nBytes int) Option { - return func(p *Proxy) { - p.maxRespBodyBufferBytes = nBytes - } -} - -// WithMethodParamOverride allows specification of the special http parameter that is used in the proxied streaming request. -func WithMethodParamOverride(param string) Option { - return func(p *Proxy) { - p.methodOverrideParam = param - } -} - -// WithTokenCookieName allows specification of the cookie that is supplied as an upstream 'Authorization: Bearer' http header. -func WithTokenCookieName(param string) Option { - return func(p *Proxy) { - p.tokenCookieName = param - } -} - -// WithRequestMutator allows a custom RequestMutatorFunc to be supplied. -func WithRequestMutator(fn RequestMutatorFunc) Option { - return func(p *Proxy) { - p.requestMutator = fn - } -} - -// WithForwardedHeaders allows controlling which headers are forwarded. -func WithForwardedHeaders(fn func(header string) bool) Option { - return func(p *Proxy) { - p.headerForwarder = fn - } -} - -// WithLogger allows a custom FieldLogger to be supplied -func WithLogger(logger Logger) Option { - return func(p *Proxy) { - p.logger = logger - } -} - -// WithPingControl allows specification of ping pong control. The interval -// parameter specifies the pingInterval between pings. The allowed wait time -// for a pong response is (pingInterval * 10) / 9. -func WithPingControl(interval time.Duration) Option { - return func(proxy *Proxy) { - proxy.pingInterval = interval - proxy.pongWait = (interval * 10) / 9 - proxy.pingWait = proxy.pongWait / 6 - } -} - -var defaultHeadersToForward = map[string]bool{ - "Origin": true, - "origin": true, - "Referer": true, - "referer": true, -} - -func defaultHeaderForwarder(header string) bool { - return defaultHeadersToForward[header] -} - -// WebsocketProxy attempts to expose the underlying handler as a bidi websocket stream with newline-delimited -// JSON as the content encoding. -// -// The HTTP Authorization header is either populated from the Sec-Websocket-Protocol field or by a cookie. -// The cookie name is specified by the TokenCookieName value. -// -// example: -// Sec-Websocket-Protocol: Bearer, foobar -// is converted to: -// Authorization: Bearer foobar -// -// Method can be overwritten with the MethodOverrideParam get parameter in the requested URL -func WebsocketProxy(h http.Handler, opts ...Option) http.Handler { - p := &Proxy{ - h: h, - logger: logrus.New(), - methodOverrideParam: MethodOverrideParam, - tokenCookieName: TokenCookieName, - headerForwarder: defaultHeaderForwarder, - } - for _, o := range opts { - o(p) - } - return p -} - -// TODO(tmc): allow modification of upgrader settings? -var upgrader = websocket.Upgrader{ - ReadBufferSize: 1024, - WriteBufferSize: 1024, - CheckOrigin: func(r *http.Request) bool { return true }, -} - -func isClosedConnError(err error) bool { - str := err.Error() - if strings.Contains(str, "use of closed network connection") { - return true - } - return websocket.IsCloseError(err, websocket.CloseNormalClosure, websocket.CloseGoingAway) -} - -func (p *Proxy) proxy(w http.ResponseWriter, r *http.Request) { - var responseHeader http.Header - // If Sec-WebSocket-Protocol starts with "Bearer", respond in kind. - // TODO(tmc): consider customizability/extension point here. - if strings.HasPrefix(r.Header.Get("Sec-WebSocket-Protocol"), "Bearer") { - responseHeader = http.Header{ - "Sec-WebSocket-Protocol": []string{"Bearer"}, - } - } - conn, err := upgrader.Upgrade(w, r, responseHeader) - if err != nil { - p.logger.Warnln("error upgrading websocket:", err) - return - } - defer conn.Close() - - ctx, cancelFn := context.WithCancel(context.Background()) - defer cancelFn() - - requestBodyR, requestBodyW := io.Pipe() - request, err := http.NewRequestWithContext(r.Context(), r.Method, r.URL.String(), requestBodyR) - if err != nil { - p.logger.Warnln("error preparing request:", err) - return - } - if swsp := r.Header.Get("Sec-WebSocket-Protocol"); swsp != "" { - request.Header.Set("Authorization", transformSubProtocolHeader(swsp)) - } - for header := range r.Header { - if p.headerForwarder(header) { - request.Header.Set(header, r.Header.Get(header)) - } - } - // If token cookie is present, populate Authorization header from the cookie instead. - if cookie, err := r.Cookie(p.tokenCookieName); err == nil { - request.Header.Set("Authorization", "Bearer "+cookie.Value) - } - if m := r.URL.Query().Get(p.methodOverrideParam); m != "" { - request.Method = m - } - - if p.requestMutator != nil { - request = p.requestMutator(r, request) - } - - responseBodyR, responseBodyW := io.Pipe() - response := newInMemoryResponseWriter(responseBodyW) - go func() { - <-ctx.Done() - p.logger.Debugln("closing pipes") - requestBodyW.CloseWithError(io.EOF) - responseBodyW.CloseWithError(io.EOF) - response.closed <- true - }() - - go func() { - defer cancelFn() - p.h.ServeHTTP(response, request) - }() - - // read loop -- take messages from websocket and write to http request - go func() { - if p.pingInterval > 0 && p.pingWait > 0 && p.pongWait > 0 { - conn.SetReadDeadline(time.Now().Add(p.pongWait)) - conn.SetPongHandler(func(string) error { conn.SetReadDeadline(time.Now().Add(p.pongWait)); return nil }) - } - defer func() { - cancelFn() - }() - for { - select { - case <-ctx.Done(): - p.logger.Debugln("read loop done") - return - default: - } - p.logger.Debugln("[read] reading from socket.") - _, payload, err := conn.ReadMessage() - if err != nil { - if isClosedConnError(err) { - p.logger.Debugln("[read] websocket closed:", err) - return - } - p.logger.Warnln("error reading websocket message:", err) - return - } - p.logger.Debugln("[read] read payload:", string(payload)) - p.logger.Debugln("[read] writing to requestBody:") - n, err := requestBodyW.Write(payload) - requestBodyW.Write([]byte("\n")) - p.logger.Debugln("[read] wrote to requestBody", n) - if err != nil { - p.logger.Warnln("[read] error writing message to upstream http server:", err) - return - } - } - }() - // ping write loop - if p.pingInterval > 0 && p.pingWait > 0 && p.pongWait > 0 { - go func() { - ticker := time.NewTicker(p.pingInterval) - defer func() { - ticker.Stop() - conn.Close() - }() - for { - select { - case <-ctx.Done(): - p.logger.Debugln("ping loop done") - return - case <-ticker.C: - conn.SetWriteDeadline(time.Now().Add(p.pingWait)) - if err := conn.WriteMessage(websocket.PingMessage, nil); err != nil { - return - } - } - } - }() - } - // write loop -- take messages from response and write to websocket - scanner := bufio.NewScanner(responseBodyR) - - // if maxRespBodyBufferSize has been specified, use custom buffer for scanner - var scannerBuf []byte - if p.maxRespBodyBufferBytes > 0 { - scannerBuf = make([]byte, 0, 64*1024) - scanner.Buffer(scannerBuf, p.maxRespBodyBufferBytes) - } - - for scanner.Scan() { - if len(scanner.Bytes()) == 0 { - p.logger.Warnln("[write] empty scan", scanner.Err()) - continue - } - p.logger.Debugln("[write] scanned", scanner.Text()) - if err = conn.WriteMessage(websocket.TextMessage, scanner.Bytes()); err != nil { - p.logger.Warnln("[write] error writing websocket message:", err) - return - } - } - if err := scanner.Err(); err != nil { - p.logger.Warnln("scanner err:", err) - } -} - -type inMemoryResponseWriter struct { - io.Writer - header http.Header - code int - closed chan bool -} - -func newInMemoryResponseWriter(w io.Writer) *inMemoryResponseWriter { - return &inMemoryResponseWriter{ - Writer: w, - header: http.Header{}, - closed: make(chan bool, 1), - } -} - -// IE and Edge do not delimit Sec-WebSocket-Protocol strings with spaces -func transformSubProtocolHeader(header string) string { - tokens := strings.SplitN(header, "Bearer,", 2) - - if len(tokens) < 2 { - return "" - } - - return fmt.Sprintf("Bearer %v", strings.Trim(tokens[1], " ")) -} - -func (w *inMemoryResponseWriter) Write(b []byte) (int, error) { - return w.Writer.Write(b) -} -func (w *inMemoryResponseWriter) Header() http.Header { - return w.header -} -func (w *inMemoryResponseWriter) WriteHeader(code int) { - w.code = code -} -func (w *inMemoryResponseWriter) CloseNotify() <-chan bool { - return w.closed -} -func (w *inMemoryResponseWriter) Flush() {} diff --git a/vendor/github.com/weaveworks/common/server/server.go b/vendor/github.com/weaveworks/common/server/server.go index ee6cafee16..58da4ae3ac 100644 --- a/vendor/github.com/weaveworks/common/server/server.go +++ b/vendor/github.com/weaveworks/common/server/server.go @@ -273,8 +273,8 @@ func New(cfg Config) (*Server, error) { grpcStreamMiddleware := []grpc.StreamServerInterceptor{ serverLog.StreamServerInterceptor, - middleware.StreamServerInstrumentInterceptor(requestDuration), otgrpc.OpenTracingStreamServerInterceptor(opentracing.GlobalTracer()), + middleware.StreamServerInstrumentInterceptor(requestDuration), } grpcStreamMiddleware = append(grpcStreamMiddleware, cfg.GRPCStreamMiddleware...) diff --git a/vendor/github.com/xiang90/probing/.gitignore b/vendor/github.com/xiang90/probing/.gitignore deleted file mode 100644 index daf913b1b3..0000000000 --- a/vendor/github.com/xiang90/probing/.gitignore +++ /dev/null @@ -1,24 +0,0 @@ -# Compiled Object files, Static and Dynamic libs (Shared Objects) -*.o -*.a -*.so - -# Folders -_obj -_test - -# Architecture specific extensions/prefixes -*.[568vq] -[568vq].out - -*.cgo1.go -*.cgo2.c -_cgo_defun.c -_cgo_gotypes.go -_cgo_export.* - -_testmain.go - -*.exe -*.test -*.prof diff --git a/vendor/github.com/xiang90/probing/LICENSE b/vendor/github.com/xiang90/probing/LICENSE deleted file mode 100644 index cde8b8b05f..0000000000 --- a/vendor/github.com/xiang90/probing/LICENSE +++ /dev/null @@ -1,22 +0,0 @@ -The MIT License (MIT) - -Copyright (c) 2015 Xiang Li - -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: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -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. - diff --git a/vendor/github.com/xiang90/probing/README.md b/vendor/github.com/xiang90/probing/README.md deleted file mode 100644 index 2ff682057a..0000000000 --- a/vendor/github.com/xiang90/probing/README.md +++ /dev/null @@ -1,39 +0,0 @@ -## Getting Started - -### Install the handler - -We first need to serve the probing HTTP handler. - -```go - http.HandleFunc("/health", probing.NewHandler()) - err := http.ListenAndServe(":12345", nil) - if err != nil { - log.Fatal("ListenAndServe: ", err) - } -``` - -### Start to probe - -Now we can start to probe the endpoint. - -``` go - id := "example" - probingInterval = 5 * time.Second - url := "http://example.com:12345/health" - p.AddHTTP(id, probingInterval, url) - - time.Sleep(13 * time.Second) - status, err := p.Status(id) - fmt.Printf("Total Probing: %d, Total Loss: %d, Estimated RTT: %v, Estimated Clock Difference: %v\n", - status.Total(), status.Loss(), status.SRTT(), status.ClockDiff()) - // Total Probing: 2, Total Loss: 0, Estimated RTT: 320.771µs, Estimated Clock Difference: -35.869µs -``` - -### TODOs: - -- TCP probing -- UDP probing -- Gossip based probing -- More accurate RTT estimation -- More accurate Clock difference estimation -- Use a clock interface rather than the real clock diff --git a/vendor/github.com/xiang90/probing/prober.go b/vendor/github.com/xiang90/probing/prober.go deleted file mode 100644 index 9431c101e3..0000000000 --- a/vendor/github.com/xiang90/probing/prober.go +++ /dev/null @@ -1,139 +0,0 @@ -package probing - -import ( - "encoding/json" - "errors" - "fmt" - "net/http" - "sync" - "time" -) - -var ( - ErrNotFound = errors.New("probing: id not found") - ErrExist = errors.New("probing: id exists") -) - -type Prober interface { - AddHTTP(id string, probingInterval time.Duration, endpoints []string) error - Remove(id string) error - RemoveAll() - Reset(id string) error - Status(id string) (Status, error) -} - -type prober struct { - mu sync.Mutex - targets map[string]*status - tr http.RoundTripper -} - -func NewProber(tr http.RoundTripper) Prober { - p := &prober{targets: make(map[string]*status)} - if tr == nil { - p.tr = http.DefaultTransport - } else { - p.tr = tr - } - return p -} - -func (p *prober) AddHTTP(id string, probingInterval time.Duration, endpoints []string) error { - p.mu.Lock() - defer p.mu.Unlock() - if _, ok := p.targets[id]; ok { - return ErrExist - } - - s := &status{stopC: make(chan struct{})} - p.targets[id] = s - - ticker := time.NewTicker(probingInterval) - - go func() { - pinned := 0 - for { - select { - case <-ticker.C: - start := time.Now() - req, err := http.NewRequest("GET", endpoints[pinned], nil) - if err != nil { - panic(err) - } - resp, err := p.tr.RoundTrip(req) - if err == nil && resp.StatusCode != http.StatusOK { - err = fmt.Errorf("got unexpected HTTP status code %s from %s", resp.Status, endpoints[pinned]) - resp.Body.Close() - } - if err != nil { - s.recordFailure(err) - pinned = (pinned + 1) % len(endpoints) - continue - } - - var hh Health - d := json.NewDecoder(resp.Body) - err = d.Decode(&hh) - resp.Body.Close() - if err != nil || !hh.OK { - s.recordFailure(err) - pinned = (pinned + 1) % len(endpoints) - continue - } - - s.record(time.Since(start), hh.Now) - case <-s.stopC: - ticker.Stop() - return - } - } - }() - - return nil -} - -func (p *prober) Remove(id string) error { - p.mu.Lock() - defer p.mu.Unlock() - - s, ok := p.targets[id] - if !ok { - return ErrNotFound - } - close(s.stopC) - delete(p.targets, id) - return nil -} - -func (p *prober) RemoveAll() { - p.mu.Lock() - defer p.mu.Unlock() - - for _, s := range p.targets { - close(s.stopC) - } - p.targets = make(map[string]*status) -} - -func (p *prober) Reset(id string) error { - p.mu.Lock() - defer p.mu.Unlock() - - s, ok := p.targets[id] - if !ok { - return ErrNotFound - } - s.reset() - return nil -} - -func (p *prober) Status(id string) (Status, error) { - p.mu.Lock() - defer p.mu.Unlock() - - s, ok := p.targets[id] - if !ok { - return nil, ErrNotFound - } - return s, nil -} diff --git a/vendor/github.com/xiang90/probing/server.go b/vendor/github.com/xiang90/probing/server.go deleted file mode 100644 index 0e7b797d25..0000000000 --- a/vendor/github.com/xiang90/probing/server.go +++ /dev/null @@ -1,25 +0,0 @@ -package probing - -import ( - "encoding/json" - "net/http" - "time" -) - -func NewHandler() http.Handler { - return &httpHealth{} -} - -type httpHealth struct { -} - -type Health struct { - OK bool - Now time.Time -} - -func (h *httpHealth) ServeHTTP(w http.ResponseWriter, r *http.Request) { - health := Health{OK: true, Now: time.Now()} - e := json.NewEncoder(w) - e.Encode(health) -} diff --git a/vendor/github.com/xiang90/probing/status.go b/vendor/github.com/xiang90/probing/status.go deleted file mode 100644 index bb5f6599fc..0000000000 --- a/vendor/github.com/xiang90/probing/status.go +++ /dev/null @@ -1,108 +0,0 @@ -package probing - -import ( - "sync" - "time" -) - -var ( - // weight factor - α = 0.125 -) - -type Status interface { - Total() int64 - Loss() int64 - Health() bool - Err() error - // Estimated smoothed round trip time - SRTT() time.Duration - // Estimated clock difference - ClockDiff() time.Duration - StopNotify() <-chan struct{} -} - -type status struct { - mu sync.Mutex - srtt time.Duration - total int64 - loss int64 - health bool - err error - clockdiff time.Duration - stopC chan struct{} -} - -// SRTT = (1-α) * SRTT + α * RTT -func (s *status) SRTT() time.Duration { - s.mu.Lock() - defer s.mu.Unlock() - return s.srtt -} - -func (s *status) Total() int64 { - s.mu.Lock() - defer s.mu.Unlock() - return s.total -} - -func (s *status) Loss() int64 { - s.mu.Lock() - defer s.mu.Unlock() - return s.loss -} - -func (s *status) Health() bool { - s.mu.Lock() - defer s.mu.Unlock() - return s.health -} - -func (s *status) Err() error { - s.mu.Lock() - defer s.mu.Unlock() - return s.err -} - -func (s *status) ClockDiff() time.Duration { - s.mu.Lock() - defer s.mu.Unlock() - return s.clockdiff -} - -func (s *status) StopNotify() <-chan struct{} { - return s.stopC -} - -func (s *status) record(rtt time.Duration, when time.Time) { - s.mu.Lock() - defer s.mu.Unlock() - - s.total += 1 - s.health = true - s.srtt = time.Duration((1-α)*float64(s.srtt) + α*float64(rtt)) - s.clockdiff = time.Now().Sub(when) - s.srtt/2 - s.err = nil -} - -func (s *status) recordFailure(err error) { - s.mu.Lock() - defer s.mu.Unlock() - - s.total++ - s.health = false - s.loss += 1 - s.err = err -} - -func (s *status) reset() { - s.mu.Lock() - defer s.mu.Unlock() - - s.srtt = 0 - s.total = 0 - s.loss = 0 - s.health = false - s.clockdiff = 0 - s.err = nil -} diff --git a/vendor/go.etcd.io/etcd/api/v3/etcdserverpb/gw/rpc.pb.gw.go b/vendor/go.etcd.io/etcd/api/v3/etcdserverpb/gw/rpc.pb.gw.go deleted file mode 100644 index 2fca126af8..0000000000 --- a/vendor/go.etcd.io/etcd/api/v3/etcdserverpb/gw/rpc.pb.gw.go +++ /dev/null @@ -1,3771 +0,0 @@ -// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. -// source: api/etcdserverpb/rpc.proto - -/* -Package etcdserverpb is a reverse proxy. - -It translates gRPC into RESTful JSON APIs. -*/ -package gw - -import ( - "context" - "go.etcd.io/etcd/api/v3/etcdserverpb" - "io" - "net/http" - - "github.com/golang/protobuf/descriptor" - "github.com/golang/protobuf/proto" - "github.com/grpc-ecosystem/grpc-gateway/runtime" - "github.com/grpc-ecosystem/grpc-gateway/utilities" - "google.golang.org/grpc" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/grpclog" - "google.golang.org/grpc/status" -) - -// Suppress "imported and not used" errors -var _ codes.Code -var _ io.Reader -var _ status.Status -var _ = runtime.String -var _ = utilities.NewDoubleArray -var _ = descriptor.ForMessage - -func request_KV_Range_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.KVClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.RangeRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.Range(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func local_request_KV_Range_0(ctx context.Context, marshaler runtime.Marshaler, server etcdserverpb.KVServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.RangeRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := server.Range(ctx, &protoReq) - return msg, metadata, err - -} - -func request_KV_Put_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.KVClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.PutRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.Put(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func local_request_KV_Put_0(ctx context.Context, marshaler runtime.Marshaler, server etcdserverpb.KVServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.PutRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := server.Put(ctx, &protoReq) - return msg, metadata, err - -} - -func request_KV_DeleteRange_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.KVClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.DeleteRangeRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.DeleteRange(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func local_request_KV_DeleteRange_0(ctx context.Context, marshaler runtime.Marshaler, server etcdserverpb.KVServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.DeleteRangeRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := server.DeleteRange(ctx, &protoReq) - return msg, metadata, err - -} - -func request_KV_Txn_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.KVClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.TxnRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.Txn(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func local_request_KV_Txn_0(ctx context.Context, marshaler runtime.Marshaler, server etcdserverpb.KVServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.TxnRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := server.Txn(ctx, &protoReq) - return msg, metadata, err - -} - -func request_KV_Compact_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.KVClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.CompactionRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.Compact(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func local_request_KV_Compact_0(ctx context.Context, marshaler runtime.Marshaler, server etcdserverpb.KVServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.CompactionRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := server.Compact(ctx, &protoReq) - return msg, metadata, err - -} - -func request_Watch_Watch_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.WatchClient, req *http.Request, pathParams map[string]string) (etcdserverpb.Watch_WatchClient, runtime.ServerMetadata, error) { - var metadata runtime.ServerMetadata - stream, err := client.Watch(ctx) - if err != nil { - grpclog.Infof("Failed to start streaming: %v", err) - return nil, metadata, err - } - dec := marshaler.NewDecoder(req.Body) - handleSend := func() error { - var protoReq etcdserverpb.WatchRequest - err := dec.Decode(&protoReq) - if err == io.EOF { - return err - } - if err != nil { - grpclog.Infof("Failed to decode request: %v", err) - return err - } - if err := stream.Send(&protoReq); err != nil { - grpclog.Infof("Failed to send request: %v", err) - return err - } - return nil - } - if err := handleSend(); err != nil { - if cerr := stream.CloseSend(); cerr != nil { - grpclog.Infof("Failed to terminate client stream: %v", cerr) - } - if err == io.EOF { - return stream, metadata, nil - } - return nil, metadata, err - } - go func() { - for { - if err := handleSend(); err != nil { - break - } - } - if err := stream.CloseSend(); err != nil { - grpclog.Infof("Failed to terminate client stream: %v", err) - } - }() - header, err := stream.Header() - if err != nil { - grpclog.Infof("Failed to get header from client: %v", err) - return nil, metadata, err - } - metadata.HeaderMD = header - return stream, metadata, nil -} - -func request_Lease_LeaseGrant_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.LeaseClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.LeaseGrantRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.LeaseGrant(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func local_request_Lease_LeaseGrant_0(ctx context.Context, marshaler runtime.Marshaler, server etcdserverpb.LeaseServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.LeaseGrantRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := server.LeaseGrant(ctx, &protoReq) - return msg, metadata, err - -} - -func request_Lease_LeaseRevoke_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.LeaseClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.LeaseRevokeRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.LeaseRevoke(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func local_request_Lease_LeaseRevoke_0(ctx context.Context, marshaler runtime.Marshaler, server etcdserverpb.LeaseServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.LeaseRevokeRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := server.LeaseRevoke(ctx, &protoReq) - return msg, metadata, err - -} - -func request_Lease_LeaseRevoke_1(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.LeaseClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.LeaseRevokeRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.LeaseRevoke(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func local_request_Lease_LeaseRevoke_1(ctx context.Context, marshaler runtime.Marshaler, server etcdserverpb.LeaseServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.LeaseRevokeRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := server.LeaseRevoke(ctx, &protoReq) - return msg, metadata, err - -} - -func request_Lease_LeaseKeepAlive_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.LeaseClient, req *http.Request, pathParams map[string]string) (etcdserverpb.Lease_LeaseKeepAliveClient, runtime.ServerMetadata, error) { - var metadata runtime.ServerMetadata - stream, err := client.LeaseKeepAlive(ctx) - if err != nil { - grpclog.Infof("Failed to start streaming: %v", err) - return nil, metadata, err - } - dec := marshaler.NewDecoder(req.Body) - handleSend := func() error { - var protoReq etcdserverpb.LeaseKeepAliveRequest - err := dec.Decode(&protoReq) - if err == io.EOF { - return err - } - if err != nil { - grpclog.Infof("Failed to decode request: %v", err) - return err - } - if err := stream.Send(&protoReq); err != nil { - grpclog.Infof("Failed to send request: %v", err) - return err - } - return nil - } - if err := handleSend(); err != nil { - if cerr := stream.CloseSend(); cerr != nil { - grpclog.Infof("Failed to terminate client stream: %v", cerr) - } - if err == io.EOF { - return stream, metadata, nil - } - return nil, metadata, err - } - go func() { - for { - if err := handleSend(); err != nil { - break - } - } - if err := stream.CloseSend(); err != nil { - grpclog.Infof("Failed to terminate client stream: %v", err) - } - }() - header, err := stream.Header() - if err != nil { - grpclog.Infof("Failed to get header from client: %v", err) - return nil, metadata, err - } - metadata.HeaderMD = header - return stream, metadata, nil -} - -func request_Lease_LeaseTimeToLive_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.LeaseClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.LeaseTimeToLiveRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.LeaseTimeToLive(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func local_request_Lease_LeaseTimeToLive_0(ctx context.Context, marshaler runtime.Marshaler, server etcdserverpb.LeaseServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.LeaseTimeToLiveRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := server.LeaseTimeToLive(ctx, &protoReq) - return msg, metadata, err - -} - -func request_Lease_LeaseTimeToLive_1(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.LeaseClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.LeaseTimeToLiveRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.LeaseTimeToLive(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func local_request_Lease_LeaseTimeToLive_1(ctx context.Context, marshaler runtime.Marshaler, server etcdserverpb.LeaseServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.LeaseTimeToLiveRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := server.LeaseTimeToLive(ctx, &protoReq) - return msg, metadata, err - -} - -func request_Lease_LeaseLeases_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.LeaseClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.LeaseLeasesRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.LeaseLeases(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func local_request_Lease_LeaseLeases_0(ctx context.Context, marshaler runtime.Marshaler, server etcdserverpb.LeaseServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.LeaseLeasesRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := server.LeaseLeases(ctx, &protoReq) - return msg, metadata, err - -} - -func request_Lease_LeaseLeases_1(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.LeaseClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.LeaseLeasesRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.LeaseLeases(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func local_request_Lease_LeaseLeases_1(ctx context.Context, marshaler runtime.Marshaler, server etcdserverpb.LeaseServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.LeaseLeasesRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := server.LeaseLeases(ctx, &protoReq) - return msg, metadata, err - -} - -func request_Cluster_MemberAdd_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.ClusterClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.MemberAddRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.MemberAdd(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func local_request_Cluster_MemberAdd_0(ctx context.Context, marshaler runtime.Marshaler, server etcdserverpb.ClusterServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.MemberAddRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := server.MemberAdd(ctx, &protoReq) - return msg, metadata, err - -} - -func request_Cluster_MemberRemove_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.ClusterClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.MemberRemoveRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.MemberRemove(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func local_request_Cluster_MemberRemove_0(ctx context.Context, marshaler runtime.Marshaler, server etcdserverpb.ClusterServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.MemberRemoveRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := server.MemberRemove(ctx, &protoReq) - return msg, metadata, err - -} - -func request_Cluster_MemberUpdate_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.ClusterClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.MemberUpdateRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.MemberUpdate(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func local_request_Cluster_MemberUpdate_0(ctx context.Context, marshaler runtime.Marshaler, server etcdserverpb.ClusterServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.MemberUpdateRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := server.MemberUpdate(ctx, &protoReq) - return msg, metadata, err - -} - -func request_Cluster_MemberList_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.ClusterClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.MemberListRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.MemberList(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func local_request_Cluster_MemberList_0(ctx context.Context, marshaler runtime.Marshaler, server etcdserverpb.ClusterServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.MemberListRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := server.MemberList(ctx, &protoReq) - return msg, metadata, err - -} - -func request_Cluster_MemberPromote_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.ClusterClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.MemberPromoteRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.MemberPromote(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func local_request_Cluster_MemberPromote_0(ctx context.Context, marshaler runtime.Marshaler, server etcdserverpb.ClusterServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.MemberPromoteRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := server.MemberPromote(ctx, &protoReq) - return msg, metadata, err - -} - -func request_Maintenance_Alarm_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.MaintenanceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.AlarmRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.Alarm(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func local_request_Maintenance_Alarm_0(ctx context.Context, marshaler runtime.Marshaler, server etcdserverpb.MaintenanceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.AlarmRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := server.Alarm(ctx, &protoReq) - return msg, metadata, err - -} - -func request_Maintenance_Status_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.MaintenanceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.StatusRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.Status(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func local_request_Maintenance_Status_0(ctx context.Context, marshaler runtime.Marshaler, server etcdserverpb.MaintenanceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.StatusRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := server.Status(ctx, &protoReq) - return msg, metadata, err - -} - -func request_Maintenance_Defragment_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.MaintenanceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.DefragmentRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.Defragment(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func local_request_Maintenance_Defragment_0(ctx context.Context, marshaler runtime.Marshaler, server etcdserverpb.MaintenanceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.DefragmentRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := server.Defragment(ctx, &protoReq) - return msg, metadata, err - -} - -func request_Maintenance_Hash_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.MaintenanceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.HashRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.Hash(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func local_request_Maintenance_Hash_0(ctx context.Context, marshaler runtime.Marshaler, server etcdserverpb.MaintenanceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.HashRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := server.Hash(ctx, &protoReq) - return msg, metadata, err - -} - -func request_Maintenance_HashKV_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.MaintenanceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.HashKVRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.HashKV(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func local_request_Maintenance_HashKV_0(ctx context.Context, marshaler runtime.Marshaler, server etcdserverpb.MaintenanceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.HashKVRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := server.HashKV(ctx, &protoReq) - return msg, metadata, err - -} - -func request_Maintenance_Snapshot_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.MaintenanceClient, req *http.Request, pathParams map[string]string) (etcdserverpb.Maintenance_SnapshotClient, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.SnapshotRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - stream, err := client.Snapshot(ctx, &protoReq) - if err != nil { - return nil, metadata, err - } - header, err := stream.Header() - if err != nil { - return nil, metadata, err - } - metadata.HeaderMD = header - return stream, metadata, nil - -} - -func request_Maintenance_MoveLeader_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.MaintenanceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.MoveLeaderRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.MoveLeader(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func local_request_Maintenance_MoveLeader_0(ctx context.Context, marshaler runtime.Marshaler, server etcdserverpb.MaintenanceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.MoveLeaderRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := server.MoveLeader(ctx, &protoReq) - return msg, metadata, err - -} - -func request_Maintenance_Downgrade_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.MaintenanceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.DowngradeRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.Downgrade(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func local_request_Maintenance_Downgrade_0(ctx context.Context, marshaler runtime.Marshaler, server etcdserverpb.MaintenanceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.DowngradeRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := server.Downgrade(ctx, &protoReq) - return msg, metadata, err - -} - -func request_Auth_AuthEnable_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.AuthClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.AuthEnableRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.AuthEnable(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func local_request_Auth_AuthEnable_0(ctx context.Context, marshaler runtime.Marshaler, server etcdserverpb.AuthServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.AuthEnableRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := server.AuthEnable(ctx, &protoReq) - return msg, metadata, err - -} - -func request_Auth_AuthDisable_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.AuthClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.AuthDisableRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.AuthDisable(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func local_request_Auth_AuthDisable_0(ctx context.Context, marshaler runtime.Marshaler, server etcdserverpb.AuthServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.AuthDisableRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := server.AuthDisable(ctx, &protoReq) - return msg, metadata, err - -} - -func request_Auth_AuthStatus_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.AuthClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.AuthStatusRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.AuthStatus(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func local_request_Auth_AuthStatus_0(ctx context.Context, marshaler runtime.Marshaler, server etcdserverpb.AuthServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.AuthStatusRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := server.AuthStatus(ctx, &protoReq) - return msg, metadata, err - -} - -func request_Auth_Authenticate_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.AuthClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.AuthenticateRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.Authenticate(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func local_request_Auth_Authenticate_0(ctx context.Context, marshaler runtime.Marshaler, server etcdserverpb.AuthServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.AuthenticateRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := server.Authenticate(ctx, &protoReq) - return msg, metadata, err - -} - -func request_Auth_UserAdd_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.AuthClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.AuthUserAddRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.UserAdd(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func local_request_Auth_UserAdd_0(ctx context.Context, marshaler runtime.Marshaler, server etcdserverpb.AuthServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.AuthUserAddRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := server.UserAdd(ctx, &protoReq) - return msg, metadata, err - -} - -func request_Auth_UserGet_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.AuthClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.AuthUserGetRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.UserGet(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func local_request_Auth_UserGet_0(ctx context.Context, marshaler runtime.Marshaler, server etcdserverpb.AuthServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.AuthUserGetRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := server.UserGet(ctx, &protoReq) - return msg, metadata, err - -} - -func request_Auth_UserList_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.AuthClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.AuthUserListRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.UserList(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func local_request_Auth_UserList_0(ctx context.Context, marshaler runtime.Marshaler, server etcdserverpb.AuthServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.AuthUserListRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := server.UserList(ctx, &protoReq) - return msg, metadata, err - -} - -func request_Auth_UserDelete_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.AuthClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.AuthUserDeleteRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.UserDelete(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func local_request_Auth_UserDelete_0(ctx context.Context, marshaler runtime.Marshaler, server etcdserverpb.AuthServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.AuthUserDeleteRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := server.UserDelete(ctx, &protoReq) - return msg, metadata, err - -} - -func request_Auth_UserChangePassword_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.AuthClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.AuthUserChangePasswordRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.UserChangePassword(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func local_request_Auth_UserChangePassword_0(ctx context.Context, marshaler runtime.Marshaler, server etcdserverpb.AuthServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.AuthUserChangePasswordRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := server.UserChangePassword(ctx, &protoReq) - return msg, metadata, err - -} - -func request_Auth_UserGrantRole_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.AuthClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.AuthUserGrantRoleRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.UserGrantRole(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func local_request_Auth_UserGrantRole_0(ctx context.Context, marshaler runtime.Marshaler, server etcdserverpb.AuthServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.AuthUserGrantRoleRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := server.UserGrantRole(ctx, &protoReq) - return msg, metadata, err - -} - -func request_Auth_UserRevokeRole_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.AuthClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.AuthUserRevokeRoleRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.UserRevokeRole(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func local_request_Auth_UserRevokeRole_0(ctx context.Context, marshaler runtime.Marshaler, server etcdserverpb.AuthServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.AuthUserRevokeRoleRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := server.UserRevokeRole(ctx, &protoReq) - return msg, metadata, err - -} - -func request_Auth_RoleAdd_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.AuthClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.AuthRoleAddRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.RoleAdd(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func local_request_Auth_RoleAdd_0(ctx context.Context, marshaler runtime.Marshaler, server etcdserverpb.AuthServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.AuthRoleAddRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := server.RoleAdd(ctx, &protoReq) - return msg, metadata, err - -} - -func request_Auth_RoleGet_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.AuthClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.AuthRoleGetRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.RoleGet(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func local_request_Auth_RoleGet_0(ctx context.Context, marshaler runtime.Marshaler, server etcdserverpb.AuthServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.AuthRoleGetRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := server.RoleGet(ctx, &protoReq) - return msg, metadata, err - -} - -func request_Auth_RoleList_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.AuthClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.AuthRoleListRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.RoleList(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func local_request_Auth_RoleList_0(ctx context.Context, marshaler runtime.Marshaler, server etcdserverpb.AuthServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.AuthRoleListRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := server.RoleList(ctx, &protoReq) - return msg, metadata, err - -} - -func request_Auth_RoleDelete_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.AuthClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.AuthRoleDeleteRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.RoleDelete(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func local_request_Auth_RoleDelete_0(ctx context.Context, marshaler runtime.Marshaler, server etcdserverpb.AuthServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.AuthRoleDeleteRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := server.RoleDelete(ctx, &protoReq) - return msg, metadata, err - -} - -func request_Auth_RoleGrantPermission_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.AuthClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.AuthRoleGrantPermissionRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.RoleGrantPermission(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func local_request_Auth_RoleGrantPermission_0(ctx context.Context, marshaler runtime.Marshaler, server etcdserverpb.AuthServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.AuthRoleGrantPermissionRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := server.RoleGrantPermission(ctx, &protoReq) - return msg, metadata, err - -} - -func request_Auth_RoleRevokePermission_0(ctx context.Context, marshaler runtime.Marshaler, client etcdserverpb.AuthClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.AuthRoleRevokePermissionRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.RoleRevokePermission(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func local_request_Auth_RoleRevokePermission_0(ctx context.Context, marshaler runtime.Marshaler, server etcdserverpb.AuthServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq etcdserverpb.AuthRoleRevokePermissionRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := server.RoleRevokePermission(ctx, &protoReq) - return msg, metadata, err - -} - -// etcdserverpb.RegisterKVHandlerServer registers the http handlers for service KV to "mux". -// UnaryRPC :call etcdserverpb.KVServer directly. -// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. -func RegisterKVHandlerServer(ctx context.Context, mux *runtime.ServeMux, server etcdserverpb.KVServer) error { - - mux.Handle("POST", pattern_KV_Range_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := local_request_KV_Range_0(rctx, inboundMarshaler, server, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_KV_Range_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_KV_Put_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := local_request_KV_Put_0(rctx, inboundMarshaler, server, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_KV_Put_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_KV_DeleteRange_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := local_request_KV_DeleteRange_0(rctx, inboundMarshaler, server, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_KV_DeleteRange_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_KV_Txn_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := local_request_KV_Txn_0(rctx, inboundMarshaler, server, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_KV_Txn_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_KV_Compact_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := local_request_KV_Compact_0(rctx, inboundMarshaler, server, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_KV_Compact_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - return nil -} - -// etcdserverpb.RegisterWatchHandlerServer registers the http handlers for service Watch to "mux". -// UnaryRPC :call etcdserverpb.WatchServer directly. -// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. -func RegisterWatchHandlerServer(ctx context.Context, mux *runtime.ServeMux, server etcdserverpb.WatchServer) error { - - mux.Handle("POST", pattern_Watch_Watch_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - err := status.Error(codes.Unimplemented, "streaming calls are not yet supported in the in-process transport") - _, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - }) - - return nil -} - -// etcdserverpb.RegisterLeaseHandlerServer registers the http handlers for service Lease to "mux". -// UnaryRPC :call etcdserverpb.LeaseServer directly. -// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. -func RegisterLeaseHandlerServer(ctx context.Context, mux *runtime.ServeMux, server etcdserverpb.LeaseServer) error { - - mux.Handle("POST", pattern_Lease_LeaseGrant_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := local_request_Lease_LeaseGrant_0(rctx, inboundMarshaler, server, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Lease_LeaseGrant_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Lease_LeaseRevoke_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := local_request_Lease_LeaseRevoke_0(rctx, inboundMarshaler, server, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Lease_LeaseRevoke_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Lease_LeaseRevoke_1, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := local_request_Lease_LeaseRevoke_1(rctx, inboundMarshaler, server, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Lease_LeaseRevoke_1(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Lease_LeaseKeepAlive_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - err := status.Error(codes.Unimplemented, "streaming calls are not yet supported in the in-process transport") - _, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - }) - - mux.Handle("POST", pattern_Lease_LeaseTimeToLive_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := local_request_Lease_LeaseTimeToLive_0(rctx, inboundMarshaler, server, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Lease_LeaseTimeToLive_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Lease_LeaseTimeToLive_1, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := local_request_Lease_LeaseTimeToLive_1(rctx, inboundMarshaler, server, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Lease_LeaseTimeToLive_1(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Lease_LeaseLeases_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := local_request_Lease_LeaseLeases_0(rctx, inboundMarshaler, server, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Lease_LeaseLeases_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Lease_LeaseLeases_1, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := local_request_Lease_LeaseLeases_1(rctx, inboundMarshaler, server, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Lease_LeaseLeases_1(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - return nil -} - -// etcdserverpb.RegisterClusterHandlerServer registers the http handlers for service Cluster to "mux". -// UnaryRPC :call etcdserverpb.ClusterServer directly. -// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. -func RegisterClusterHandlerServer(ctx context.Context, mux *runtime.ServeMux, server etcdserverpb.ClusterServer) error { - - mux.Handle("POST", pattern_Cluster_MemberAdd_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := local_request_Cluster_MemberAdd_0(rctx, inboundMarshaler, server, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Cluster_MemberAdd_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Cluster_MemberRemove_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := local_request_Cluster_MemberRemove_0(rctx, inboundMarshaler, server, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Cluster_MemberRemove_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Cluster_MemberUpdate_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := local_request_Cluster_MemberUpdate_0(rctx, inboundMarshaler, server, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Cluster_MemberUpdate_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Cluster_MemberList_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := local_request_Cluster_MemberList_0(rctx, inboundMarshaler, server, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Cluster_MemberList_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Cluster_MemberPromote_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := local_request_Cluster_MemberPromote_0(rctx, inboundMarshaler, server, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Cluster_MemberPromote_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - return nil -} - -// etcdserverpb.RegisterMaintenanceHandlerServer registers the http handlers for service Maintenance to "mux". -// UnaryRPC :call etcdserverpb.MaintenanceServer directly. -// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. -func RegisterMaintenanceHandlerServer(ctx context.Context, mux *runtime.ServeMux, server etcdserverpb.MaintenanceServer) error { - - mux.Handle("POST", pattern_Maintenance_Alarm_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := local_request_Maintenance_Alarm_0(rctx, inboundMarshaler, server, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Maintenance_Alarm_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Maintenance_Status_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := local_request_Maintenance_Status_0(rctx, inboundMarshaler, server, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Maintenance_Status_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Maintenance_Defragment_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := local_request_Maintenance_Defragment_0(rctx, inboundMarshaler, server, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Maintenance_Defragment_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Maintenance_Hash_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := local_request_Maintenance_Hash_0(rctx, inboundMarshaler, server, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Maintenance_Hash_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Maintenance_HashKV_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := local_request_Maintenance_HashKV_0(rctx, inboundMarshaler, server, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Maintenance_HashKV_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Maintenance_Snapshot_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - err := status.Error(codes.Unimplemented, "streaming calls are not yet supported in the in-process transport") - _, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - }) - - mux.Handle("POST", pattern_Maintenance_MoveLeader_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := local_request_Maintenance_MoveLeader_0(rctx, inboundMarshaler, server, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Maintenance_MoveLeader_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Maintenance_Downgrade_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := local_request_Maintenance_Downgrade_0(rctx, inboundMarshaler, server, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Maintenance_Downgrade_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - return nil -} - -// etcdserverpb.RegisterAuthHandlerServer registers the http handlers for service Auth to "mux". -// UnaryRPC :call etcdserverpb.AuthServer directly. -// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. -func RegisterAuthHandlerServer(ctx context.Context, mux *runtime.ServeMux, server etcdserverpb.AuthServer) error { - - mux.Handle("POST", pattern_Auth_AuthEnable_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := local_request_Auth_AuthEnable_0(rctx, inboundMarshaler, server, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Auth_AuthEnable_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Auth_AuthDisable_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := local_request_Auth_AuthDisable_0(rctx, inboundMarshaler, server, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Auth_AuthDisable_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Auth_AuthStatus_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := local_request_Auth_AuthStatus_0(rctx, inboundMarshaler, server, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Auth_AuthStatus_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Auth_Authenticate_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := local_request_Auth_Authenticate_0(rctx, inboundMarshaler, server, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Auth_Authenticate_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Auth_UserAdd_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := local_request_Auth_UserAdd_0(rctx, inboundMarshaler, server, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Auth_UserAdd_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Auth_UserGet_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := local_request_Auth_UserGet_0(rctx, inboundMarshaler, server, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Auth_UserGet_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Auth_UserList_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := local_request_Auth_UserList_0(rctx, inboundMarshaler, server, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Auth_UserList_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Auth_UserDelete_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := local_request_Auth_UserDelete_0(rctx, inboundMarshaler, server, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Auth_UserDelete_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Auth_UserChangePassword_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := local_request_Auth_UserChangePassword_0(rctx, inboundMarshaler, server, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Auth_UserChangePassword_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Auth_UserGrantRole_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := local_request_Auth_UserGrantRole_0(rctx, inboundMarshaler, server, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Auth_UserGrantRole_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Auth_UserRevokeRole_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := local_request_Auth_UserRevokeRole_0(rctx, inboundMarshaler, server, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Auth_UserRevokeRole_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Auth_RoleAdd_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := local_request_Auth_RoleAdd_0(rctx, inboundMarshaler, server, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Auth_RoleAdd_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Auth_RoleGet_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := local_request_Auth_RoleGet_0(rctx, inboundMarshaler, server, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Auth_RoleGet_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Auth_RoleList_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := local_request_Auth_RoleList_0(rctx, inboundMarshaler, server, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Auth_RoleList_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Auth_RoleDelete_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := local_request_Auth_RoleDelete_0(rctx, inboundMarshaler, server, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Auth_RoleDelete_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Auth_RoleGrantPermission_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := local_request_Auth_RoleGrantPermission_0(rctx, inboundMarshaler, server, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Auth_RoleGrantPermission_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Auth_RoleRevokePermission_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := local_request_Auth_RoleRevokePermission_0(rctx, inboundMarshaler, server, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Auth_RoleRevokePermission_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - return nil -} - -// RegisterKVHandlerFromEndpoint is same as RegisterKVHandler but -// automatically dials to "endpoint" and closes the connection when "ctx" gets done. -func RegisterKVHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { - conn, err := grpc.Dial(endpoint, opts...) - if err != nil { - return err - } - defer func() { - if err != nil { - if cerr := conn.Close(); cerr != nil { - grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) - } - return - } - go func() { - <-ctx.Done() - if cerr := conn.Close(); cerr != nil { - grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) - } - }() - }() - - return RegisterKVHandler(ctx, mux, conn) -} - -// RegisterKVHandler registers the http handlers for service KV to "mux". -// The handlers forward requests to the grpc endpoint over "conn". -func RegisterKVHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { - return RegisterKVHandlerClient(ctx, mux, etcdserverpb.NewKVClient(conn)) -} - -// etcdserverpb.RegisterKVHandlerClient registers the http handlers for service KV -// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "KVClient". -// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "KVClient" -// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in -// "KVClient" to call the correct interceptors. -func RegisterKVHandlerClient(ctx context.Context, mux *runtime.ServeMux, client etcdserverpb.KVClient) error { - - mux.Handle("POST", pattern_KV_Range_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_KV_Range_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_KV_Range_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_KV_Put_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_KV_Put_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_KV_Put_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_KV_DeleteRange_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_KV_DeleteRange_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_KV_DeleteRange_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_KV_Txn_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_KV_Txn_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_KV_Txn_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_KV_Compact_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_KV_Compact_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_KV_Compact_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - return nil -} - -var ( - pattern_KV_Range_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v3", "kv", "range"}, "", runtime.AssumeColonVerbOpt(true))) - - pattern_KV_Put_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v3", "kv", "put"}, "", runtime.AssumeColonVerbOpt(true))) - - pattern_KV_DeleteRange_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v3", "kv", "deleterange"}, "", runtime.AssumeColonVerbOpt(true))) - - pattern_KV_Txn_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v3", "kv", "txn"}, "", runtime.AssumeColonVerbOpt(true))) - - pattern_KV_Compact_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v3", "kv", "compaction"}, "", runtime.AssumeColonVerbOpt(true))) -) - -var ( - forward_KV_Range_0 = runtime.ForwardResponseMessage - - forward_KV_Put_0 = runtime.ForwardResponseMessage - - forward_KV_DeleteRange_0 = runtime.ForwardResponseMessage - - forward_KV_Txn_0 = runtime.ForwardResponseMessage - - forward_KV_Compact_0 = runtime.ForwardResponseMessage -) - -// RegisterWatchHandlerFromEndpoint is same as RegisterWatchHandler but -// automatically dials to "endpoint" and closes the connection when "ctx" gets done. -func RegisterWatchHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { - conn, err := grpc.Dial(endpoint, opts...) - if err != nil { - return err - } - defer func() { - if err != nil { - if cerr := conn.Close(); cerr != nil { - grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) - } - return - } - go func() { - <-ctx.Done() - if cerr := conn.Close(); cerr != nil { - grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) - } - }() - }() - - return RegisterWatchHandler(ctx, mux, conn) -} - -// RegisterWatchHandler registers the http handlers for service Watch to "mux". -// The handlers forward requests to the grpc endpoint over "conn". -func RegisterWatchHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { - return RegisterWatchHandlerClient(ctx, mux, etcdserverpb.NewWatchClient(conn)) -} - -// etcdserverpb.RegisterWatchHandlerClient registers the http handlers for service Watch -// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "WatchClient". -// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "WatchClient" -// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in -// "WatchClient" to call the correct interceptors. -func RegisterWatchHandlerClient(ctx context.Context, mux *runtime.ServeMux, client etcdserverpb.WatchClient) error { - - mux.Handle("POST", pattern_Watch_Watch_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Watch_Watch_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Watch_Watch_0(ctx, mux, outboundMarshaler, w, req, func() (proto.Message, error) { return resp.Recv() }, mux.GetForwardResponseOptions()...) - - }) - - return nil -} - -var ( - pattern_Watch_Watch_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v3", "watch"}, "", runtime.AssumeColonVerbOpt(true))) -) - -var ( - forward_Watch_Watch_0 = runtime.ForwardResponseStream -) - -// RegisterLeaseHandlerFromEndpoint is same as RegisterLeaseHandler but -// automatically dials to "endpoint" and closes the connection when "ctx" gets done. -func RegisterLeaseHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { - conn, err := grpc.Dial(endpoint, opts...) - if err != nil { - return err - } - defer func() { - if err != nil { - if cerr := conn.Close(); cerr != nil { - grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) - } - return - } - go func() { - <-ctx.Done() - if cerr := conn.Close(); cerr != nil { - grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) - } - }() - }() - - return RegisterLeaseHandler(ctx, mux, conn) -} - -// RegisterLeaseHandler registers the http handlers for service Lease to "mux". -// The handlers forward requests to the grpc endpoint over "conn". -func RegisterLeaseHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { - return RegisterLeaseHandlerClient(ctx, mux, etcdserverpb.NewLeaseClient(conn)) -} - -// etcdserverpb.RegisterLeaseHandlerClient registers the http handlers for service Lease -// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "LeaseClient". -// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "LeaseClient" -// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in -// "LeaseClient" to call the correct interceptors. -func RegisterLeaseHandlerClient(ctx context.Context, mux *runtime.ServeMux, client etcdserverpb.LeaseClient) error { - - mux.Handle("POST", pattern_Lease_LeaseGrant_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Lease_LeaseGrant_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Lease_LeaseGrant_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Lease_LeaseRevoke_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Lease_LeaseRevoke_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Lease_LeaseRevoke_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Lease_LeaseRevoke_1, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Lease_LeaseRevoke_1(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Lease_LeaseRevoke_1(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Lease_LeaseKeepAlive_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Lease_LeaseKeepAlive_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Lease_LeaseKeepAlive_0(ctx, mux, outboundMarshaler, w, req, func() (proto.Message, error) { return resp.Recv() }, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Lease_LeaseTimeToLive_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Lease_LeaseTimeToLive_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Lease_LeaseTimeToLive_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Lease_LeaseTimeToLive_1, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Lease_LeaseTimeToLive_1(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Lease_LeaseTimeToLive_1(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Lease_LeaseLeases_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Lease_LeaseLeases_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Lease_LeaseLeases_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Lease_LeaseLeases_1, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Lease_LeaseLeases_1(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Lease_LeaseLeases_1(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - return nil -} - -var ( - pattern_Lease_LeaseGrant_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v3", "lease", "grant"}, "", runtime.AssumeColonVerbOpt(true))) - - pattern_Lease_LeaseRevoke_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v3", "lease", "revoke"}, "", runtime.AssumeColonVerbOpt(true))) - - pattern_Lease_LeaseRevoke_1 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"v3", "kv", "lease", "revoke"}, "", runtime.AssumeColonVerbOpt(true))) - - pattern_Lease_LeaseKeepAlive_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v3", "lease", "keepalive"}, "", runtime.AssumeColonVerbOpt(true))) - - pattern_Lease_LeaseTimeToLive_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v3", "lease", "timetolive"}, "", runtime.AssumeColonVerbOpt(true))) - - pattern_Lease_LeaseTimeToLive_1 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"v3", "kv", "lease", "timetolive"}, "", runtime.AssumeColonVerbOpt(true))) - - pattern_Lease_LeaseLeases_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v3", "lease", "leases"}, "", runtime.AssumeColonVerbOpt(true))) - - pattern_Lease_LeaseLeases_1 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"v3", "kv", "lease", "leases"}, "", runtime.AssumeColonVerbOpt(true))) -) - -var ( - forward_Lease_LeaseGrant_0 = runtime.ForwardResponseMessage - - forward_Lease_LeaseRevoke_0 = runtime.ForwardResponseMessage - - forward_Lease_LeaseRevoke_1 = runtime.ForwardResponseMessage - - forward_Lease_LeaseKeepAlive_0 = runtime.ForwardResponseStream - - forward_Lease_LeaseTimeToLive_0 = runtime.ForwardResponseMessage - - forward_Lease_LeaseTimeToLive_1 = runtime.ForwardResponseMessage - - forward_Lease_LeaseLeases_0 = runtime.ForwardResponseMessage - - forward_Lease_LeaseLeases_1 = runtime.ForwardResponseMessage -) - -// RegisterClusterHandlerFromEndpoint is same as RegisterClusterHandler but -// automatically dials to "endpoint" and closes the connection when "ctx" gets done. -func RegisterClusterHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { - conn, err := grpc.Dial(endpoint, opts...) - if err != nil { - return err - } - defer func() { - if err != nil { - if cerr := conn.Close(); cerr != nil { - grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) - } - return - } - go func() { - <-ctx.Done() - if cerr := conn.Close(); cerr != nil { - grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) - } - }() - }() - - return RegisterClusterHandler(ctx, mux, conn) -} - -// RegisterClusterHandler registers the http handlers for service Cluster to "mux". -// The handlers forward requests to the grpc endpoint over "conn". -func RegisterClusterHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { - return RegisterClusterHandlerClient(ctx, mux, etcdserverpb.NewClusterClient(conn)) -} - -// etcdserverpb.RegisterClusterHandlerClient registers the http handlers for service Cluster -// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "ClusterClient". -// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "ClusterClient" -// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in -// "ClusterClient" to call the correct interceptors. -func RegisterClusterHandlerClient(ctx context.Context, mux *runtime.ServeMux, client etcdserverpb.ClusterClient) error { - - mux.Handle("POST", pattern_Cluster_MemberAdd_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Cluster_MemberAdd_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Cluster_MemberAdd_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Cluster_MemberRemove_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Cluster_MemberRemove_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Cluster_MemberRemove_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Cluster_MemberUpdate_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Cluster_MemberUpdate_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Cluster_MemberUpdate_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Cluster_MemberList_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Cluster_MemberList_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Cluster_MemberList_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Cluster_MemberPromote_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Cluster_MemberPromote_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Cluster_MemberPromote_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - return nil -} - -var ( - pattern_Cluster_MemberAdd_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"v3", "cluster", "member", "add"}, "", runtime.AssumeColonVerbOpt(true))) - - pattern_Cluster_MemberRemove_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"v3", "cluster", "member", "remove"}, "", runtime.AssumeColonVerbOpt(true))) - - pattern_Cluster_MemberUpdate_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"v3", "cluster", "member", "update"}, "", runtime.AssumeColonVerbOpt(true))) - - pattern_Cluster_MemberList_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"v3", "cluster", "member", "list"}, "", runtime.AssumeColonVerbOpt(true))) - - pattern_Cluster_MemberPromote_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"v3", "cluster", "member", "promote"}, "", runtime.AssumeColonVerbOpt(true))) -) - -var ( - forward_Cluster_MemberAdd_0 = runtime.ForwardResponseMessage - - forward_Cluster_MemberRemove_0 = runtime.ForwardResponseMessage - - forward_Cluster_MemberUpdate_0 = runtime.ForwardResponseMessage - - forward_Cluster_MemberList_0 = runtime.ForwardResponseMessage - - forward_Cluster_MemberPromote_0 = runtime.ForwardResponseMessage -) - -// RegisterMaintenanceHandlerFromEndpoint is same as RegisterMaintenanceHandler but -// automatically dials to "endpoint" and closes the connection when "ctx" gets done. -func RegisterMaintenanceHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { - conn, err := grpc.Dial(endpoint, opts...) - if err != nil { - return err - } - defer func() { - if err != nil { - if cerr := conn.Close(); cerr != nil { - grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) - } - return - } - go func() { - <-ctx.Done() - if cerr := conn.Close(); cerr != nil { - grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) - } - }() - }() - - return RegisterMaintenanceHandler(ctx, mux, conn) -} - -// RegisterMaintenanceHandler registers the http handlers for service Maintenance to "mux". -// The handlers forward requests to the grpc endpoint over "conn". -func RegisterMaintenanceHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { - return RegisterMaintenanceHandlerClient(ctx, mux, etcdserverpb.NewMaintenanceClient(conn)) -} - -// etcdserverpb.RegisterMaintenanceHandlerClient registers the http handlers for service Maintenance -// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "MaintenanceClient". -// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "MaintenanceClient" -// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in -// "MaintenanceClient" to call the correct interceptors. -func RegisterMaintenanceHandlerClient(ctx context.Context, mux *runtime.ServeMux, client etcdserverpb.MaintenanceClient) error { - - mux.Handle("POST", pattern_Maintenance_Alarm_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Maintenance_Alarm_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Maintenance_Alarm_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Maintenance_Status_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Maintenance_Status_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Maintenance_Status_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Maintenance_Defragment_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Maintenance_Defragment_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Maintenance_Defragment_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Maintenance_Hash_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Maintenance_Hash_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Maintenance_Hash_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Maintenance_HashKV_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Maintenance_HashKV_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Maintenance_HashKV_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Maintenance_Snapshot_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Maintenance_Snapshot_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Maintenance_Snapshot_0(ctx, mux, outboundMarshaler, w, req, func() (proto.Message, error) { return resp.Recv() }, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Maintenance_MoveLeader_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Maintenance_MoveLeader_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Maintenance_MoveLeader_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Maintenance_Downgrade_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Maintenance_Downgrade_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Maintenance_Downgrade_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - return nil -} - -var ( - pattern_Maintenance_Alarm_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v3", "maintenance", "alarm"}, "", runtime.AssumeColonVerbOpt(true))) - - pattern_Maintenance_Status_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v3", "maintenance", "status"}, "", runtime.AssumeColonVerbOpt(true))) - - pattern_Maintenance_Defragment_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v3", "maintenance", "defragment"}, "", runtime.AssumeColonVerbOpt(true))) - - pattern_Maintenance_Hash_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v3", "maintenance", "hash"}, "", runtime.AssumeColonVerbOpt(true))) - - pattern_Maintenance_HashKV_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v3", "maintenance", "hash"}, "", runtime.AssumeColonVerbOpt(true))) - - pattern_Maintenance_Snapshot_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v3", "maintenance", "snapshot"}, "", runtime.AssumeColonVerbOpt(true))) - - pattern_Maintenance_MoveLeader_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v3", "maintenance", "transfer-leadership"}, "", runtime.AssumeColonVerbOpt(true))) - - pattern_Maintenance_Downgrade_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v3", "maintenance", "downgrade"}, "", runtime.AssumeColonVerbOpt(true))) -) - -var ( - forward_Maintenance_Alarm_0 = runtime.ForwardResponseMessage - - forward_Maintenance_Status_0 = runtime.ForwardResponseMessage - - forward_Maintenance_Defragment_0 = runtime.ForwardResponseMessage - - forward_Maintenance_Hash_0 = runtime.ForwardResponseMessage - - forward_Maintenance_HashKV_0 = runtime.ForwardResponseMessage - - forward_Maintenance_Snapshot_0 = runtime.ForwardResponseStream - - forward_Maintenance_MoveLeader_0 = runtime.ForwardResponseMessage - - forward_Maintenance_Downgrade_0 = runtime.ForwardResponseMessage -) - -// RegisterAuthHandlerFromEndpoint is same as RegisterAuthHandler but -// automatically dials to "endpoint" and closes the connection when "ctx" gets done. -func RegisterAuthHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { - conn, err := grpc.Dial(endpoint, opts...) - if err != nil { - return err - } - defer func() { - if err != nil { - if cerr := conn.Close(); cerr != nil { - grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) - } - return - } - go func() { - <-ctx.Done() - if cerr := conn.Close(); cerr != nil { - grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) - } - }() - }() - - return RegisterAuthHandler(ctx, mux, conn) -} - -// RegisterAuthHandler registers the http handlers for service Auth to "mux". -// The handlers forward requests to the grpc endpoint over "conn". -func RegisterAuthHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { - return RegisterAuthHandlerClient(ctx, mux, etcdserverpb.NewAuthClient(conn)) -} - -// etcdserverpb.RegisterAuthHandlerClient registers the http handlers for service Auth -// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "AuthClient". -// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "AuthClient" -// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in -// "AuthClient" to call the correct interceptors. -func RegisterAuthHandlerClient(ctx context.Context, mux *runtime.ServeMux, client etcdserverpb.AuthClient) error { - - mux.Handle("POST", pattern_Auth_AuthEnable_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Auth_AuthEnable_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Auth_AuthEnable_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Auth_AuthDisable_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Auth_AuthDisable_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Auth_AuthDisable_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Auth_AuthStatus_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Auth_AuthStatus_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Auth_AuthStatus_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Auth_Authenticate_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Auth_Authenticate_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Auth_Authenticate_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Auth_UserAdd_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Auth_UserAdd_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Auth_UserAdd_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Auth_UserGet_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Auth_UserGet_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Auth_UserGet_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Auth_UserList_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Auth_UserList_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Auth_UserList_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Auth_UserDelete_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Auth_UserDelete_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Auth_UserDelete_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Auth_UserChangePassword_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Auth_UserChangePassword_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Auth_UserChangePassword_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Auth_UserGrantRole_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Auth_UserGrantRole_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Auth_UserGrantRole_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Auth_UserRevokeRole_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Auth_UserRevokeRole_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Auth_UserRevokeRole_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Auth_RoleAdd_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Auth_RoleAdd_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Auth_RoleAdd_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Auth_RoleGet_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Auth_RoleGet_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Auth_RoleGet_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Auth_RoleList_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Auth_RoleList_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Auth_RoleList_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Auth_RoleDelete_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Auth_RoleDelete_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Auth_RoleDelete_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Auth_RoleGrantPermission_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Auth_RoleGrantPermission_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Auth_RoleGrantPermission_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Auth_RoleRevokePermission_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Auth_RoleRevokePermission_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Auth_RoleRevokePermission_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - return nil -} - -var ( - pattern_Auth_AuthEnable_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v3", "auth", "enable"}, "", runtime.AssumeColonVerbOpt(true))) - - pattern_Auth_AuthDisable_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v3", "auth", "disable"}, "", runtime.AssumeColonVerbOpt(true))) - - pattern_Auth_AuthStatus_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v3", "auth", "status"}, "", runtime.AssumeColonVerbOpt(true))) - - pattern_Auth_Authenticate_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v3", "auth", "authenticate"}, "", runtime.AssumeColonVerbOpt(true))) - - pattern_Auth_UserAdd_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"v3", "auth", "user", "add"}, "", runtime.AssumeColonVerbOpt(true))) - - pattern_Auth_UserGet_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"v3", "auth", "user", "get"}, "", runtime.AssumeColonVerbOpt(true))) - - pattern_Auth_UserList_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"v3", "auth", "user", "list"}, "", runtime.AssumeColonVerbOpt(true))) - - pattern_Auth_UserDelete_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"v3", "auth", "user", "delete"}, "", runtime.AssumeColonVerbOpt(true))) - - pattern_Auth_UserChangePassword_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"v3", "auth", "user", "changepw"}, "", runtime.AssumeColonVerbOpt(true))) - - pattern_Auth_UserGrantRole_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"v3", "auth", "user", "grant"}, "", runtime.AssumeColonVerbOpt(true))) - - pattern_Auth_UserRevokeRole_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"v3", "auth", "user", "revoke"}, "", runtime.AssumeColonVerbOpt(true))) - - pattern_Auth_RoleAdd_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"v3", "auth", "role", "add"}, "", runtime.AssumeColonVerbOpt(true))) - - pattern_Auth_RoleGet_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"v3", "auth", "role", "get"}, "", runtime.AssumeColonVerbOpt(true))) - - pattern_Auth_RoleList_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"v3", "auth", "role", "list"}, "", runtime.AssumeColonVerbOpt(true))) - - pattern_Auth_RoleDelete_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"v3", "auth", "role", "delete"}, "", runtime.AssumeColonVerbOpt(true))) - - pattern_Auth_RoleGrantPermission_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"v3", "auth", "role", "grant"}, "", runtime.AssumeColonVerbOpt(true))) - - pattern_Auth_RoleRevokePermission_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"v3", "auth", "role", "revoke"}, "", runtime.AssumeColonVerbOpt(true))) -) - -var ( - forward_Auth_AuthEnable_0 = runtime.ForwardResponseMessage - - forward_Auth_AuthDisable_0 = runtime.ForwardResponseMessage - - forward_Auth_AuthStatus_0 = runtime.ForwardResponseMessage - - forward_Auth_Authenticate_0 = runtime.ForwardResponseMessage - - forward_Auth_UserAdd_0 = runtime.ForwardResponseMessage - - forward_Auth_UserGet_0 = runtime.ForwardResponseMessage - - forward_Auth_UserList_0 = runtime.ForwardResponseMessage - - forward_Auth_UserDelete_0 = runtime.ForwardResponseMessage - - forward_Auth_UserChangePassword_0 = runtime.ForwardResponseMessage - - forward_Auth_UserGrantRole_0 = runtime.ForwardResponseMessage - - forward_Auth_UserRevokeRole_0 = runtime.ForwardResponseMessage - - forward_Auth_RoleAdd_0 = runtime.ForwardResponseMessage - - forward_Auth_RoleGet_0 = runtime.ForwardResponseMessage - - forward_Auth_RoleList_0 = runtime.ForwardResponseMessage - - forward_Auth_RoleDelete_0 = runtime.ForwardResponseMessage - - forward_Auth_RoleGrantPermission_0 = runtime.ForwardResponseMessage - - forward_Auth_RoleRevokePermission_0 = runtime.ForwardResponseMessage -) diff --git a/vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/dir_unix.go b/vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/dir_unix.go deleted file mode 100644 index ca82f765c9..0000000000 --- a/vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/dir_unix.go +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -//go:build !windows -// +build !windows - -package fileutil - -import "os" - -const ( - // PrivateDirMode grants owner to make/remove files inside the directory. - PrivateDirMode = 0700 -) - -// OpenDir opens a directory for syncing. -func OpenDir(path string) (*os.File, error) { return os.Open(path) } diff --git a/vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/dir_windows.go b/vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/dir_windows.go deleted file mode 100644 index 849c63c876..0000000000 --- a/vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/dir_windows.go +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -//go:build windows -// +build windows - -package fileutil - -import ( - "os" - "syscall" -) - -const ( - // PrivateDirMode grants owner to make/remove files inside the directory. - PrivateDirMode = 0777 -) - -// OpenDir opens a directory in windows with write access for syncing. -func OpenDir(path string) (*os.File, error) { - fd, err := openDir(path) - if err != nil { - return nil, err - } - return os.NewFile(uintptr(fd), path), nil -} - -func openDir(path string) (fd syscall.Handle, err error) { - if len(path) == 0 { - return syscall.InvalidHandle, syscall.ERROR_FILE_NOT_FOUND - } - pathp, err := syscall.UTF16PtrFromString(path) - if err != nil { - return syscall.InvalidHandle, err - } - access := uint32(syscall.GENERIC_READ | syscall.GENERIC_WRITE) - sharemode := uint32(syscall.FILE_SHARE_READ | syscall.FILE_SHARE_WRITE) - createmode := uint32(syscall.OPEN_EXISTING) - fl := uint32(syscall.FILE_FLAG_BACKUP_SEMANTICS) - return syscall.CreateFile(pathp, access, sharemode, nil, createmode, fl, 0) -} diff --git a/vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/doc.go b/vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/doc.go deleted file mode 100644 index 69dde5a7dd..0000000000 --- a/vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/doc.go +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2018 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package fileutil implements utility functions related to files and paths. -package fileutil diff --git a/vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/fileutil.go b/vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/fileutil.go deleted file mode 100644 index e442c3c92e..0000000000 --- a/vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/fileutil.go +++ /dev/null @@ -1,172 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package fileutil - -import ( - "fmt" - "io" - "io/ioutil" - "os" - "path/filepath" - - "go.uber.org/zap" -) - -const ( - // PrivateFileMode grants owner to read/write a file. - PrivateFileMode = 0600 -) - -// IsDirWriteable checks if dir is writable by writing and removing a file -// to dir. It returns nil if dir is writable. -func IsDirWriteable(dir string) error { - f, err := filepath.Abs(filepath.Join(dir, ".touch")) - if err != nil { - return err - } - if err := ioutil.WriteFile(f, []byte(""), PrivateFileMode); err != nil { - return err - } - return os.Remove(f) -} - -// TouchDirAll is similar to os.MkdirAll. It creates directories with 0700 permission if any directory -// does not exists. TouchDirAll also ensures the given directory is writable. -func TouchDirAll(dir string) error { - // If path is already a directory, MkdirAll does nothing and returns nil, so, - // first check if dir exist with an expected permission mode. - if Exist(dir) { - err := CheckDirPermission(dir, PrivateDirMode) - if err != nil { - lg, _ := zap.NewProduction() - if lg == nil { - lg = zap.NewExample() - } - lg.Warn("check file permission", zap.Error(err)) - } - } else { - err := os.MkdirAll(dir, PrivateDirMode) - if err != nil { - // if mkdirAll("a/text") and "text" is not - // a directory, this will return syscall.ENOTDIR - return err - } - } - - return IsDirWriteable(dir) -} - -// CreateDirAll is similar to TouchDirAll but returns error -// if the deepest directory was not empty. -func CreateDirAll(dir string) error { - err := TouchDirAll(dir) - if err == nil { - var ns []string - ns, err = ReadDir(dir) - if err != nil { - return err - } - if len(ns) != 0 { - err = fmt.Errorf("expected %q to be empty, got %q", dir, ns) - } - } - return err -} - -// Exist returns true if a file or directory exists. -func Exist(name string) bool { - _, err := os.Stat(name) - return err == nil -} - -// DirEmpty returns true if a directory empty and can access. -func DirEmpty(name string) bool { - ns, err := ReadDir(name) - return len(ns) == 0 && err == nil -} - -// ZeroToEnd zeros a file starting from SEEK_CUR to its SEEK_END. May temporarily -// shorten the length of the file. -func ZeroToEnd(f *os.File) error { - // TODO: support FALLOC_FL_ZERO_RANGE - off, err := f.Seek(0, io.SeekCurrent) - if err != nil { - return err - } - lenf, lerr := f.Seek(0, io.SeekEnd) - if lerr != nil { - return lerr - } - if err = f.Truncate(off); err != nil { - return err - } - // make sure blocks remain allocated - if err = Preallocate(f, lenf, true); err != nil { - return err - } - _, err = f.Seek(off, io.SeekStart) - return err -} - -// CheckDirPermission checks permission on an existing dir. -// Returns error if dir is empty or exist with a different permission than specified. -func CheckDirPermission(dir string, perm os.FileMode) error { - if !Exist(dir) { - return fmt.Errorf("directory %q empty, cannot check permission", dir) - } - //check the existing permission on the directory - dirInfo, err := os.Stat(dir) - if err != nil { - return err - } - dirMode := dirInfo.Mode().Perm() - if dirMode != perm { - err = fmt.Errorf("directory %q exist, but the permission is %q. The recommended permission is %q to prevent possible unprivileged access to the data", dir, dirInfo.Mode(), os.FileMode(PrivateDirMode)) - return err - } - return nil -} - -// RemoveMatchFile deletes file if matchFunc is true on an existing dir -// Returns error if the dir does not exist or remove file fail -func RemoveMatchFile(lg *zap.Logger, dir string, matchFunc func(fileName string) bool) error { - if lg == nil { - lg = zap.NewNop() - } - if !Exist(dir) { - return fmt.Errorf("directory %s does not exist", dir) - } - fileNames, err := ReadDir(dir) - if err != nil { - return err - } - var removeFailedFiles []string - for _, fileName := range fileNames { - if matchFunc(fileName) { - file := filepath.Join(dir, fileName) - if err = os.Remove(file); err != nil { - removeFailedFiles = append(removeFailedFiles, fileName) - lg.Error("remove file failed", - zap.String("file", file), - zap.Error(err)) - continue - } - } - } - if len(removeFailedFiles) != 0 { - return fmt.Errorf("remove file(s) %v error", removeFailedFiles) - } - return nil -} diff --git a/vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/lock.go b/vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/lock.go deleted file mode 100644 index 338627f43c..0000000000 --- a/vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/lock.go +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package fileutil - -import ( - "errors" - "os" -) - -var ( - ErrLocked = errors.New("fileutil: file already locked") -) - -type LockedFile struct{ *os.File } diff --git a/vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/lock_flock.go b/vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/lock_flock.go deleted file mode 100644 index dcdf226cdb..0000000000 --- a/vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/lock_flock.go +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -//go:build !windows && !plan9 && !solaris -// +build !windows,!plan9,!solaris - -package fileutil - -import ( - "os" - "syscall" -) - -func flockTryLockFile(path string, flag int, perm os.FileMode) (*LockedFile, error) { - f, err := os.OpenFile(path, flag, perm) - if err != nil { - return nil, err - } - if err = syscall.Flock(int(f.Fd()), syscall.LOCK_EX|syscall.LOCK_NB); err != nil { - f.Close() - if err == syscall.EWOULDBLOCK { - err = ErrLocked - } - return nil, err - } - return &LockedFile{f}, nil -} - -func flockLockFile(path string, flag int, perm os.FileMode) (*LockedFile, error) { - f, err := os.OpenFile(path, flag, perm) - if err != nil { - return nil, err - } - if err = syscall.Flock(int(f.Fd()), syscall.LOCK_EX); err != nil { - f.Close() - return nil, err - } - return &LockedFile{f}, err -} diff --git a/vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/lock_linux.go b/vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/lock_linux.go deleted file mode 100644 index d8952cc481..0000000000 --- a/vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/lock_linux.go +++ /dev/null @@ -1,93 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -//go:build linux -// +build linux - -package fileutil - -import ( - "fmt" - "io" - "os" - "syscall" - - "golang.org/x/sys/unix" -) - -// This used to call syscall.Flock() but that call fails with EBADF on NFS. -// An alternative is lockf() which works on NFS but that call lets a process lock -// the same file twice. Instead, use Linux's non-standard open file descriptor -// locks which will block if the process already holds the file lock. - -var ( - wrlck = syscall.Flock_t{ - Type: syscall.F_WRLCK, - Whence: int16(io.SeekStart), - Start: 0, - Len: 0, - } - - linuxTryLockFile = flockTryLockFile - linuxLockFile = flockLockFile -) - -func init() { - // use open file descriptor locks if the system supports it - getlk := syscall.Flock_t{Type: syscall.F_RDLCK} - if err := syscall.FcntlFlock(0, unix.F_OFD_GETLK, &getlk); err == nil { - linuxTryLockFile = ofdTryLockFile - linuxLockFile = ofdLockFile - } -} - -func TryLockFile(path string, flag int, perm os.FileMode) (*LockedFile, error) { - return linuxTryLockFile(path, flag, perm) -} - -func ofdTryLockFile(path string, flag int, perm os.FileMode) (*LockedFile, error) { - f, err := os.OpenFile(path, flag, perm) - if err != nil { - return nil, fmt.Errorf("ofdTryLockFile failed to open %q (%v)", path, err) - } - - flock := wrlck - if err = syscall.FcntlFlock(f.Fd(), unix.F_OFD_SETLK, &flock); err != nil { - f.Close() - if err == syscall.EWOULDBLOCK { - err = ErrLocked - } - return nil, err - } - return &LockedFile{f}, nil -} - -func LockFile(path string, flag int, perm os.FileMode) (*LockedFile, error) { - return linuxLockFile(path, flag, perm) -} - -func ofdLockFile(path string, flag int, perm os.FileMode) (*LockedFile, error) { - f, err := os.OpenFile(path, flag, perm) - if err != nil { - return nil, fmt.Errorf("ofdLockFile failed to open %q (%v)", path, err) - } - - flock := wrlck - err = syscall.FcntlFlock(f.Fd(), unix.F_OFD_SETLKW, &flock) - if err != nil { - f.Close() - return nil, err - } - return &LockedFile{f}, nil -} diff --git a/vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/lock_plan9.go b/vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/lock_plan9.go deleted file mode 100644 index fee6a7c8f4..0000000000 --- a/vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/lock_plan9.go +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package fileutil - -import ( - "os" - "syscall" - "time" -) - -func TryLockFile(path string, flag int, perm os.FileMode) (*LockedFile, error) { - if err := os.Chmod(path, syscall.DMEXCL|PrivateFileMode); err != nil { - return nil, err - } - f, err := os.Open(path, flag, perm) - if err != nil { - return nil, ErrLocked - } - return &LockedFile{f}, nil -} - -func LockFile(path string, flag int, perm os.FileMode) (*LockedFile, error) { - if err := os.Chmod(path, syscall.DMEXCL|PrivateFileMode); err != nil { - return nil, err - } - for { - f, err := os.OpenFile(path, flag, perm) - if err == nil { - return &LockedFile{f}, nil - } - time.Sleep(10 * time.Millisecond) - } -} diff --git a/vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/lock_solaris.go b/vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/lock_solaris.go deleted file mode 100644 index 683cc1db9c..0000000000 --- a/vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/lock_solaris.go +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -//go:build solaris -// +build solaris - -package fileutil - -import ( - "os" - "syscall" -) - -func TryLockFile(path string, flag int, perm os.FileMode) (*LockedFile, error) { - var lock syscall.Flock_t - lock.Start = 0 - lock.Len = 0 - lock.Pid = 0 - lock.Type = syscall.F_WRLCK - lock.Whence = 0 - lock.Pid = 0 - f, err := os.OpenFile(path, flag, perm) - if err != nil { - return nil, err - } - if err := syscall.FcntlFlock(f.Fd(), syscall.F_SETLK, &lock); err != nil { - f.Close() - if err == syscall.EAGAIN { - err = ErrLocked - } - return nil, err - } - return &LockedFile{f}, nil -} - -func LockFile(path string, flag int, perm os.FileMode) (*LockedFile, error) { - var lock syscall.Flock_t - lock.Start = 0 - lock.Len = 0 - lock.Pid = 0 - lock.Type = syscall.F_WRLCK - lock.Whence = 0 - f, err := os.OpenFile(path, flag, perm) - if err != nil { - return nil, err - } - if err = syscall.FcntlFlock(f.Fd(), syscall.F_SETLKW, &lock); err != nil { - f.Close() - return nil, err - } - return &LockedFile{f}, nil -} diff --git a/vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/lock_unix.go b/vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/lock_unix.go deleted file mode 100644 index d89027e1fa..0000000000 --- a/vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/lock_unix.go +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -//go:build !windows && !plan9 && !solaris && !linux -// +build !windows,!plan9,!solaris,!linux - -package fileutil - -import ( - "os" -) - -func TryLockFile(path string, flag int, perm os.FileMode) (*LockedFile, error) { - return flockTryLockFile(path, flag, perm) -} - -func LockFile(path string, flag int, perm os.FileMode) (*LockedFile, error) { - return flockLockFile(path, flag, perm) -} diff --git a/vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/lock_windows.go b/vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/lock_windows.go deleted file mode 100644 index 5cbf2bc3d5..0000000000 --- a/vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/lock_windows.go +++ /dev/null @@ -1,126 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -//go:build windows -// +build windows - -package fileutil - -import ( - "errors" - "fmt" - "os" - "syscall" - "unsafe" -) - -var ( - modkernel32 = syscall.NewLazyDLL("kernel32.dll") - procLockFileEx = modkernel32.NewProc("LockFileEx") - - errLocked = errors.New("the process cannot access the file because another process has locked a portion of the file") -) - -const ( - // https://msdn.microsoft.com/en-us/library/windows/desktop/aa365203(v=vs.85).aspx - LOCKFILE_EXCLUSIVE_LOCK = 2 - LOCKFILE_FAIL_IMMEDIATELY = 1 - - // see https://msdn.microsoft.com/en-us/library/windows/desktop/ms681382(v=vs.85).aspx - errLockViolation syscall.Errno = 0x21 -) - -func TryLockFile(path string, flag int, perm os.FileMode) (*LockedFile, error) { - f, err := open(path, flag, perm) - if err != nil { - return nil, err - } - if err := lockFile(syscall.Handle(f.Fd()), LOCKFILE_FAIL_IMMEDIATELY); err != nil { - f.Close() - return nil, err - } - return &LockedFile{f}, nil -} - -func LockFile(path string, flag int, perm os.FileMode) (*LockedFile, error) { - f, err := open(path, flag, perm) - if err != nil { - return nil, err - } - if err := lockFile(syscall.Handle(f.Fd()), 0); err != nil { - f.Close() - return nil, err - } - return &LockedFile{f}, nil -} - -func open(path string, flag int, perm os.FileMode) (*os.File, error) { - if path == "" { - return nil, fmt.Errorf("cannot open empty filename") - } - var access uint32 - switch flag { - case syscall.O_RDONLY: - access = syscall.GENERIC_READ - case syscall.O_WRONLY: - access = syscall.GENERIC_WRITE - case syscall.O_RDWR: - access = syscall.GENERIC_READ | syscall.GENERIC_WRITE - case syscall.O_WRONLY | syscall.O_CREAT: - access = syscall.GENERIC_ALL - default: - panic(fmt.Errorf("flag %v is not supported", flag)) - } - fd, err := syscall.CreateFile(&(syscall.StringToUTF16(path)[0]), - access, - syscall.FILE_SHARE_READ|syscall.FILE_SHARE_WRITE|syscall.FILE_SHARE_DELETE, - nil, - syscall.OPEN_ALWAYS, - syscall.FILE_ATTRIBUTE_NORMAL, - 0) - if err != nil { - return nil, err - } - return os.NewFile(uintptr(fd), path), nil -} - -func lockFile(fd syscall.Handle, flags uint32) error { - var flag uint32 = LOCKFILE_EXCLUSIVE_LOCK - flag |= flags - if fd == syscall.InvalidHandle { - return nil - } - err := lockFileEx(fd, flag, 1, 0, &syscall.Overlapped{}) - if err == nil { - return nil - } else if err.Error() == errLocked.Error() { - return ErrLocked - } else if err != errLockViolation { - return err - } - return nil -} - -func lockFileEx(h syscall.Handle, flags, locklow, lockhigh uint32, ol *syscall.Overlapped) (err error) { - var reserved uint32 = 0 - r1, _, e1 := syscall.Syscall6(procLockFileEx.Addr(), 6, uintptr(h), uintptr(flags), uintptr(reserved), uintptr(locklow), uintptr(lockhigh), uintptr(unsafe.Pointer(ol))) - if r1 == 0 { - if e1 != 0 { - err = error(e1) - } else { - err = syscall.EINVAL - } - } - return err -} diff --git a/vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/preallocate.go b/vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/preallocate.go deleted file mode 100644 index c747b7cf81..0000000000 --- a/vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/preallocate.go +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package fileutil - -import ( - "io" - "os" -) - -// Preallocate tries to allocate the space for given -// file. This operation is only supported on linux by a -// few filesystems (btrfs, ext4, etc.). -// If the operation is unsupported, no error will be returned. -// Otherwise, the error encountered will be returned. -func Preallocate(f *os.File, sizeInBytes int64, extendFile bool) error { - if sizeInBytes == 0 { - // fallocate will return EINVAL if length is 0; skip - return nil - } - if extendFile { - return preallocExtend(f, sizeInBytes) - } - return preallocFixed(f, sizeInBytes) -} - -func preallocExtendTrunc(f *os.File, sizeInBytes int64) error { - curOff, err := f.Seek(0, io.SeekCurrent) - if err != nil { - return err - } - size, err := f.Seek(sizeInBytes, io.SeekEnd) - if err != nil { - return err - } - if _, err = f.Seek(curOff, io.SeekStart); err != nil { - return err - } - if sizeInBytes > size { - return nil - } - return f.Truncate(sizeInBytes) -} diff --git a/vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/preallocate_darwin.go b/vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/preallocate_darwin.go deleted file mode 100644 index caab143dd3..0000000000 --- a/vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/preallocate_darwin.go +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -//go:build darwin -// +build darwin - -package fileutil - -import ( - "os" - "syscall" - - "golang.org/x/sys/unix" -) - -func preallocExtend(f *os.File, sizeInBytes int64) error { - if err := preallocFixed(f, sizeInBytes); err != nil { - return err - } - return preallocExtendTrunc(f, sizeInBytes) -} - -func preallocFixed(f *os.File, sizeInBytes int64) error { - // allocate all requested space or no space at all - // TODO: allocate contiguous space on disk with F_ALLOCATECONTIG flag - fstore := &unix.Fstore_t{ - Flags: unix.F_ALLOCATEALL, - Posmode: unix.F_PEOFPOSMODE, - Length: sizeInBytes, - } - err := unix.FcntlFstore(f.Fd(), unix.F_PREALLOCATE, fstore) - if err == nil || err == unix.ENOTSUP { - return nil - } - - // wrong argument to fallocate syscall - if err == unix.EINVAL { - // filesystem "st_blocks" are allocated in the units of - // "Allocation Block Size" (run "diskutil info /" command) - var stat syscall.Stat_t - syscall.Fstat(int(f.Fd()), &stat) - - // syscall.Statfs_t.Bsize is "optimal transfer block size" - // and contains matching 4096 value when latest OS X kernel - // supports 4,096 KB filesystem block size - var statfs syscall.Statfs_t - syscall.Fstatfs(int(f.Fd()), &statfs) - blockSize := int64(statfs.Bsize) - - if stat.Blocks*blockSize >= sizeInBytes { - // enough blocks are already allocated - return nil - } - } - return err -} diff --git a/vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/preallocate_unix.go b/vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/preallocate_unix.go deleted file mode 100644 index ebb8207c34..0000000000 --- a/vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/preallocate_unix.go +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -//go:build linux -// +build linux - -package fileutil - -import ( - "os" - "syscall" -) - -func preallocExtend(f *os.File, sizeInBytes int64) error { - // use mode = 0 to change size - err := syscall.Fallocate(int(f.Fd()), 0, 0, sizeInBytes) - if err != nil { - errno, ok := err.(syscall.Errno) - // not supported; fallback - // fallocate EINTRs frequently in some environments; fallback - if ok && (errno == syscall.ENOTSUP || errno == syscall.EINTR) { - return preallocExtendTrunc(f, sizeInBytes) - } - } - return err -} - -func preallocFixed(f *os.File, sizeInBytes int64) error { - // use mode = 1 to keep size; see FALLOC_FL_KEEP_SIZE - err := syscall.Fallocate(int(f.Fd()), 1, 0, sizeInBytes) - if err != nil { - errno, ok := err.(syscall.Errno) - // treat not supported as nil error - if ok && errno == syscall.ENOTSUP { - return nil - } - } - return err -} diff --git a/vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/preallocate_unsupported.go b/vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/preallocate_unsupported.go deleted file mode 100644 index 2c46dd4907..0000000000 --- a/vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/preallocate_unsupported.go +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -//go:build !linux && !darwin -// +build !linux,!darwin - -package fileutil - -import "os" - -func preallocExtend(f *os.File, sizeInBytes int64) error { - return preallocExtendTrunc(f, sizeInBytes) -} - -func preallocFixed(f *os.File, sizeInBytes int64) error { return nil } diff --git a/vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/purge.go b/vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/purge.go deleted file mode 100644 index e8ac0ca6f5..0000000000 --- a/vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/purge.go +++ /dev/null @@ -1,93 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package fileutil - -import ( - "os" - "path/filepath" - "sort" - "strings" - "time" - - "go.uber.org/zap" -) - -func PurgeFile(lg *zap.Logger, dirname string, suffix string, max uint, interval time.Duration, stop <-chan struct{}) <-chan error { - return purgeFile(lg, dirname, suffix, max, interval, stop, nil, nil) -} - -func PurgeFileWithDoneNotify(lg *zap.Logger, dirname string, suffix string, max uint, interval time.Duration, stop <-chan struct{}) (<-chan struct{}, <-chan error) { - doneC := make(chan struct{}) - errC := purgeFile(lg, dirname, suffix, max, interval, stop, nil, doneC) - return doneC, errC -} - -// purgeFile is the internal implementation for PurgeFile which can post purged files to purgec if non-nil. -// if donec is non-nil, the function closes it to notify its exit. -func purgeFile(lg *zap.Logger, dirname string, suffix string, max uint, interval time.Duration, stop <-chan struct{}, purgec chan<- string, donec chan<- struct{}) <-chan error { - if lg == nil { - lg = zap.NewNop() - } - errC := make(chan error, 1) - go func() { - if donec != nil { - defer close(donec) - } - for { - fnames, err := ReadDir(dirname) - if err != nil { - errC <- err - return - } - newfnames := make([]string, 0) - for _, fname := range fnames { - if strings.HasSuffix(fname, suffix) { - newfnames = append(newfnames, fname) - } - } - sort.Strings(newfnames) - fnames = newfnames - for len(newfnames) > int(max) { - f := filepath.Join(dirname, newfnames[0]) - l, err := TryLockFile(f, os.O_WRONLY, PrivateFileMode) - if err != nil { - break - } - if err = os.Remove(f); err != nil { - errC <- err - return - } - if err = l.Close(); err != nil { - lg.Warn("failed to unlock/close", zap.String("path", l.Name()), zap.Error(err)) - errC <- err - return - } - lg.Info("purged", zap.String("path", f)) - newfnames = newfnames[1:] - } - if purgec != nil { - for i := 0; i < len(fnames)-len(newfnames); i++ { - purgec <- fnames[i] - } - } - select { - case <-time.After(interval): - case <-stop: - return - } - } - }() - return errC -} diff --git a/vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/read_dir.go b/vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/read_dir.go deleted file mode 100644 index 2eeaa89bc0..0000000000 --- a/vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/read_dir.go +++ /dev/null @@ -1,70 +0,0 @@ -// Copyright 2018 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package fileutil - -import ( - "os" - "path/filepath" - "sort" -) - -// ReadDirOp represents an read-directory operation. -type ReadDirOp struct { - ext string -} - -// ReadDirOption configures archiver operations. -type ReadDirOption func(*ReadDirOp) - -// WithExt filters file names by their extensions. -// (e.g. WithExt(".wal") to list only WAL files) -func WithExt(ext string) ReadDirOption { - return func(op *ReadDirOp) { op.ext = ext } -} - -func (op *ReadDirOp) applyOpts(opts []ReadDirOption) { - for _, opt := range opts { - opt(op) - } -} - -// ReadDir returns the filenames in the given directory in sorted order. -func ReadDir(d string, opts ...ReadDirOption) ([]string, error) { - op := &ReadDirOp{} - op.applyOpts(opts) - - dir, err := os.Open(d) - if err != nil { - return nil, err - } - defer dir.Close() - - names, err := dir.Readdirnames(-1) - if err != nil { - return nil, err - } - sort.Strings(names) - - if op.ext != "" { - tss := make([]string, 0) - for _, v := range names { - if filepath.Ext(v) == op.ext { - tss = append(tss, v) - } - } - names = tss - } - return names, nil -} diff --git a/vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/sync.go b/vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/sync.go deleted file mode 100644 index 0a0855309e..0000000000 --- a/vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/sync.go +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -//go:build !linux && !darwin -// +build !linux,!darwin - -package fileutil - -import "os" - -// Fsync is a wrapper around file.Sync(). Special handling is needed on darwin platform. -func Fsync(f *os.File) error { - return f.Sync() -} - -// Fdatasync is a wrapper around file.Sync(). Special handling is needed on linux platform. -func Fdatasync(f *os.File) error { - return f.Sync() -} diff --git a/vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/sync_darwin.go b/vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/sync_darwin.go deleted file mode 100644 index 1923b276ea..0000000000 --- a/vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/sync_darwin.go +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -//go:build darwin -// +build darwin - -package fileutil - -import ( - "os" - - "golang.org/x/sys/unix" -) - -// Fsync on HFS/OSX flushes the data on to the physical drive but the drive -// may not write it to the persistent media for quite sometime and it may be -// written in out-of-order sequence. Using F_FULLFSYNC ensures that the -// physical drive's buffer will also get flushed to the media. -func Fsync(f *os.File) error { - _, err := unix.FcntlInt(f.Fd(), unix.F_FULLFSYNC, 0) - return err -} - -// Fdatasync on darwin platform invokes fcntl(F_FULLFSYNC) for actual persistence -// on physical drive media. -func Fdatasync(f *os.File) error { - return Fsync(f) -} diff --git a/vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/sync_linux.go b/vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/sync_linux.go deleted file mode 100644 index b9398c23f9..0000000000 --- a/vendor/go.etcd.io/etcd/client/pkg/v3/fileutil/sync_linux.go +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -//go:build linux -// +build linux - -package fileutil - -import ( - "os" - "syscall" -) - -// Fsync is a wrapper around file.Sync(). Special handling is needed on darwin platform. -func Fsync(f *os.File) error { - return f.Sync() -} - -// Fdatasync is similar to fsync(), but does not flush modified metadata -// unless that metadata is needed in order to allow a subsequent data retrieval -// to be correctly handled. -func Fdatasync(f *os.File) error { - return syscall.Fdatasync(int(f.Fd())) -} diff --git a/vendor/go.etcd.io/etcd/client/pkg/v3/pathutil/path.go b/vendor/go.etcd.io/etcd/client/pkg/v3/pathutil/path.go deleted file mode 100644 index f26254ba93..0000000000 --- a/vendor/go.etcd.io/etcd/client/pkg/v3/pathutil/path.go +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright 2009 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// Package pathutil implements utility functions for handling slash-separated -// paths. -package pathutil - -import "path" - -// CanonicalURLPath returns the canonical url path for p, which follows the rules: -// 1. the path always starts with "/" -// 2. replace multiple slashes with a single slash -// 3. replace each '.' '..' path name element with equivalent one -// 4. keep the trailing slash -// The function is borrowed from stdlib http.cleanPath in server.go. -func CanonicalURLPath(p string) string { - if p == "" { - return "/" - } - if p[0] != '/' { - p = "/" + p - } - np := path.Clean(p) - // path.Clean removes trailing slash except for root, - // put the trailing slash back if necessary. - if p[len(p)-1] == '/' && np != "/" { - np += "/" - } - return np -} diff --git a/vendor/go.etcd.io/etcd/client/pkg/v3/srv/srv.go b/vendor/go.etcd.io/etcd/client/pkg/v3/srv/srv.go deleted file mode 100644 index 948c683490..0000000000 --- a/vendor/go.etcd.io/etcd/client/pkg/v3/srv/srv.go +++ /dev/null @@ -1,142 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package srv looks up DNS SRV records. -package srv - -import ( - "fmt" - "net" - "net/url" - "strings" - - "go.etcd.io/etcd/client/pkg/v3/types" -) - -var ( - // indirection for testing - lookupSRV = net.LookupSRV // net.DefaultResolver.LookupSRV when ctxs don't conflict - resolveTCPAddr = net.ResolveTCPAddr -) - -// GetCluster gets the cluster information via DNS discovery. -// Also sees each entry as a separate instance. -func GetCluster(serviceScheme, service, name, dns string, apurls types.URLs) ([]string, error) { - tempName := int(0) - tcp2ap := make(map[string]url.URL) - - // First, resolve the apurls - for _, url := range apurls { - tcpAddr, err := resolveTCPAddr("tcp", url.Host) - if err != nil { - return nil, err - } - tcp2ap[tcpAddr.String()] = url - } - - stringParts := []string{} - updateNodeMap := func(service, scheme string) error { - _, addrs, err := lookupSRV(service, "tcp", dns) - if err != nil { - return err - } - for _, srv := range addrs { - port := fmt.Sprintf("%d", srv.Port) - host := net.JoinHostPort(srv.Target, port) - tcpAddr, terr := resolveTCPAddr("tcp", host) - if terr != nil { - err = terr - continue - } - n := "" - url, ok := tcp2ap[tcpAddr.String()] - if ok { - n = name - } - if n == "" { - n = fmt.Sprintf("%d", tempName) - tempName++ - } - // SRV records have a trailing dot but URL shouldn't. - shortHost := strings.TrimSuffix(srv.Target, ".") - urlHost := net.JoinHostPort(shortHost, port) - if ok && url.Scheme != scheme { - err = fmt.Errorf("bootstrap at %s from DNS for %s has scheme mismatch with expected peer %s", scheme+"://"+urlHost, service, url.String()) - } else { - stringParts = append(stringParts, fmt.Sprintf("%s=%s://%s", n, scheme, urlHost)) - } - } - if len(stringParts) == 0 { - return err - } - return nil - } - - err := updateNodeMap(service, serviceScheme) - if err != nil { - return nil, fmt.Errorf("error querying DNS SRV records for _%s %s", service, err) - } - return stringParts, nil -} - -type SRVClients struct { - Endpoints []string - SRVs []*net.SRV -} - -// GetClient looks up the client endpoints for a service and domain. -func GetClient(service, domain string, serviceName string) (*SRVClients, error) { - var urls []*url.URL - var srvs []*net.SRV - - updateURLs := func(service, scheme string) error { - _, addrs, err := lookupSRV(service, "tcp", domain) - if err != nil { - return err - } - for _, srv := range addrs { - urls = append(urls, &url.URL{ - Scheme: scheme, - Host: net.JoinHostPort(srv.Target, fmt.Sprintf("%d", srv.Port)), - }) - } - srvs = append(srvs, addrs...) - return nil - } - - errHTTPS := updateURLs(GetSRVService(service, serviceName, "https"), "https") - errHTTP := updateURLs(GetSRVService(service, serviceName, "http"), "http") - - if errHTTPS != nil && errHTTP != nil { - return nil, fmt.Errorf("dns lookup errors: %s and %s", errHTTPS, errHTTP) - } - - endpoints := make([]string, len(urls)) - for i := range urls { - endpoints[i] = urls[i].String() - } - return &SRVClients{Endpoints: endpoints, SRVs: srvs}, nil -} - -// GetSRVService generates a SRV service including an optional suffix. -func GetSRVService(service, serviceName string, scheme string) (SRVService string) { - if scheme == "https" { - service = fmt.Sprintf("%s-ssl", service) - } - - if serviceName != "" { - return fmt.Sprintf("%s-%s", service, serviceName) - } - return service -} diff --git a/vendor/go.etcd.io/etcd/client/pkg/v3/tlsutil/cipher_suites.go b/vendor/go.etcd.io/etcd/client/pkg/v3/tlsutil/cipher_suites.go deleted file mode 100644 index f278a61f8a..0000000000 --- a/vendor/go.etcd.io/etcd/client/pkg/v3/tlsutil/cipher_suites.go +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright 2018 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package tlsutil - -import "crypto/tls" - -// GetCipherSuite returns the corresponding cipher suite, -// and boolean value if it is supported. -func GetCipherSuite(s string) (uint16, bool) { - for _, c := range tls.CipherSuites() { - if s == c.Name { - return c.ID, true - } - } - for _, c := range tls.InsecureCipherSuites() { - if s == c.Name { - return c.ID, true - } - } - switch s { - case "TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305": - return tls.TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256, true - case "TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305": - return tls.TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256, true - } - return 0, false -} diff --git a/vendor/go.etcd.io/etcd/client/pkg/v3/tlsutil/doc.go b/vendor/go.etcd.io/etcd/client/pkg/v3/tlsutil/doc.go deleted file mode 100644 index 3b6aa670ba..0000000000 --- a/vendor/go.etcd.io/etcd/client/pkg/v3/tlsutil/doc.go +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package tlsutil provides utility functions for handling TLS. -package tlsutil diff --git a/vendor/go.etcd.io/etcd/client/pkg/v3/tlsutil/tlsutil.go b/vendor/go.etcd.io/etcd/client/pkg/v3/tlsutil/tlsutil.go deleted file mode 100644 index 3a5aef089a..0000000000 --- a/vendor/go.etcd.io/etcd/client/pkg/v3/tlsutil/tlsutil.go +++ /dev/null @@ -1,73 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package tlsutil - -import ( - "crypto/tls" - "crypto/x509" - "encoding/pem" - "io/ioutil" -) - -// NewCertPool creates x509 certPool with provided CA files. -func NewCertPool(CAFiles []string) (*x509.CertPool, error) { - certPool := x509.NewCertPool() - - for _, CAFile := range CAFiles { - pemByte, err := ioutil.ReadFile(CAFile) - if err != nil { - return nil, err - } - - for { - var block *pem.Block - block, pemByte = pem.Decode(pemByte) - if block == nil { - break - } - cert, err := x509.ParseCertificate(block.Bytes) - if err != nil { - return nil, err - } - - certPool.AddCert(cert) - } - } - - return certPool, nil -} - -// NewCert generates TLS cert by using the given cert,key and parse function. -func NewCert(certfile, keyfile string, parseFunc func([]byte, []byte) (tls.Certificate, error)) (*tls.Certificate, error) { - cert, err := ioutil.ReadFile(certfile) - if err != nil { - return nil, err - } - - key, err := ioutil.ReadFile(keyfile) - if err != nil { - return nil, err - } - - if parseFunc == nil { - parseFunc = tls.X509KeyPair - } - - tlsCert, err := parseFunc(cert, key) - if err != nil { - return nil, err - } - return &tlsCert, nil -} diff --git a/vendor/go.etcd.io/etcd/client/pkg/v3/transport/doc.go b/vendor/go.etcd.io/etcd/client/pkg/v3/transport/doc.go deleted file mode 100644 index 37658ce591..0000000000 --- a/vendor/go.etcd.io/etcd/client/pkg/v3/transport/doc.go +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package transport implements various HTTP transport utilities based on Go -// net package. -package transport diff --git a/vendor/go.etcd.io/etcd/client/pkg/v3/transport/keepalive_listener.go b/vendor/go.etcd.io/etcd/client/pkg/v3/transport/keepalive_listener.go deleted file mode 100644 index 4ff8e7f001..0000000000 --- a/vendor/go.etcd.io/etcd/client/pkg/v3/transport/keepalive_listener.go +++ /dev/null @@ -1,94 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package transport - -import ( - "crypto/tls" - "fmt" - "net" - "time" -) - -type keepAliveConn interface { - SetKeepAlive(bool) error - SetKeepAlivePeriod(d time.Duration) error -} - -// NewKeepAliveListener returns a listener that listens on the given address. -// Be careful when wrap around KeepAliveListener with another Listener if TLSInfo is not nil. -// Some pkgs (like go/http) might expect Listener to return TLSConn type to start TLS handshake. -// http://tldp.org/HOWTO/TCP-Keepalive-HOWTO/overview.html -func NewKeepAliveListener(l net.Listener, scheme string, tlscfg *tls.Config) (net.Listener, error) { - if scheme == "https" { - if tlscfg == nil { - return nil, fmt.Errorf("cannot listen on TLS for given listener: KeyFile and CertFile are not presented") - } - return newTLSKeepaliveListener(l, tlscfg), nil - } - - return &keepaliveListener{ - Listener: l, - }, nil -} - -type keepaliveListener struct{ net.Listener } - -func (kln *keepaliveListener) Accept() (net.Conn, error) { - c, err := kln.Listener.Accept() - if err != nil { - return nil, err - } - kac := c.(keepAliveConn) - // detection time: tcp_keepalive_time + tcp_keepalive_probes + tcp_keepalive_intvl - // default on linux: 30 + 8 * 30 - // default on osx: 30 + 8 * 75 - kac.SetKeepAlive(true) - kac.SetKeepAlivePeriod(30 * time.Second) - return c, nil -} - -// A tlsKeepaliveListener implements a network listener (net.Listener) for TLS connections. -type tlsKeepaliveListener struct { - net.Listener - config *tls.Config -} - -// Accept waits for and returns the next incoming TLS connection. -// The returned connection c is a *tls.Conn. -func (l *tlsKeepaliveListener) Accept() (c net.Conn, err error) { - c, err = l.Listener.Accept() - if err != nil { - return - } - kac := c.(keepAliveConn) - // detection time: tcp_keepalive_time + tcp_keepalive_probes + tcp_keepalive_intvl - // default on linux: 30 + 8 * 30 - // default on osx: 30 + 8 * 75 - kac.SetKeepAlive(true) - kac.SetKeepAlivePeriod(30 * time.Second) - c = tls.Server(c, l.config) - return c, nil -} - -// NewListener creates a Listener which accepts connections from an inner -// Listener and wraps each connection with Server. -// The configuration config must be non-nil and must have -// at least one certificate. -func newTLSKeepaliveListener(inner net.Listener, config *tls.Config) net.Listener { - l := &tlsKeepaliveListener{} - l.Listener = inner - l.config = config - return l -} diff --git a/vendor/go.etcd.io/etcd/client/pkg/v3/transport/limit_listen.go b/vendor/go.etcd.io/etcd/client/pkg/v3/transport/limit_listen.go deleted file mode 100644 index 930c542066..0000000000 --- a/vendor/go.etcd.io/etcd/client/pkg/v3/transport/limit_listen.go +++ /dev/null @@ -1,80 +0,0 @@ -// Copyright 2013 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package transport provides network utility functions, complementing the more -// common ones in the net package. -package transport - -import ( - "errors" - "net" - "sync" - "time" -) - -var ( - ErrNotTCP = errors.New("only tcp connections have keepalive") -) - -// LimitListener returns a Listener that accepts at most n simultaneous -// connections from the provided Listener. -func LimitListener(l net.Listener, n int) net.Listener { - return &limitListener{l, make(chan struct{}, n)} -} - -type limitListener struct { - net.Listener - sem chan struct{} -} - -func (l *limitListener) acquire() { l.sem <- struct{}{} } -func (l *limitListener) release() { <-l.sem } - -func (l *limitListener) Accept() (net.Conn, error) { - l.acquire() - c, err := l.Listener.Accept() - if err != nil { - l.release() - return nil, err - } - return &limitListenerConn{Conn: c, release: l.release}, nil -} - -type limitListenerConn struct { - net.Conn - releaseOnce sync.Once - release func() -} - -func (l *limitListenerConn) Close() error { - err := l.Conn.Close() - l.releaseOnce.Do(l.release) - return err -} - -func (l *limitListenerConn) SetKeepAlive(doKeepAlive bool) error { - tcpc, ok := l.Conn.(*net.TCPConn) - if !ok { - return ErrNotTCP - } - return tcpc.SetKeepAlive(doKeepAlive) -} - -func (l *limitListenerConn) SetKeepAlivePeriod(d time.Duration) error { - tcpc, ok := l.Conn.(*net.TCPConn) - if !ok { - return ErrNotTCP - } - return tcpc.SetKeepAlivePeriod(d) -} diff --git a/vendor/go.etcd.io/etcd/client/pkg/v3/transport/listener.go b/vendor/go.etcd.io/etcd/client/pkg/v3/transport/listener.go deleted file mode 100644 index 992c773eaa..0000000000 --- a/vendor/go.etcd.io/etcd/client/pkg/v3/transport/listener.go +++ /dev/null @@ -1,574 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package transport - -import ( - "context" - "crypto/ecdsa" - "crypto/elliptic" - "crypto/rand" - "crypto/tls" - "crypto/x509" - "crypto/x509/pkix" - "encoding/pem" - "errors" - "fmt" - "math/big" - "net" - "os" - "path/filepath" - "strings" - "time" - - "go.etcd.io/etcd/client/pkg/v3/fileutil" - "go.etcd.io/etcd/client/pkg/v3/tlsutil" - - "go.uber.org/zap" -) - -// NewListener creates a new listner. -func NewListener(addr, scheme string, tlsinfo *TLSInfo) (l net.Listener, err error) { - return newListener(addr, scheme, WithTLSInfo(tlsinfo)) -} - -// NewListenerWithOpts creates a new listener which accpets listener options. -func NewListenerWithOpts(addr, scheme string, opts ...ListenerOption) (net.Listener, error) { - return newListener(addr, scheme, opts...) -} - -func newListener(addr, scheme string, opts ...ListenerOption) (net.Listener, error) { - if scheme == "unix" || scheme == "unixs" { - // unix sockets via unix://laddr - return NewUnixListener(addr) - } - - lnOpts := newListenOpts(opts...) - - switch { - case lnOpts.IsSocketOpts(): - // new ListenConfig with socket options. - config, err := newListenConfig(lnOpts.socketOpts) - if err != nil { - return nil, err - } - lnOpts.ListenConfig = config - // check for timeout - fallthrough - case lnOpts.IsTimeout(), lnOpts.IsSocketOpts(): - // timeout listener with socket options. - ln, err := lnOpts.ListenConfig.Listen(context.TODO(), "tcp", addr) - if err != nil { - return nil, err - } - lnOpts.Listener = &rwTimeoutListener{ - Listener: ln, - readTimeout: lnOpts.readTimeout, - writeTimeout: lnOpts.writeTimeout, - } - case lnOpts.IsTimeout(): - ln, err := net.Listen("tcp", addr) - if err != nil { - return nil, err - } - lnOpts.Listener = &rwTimeoutListener{ - Listener: ln, - readTimeout: lnOpts.readTimeout, - writeTimeout: lnOpts.writeTimeout, - } - default: - ln, err := net.Listen("tcp", addr) - if err != nil { - return nil, err - } - lnOpts.Listener = ln - } - - // only skip if not passing TLSInfo - if lnOpts.skipTLSInfoCheck && !lnOpts.IsTLS() { - return lnOpts.Listener, nil - } - return wrapTLS(scheme, lnOpts.tlsInfo, lnOpts.Listener) -} - -func wrapTLS(scheme string, tlsinfo *TLSInfo, l net.Listener) (net.Listener, error) { - if scheme != "https" && scheme != "unixs" { - return l, nil - } - if tlsinfo != nil && tlsinfo.SkipClientSANVerify { - return NewTLSListener(l, tlsinfo) - } - return newTLSListener(l, tlsinfo, checkSAN) -} - -func newListenConfig(sopts *SocketOpts) (net.ListenConfig, error) { - lc := net.ListenConfig{} - if sopts != nil { - ctls := getControls(sopts) - if len(ctls) > 0 { - lc.Control = ctls.Control - } - } - return lc, nil -} - -type TLSInfo struct { - // CertFile is the _server_ cert, it will also be used as a _client_ certificate if ClientCertFile is empty - CertFile string - // KeyFile is the key for the CertFile - KeyFile string - // ClientCertFile is a _client_ cert for initiating connections when ClientCertAuth is defined. If ClientCertAuth - // is true but this value is empty, the CertFile will be used instead. - ClientCertFile string - // ClientKeyFile is the key for the ClientCertFile - ClientKeyFile string - - TrustedCAFile string - ClientCertAuth bool - CRLFile string - InsecureSkipVerify bool - SkipClientSANVerify bool - - // ServerName ensures the cert matches the given host in case of discovery / virtual hosting - ServerName string - - // HandshakeFailure is optionally called when a connection fails to handshake. The - // connection will be closed immediately afterwards. - HandshakeFailure func(*tls.Conn, error) - - // CipherSuites is a list of supported cipher suites. - // If empty, Go auto-populates it by default. - // Note that cipher suites are prioritized in the given order. - CipherSuites []uint16 - - selfCert bool - - // parseFunc exists to simplify testing. Typically, parseFunc - // should be left nil. In that case, tls.X509KeyPair will be used. - parseFunc func([]byte, []byte) (tls.Certificate, error) - - // AllowedCN is a CN which must be provided by a client. - AllowedCN string - - // AllowedHostname is an IP address or hostname that must match the TLS - // certificate provided by a client. - AllowedHostname string - - // Logger logs TLS errors. - // If nil, all logs are discarded. - Logger *zap.Logger - - // EmptyCN indicates that the cert must have empty CN. - // If true, ClientConfig() will return an error for a cert with non empty CN. - EmptyCN bool -} - -func (info TLSInfo) String() string { - return fmt.Sprintf("cert = %s, key = %s, client-cert=%s, client-key=%s, trusted-ca = %s, client-cert-auth = %v, crl-file = %s", info.CertFile, info.KeyFile, info.ClientCertFile, info.ClientKeyFile, info.TrustedCAFile, info.ClientCertAuth, info.CRLFile) -} - -func (info TLSInfo) Empty() bool { - return info.CertFile == "" && info.KeyFile == "" -} - -func SelfCert(lg *zap.Logger, dirpath string, hosts []string, selfSignedCertValidity uint, additionalUsages ...x509.ExtKeyUsage) (info TLSInfo, err error) { - info.Logger = lg - if selfSignedCertValidity == 0 { - err = fmt.Errorf("selfSignedCertValidity is invalid,it should be greater than 0") - info.Logger.Warn( - "cannot generate cert", - zap.Error(err), - ) - return - } - err = fileutil.TouchDirAll(dirpath) - if err != nil { - if info.Logger != nil { - info.Logger.Warn( - "cannot create cert directory", - zap.Error(err), - ) - } - return - } - - certPath, err := filepath.Abs(filepath.Join(dirpath, "cert.pem")) - if err != nil { - return - } - keyPath, err := filepath.Abs(filepath.Join(dirpath, "key.pem")) - if err != nil { - return - } - _, errcert := os.Stat(certPath) - _, errkey := os.Stat(keyPath) - if errcert == nil && errkey == nil { - info.CertFile = certPath - info.KeyFile = keyPath - info.ClientCertFile = certPath - info.ClientKeyFile = keyPath - info.selfCert = true - return - } - - serialNumberLimit := new(big.Int).Lsh(big.NewInt(1), 128) - serialNumber, err := rand.Int(rand.Reader, serialNumberLimit) - if err != nil { - if info.Logger != nil { - info.Logger.Warn( - "cannot generate random number", - zap.Error(err), - ) - } - return - } - - tmpl := x509.Certificate{ - SerialNumber: serialNumber, - Subject: pkix.Name{Organization: []string{"etcd"}}, - NotBefore: time.Now(), - NotAfter: time.Now().Add(time.Duration(selfSignedCertValidity) * 365 * (24 * time.Hour)), - - KeyUsage: x509.KeyUsageKeyEncipherment | x509.KeyUsageDigitalSignature, - ExtKeyUsage: append([]x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth}, additionalUsages...), - BasicConstraintsValid: true, - } - - if info.Logger != nil { - info.Logger.Warn( - "automatically generate certificates", - zap.Time("certificate-validity-bound-not-after", tmpl.NotAfter), - ) - } - - for _, host := range hosts { - h, _, _ := net.SplitHostPort(host) - if ip := net.ParseIP(h); ip != nil { - tmpl.IPAddresses = append(tmpl.IPAddresses, ip) - } else { - tmpl.DNSNames = append(tmpl.DNSNames, h) - } - } - - priv, err := ecdsa.GenerateKey(elliptic.P521(), rand.Reader) - if err != nil { - if info.Logger != nil { - info.Logger.Warn( - "cannot generate ECDSA key", - zap.Error(err), - ) - } - return - } - - derBytes, err := x509.CreateCertificate(rand.Reader, &tmpl, &tmpl, &priv.PublicKey, priv) - if err != nil { - if info.Logger != nil { - info.Logger.Warn( - "cannot generate x509 certificate", - zap.Error(err), - ) - } - return - } - - certOut, err := os.Create(certPath) - if err != nil { - info.Logger.Warn( - "cannot cert file", - zap.String("path", certPath), - zap.Error(err), - ) - return - } - pem.Encode(certOut, &pem.Block{Type: "CERTIFICATE", Bytes: derBytes}) - certOut.Close() - if info.Logger != nil { - info.Logger.Info("created cert file", zap.String("path", certPath)) - } - - b, err := x509.MarshalECPrivateKey(priv) - if err != nil { - return - } - keyOut, err := os.OpenFile(keyPath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600) - if err != nil { - if info.Logger != nil { - info.Logger.Warn( - "cannot key file", - zap.String("path", keyPath), - zap.Error(err), - ) - } - return - } - pem.Encode(keyOut, &pem.Block{Type: "EC PRIVATE KEY", Bytes: b}) - keyOut.Close() - if info.Logger != nil { - info.Logger.Info("created key file", zap.String("path", keyPath)) - } - return SelfCert(lg, dirpath, hosts, selfSignedCertValidity) -} - -// baseConfig is called on initial TLS handshake start. -// -// Previously, -// 1. Server has non-empty (*tls.Config).Certificates on client hello -// 2. Server calls (*tls.Config).GetCertificate iff: -// - Server's (*tls.Config).Certificates is not empty, or -// - Client supplies SNI; non-empty (*tls.ClientHelloInfo).ServerName -// -// When (*tls.Config).Certificates is always populated on initial handshake, -// client is expected to provide a valid matching SNI to pass the TLS -// verification, thus trigger server (*tls.Config).GetCertificate to reload -// TLS assets. However, a cert whose SAN field does not include domain names -// but only IP addresses, has empty (*tls.ClientHelloInfo).ServerName, thus -// it was never able to trigger TLS reload on initial handshake; first -// ceritifcate object was being used, never being updated. -// -// Now, (*tls.Config).Certificates is created empty on initial TLS client -// handshake, in order to trigger (*tls.Config).GetCertificate and populate -// rest of the certificates on every new TLS connection, even when client -// SNI is empty (e.g. cert only includes IPs). -func (info TLSInfo) baseConfig() (*tls.Config, error) { - if info.KeyFile == "" || info.CertFile == "" { - return nil, fmt.Errorf("KeyFile and CertFile must both be present[key: %v, cert: %v]", info.KeyFile, info.CertFile) - } - if info.Logger == nil { - info.Logger = zap.NewNop() - } - - _, err := tlsutil.NewCert(info.CertFile, info.KeyFile, info.parseFunc) - if err != nil { - return nil, err - } - - // Perform prevalidation of client cert and key if either are provided. This makes sure we crash before accepting any connections. - if (info.ClientKeyFile == "") != (info.ClientCertFile == "") { - return nil, fmt.Errorf("ClientKeyFile and ClientCertFile must both be present or both absent: key: %v, cert: %v]", info.ClientKeyFile, info.ClientCertFile) - } - if info.ClientCertFile != "" { - _, err := tlsutil.NewCert(info.ClientCertFile, info.ClientKeyFile, info.parseFunc) - if err != nil { - return nil, err - } - } - - cfg := &tls.Config{ - MinVersion: tls.VersionTLS12, - ServerName: info.ServerName, - } - - if len(info.CipherSuites) > 0 { - cfg.CipherSuites = info.CipherSuites - } - - // Client certificates may be verified by either an exact match on the CN, - // or a more general check of the CN and SANs. - var verifyCertificate func(*x509.Certificate) bool - if info.AllowedCN != "" { - if info.AllowedHostname != "" { - return nil, fmt.Errorf("AllowedCN and AllowedHostname are mutually exclusive (cn=%q, hostname=%q)", info.AllowedCN, info.AllowedHostname) - } - verifyCertificate = func(cert *x509.Certificate) bool { - return info.AllowedCN == cert.Subject.CommonName - } - } - if info.AllowedHostname != "" { - verifyCertificate = func(cert *x509.Certificate) bool { - return cert.VerifyHostname(info.AllowedHostname) == nil - } - } - if verifyCertificate != nil { - cfg.VerifyPeerCertificate = func(rawCerts [][]byte, verifiedChains [][]*x509.Certificate) error { - for _, chains := range verifiedChains { - if len(chains) != 0 { - if verifyCertificate(chains[0]) { - return nil - } - } - } - return errors.New("client certificate authentication failed") - } - } - - // this only reloads certs when there's a client request - // TODO: support server-side refresh (e.g. inotify, SIGHUP), caching - cfg.GetCertificate = func(clientHello *tls.ClientHelloInfo) (cert *tls.Certificate, err error) { - cert, err = tlsutil.NewCert(info.CertFile, info.KeyFile, info.parseFunc) - if os.IsNotExist(err) { - if info.Logger != nil { - info.Logger.Warn( - "failed to find peer cert files", - zap.String("cert-file", info.CertFile), - zap.String("key-file", info.KeyFile), - zap.Error(err), - ) - } - } else if err != nil { - if info.Logger != nil { - info.Logger.Warn( - "failed to create peer certificate", - zap.String("cert-file", info.CertFile), - zap.String("key-file", info.KeyFile), - zap.Error(err), - ) - } - } - return cert, err - } - cfg.GetClientCertificate = func(unused *tls.CertificateRequestInfo) (cert *tls.Certificate, err error) { - certfile, keyfile := info.CertFile, info.KeyFile - if info.ClientCertFile != "" { - certfile, keyfile = info.ClientCertFile, info.ClientKeyFile - } - cert, err = tlsutil.NewCert(certfile, keyfile, info.parseFunc) - if os.IsNotExist(err) { - if info.Logger != nil { - info.Logger.Warn( - "failed to find client cert files", - zap.String("cert-file", certfile), - zap.String("key-file", keyfile), - zap.Error(err), - ) - } - } else if err != nil { - if info.Logger != nil { - info.Logger.Warn( - "failed to create client certificate", - zap.String("cert-file", certfile), - zap.String("key-file", keyfile), - zap.Error(err), - ) - } - } - return cert, err - } - return cfg, nil -} - -// cafiles returns a list of CA file paths. -func (info TLSInfo) cafiles() []string { - cs := make([]string, 0) - if info.TrustedCAFile != "" { - cs = append(cs, info.TrustedCAFile) - } - return cs -} - -// ServerConfig generates a tls.Config object for use by an HTTP server. -func (info TLSInfo) ServerConfig() (*tls.Config, error) { - cfg, err := info.baseConfig() - if err != nil { - return nil, err - } - - if info.Logger == nil { - info.Logger = zap.NewNop() - } - - cfg.ClientAuth = tls.NoClientCert - if info.TrustedCAFile != "" || info.ClientCertAuth { - cfg.ClientAuth = tls.RequireAndVerifyClientCert - } - - cs := info.cafiles() - if len(cs) > 0 { - info.Logger.Info("Loading cert pool", zap.Strings("cs", cs), - zap.Any("tlsinfo", info)) - cp, err := tlsutil.NewCertPool(cs) - if err != nil { - return nil, err - } - cfg.ClientCAs = cp - } - - // "h2" NextProtos is necessary for enabling HTTP2 for go's HTTP server - cfg.NextProtos = []string{"h2"} - - // go1.13 enables TLS 1.3 by default - // and in TLS 1.3, cipher suites are not configurable - // setting Max TLS version to TLS 1.2 for go 1.13 - cfg.MaxVersion = tls.VersionTLS12 - - return cfg, nil -} - -// ClientConfig generates a tls.Config object for use by an HTTP client. -func (info TLSInfo) ClientConfig() (*tls.Config, error) { - var cfg *tls.Config - var err error - - if !info.Empty() { - cfg, err = info.baseConfig() - if err != nil { - return nil, err - } - } else { - cfg = &tls.Config{ServerName: info.ServerName} - } - cfg.InsecureSkipVerify = info.InsecureSkipVerify - - cs := info.cafiles() - if len(cs) > 0 { - cfg.RootCAs, err = tlsutil.NewCertPool(cs) - if err != nil { - return nil, err - } - } - - if info.selfCert { - cfg.InsecureSkipVerify = true - } - - if info.EmptyCN { - hasNonEmptyCN := false - cn := "" - _, err := tlsutil.NewCert(info.CertFile, info.KeyFile, func(certPEMBlock []byte, keyPEMBlock []byte) (tls.Certificate, error) { - var block *pem.Block - block, _ = pem.Decode(certPEMBlock) - cert, err := x509.ParseCertificate(block.Bytes) - if err != nil { - return tls.Certificate{}, err - } - if len(cert.Subject.CommonName) != 0 { - hasNonEmptyCN = true - cn = cert.Subject.CommonName - } - return tls.X509KeyPair(certPEMBlock, keyPEMBlock) - }) - if err != nil { - return nil, err - } - if hasNonEmptyCN { - return nil, fmt.Errorf("cert has non empty Common Name (%s): %s", cn, info.CertFile) - } - } - - // go1.13 enables TLS 1.3 by default - // and in TLS 1.3, cipher suites are not configurable - // setting Max TLS version to TLS 1.2 for go 1.13 - cfg.MaxVersion = tls.VersionTLS12 - - return cfg, nil -} - -// IsClosedConnError returns true if the error is from closing listener, cmux. -// copied from golang.org/x/net/http2/http2.go -func IsClosedConnError(err error) bool { - // 'use of closed network connection' (Go <=1.8) - // 'use of closed file or network connection' (Go >1.8, internal/poll.ErrClosing) - // 'mux: listener closed' (cmux.ErrListenerClosed) - return err != nil && strings.Contains(err.Error(), "closed") -} diff --git a/vendor/go.etcd.io/etcd/client/pkg/v3/transport/listener_opts.go b/vendor/go.etcd.io/etcd/client/pkg/v3/transport/listener_opts.go deleted file mode 100644 index ad4f6904da..0000000000 --- a/vendor/go.etcd.io/etcd/client/pkg/v3/transport/listener_opts.go +++ /dev/null @@ -1,76 +0,0 @@ -package transport - -import ( - "net" - "time" -) - -type ListenerOptions struct { - Listener net.Listener - ListenConfig net.ListenConfig - - socketOpts *SocketOpts - tlsInfo *TLSInfo - skipTLSInfoCheck bool - writeTimeout time.Duration - readTimeout time.Duration -} - -func newListenOpts(opts ...ListenerOption) *ListenerOptions { - lnOpts := &ListenerOptions{} - lnOpts.applyOpts(opts) - return lnOpts -} - -func (lo *ListenerOptions) applyOpts(opts []ListenerOption) { - for _, opt := range opts { - opt(lo) - } -} - -// IsTimeout returns true if the listener has a read/write timeout defined. -func (lo *ListenerOptions) IsTimeout() bool { return lo.readTimeout != 0 || lo.writeTimeout != 0 } - -// IsSocketOpts returns true if the listener options includes socket options. -func (lo *ListenerOptions) IsSocketOpts() bool { - if lo.socketOpts == nil { - return false - } - return lo.socketOpts.ReusePort || lo.socketOpts.ReuseAddress -} - -// IsTLS returns true if listner options includes TLSInfo. -func (lo *ListenerOptions) IsTLS() bool { - if lo.tlsInfo == nil { - return false - } - return !lo.tlsInfo.Empty() -} - -// ListenerOption are options which can be applied to the listener. -type ListenerOption func(*ListenerOptions) - -// WithTimeout allows for a read or write timeout to be applied to the listener. -func WithTimeout(read, write time.Duration) ListenerOption { - return func(lo *ListenerOptions) { - lo.writeTimeout = write - lo.readTimeout = read - } -} - -// WithSocketOpts defines socket options that will be applied to the listener. -func WithSocketOpts(s *SocketOpts) ListenerOption { - return func(lo *ListenerOptions) { lo.socketOpts = s } -} - -// WithTLSInfo adds TLS credentials to the listener. -func WithTLSInfo(t *TLSInfo) ListenerOption { - return func(lo *ListenerOptions) { lo.tlsInfo = t } -} - -// WithSkipTLSInfoCheck when true a transport can be created with an https scheme -// without passing TLSInfo, circumventing not presented error. Skipping this check -// also requires that TLSInfo is not passed. -func WithSkipTLSInfoCheck(skip bool) ListenerOption { - return func(lo *ListenerOptions) { lo.skipTLSInfoCheck = skip } -} diff --git a/vendor/go.etcd.io/etcd/client/pkg/v3/transport/listener_tls.go b/vendor/go.etcd.io/etcd/client/pkg/v3/transport/listener_tls.go deleted file mode 100644 index 6f1600945c..0000000000 --- a/vendor/go.etcd.io/etcd/client/pkg/v3/transport/listener_tls.go +++ /dev/null @@ -1,272 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package transport - -import ( - "context" - "crypto/tls" - "crypto/x509" - "fmt" - "io/ioutil" - "net" - "strings" - "sync" -) - -// tlsListener overrides a TLS listener so it will reject client -// certificates with insufficient SAN credentials or CRL revoked -// certificates. -type tlsListener struct { - net.Listener - connc chan net.Conn - donec chan struct{} - err error - handshakeFailure func(*tls.Conn, error) - check tlsCheckFunc -} - -type tlsCheckFunc func(context.Context, *tls.Conn) error - -// NewTLSListener handshakes TLS connections and performs optional CRL checking. -func NewTLSListener(l net.Listener, tlsinfo *TLSInfo) (net.Listener, error) { - check := func(context.Context, *tls.Conn) error { return nil } - return newTLSListener(l, tlsinfo, check) -} - -func newTLSListener(l net.Listener, tlsinfo *TLSInfo, check tlsCheckFunc) (net.Listener, error) { - if tlsinfo == nil || tlsinfo.Empty() { - l.Close() - return nil, fmt.Errorf("cannot listen on TLS for %s: KeyFile and CertFile are not presented", l.Addr().String()) - } - tlscfg, err := tlsinfo.ServerConfig() - if err != nil { - return nil, err - } - - hf := tlsinfo.HandshakeFailure - if hf == nil { - hf = func(*tls.Conn, error) {} - } - - if len(tlsinfo.CRLFile) > 0 { - prevCheck := check - check = func(ctx context.Context, tlsConn *tls.Conn) error { - if err := prevCheck(ctx, tlsConn); err != nil { - return err - } - st := tlsConn.ConnectionState() - if certs := st.PeerCertificates; len(certs) > 0 { - return checkCRL(tlsinfo.CRLFile, certs) - } - return nil - } - } - - tlsl := &tlsListener{ - Listener: tls.NewListener(l, tlscfg), - connc: make(chan net.Conn), - donec: make(chan struct{}), - handshakeFailure: hf, - check: check, - } - go tlsl.acceptLoop() - return tlsl, nil -} - -func (l *tlsListener) Accept() (net.Conn, error) { - select { - case conn := <-l.connc: - return conn, nil - case <-l.donec: - return nil, l.err - } -} - -func checkSAN(ctx context.Context, tlsConn *tls.Conn) error { - st := tlsConn.ConnectionState() - if certs := st.PeerCertificates; len(certs) > 0 { - addr := tlsConn.RemoteAddr().String() - return checkCertSAN(ctx, certs[0], addr) - } - return nil -} - -// acceptLoop launches each TLS handshake in a separate goroutine -// to prevent a hanging TLS connection from blocking other connections. -func (l *tlsListener) acceptLoop() { - var wg sync.WaitGroup - var pendingMu sync.Mutex - - pending := make(map[net.Conn]struct{}) - ctx, cancel := context.WithCancel(context.Background()) - defer func() { - cancel() - pendingMu.Lock() - for c := range pending { - c.Close() - } - pendingMu.Unlock() - wg.Wait() - close(l.donec) - }() - - for { - conn, err := l.Listener.Accept() - if err != nil { - l.err = err - return - } - - pendingMu.Lock() - pending[conn] = struct{}{} - pendingMu.Unlock() - - wg.Add(1) - go func() { - defer func() { - if conn != nil { - conn.Close() - } - wg.Done() - }() - - tlsConn := conn.(*tls.Conn) - herr := tlsConn.Handshake() - pendingMu.Lock() - delete(pending, conn) - pendingMu.Unlock() - - if herr != nil { - l.handshakeFailure(tlsConn, herr) - return - } - if err := l.check(ctx, tlsConn); err != nil { - l.handshakeFailure(tlsConn, err) - return - } - - select { - case l.connc <- tlsConn: - conn = nil - case <-ctx.Done(): - } - }() - } -} - -func checkCRL(crlPath string, cert []*x509.Certificate) error { - // TODO: cache - crlBytes, err := ioutil.ReadFile(crlPath) - if err != nil { - return err - } - certList, err := x509.ParseCRL(crlBytes) - if err != nil { - return err - } - revokedSerials := make(map[string]struct{}) - for _, rc := range certList.TBSCertList.RevokedCertificates { - revokedSerials[string(rc.SerialNumber.Bytes())] = struct{}{} - } - for _, c := range cert { - serial := string(c.SerialNumber.Bytes()) - if _, ok := revokedSerials[serial]; ok { - return fmt.Errorf("transport: certificate serial %x revoked", serial) - } - } - return nil -} - -func checkCertSAN(ctx context.Context, cert *x509.Certificate, remoteAddr string) error { - if len(cert.IPAddresses) == 0 && len(cert.DNSNames) == 0 { - return nil - } - h, _, herr := net.SplitHostPort(remoteAddr) - if herr != nil { - return herr - } - if len(cert.IPAddresses) > 0 { - cerr := cert.VerifyHostname(h) - if cerr == nil { - return nil - } - if len(cert.DNSNames) == 0 { - return cerr - } - } - if len(cert.DNSNames) > 0 { - ok, err := isHostInDNS(ctx, h, cert.DNSNames) - if ok { - return nil - } - errStr := "" - if err != nil { - errStr = " (" + err.Error() + ")" - } - return fmt.Errorf("tls: %q does not match any of DNSNames %q"+errStr, h, cert.DNSNames) - } - return nil -} - -func isHostInDNS(ctx context.Context, host string, dnsNames []string) (ok bool, err error) { - // reverse lookup - wildcards, names := []string{}, []string{} - for _, dns := range dnsNames { - if strings.HasPrefix(dns, "*.") { - wildcards = append(wildcards, dns[1:]) - } else { - names = append(names, dns) - } - } - lnames, lerr := net.DefaultResolver.LookupAddr(ctx, host) - for _, name := range lnames { - // strip trailing '.' from PTR record - if name[len(name)-1] == '.' { - name = name[:len(name)-1] - } - for _, wc := range wildcards { - if strings.HasSuffix(name, wc) { - return true, nil - } - } - for _, n := range names { - if n == name { - return true, nil - } - } - } - err = lerr - - // forward lookup - for _, dns := range names { - addrs, lerr := net.DefaultResolver.LookupHost(ctx, dns) - if lerr != nil { - err = lerr - continue - } - for _, addr := range addrs { - if addr == host { - return true, nil - } - } - } - return false, err -} - -func (l *tlsListener) Close() error { - err := l.Listener.Close() - <-l.donec - return err -} diff --git a/vendor/go.etcd.io/etcd/client/pkg/v3/transport/sockopt.go b/vendor/go.etcd.io/etcd/client/pkg/v3/transport/sockopt.go deleted file mode 100644 index 38548ddd71..0000000000 --- a/vendor/go.etcd.io/etcd/client/pkg/v3/transport/sockopt.go +++ /dev/null @@ -1,45 +0,0 @@ -package transport - -import ( - "syscall" -) - -type Controls []func(network, addr string, conn syscall.RawConn) error - -func (ctls Controls) Control(network, addr string, conn syscall.RawConn) error { - for _, s := range ctls { - if err := s(network, addr, conn); err != nil { - return err - } - } - return nil -} - -type SocketOpts struct { - // ReusePort enables socket option SO_REUSEPORT [1] which allows rebind of - // a port already in use. User should keep in mind that flock can fail - // in which case lock on data file could result in unexpected - // condition. User should take caution to protect against lock race. - // [1] https://man7.org/linux/man-pages/man7/socket.7.html - ReusePort bool - // ReuseAddress enables a socket option SO_REUSEADDR which allows - // binding to an address in `TIME_WAIT` state. Useful to improve MTTR - // in cases where etcd slow to restart due to excessive `TIME_WAIT`. - // [1] https://man7.org/linux/man-pages/man7/socket.7.html - ReuseAddress bool -} - -func getControls(sopts *SocketOpts) Controls { - ctls := Controls{} - if sopts.ReuseAddress { - ctls = append(ctls, setReuseAddress) - } - if sopts.ReusePort { - ctls = append(ctls, setReusePort) - } - return ctls -} - -func (sopts *SocketOpts) Empty() bool { - return !sopts.ReuseAddress && !sopts.ReusePort -} diff --git a/vendor/go.etcd.io/etcd/client/pkg/v3/transport/sockopt_unix.go b/vendor/go.etcd.io/etcd/client/pkg/v3/transport/sockopt_unix.go deleted file mode 100644 index 432b52e0fc..0000000000 --- a/vendor/go.etcd.io/etcd/client/pkg/v3/transport/sockopt_unix.go +++ /dev/null @@ -1,22 +0,0 @@ -//go:build !windows -// +build !windows - -package transport - -import ( - "syscall" - - "golang.org/x/sys/unix" -) - -func setReusePort(network, address string, conn syscall.RawConn) error { - return conn.Control(func(fd uintptr) { - syscall.SetsockoptInt(int(fd), syscall.SOL_SOCKET, unix.SO_REUSEPORT, 1) - }) -} - -func setReuseAddress(network, address string, conn syscall.RawConn) error { - return conn.Control(func(fd uintptr) { - syscall.SetsockoptInt(int(fd), syscall.SOL_SOCKET, unix.SO_REUSEADDR, 1) - }) -} diff --git a/vendor/go.etcd.io/etcd/client/pkg/v3/transport/sockopt_windows.go b/vendor/go.etcd.io/etcd/client/pkg/v3/transport/sockopt_windows.go deleted file mode 100644 index 4e5af70b11..0000000000 --- a/vendor/go.etcd.io/etcd/client/pkg/v3/transport/sockopt_windows.go +++ /dev/null @@ -1,19 +0,0 @@ -//go:build windows -// +build windows - -package transport - -import ( - "fmt" - "syscall" -) - -func setReusePort(network, address string, c syscall.RawConn) error { - return fmt.Errorf("port reuse is not supported on Windows") -} - -// Windows supports SO_REUSEADDR, but it may cause undefined behavior, as -// there is no protection against port hijacking. -func setReuseAddress(network, addr string, conn syscall.RawConn) error { - return fmt.Errorf("address reuse is not supported on Windows") -} diff --git a/vendor/go.etcd.io/etcd/client/pkg/v3/transport/timeout_conn.go b/vendor/go.etcd.io/etcd/client/pkg/v3/transport/timeout_conn.go deleted file mode 100644 index 80e3293941..0000000000 --- a/vendor/go.etcd.io/etcd/client/pkg/v3/transport/timeout_conn.go +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package transport - -import ( - "net" - "time" -) - -type timeoutConn struct { - net.Conn - writeTimeout time.Duration - readTimeout time.Duration -} - -func (c timeoutConn) Write(b []byte) (n int, err error) { - if c.writeTimeout > 0 { - if err := c.SetWriteDeadline(time.Now().Add(c.writeTimeout)); err != nil { - return 0, err - } - } - return c.Conn.Write(b) -} - -func (c timeoutConn) Read(b []byte) (n int, err error) { - if c.readTimeout > 0 { - if err := c.SetReadDeadline(time.Now().Add(c.readTimeout)); err != nil { - return 0, err - } - } - return c.Conn.Read(b) -} diff --git a/vendor/go.etcd.io/etcd/client/pkg/v3/transport/timeout_dialer.go b/vendor/go.etcd.io/etcd/client/pkg/v3/transport/timeout_dialer.go deleted file mode 100644 index 9c0245d31a..0000000000 --- a/vendor/go.etcd.io/etcd/client/pkg/v3/transport/timeout_dialer.go +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package transport - -import ( - "net" - "time" -) - -type rwTimeoutDialer struct { - wtimeoutd time.Duration - rdtimeoutd time.Duration - net.Dialer -} - -func (d *rwTimeoutDialer) Dial(network, address string) (net.Conn, error) { - conn, err := d.Dialer.Dial(network, address) - tconn := &timeoutConn{ - readTimeout: d.rdtimeoutd, - writeTimeout: d.wtimeoutd, - Conn: conn, - } - return tconn, err -} diff --git a/vendor/go.etcd.io/etcd/client/pkg/v3/transport/timeout_listener.go b/vendor/go.etcd.io/etcd/client/pkg/v3/transport/timeout_listener.go deleted file mode 100644 index 5d74bd70c2..0000000000 --- a/vendor/go.etcd.io/etcd/client/pkg/v3/transport/timeout_listener.go +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package transport - -import ( - "net" - "time" -) - -// NewTimeoutListener returns a listener that listens on the given address. -// If read/write on the accepted connection blocks longer than its time limit, -// it will return timeout error. -func NewTimeoutListener(addr string, scheme string, tlsinfo *TLSInfo, readTimeout, writeTimeout time.Duration) (net.Listener, error) { - return newListener(addr, scheme, WithTimeout(readTimeout, writeTimeout), WithTLSInfo(tlsinfo)) -} - -type rwTimeoutListener struct { - net.Listener - writeTimeout time.Duration - readTimeout time.Duration -} - -func (rwln *rwTimeoutListener) Accept() (net.Conn, error) { - c, err := rwln.Listener.Accept() - if err != nil { - return nil, err - } - return timeoutConn{ - Conn: c, - writeTimeout: rwln.writeTimeout, - readTimeout: rwln.readTimeout, - }, nil -} diff --git a/vendor/go.etcd.io/etcd/client/pkg/v3/transport/timeout_transport.go b/vendor/go.etcd.io/etcd/client/pkg/v3/transport/timeout_transport.go deleted file mode 100644 index ea16b4c0f8..0000000000 --- a/vendor/go.etcd.io/etcd/client/pkg/v3/transport/timeout_transport.go +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package transport - -import ( - "net" - "net/http" - "time" -) - -// NewTimeoutTransport returns a transport created using the given TLS info. -// If read/write on the created connection blocks longer than its time limit, -// it will return timeout error. -// If read/write timeout is set, transport will not be able to reuse connection. -func NewTimeoutTransport(info TLSInfo, dialtimeoutd, rdtimeoutd, wtimeoutd time.Duration) (*http.Transport, error) { - tr, err := NewTransport(info, dialtimeoutd) - if err != nil { - return nil, err - } - - if rdtimeoutd != 0 || wtimeoutd != 0 { - // the timed out connection will timeout soon after it is idle. - // it should not be put back to http transport as an idle connection for future usage. - tr.MaxIdleConnsPerHost = -1 - } else { - // allow more idle connections between peers to avoid unnecessary port allocation. - tr.MaxIdleConnsPerHost = 1024 - } - - tr.Dial = (&rwTimeoutDialer{ - Dialer: net.Dialer{ - Timeout: dialtimeoutd, - KeepAlive: 30 * time.Second, - }, - rdtimeoutd: rdtimeoutd, - wtimeoutd: wtimeoutd, - }).Dial - return tr, nil -} diff --git a/vendor/go.etcd.io/etcd/client/pkg/v3/transport/tls.go b/vendor/go.etcd.io/etcd/client/pkg/v3/transport/tls.go deleted file mode 100644 index 62fe0d3851..0000000000 --- a/vendor/go.etcd.io/etcd/client/pkg/v3/transport/tls.go +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package transport - -import ( - "fmt" - "strings" - "time" -) - -// ValidateSecureEndpoints scans the given endpoints against tls info, returning only those -// endpoints that could be validated as secure. -func ValidateSecureEndpoints(tlsInfo TLSInfo, eps []string) ([]string, error) { - t, err := NewTransport(tlsInfo, 5*time.Second) - if err != nil { - return nil, err - } - var errs []string - var endpoints []string - for _, ep := range eps { - if !strings.HasPrefix(ep, "https://") { - errs = append(errs, fmt.Sprintf("%q is insecure", ep)) - continue - } - conn, cerr := t.Dial("tcp", ep[len("https://"):]) - if cerr != nil { - errs = append(errs, fmt.Sprintf("%q failed to dial (%v)", ep, cerr)) - continue - } - conn.Close() - endpoints = append(endpoints, ep) - } - if len(errs) != 0 { - err = fmt.Errorf("%s", strings.Join(errs, ",")) - } - return endpoints, err -} diff --git a/vendor/go.etcd.io/etcd/client/pkg/v3/transport/transport.go b/vendor/go.etcd.io/etcd/client/pkg/v3/transport/transport.go deleted file mode 100644 index 648512772d..0000000000 --- a/vendor/go.etcd.io/etcd/client/pkg/v3/transport/transport.go +++ /dev/null @@ -1,77 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package transport - -import ( - "context" - "net" - "net/http" - "strings" - "time" -) - -type unixTransport struct{ *http.Transport } - -func NewTransport(info TLSInfo, dialtimeoutd time.Duration) (*http.Transport, error) { - cfg, err := info.ClientConfig() - if err != nil { - return nil, err - } - - t := &http.Transport{ - Proxy: http.ProxyFromEnvironment, - DialContext: (&net.Dialer{ - Timeout: dialtimeoutd, - // value taken from http.DefaultTransport - KeepAlive: 30 * time.Second, - }).DialContext, - // value taken from http.DefaultTransport - TLSHandshakeTimeout: 10 * time.Second, - TLSClientConfig: cfg, - } - - dialer := &net.Dialer{ - Timeout: dialtimeoutd, - KeepAlive: 30 * time.Second, - } - - dialContext := func(ctx context.Context, net, addr string) (net.Conn, error) { - return dialer.DialContext(ctx, "unix", addr) - } - tu := &http.Transport{ - Proxy: http.ProxyFromEnvironment, - DialContext: dialContext, - TLSHandshakeTimeout: 10 * time.Second, - TLSClientConfig: cfg, - // Cost of reopening connection on sockets is low, and they are mostly used in testing. - // Long living unix-transport connections were leading to 'leak' test flakes. - // Alternativly the returned Transport (t) should override CloseIdleConnections to - // forward it to 'tu' as well. - IdleConnTimeout: time.Microsecond, - } - ut := &unixTransport{tu} - - t.RegisterProtocol("unix", ut) - t.RegisterProtocol("unixs", ut) - - return t, nil -} - -func (urt *unixTransport) RoundTrip(req *http.Request) (*http.Response, error) { - url := *req.URL - req.URL = &url - req.URL.Scheme = strings.Replace(req.URL.Scheme, "unix", "http", 1) - return urt.Transport.RoundTrip(req) -} diff --git a/vendor/go.etcd.io/etcd/client/pkg/v3/transport/unix_listener.go b/vendor/go.etcd.io/etcd/client/pkg/v3/transport/unix_listener.go deleted file mode 100644 index 123e2036f0..0000000000 --- a/vendor/go.etcd.io/etcd/client/pkg/v3/transport/unix_listener.go +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package transport - -import ( - "net" - "os" -) - -type unixListener struct{ net.Listener } - -func NewUnixListener(addr string) (net.Listener, error) { - if err := os.Remove(addr); err != nil && !os.IsNotExist(err) { - return nil, err - } - l, err := net.Listen("unix", addr) - if err != nil { - return nil, err - } - return &unixListener{l}, nil -} - -func (ul *unixListener) Close() error { - if err := os.Remove(ul.Addr().String()); err != nil && !os.IsNotExist(err) { - return err - } - return ul.Listener.Close() -} diff --git a/vendor/go.etcd.io/etcd/client/v2/LICENSE b/vendor/go.etcd.io/etcd/client/v2/LICENSE deleted file mode 100644 index d645695673..0000000000 --- a/vendor/go.etcd.io/etcd/client/v2/LICENSE +++ /dev/null @@ -1,202 +0,0 @@ - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. diff --git a/vendor/go.etcd.io/etcd/client/v2/README.md b/vendor/go.etcd.io/etcd/client/v2/README.md deleted file mode 100644 index 5ecb67820f..0000000000 --- a/vendor/go.etcd.io/etcd/client/v2/README.md +++ /dev/null @@ -1,112 +0,0 @@ -# etcd/client - -etcd/client is the Go client library for etcd. - -[![GoDoc](https://godoc.org/go.etcd.io/etcd/client?status.png)](https://godoc.org/go.etcd.io/etcd/client) - -For full compatibility, it is recommended to install released versions of clients using go modules. - -## Install - -```bash -go get go.etcd.io/etcd/v3/client -``` - -## Usage - -```go -package main - -import ( - "log" - "time" - "context" - - "go.etcd.io/etcd/v3/client" -) - -func main() { - cfg := client.Config{ - Endpoints: []string{"http://127.0.0.1:2379"}, - Transport: client.DefaultTransport, - // set timeout per request to fail fast when the target endpoint is unavailable - HeaderTimeoutPerRequest: time.Second, - } - c, err := client.New(cfg) - if err != nil { - log.Fatal(err) - } - kapi := client.NewKeysAPI(c) - // set "/foo" key with "bar" value - log.Print("Setting '/foo' key with 'bar' value") - resp, err := kapi.Set(context.Background(), "/foo", "bar", nil) - if err != nil { - log.Fatal(err) - } else { - // print common key info - log.Printf("Set is done. Metadata is %q\n", resp) - } - // get "/foo" key's value - log.Print("Getting '/foo' key value") - resp, err = kapi.Get(context.Background(), "/foo", nil) - if err != nil { - log.Fatal(err) - } else { - // print common key info - log.Printf("Get is done. Metadata is %q\n", resp) - // print value - log.Printf("%q key has %q value\n", resp.Node.Key, resp.Node.Value) - } -} -``` - -## Error Handling - -etcd client might return three types of errors. - -- context error - -Each API call has its first parameter as `context`. A context can be canceled or have an attached deadline. If the context is canceled or reaches its deadline, the responding context error will be returned no matter what internal errors the API call has already encountered. - -- cluster error - -Each API call tries to send request to the cluster endpoints one by one until it successfully gets a response. If a requests to an endpoint fails, due to exceeding per request timeout or connection issues, the error will be added into a list of errors. If all possible endpoints fail, a cluster error that includes all encountered errors will be returned. - -- response error - -If the response gets from the cluster is invalid, a plain string error will be returned. For example, it might be a invalid JSON error. - -Here is the example code to handle client errors: - -```go -cfg := client.Config{Endpoints: []string{"http://etcd1:2379","http://etcd2:2379","http://etcd3:2379"}} -c, err := client.New(cfg) -if err != nil { - log.Fatal(err) -} - -kapi := client.NewKeysAPI(c) -resp, err := kapi.Set(ctx, "test", "bar", nil) -if err != nil { - if err == context.Canceled { - // ctx is canceled by another routine - } else if err == context.DeadlineExceeded { - // ctx is attached with a deadline and it exceeded - } else if cerr, ok := err.(*client.ClusterError); ok { - // process (cerr.Errors) - } else { - // bad cluster endpoints, which are not etcd servers - } -} -``` - - -## Caveat - -1. etcd/client prefers to use the same endpoint as long as the endpoint continues to work well. This saves socket resources, and improves efficiency for both client and server side. This preference doesn't remove consistency from the data consumed by the client because data replicated to each etcd member has already passed through the consensus process. - -2. etcd/client does round-robin rotation on other available endpoints if the preferred endpoint isn't functioning properly. For example, if the member that etcd/client connects to is hard killed, etcd/client will fail on the first attempt with the killed member, and succeed on the second attempt with another member. If it fails to talk to all available endpoints, it will return all errors happened. - -3. Default etcd/client cannot handle the case that the remote server is SIGSTOPed now. TCP keepalive mechanism doesn't help in this scenario because operating system may still send TCP keep-alive packets. Over time we'd like to improve this functionality, but solving this issue isn't high priority because a real-life case in which a server is stopped, but the connection is kept alive, hasn't been brought to our attention. - -4. etcd/client cannot detect whether a member is healthy with watches and non-quorum read requests. If the member is isolated from the cluster, etcd/client may retrieve outdated data. Instead, users can either issue quorum read requests or monitor the /health endpoint for member health information. diff --git a/vendor/go.etcd.io/etcd/client/v2/auth_role.go b/vendor/go.etcd.io/etcd/client/v2/auth_role.go deleted file mode 100644 index b6ba7e150d..0000000000 --- a/vendor/go.etcd.io/etcd/client/v2/auth_role.go +++ /dev/null @@ -1,236 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package client - -import ( - "bytes" - "context" - "encoding/json" - "net/http" - "net/url" -) - -type Role struct { - Role string `json:"role"` - Permissions Permissions `json:"permissions"` - Grant *Permissions `json:"grant,omitempty"` - Revoke *Permissions `json:"revoke,omitempty"` -} - -type Permissions struct { - KV rwPermission `json:"kv"` -} - -type rwPermission struct { - Read []string `json:"read"` - Write []string `json:"write"` -} - -type PermissionType int - -const ( - ReadPermission PermissionType = iota - WritePermission - ReadWritePermission -) - -// NewAuthRoleAPI constructs a new AuthRoleAPI that uses HTTP to -// interact with etcd's role creation and modification features. -func NewAuthRoleAPI(c Client) AuthRoleAPI { - return &httpAuthRoleAPI{ - client: c, - } -} - -type AuthRoleAPI interface { - // AddRole adds a role. - AddRole(ctx context.Context, role string) error - - // RemoveRole removes a role. - RemoveRole(ctx context.Context, role string) error - - // GetRole retrieves role details. - GetRole(ctx context.Context, role string) (*Role, error) - - // GrantRoleKV grants a role some permission prefixes for the KV store. - GrantRoleKV(ctx context.Context, role string, prefixes []string, permType PermissionType) (*Role, error) - - // RevokeRoleKV revokes some permission prefixes for a role on the KV store. - RevokeRoleKV(ctx context.Context, role string, prefixes []string, permType PermissionType) (*Role, error) - - // ListRoles lists roles. - ListRoles(ctx context.Context) ([]string, error) -} - -type httpAuthRoleAPI struct { - client httpClient -} - -type authRoleAPIAction struct { - verb string - name string - role *Role -} - -type authRoleAPIList struct{} - -func (list *authRoleAPIList) HTTPRequest(ep url.URL) *http.Request { - u := v2AuthURL(ep, "roles", "") - req, _ := http.NewRequest("GET", u.String(), nil) - req.Header.Set("Content-Type", "application/json") - return req -} - -func (l *authRoleAPIAction) HTTPRequest(ep url.URL) *http.Request { - u := v2AuthURL(ep, "roles", l.name) - if l.role == nil { - req, _ := http.NewRequest(l.verb, u.String(), nil) - return req - } - b, err := json.Marshal(l.role) - if err != nil { - panic(err) - } - body := bytes.NewReader(b) - req, _ := http.NewRequest(l.verb, u.String(), body) - req.Header.Set("Content-Type", "application/json") - return req -} - -func (r *httpAuthRoleAPI) ListRoles(ctx context.Context) ([]string, error) { - resp, body, err := r.client.Do(ctx, &authRoleAPIList{}) - if err != nil { - return nil, err - } - if err = assertStatusCode(resp.StatusCode, http.StatusOK); err != nil { - return nil, err - } - var roleList struct { - Roles []Role `json:"roles"` - } - if err = json.Unmarshal(body, &roleList); err != nil { - return nil, err - } - ret := make([]string, 0, len(roleList.Roles)) - for _, r := range roleList.Roles { - ret = append(ret, r.Role) - } - return ret, nil -} - -func (r *httpAuthRoleAPI) AddRole(ctx context.Context, rolename string) error { - role := &Role{ - Role: rolename, - } - return r.addRemoveRole(ctx, &authRoleAPIAction{ - verb: "PUT", - name: rolename, - role: role, - }) -} - -func (r *httpAuthRoleAPI) RemoveRole(ctx context.Context, rolename string) error { - return r.addRemoveRole(ctx, &authRoleAPIAction{ - verb: "DELETE", - name: rolename, - }) -} - -func (r *httpAuthRoleAPI) addRemoveRole(ctx context.Context, req *authRoleAPIAction) error { - resp, body, err := r.client.Do(ctx, req) - if err != nil { - return err - } - if err := assertStatusCode(resp.StatusCode, http.StatusOK, http.StatusCreated); err != nil { - var sec authError - err := json.Unmarshal(body, &sec) - if err != nil { - return err - } - return sec - } - return nil -} - -func (r *httpAuthRoleAPI) GetRole(ctx context.Context, rolename string) (*Role, error) { - return r.modRole(ctx, &authRoleAPIAction{ - verb: "GET", - name: rolename, - }) -} - -func buildRWPermission(prefixes []string, permType PermissionType) rwPermission { - var out rwPermission - switch permType { - case ReadPermission: - out.Read = prefixes - case WritePermission: - out.Write = prefixes - case ReadWritePermission: - out.Read = prefixes - out.Write = prefixes - } - return out -} - -func (r *httpAuthRoleAPI) GrantRoleKV(ctx context.Context, rolename string, prefixes []string, permType PermissionType) (*Role, error) { - rwp := buildRWPermission(prefixes, permType) - role := &Role{ - Role: rolename, - Grant: &Permissions{ - KV: rwp, - }, - } - return r.modRole(ctx, &authRoleAPIAction{ - verb: "PUT", - name: rolename, - role: role, - }) -} - -func (r *httpAuthRoleAPI) RevokeRoleKV(ctx context.Context, rolename string, prefixes []string, permType PermissionType) (*Role, error) { - rwp := buildRWPermission(prefixes, permType) - role := &Role{ - Role: rolename, - Revoke: &Permissions{ - KV: rwp, - }, - } - return r.modRole(ctx, &authRoleAPIAction{ - verb: "PUT", - name: rolename, - role: role, - }) -} - -func (r *httpAuthRoleAPI) modRole(ctx context.Context, req *authRoleAPIAction) (*Role, error) { - resp, body, err := r.client.Do(ctx, req) - if err != nil { - return nil, err - } - if err = assertStatusCode(resp.StatusCode, http.StatusOK); err != nil { - var sec authError - err = json.Unmarshal(body, &sec) - if err != nil { - return nil, err - } - return nil, sec - } - var role Role - if err = json.Unmarshal(body, &role); err != nil { - return nil, err - } - return &role, nil -} diff --git a/vendor/go.etcd.io/etcd/client/v2/auth_user.go b/vendor/go.etcd.io/etcd/client/v2/auth_user.go deleted file mode 100644 index 8e7e2efe83..0000000000 --- a/vendor/go.etcd.io/etcd/client/v2/auth_user.go +++ /dev/null @@ -1,319 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package client - -import ( - "bytes" - "context" - "encoding/json" - "net/http" - "net/url" - "path" -) - -var ( - defaultV2AuthPrefix = "/v2/auth" -) - -type User struct { - User string `json:"user"` - Password string `json:"password,omitempty"` - Roles []string `json:"roles"` - Grant []string `json:"grant,omitempty"` - Revoke []string `json:"revoke,omitempty"` -} - -// userListEntry is the user representation given by the server for ListUsers -type userListEntry struct { - User string `json:"user"` - Roles []Role `json:"roles"` -} - -type UserRoles struct { - User string `json:"user"` - Roles []Role `json:"roles"` -} - -func v2AuthURL(ep url.URL, action string, name string) *url.URL { - if name != "" { - ep.Path = path.Join(ep.Path, defaultV2AuthPrefix, action, name) - return &ep - } - ep.Path = path.Join(ep.Path, defaultV2AuthPrefix, action) - return &ep -} - -// NewAuthAPI constructs a new AuthAPI that uses HTTP to -// interact with etcd's general auth features. -func NewAuthAPI(c Client) AuthAPI { - return &httpAuthAPI{ - client: c, - } -} - -type AuthAPI interface { - // Enable auth. - Enable(ctx context.Context) error - - // Disable auth. - Disable(ctx context.Context) error -} - -type httpAuthAPI struct { - client httpClient -} - -func (s *httpAuthAPI) Enable(ctx context.Context) error { - return s.enableDisable(ctx, &authAPIAction{"PUT"}) -} - -func (s *httpAuthAPI) Disable(ctx context.Context) error { - return s.enableDisable(ctx, &authAPIAction{"DELETE"}) -} - -func (s *httpAuthAPI) enableDisable(ctx context.Context, req httpAction) error { - resp, body, err := s.client.Do(ctx, req) - if err != nil { - return err - } - if err = assertStatusCode(resp.StatusCode, http.StatusOK, http.StatusCreated); err != nil { - var sec authError - err = json.Unmarshal(body, &sec) - if err != nil { - return err - } - return sec - } - return nil -} - -type authAPIAction struct { - verb string -} - -func (l *authAPIAction) HTTPRequest(ep url.URL) *http.Request { - u := v2AuthURL(ep, "enable", "") - req, _ := http.NewRequest(l.verb, u.String(), nil) - return req -} - -type authError struct { - Message string `json:"message"` - Code int `json:"-"` -} - -func (e authError) Error() string { - return e.Message -} - -// NewAuthUserAPI constructs a new AuthUserAPI that uses HTTP to -// interact with etcd's user creation and modification features. -func NewAuthUserAPI(c Client) AuthUserAPI { - return &httpAuthUserAPI{ - client: c, - } -} - -type AuthUserAPI interface { - // AddUser adds a user. - AddUser(ctx context.Context, username string, password string) error - - // RemoveUser removes a user. - RemoveUser(ctx context.Context, username string) error - - // GetUser retrieves user details. - GetUser(ctx context.Context, username string) (*User, error) - - // GrantUser grants a user some permission roles. - GrantUser(ctx context.Context, username string, roles []string) (*User, error) - - // RevokeUser revokes some permission roles from a user. - RevokeUser(ctx context.Context, username string, roles []string) (*User, error) - - // ChangePassword changes the user's password. - ChangePassword(ctx context.Context, username string, password string) (*User, error) - - // ListUsers lists the users. - ListUsers(ctx context.Context) ([]string, error) -} - -type httpAuthUserAPI struct { - client httpClient -} - -type authUserAPIAction struct { - verb string - username string - user *User -} - -type authUserAPIList struct{} - -func (list *authUserAPIList) HTTPRequest(ep url.URL) *http.Request { - u := v2AuthURL(ep, "users", "") - req, _ := http.NewRequest("GET", u.String(), nil) - req.Header.Set("Content-Type", "application/json") - return req -} - -func (l *authUserAPIAction) HTTPRequest(ep url.URL) *http.Request { - u := v2AuthURL(ep, "users", l.username) - if l.user == nil { - req, _ := http.NewRequest(l.verb, u.String(), nil) - return req - } - b, err := json.Marshal(l.user) - if err != nil { - panic(err) - } - body := bytes.NewReader(b) - req, _ := http.NewRequest(l.verb, u.String(), body) - req.Header.Set("Content-Type", "application/json") - return req -} - -func (u *httpAuthUserAPI) ListUsers(ctx context.Context) ([]string, error) { - resp, body, err := u.client.Do(ctx, &authUserAPIList{}) - if err != nil { - return nil, err - } - if err = assertStatusCode(resp.StatusCode, http.StatusOK); err != nil { - var sec authError - err = json.Unmarshal(body, &sec) - if err != nil { - return nil, err - } - return nil, sec - } - - var userList struct { - Users []userListEntry `json:"users"` - } - - if err = json.Unmarshal(body, &userList); err != nil { - return nil, err - } - - ret := make([]string, 0, len(userList.Users)) - for _, u := range userList.Users { - ret = append(ret, u.User) - } - return ret, nil -} - -func (u *httpAuthUserAPI) AddUser(ctx context.Context, username string, password string) error { - user := &User{ - User: username, - Password: password, - } - return u.addRemoveUser(ctx, &authUserAPIAction{ - verb: "PUT", - username: username, - user: user, - }) -} - -func (u *httpAuthUserAPI) RemoveUser(ctx context.Context, username string) error { - return u.addRemoveUser(ctx, &authUserAPIAction{ - verb: "DELETE", - username: username, - }) -} - -func (u *httpAuthUserAPI) addRemoveUser(ctx context.Context, req *authUserAPIAction) error { - resp, body, err := u.client.Do(ctx, req) - if err != nil { - return err - } - if err = assertStatusCode(resp.StatusCode, http.StatusOK, http.StatusCreated); err != nil { - var sec authError - err = json.Unmarshal(body, &sec) - if err != nil { - return err - } - return sec - } - return nil -} - -func (u *httpAuthUserAPI) GetUser(ctx context.Context, username string) (*User, error) { - return u.modUser(ctx, &authUserAPIAction{ - verb: "GET", - username: username, - }) -} - -func (u *httpAuthUserAPI) GrantUser(ctx context.Context, username string, roles []string) (*User, error) { - user := &User{ - User: username, - Grant: roles, - } - return u.modUser(ctx, &authUserAPIAction{ - verb: "PUT", - username: username, - user: user, - }) -} - -func (u *httpAuthUserAPI) RevokeUser(ctx context.Context, username string, roles []string) (*User, error) { - user := &User{ - User: username, - Revoke: roles, - } - return u.modUser(ctx, &authUserAPIAction{ - verb: "PUT", - username: username, - user: user, - }) -} - -func (u *httpAuthUserAPI) ChangePassword(ctx context.Context, username string, password string) (*User, error) { - user := &User{ - User: username, - Password: password, - } - return u.modUser(ctx, &authUserAPIAction{ - verb: "PUT", - username: username, - user: user, - }) -} - -func (u *httpAuthUserAPI) modUser(ctx context.Context, req *authUserAPIAction) (*User, error) { - resp, body, err := u.client.Do(ctx, req) - if err != nil { - return nil, err - } - if err = assertStatusCode(resp.StatusCode, http.StatusOK); err != nil { - var sec authError - err = json.Unmarshal(body, &sec) - if err != nil { - return nil, err - } - return nil, sec - } - var user User - if err = json.Unmarshal(body, &user); err != nil { - var userR UserRoles - if urerr := json.Unmarshal(body, &userR); urerr != nil { - return nil, err - } - user.User = userR.User - for _, r := range userR.Roles { - user.Roles = append(user.Roles, r.Role) - } - } - return &user, nil -} diff --git a/vendor/go.etcd.io/etcd/client/v2/cancelreq.go b/vendor/go.etcd.io/etcd/client/v2/cancelreq.go deleted file mode 100644 index 76d1f04019..0000000000 --- a/vendor/go.etcd.io/etcd/client/v2/cancelreq.go +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright 2015 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// borrowed from golang/net/context/ctxhttp/cancelreq.go - -package client - -import "net/http" - -func requestCanceler(tr CancelableTransport, req *http.Request) func() { - ch := make(chan struct{}) - req.Cancel = ch - - return func() { - close(ch) - } -} diff --git a/vendor/go.etcd.io/etcd/client/v2/client.go b/vendor/go.etcd.io/etcd/client/v2/client.go deleted file mode 100644 index fda25988f6..0000000000 --- a/vendor/go.etcd.io/etcd/client/v2/client.go +++ /dev/null @@ -1,717 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package client - -import ( - "context" - "encoding/json" - "errors" - "fmt" - "io/ioutil" - "math/rand" - "net" - "net/http" - "net/url" - "sort" - "strconv" - "sync" - "time" - - "go.etcd.io/etcd/api/v3/version" -) - -var ( - ErrNoEndpoints = errors.New("client: no endpoints available") - ErrTooManyRedirects = errors.New("client: too many redirects") - ErrClusterUnavailable = errors.New("client: etcd cluster is unavailable or misconfigured") - ErrNoLeaderEndpoint = errors.New("client: no leader endpoint available") - errTooManyRedirectChecks = errors.New("client: too many redirect checks") - - // oneShotCtxValue is set on a context using WithValue(&oneShotValue) so - // that Do() will not retry a request - oneShotCtxValue interface{} -) - -var DefaultRequestTimeout = 5 * time.Second - -var DefaultTransport CancelableTransport = &http.Transport{ - Proxy: http.ProxyFromEnvironment, - DialContext: (&net.Dialer{ - Timeout: 30 * time.Second, - KeepAlive: 30 * time.Second, - }).DialContext, - TLSHandshakeTimeout: 10 * time.Second, -} - -type EndpointSelectionMode int - -const ( - // EndpointSelectionRandom is the default value of the 'SelectionMode'. - // As the name implies, the client object will pick a node from the members - // of the cluster in a random fashion. If the cluster has three members, A, B, - // and C, the client picks any node from its three members as its request - // destination. - EndpointSelectionRandom EndpointSelectionMode = iota - - // If 'SelectionMode' is set to 'EndpointSelectionPrioritizeLeader', - // requests are sent directly to the cluster leader. This reduces - // forwarding roundtrips compared to making requests to etcd followers - // who then forward them to the cluster leader. In the event of a leader - // failure, however, clients configured this way cannot prioritize among - // the remaining etcd followers. Therefore, when a client sets 'SelectionMode' - // to 'EndpointSelectionPrioritizeLeader', it must use 'client.AutoSync()' to - // maintain its knowledge of current cluster state. - // - // This mode should be used with Client.AutoSync(). - EndpointSelectionPrioritizeLeader -) - -type Config struct { - // Endpoints defines a set of URLs (schemes, hosts and ports only) - // that can be used to communicate with a logical etcd cluster. For - // example, a three-node cluster could be provided like so: - // - // Endpoints: []string{ - // "http://node1.example.com:2379", - // "http://node2.example.com:2379", - // "http://node3.example.com:2379", - // } - // - // If multiple endpoints are provided, the Client will attempt to - // use them all in the event that one or more of them are unusable. - // - // If Client.Sync is ever called, the Client may cache an alternate - // set of endpoints to continue operation. - Endpoints []string - - // Transport is used by the Client to drive HTTP requests. If not - // provided, DefaultTransport will be used. - Transport CancelableTransport - - // CheckRedirect specifies the policy for handling HTTP redirects. - // If CheckRedirect is not nil, the Client calls it before - // following an HTTP redirect. The sole argument is the number of - // requests that have already been made. If CheckRedirect returns - // an error, Client.Do will not make any further requests and return - // the error back it to the caller. - // - // If CheckRedirect is nil, the Client uses its default policy, - // which is to stop after 10 consecutive requests. - CheckRedirect CheckRedirectFunc - - // Username specifies the user credential to add as an authorization header - Username string - - // Password is the password for the specified user to add as an authorization header - // to the request. - Password string - - // HeaderTimeoutPerRequest specifies the time limit to wait for response - // header in a single request made by the Client. The timeout includes - // connection time, any redirects, and header wait time. - // - // For non-watch GET request, server returns the response body immediately. - // For PUT/POST/DELETE request, server will attempt to commit request - // before responding, which is expected to take `100ms + 2 * RTT`. - // For watch request, server returns the header immediately to notify Client - // watch start. But if server is behind some kind of proxy, the response - // header may be cached at proxy, and Client cannot rely on this behavior. - // - // Especially, wait request will ignore this timeout. - // - // One API call may send multiple requests to different etcd servers until it - // succeeds. Use context of the API to specify the overall timeout. - // - // A HeaderTimeoutPerRequest of zero means no timeout. - HeaderTimeoutPerRequest time.Duration - - // SelectionMode is an EndpointSelectionMode enum that specifies the - // policy for choosing the etcd cluster node to which requests are sent. - SelectionMode EndpointSelectionMode -} - -func (cfg *Config) transport() CancelableTransport { - if cfg.Transport == nil { - return DefaultTransport - } - return cfg.Transport -} - -func (cfg *Config) checkRedirect() CheckRedirectFunc { - if cfg.CheckRedirect == nil { - return DefaultCheckRedirect - } - return cfg.CheckRedirect -} - -// CancelableTransport mimics net/http.Transport, but requires that -// the object also support request cancellation. -type CancelableTransport interface { - http.RoundTripper - CancelRequest(req *http.Request) -} - -type CheckRedirectFunc func(via int) error - -// DefaultCheckRedirect follows up to 10 redirects, but no more. -var DefaultCheckRedirect CheckRedirectFunc = func(via int) error { - if via > 10 { - return ErrTooManyRedirects - } - return nil -} - -type Client interface { - // Sync updates the internal cache of the etcd cluster's membership. - Sync(context.Context) error - - // AutoSync periodically calls Sync() every given interval. - // The recommended sync interval is 10 seconds to 1 minute, which does - // not bring too much overhead to server and makes client catch up the - // cluster change in time. - // - // The example to use it: - // - // for { - // err := client.AutoSync(ctx, 10*time.Second) - // if err == context.DeadlineExceeded || err == context.Canceled { - // break - // } - // log.Print(err) - // } - AutoSync(context.Context, time.Duration) error - - // Endpoints returns a copy of the current set of API endpoints used - // by Client to resolve HTTP requests. If Sync has ever been called, - // this may differ from the initial Endpoints provided in the Config. - Endpoints() []string - - // SetEndpoints sets the set of API endpoints used by Client to resolve - // HTTP requests. If the given endpoints are not valid, an error will be - // returned - SetEndpoints(eps []string) error - - // GetVersion retrieves the current etcd server and cluster version - GetVersion(ctx context.Context) (*version.Versions, error) - - httpClient -} - -func New(cfg Config) (Client, error) { - c := &httpClusterClient{ - clientFactory: newHTTPClientFactory(cfg.transport(), cfg.checkRedirect(), cfg.HeaderTimeoutPerRequest), - rand: rand.New(rand.NewSource(int64(time.Now().Nanosecond()))), - selectionMode: cfg.SelectionMode, - } - if cfg.Username != "" { - c.credentials = &credentials{ - username: cfg.Username, - password: cfg.Password, - } - } - if err := c.SetEndpoints(cfg.Endpoints); err != nil { - return nil, err - } - return c, nil -} - -type httpClient interface { - Do(context.Context, httpAction) (*http.Response, []byte, error) -} - -func newHTTPClientFactory(tr CancelableTransport, cr CheckRedirectFunc, headerTimeout time.Duration) httpClientFactory { - return func(ep url.URL) httpClient { - return &redirectFollowingHTTPClient{ - checkRedirect: cr, - client: &simpleHTTPClient{ - transport: tr, - endpoint: ep, - headerTimeout: headerTimeout, - }, - } - } -} - -type credentials struct { - username string - password string -} - -type httpClientFactory func(url.URL) httpClient - -type httpAction interface { - HTTPRequest(url.URL) *http.Request -} - -type httpClusterClient struct { - clientFactory httpClientFactory - endpoints []url.URL - pinned int - credentials *credentials - sync.RWMutex - rand *rand.Rand - selectionMode EndpointSelectionMode -} - -func (c *httpClusterClient) getLeaderEndpoint(ctx context.Context, eps []url.URL) (string, error) { - ceps := make([]url.URL, len(eps)) - copy(ceps, eps) - - // To perform a lookup on the new endpoint list without using the current - // client, we'll copy it - clientCopy := &httpClusterClient{ - clientFactory: c.clientFactory, - credentials: c.credentials, - rand: c.rand, - - pinned: 0, - endpoints: ceps, - } - - mAPI := NewMembersAPI(clientCopy) - leader, err := mAPI.Leader(ctx) - if err != nil { - return "", err - } - if len(leader.ClientURLs) == 0 { - return "", ErrNoLeaderEndpoint - } - - return leader.ClientURLs[0], nil // TODO: how to handle multiple client URLs? -} - -func (c *httpClusterClient) parseEndpoints(eps []string) ([]url.URL, error) { - if len(eps) == 0 { - return []url.URL{}, ErrNoEndpoints - } - - neps := make([]url.URL, len(eps)) - for i, ep := range eps { - u, err := url.Parse(ep) - if err != nil { - return []url.URL{}, err - } - neps[i] = *u - } - return neps, nil -} - -func (c *httpClusterClient) SetEndpoints(eps []string) error { - neps, err := c.parseEndpoints(eps) - if err != nil { - return err - } - - c.Lock() - defer c.Unlock() - - c.endpoints = shuffleEndpoints(c.rand, neps) - // We're not doing anything for PrioritizeLeader here. This is - // due to not having a context meaning we can't call getLeaderEndpoint - // However, if you're using PrioritizeLeader, you've already been told - // to regularly call sync, where we do have a ctx, and can figure the - // leader. PrioritizeLeader is also quite a loose guarantee, so deal - // with it - c.pinned = 0 - - return nil -} - -func (c *httpClusterClient) Do(ctx context.Context, act httpAction) (*http.Response, []byte, error) { - action := act - c.RLock() - leps := len(c.endpoints) - eps := make([]url.URL, leps) - n := copy(eps, c.endpoints) - pinned := c.pinned - - if c.credentials != nil { - action = &authedAction{ - act: act, - credentials: *c.credentials, - } - } - c.RUnlock() - - if leps == 0 { - return nil, nil, ErrNoEndpoints - } - - if leps != n { - return nil, nil, errors.New("unable to pick endpoint: copy failed") - } - - var resp *http.Response - var body []byte - var err error - cerr := &ClusterError{} - isOneShot := ctx.Value(&oneShotCtxValue) != nil - - for i := pinned; i < leps+pinned; i++ { - k := i % leps - hc := c.clientFactory(eps[k]) - resp, body, err = hc.Do(ctx, action) - if err != nil { - cerr.Errors = append(cerr.Errors, err) - if err == ctx.Err() { - return nil, nil, ctx.Err() - } - if err == context.Canceled || err == context.DeadlineExceeded { - return nil, nil, err - } - } else if resp.StatusCode/100 == 5 { - switch resp.StatusCode { - case http.StatusInternalServerError, http.StatusServiceUnavailable: - // TODO: make sure this is a no leader response - cerr.Errors = append(cerr.Errors, fmt.Errorf("client: etcd member %s has no leader", eps[k].String())) - default: - cerr.Errors = append(cerr.Errors, fmt.Errorf("client: etcd member %s returns server error [%s]", eps[k].String(), http.StatusText(resp.StatusCode))) - } - err = cerr.Errors[0] - } - if err != nil { - if !isOneShot { - continue - } - c.Lock() - c.pinned = (k + 1) % leps - c.Unlock() - return nil, nil, err - } - if k != pinned { - c.Lock() - c.pinned = k - c.Unlock() - } - return resp, body, nil - } - - return nil, nil, cerr -} - -func (c *httpClusterClient) Endpoints() []string { - c.RLock() - defer c.RUnlock() - - eps := make([]string, len(c.endpoints)) - for i, ep := range c.endpoints { - eps[i] = ep.String() - } - - return eps -} - -func (c *httpClusterClient) Sync(ctx context.Context) error { - mAPI := NewMembersAPI(c) - ms, err := mAPI.List(ctx) - if err != nil { - return err - } - - var eps []string - for _, m := range ms { - eps = append(eps, m.ClientURLs...) - } - - neps, err := c.parseEndpoints(eps) - if err != nil { - return err - } - - npin := 0 - - switch c.selectionMode { - case EndpointSelectionRandom: - c.RLock() - eq := endpointsEqual(c.endpoints, neps) - c.RUnlock() - - if eq { - return nil - } - // When items in the endpoint list changes, we choose a new pin - neps = shuffleEndpoints(c.rand, neps) - case EndpointSelectionPrioritizeLeader: - nle, err := c.getLeaderEndpoint(ctx, neps) - if err != nil { - return ErrNoLeaderEndpoint - } - - for i, n := range neps { - if n.String() == nle { - npin = i - break - } - } - default: - return fmt.Errorf("invalid endpoint selection mode: %d", c.selectionMode) - } - - c.Lock() - defer c.Unlock() - c.endpoints = neps - c.pinned = npin - - return nil -} - -func (c *httpClusterClient) AutoSync(ctx context.Context, interval time.Duration) error { - ticker := time.NewTicker(interval) - defer ticker.Stop() - for { - err := c.Sync(ctx) - if err != nil { - return err - } - select { - case <-ctx.Done(): - return ctx.Err() - case <-ticker.C: - } - } -} - -func (c *httpClusterClient) GetVersion(ctx context.Context) (*version.Versions, error) { - act := &getAction{Prefix: "/version"} - - resp, body, err := c.Do(ctx, act) - if err != nil { - return nil, err - } - - switch resp.StatusCode { - case http.StatusOK: - if len(body) == 0 { - return nil, ErrEmptyBody - } - var vresp version.Versions - if err := json.Unmarshal(body, &vresp); err != nil { - return nil, ErrInvalidJSON - } - return &vresp, nil - default: - var etcdErr Error - if err := json.Unmarshal(body, &etcdErr); err != nil { - return nil, ErrInvalidJSON - } - return nil, etcdErr - } -} - -type roundTripResponse struct { - resp *http.Response - err error -} - -type simpleHTTPClient struct { - transport CancelableTransport - endpoint url.URL - headerTimeout time.Duration -} - -// ErrNoRequest indicates that the HTTPRequest object could not be found -// or was nil. No processing could continue. -var ErrNoRequest = errors.New("no HTTPRequest was available") - -func (c *simpleHTTPClient) Do(ctx context.Context, act httpAction) (*http.Response, []byte, error) { - req := act.HTTPRequest(c.endpoint) - if req == nil { - return nil, nil, ErrNoRequest - } - - if err := printcURL(req); err != nil { - return nil, nil, err - } - - isWait := false - if req.URL != nil { - ws := req.URL.Query().Get("wait") - if len(ws) != 0 { - var err error - isWait, err = strconv.ParseBool(ws) - if err != nil { - return nil, nil, fmt.Errorf("wrong wait value %s (%v for %+v)", ws, err, req) - } - } - } - - var hctx context.Context - var hcancel context.CancelFunc - if !isWait && c.headerTimeout > 0 { - hctx, hcancel = context.WithTimeout(ctx, c.headerTimeout) - } else { - hctx, hcancel = context.WithCancel(ctx) - } - defer hcancel() - - reqcancel := requestCanceler(c.transport, req) - - rtchan := make(chan roundTripResponse, 1) - go func() { - resp, err := c.transport.RoundTrip(req) - rtchan <- roundTripResponse{resp: resp, err: err} - close(rtchan) - }() - - var resp *http.Response - var err error - - select { - case rtresp := <-rtchan: - resp, err = rtresp.resp, rtresp.err - case <-hctx.Done(): - // cancel and wait for request to actually exit before continuing - reqcancel() - rtresp := <-rtchan - resp = rtresp.resp - switch { - case ctx.Err() != nil: - err = ctx.Err() - case hctx.Err() != nil: - err = fmt.Errorf("client: endpoint %s exceeded header timeout", c.endpoint.String()) - default: - panic("failed to get error from context") - } - } - - // always check for resp nil-ness to deal with possible - // race conditions between channels above - defer func() { - if resp != nil { - resp.Body.Close() - } - }() - - if err != nil { - return nil, nil, err - } - - var body []byte - done := make(chan struct{}) - go func() { - body, err = ioutil.ReadAll(resp.Body) - done <- struct{}{} - }() - - select { - case <-ctx.Done(): - resp.Body.Close() - <-done - return nil, nil, ctx.Err() - case <-done: - } - - return resp, body, err -} - -type authedAction struct { - act httpAction - credentials credentials -} - -func (a *authedAction) HTTPRequest(url url.URL) *http.Request { - r := a.act.HTTPRequest(url) - r.SetBasicAuth(a.credentials.username, a.credentials.password) - return r -} - -type redirectFollowingHTTPClient struct { - client httpClient - checkRedirect CheckRedirectFunc -} - -func (r *redirectFollowingHTTPClient) Do(ctx context.Context, act httpAction) (*http.Response, []byte, error) { - next := act - for i := 0; i < 100; i++ { - if i > 0 { - if err := r.checkRedirect(i); err != nil { - return nil, nil, err - } - } - resp, body, err := r.client.Do(ctx, next) - if err != nil { - return nil, nil, err - } - if resp.StatusCode/100 == 3 { - hdr := resp.Header.Get("Location") - if hdr == "" { - return nil, nil, fmt.Errorf("location header not set") - } - loc, err := url.Parse(hdr) - if err != nil { - return nil, nil, fmt.Errorf("location header not valid URL: %s", hdr) - } - next = &redirectedHTTPAction{ - action: act, - location: *loc, - } - continue - } - return resp, body, nil - } - - return nil, nil, errTooManyRedirectChecks -} - -type redirectedHTTPAction struct { - action httpAction - location url.URL -} - -func (r *redirectedHTTPAction) HTTPRequest(ep url.URL) *http.Request { - orig := r.action.HTTPRequest(ep) - orig.URL = &r.location - return orig -} - -func shuffleEndpoints(r *rand.Rand, eps []url.URL) []url.URL { - // copied from Go 1.9<= rand.Rand.Perm - n := len(eps) - p := make([]int, n) - for i := 0; i < n; i++ { - j := r.Intn(i + 1) - p[i] = p[j] - p[j] = i - } - neps := make([]url.URL, n) - for i, k := range p { - neps[i] = eps[k] - } - return neps -} - -func endpointsEqual(left, right []url.URL) bool { - if len(left) != len(right) { - return false - } - - sLeft := make([]string, len(left)) - sRight := make([]string, len(right)) - for i, l := range left { - sLeft[i] = l.String() - } - for i, r := range right { - sRight[i] = r.String() - } - - sort.Strings(sLeft) - sort.Strings(sRight) - for i := range sLeft { - if sLeft[i] != sRight[i] { - return false - } - } - return true -} diff --git a/vendor/go.etcd.io/etcd/client/v2/cluster_error.go b/vendor/go.etcd.io/etcd/client/v2/cluster_error.go deleted file mode 100644 index 34618cdbd9..0000000000 --- a/vendor/go.etcd.io/etcd/client/v2/cluster_error.go +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package client - -import "fmt" - -type ClusterError struct { - Errors []error -} - -func (ce *ClusterError) Error() string { - s := ErrClusterUnavailable.Error() - for i, e := range ce.Errors { - s += fmt.Sprintf("; error #%d: %s\n", i, e) - } - return s -} - -func (ce *ClusterError) Detail() string { - s := "" - for i, e := range ce.Errors { - s += fmt.Sprintf("error #%d: %s\n", i, e) - } - return s -} diff --git a/vendor/go.etcd.io/etcd/client/v2/curl.go b/vendor/go.etcd.io/etcd/client/v2/curl.go deleted file mode 100644 index c8bc9fba20..0000000000 --- a/vendor/go.etcd.io/etcd/client/v2/curl.go +++ /dev/null @@ -1,70 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package client - -import ( - "bytes" - "fmt" - "io/ioutil" - "net/http" - "os" -) - -var ( - cURLDebug = false -) - -func EnablecURLDebug() { - cURLDebug = true -} - -func DisablecURLDebug() { - cURLDebug = false -} - -// printcURL prints the cURL equivalent request to stderr. -// It returns an error if the body of the request cannot -// be read. -// The caller MUST cancel the request if there is an error. -func printcURL(req *http.Request) error { - if !cURLDebug { - return nil - } - var ( - command string - b []byte - err error - ) - - if req.URL != nil { - command = fmt.Sprintf("curl -X %s %s", req.Method, req.URL.String()) - } - - if req.Body != nil { - b, err = ioutil.ReadAll(req.Body) - if err != nil { - return err - } - command += fmt.Sprintf(" -d %q", string(b)) - } - - fmt.Fprintf(os.Stderr, "cURL Command: %s\n", command) - - // reset body - body := bytes.NewBuffer(b) - req.Body = ioutil.NopCloser(body) - - return nil -} diff --git a/vendor/go.etcd.io/etcd/client/v2/discover.go b/vendor/go.etcd.io/etcd/client/v2/discover.go deleted file mode 100644 index 646ba5dada..0000000000 --- a/vendor/go.etcd.io/etcd/client/v2/discover.go +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package client - -import ( - "go.etcd.io/etcd/client/pkg/v3/srv" -) - -// Discoverer is an interface that wraps the Discover method. -type Discoverer interface { - // Discover looks up the etcd servers for the domain. - Discover(domain string, serviceName string) ([]string, error) -} - -type srvDiscover struct{} - -// NewSRVDiscover constructs a new Discoverer that uses the stdlib to lookup SRV records. -func NewSRVDiscover() Discoverer { - return &srvDiscover{} -} - -func (d *srvDiscover) Discover(domain string, serviceName string) ([]string, error) { - srvs, err := srv.GetClient("etcd-client", domain, serviceName) - if err != nil { - return nil, err - } - return srvs.Endpoints, nil -} diff --git a/vendor/go.etcd.io/etcd/client/v2/doc.go b/vendor/go.etcd.io/etcd/client/v2/doc.go deleted file mode 100644 index 5250758b01..0000000000 --- a/vendor/go.etcd.io/etcd/client/v2/doc.go +++ /dev/null @@ -1,73 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/* -Package client provides bindings for the etcd APIs. - -Create a Config and exchange it for a Client: - - import ( - "net/http" - "context" - - "go.etcd.io/etcd/client/v2" - ) - - cfg := client.Config{ - Endpoints: []string{"http://127.0.0.1:2379"}, - Transport: DefaultTransport, - } - - c, err := client.New(cfg) - if err != nil { - // handle error - } - -Clients are safe for concurrent use by multiple goroutines. - -Create a KeysAPI using the Client, then use it to interact with etcd: - - kAPI := client.NewKeysAPI(c) - - // create a new key /foo with the value "bar" - _, err = kAPI.Create(context.Background(), "/foo", "bar") - if err != nil { - // handle error - } - - // delete the newly created key only if the value is still "bar" - _, err = kAPI.Delete(context.Background(), "/foo", &DeleteOptions{PrevValue: "bar"}) - if err != nil { - // handle error - } - -Use a custom context to set timeouts on your operations: - - import "time" - - ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) - defer cancel() - - // set a new key, ignoring its previous state - _, err := kAPI.Set(ctx, "/ping", "pong", nil) - if err != nil { - if err == context.DeadlineExceeded { - // request took longer than 5s - } else { - // handle error - } - } - -*/ -package client diff --git a/vendor/go.etcd.io/etcd/client/v2/go.mod b/vendor/go.etcd.io/etcd/client/v2/go.mod deleted file mode 100644 index e63dfc927b..0000000000 --- a/vendor/go.etcd.io/etcd/client/v2/go.mod +++ /dev/null @@ -1,24 +0,0 @@ -module go.etcd.io/etcd/client/v2 - -go 1.16 - -require ( - github.com/json-iterator/go v1.1.11 - github.com/modern-go/reflect2 v1.0.1 - go.etcd.io/etcd/api/v3 v3.5.0 - go.etcd.io/etcd/client/pkg/v3 v3.5.0 -) - -replace ( - go.etcd.io/etcd/api/v3 => ../../api - go.etcd.io/etcd/client/pkg/v3 => ../pkg -) - -// Bad imports are sometimes causing attempts to pull that code. -// This makes the error more explicit. -replace ( - go.etcd.io/etcd => ./FORBIDDEN_DEPENDENCY - go.etcd.io/etcd/pkg/v3 => ./FORBIDDED_DEPENDENCY - go.etcd.io/etcd/tests/v3 => ./FORBIDDEN_DEPENDENCY - go.etcd.io/etcd/v3 => ./FORBIDDEN_DEPENDENCY -) diff --git a/vendor/go.etcd.io/etcd/client/v2/go.sum b/vendor/go.etcd.io/etcd/client/v2/go.sum deleted file mode 100644 index 93dd93b2d4..0000000000 --- a/vendor/go.etcd.io/etcd/client/v2/go.sum +++ /dev/null @@ -1,163 +0,0 @@ -cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= -github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= -github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= -github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= -github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= -github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= -github.com/coreos/go-semver v0.3.0 h1:wkHLiw0WNATZnSG7epLsujiMCgPAc9xhjJ4tgnAxmfM= -github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= -github.com/coreos/go-systemd/v22 v22.3.2/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= -github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= -github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= -github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= -github.com/envoyproxy/go-control-plane v0.9.9-0.20210217033140-668b12f5399d/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk= -github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= -github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= -github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= -github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= -github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= -github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= -github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= -github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= -github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= -github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= -github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= -github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= -github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= -github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= -github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= -github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= -github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= -github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= -github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= -github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= -github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= -github.com/json-iterator/go v1.1.11 h1:uVUAXhF2To8cbw/3xN3pxj6kk7TYKs98NIrTqPlMWAQ= -github.com/json-iterator/go v1.1.11/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= -github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= -github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= -github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc= -github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= -github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= -github.com/modern-go/reflect2 v1.0.1 h1:9f412s+6RmYXLWZSEzVVgPGK7C2PphHj5RJrvfx9AWI= -github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= -github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= -github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= -github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= -github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= -github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= -github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= -github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= -go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= -go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU= -go.uber.org/zap v1.17.0/go.mod h1:MXVU+bhUf/A7Xi2HNOnopQOrmycQ5Ih87HtOu4q5SSo= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= -golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= -golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= -golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= -golang.org/x/lint v0.0.0-20210508222113-6edffad5e616/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= -golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= -golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= -golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= -golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= -golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= -golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= -golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210403161142-5e06dd20ab57/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= -golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= -golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= -golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= -golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= -golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= -golang.org/x/tools v0.1.2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= -golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= -google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= -google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= -google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= -google.golang.org/genproto v0.0.0-20200513103714-09dca8ec2884/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= -google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= -google.golang.org/genproto v0.0.0-20210602131652-f16073e35f0c/go.mod h1:UODoCrxHCcBojKKwX1terBiRUaqAsFqJiF615XL43r0= -google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= -google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= -google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= -google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= -google.golang.org/grpc v1.33.1/go.mod h1:fr5YgcSWrqhRRxogOsw7RzIpsmvOZ6IcH4kBYTpR3n0= -google.golang.org/grpc v1.38.0/go.mod h1:NREThFqKR1f3iQ6oBuvc5LadQuXVGo9rkm5ZGrQdJfM= -google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= -google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= -google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= -google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= -google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= -google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= -google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= -google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= -google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= -google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= -google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10= -gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo= -gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= -honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/vendor/go.etcd.io/etcd/client/v2/json.go b/vendor/go.etcd.io/etcd/client/v2/json.go deleted file mode 100644 index d5be690a17..0000000000 --- a/vendor/go.etcd.io/etcd/client/v2/json.go +++ /dev/null @@ -1,73 +0,0 @@ -// Copyright 2019 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package client - -import ( - "strconv" - "unsafe" - - "github.com/json-iterator/go" - "github.com/modern-go/reflect2" -) - -type customNumberExtension struct { - jsoniter.DummyExtension -} - -func (cne *customNumberExtension) CreateDecoder(typ reflect2.Type) jsoniter.ValDecoder { - if typ.String() == "interface {}" { - return customNumberDecoder{} - } - return nil -} - -type customNumberDecoder struct { -} - -func (customNumberDecoder) Decode(ptr unsafe.Pointer, iter *jsoniter.Iterator) { - switch iter.WhatIsNext() { - case jsoniter.NumberValue: - var number jsoniter.Number - iter.ReadVal(&number) - i64, err := strconv.ParseInt(string(number), 10, 64) - if err == nil { - *(*interface{})(ptr) = i64 - return - } - f64, err := strconv.ParseFloat(string(number), 64) - if err == nil { - *(*interface{})(ptr) = f64 - return - } - iter.ReportError("DecodeNumber", err.Error()) - default: - *(*interface{})(ptr) = iter.Read() - } -} - -// caseSensitiveJsonIterator returns a jsoniterator API that's configured to be -// case-sensitive when unmarshalling, and otherwise compatible with -// the encoding/json standard library. -func caseSensitiveJsonIterator() jsoniter.API { - config := jsoniter.Config{ - EscapeHTML: true, - SortMapKeys: true, - ValidateJsonRawMessage: true, - CaseSensitive: true, - }.Froze() - // Force jsoniter to decode number to interface{} via int64/float64, if possible. - config.RegisterExtension(&customNumberExtension{}) - return config -} diff --git a/vendor/go.etcd.io/etcd/client/v2/keys.go b/vendor/go.etcd.io/etcd/client/v2/keys.go deleted file mode 100644 index e8f1664617..0000000000 --- a/vendor/go.etcd.io/etcd/client/v2/keys.go +++ /dev/null @@ -1,680 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package client - -import ( - "context" - "encoding/json" - "errors" - "fmt" - "net/http" - "net/url" - "strconv" - "strings" - "time" - - "go.etcd.io/etcd/client/pkg/v3/pathutil" -) - -const ( - ErrorCodeKeyNotFound = 100 - ErrorCodeTestFailed = 101 - ErrorCodeNotFile = 102 - ErrorCodeNotDir = 104 - ErrorCodeNodeExist = 105 - ErrorCodeRootROnly = 107 - ErrorCodeDirNotEmpty = 108 - ErrorCodeUnauthorized = 110 - - ErrorCodePrevValueRequired = 201 - ErrorCodeTTLNaN = 202 - ErrorCodeIndexNaN = 203 - ErrorCodeInvalidField = 209 - ErrorCodeInvalidForm = 210 - - ErrorCodeRaftInternal = 300 - ErrorCodeLeaderElect = 301 - - ErrorCodeWatcherCleared = 400 - ErrorCodeEventIndexCleared = 401 -) - -type Error struct { - Code int `json:"errorCode"` - Message string `json:"message"` - Cause string `json:"cause"` - Index uint64 `json:"index"` -} - -func (e Error) Error() string { - return fmt.Sprintf("%v: %v (%v) [%v]", e.Code, e.Message, e.Cause, e.Index) -} - -var ( - ErrInvalidJSON = errors.New("client: response is invalid json. The endpoint is probably not valid etcd cluster endpoint") - ErrEmptyBody = errors.New("client: response body is empty") -) - -// PrevExistType is used to define an existence condition when setting -// or deleting Nodes. -type PrevExistType string - -const ( - PrevIgnore = PrevExistType("") - PrevExist = PrevExistType("true") - PrevNoExist = PrevExistType("false") -) - -var ( - defaultV2KeysPrefix = "/v2/keys" -) - -// NewKeysAPI builds a KeysAPI that interacts with etcd's key-value -// API over HTTP. -func NewKeysAPI(c Client) KeysAPI { - return NewKeysAPIWithPrefix(c, defaultV2KeysPrefix) -} - -// NewKeysAPIWithPrefix acts like NewKeysAPI, but allows the caller -// to provide a custom base URL path. This should only be used in -// very rare cases. -func NewKeysAPIWithPrefix(c Client, p string) KeysAPI { - return &httpKeysAPI{ - client: c, - prefix: p, - } -} - -type KeysAPI interface { - // Get retrieves a set of Nodes from etcd - Get(ctx context.Context, key string, opts *GetOptions) (*Response, error) - - // Set assigns a new value to a Node identified by a given key. The caller - // may define a set of conditions in the SetOptions. If SetOptions.Dir=true - // then value is ignored. - Set(ctx context.Context, key, value string, opts *SetOptions) (*Response, error) - - // Delete removes a Node identified by the given key, optionally destroying - // all of its children as well. The caller may define a set of required - // conditions in an DeleteOptions object. - Delete(ctx context.Context, key string, opts *DeleteOptions) (*Response, error) - - // Create is an alias for Set w/ PrevExist=false - Create(ctx context.Context, key, value string) (*Response, error) - - // CreateInOrder is used to atomically create in-order keys within the given directory. - CreateInOrder(ctx context.Context, dir, value string, opts *CreateInOrderOptions) (*Response, error) - - // Update is an alias for Set w/ PrevExist=true - Update(ctx context.Context, key, value string) (*Response, error) - - // Watcher builds a new Watcher targeted at a specific Node identified - // by the given key. The Watcher may be configured at creation time - // through a WatcherOptions object. The returned Watcher is designed - // to emit events that happen to a Node, and optionally to its children. - Watcher(key string, opts *WatcherOptions) Watcher -} - -type WatcherOptions struct { - // AfterIndex defines the index after-which the Watcher should - // start emitting events. For example, if a value of 5 is - // provided, the first event will have an index >= 6. - // - // Setting AfterIndex to 0 (default) means that the Watcher - // should start watching for events starting at the current - // index, whatever that may be. - AfterIndex uint64 - - // Recursive specifies whether or not the Watcher should emit - // events that occur in children of the given keyspace. If set - // to false (default), events will be limited to those that - // occur for the exact key. - Recursive bool -} - -type CreateInOrderOptions struct { - // TTL defines a period of time after-which the Node should - // expire and no longer exist. Values <= 0 are ignored. Given - // that the zero-value is ignored, TTL cannot be used to set - // a TTL of 0. - TTL time.Duration -} - -type SetOptions struct { - // PrevValue specifies what the current value of the Node must - // be in order for the Set operation to succeed. - // - // Leaving this field empty means that the caller wishes to - // ignore the current value of the Node. This cannot be used - // to compare the Node's current value to an empty string. - // - // PrevValue is ignored if Dir=true - PrevValue string - - // PrevIndex indicates what the current ModifiedIndex of the - // Node must be in order for the Set operation to succeed. - // - // If PrevIndex is set to 0 (default), no comparison is made. - PrevIndex uint64 - - // PrevExist specifies whether the Node must currently exist - // (PrevExist) or not (PrevNoExist). If the caller does not - // care about existence, set PrevExist to PrevIgnore, or simply - // leave it unset. - PrevExist PrevExistType - - // TTL defines a period of time after-which the Node should - // expire and no longer exist. Values <= 0 are ignored. Given - // that the zero-value is ignored, TTL cannot be used to set - // a TTL of 0. - TTL time.Duration - - // Refresh set to true means a TTL value can be updated - // without firing a watch or changing the node value. A - // value must not be provided when refreshing a key. - Refresh bool - - // Dir specifies whether or not this Node should be created as a directory. - Dir bool - - // NoValueOnSuccess specifies whether the response contains the current value of the Node. - // If set, the response will only contain the current value when the request fails. - NoValueOnSuccess bool -} - -type GetOptions struct { - // Recursive defines whether or not all children of the Node - // should be returned. - Recursive bool - - // Sort instructs the server whether or not to sort the Nodes. - // If true, the Nodes are sorted alphabetically by key in - // ascending order (A to z). If false (default), the Nodes will - // not be sorted and the ordering used should not be considered - // predictable. - Sort bool - - // Quorum specifies whether it gets the latest committed value that - // has been applied in quorum of members, which ensures external - // consistency (or linearizability). - Quorum bool -} - -type DeleteOptions struct { - // PrevValue specifies what the current value of the Node must - // be in order for the Delete operation to succeed. - // - // Leaving this field empty means that the caller wishes to - // ignore the current value of the Node. This cannot be used - // to compare the Node's current value to an empty string. - PrevValue string - - // PrevIndex indicates what the current ModifiedIndex of the - // Node must be in order for the Delete operation to succeed. - // - // If PrevIndex is set to 0 (default), no comparison is made. - PrevIndex uint64 - - // Recursive defines whether or not all children of the Node - // should be deleted. If set to true, all children of the Node - // identified by the given key will be deleted. If left unset - // or explicitly set to false, only a single Node will be - // deleted. - Recursive bool - - // Dir specifies whether or not this Node should be removed as a directory. - Dir bool -} - -type Watcher interface { - // Next blocks until an etcd event occurs, then returns a Response - // representing that event. The behavior of Next depends on the - // WatcherOptions used to construct the Watcher. Next is designed to - // be called repeatedly, each time blocking until a subsequent event - // is available. - // - // If the provided context is cancelled, Next will return a non-nil - // error. Any other failures encountered while waiting for the next - // event (connection issues, deserialization failures, etc) will - // also result in a non-nil error. - Next(context.Context) (*Response, error) -} - -type Response struct { - // Action is the name of the operation that occurred. Possible values - // include get, set, delete, update, create, compareAndSwap, - // compareAndDelete and expire. - Action string `json:"action"` - - // Node represents the state of the relevant etcd Node. - Node *Node `json:"node"` - - // PrevNode represents the previous state of the Node. PrevNode is non-nil - // only if the Node existed before the action occurred and the action - // caused a change to the Node. - PrevNode *Node `json:"prevNode"` - - // Index holds the cluster-level index at the time the Response was generated. - // This index is not tied to the Node(s) contained in this Response. - Index uint64 `json:"-"` - - // ClusterID holds the cluster-level ID reported by the server. This - // should be different for different etcd clusters. - ClusterID string `json:"-"` -} - -type Node struct { - // Key represents the unique location of this Node (e.g. "/foo/bar"). - Key string `json:"key"` - - // Dir reports whether node describes a directory. - Dir bool `json:"dir,omitempty"` - - // Value is the current data stored on this Node. If this Node - // is a directory, Value will be empty. - Value string `json:"value"` - - // Nodes holds the children of this Node, only if this Node is a directory. - // This slice of will be arbitrarily deep (children, grandchildren, great- - // grandchildren, etc.) if a recursive Get or Watch request were made. - Nodes Nodes `json:"nodes"` - - // CreatedIndex is the etcd index at-which this Node was created. - CreatedIndex uint64 `json:"createdIndex"` - - // ModifiedIndex is the etcd index at-which this Node was last modified. - ModifiedIndex uint64 `json:"modifiedIndex"` - - // Expiration is the server side expiration time of the key. - Expiration *time.Time `json:"expiration,omitempty"` - - // TTL is the time to live of the key in second. - TTL int64 `json:"ttl,omitempty"` -} - -func (n *Node) String() string { - return fmt.Sprintf("{Key: %s, CreatedIndex: %d, ModifiedIndex: %d, TTL: %d}", n.Key, n.CreatedIndex, n.ModifiedIndex, n.TTL) -} - -// TTLDuration returns the Node's TTL as a time.Duration object -func (n *Node) TTLDuration() time.Duration { - return time.Duration(n.TTL) * time.Second -} - -type Nodes []*Node - -// interfaces for sorting - -func (ns Nodes) Len() int { return len(ns) } -func (ns Nodes) Less(i, j int) bool { return ns[i].Key < ns[j].Key } -func (ns Nodes) Swap(i, j int) { ns[i], ns[j] = ns[j], ns[i] } - -type httpKeysAPI struct { - client httpClient - prefix string -} - -func (k *httpKeysAPI) Set(ctx context.Context, key, val string, opts *SetOptions) (*Response, error) { - act := &setAction{ - Prefix: k.prefix, - Key: key, - Value: val, - } - - if opts != nil { - act.PrevValue = opts.PrevValue - act.PrevIndex = opts.PrevIndex - act.PrevExist = opts.PrevExist - act.TTL = opts.TTL - act.Refresh = opts.Refresh - act.Dir = opts.Dir - act.NoValueOnSuccess = opts.NoValueOnSuccess - } - - doCtx := ctx - if act.PrevExist == PrevNoExist { - doCtx = context.WithValue(doCtx, &oneShotCtxValue, &oneShotCtxValue) - } - resp, body, err := k.client.Do(doCtx, act) - if err != nil { - return nil, err - } - - return unmarshalHTTPResponse(resp.StatusCode, resp.Header, body) -} - -func (k *httpKeysAPI) Create(ctx context.Context, key, val string) (*Response, error) { - return k.Set(ctx, key, val, &SetOptions{PrevExist: PrevNoExist}) -} - -func (k *httpKeysAPI) CreateInOrder(ctx context.Context, dir, val string, opts *CreateInOrderOptions) (*Response, error) { - act := &createInOrderAction{ - Prefix: k.prefix, - Dir: dir, - Value: val, - } - - if opts != nil { - act.TTL = opts.TTL - } - - resp, body, err := k.client.Do(ctx, act) - if err != nil { - return nil, err - } - - return unmarshalHTTPResponse(resp.StatusCode, resp.Header, body) -} - -func (k *httpKeysAPI) Update(ctx context.Context, key, val string) (*Response, error) { - return k.Set(ctx, key, val, &SetOptions{PrevExist: PrevExist}) -} - -func (k *httpKeysAPI) Delete(ctx context.Context, key string, opts *DeleteOptions) (*Response, error) { - act := &deleteAction{ - Prefix: k.prefix, - Key: key, - } - - if opts != nil { - act.PrevValue = opts.PrevValue - act.PrevIndex = opts.PrevIndex - act.Dir = opts.Dir - act.Recursive = opts.Recursive - } - - doCtx := context.WithValue(ctx, &oneShotCtxValue, &oneShotCtxValue) - resp, body, err := k.client.Do(doCtx, act) - if err != nil { - return nil, err - } - - return unmarshalHTTPResponse(resp.StatusCode, resp.Header, body) -} - -func (k *httpKeysAPI) Get(ctx context.Context, key string, opts *GetOptions) (*Response, error) { - act := &getAction{ - Prefix: k.prefix, - Key: key, - } - - if opts != nil { - act.Recursive = opts.Recursive - act.Sorted = opts.Sort - act.Quorum = opts.Quorum - } - - resp, body, err := k.client.Do(ctx, act) - if err != nil { - return nil, err - } - - return unmarshalHTTPResponse(resp.StatusCode, resp.Header, body) -} - -func (k *httpKeysAPI) Watcher(key string, opts *WatcherOptions) Watcher { - act := waitAction{ - Prefix: k.prefix, - Key: key, - } - - if opts != nil { - act.Recursive = opts.Recursive - if opts.AfterIndex > 0 { - act.WaitIndex = opts.AfterIndex + 1 - } - } - - return &httpWatcher{ - client: k.client, - nextWait: act, - } -} - -type httpWatcher struct { - client httpClient - nextWait waitAction -} - -func (hw *httpWatcher) Next(ctx context.Context) (*Response, error) { - for { - httpresp, body, err := hw.client.Do(ctx, &hw.nextWait) - if err != nil { - return nil, err - } - - resp, err := unmarshalHTTPResponse(httpresp.StatusCode, httpresp.Header, body) - if err != nil { - if err == ErrEmptyBody { - continue - } - return nil, err - } - - hw.nextWait.WaitIndex = resp.Node.ModifiedIndex + 1 - return resp, nil - } -} - -// v2KeysURL forms a URL representing the location of a key. -// The endpoint argument represents the base URL of an etcd -// server. The prefix is the path needed to route from the -// provided endpoint's path to the root of the keys API -// (typically "/v2/keys"). -func v2KeysURL(ep url.URL, prefix, key string) *url.URL { - // We concatenate all parts together manually. We cannot use - // path.Join because it does not reserve trailing slash. - // We call CanonicalURLPath to further cleanup the path. - if prefix != "" && prefix[0] != '/' { - prefix = "/" + prefix - } - if key != "" && key[0] != '/' { - key = "/" + key - } - ep.Path = pathutil.CanonicalURLPath(ep.Path + prefix + key) - return &ep -} - -type getAction struct { - Prefix string - Key string - Recursive bool - Sorted bool - Quorum bool -} - -func (g *getAction) HTTPRequest(ep url.URL) *http.Request { - u := v2KeysURL(ep, g.Prefix, g.Key) - - params := u.Query() - params.Set("recursive", strconv.FormatBool(g.Recursive)) - params.Set("sorted", strconv.FormatBool(g.Sorted)) - params.Set("quorum", strconv.FormatBool(g.Quorum)) - u.RawQuery = params.Encode() - - req, _ := http.NewRequest("GET", u.String(), nil) - return req -} - -type waitAction struct { - Prefix string - Key string - WaitIndex uint64 - Recursive bool -} - -func (w *waitAction) HTTPRequest(ep url.URL) *http.Request { - u := v2KeysURL(ep, w.Prefix, w.Key) - - params := u.Query() - params.Set("wait", "true") - params.Set("waitIndex", strconv.FormatUint(w.WaitIndex, 10)) - params.Set("recursive", strconv.FormatBool(w.Recursive)) - u.RawQuery = params.Encode() - - req, _ := http.NewRequest("GET", u.String(), nil) - return req -} - -type setAction struct { - Prefix string - Key string - Value string - PrevValue string - PrevIndex uint64 - PrevExist PrevExistType - TTL time.Duration - Refresh bool - Dir bool - NoValueOnSuccess bool -} - -func (a *setAction) HTTPRequest(ep url.URL) *http.Request { - u := v2KeysURL(ep, a.Prefix, a.Key) - - params := u.Query() - form := url.Values{} - - // we're either creating a directory or setting a key - if a.Dir { - params.Set("dir", strconv.FormatBool(a.Dir)) - } else { - // These options are only valid for setting a key - if a.PrevValue != "" { - params.Set("prevValue", a.PrevValue) - } - form.Add("value", a.Value) - } - - // Options which apply to both setting a key and creating a dir - if a.PrevIndex != 0 { - params.Set("prevIndex", strconv.FormatUint(a.PrevIndex, 10)) - } - if a.PrevExist != PrevIgnore { - params.Set("prevExist", string(a.PrevExist)) - } - if a.TTL > 0 { - form.Add("ttl", strconv.FormatUint(uint64(a.TTL.Seconds()), 10)) - } - - if a.Refresh { - form.Add("refresh", "true") - } - if a.NoValueOnSuccess { - params.Set("noValueOnSuccess", strconv.FormatBool(a.NoValueOnSuccess)) - } - - u.RawQuery = params.Encode() - body := strings.NewReader(form.Encode()) - - req, _ := http.NewRequest("PUT", u.String(), body) - req.Header.Set("Content-Type", "application/x-www-form-urlencoded") - - return req -} - -type deleteAction struct { - Prefix string - Key string - PrevValue string - PrevIndex uint64 - Dir bool - Recursive bool -} - -func (a *deleteAction) HTTPRequest(ep url.URL) *http.Request { - u := v2KeysURL(ep, a.Prefix, a.Key) - - params := u.Query() - if a.PrevValue != "" { - params.Set("prevValue", a.PrevValue) - } - if a.PrevIndex != 0 { - params.Set("prevIndex", strconv.FormatUint(a.PrevIndex, 10)) - } - if a.Dir { - params.Set("dir", "true") - } - if a.Recursive { - params.Set("recursive", "true") - } - u.RawQuery = params.Encode() - - req, _ := http.NewRequest("DELETE", u.String(), nil) - req.Header.Set("Content-Type", "application/x-www-form-urlencoded") - - return req -} - -type createInOrderAction struct { - Prefix string - Dir string - Value string - TTL time.Duration -} - -func (a *createInOrderAction) HTTPRequest(ep url.URL) *http.Request { - u := v2KeysURL(ep, a.Prefix, a.Dir) - - form := url.Values{} - form.Add("value", a.Value) - if a.TTL > 0 { - form.Add("ttl", strconv.FormatUint(uint64(a.TTL.Seconds()), 10)) - } - body := strings.NewReader(form.Encode()) - - req, _ := http.NewRequest("POST", u.String(), body) - req.Header.Set("Content-Type", "application/x-www-form-urlencoded") - return req -} - -func unmarshalHTTPResponse(code int, header http.Header, body []byte) (res *Response, err error) { - switch code { - case http.StatusOK, http.StatusCreated: - if len(body) == 0 { - return nil, ErrEmptyBody - } - res, err = unmarshalSuccessfulKeysResponse(header, body) - default: - err = unmarshalFailedKeysResponse(body) - } - return res, err -} - -var jsonIterator = caseSensitiveJsonIterator() - -func unmarshalSuccessfulKeysResponse(header http.Header, body []byte) (*Response, error) { - var res Response - err := jsonIterator.Unmarshal(body, &res) - if err != nil { - return nil, ErrInvalidJSON - } - if header.Get("X-Etcd-Index") != "" { - res.Index, err = strconv.ParseUint(header.Get("X-Etcd-Index"), 10, 64) - if err != nil { - return nil, err - } - } - res.ClusterID = header.Get("X-Etcd-Cluster-ID") - return &res, nil -} - -func unmarshalFailedKeysResponse(body []byte) error { - var etcdErr Error - if err := json.Unmarshal(body, &etcdErr); err != nil { - return ErrInvalidJSON - } - return etcdErr -} diff --git a/vendor/go.etcd.io/etcd/client/v2/members.go b/vendor/go.etcd.io/etcd/client/v2/members.go deleted file mode 100644 index 5d638487c5..0000000000 --- a/vendor/go.etcd.io/etcd/client/v2/members.go +++ /dev/null @@ -1,303 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package client - -import ( - "bytes" - "context" - "encoding/json" - "fmt" - "net/http" - "net/url" - "path" - - "go.etcd.io/etcd/client/pkg/v3/types" -) - -var ( - defaultV2MembersPrefix = "/v2/members" - defaultLeaderSuffix = "/leader" -) - -type Member struct { - // ID is the unique identifier of this Member. - ID string `json:"id"` - - // Name is a human-readable, non-unique identifier of this Member. - Name string `json:"name"` - - // PeerURLs represents the HTTP(S) endpoints this Member uses to - // participate in etcd's consensus protocol. - PeerURLs []string `json:"peerURLs"` - - // ClientURLs represents the HTTP(S) endpoints on which this Member - // serves its client-facing APIs. - ClientURLs []string `json:"clientURLs"` -} - -type memberCollection []Member - -func (c *memberCollection) UnmarshalJSON(data []byte) error { - d := struct { - Members []Member - }{} - - if err := json.Unmarshal(data, &d); err != nil { - return err - } - - if d.Members == nil { - *c = make([]Member, 0) - return nil - } - - *c = d.Members - return nil -} - -type memberCreateOrUpdateRequest struct { - PeerURLs types.URLs -} - -func (m *memberCreateOrUpdateRequest) MarshalJSON() ([]byte, error) { - s := struct { - PeerURLs []string `json:"peerURLs"` - }{ - PeerURLs: make([]string, len(m.PeerURLs)), - } - - for i, u := range m.PeerURLs { - s.PeerURLs[i] = u.String() - } - - return json.Marshal(&s) -} - -// NewMembersAPI constructs a new MembersAPI that uses HTTP to -// interact with etcd's membership API. -func NewMembersAPI(c Client) MembersAPI { - return &httpMembersAPI{ - client: c, - } -} - -type MembersAPI interface { - // List enumerates the current cluster membership. - List(ctx context.Context) ([]Member, error) - - // Add instructs etcd to accept a new Member into the cluster. - Add(ctx context.Context, peerURL string) (*Member, error) - - // Remove demotes an existing Member out of the cluster. - Remove(ctx context.Context, mID string) error - - // Update instructs etcd to update an existing Member in the cluster. - Update(ctx context.Context, mID string, peerURLs []string) error - - // Leader gets current leader of the cluster - Leader(ctx context.Context) (*Member, error) -} - -type httpMembersAPI struct { - client httpClient -} - -func (m *httpMembersAPI) List(ctx context.Context) ([]Member, error) { - req := &membersAPIActionList{} - resp, body, err := m.client.Do(ctx, req) - if err != nil { - return nil, err - } - - if err := assertStatusCode(resp.StatusCode, http.StatusOK); err != nil { - return nil, err - } - - var mCollection memberCollection - if err := json.Unmarshal(body, &mCollection); err != nil { - return nil, err - } - - return []Member(mCollection), nil -} - -func (m *httpMembersAPI) Add(ctx context.Context, peerURL string) (*Member, error) { - urls, err := types.NewURLs([]string{peerURL}) - if err != nil { - return nil, err - } - - req := &membersAPIActionAdd{peerURLs: urls} - resp, body, err := m.client.Do(ctx, req) - if err != nil { - return nil, err - } - - if err := assertStatusCode(resp.StatusCode, http.StatusCreated, http.StatusConflict); err != nil { - return nil, err - } - - if resp.StatusCode != http.StatusCreated { - var merr membersError - if err := json.Unmarshal(body, &merr); err != nil { - return nil, err - } - return nil, merr - } - - var memb Member - if err := json.Unmarshal(body, &memb); err != nil { - return nil, err - } - - return &memb, nil -} - -func (m *httpMembersAPI) Update(ctx context.Context, memberID string, peerURLs []string) error { - urls, err := types.NewURLs(peerURLs) - if err != nil { - return err - } - - req := &membersAPIActionUpdate{peerURLs: urls, memberID: memberID} - resp, body, err := m.client.Do(ctx, req) - if err != nil { - return err - } - - if err := assertStatusCode(resp.StatusCode, http.StatusNoContent, http.StatusNotFound, http.StatusConflict); err != nil { - return err - } - - if resp.StatusCode != http.StatusNoContent { - var merr membersError - if err := json.Unmarshal(body, &merr); err != nil { - return err - } - return merr - } - - return nil -} - -func (m *httpMembersAPI) Remove(ctx context.Context, memberID string) error { - req := &membersAPIActionRemove{memberID: memberID} - resp, _, err := m.client.Do(ctx, req) - if err != nil { - return err - } - - return assertStatusCode(resp.StatusCode, http.StatusNoContent, http.StatusGone) -} - -func (m *httpMembersAPI) Leader(ctx context.Context) (*Member, error) { - req := &membersAPIActionLeader{} - resp, body, err := m.client.Do(ctx, req) - if err != nil { - return nil, err - } - - if err := assertStatusCode(resp.StatusCode, http.StatusOK); err != nil { - return nil, err - } - - var leader Member - if err := json.Unmarshal(body, &leader); err != nil { - return nil, err - } - - return &leader, nil -} - -type membersAPIActionList struct{} - -func (l *membersAPIActionList) HTTPRequest(ep url.URL) *http.Request { - u := v2MembersURL(ep) - req, _ := http.NewRequest("GET", u.String(), nil) - return req -} - -type membersAPIActionRemove struct { - memberID string -} - -func (d *membersAPIActionRemove) HTTPRequest(ep url.URL) *http.Request { - u := v2MembersURL(ep) - u.Path = path.Join(u.Path, d.memberID) - req, _ := http.NewRequest("DELETE", u.String(), nil) - return req -} - -type membersAPIActionAdd struct { - peerURLs types.URLs -} - -func (a *membersAPIActionAdd) HTTPRequest(ep url.URL) *http.Request { - u := v2MembersURL(ep) - m := memberCreateOrUpdateRequest{PeerURLs: a.peerURLs} - b, _ := json.Marshal(&m) - req, _ := http.NewRequest("POST", u.String(), bytes.NewReader(b)) - req.Header.Set("Content-Type", "application/json") - return req -} - -type membersAPIActionUpdate struct { - memberID string - peerURLs types.URLs -} - -func (a *membersAPIActionUpdate) HTTPRequest(ep url.URL) *http.Request { - u := v2MembersURL(ep) - m := memberCreateOrUpdateRequest{PeerURLs: a.peerURLs} - u.Path = path.Join(u.Path, a.memberID) - b, _ := json.Marshal(&m) - req, _ := http.NewRequest("PUT", u.String(), bytes.NewReader(b)) - req.Header.Set("Content-Type", "application/json") - return req -} - -func assertStatusCode(got int, want ...int) (err error) { - for _, w := range want { - if w == got { - return nil - } - } - return fmt.Errorf("unexpected status code %d", got) -} - -type membersAPIActionLeader struct{} - -func (l *membersAPIActionLeader) HTTPRequest(ep url.URL) *http.Request { - u := v2MembersURL(ep) - u.Path = path.Join(u.Path, defaultLeaderSuffix) - req, _ := http.NewRequest("GET", u.String(), nil) - return req -} - -// v2MembersURL add the necessary path to the provided endpoint -// to route requests to the default v2 members API. -func v2MembersURL(ep url.URL) *url.URL { - ep.Path = path.Join(ep.Path, defaultV2MembersPrefix) - return &ep -} - -type membersError struct { - Message string `json:"message"` - Code int `json:"-"` -} - -func (e membersError) Error() string { - return e.Message -} diff --git a/vendor/go.etcd.io/etcd/client/v2/util.go b/vendor/go.etcd.io/etcd/client/v2/util.go deleted file mode 100644 index 15a8babff4..0000000000 --- a/vendor/go.etcd.io/etcd/client/v2/util.go +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package client - -import ( - "regexp" -) - -var ( - roleNotFoundRegExp *regexp.Regexp - userNotFoundRegExp *regexp.Regexp -) - -func init() { - roleNotFoundRegExp = regexp.MustCompile("auth: Role .* does not exist.") - userNotFoundRegExp = regexp.MustCompile("auth: User .* does not exist.") -} - -// IsKeyNotFound returns true if the error code is ErrorCodeKeyNotFound. -func IsKeyNotFound(err error) bool { - if cErr, ok := err.(Error); ok { - return cErr.Code == ErrorCodeKeyNotFound - } - return false -} - -// IsRoleNotFound returns true if the error means role not found of v2 API. -func IsRoleNotFound(err error) bool { - if ae, ok := err.(authError); ok { - return roleNotFoundRegExp.MatchString(ae.Message) - } - return false -} - -// IsUserNotFound returns true if the error means user not found of v2 API. -func IsUserNotFound(err error) bool { - if ae, ok := err.(authError); ok { - return userNotFoundRegExp.MatchString(ae.Message) - } - return false -} diff --git a/vendor/go.etcd.io/etcd/client/v3/concurrency/doc.go b/vendor/go.etcd.io/etcd/client/v3/concurrency/doc.go deleted file mode 100644 index dcdbf511d1..0000000000 --- a/vendor/go.etcd.io/etcd/client/v3/concurrency/doc.go +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package concurrency implements concurrency operations on top of -// etcd such as distributed locks, barriers, and elections. -package concurrency diff --git a/vendor/go.etcd.io/etcd/client/v3/concurrency/election.go b/vendor/go.etcd.io/etcd/client/v3/concurrency/election.go deleted file mode 100644 index 31e93d2428..0000000000 --- a/vendor/go.etcd.io/etcd/client/v3/concurrency/election.go +++ /dev/null @@ -1,254 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package concurrency - -import ( - "context" - "errors" - "fmt" - - pb "go.etcd.io/etcd/api/v3/etcdserverpb" - "go.etcd.io/etcd/api/v3/mvccpb" - v3 "go.etcd.io/etcd/client/v3" -) - -var ( - ErrElectionNotLeader = errors.New("election: not leader") - ErrElectionNoLeader = errors.New("election: no leader") -) - -type Election struct { - session *Session - - keyPrefix string - - leaderKey string - leaderRev int64 - leaderSession *Session - hdr *pb.ResponseHeader -} - -// NewElection returns a new election on a given key prefix. -func NewElection(s *Session, pfx string) *Election { - return &Election{session: s, keyPrefix: pfx + "/"} -} - -// ResumeElection initializes an election with a known leader. -func ResumeElection(s *Session, pfx string, leaderKey string, leaderRev int64) *Election { - return &Election{ - keyPrefix: pfx, - session: s, - leaderKey: leaderKey, - leaderRev: leaderRev, - leaderSession: s, - } -} - -// Campaign puts a value as eligible for the election on the prefix -// key. -// Multiple sessions can participate in the election for the -// same prefix, but only one can be the leader at a time. -// -// If the context is 'context.TODO()/context.Background()', the Campaign -// will continue to be blocked for other keys to be deleted, unless server -// returns a non-recoverable error (e.g. ErrCompacted). -// Otherwise, until the context is not cancelled or timed-out, Campaign will -// continue to be blocked until it becomes the leader. -func (e *Election) Campaign(ctx context.Context, val string) error { - s := e.session - client := e.session.Client() - - k := fmt.Sprintf("%s%x", e.keyPrefix, s.Lease()) - txn := client.Txn(ctx).If(v3.Compare(v3.CreateRevision(k), "=", 0)) - txn = txn.Then(v3.OpPut(k, val, v3.WithLease(s.Lease()))) - txn = txn.Else(v3.OpGet(k)) - resp, err := txn.Commit() - if err != nil { - return err - } - e.leaderKey, e.leaderRev, e.leaderSession = k, resp.Header.Revision, s - if !resp.Succeeded { - kv := resp.Responses[0].GetResponseRange().Kvs[0] - e.leaderRev = kv.CreateRevision - if string(kv.Value) != val { - if err = e.Proclaim(ctx, val); err != nil { - e.Resign(ctx) - return err - } - } - } - - _, err = waitDeletes(ctx, client, e.keyPrefix, e.leaderRev-1) - if err != nil { - // clean up in case of context cancel - select { - case <-ctx.Done(): - e.Resign(client.Ctx()) - default: - e.leaderSession = nil - } - return err - } - e.hdr = resp.Header - - return nil -} - -// Proclaim lets the leader announce a new value without another election. -func (e *Election) Proclaim(ctx context.Context, val string) error { - if e.leaderSession == nil { - return ErrElectionNotLeader - } - client := e.session.Client() - cmp := v3.Compare(v3.CreateRevision(e.leaderKey), "=", e.leaderRev) - txn := client.Txn(ctx).If(cmp) - txn = txn.Then(v3.OpPut(e.leaderKey, val, v3.WithLease(e.leaderSession.Lease()))) - tresp, terr := txn.Commit() - if terr != nil { - return terr - } - if !tresp.Succeeded { - e.leaderKey = "" - return ErrElectionNotLeader - } - - e.hdr = tresp.Header - return nil -} - -// Resign lets a leader start a new election. -func (e *Election) Resign(ctx context.Context) (err error) { - if e.leaderSession == nil { - return nil - } - client := e.session.Client() - cmp := v3.Compare(v3.CreateRevision(e.leaderKey), "=", e.leaderRev) - resp, err := client.Txn(ctx).If(cmp).Then(v3.OpDelete(e.leaderKey)).Commit() - if err == nil { - e.hdr = resp.Header - } - e.leaderKey = "" - e.leaderSession = nil - return err -} - -// Leader returns the leader value for the current election. -func (e *Election) Leader(ctx context.Context) (*v3.GetResponse, error) { - client := e.session.Client() - resp, err := client.Get(ctx, e.keyPrefix, v3.WithFirstCreate()...) - if err != nil { - return nil, err - } else if len(resp.Kvs) == 0 { - // no leader currently elected - return nil, ErrElectionNoLeader - } - return resp, nil -} - -// Observe returns a channel that reliably observes ordered leader proposals -// as GetResponse values on every current elected leader key. It will not -// necessarily fetch all historical leader updates, but will always post the -// most recent leader value. -// -// The channel closes when the context is canceled or the underlying watcher -// is otherwise disrupted. -func (e *Election) Observe(ctx context.Context) <-chan v3.GetResponse { - retc := make(chan v3.GetResponse) - go e.observe(ctx, retc) - return retc -} - -func (e *Election) observe(ctx context.Context, ch chan<- v3.GetResponse) { - client := e.session.Client() - - defer close(ch) - for { - resp, err := client.Get(ctx, e.keyPrefix, v3.WithFirstCreate()...) - if err != nil { - return - } - - var kv *mvccpb.KeyValue - var hdr *pb.ResponseHeader - - if len(resp.Kvs) == 0 { - cctx, cancel := context.WithCancel(ctx) - // wait for first key put on prefix - opts := []v3.OpOption{v3.WithRev(resp.Header.Revision), v3.WithPrefix()} - wch := client.Watch(cctx, e.keyPrefix, opts...) - for kv == nil { - wr, ok := <-wch - if !ok || wr.Err() != nil { - cancel() - return - } - // only accept puts; a delete will make observe() spin - for _, ev := range wr.Events { - if ev.Type == mvccpb.PUT { - hdr, kv = &wr.Header, ev.Kv - // may have multiple revs; hdr.rev = the last rev - // set to kv's rev in case batch has multiple Puts - hdr.Revision = kv.ModRevision - break - } - } - } - cancel() - } else { - hdr, kv = resp.Header, resp.Kvs[0] - } - - select { - case ch <- v3.GetResponse{Header: hdr, Kvs: []*mvccpb.KeyValue{kv}}: - case <-ctx.Done(): - return - } - - cctx, cancel := context.WithCancel(ctx) - wch := client.Watch(cctx, string(kv.Key), v3.WithRev(hdr.Revision+1)) - keyDeleted := false - for !keyDeleted { - wr, ok := <-wch - if !ok { - cancel() - return - } - for _, ev := range wr.Events { - if ev.Type == mvccpb.DELETE { - keyDeleted = true - break - } - resp.Header = &wr.Header - resp.Kvs = []*mvccpb.KeyValue{ev.Kv} - select { - case ch <- *resp: - case <-cctx.Done(): - cancel() - return - } - } - } - cancel() - } -} - -// Key returns the leader key if elected, empty string otherwise. -func (e *Election) Key() string { return e.leaderKey } - -// Rev returns the leader key's creation revision, if elected. -func (e *Election) Rev() int64 { return e.leaderRev } - -// Header is the response header from the last successful election proposal. -func (e *Election) Header() *pb.ResponseHeader { return e.hdr } diff --git a/vendor/go.etcd.io/etcd/client/v3/concurrency/key.go b/vendor/go.etcd.io/etcd/client/v3/concurrency/key.go deleted file mode 100644 index 20825950f3..0000000000 --- a/vendor/go.etcd.io/etcd/client/v3/concurrency/key.go +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package concurrency - -import ( - "context" - "fmt" - - pb "go.etcd.io/etcd/api/v3/etcdserverpb" - "go.etcd.io/etcd/api/v3/mvccpb" - v3 "go.etcd.io/etcd/client/v3" -) - -func waitDelete(ctx context.Context, client *v3.Client, key string, rev int64) error { - cctx, cancel := context.WithCancel(ctx) - defer cancel() - - var wr v3.WatchResponse - wch := client.Watch(cctx, key, v3.WithRev(rev)) - for wr = range wch { - for _, ev := range wr.Events { - if ev.Type == mvccpb.DELETE { - return nil - } - } - } - if err := wr.Err(); err != nil { - return err - } - if err := ctx.Err(); err != nil { - return err - } - return fmt.Errorf("lost watcher waiting for delete") -} - -// waitDeletes efficiently waits until all keys matching the prefix and no greater -// than the create revision. -func waitDeletes(ctx context.Context, client *v3.Client, pfx string, maxCreateRev int64) (*pb.ResponseHeader, error) { - getOpts := append(v3.WithLastCreate(), v3.WithMaxCreateRev(maxCreateRev)) - for { - resp, err := client.Get(ctx, pfx, getOpts...) - if err != nil { - return nil, err - } - if len(resp.Kvs) == 0 { - return resp.Header, nil - } - lastKey := string(resp.Kvs[0].Key) - if err = waitDelete(ctx, client, lastKey, resp.Header.Revision); err != nil { - return nil, err - } - } -} diff --git a/vendor/go.etcd.io/etcd/client/v3/concurrency/mutex.go b/vendor/go.etcd.io/etcd/client/v3/concurrency/mutex.go deleted file mode 100644 index c3800d6282..0000000000 --- a/vendor/go.etcd.io/etcd/client/v3/concurrency/mutex.go +++ /dev/null @@ -1,167 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package concurrency - -import ( - "context" - "errors" - "fmt" - "sync" - - pb "go.etcd.io/etcd/api/v3/etcdserverpb" - v3 "go.etcd.io/etcd/client/v3" -) - -// ErrLocked is returned by TryLock when Mutex is already locked by another session. -var ErrLocked = errors.New("mutex: Locked by another session") -var ErrSessionExpired = errors.New("mutex: session is expired") - -// Mutex implements the sync Locker interface with etcd -type Mutex struct { - s *Session - - pfx string - myKey string - myRev int64 - hdr *pb.ResponseHeader -} - -func NewMutex(s *Session, pfx string) *Mutex { - return &Mutex{s, pfx + "/", "", -1, nil} -} - -// TryLock locks the mutex if not already locked by another session. -// If lock is held by another session, return immediately after attempting necessary cleanup -// The ctx argument is used for the sending/receiving Txn RPC. -func (m *Mutex) TryLock(ctx context.Context) error { - resp, err := m.tryAcquire(ctx) - if err != nil { - return err - } - // if no key on prefix / the minimum rev is key, already hold the lock - ownerKey := resp.Responses[1].GetResponseRange().Kvs - if len(ownerKey) == 0 || ownerKey[0].CreateRevision == m.myRev { - m.hdr = resp.Header - return nil - } - client := m.s.Client() - // Cannot lock, so delete the key - if _, err := client.Delete(ctx, m.myKey); err != nil { - return err - } - m.myKey = "\x00" - m.myRev = -1 - return ErrLocked -} - -// Lock locks the mutex with a cancelable context. If the context is canceled -// while trying to acquire the lock, the mutex tries to clean its stale lock entry. -func (m *Mutex) Lock(ctx context.Context) error { - resp, err := m.tryAcquire(ctx) - if err != nil { - return err - } - // if no key on prefix / the minimum rev is key, already hold the lock - ownerKey := resp.Responses[1].GetResponseRange().Kvs - if len(ownerKey) == 0 || ownerKey[0].CreateRevision == m.myRev { - m.hdr = resp.Header - return nil - } - client := m.s.Client() - // wait for deletion revisions prior to myKey - // TODO: early termination if the session key is deleted before other session keys with smaller revisions. - _, werr := waitDeletes(ctx, client, m.pfx, m.myRev-1) - // release lock key if wait failed - if werr != nil { - m.Unlock(client.Ctx()) - return werr - } - - // make sure the session is not expired, and the owner key still exists. - gresp, werr := client.Get(ctx, m.myKey) - if werr != nil { - m.Unlock(client.Ctx()) - return werr - } - - if len(gresp.Kvs) == 0 { // is the session key lost? - return ErrSessionExpired - } - m.hdr = gresp.Header - - return nil -} - -func (m *Mutex) tryAcquire(ctx context.Context) (*v3.TxnResponse, error) { - s := m.s - client := m.s.Client() - - m.myKey = fmt.Sprintf("%s%x", m.pfx, s.Lease()) - cmp := v3.Compare(v3.CreateRevision(m.myKey), "=", 0) - // put self in lock waiters via myKey; oldest waiter holds lock - put := v3.OpPut(m.myKey, "", v3.WithLease(s.Lease())) - // reuse key in case this session already holds the lock - get := v3.OpGet(m.myKey) - // fetch current holder to complete uncontended path with only one RPC - getOwner := v3.OpGet(m.pfx, v3.WithFirstCreate()...) - resp, err := client.Txn(ctx).If(cmp).Then(put, getOwner).Else(get, getOwner).Commit() - if err != nil { - return nil, err - } - m.myRev = resp.Header.Revision - if !resp.Succeeded { - m.myRev = resp.Responses[0].GetResponseRange().Kvs[0].CreateRevision - } - return resp, nil -} - -func (m *Mutex) Unlock(ctx context.Context) error { - client := m.s.Client() - if _, err := client.Delete(ctx, m.myKey); err != nil { - return err - } - m.myKey = "\x00" - m.myRev = -1 - return nil -} - -func (m *Mutex) IsOwner() v3.Cmp { - return v3.Compare(v3.CreateRevision(m.myKey), "=", m.myRev) -} - -func (m *Mutex) Key() string { return m.myKey } - -// Header is the response header received from etcd on acquiring the lock. -func (m *Mutex) Header() *pb.ResponseHeader { return m.hdr } - -type lockerMutex struct{ *Mutex } - -func (lm *lockerMutex) Lock() { - client := lm.s.Client() - if err := lm.Mutex.Lock(client.Ctx()); err != nil { - panic(err) - } -} -func (lm *lockerMutex) Unlock() { - client := lm.s.Client() - if err := lm.Mutex.Unlock(client.Ctx()); err != nil { - panic(err) - } -} - -// NewLocker creates a sync.Locker backed by an etcd mutex. -func NewLocker(s *Session, pfx string) sync.Locker { - return &lockerMutex{NewMutex(s, pfx)} -} diff --git a/vendor/go.etcd.io/etcd/client/v3/concurrency/session.go b/vendor/go.etcd.io/etcd/client/v3/concurrency/session.go deleted file mode 100644 index 7143cc4747..0000000000 --- a/vendor/go.etcd.io/etcd/client/v3/concurrency/session.go +++ /dev/null @@ -1,141 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package concurrency - -import ( - "context" - "time" - - v3 "go.etcd.io/etcd/client/v3" -) - -const defaultSessionTTL = 60 - -// Session represents a lease kept alive for the lifetime of a client. -// Fault-tolerant applications may use sessions to reason about liveness. -type Session struct { - client *v3.Client - opts *sessionOptions - id v3.LeaseID - - cancel context.CancelFunc - donec <-chan struct{} -} - -// NewSession gets the leased session for a client. -func NewSession(client *v3.Client, opts ...SessionOption) (*Session, error) { - ops := &sessionOptions{ttl: defaultSessionTTL, ctx: client.Ctx()} - for _, opt := range opts { - opt(ops) - } - - id := ops.leaseID - if id == v3.NoLease { - resp, err := client.Grant(ops.ctx, int64(ops.ttl)) - if err != nil { - return nil, err - } - id = resp.ID - } - - ctx, cancel := context.WithCancel(ops.ctx) - keepAlive, err := client.KeepAlive(ctx, id) - if err != nil || keepAlive == nil { - cancel() - return nil, err - } - - donec := make(chan struct{}) - s := &Session{client: client, opts: ops, id: id, cancel: cancel, donec: donec} - - // keep the lease alive until client error or cancelled context - go func() { - defer close(donec) - for range keepAlive { - // eat messages until keep alive channel closes - } - }() - - return s, nil -} - -// Client is the etcd client that is attached to the session. -func (s *Session) Client() *v3.Client { - return s.client -} - -// Lease is the lease ID for keys bound to the session. -func (s *Session) Lease() v3.LeaseID { return s.id } - -// Done returns a channel that closes when the lease is orphaned, expires, or -// is otherwise no longer being refreshed. -func (s *Session) Done() <-chan struct{} { return s.donec } - -// Orphan ends the refresh for the session lease. This is useful -// in case the state of the client connection is indeterminate (revoke -// would fail) or when transferring lease ownership. -func (s *Session) Orphan() { - s.cancel() - <-s.donec -} - -// Close orphans the session and revokes the session lease. -func (s *Session) Close() error { - s.Orphan() - // if revoke takes longer than the ttl, lease is expired anyway - ctx, cancel := context.WithTimeout(s.opts.ctx, time.Duration(s.opts.ttl)*time.Second) - _, err := s.client.Revoke(ctx, s.id) - cancel() - return err -} - -type sessionOptions struct { - ttl int - leaseID v3.LeaseID - ctx context.Context -} - -// SessionOption configures Session. -type SessionOption func(*sessionOptions) - -// WithTTL configures the session's TTL in seconds. -// If TTL is <= 0, the default 60 seconds TTL will be used. -func WithTTL(ttl int) SessionOption { - return func(so *sessionOptions) { - if ttl > 0 { - so.ttl = ttl - } - } -} - -// WithLease specifies the existing leaseID to be used for the session. -// This is useful in process restart scenario, for example, to reclaim -// leadership from an election prior to restart. -func WithLease(leaseID v3.LeaseID) SessionOption { - return func(so *sessionOptions) { - so.leaseID = leaseID - } -} - -// WithContext assigns a context to the session instead of defaulting to -// using the client context. This is useful for canceling NewSession and -// Close operations immediately without having to close the client. If the -// context is canceled before Close() completes, the session's lease will be -// abandoned and left to expire instead of being revoked. -func WithContext(ctx context.Context) SessionOption { - return func(so *sessionOptions) { - so.ctx = ctx - } -} diff --git a/vendor/go.etcd.io/etcd/client/v3/concurrency/stm.go b/vendor/go.etcd.io/etcd/client/v3/concurrency/stm.go deleted file mode 100644 index ba7303d097..0000000000 --- a/vendor/go.etcd.io/etcd/client/v3/concurrency/stm.go +++ /dev/null @@ -1,387 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package concurrency - -import ( - "context" - "math" - - v3 "go.etcd.io/etcd/client/v3" -) - -// STM is an interface for software transactional memory. -type STM interface { - // Get returns the value for a key and inserts the key in the txn's read set. - // If Get fails, it aborts the transaction with an error, never returning. - Get(key ...string) string - // Put adds a value for a key to the write set. - Put(key, val string, opts ...v3.OpOption) - // Rev returns the revision of a key in the read set. - Rev(key string) int64 - // Del deletes a key. - Del(key string) - - // commit attempts to apply the txn's changes to the server. - commit() *v3.TxnResponse - reset() -} - -// Isolation is an enumeration of transactional isolation levels which -// describes how transactions should interfere and conflict. -type Isolation int - -const ( - // SerializableSnapshot provides serializable isolation and also checks - // for write conflicts. - SerializableSnapshot Isolation = iota - // Serializable reads within the same transaction attempt return data - // from the at the revision of the first read. - Serializable - // RepeatableReads reads within the same transaction attempt always - // return the same data. - RepeatableReads - // ReadCommitted reads keys from any committed revision. - ReadCommitted -) - -// stmError safely passes STM errors through panic to the STM error channel. -type stmError struct{ err error } - -type stmOptions struct { - iso Isolation - ctx context.Context - prefetch []string -} - -type stmOption func(*stmOptions) - -// WithIsolation specifies the transaction isolation level. -func WithIsolation(lvl Isolation) stmOption { - return func(so *stmOptions) { so.iso = lvl } -} - -// WithAbortContext specifies the context for permanently aborting the transaction. -func WithAbortContext(ctx context.Context) stmOption { - return func(so *stmOptions) { so.ctx = ctx } -} - -// WithPrefetch is a hint to prefetch a list of keys before trying to apply. -// If an STM transaction will unconditionally fetch a set of keys, prefetching -// those keys will save the round-trip cost from requesting each key one by one -// with Get(). -func WithPrefetch(keys ...string) stmOption { - return func(so *stmOptions) { so.prefetch = append(so.prefetch, keys...) } -} - -// NewSTM initiates a new STM instance, using serializable snapshot isolation by default. -func NewSTM(c *v3.Client, apply func(STM) error, so ...stmOption) (*v3.TxnResponse, error) { - opts := &stmOptions{ctx: c.Ctx()} - for _, f := range so { - f(opts) - } - if len(opts.prefetch) != 0 { - f := apply - apply = func(s STM) error { - s.Get(opts.prefetch...) - return f(s) - } - } - return runSTM(mkSTM(c, opts), apply) -} - -func mkSTM(c *v3.Client, opts *stmOptions) STM { - switch opts.iso { - case SerializableSnapshot: - s := &stmSerializable{ - stm: stm{client: c, ctx: opts.ctx}, - prefetch: make(map[string]*v3.GetResponse), - } - s.conflicts = func() []v3.Cmp { - return append(s.rset.cmps(), s.wset.cmps(s.rset.first()+1)...) - } - return s - case Serializable: - s := &stmSerializable{ - stm: stm{client: c, ctx: opts.ctx}, - prefetch: make(map[string]*v3.GetResponse), - } - s.conflicts = func() []v3.Cmp { return s.rset.cmps() } - return s - case RepeatableReads: - s := &stm{client: c, ctx: opts.ctx, getOpts: []v3.OpOption{v3.WithSerializable()}} - s.conflicts = func() []v3.Cmp { return s.rset.cmps() } - return s - case ReadCommitted: - s := &stm{client: c, ctx: opts.ctx, getOpts: []v3.OpOption{v3.WithSerializable()}} - s.conflicts = func() []v3.Cmp { return nil } - return s - default: - panic("unsupported stm") - } -} - -type stmResponse struct { - resp *v3.TxnResponse - err error -} - -func runSTM(s STM, apply func(STM) error) (*v3.TxnResponse, error) { - outc := make(chan stmResponse, 1) - go func() { - defer func() { - if r := recover(); r != nil { - e, ok := r.(stmError) - if !ok { - // client apply panicked - panic(r) - } - outc <- stmResponse{nil, e.err} - } - }() - var out stmResponse - for { - s.reset() - if out.err = apply(s); out.err != nil { - break - } - if out.resp = s.commit(); out.resp != nil { - break - } - } - outc <- out - }() - r := <-outc - return r.resp, r.err -} - -// stm implements repeatable-read software transactional memory over etcd -type stm struct { - client *v3.Client - ctx context.Context - // rset holds read key values and revisions - rset readSet - // wset holds overwritten keys and their values - wset writeSet - // getOpts are the opts used for gets - getOpts []v3.OpOption - // conflicts computes the current conflicts on the txn - conflicts func() []v3.Cmp -} - -type stmPut struct { - val string - op v3.Op -} - -type readSet map[string]*v3.GetResponse - -func (rs readSet) add(keys []string, txnresp *v3.TxnResponse) { - for i, resp := range txnresp.Responses { - rs[keys[i]] = (*v3.GetResponse)(resp.GetResponseRange()) - } -} - -// first returns the store revision from the first fetch -func (rs readSet) first() int64 { - ret := int64(math.MaxInt64 - 1) - for _, resp := range rs { - if rev := resp.Header.Revision; rev < ret { - ret = rev - } - } - return ret -} - -// cmps guards the txn from updates to read set -func (rs readSet) cmps() []v3.Cmp { - cmps := make([]v3.Cmp, 0, len(rs)) - for k, rk := range rs { - cmps = append(cmps, isKeyCurrent(k, rk)) - } - return cmps -} - -type writeSet map[string]stmPut - -func (ws writeSet) get(keys ...string) *stmPut { - for _, key := range keys { - if wv, ok := ws[key]; ok { - return &wv - } - } - return nil -} - -// cmps returns a cmp list testing no writes have happened past rev -func (ws writeSet) cmps(rev int64) []v3.Cmp { - cmps := make([]v3.Cmp, 0, len(ws)) - for key := range ws { - cmps = append(cmps, v3.Compare(v3.ModRevision(key), "<", rev)) - } - return cmps -} - -// puts is the list of ops for all pending writes -func (ws writeSet) puts() []v3.Op { - puts := make([]v3.Op, 0, len(ws)) - for _, v := range ws { - puts = append(puts, v.op) - } - return puts -} - -func (s *stm) Get(keys ...string) string { - if wv := s.wset.get(keys...); wv != nil { - return wv.val - } - return respToValue(s.fetch(keys...)) -} - -func (s *stm) Put(key, val string, opts ...v3.OpOption) { - s.wset[key] = stmPut{val, v3.OpPut(key, val, opts...)} -} - -func (s *stm) Del(key string) { s.wset[key] = stmPut{"", v3.OpDelete(key)} } - -func (s *stm) Rev(key string) int64 { - if resp := s.fetch(key); resp != nil && len(resp.Kvs) != 0 { - return resp.Kvs[0].ModRevision - } - return 0 -} - -func (s *stm) commit() *v3.TxnResponse { - txnresp, err := s.client.Txn(s.ctx).If(s.conflicts()...).Then(s.wset.puts()...).Commit() - if err != nil { - panic(stmError{err}) - } - if txnresp.Succeeded { - return txnresp - } - return nil -} - -func (s *stm) fetch(keys ...string) *v3.GetResponse { - if len(keys) == 0 { - return nil - } - ops := make([]v3.Op, len(keys)) - for i, key := range keys { - if resp, ok := s.rset[key]; ok { - return resp - } - ops[i] = v3.OpGet(key, s.getOpts...) - } - txnresp, err := s.client.Txn(s.ctx).Then(ops...).Commit() - if err != nil { - panic(stmError{err}) - } - s.rset.add(keys, txnresp) - return (*v3.GetResponse)(txnresp.Responses[0].GetResponseRange()) -} - -func (s *stm) reset() { - s.rset = make(map[string]*v3.GetResponse) - s.wset = make(map[string]stmPut) -} - -type stmSerializable struct { - stm - prefetch map[string]*v3.GetResponse -} - -func (s *stmSerializable) Get(keys ...string) string { - if wv := s.wset.get(keys...); wv != nil { - return wv.val - } - firstRead := len(s.rset) == 0 - for _, key := range keys { - if resp, ok := s.prefetch[key]; ok { - delete(s.prefetch, key) - s.rset[key] = resp - } - } - resp := s.stm.fetch(keys...) - if firstRead { - // txn's base revision is defined by the first read - s.getOpts = []v3.OpOption{ - v3.WithRev(resp.Header.Revision), - v3.WithSerializable(), - } - } - return respToValue(resp) -} - -func (s *stmSerializable) Rev(key string) int64 { - s.Get(key) - return s.stm.Rev(key) -} - -func (s *stmSerializable) gets() ([]string, []v3.Op) { - keys := make([]string, 0, len(s.rset)) - ops := make([]v3.Op, 0, len(s.rset)) - for k := range s.rset { - keys = append(keys, k) - ops = append(ops, v3.OpGet(k)) - } - return keys, ops -} - -func (s *stmSerializable) commit() *v3.TxnResponse { - keys, getops := s.gets() - txn := s.client.Txn(s.ctx).If(s.conflicts()...).Then(s.wset.puts()...) - // use Else to prefetch keys in case of conflict to save a round trip - txnresp, err := txn.Else(getops...).Commit() - if err != nil { - panic(stmError{err}) - } - if txnresp.Succeeded { - return txnresp - } - // load prefetch with Else data - s.rset.add(keys, txnresp) - s.prefetch = s.rset - s.getOpts = nil - return nil -} - -func isKeyCurrent(k string, r *v3.GetResponse) v3.Cmp { - if len(r.Kvs) != 0 { - return v3.Compare(v3.ModRevision(k), "=", r.Kvs[0].ModRevision) - } - return v3.Compare(v3.ModRevision(k), "=", 0) -} - -func respToValue(resp *v3.GetResponse) string { - if resp == nil || len(resp.Kvs) == 0 { - return "" - } - return string(resp.Kvs[0].Value) -} - -// NewSTMRepeatable is deprecated. -func NewSTMRepeatable(ctx context.Context, c *v3.Client, apply func(STM) error) (*v3.TxnResponse, error) { - return NewSTM(c, apply, WithAbortContext(ctx), WithIsolation(RepeatableReads)) -} - -// NewSTMSerializable is deprecated. -func NewSTMSerializable(ctx context.Context, c *v3.Client, apply func(STM) error) (*v3.TxnResponse, error) { - return NewSTM(c, apply, WithAbortContext(ctx), WithIsolation(Serializable)) -} - -// NewSTMReadCommitted is deprecated. -func NewSTMReadCommitted(ctx context.Context, c *v3.Client, apply func(STM) error) (*v3.TxnResponse, error) { - return NewSTM(c, apply, WithAbortContext(ctx), WithIsolation(ReadCommitted)) -} diff --git a/vendor/go.etcd.io/etcd/pkg/v3/LICENSE b/vendor/go.etcd.io/etcd/pkg/v3/LICENSE deleted file mode 100644 index d645695673..0000000000 --- a/vendor/go.etcd.io/etcd/pkg/v3/LICENSE +++ /dev/null @@ -1,202 +0,0 @@ - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. diff --git a/vendor/go.etcd.io/etcd/pkg/v3/adt/README.md b/vendor/go.etcd.io/etcd/pkg/v3/adt/README.md deleted file mode 100644 index 107c6bcae2..0000000000 --- a/vendor/go.etcd.io/etcd/pkg/v3/adt/README.md +++ /dev/null @@ -1,48 +0,0 @@ - -## Red-Black Tree - -*"Introduction to Algorithms" (Cormen et al, 3rd ed.), Chapter 13* - -1. Every node is either red or black. -2. The root is black. -3. Every leaf (NIL) is black. -4. If a node is red, then both its children are black. -5. For each node, all simple paths from the node to descendant leaves contain the -same number of black nodes. - -For example, - -```go -import ( - "fmt" - - "go.etcd.io/etcd/pkg/v3/adt" -) - -func main() { - ivt := adt.NewIntervalTree() - ivt.Insert(NewInt64Interval(510, 511), 0) - ivt.Insert(NewInt64Interval(82, 83), 0) - ivt.Insert(NewInt64Interval(830, 831), 0) - ... -``` - -After inserting the values `510`, `82`, `830`, `11`, `383`, `647`, `899`, `261`, `410`, `514`, `815`, `888`, `972`, `238`, `292`, `953`. - -![red-black-tree-01-insertion.png](img/red-black-tree-01-insertion.png) - -Deleting the node `514` should not trigger any rebalancing: - -![red-black-tree-02-delete-514.png](img/red-black-tree-02-delete-514.png) - -Deleting the node `11` triggers multiple rotates for rebalancing: - -![red-black-tree-03-delete-11.png](img/red-black-tree-03-delete-11.png) -![red-black-tree-04-delete-11.png](img/red-black-tree-04-delete-11.png) -![red-black-tree-05-delete-11.png](img/red-black-tree-05-delete-11.png) -![red-black-tree-06-delete-11.png](img/red-black-tree-06-delete-11.png) -![red-black-tree-07-delete-11.png](img/red-black-tree-07-delete-11.png) -![red-black-tree-08-delete-11.png](img/red-black-tree-08-delete-11.png) -![red-black-tree-09-delete-11.png](img/red-black-tree-09-delete-11.png) - -Try yourself at https://www.cs.usfca.edu/~galles/visualization/RedBlack.html. diff --git a/vendor/go.etcd.io/etcd/pkg/v3/adt/adt.go b/vendor/go.etcd.io/etcd/pkg/v3/adt/adt.go deleted file mode 100644 index 1a9559145b..0000000000 --- a/vendor/go.etcd.io/etcd/pkg/v3/adt/adt.go +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package adt implements useful abstract data types. -package adt diff --git a/vendor/go.etcd.io/etcd/pkg/v3/adt/interval_tree.go b/vendor/go.etcd.io/etcd/pkg/v3/adt/interval_tree.go deleted file mode 100644 index 74a9aeb141..0000000000 --- a/vendor/go.etcd.io/etcd/pkg/v3/adt/interval_tree.go +++ /dev/null @@ -1,951 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package adt - -import ( - "bytes" - "fmt" - "math" - "strings" -) - -// Comparable is an interface for trichotomic comparisons. -type Comparable interface { - // Compare gives the result of a 3-way comparison - // a.Compare(b) = 1 => a > b - // a.Compare(b) = 0 => a == b - // a.Compare(b) = -1 => a < b - Compare(c Comparable) int -} - -type rbcolor int - -const ( - black rbcolor = iota - red -) - -func (c rbcolor) String() string { - switch c { - case black: - return "black" - case red: - return "red" - default: - panic(fmt.Errorf("unknown color %d", c)) - } -} - -// Interval implements a Comparable interval [begin, end) -// TODO: support different sorts of intervals: (a,b), [a,b], (a, b] -type Interval struct { - Begin Comparable - End Comparable -} - -// Compare on an interval gives == if the interval overlaps. -func (ivl *Interval) Compare(c Comparable) int { - ivl2 := c.(*Interval) - ivbCmpBegin := ivl.Begin.Compare(ivl2.Begin) - ivbCmpEnd := ivl.Begin.Compare(ivl2.End) - iveCmpBegin := ivl.End.Compare(ivl2.Begin) - - // ivl is left of ivl2 - if ivbCmpBegin < 0 && iveCmpBegin <= 0 { - return -1 - } - - // iv is right of iv2 - if ivbCmpEnd >= 0 { - return 1 - } - - return 0 -} - -type intervalNode struct { - // iv is the interval-value pair entry. - iv IntervalValue - // max endpoint of all descendent nodes. - max Comparable - // left and right are sorted by low endpoint of key interval - left, right *intervalNode - // parent is the direct ancestor of the node - parent *intervalNode - c rbcolor -} - -func (x *intervalNode) color(sentinel *intervalNode) rbcolor { - if x == sentinel { - return black - } - return x.c -} - -func (x *intervalNode) height(sentinel *intervalNode) int { - if x == sentinel { - return 0 - } - ld := x.left.height(sentinel) - rd := x.right.height(sentinel) - if ld < rd { - return rd + 1 - } - return ld + 1 -} - -func (x *intervalNode) min(sentinel *intervalNode) *intervalNode { - for x.left != sentinel { - x = x.left - } - return x -} - -// successor is the next in-order node in the tree -func (x *intervalNode) successor(sentinel *intervalNode) *intervalNode { - if x.right != sentinel { - return x.right.min(sentinel) - } - y := x.parent - for y != sentinel && x == y.right { - x = y - y = y.parent - } - return y -} - -// updateMax updates the maximum values for a node and its ancestors -func (x *intervalNode) updateMax(sentinel *intervalNode) { - for x != sentinel { - oldmax := x.max - max := x.iv.Ivl.End - if x.left != sentinel && x.left.max.Compare(max) > 0 { - max = x.left.max - } - if x.right != sentinel && x.right.max.Compare(max) > 0 { - max = x.right.max - } - if oldmax.Compare(max) == 0 { - break - } - x.max = max - x = x.parent - } -} - -type nodeVisitor func(n *intervalNode) bool - -// visit will call a node visitor on each node that overlaps the given interval -func (x *intervalNode) visit(iv *Interval, sentinel *intervalNode, nv nodeVisitor) bool { - if x == sentinel { - return true - } - v := iv.Compare(&x.iv.Ivl) - switch { - case v < 0: - if !x.left.visit(iv, sentinel, nv) { - return false - } - case v > 0: - maxiv := Interval{x.iv.Ivl.Begin, x.max} - if maxiv.Compare(iv) == 0 { - if !x.left.visit(iv, sentinel, nv) || !x.right.visit(iv, sentinel, nv) { - return false - } - } - default: - if !x.left.visit(iv, sentinel, nv) || !nv(x) || !x.right.visit(iv, sentinel, nv) { - return false - } - } - return true -} - -// IntervalValue represents a range tree node that contains a range and a value. -type IntervalValue struct { - Ivl Interval - Val interface{} -} - -// IntervalTree represents a (mostly) textbook implementation of the -// "Introduction to Algorithms" (Cormen et al, 3rd ed.) chapter 13 red-black tree -// and chapter 14.3 interval tree with search supporting "stabbing queries". -type IntervalTree interface { - // Insert adds a node with the given interval into the tree. - Insert(ivl Interval, val interface{}) - // Delete removes the node with the given interval from the tree, returning - // true if a node is in fact removed. - Delete(ivl Interval) bool - // Len gives the number of elements in the tree. - Len() int - // Height is the number of levels in the tree; one node has height 1. - Height() int - // MaxHeight is the expected maximum tree height given the number of nodes. - MaxHeight() int - // Visit calls a visitor function on every tree node intersecting the given interval. - // It will visit each interval [x, y) in ascending order sorted on x. - Visit(ivl Interval, ivv IntervalVisitor) - // Find gets the IntervalValue for the node matching the given interval - Find(ivl Interval) *IntervalValue - // Intersects returns true if there is some tree node intersecting the given interval. - Intersects(iv Interval) bool - // Contains returns true if the interval tree's keys cover the entire given interval. - Contains(ivl Interval) bool - // Stab returns a slice with all elements in the tree intersecting the interval. - Stab(iv Interval) []*IntervalValue - // Union merges a given interval tree into the receiver. - Union(inIvt IntervalTree, ivl Interval) -} - -// NewIntervalTree returns a new interval tree. -func NewIntervalTree() IntervalTree { - sentinel := &intervalNode{ - iv: IntervalValue{}, - max: nil, - left: nil, - right: nil, - parent: nil, - c: black, - } - return &intervalTree{ - root: sentinel, - count: 0, - sentinel: sentinel, - } -} - -type intervalTree struct { - root *intervalNode - count int - - // red-black NIL node - // use 'sentinel' as a dummy object to simplify boundary conditions - // use the sentinel to treat a nil child of a node x as an ordinary node whose parent is x - // use one shared sentinel to represent all nil leaves and the root's parent - sentinel *intervalNode -} - -// TODO: make this consistent with textbook implementation -// -// "Introduction to Algorithms" (Cormen et al, 3rd ed.), chapter 13.4, p324 -// -// 0. RB-DELETE(T, z) -// 1. -// 2. y = z -// 3. y-original-color = y.color -// 4. -// 5. if z.left == T.nil -// 6. x = z.right -// 7. RB-TRANSPLANT(T, z, z.right) -// 8. else if z.right == T.nil -// 9. x = z.left -// 10. RB-TRANSPLANT(T, z, z.left) -// 11. else -// 12. y = TREE-MINIMUM(z.right) -// 13. y-original-color = y.color -// 14. x = y.right -// 15. if y.p == z -// 16. x.p = y -// 17. else -// 18. RB-TRANSPLANT(T, y, y.right) -// 19. y.right = z.right -// 20. y.right.p = y -// 21. RB-TRANSPLANT(T, z, y) -// 22. y.left = z.left -// 23. y.left.p = y -// 24. y.color = z.color -// 25. -// 26. if y-original-color == BLACK -// 27. RB-DELETE-FIXUP(T, x) - -// Delete removes the node with the given interval from the tree, returning -// true if a node is in fact removed. -func (ivt *intervalTree) Delete(ivl Interval) bool { - z := ivt.find(ivl) - if z == ivt.sentinel { - return false - } - - y := z - if z.left != ivt.sentinel && z.right != ivt.sentinel { - y = z.successor(ivt.sentinel) - } - - x := ivt.sentinel - if y.left != ivt.sentinel { - x = y.left - } else if y.right != ivt.sentinel { - x = y.right - } - - x.parent = y.parent - - if y.parent == ivt.sentinel { - ivt.root = x - } else { - if y == y.parent.left { - y.parent.left = x - } else { - y.parent.right = x - } - y.parent.updateMax(ivt.sentinel) - } - if y != z { - z.iv = y.iv - z.updateMax(ivt.sentinel) - } - - if y.color(ivt.sentinel) == black { - ivt.deleteFixup(x) - } - - ivt.count-- - return true -} - -// "Introduction to Algorithms" (Cormen et al, 3rd ed.), chapter 13.4, p326 -// -// 0. RB-DELETE-FIXUP(T, z) -// 1. -// 2. while x ≠ T.root and x.color == BLACK -// 3. if x == x.p.left -// 4. w = x.p.right -// 5. if w.color == RED -// 6. w.color = BLACK -// 7. x.p.color = RED -// 8. LEFT-ROTATE(T, x, p) -// 9. if w.left.color == BLACK and w.right.color == BLACK -// 10. w.color = RED -// 11. x = x.p -// 12. else if w.right.color == BLACK -// 13. w.left.color = BLACK -// 14. w.color = RED -// 15. RIGHT-ROTATE(T, w) -// 16. w = w.p.right -// 17. w.color = x.p.color -// 18. x.p.color = BLACK -// 19. LEFT-ROTATE(T, w.p) -// 20. x = T.root -// 21. else -// 22. w = x.p.left -// 23. if w.color == RED -// 24. w.color = BLACK -// 25. x.p.color = RED -// 26. RIGHT-ROTATE(T, x, p) -// 27. if w.right.color == BLACK and w.left.color == BLACK -// 28. w.color = RED -// 29. x = x.p -// 30. else if w.left.color == BLACK -// 31. w.right.color = BLACK -// 32. w.color = RED -// 33. LEFT-ROTATE(T, w) -// 34. w = w.p.left -// 35. w.color = x.p.color -// 36. x.p.color = BLACK -// 37. RIGHT-ROTATE(T, w.p) -// 38. x = T.root -// 39. -// 40. x.color = BLACK -// -func (ivt *intervalTree) deleteFixup(x *intervalNode) { - for x != ivt.root && x.color(ivt.sentinel) == black { - if x == x.parent.left { // line 3-20 - w := x.parent.right - if w.color(ivt.sentinel) == red { - w.c = black - x.parent.c = red - ivt.rotateLeft(x.parent) - w = x.parent.right - } - if w == nil { - break - } - if w.left.color(ivt.sentinel) == black && w.right.color(ivt.sentinel) == black { - w.c = red - x = x.parent - } else { - if w.right.color(ivt.sentinel) == black { - w.left.c = black - w.c = red - ivt.rotateRight(w) - w = x.parent.right - } - w.c = x.parent.color(ivt.sentinel) - x.parent.c = black - w.right.c = black - ivt.rotateLeft(x.parent) - x = ivt.root - } - } else { // line 22-38 - // same as above but with left and right exchanged - w := x.parent.left - if w.color(ivt.sentinel) == red { - w.c = black - x.parent.c = red - ivt.rotateRight(x.parent) - w = x.parent.left - } - if w == nil { - break - } - if w.left.color(ivt.sentinel) == black && w.right.color(ivt.sentinel) == black { - w.c = red - x = x.parent - } else { - if w.left.color(ivt.sentinel) == black { - w.right.c = black - w.c = red - ivt.rotateLeft(w) - w = x.parent.left - } - w.c = x.parent.color(ivt.sentinel) - x.parent.c = black - w.left.c = black - ivt.rotateRight(x.parent) - x = ivt.root - } - } - } - - if x != nil { - x.c = black - } -} - -func (ivt *intervalTree) createIntervalNode(ivl Interval, val interface{}) *intervalNode { - return &intervalNode{ - iv: IntervalValue{ivl, val}, - max: ivl.End, - c: red, - left: ivt.sentinel, - right: ivt.sentinel, - parent: ivt.sentinel, - } -} - -// TODO: make this consistent with textbook implementation -// -// "Introduction to Algorithms" (Cormen et al, 3rd ed.), chapter 13.3, p315 -// -// 0. RB-INSERT(T, z) -// 1. -// 2. y = T.nil -// 3. x = T.root -// 4. -// 5. while x ≠ T.nil -// 6. y = x -// 7. if z.key < x.key -// 8. x = x.left -// 9. else -// 10. x = x.right -// 11. -// 12. z.p = y -// 13. -// 14. if y == T.nil -// 15. T.root = z -// 16. else if z.key < y.key -// 17. y.left = z -// 18. else -// 19. y.right = z -// 20. -// 21. z.left = T.nil -// 22. z.right = T.nil -// 23. z.color = RED -// 24. -// 25. RB-INSERT-FIXUP(T, z) - -// Insert adds a node with the given interval into the tree. -func (ivt *intervalTree) Insert(ivl Interval, val interface{}) { - y := ivt.sentinel - z := ivt.createIntervalNode(ivl, val) - x := ivt.root - for x != ivt.sentinel { - y = x - if z.iv.Ivl.Begin.Compare(x.iv.Ivl.Begin) < 0 { - x = x.left - } else { - x = x.right - } - } - - z.parent = y - if y == ivt.sentinel { - ivt.root = z - } else { - if z.iv.Ivl.Begin.Compare(y.iv.Ivl.Begin) < 0 { - y.left = z - } else { - y.right = z - } - y.updateMax(ivt.sentinel) - } - z.c = red - - ivt.insertFixup(z) - ivt.count++ -} - -// "Introduction to Algorithms" (Cormen et al, 3rd ed.), chapter 13.3, p316 -// -// 0. RB-INSERT-FIXUP(T, z) -// 1. -// 2. while z.p.color == RED -// 3. if z.p == z.p.p.left -// 4. y = z.p.p.right -// 5. if y.color == RED -// 6. z.p.color = BLACK -// 7. y.color = BLACK -// 8. z.p.p.color = RED -// 9. z = z.p.p -// 10. else if z == z.p.right -// 11. z = z.p -// 12. LEFT-ROTATE(T, z) -// 13. z.p.color = BLACK -// 14. z.p.p.color = RED -// 15. RIGHT-ROTATE(T, z.p.p) -// 16. else -// 17. y = z.p.p.left -// 18. if y.color == RED -// 19. z.p.color = BLACK -// 20. y.color = BLACK -// 21. z.p.p.color = RED -// 22. z = z.p.p -// 23. else if z == z.p.right -// 24. z = z.p -// 25. RIGHT-ROTATE(T, z) -// 26. z.p.color = BLACK -// 27. z.p.p.color = RED -// 28. LEFT-ROTATE(T, z.p.p) -// 29. -// 30. T.root.color = BLACK -// -func (ivt *intervalTree) insertFixup(z *intervalNode) { - for z.parent.color(ivt.sentinel) == red { - if z.parent == z.parent.parent.left { // line 3-15 - - y := z.parent.parent.right - if y.color(ivt.sentinel) == red { - y.c = black - z.parent.c = black - z.parent.parent.c = red - z = z.parent.parent - } else { - if z == z.parent.right { - z = z.parent - ivt.rotateLeft(z) - } - z.parent.c = black - z.parent.parent.c = red - ivt.rotateRight(z.parent.parent) - } - } else { // line 16-28 - // same as then with left/right exchanged - y := z.parent.parent.left - if y.color(ivt.sentinel) == red { - y.c = black - z.parent.c = black - z.parent.parent.c = red - z = z.parent.parent - } else { - if z == z.parent.left { - z = z.parent - ivt.rotateRight(z) - } - z.parent.c = black - z.parent.parent.c = red - ivt.rotateLeft(z.parent.parent) - } - } - } - - // line 30 - ivt.root.c = black -} - -// rotateLeft moves x so it is left of its right child -// -// "Introduction to Algorithms" (Cormen et al, 3rd ed.), chapter 13.2, p313 -// -// 0. LEFT-ROTATE(T, x) -// 1. -// 2. y = x.right -// 3. x.right = y.left -// 4. -// 5. if y.left ≠ T.nil -// 6. y.left.p = x -// 7. -// 8. y.p = x.p -// 9. -// 10. if x.p == T.nil -// 11. T.root = y -// 12. else if x == x.p.left -// 13. x.p.left = y -// 14. else -// 15. x.p.right = y -// 16. -// 17. y.left = x -// 18. x.p = y -// -func (ivt *intervalTree) rotateLeft(x *intervalNode) { - // rotateLeft x must have right child - if x.right == ivt.sentinel { - return - } - - // line 2-3 - y := x.right - x.right = y.left - - // line 5-6 - if y.left != ivt.sentinel { - y.left.parent = x - } - x.updateMax(ivt.sentinel) - - // line 10-15, 18 - ivt.replaceParent(x, y) - - // line 17 - y.left = x - y.updateMax(ivt.sentinel) -} - -// rotateRight moves x so it is right of its left child -// -// 0. RIGHT-ROTATE(T, x) -// 1. -// 2. y = x.left -// 3. x.left = y.right -// 4. -// 5. if y.right ≠ T.nil -// 6. y.right.p = x -// 7. -// 8. y.p = x.p -// 9. -// 10. if x.p == T.nil -// 11. T.root = y -// 12. else if x == x.p.right -// 13. x.p.right = y -// 14. else -// 15. x.p.left = y -// 16. -// 17. y.right = x -// 18. x.p = y -// -func (ivt *intervalTree) rotateRight(x *intervalNode) { - // rotateRight x must have left child - if x.left == ivt.sentinel { - return - } - - // line 2-3 - y := x.left - x.left = y.right - - // line 5-6 - if y.right != ivt.sentinel { - y.right.parent = x - } - x.updateMax(ivt.sentinel) - - // line 10-15, 18 - ivt.replaceParent(x, y) - - // line 17 - y.right = x - y.updateMax(ivt.sentinel) -} - -// replaceParent replaces x's parent with y -func (ivt *intervalTree) replaceParent(x *intervalNode, y *intervalNode) { - y.parent = x.parent - if x.parent == ivt.sentinel { - ivt.root = y - } else { - if x == x.parent.left { - x.parent.left = y - } else { - x.parent.right = y - } - x.parent.updateMax(ivt.sentinel) - } - x.parent = y -} - -// Len gives the number of elements in the tree -func (ivt *intervalTree) Len() int { return ivt.count } - -// Height is the number of levels in the tree; one node has height 1. -func (ivt *intervalTree) Height() int { return ivt.root.height(ivt.sentinel) } - -// MaxHeight is the expected maximum tree height given the number of nodes -func (ivt *intervalTree) MaxHeight() int { - return int((2 * math.Log2(float64(ivt.Len()+1))) + 0.5) -} - -// IntervalVisitor is used on tree searches; return false to stop searching. -type IntervalVisitor func(n *IntervalValue) bool - -// Visit calls a visitor function on every tree node intersecting the given interval. -// It will visit each interval [x, y) in ascending order sorted on x. -func (ivt *intervalTree) Visit(ivl Interval, ivv IntervalVisitor) { - ivt.root.visit(&ivl, ivt.sentinel, func(n *intervalNode) bool { return ivv(&n.iv) }) -} - -// find the exact node for a given interval -func (ivt *intervalTree) find(ivl Interval) *intervalNode { - ret := ivt.sentinel - f := func(n *intervalNode) bool { - if n.iv.Ivl != ivl { - return true - } - ret = n - return false - } - ivt.root.visit(&ivl, ivt.sentinel, f) - return ret -} - -// Find gets the IntervalValue for the node matching the given interval -func (ivt *intervalTree) Find(ivl Interval) (ret *IntervalValue) { - n := ivt.find(ivl) - if n == ivt.sentinel { - return nil - } - return &n.iv -} - -// Intersects returns true if there is some tree node intersecting the given interval. -func (ivt *intervalTree) Intersects(iv Interval) bool { - x := ivt.root - for x != ivt.sentinel && iv.Compare(&x.iv.Ivl) != 0 { - if x.left != ivt.sentinel && x.left.max.Compare(iv.Begin) > 0 { - x = x.left - } else { - x = x.right - } - } - return x != ivt.sentinel -} - -// Contains returns true if the interval tree's keys cover the entire given interval. -func (ivt *intervalTree) Contains(ivl Interval) bool { - var maxEnd, minBegin Comparable - - isContiguous := true - ivt.Visit(ivl, func(n *IntervalValue) bool { - if minBegin == nil { - minBegin = n.Ivl.Begin - maxEnd = n.Ivl.End - return true - } - if maxEnd.Compare(n.Ivl.Begin) < 0 { - isContiguous = false - return false - } - if n.Ivl.End.Compare(maxEnd) > 0 { - maxEnd = n.Ivl.End - } - return true - }) - - return isContiguous && minBegin != nil && maxEnd.Compare(ivl.End) >= 0 && minBegin.Compare(ivl.Begin) <= 0 -} - -// Stab returns a slice with all elements in the tree intersecting the interval. -func (ivt *intervalTree) Stab(iv Interval) (ivs []*IntervalValue) { - if ivt.count == 0 { - return nil - } - f := func(n *IntervalValue) bool { ivs = append(ivs, n); return true } - ivt.Visit(iv, f) - return ivs -} - -// Union merges a given interval tree into the receiver. -func (ivt *intervalTree) Union(inIvt IntervalTree, ivl Interval) { - f := func(n *IntervalValue) bool { - ivt.Insert(n.Ivl, n.Val) - return true - } - inIvt.Visit(ivl, f) -} - -type visitedInterval struct { - root Interval - left Interval - right Interval - color rbcolor - depth int -} - -func (vi visitedInterval) String() string { - bd := new(strings.Builder) - bd.WriteString(fmt.Sprintf("root [%v,%v,%v], left [%v,%v], right [%v,%v], depth %d", - vi.root.Begin, vi.root.End, vi.color, - vi.left.Begin, vi.left.End, - vi.right.Begin, vi.right.End, - vi.depth, - )) - return bd.String() -} - -// visitLevel traverses tree in level order. -// used for testing -func (ivt *intervalTree) visitLevel() []visitedInterval { - if ivt.root == ivt.sentinel { - return nil - } - - rs := make([]visitedInterval, 0, ivt.Len()) - - type pair struct { - node *intervalNode - depth int - } - queue := []pair{{ivt.root, 0}} - for len(queue) > 0 { - f := queue[0] - queue = queue[1:] - - vi := visitedInterval{ - root: f.node.iv.Ivl, - color: f.node.color(ivt.sentinel), - depth: f.depth, - } - if f.node.left != ivt.sentinel { - vi.left = f.node.left.iv.Ivl - queue = append(queue, pair{f.node.left, f.depth + 1}) - } - if f.node.right != ivt.sentinel { - vi.right = f.node.right.iv.Ivl - queue = append(queue, pair{f.node.right, f.depth + 1}) - } - - rs = append(rs, vi) - } - - return rs -} - -type StringComparable string - -func (s StringComparable) Compare(c Comparable) int { - sc := c.(StringComparable) - if s < sc { - return -1 - } - if s > sc { - return 1 - } - return 0 -} - -func NewStringInterval(begin, end string) Interval { - return Interval{StringComparable(begin), StringComparable(end)} -} - -func NewStringPoint(s string) Interval { - return Interval{StringComparable(s), StringComparable(s + "\x00")} -} - -// StringAffineComparable treats "" as > all other strings -type StringAffineComparable string - -func (s StringAffineComparable) Compare(c Comparable) int { - sc := c.(StringAffineComparable) - - if len(s) == 0 { - if len(sc) == 0 { - return 0 - } - return 1 - } - if len(sc) == 0 { - return -1 - } - - if s < sc { - return -1 - } - if s > sc { - return 1 - } - return 0 -} - -func NewStringAffineInterval(begin, end string) Interval { - return Interval{StringAffineComparable(begin), StringAffineComparable(end)} -} - -func NewStringAffinePoint(s string) Interval { - return NewStringAffineInterval(s, s+"\x00") -} - -func NewInt64Interval(a int64, b int64) Interval { - return Interval{Int64Comparable(a), Int64Comparable(b)} -} - -func newInt64EmptyInterval() Interval { - return Interval{Begin: nil, End: nil} -} - -func NewInt64Point(a int64) Interval { - return Interval{Int64Comparable(a), Int64Comparable(a + 1)} -} - -type Int64Comparable int64 - -func (v Int64Comparable) Compare(c Comparable) int { - vc := c.(Int64Comparable) - cmp := v - vc - if cmp < 0 { - return -1 - } - if cmp > 0 { - return 1 - } - return 0 -} - -// BytesAffineComparable treats empty byte arrays as > all other byte arrays -type BytesAffineComparable []byte - -func (b BytesAffineComparable) Compare(c Comparable) int { - bc := c.(BytesAffineComparable) - - if len(b) == 0 { - if len(bc) == 0 { - return 0 - } - return 1 - } - if len(bc) == 0 { - return -1 - } - - return bytes.Compare(b, bc) -} - -func NewBytesAffineInterval(begin, end []byte) Interval { - return Interval{BytesAffineComparable(begin), BytesAffineComparable(end)} -} - -func NewBytesAffinePoint(b []byte) Interval { - be := make([]byte, len(b)+1) - copy(be, b) - be[len(b)] = 0 - return NewBytesAffineInterval(b, be) -} diff --git a/vendor/go.etcd.io/etcd/pkg/v3/contention/contention.go b/vendor/go.etcd.io/etcd/pkg/v3/contention/contention.go deleted file mode 100644 index 26ce9a2f34..0000000000 --- a/vendor/go.etcd.io/etcd/pkg/v3/contention/contention.go +++ /dev/null @@ -1,69 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package contention - -import ( - "sync" - "time" -) - -// TimeoutDetector detects routine starvations by -// observing the actual time duration to finish an action -// or between two events that should happen in a fixed -// interval. If the observed duration is longer than -// the expectation, the detector will report the result. -type TimeoutDetector struct { - mu sync.Mutex // protects all - maxDuration time.Duration - // map from event to time - // time is the last seen time of the event. - records map[uint64]time.Time -} - -// NewTimeoutDetector creates the TimeoutDetector. -func NewTimeoutDetector(maxDuration time.Duration) *TimeoutDetector { - return &TimeoutDetector{ - maxDuration: maxDuration, - records: make(map[uint64]time.Time), - } -} - -// Reset resets the NewTimeoutDetector. -func (td *TimeoutDetector) Reset() { - td.mu.Lock() - defer td.mu.Unlock() - - td.records = make(map[uint64]time.Time) -} - -// Observe observes an event for given id. It returns false and exceeded duration -// if the interval is longer than the expectation. -func (td *TimeoutDetector) Observe(which uint64) (bool, time.Duration) { - td.mu.Lock() - defer td.mu.Unlock() - - ok := true - now := time.Now() - exceed := time.Duration(0) - - if pt, found := td.records[which]; found { - exceed = now.Sub(pt) - td.maxDuration - if exceed > 0 { - ok = false - } - } - td.records[which] = now - return ok, exceed -} diff --git a/vendor/go.etcd.io/etcd/pkg/v3/contention/doc.go b/vendor/go.etcd.io/etcd/pkg/v3/contention/doc.go deleted file mode 100644 index daf452219e..0000000000 --- a/vendor/go.etcd.io/etcd/pkg/v3/contention/doc.go +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package contention provides facilities for detecting system contention. -package contention diff --git a/vendor/go.etcd.io/etcd/pkg/v3/cpuutil/doc.go b/vendor/go.etcd.io/etcd/pkg/v3/cpuutil/doc.go deleted file mode 100644 index 0323b2d34c..0000000000 --- a/vendor/go.etcd.io/etcd/pkg/v3/cpuutil/doc.go +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package cpuutil provides facilities for detecting cpu-specific features. -package cpuutil diff --git a/vendor/go.etcd.io/etcd/pkg/v3/cpuutil/endian.go b/vendor/go.etcd.io/etcd/pkg/v3/cpuutil/endian.go deleted file mode 100644 index 06c06cd4a5..0000000000 --- a/vendor/go.etcd.io/etcd/pkg/v3/cpuutil/endian.go +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package cpuutil - -import ( - "encoding/binary" - "unsafe" -) - -const intWidth int = int(unsafe.Sizeof(0)) - -var byteOrder binary.ByteOrder - -// ByteOrder returns the byte order for the CPU's native endianness. -func ByteOrder() binary.ByteOrder { return byteOrder } - -func init() { - i := int(0x1) - if v := (*[intWidth]byte)(unsafe.Pointer(&i)); v[0] == 0 { - byteOrder = binary.BigEndian - } else { - byteOrder = binary.LittleEndian - } -} diff --git a/vendor/go.etcd.io/etcd/pkg/v3/crc/crc.go b/vendor/go.etcd.io/etcd/pkg/v3/crc/crc.go deleted file mode 100644 index 4b998a4845..0000000000 --- a/vendor/go.etcd.io/etcd/pkg/v3/crc/crc.go +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright 2009 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// Package crc provides utility function for cyclic redundancy check -// algorithms. -package crc - -import ( - "hash" - "hash/crc32" -) - -// The size of a CRC-32 checksum in bytes. -const Size = 4 - -type digest struct { - crc uint32 - tab *crc32.Table -} - -// New creates a new hash.Hash32 computing the CRC-32 checksum -// using the polynomial represented by the Table. -// Modified by xiangli to take a prevcrc. -func New(prev uint32, tab *crc32.Table) hash.Hash32 { return &digest{prev, tab} } - -func (d *digest) Size() int { return Size } - -func (d *digest) BlockSize() int { return 1 } - -func (d *digest) Reset() { d.crc = 0 } - -func (d *digest) Write(p []byte) (n int, err error) { - d.crc = crc32.Update(d.crc, d.tab, p) - return len(p), nil -} - -func (d *digest) Sum32() uint32 { return d.crc } - -func (d *digest) Sum(in []byte) []byte { - s := d.Sum32() - return append(in, byte(s>>24), byte(s>>16), byte(s>>8), byte(s)) -} diff --git a/vendor/go.etcd.io/etcd/pkg/v3/debugutil/doc.go b/vendor/go.etcd.io/etcd/pkg/v3/debugutil/doc.go deleted file mode 100644 index 74499eb273..0000000000 --- a/vendor/go.etcd.io/etcd/pkg/v3/debugutil/doc.go +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package debugutil includes utility functions for debugging. -package debugutil diff --git a/vendor/go.etcd.io/etcd/pkg/v3/debugutil/pprof.go b/vendor/go.etcd.io/etcd/pkg/v3/debugutil/pprof.go deleted file mode 100644 index 22c2e1ee5d..0000000000 --- a/vendor/go.etcd.io/etcd/pkg/v3/debugutil/pprof.go +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package debugutil - -import ( - "net/http" - "net/http/pprof" - "runtime" -) - -const HTTPPrefixPProf = "/debug/pprof" - -// PProfHandlers returns a map of pprof handlers keyed by the HTTP path. -func PProfHandlers() map[string]http.Handler { - // set only when there's no existing setting - if runtime.SetMutexProfileFraction(-1) == 0 { - // 1 out of 5 mutex events are reported, on average - runtime.SetMutexProfileFraction(5) - } - - m := make(map[string]http.Handler) - - m[HTTPPrefixPProf+"/"] = http.HandlerFunc(pprof.Index) - m[HTTPPrefixPProf+"/profile"] = http.HandlerFunc(pprof.Profile) - m[HTTPPrefixPProf+"/symbol"] = http.HandlerFunc(pprof.Symbol) - m[HTTPPrefixPProf+"/cmdline"] = http.HandlerFunc(pprof.Cmdline) - m[HTTPPrefixPProf+"/trace"] = http.HandlerFunc(pprof.Trace) - m[HTTPPrefixPProf+"/heap"] = pprof.Handler("heap") - m[HTTPPrefixPProf+"/goroutine"] = pprof.Handler("goroutine") - m[HTTPPrefixPProf+"/threadcreate"] = pprof.Handler("threadcreate") - m[HTTPPrefixPProf+"/block"] = pprof.Handler("block") - m[HTTPPrefixPProf+"/mutex"] = pprof.Handler("mutex") - - return m -} diff --git a/vendor/go.etcd.io/etcd/pkg/v3/flags/flag.go b/vendor/go.etcd.io/etcd/pkg/v3/flags/flag.go deleted file mode 100644 index 76a51a8901..0000000000 --- a/vendor/go.etcd.io/etcd/pkg/v3/flags/flag.go +++ /dev/null @@ -1,132 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package flags implements command-line flag parsing. -package flags - -import ( - "flag" - "fmt" - "os" - "strings" - - "github.com/spf13/pflag" - "go.uber.org/zap" -) - -// SetFlagsFromEnv parses all registered flags in the given flagset, -// and if they are not already set it attempts to set their values from -// environment variables. Environment variables take the name of the flag but -// are UPPERCASE, have the given prefix and any dashes are replaced by -// underscores - for example: some-flag => ETCD_SOME_FLAG -func SetFlagsFromEnv(lg *zap.Logger, prefix string, fs *flag.FlagSet) error { - var err error - alreadySet := make(map[string]bool) - fs.Visit(func(f *flag.Flag) { - alreadySet[FlagToEnv(prefix, f.Name)] = true - }) - usedEnvKey := make(map[string]bool) - fs.VisitAll(func(f *flag.Flag) { - if serr := setFlagFromEnv(lg, fs, prefix, f.Name, usedEnvKey, alreadySet, true); serr != nil { - err = serr - } - }) - verifyEnv(lg, prefix, usedEnvKey, alreadySet) - return err -} - -// SetPflagsFromEnv is similar to SetFlagsFromEnv. However, the accepted flagset type is pflag.FlagSet -// and it does not do any logging. -func SetPflagsFromEnv(lg *zap.Logger, prefix string, fs *pflag.FlagSet) error { - var err error - alreadySet := make(map[string]bool) - usedEnvKey := make(map[string]bool) - fs.VisitAll(func(f *pflag.Flag) { - if f.Changed { - alreadySet[FlagToEnv(prefix, f.Name)] = true - } - if serr := setFlagFromEnv(lg, fs, prefix, f.Name, usedEnvKey, alreadySet, false); serr != nil { - err = serr - } - }) - verifyEnv(lg, prefix, usedEnvKey, alreadySet) - return err -} - -// FlagToEnv converts flag string to upper-case environment variable key string. -func FlagToEnv(prefix, name string) string { - return prefix + "_" + strings.ToUpper(strings.Replace(name, "-", "_", -1)) -} - -func verifyEnv(lg *zap.Logger, prefix string, usedEnvKey, alreadySet map[string]bool) { - for _, env := range os.Environ() { - kv := strings.SplitN(env, "=", 2) - if len(kv) != 2 { - if lg != nil { - lg.Warn("found invalid environment variable", zap.String("environment-variable", env)) - } - } - if usedEnvKey[kv[0]] { - continue - } - if alreadySet[kv[0]] { - if lg != nil { - lg.Fatal( - "conflicting environment variable is shadowed by corresponding command-line flag (either unset environment variable or disable flag))", - zap.String("environment-variable", kv[0]), - ) - } - } - if strings.HasPrefix(env, prefix+"_") { - if lg != nil { - lg.Warn("unrecognized environment variable", zap.String("environment-variable", env)) - } - } - } -} - -type flagSetter interface { - Set(fk string, fv string) error -} - -func setFlagFromEnv(lg *zap.Logger, fs flagSetter, prefix, fname string, usedEnvKey, alreadySet map[string]bool, log bool) error { - key := FlagToEnv(prefix, fname) - if !alreadySet[key] { - val := os.Getenv(key) - if val != "" { - usedEnvKey[key] = true - if serr := fs.Set(fname, val); serr != nil { - return fmt.Errorf("invalid value %q for %s: %v", val, key, serr) - } - if log && lg != nil { - lg.Info( - "recognized and used environment variable", - zap.String("variable-name", key), - zap.String("variable-value", val), - ) - } - } - } - return nil -} - -func IsSet(fs *flag.FlagSet, name string) bool { - set := false - fs.Visit(func(f *flag.Flag) { - if f.Name == name { - set = true - } - }) - return set -} diff --git a/vendor/go.etcd.io/etcd/pkg/v3/flags/ignored.go b/vendor/go.etcd.io/etcd/pkg/v3/flags/ignored.go deleted file mode 100644 index 9443935354..0000000000 --- a/vendor/go.etcd.io/etcd/pkg/v3/flags/ignored.go +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright 2018 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package flags - -import "go.uber.org/zap" - -// IgnoredFlag encapsulates a flag that may have been previously valid but is -// now ignored. If an IgnoredFlag is set, a warning is printed and -// operation continues. -type IgnoredFlag struct { - lg *zap.Logger - Name string -} - -// IsBoolFlag is defined to allow the flag to be defined without an argument -func (f *IgnoredFlag) IsBoolFlag() bool { - return true -} - -func (f *IgnoredFlag) Set(s string) error { - if f.lg != nil { - f.lg.Warn("flag is no longer supported - ignoring", zap.String("flag-name", f.Name)) - } - return nil -} - -func (f *IgnoredFlag) String() string { - return "" -} diff --git a/vendor/go.etcd.io/etcd/pkg/v3/flags/selective_string.go b/vendor/go.etcd.io/etcd/pkg/v3/flags/selective_string.go deleted file mode 100644 index 4b90fbf4b4..0000000000 --- a/vendor/go.etcd.io/etcd/pkg/v3/flags/selective_string.go +++ /dev/null @@ -1,114 +0,0 @@ -// Copyright 2018 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package flags - -import ( - "errors" - "fmt" - "sort" - "strings" -) - -// SelectiveStringValue implements the flag.Value interface. -type SelectiveStringValue struct { - v string - valids map[string]struct{} -} - -// Set verifies the argument to be a valid member of the allowed values -// before setting the underlying flag value. -func (ss *SelectiveStringValue) Set(s string) error { - if _, ok := ss.valids[s]; ok { - ss.v = s - return nil - } - return errors.New("invalid value") -} - -// String returns the set value (if any) of the SelectiveStringValue -func (ss *SelectiveStringValue) String() string { - return ss.v -} - -// Valids returns the list of valid strings. -func (ss *SelectiveStringValue) Valids() []string { - s := make([]string, 0, len(ss.valids)) - for k := range ss.valids { - s = append(s, k) - } - sort.Strings(s) - return s -} - -// NewSelectiveStringValue creates a new string flag -// for which any one of the given strings is a valid value, -// and any other value is an error. -// -// valids[0] will be default value. Caller must be sure -// len(valids) != 0 or it will panic. -func NewSelectiveStringValue(valids ...string) *SelectiveStringValue { - vm := make(map[string]struct{}) - for _, v := range valids { - vm[v] = struct{}{} - } - return &SelectiveStringValue{valids: vm, v: valids[0]} -} - -// SelectiveStringsValue implements the flag.Value interface. -type SelectiveStringsValue struct { - vs []string - valids map[string]struct{} -} - -// Set verifies the argument to be a valid member of the allowed values -// before setting the underlying flag value. -func (ss *SelectiveStringsValue) Set(s string) error { - vs := strings.Split(s, ",") - for i := range vs { - if _, ok := ss.valids[vs[i]]; ok { - ss.vs = append(ss.vs, vs[i]) - } else { - return fmt.Errorf("invalid value %q", vs[i]) - } - } - sort.Strings(ss.vs) - return nil -} - -// String returns the set value (if any) of the SelectiveStringsValue. -func (ss *SelectiveStringsValue) String() string { - return strings.Join(ss.vs, ",") -} - -// Valids returns the list of valid strings. -func (ss *SelectiveStringsValue) Valids() []string { - s := make([]string, 0, len(ss.valids)) - for k := range ss.valids { - s = append(s, k) - } - sort.Strings(s) - return s -} - -// NewSelectiveStringsValue creates a new string slice flag -// for which any one of the given strings is a valid value, -// and any other value is an error. -func NewSelectiveStringsValue(valids ...string) *SelectiveStringsValue { - vm := make(map[string]struct{}) - for _, v := range valids { - vm[v] = struct{}{} - } - return &SelectiveStringsValue{valids: vm, vs: []string{}} -} diff --git a/vendor/go.etcd.io/etcd/pkg/v3/flags/strings.go b/vendor/go.etcd.io/etcd/pkg/v3/flags/strings.go deleted file mode 100644 index a80190658e..0000000000 --- a/vendor/go.etcd.io/etcd/pkg/v3/flags/strings.go +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright 2018 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package flags - -import ( - "flag" - "fmt" - "sort" - "strings" -) - -// StringsValue wraps "sort.StringSlice". -type StringsValue sort.StringSlice - -// Set parses a command line set of strings, separated by comma. -// Implements "flag.Value" interface. -func (ss *StringsValue) Set(s string) error { - *ss = strings.Split(s, ",") - return nil -} - -// String implements "flag.Value" interface. -func (ss *StringsValue) String() string { return strings.Join(*ss, ",") } - -// NewStringsValue implements string slice as "flag.Value" interface. -// Given value is to be separated by comma. -func NewStringsValue(s string) (ss *StringsValue) { - if s == "" { - return &StringsValue{} - } - ss = new(StringsValue) - if err := ss.Set(s); err != nil { - panic(fmt.Sprintf("new StringsValue should never fail: %v", err)) - } - return ss -} - -// StringsFromFlag returns a string slice from the flag. -func StringsFromFlag(fs *flag.FlagSet, flagName string) []string { - return []string(*fs.Lookup(flagName).Value.(*StringsValue)) -} diff --git a/vendor/go.etcd.io/etcd/pkg/v3/flags/unique_strings.go b/vendor/go.etcd.io/etcd/pkg/v3/flags/unique_strings.go deleted file mode 100644 index e67af1f9b5..0000000000 --- a/vendor/go.etcd.io/etcd/pkg/v3/flags/unique_strings.go +++ /dev/null @@ -1,77 +0,0 @@ -// Copyright 2018 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package flags - -import ( - "flag" - "fmt" - "sort" - "strings" -) - -// UniqueStringsValue wraps a list of unique strings. -// The values are set in order. -type UniqueStringsValue struct { - Values map[string]struct{} -} - -// Set parses a command line set of strings, separated by comma. -// Implements "flag.Value" interface. -// The values are set in order. -func (us *UniqueStringsValue) Set(s string) error { - us.Values = make(map[string]struct{}) - for _, v := range strings.Split(s, ",") { - us.Values[v] = struct{}{} - } - return nil -} - -// String implements "flag.Value" interface. -func (us *UniqueStringsValue) String() string { - return strings.Join(us.stringSlice(), ",") -} - -func (us *UniqueStringsValue) stringSlice() []string { - ss := make([]string, 0, len(us.Values)) - for v := range us.Values { - ss = append(ss, v) - } - sort.Strings(ss) - return ss -} - -// NewUniqueStringsValue implements string slice as "flag.Value" interface. -// Given value is to be separated by comma. -// The values are set in order. -func NewUniqueStringsValue(s string) (us *UniqueStringsValue) { - us = &UniqueStringsValue{Values: make(map[string]struct{})} - if s == "" { - return us - } - if err := us.Set(s); err != nil { - panic(fmt.Sprintf("new UniqueStringsValue should never fail: %v", err)) - } - return us -} - -// UniqueStringsFromFlag returns a string slice from the flag. -func UniqueStringsFromFlag(fs *flag.FlagSet, flagName string) []string { - return (*fs.Lookup(flagName).Value.(*UniqueStringsValue)).stringSlice() -} - -// UniqueStringsMapFromFlag returns a map of strings from the flag. -func UniqueStringsMapFromFlag(fs *flag.FlagSet, flagName string) map[string]struct{} { - return (*fs.Lookup(flagName).Value.(*UniqueStringsValue)).Values -} diff --git a/vendor/go.etcd.io/etcd/pkg/v3/flags/unique_urls.go b/vendor/go.etcd.io/etcd/pkg/v3/flags/unique_urls.go deleted file mode 100644 index 5b22ef21ad..0000000000 --- a/vendor/go.etcd.io/etcd/pkg/v3/flags/unique_urls.go +++ /dev/null @@ -1,93 +0,0 @@ -// Copyright 2018 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package flags - -import ( - "flag" - "fmt" - "net/url" - "sort" - "strings" - - "go.etcd.io/etcd/client/pkg/v3/types" -) - -// UniqueURLs contains unique URLs -// with non-URL exceptions. -type UniqueURLs struct { - Values map[string]struct{} - uss []url.URL - Allowed map[string]struct{} -} - -// Set parses a command line set of URLs formatted like: -// http://127.0.0.1:2380,http://10.1.1.2:80 -// Implements "flag.Value" interface. -func (us *UniqueURLs) Set(s string) error { - if _, ok := us.Values[s]; ok { - return nil - } - if _, ok := us.Allowed[s]; ok { - us.Values[s] = struct{}{} - return nil - } - ss, err := types.NewURLs(strings.Split(s, ",")) - if err != nil { - return err - } - us.Values = make(map[string]struct{}) - us.uss = make([]url.URL, 0) - for _, v := range ss { - us.Values[v.String()] = struct{}{} - us.uss = append(us.uss, v) - } - return nil -} - -// String implements "flag.Value" interface. -func (us *UniqueURLs) String() string { - all := make([]string, 0, len(us.Values)) - for u := range us.Values { - all = append(all, u) - } - sort.Strings(all) - return strings.Join(all, ",") -} - -// NewUniqueURLsWithExceptions implements "url.URL" slice as flag.Value interface. -// Given value is to be separated by comma. -func NewUniqueURLsWithExceptions(s string, exceptions ...string) *UniqueURLs { - us := &UniqueURLs{Values: make(map[string]struct{}), Allowed: make(map[string]struct{})} - for _, v := range exceptions { - us.Allowed[v] = struct{}{} - } - if s == "" { - return us - } - if err := us.Set(s); err != nil { - panic(fmt.Sprintf("new UniqueURLs should never fail: %v", err)) - } - return us -} - -// UniqueURLsFromFlag returns a slice from urls got from the flag. -func UniqueURLsFromFlag(fs *flag.FlagSet, urlsFlagName string) []url.URL { - return (*fs.Lookup(urlsFlagName).Value.(*UniqueURLs)).uss -} - -// UniqueURLsMapFromFlag returns a map from url strings got from the flag. -func UniqueURLsMapFromFlag(fs *flag.FlagSet, urlsFlagName string) map[string]struct{} { - return (*fs.Lookup(urlsFlagName).Value.(*UniqueURLs)).Values -} diff --git a/vendor/go.etcd.io/etcd/pkg/v3/flags/urls.go b/vendor/go.etcd.io/etcd/pkg/v3/flags/urls.go deleted file mode 100644 index 885d32f457..0000000000 --- a/vendor/go.etcd.io/etcd/pkg/v3/flags/urls.go +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package flags - -import ( - "flag" - "fmt" - "net/url" - "strings" - - "go.etcd.io/etcd/client/pkg/v3/types" -) - -// URLsValue wraps "types.URLs". -type URLsValue types.URLs - -// Set parses a command line set of URLs formatted like: -// http://127.0.0.1:2380,http://10.1.1.2:80 -// Implements "flag.Value" interface. -func (us *URLsValue) Set(s string) error { - ss, err := types.NewURLs(strings.Split(s, ",")) - if err != nil { - return err - } - *us = URLsValue(ss) - return nil -} - -// String implements "flag.Value" interface. -func (us *URLsValue) String() string { - all := make([]string, len(*us)) - for i, u := range *us { - all[i] = u.String() - } - return strings.Join(all, ",") -} - -// NewURLsValue implements "url.URL" slice as flag.Value interface. -// Given value is to be separated by comma. -func NewURLsValue(s string) *URLsValue { - if s == "" { - return &URLsValue{} - } - v := &URLsValue{} - if err := v.Set(s); err != nil { - panic(fmt.Sprintf("new URLsValue should never fail: %v", err)) - } - return v -} - -// URLsFromFlag returns a slices from url got from the flag. -func URLsFromFlag(fs *flag.FlagSet, urlsFlagName string) []url.URL { - return []url.URL(*fs.Lookup(urlsFlagName).Value.(*URLsValue)) -} diff --git a/vendor/go.etcd.io/etcd/pkg/v3/httputil/httputil.go b/vendor/go.etcd.io/etcd/pkg/v3/httputil/httputil.go deleted file mode 100644 index 3bf58a3a1d..0000000000 --- a/vendor/go.etcd.io/etcd/pkg/v3/httputil/httputil.go +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright 2018 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Copyright 2015 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// Package httputil provides HTTP utility functions. -package httputil - -import ( - "io" - "io/ioutil" - "net" - "net/http" -) - -// GracefulClose drains http.Response.Body until it hits EOF -// and closes it. This prevents TCP/TLS connections from closing, -// therefore available for reuse. -// Borrowed from golang/net/context/ctxhttp/cancelreq.go. -func GracefulClose(resp *http.Response) { - io.Copy(ioutil.Discard, resp.Body) - resp.Body.Close() -} - -// GetHostname returns the hostname from request Host field. -// It returns empty string, if Host field contains invalid -// value (e.g. "localhost:::" with too many colons). -func GetHostname(req *http.Request) string { - if req == nil { - return "" - } - h, _, err := net.SplitHostPort(req.Host) - if err != nil { - return req.Host - } - return h -} diff --git a/vendor/go.etcd.io/etcd/pkg/v3/idutil/id.go b/vendor/go.etcd.io/etcd/pkg/v3/idutil/id.go deleted file mode 100644 index 63a02cd734..0000000000 --- a/vendor/go.etcd.io/etcd/pkg/v3/idutil/id.go +++ /dev/null @@ -1,75 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package idutil implements utility functions for generating unique, -// randomized ids. -package idutil - -import ( - "math" - "sync/atomic" - "time" -) - -const ( - tsLen = 5 * 8 - cntLen = 8 - suffixLen = tsLen + cntLen -) - -// Generator generates unique identifiers based on counters, timestamps, and -// a node member ID. -// -// The initial id is in this format: -// High order 2 bytes are from memberID, next 5 bytes are from timestamp, -// and low order one byte is a counter. -// | prefix | suffix | -// | 2 bytes | 5 bytes | 1 byte | -// | memberID | timestamp | cnt | -// -// The timestamp 5 bytes is different when the machine is restart -// after 1 ms and before 35 years. -// -// It increases suffix to generate the next id. -// The count field may overflow to timestamp field, which is intentional. -// It helps to extend the event window to 2^56. This doesn't break that -// id generated after restart is unique because etcd throughput is << -// 256req/ms(250k reqs/second). -type Generator struct { - // high order 2 bytes - prefix uint64 - // low order 6 bytes - suffix uint64 -} - -func NewGenerator(memberID uint16, now time.Time) *Generator { - prefix := uint64(memberID) << suffixLen - unixMilli := uint64(now.UnixNano()) / uint64(time.Millisecond/time.Nanosecond) - suffix := lowbit(unixMilli, tsLen) << cntLen - return &Generator{ - prefix: prefix, - suffix: suffix, - } -} - -// Next generates a id that is unique. -func (g *Generator) Next() uint64 { - suffix := atomic.AddUint64(&g.suffix, 1) - id := g.prefix | lowbit(suffix, suffixLen) - return id -} - -func lowbit(x uint64, n uint) uint64 { - return x & (math.MaxUint64 >> (64 - n)) -} diff --git a/vendor/go.etcd.io/etcd/pkg/v3/ioutil/pagewriter.go b/vendor/go.etcd.io/etcd/pkg/v3/ioutil/pagewriter.go deleted file mode 100644 index cf9a8dc664..0000000000 --- a/vendor/go.etcd.io/etcd/pkg/v3/ioutil/pagewriter.go +++ /dev/null @@ -1,117 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package ioutil - -import ( - "io" -) - -var defaultBufferBytes = 128 * 1024 - -// PageWriter implements the io.Writer interface so that writes will -// either be in page chunks or from flushing. -type PageWriter struct { - w io.Writer - // pageOffset tracks the page offset of the base of the buffer - pageOffset int - // pageBytes is the number of bytes per page - pageBytes int - // bufferedBytes counts the number of bytes pending for write in the buffer - bufferedBytes int - // buf holds the write buffer - buf []byte - // bufWatermarkBytes is the number of bytes the buffer can hold before it needs - // to be flushed. It is less than len(buf) so there is space for slack writes - // to bring the writer to page alignment. - bufWatermarkBytes int -} - -// NewPageWriter creates a new PageWriter. pageBytes is the number of bytes -// to write per page. pageOffset is the starting offset of io.Writer. -func NewPageWriter(w io.Writer, pageBytes, pageOffset int) *PageWriter { - return &PageWriter{ - w: w, - pageOffset: pageOffset, - pageBytes: pageBytes, - buf: make([]byte, defaultBufferBytes+pageBytes), - bufWatermarkBytes: defaultBufferBytes, - } -} - -func (pw *PageWriter) Write(p []byte) (n int, err error) { - if len(p)+pw.bufferedBytes <= pw.bufWatermarkBytes { - // no overflow - copy(pw.buf[pw.bufferedBytes:], p) - pw.bufferedBytes += len(p) - return len(p), nil - } - // complete the slack page in the buffer if unaligned - slack := pw.pageBytes - ((pw.pageOffset + pw.bufferedBytes) % pw.pageBytes) - if slack != pw.pageBytes { - partial := slack > len(p) - if partial { - // not enough data to complete the slack page - slack = len(p) - } - // special case: writing to slack page in buffer - copy(pw.buf[pw.bufferedBytes:], p[:slack]) - pw.bufferedBytes += slack - n = slack - p = p[slack:] - if partial { - // avoid forcing an unaligned flush - return n, nil - } - } - // buffer contents are now page-aligned; clear out - if err = pw.Flush(); err != nil { - return n, err - } - // directly write all complete pages without copying - if len(p) > pw.pageBytes { - pages := len(p) / pw.pageBytes - c, werr := pw.w.Write(p[:pages*pw.pageBytes]) - n += c - if werr != nil { - return n, werr - } - p = p[pages*pw.pageBytes:] - } - // write remaining tail to buffer - c, werr := pw.Write(p) - n += c - return n, werr -} - -// Flush flushes buffered data. -func (pw *PageWriter) Flush() error { - _, err := pw.flush() - return err -} - -// FlushN flushes buffered data and returns the number of written bytes. -func (pw *PageWriter) FlushN() (int, error) { - return pw.flush() -} - -func (pw *PageWriter) flush() (int, error) { - if pw.bufferedBytes == 0 { - return 0, nil - } - n, err := pw.w.Write(pw.buf[:pw.bufferedBytes]) - pw.pageOffset = (pw.pageOffset + pw.bufferedBytes) % pw.pageBytes - pw.bufferedBytes = 0 - return n, err -} diff --git a/vendor/go.etcd.io/etcd/pkg/v3/ioutil/readcloser.go b/vendor/go.etcd.io/etcd/pkg/v3/ioutil/readcloser.go deleted file mode 100644 index d3efcfe3d5..0000000000 --- a/vendor/go.etcd.io/etcd/pkg/v3/ioutil/readcloser.go +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package ioutil - -import ( - "fmt" - "io" -) - -// ReaderAndCloser implements io.ReadCloser interface by combining -// reader and closer together. -type ReaderAndCloser struct { - io.Reader - io.Closer -} - -var ( - ErrShortRead = fmt.Errorf("ioutil: short read") - ErrExpectEOF = fmt.Errorf("ioutil: expect EOF") -) - -// NewExactReadCloser returns a ReadCloser that returns errors if the underlying -// reader does not read back exactly the requested number of bytes. -func NewExactReadCloser(rc io.ReadCloser, totalBytes int64) io.ReadCloser { - return &exactReadCloser{rc: rc, totalBytes: totalBytes} -} - -type exactReadCloser struct { - rc io.ReadCloser - br int64 - totalBytes int64 -} - -func (e *exactReadCloser) Read(p []byte) (int, error) { - n, err := e.rc.Read(p) - e.br += int64(n) - if e.br > e.totalBytes { - return 0, ErrExpectEOF - } - if e.br < e.totalBytes && n == 0 { - return 0, ErrShortRead - } - return n, err -} - -func (e *exactReadCloser) Close() error { - if err := e.rc.Close(); err != nil { - return err - } - if e.br < e.totalBytes { - return ErrShortRead - } - return nil -} diff --git a/vendor/go.etcd.io/etcd/pkg/v3/ioutil/reader.go b/vendor/go.etcd.io/etcd/pkg/v3/ioutil/reader.go deleted file mode 100644 index 0703ed476d..0000000000 --- a/vendor/go.etcd.io/etcd/pkg/v3/ioutil/reader.go +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package ioutil implements I/O utility functions. -package ioutil - -import "io" - -// NewLimitedBufferReader returns a reader that reads from the given reader -// but limits the amount of data returned to at most n bytes. -func NewLimitedBufferReader(r io.Reader, n int) io.Reader { - return &limitedBufferReader{ - r: r, - n: n, - } -} - -type limitedBufferReader struct { - r io.Reader - n int -} - -func (r *limitedBufferReader) Read(p []byte) (n int, err error) { - np := p - if len(np) > r.n { - np = np[:r.n] - } - return r.r.Read(np) -} diff --git a/vendor/go.etcd.io/etcd/pkg/v3/ioutil/util.go b/vendor/go.etcd.io/etcd/pkg/v3/ioutil/util.go deleted file mode 100644 index dc36e183c2..0000000000 --- a/vendor/go.etcd.io/etcd/pkg/v3/ioutil/util.go +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package ioutil - -import ( - "io" - "os" - - "go.etcd.io/etcd/client/pkg/v3/fileutil" -) - -// WriteAndSyncFile behaves just like ioutil.WriteFile in the standard library, -// but calls Sync before closing the file. WriteAndSyncFile guarantees the data -// is synced if there is no error returned. -func WriteAndSyncFile(filename string, data []byte, perm os.FileMode) error { - f, err := os.OpenFile(filename, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, perm) - if err != nil { - return err - } - n, err := f.Write(data) - if err == nil && n < len(data) { - err = io.ErrShortWrite - } - if err == nil { - err = fileutil.Fsync(f) - } - if err1 := f.Close(); err == nil { - err = err1 - } - return err -} diff --git a/vendor/go.etcd.io/etcd/pkg/v3/netutil/doc.go b/vendor/go.etcd.io/etcd/pkg/v3/netutil/doc.go deleted file mode 100644 index 5d92d03a6f..0000000000 --- a/vendor/go.etcd.io/etcd/pkg/v3/netutil/doc.go +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2018 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package netutil implements network-related utility functions. -package netutil diff --git a/vendor/go.etcd.io/etcd/pkg/v3/netutil/netutil.go b/vendor/go.etcd.io/etcd/pkg/v3/netutil/netutil.go deleted file mode 100644 index bf737a4d94..0000000000 --- a/vendor/go.etcd.io/etcd/pkg/v3/netutil/netutil.go +++ /dev/null @@ -1,213 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package netutil - -import ( - "context" - "fmt" - "net" - "net/url" - "reflect" - "sort" - "time" - - "go.etcd.io/etcd/client/pkg/v3/types" - - "go.uber.org/zap" -) - -// indirection for testing -var resolveTCPAddr = resolveTCPAddrDefault - -const retryInterval = time.Second - -// taken from go's ResolveTCP code but uses configurable ctx -func resolveTCPAddrDefault(ctx context.Context, addr string) (*net.TCPAddr, error) { - host, port, serr := net.SplitHostPort(addr) - if serr != nil { - return nil, serr - } - portnum, perr := net.DefaultResolver.LookupPort(ctx, "tcp", port) - if perr != nil { - return nil, perr - } - - var ips []net.IPAddr - if ip := net.ParseIP(host); ip != nil { - ips = []net.IPAddr{{IP: ip}} - } else { - // Try as a DNS name. - ipss, err := net.DefaultResolver.LookupIPAddr(ctx, host) - if err != nil { - return nil, err - } - ips = ipss - } - // randomize? - ip := ips[0] - return &net.TCPAddr{IP: ip.IP, Port: portnum, Zone: ip.Zone}, nil -} - -// resolveTCPAddrs is a convenience wrapper for net.ResolveTCPAddr. -// resolveTCPAddrs return a new set of url.URLs, in which all DNS hostnames -// are resolved. -func resolveTCPAddrs(ctx context.Context, lg *zap.Logger, urls [][]url.URL) ([][]url.URL, error) { - newurls := make([][]url.URL, 0) - for _, us := range urls { - nus := make([]url.URL, len(us)) - for i, u := range us { - nu, err := url.Parse(u.String()) - if err != nil { - return nil, fmt.Errorf("failed to parse %q (%v)", u.String(), err) - } - nus[i] = *nu - } - for i, u := range nus { - h, err := resolveURL(ctx, lg, u) - if err != nil { - return nil, fmt.Errorf("failed to resolve %q (%v)", u.String(), err) - } - if h != "" { - nus[i].Host = h - } - } - newurls = append(newurls, nus) - } - return newurls, nil -} - -func resolveURL(ctx context.Context, lg *zap.Logger, u url.URL) (string, error) { - if u.Scheme == "unix" || u.Scheme == "unixs" { - // unix sockets don't resolve over TCP - return "", nil - } - host, _, err := net.SplitHostPort(u.Host) - if err != nil { - lg.Warn( - "failed to parse URL Host while resolving URL", - zap.String("url", u.String()), - zap.String("host", u.Host), - zap.Error(err), - ) - return "", err - } - if host == "localhost" || net.ParseIP(host) != nil { - return "", nil - } - for ctx.Err() == nil { - tcpAddr, err := resolveTCPAddr(ctx, u.Host) - if err == nil { - lg.Info( - "resolved URL Host", - zap.String("url", u.String()), - zap.String("host", u.Host), - zap.String("resolved-addr", tcpAddr.String()), - ) - return tcpAddr.String(), nil - } - - lg.Warn( - "failed to resolve URL Host", - zap.String("url", u.String()), - zap.String("host", u.Host), - zap.Duration("retry-interval", retryInterval), - zap.Error(err), - ) - - select { - case <-ctx.Done(): - lg.Warn( - "failed to resolve URL Host; returning", - zap.String("url", u.String()), - zap.String("host", u.Host), - zap.Duration("retry-interval", retryInterval), - zap.Error(err), - ) - return "", err - case <-time.After(retryInterval): - } - } - return "", ctx.Err() -} - -// urlsEqual checks equality of url.URLS between two arrays. -// This check pass even if an URL is in hostname and opposite is in IP address. -func urlsEqual(ctx context.Context, lg *zap.Logger, a []url.URL, b []url.URL) (bool, error) { - if len(a) != len(b) { - return false, fmt.Errorf("len(%q) != len(%q)", urlsToStrings(a), urlsToStrings(b)) - } - urls, err := resolveTCPAddrs(ctx, lg, [][]url.URL{a, b}) - if err != nil { - return false, err - } - preva, prevb := a, b - a, b = urls[0], urls[1] - sort.Sort(types.URLs(a)) - sort.Sort(types.URLs(b)) - for i := range a { - if !reflect.DeepEqual(a[i], b[i]) { - return false, fmt.Errorf("%q(resolved from %q) != %q(resolved from %q)", - a[i].String(), preva[i].String(), - b[i].String(), prevb[i].String(), - ) - } - } - return true, nil -} - -// URLStringsEqual returns "true" if given URLs are valid -// and resolved to same IP addresses. Otherwise, return "false" -// and error, if any. -func URLStringsEqual(ctx context.Context, lg *zap.Logger, a []string, b []string) (bool, error) { - if len(a) != len(b) { - return false, fmt.Errorf("len(%q) != len(%q)", a, b) - } - urlsA := make([]url.URL, 0) - for _, str := range a { - u, err := url.Parse(str) - if err != nil { - return false, fmt.Errorf("failed to parse %q", str) - } - urlsA = append(urlsA, *u) - } - urlsB := make([]url.URL, 0) - for _, str := range b { - u, err := url.Parse(str) - if err != nil { - return false, fmt.Errorf("failed to parse %q", str) - } - urlsB = append(urlsB, *u) - } - if lg == nil { - lg, _ = zap.NewProduction() - if lg == nil { - lg = zap.NewExample() - } - } - return urlsEqual(ctx, lg, urlsA, urlsB) -} - -func urlsToStrings(us []url.URL) []string { - rs := make([]string, len(us)) - for i := range us { - rs[i] = us[i].String() - } - return rs -} - -func IsNetworkTimeoutError(err error) bool { - nerr, ok := err.(net.Error) - return ok && nerr.Timeout() -} diff --git a/vendor/go.etcd.io/etcd/pkg/v3/netutil/routes.go b/vendor/go.etcd.io/etcd/pkg/v3/netutil/routes.go deleted file mode 100644 index f66719ea16..0000000000 --- a/vendor/go.etcd.io/etcd/pkg/v3/netutil/routes.go +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -//go:build !linux -// +build !linux - -package netutil - -import ( - "fmt" - "runtime" -) - -// GetDefaultHost fetches the a resolvable name that corresponds -// to the machine's default routable interface -func GetDefaultHost() (string, error) { - return "", fmt.Errorf("default host not supported on %s_%s", runtime.GOOS, runtime.GOARCH) -} - -// GetDefaultInterfaces fetches the device name of default routable interface. -func GetDefaultInterfaces() (map[string]uint8, error) { - return nil, fmt.Errorf("default host not supported on %s_%s", runtime.GOOS, runtime.GOARCH) -} diff --git a/vendor/go.etcd.io/etcd/pkg/v3/netutil/routes_linux.go b/vendor/go.etcd.io/etcd/pkg/v3/netutil/routes_linux.go deleted file mode 100644 index 5f8bd0c488..0000000000 --- a/vendor/go.etcd.io/etcd/pkg/v3/netutil/routes_linux.go +++ /dev/null @@ -1,251 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -//go:build linux -// +build linux - -package netutil - -import ( - "bytes" - "encoding/binary" - "fmt" - "net" - "sort" - "syscall" - - "go.etcd.io/etcd/pkg/v3/cpuutil" -) - -var errNoDefaultRoute = fmt.Errorf("could not find default route") -var errNoDefaultHost = fmt.Errorf("could not find default host") -var errNoDefaultInterface = fmt.Errorf("could not find default interface") - -// GetDefaultHost obtains the first IP address of machine from the routing table and returns the IP address as string. -// An IPv4 address is preferred to an IPv6 address for backward compatibility. -func GetDefaultHost() (string, error) { - rmsgs, rerr := getDefaultRoutes() - if rerr != nil { - return "", rerr - } - - // prioritize IPv4 - if rmsg, ok := rmsgs[syscall.AF_INET]; ok { - if host, err := chooseHost(syscall.AF_INET, rmsg); host != "" || err != nil { - return host, err - } - delete(rmsgs, syscall.AF_INET) - } - - // sort so choice is deterministic - var families []int - for family := range rmsgs { - families = append(families, int(family)) - } - sort.Ints(families) - - for _, f := range families { - family := uint8(f) - if host, err := chooseHost(family, rmsgs[family]); host != "" || err != nil { - return host, err - } - } - - return "", errNoDefaultHost -} - -func chooseHost(family uint8, rmsg *syscall.NetlinkMessage) (string, error) { - host, oif, err := parsePREFSRC(rmsg) - if host != "" || err != nil { - return host, err - } - - // prefsrc not detected, fall back to getting address from iface - ifmsg, ierr := getIfaceAddr(oif, family) - if ierr != nil { - return "", ierr - } - - attrs, aerr := syscall.ParseNetlinkRouteAttr(ifmsg) - if aerr != nil { - return "", aerr - } - - for _, attr := range attrs { - // search for RTA_DST because ipv6 doesn't have RTA_SRC - if attr.Attr.Type == syscall.RTA_DST { - return net.IP(attr.Value).String(), nil - } - } - - return "", nil -} - -func getDefaultRoutes() (map[uint8]*syscall.NetlinkMessage, error) { - dat, err := syscall.NetlinkRIB(syscall.RTM_GETROUTE, syscall.AF_UNSPEC) - if err != nil { - return nil, err - } - - msgs, msgErr := syscall.ParseNetlinkMessage(dat) - if msgErr != nil { - return nil, msgErr - } - - routes := make(map[uint8]*syscall.NetlinkMessage) - rtmsg := syscall.RtMsg{} - for _, m := range msgs { - if m.Header.Type != syscall.RTM_NEWROUTE { - continue - } - buf := bytes.NewBuffer(m.Data[:syscall.SizeofRtMsg]) - if rerr := binary.Read(buf, cpuutil.ByteOrder(), &rtmsg); rerr != nil { - continue - } - if rtmsg.Dst_len == 0 && rtmsg.Table == syscall.RT_TABLE_MAIN { - // zero-length Dst_len implies default route - msg := m - routes[rtmsg.Family] = &msg - } - } - - if len(routes) > 0 { - return routes, nil - } - - return nil, errNoDefaultRoute -} - -// Used to get an address of interface. -func getIfaceAddr(idx uint32, family uint8) (*syscall.NetlinkMessage, error) { - dat, err := syscall.NetlinkRIB(syscall.RTM_GETADDR, int(family)) - if err != nil { - return nil, err - } - - msgs, msgErr := syscall.ParseNetlinkMessage(dat) - if msgErr != nil { - return nil, msgErr - } - - ifaddrmsg := syscall.IfAddrmsg{} - for _, m := range msgs { - if m.Header.Type != syscall.RTM_NEWADDR { - continue - } - buf := bytes.NewBuffer(m.Data[:syscall.SizeofIfAddrmsg]) - if rerr := binary.Read(buf, cpuutil.ByteOrder(), &ifaddrmsg); rerr != nil { - continue - } - if ifaddrmsg.Index == idx { - return &m, nil - } - } - - return nil, fmt.Errorf("could not find address for interface index %v", idx) - -} - -// Used to get a name of interface. -func getIfaceLink(idx uint32) (*syscall.NetlinkMessage, error) { - dat, err := syscall.NetlinkRIB(syscall.RTM_GETLINK, syscall.AF_UNSPEC) - if err != nil { - return nil, err - } - - msgs, msgErr := syscall.ParseNetlinkMessage(dat) - if msgErr != nil { - return nil, msgErr - } - - ifinfomsg := syscall.IfInfomsg{} - for _, m := range msgs { - if m.Header.Type != syscall.RTM_NEWLINK { - continue - } - buf := bytes.NewBuffer(m.Data[:syscall.SizeofIfInfomsg]) - if rerr := binary.Read(buf, cpuutil.ByteOrder(), &ifinfomsg); rerr != nil { - continue - } - if ifinfomsg.Index == int32(idx) { - return &m, nil - } - } - - return nil, fmt.Errorf("could not find link for interface index %v", idx) -} - -// GetDefaultInterfaces gets names of interfaces and returns a map[interface]families. -func GetDefaultInterfaces() (map[string]uint8, error) { - interfaces := make(map[string]uint8) - rmsgs, rerr := getDefaultRoutes() - if rerr != nil { - return interfaces, rerr - } - - for family, rmsg := range rmsgs { - _, oif, err := parsePREFSRC(rmsg) - if err != nil { - return interfaces, err - } - - ifmsg, ierr := getIfaceLink(oif) - if ierr != nil { - return interfaces, ierr - } - - attrs, aerr := syscall.ParseNetlinkRouteAttr(ifmsg) - if aerr != nil { - return interfaces, aerr - } - - for _, attr := range attrs { - if attr.Attr.Type == syscall.IFLA_IFNAME { - // key is an interface name - // possible values: 2 - AF_INET, 10 - AF_INET6, 12 - dualstack - interfaces[string(attr.Value[:len(attr.Value)-1])] += family - } - } - } - if len(interfaces) > 0 { - return interfaces, nil - } - return interfaces, errNoDefaultInterface -} - -// parsePREFSRC returns preferred source address and output interface index (RTA_OIF). -func parsePREFSRC(m *syscall.NetlinkMessage) (host string, oif uint32, err error) { - var attrs []syscall.NetlinkRouteAttr - attrs, err = syscall.ParseNetlinkRouteAttr(m) - if err != nil { - return "", 0, err - } - - for _, attr := range attrs { - if attr.Attr.Type == syscall.RTA_PREFSRC { - host = net.IP(attr.Value).String() - } - if attr.Attr.Type == syscall.RTA_OIF { - oif = cpuutil.ByteOrder().Uint32(attr.Value) - } - if host != "" && oif != uint32(0) { - break - } - } - - if oif == 0 { - err = errNoDefaultRoute - } - return host, oif, err -} diff --git a/vendor/go.etcd.io/etcd/pkg/v3/pbutil/pbutil.go b/vendor/go.etcd.io/etcd/pkg/v3/pbutil/pbutil.go deleted file mode 100644 index 821f59703a..0000000000 --- a/vendor/go.etcd.io/etcd/pkg/v3/pbutil/pbutil.go +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package pbutil defines interfaces for handling Protocol Buffer objects. -package pbutil - -import "fmt" - -type Marshaler interface { - Marshal() (data []byte, err error) -} - -type Unmarshaler interface { - Unmarshal(data []byte) error -} - -func MustMarshal(m Marshaler) []byte { - d, err := m.Marshal() - if err != nil { - panic(fmt.Sprintf("marshal should never fail (%v)", err)) - } - return d -} - -func MustUnmarshal(um Unmarshaler, data []byte) { - if err := um.Unmarshal(data); err != nil { - panic(fmt.Sprintf("unmarshal should never fail (%v)", err)) - } -} - -func MaybeUnmarshal(um Unmarshaler, data []byte) bool { - if err := um.Unmarshal(data); err != nil { - return false - } - return true -} - -func GetBool(v *bool) (vv bool, set bool) { - if v == nil { - return false, false - } - return *v, true -} - -func Boolp(b bool) *bool { return &b } diff --git a/vendor/go.etcd.io/etcd/pkg/v3/runtime/fds_linux.go b/vendor/go.etcd.io/etcd/pkg/v3/runtime/fds_linux.go deleted file mode 100644 index b5f6a7823a..0000000000 --- a/vendor/go.etcd.io/etcd/pkg/v3/runtime/fds_linux.go +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package runtime implements utility functions for runtime systems. -package runtime - -import ( - "os" - "syscall" -) - -func FDLimit() (uint64, error) { - var rlimit syscall.Rlimit - if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rlimit); err != nil { - return 0, err - } - return rlimit.Cur, nil -} - -func FDUsage() (uint64, error) { - return countFiles("/proc/self/fd") -} - -// countFiles reads the directory named by dirname and returns the count. -func countFiles(dirname string) (uint64, error) { - f, err := os.Open(dirname) - if err != nil { - return 0, err - } - list, err := f.Readdirnames(-1) - f.Close() - if err != nil { - return 0, err - } - return uint64(len(list)), nil -} diff --git a/vendor/go.etcd.io/etcd/pkg/v3/runtime/fds_other.go b/vendor/go.etcd.io/etcd/pkg/v3/runtime/fds_other.go deleted file mode 100644 index 034f3d4264..0000000000 --- a/vendor/go.etcd.io/etcd/pkg/v3/runtime/fds_other.go +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -//go:build !linux -// +build !linux - -package runtime - -import ( - "fmt" - "runtime" -) - -func FDLimit() (uint64, error) { - return 0, fmt.Errorf("cannot get FDLimit on %s", runtime.GOOS) -} - -func FDUsage() (uint64, error) { - return 0, fmt.Errorf("cannot get FDUsage on %s", runtime.GOOS) -} diff --git a/vendor/go.etcd.io/etcd/pkg/v3/schedule/doc.go b/vendor/go.etcd.io/etcd/pkg/v3/schedule/doc.go deleted file mode 100644 index cca2c75fb6..0000000000 --- a/vendor/go.etcd.io/etcd/pkg/v3/schedule/doc.go +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package schedule provides mechanisms and policies for scheduling units of work. -package schedule diff --git a/vendor/go.etcd.io/etcd/pkg/v3/schedule/schedule.go b/vendor/go.etcd.io/etcd/pkg/v3/schedule/schedule.go deleted file mode 100644 index 234d01989d..0000000000 --- a/vendor/go.etcd.io/etcd/pkg/v3/schedule/schedule.go +++ /dev/null @@ -1,165 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package schedule - -import ( - "context" - "sync" -) - -type Job func(context.Context) - -// Scheduler can schedule jobs. -type Scheduler interface { - // Schedule asks the scheduler to schedule a job defined by the given func. - // Schedule to a stopped scheduler might panic. - Schedule(j Job) - - // Pending returns number of pending jobs - Pending() int - - // Scheduled returns the number of scheduled jobs (excluding pending jobs) - Scheduled() int - - // Finished returns the number of finished jobs - Finished() int - - // WaitFinish waits until at least n job are finished and all pending jobs are finished. - WaitFinish(n int) - - // Stop stops the scheduler. - Stop() -} - -type fifo struct { - mu sync.Mutex - - resume chan struct{} - scheduled int - finished int - pendings []Job - - ctx context.Context - cancel context.CancelFunc - - finishCond *sync.Cond - donec chan struct{} -} - -// NewFIFOScheduler returns a Scheduler that schedules jobs in FIFO -// order sequentially -func NewFIFOScheduler() Scheduler { - f := &fifo{ - resume: make(chan struct{}, 1), - donec: make(chan struct{}, 1), - } - f.finishCond = sync.NewCond(&f.mu) - f.ctx, f.cancel = context.WithCancel(context.Background()) - go f.run() - return f -} - -// Schedule schedules a job that will be ran in FIFO order sequentially. -func (f *fifo) Schedule(j Job) { - f.mu.Lock() - defer f.mu.Unlock() - - if f.cancel == nil { - panic("schedule: schedule to stopped scheduler") - } - - if len(f.pendings) == 0 { - select { - case f.resume <- struct{}{}: - default: - } - } - f.pendings = append(f.pendings, j) -} - -func (f *fifo) Pending() int { - f.mu.Lock() - defer f.mu.Unlock() - return len(f.pendings) -} - -func (f *fifo) Scheduled() int { - f.mu.Lock() - defer f.mu.Unlock() - return f.scheduled -} - -func (f *fifo) Finished() int { - f.finishCond.L.Lock() - defer f.finishCond.L.Unlock() - return f.finished -} - -func (f *fifo) WaitFinish(n int) { - f.finishCond.L.Lock() - for f.finished < n || len(f.pendings) != 0 { - f.finishCond.Wait() - } - f.finishCond.L.Unlock() -} - -// Stop stops the scheduler and cancels all pending jobs. -func (f *fifo) Stop() { - f.mu.Lock() - f.cancel() - f.cancel = nil - f.mu.Unlock() - <-f.donec -} - -func (f *fifo) run() { - // TODO: recover from job panic? - defer func() { - close(f.donec) - close(f.resume) - }() - - for { - var todo Job - f.mu.Lock() - if len(f.pendings) != 0 { - f.scheduled++ - todo = f.pendings[0] - } - f.mu.Unlock() - if todo == nil { - select { - case <-f.resume: - case <-f.ctx.Done(): - f.mu.Lock() - pendings := f.pendings - f.pendings = nil - f.mu.Unlock() - // clean up pending jobs - for _, todo := range pendings { - todo(f.ctx) - } - return - } - } else { - todo(f.ctx) - f.finishCond.L.Lock() - f.finished++ - f.pendings = f.pendings[1:] - f.finishCond.Broadcast() - f.finishCond.L.Unlock() - } - } -} diff --git a/vendor/go.etcd.io/etcd/pkg/v3/traceutil/trace.go b/vendor/go.etcd.io/etcd/pkg/v3/traceutil/trace.go deleted file mode 100644 index bdd8e9b66a..0000000000 --- a/vendor/go.etcd.io/etcd/pkg/v3/traceutil/trace.go +++ /dev/null @@ -1,240 +0,0 @@ -// Copyright 2019 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package traceutil implements tracing utilities using "context". -package traceutil - -import ( - "bytes" - "context" - "fmt" - "math/rand" - "time" - - "go.uber.org/zap" -) - -const ( - TraceKey = "trace" - StartTimeKey = "startTime" -) - -// Field is a kv pair to record additional details of the trace. -type Field struct { - Key string - Value interface{} -} - -func (f *Field) format() string { - return fmt.Sprintf("%s:%v; ", f.Key, f.Value) -} - -func writeFields(fields []Field) string { - if len(fields) == 0 { - return "" - } - var buf bytes.Buffer - buf.WriteString("{") - for _, f := range fields { - buf.WriteString(f.format()) - } - buf.WriteString("}") - return buf.String() -} - -type Trace struct { - operation string - lg *zap.Logger - fields []Field - startTime time.Time - steps []step - stepDisabled bool - isEmpty bool -} - -type step struct { - time time.Time - msg string - fields []Field - isSubTraceStart bool - isSubTraceEnd bool -} - -func New(op string, lg *zap.Logger, fields ...Field) *Trace { - return &Trace{operation: op, lg: lg, startTime: time.Now(), fields: fields} -} - -// TODO returns a non-nil, empty Trace -func TODO() *Trace { - return &Trace{isEmpty: true} -} - -func Get(ctx context.Context) *Trace { - if trace, ok := ctx.Value(TraceKey).(*Trace); ok && trace != nil { - return trace - } - return TODO() -} - -func (t *Trace) GetStartTime() time.Time { - return t.startTime -} - -func (t *Trace) SetStartTime(time time.Time) { - t.startTime = time -} - -func (t *Trace) InsertStep(at int, time time.Time, msg string, fields ...Field) { - newStep := step{time: time, msg: msg, fields: fields} - if at < len(t.steps) { - t.steps = append(t.steps[:at+1], t.steps[at:]...) - t.steps[at] = newStep - } else { - t.steps = append(t.steps, newStep) - } -} - -// StartSubTrace adds step to trace as a start sign of sublevel trace -// All steps in the subtrace will log out the input fields of this function -func (t *Trace) StartSubTrace(fields ...Field) { - t.steps = append(t.steps, step{fields: fields, isSubTraceStart: true}) -} - -// StopSubTrace adds step to trace as a end sign of sublevel trace -// All steps in the subtrace will log out the input fields of this function -func (t *Trace) StopSubTrace(fields ...Field) { - t.steps = append(t.steps, step{fields: fields, isSubTraceEnd: true}) -} - -// Step adds step to trace -func (t *Trace) Step(msg string, fields ...Field) { - if !t.stepDisabled { - t.steps = append(t.steps, step{time: time.Now(), msg: msg, fields: fields}) - } -} - -// StepWithFunction will measure the input function as a single step -func (t *Trace) StepWithFunction(f func(), msg string, fields ...Field) { - t.disableStep() - f() - t.enableStep() - t.Step(msg, fields...) -} - -func (t *Trace) AddField(fields ...Field) { - for _, f := range fields { - if !t.updateFieldIfExist(f) { - t.fields = append(t.fields, f) - } - } -} - -func (t *Trace) IsEmpty() bool { - return t.isEmpty -} - -// Log dumps all steps in the Trace -func (t *Trace) Log() { - t.LogWithStepThreshold(0) -} - -// LogIfLong dumps logs if the duration is longer than threshold -func (t *Trace) LogIfLong(threshold time.Duration) { - if time.Since(t.startTime) > threshold { - stepThreshold := threshold / time.Duration(len(t.steps)+1) - t.LogWithStepThreshold(stepThreshold) - } -} - -// LogAllStepsIfLong dumps all logs if the duration is longer than threshold -func (t *Trace) LogAllStepsIfLong(threshold time.Duration) { - if time.Since(t.startTime) > threshold { - t.LogWithStepThreshold(0) - } -} - -// LogWithStepThreshold only dumps step whose duration is longer than step threshold -func (t *Trace) LogWithStepThreshold(threshold time.Duration) { - msg, fs := t.logInfo(threshold) - if t.lg != nil { - t.lg.Info(msg, fs...) - } -} - -func (t *Trace) logInfo(threshold time.Duration) (string, []zap.Field) { - endTime := time.Now() - totalDuration := endTime.Sub(t.startTime) - traceNum := rand.Int31() - msg := fmt.Sprintf("trace[%d] %s", traceNum, t.operation) - - var steps []string - lastStepTime := t.startTime - for i := 0; i < len(t.steps); i++ { - step := t.steps[i] - // add subtrace common fields which defined at the beginning to each sub-steps - if step.isSubTraceStart { - for j := i + 1; j < len(t.steps) && !t.steps[j].isSubTraceEnd; j++ { - t.steps[j].fields = append(step.fields, t.steps[j].fields...) - } - continue - } - // add subtrace common fields which defined at the end to each sub-steps - if step.isSubTraceEnd { - for j := i - 1; j >= 0 && !t.steps[j].isSubTraceStart; j-- { - t.steps[j].fields = append(step.fields, t.steps[j].fields...) - } - continue - } - } - for i := 0; i < len(t.steps); i++ { - step := t.steps[i] - if step.isSubTraceStart || step.isSubTraceEnd { - continue - } - stepDuration := step.time.Sub(lastStepTime) - if stepDuration > threshold { - steps = append(steps, fmt.Sprintf("trace[%d] '%v' %s (duration: %v)", - traceNum, step.msg, writeFields(step.fields), stepDuration)) - } - lastStepTime = step.time - } - - fs := []zap.Field{zap.String("detail", writeFields(t.fields)), - zap.Duration("duration", totalDuration), - zap.Time("start", t.startTime), - zap.Time("end", endTime), - zap.Strings("steps", steps), - zap.Int("step_count", len(steps))} - return msg, fs -} - -func (t *Trace) updateFieldIfExist(f Field) bool { - for i, v := range t.fields { - if v.Key == f.Key { - t.fields[i].Value = f.Value - return true - } - } - return false -} - -// disableStep sets the flag to prevent the trace from adding steps -func (t *Trace) disableStep() { - t.stepDisabled = true -} - -// enableStep re-enable the trace to add steps -func (t *Trace) enableStep() { - t.stepDisabled = false -} diff --git a/vendor/go.etcd.io/etcd/pkg/v3/wait/wait.go b/vendor/go.etcd.io/etcd/pkg/v3/wait/wait.go deleted file mode 100644 index a3e2aec7cb..0000000000 --- a/vendor/go.etcd.io/etcd/pkg/v3/wait/wait.go +++ /dev/null @@ -1,110 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package wait provides utility functions for polling, listening using Go -// channel. -package wait - -import ( - "log" - "sync" -) - -const ( - // To avoid lock contention we use an array of list struct (rw mutex & map) - // for the id argument, we apply mod operation and uses its remainder to - // index into the array and find the corresponding element. - defaultListElementLength = 64 -) - -// Wait is an interface that provides the ability to wait and trigger events that -// are associated with IDs. -type Wait interface { - // Register waits returns a chan that waits on the given ID. - // The chan will be triggered when Trigger is called with - // the same ID. - Register(id uint64) <-chan interface{} - // Trigger triggers the waiting chans with the given ID. - Trigger(id uint64, x interface{}) - IsRegistered(id uint64) bool -} - -type list struct { - e []listElement -} - -type listElement struct { - l sync.RWMutex - m map[uint64]chan interface{} -} - -// New creates a Wait. -func New() Wait { - res := list{ - e: make([]listElement, defaultListElementLength), - } - for i := 0; i < len(res.e); i++ { - res.e[i].m = make(map[uint64]chan interface{}) - } - return &res -} - -func (w *list) Register(id uint64) <-chan interface{} { - idx := id % defaultListElementLength - newCh := make(chan interface{}, 1) - w.e[idx].l.Lock() - defer w.e[idx].l.Unlock() - if _, ok := w.e[idx].m[id]; !ok { - w.e[idx].m[id] = newCh - } else { - log.Panicf("dup id %x", id) - } - return newCh -} - -func (w *list) Trigger(id uint64, x interface{}) { - idx := id % defaultListElementLength - w.e[idx].l.Lock() - ch := w.e[idx].m[id] - delete(w.e[idx].m, id) - w.e[idx].l.Unlock() - if ch != nil { - ch <- x - close(ch) - } -} - -func (w *list) IsRegistered(id uint64) bool { - idx := id % defaultListElementLength - w.e[idx].l.RLock() - defer w.e[idx].l.RUnlock() - _, ok := w.e[idx].m[id] - return ok -} - -type waitWithResponse struct { - ch <-chan interface{} -} - -func NewWithResponse(ch <-chan interface{}) Wait { - return &waitWithResponse{ch: ch} -} - -func (w *waitWithResponse) Register(id uint64) <-chan interface{} { - return w.ch -} -func (w *waitWithResponse) Trigger(id uint64, x interface{}) {} -func (w *waitWithResponse) IsRegistered(id uint64) bool { - panic("waitWithResponse.IsRegistered() shouldn't be called") -} diff --git a/vendor/go.etcd.io/etcd/pkg/v3/wait/wait_time.go b/vendor/go.etcd.io/etcd/pkg/v3/wait/wait_time.go deleted file mode 100644 index 297e48a47d..0000000000 --- a/vendor/go.etcd.io/etcd/pkg/v3/wait/wait_time.go +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package wait - -import "sync" - -type WaitTime interface { - // Wait returns a chan that waits on the given logical deadline. - // The chan will be triggered when Trigger is called with a - // deadline that is later than the one it is waiting for. - Wait(deadline uint64) <-chan struct{} - // Trigger triggers all the waiting chans with an earlier logical deadline. - Trigger(deadline uint64) -} - -var closec chan struct{} - -func init() { closec = make(chan struct{}); close(closec) } - -type timeList struct { - l sync.Mutex - lastTriggerDeadline uint64 - m map[uint64]chan struct{} -} - -func NewTimeList() *timeList { - return &timeList{m: make(map[uint64]chan struct{})} -} - -func (tl *timeList) Wait(deadline uint64) <-chan struct{} { - tl.l.Lock() - defer tl.l.Unlock() - if tl.lastTriggerDeadline >= deadline { - return closec - } - ch := tl.m[deadline] - if ch == nil { - ch = make(chan struct{}) - tl.m[deadline] = ch - } - return ch -} - -func (tl *timeList) Trigger(deadline uint64) { - tl.l.Lock() - defer tl.l.Unlock() - tl.lastTriggerDeadline = deadline - for t, ch := range tl.m { - if t <= deadline { - delete(tl.m, t) - close(ch) - } - } -} diff --git a/vendor/go.etcd.io/etcd/raft/v3/LICENSE b/vendor/go.etcd.io/etcd/raft/v3/LICENSE deleted file mode 100644 index d645695673..0000000000 --- a/vendor/go.etcd.io/etcd/raft/v3/LICENSE +++ /dev/null @@ -1,202 +0,0 @@ - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. diff --git a/vendor/go.etcd.io/etcd/raft/v3/OWNERS b/vendor/go.etcd.io/etcd/raft/v3/OWNERS deleted file mode 100644 index ab781066e2..0000000000 --- a/vendor/go.etcd.io/etcd/raft/v3/OWNERS +++ /dev/null @@ -1,19 +0,0 @@ -approvers: -- heyitsanthony -- philips -- fanminshi -- gyuho -- mitake -- jpbetz -- xiang90 -- bdarnell -reviewers: -- heyitsanthony -- philips -- fanminshi -- gyuho -- mitake -- jpbetz -- xiang90 -- bdarnell -- tschottdorf diff --git a/vendor/go.etcd.io/etcd/raft/v3/README.md b/vendor/go.etcd.io/etcd/raft/v3/README.md deleted file mode 100644 index fbd8b4d49b..0000000000 --- a/vendor/go.etcd.io/etcd/raft/v3/README.md +++ /dev/null @@ -1,201 +0,0 @@ -# Raft library - -Raft is a protocol with which a cluster of nodes can maintain a replicated state machine. -The state machine is kept in sync through the use of a replicated log. -For more details on Raft, see "In Search of an Understandable Consensus Algorithm" -(https://raft.github.io/raft.pdf) by Diego Ongaro and John Ousterhout. - -This Raft library is stable and feature complete. As of 2016, it is **the most widely used** Raft library in production, serving tens of thousands clusters each day. It powers distributed systems such as etcd, Kubernetes, Docker Swarm, Cloud Foundry Diego, CockroachDB, TiDB, Project Calico, Flannel, Hyperledger and more. - -Most Raft implementations have a monolithic design, including storage handling, messaging serialization, and network transport. This library instead follows a minimalistic design philosophy by only implementing the core raft algorithm. This minimalism buys flexibility, determinism, and performance. - -To keep the codebase small as well as provide flexibility, the library only implements the Raft algorithm; both network and disk IO are left to the user. Library users must implement their own transportation layer for message passing between Raft peers over the wire. Similarly, users must implement their own storage layer to persist the Raft log and state. - -In order to easily test the Raft library, its behavior should be deterministic. To achieve this determinism, the library models Raft as a state machine. The state machine takes a `Message` as input. A message can either be a local timer update or a network message sent from a remote peer. The state machine's output is a 3-tuple `{[]Messages, []LogEntries, NextState}` consisting of an array of `Messages`, `log entries`, and `Raft state changes`. For state machines with the same state, the same state machine input should always generate the same state machine output. - -A simple example application, _raftexample_, is also available to help illustrate how to use this package in practice: https://github.com/etcd-io/etcd/tree/main/contrib/raftexample - -# Features - -This raft implementation is a full feature implementation of Raft protocol. Features includes: - -- Leader election -- Log replication -- Log compaction -- Membership changes -- Leadership transfer extension -- Efficient linearizable read-only queries served by both the leader and followers - - leader checks with quorum and bypasses Raft log before processing read-only queries - - followers asks leader to get a safe read index before processing read-only queries -- More efficient lease-based linearizable read-only queries served by both the leader and followers - - leader bypasses Raft log and processing read-only queries locally - - followers asks leader to get a safe read index before processing read-only queries - - this approach relies on the clock of the all the machines in raft group - -This raft implementation also includes a few optional enhancements: - -- Optimistic pipelining to reduce log replication latency -- Flow control for log replication -- Batching Raft messages to reduce synchronized network I/O calls -- Batching log entries to reduce disk synchronized I/O -- Writing to leader's disk in parallel -- Internal proposal redirection from followers to leader -- Automatic stepping down when the leader loses quorum -- Protection against unbounded log growth when quorum is lost - -## Notable Users - -- [cockroachdb](https://github.com/cockroachdb/cockroach) A Scalable, Survivable, Strongly-Consistent SQL Database -- [dgraph](https://github.com/dgraph-io/dgraph) A Scalable, Distributed, Low Latency, High Throughput Graph Database -- [etcd](https://github.com/etcd-io/etcd) A distributed reliable key-value store -- [tikv](https://github.com/pingcap/tikv) A Distributed transactional key value database powered by Rust and Raft -- [swarmkit](https://github.com/docker/swarmkit) A toolkit for orchestrating distributed systems at any scale. -- [chain core](https://github.com/chain/chain) Software for operating permissioned, multi-asset blockchain networks - -## Usage - -The primary object in raft is a Node. Either start a Node from scratch using raft.StartNode or start a Node from some initial state using raft.RestartNode. - -To start a three-node cluster -```go - storage := raft.NewMemoryStorage() - c := &raft.Config{ - ID: 0x01, - ElectionTick: 10, - HeartbeatTick: 1, - Storage: storage, - MaxSizePerMsg: 4096, - MaxInflightMsgs: 256, - } - // Set peer list to the other nodes in the cluster. - // Note that they need to be started separately as well. - n := raft.StartNode(c, []raft.Peer{{ID: 0x02}, {ID: 0x03}}) -``` - -Start a single node cluster, like so: -```go - // Create storage and config as shown above. - // Set peer list to itself, so this node can become the leader of this single-node cluster. - peers := []raft.Peer{{ID: 0x01}} - n := raft.StartNode(c, peers) -``` - -To allow a new node to join this cluster, do not pass in any peers. First, add the node to the existing cluster by calling `ProposeConfChange` on any existing node inside the cluster. Then, start the node with an empty peer list, like so: -```go - // Create storage and config as shown above. - n := raft.StartNode(c, nil) -``` - -To restart a node from previous state: -```go - storage := raft.NewMemoryStorage() - - // Recover the in-memory storage from persistent snapshot, state and entries. - storage.ApplySnapshot(snapshot) - storage.SetHardState(state) - storage.Append(entries) - - c := &raft.Config{ - ID: 0x01, - ElectionTick: 10, - HeartbeatTick: 1, - Storage: storage, - MaxSizePerMsg: 4096, - MaxInflightMsgs: 256, - } - - // Restart raft without peer information. - // Peer information is already included in the storage. - n := raft.RestartNode(c) -``` - -After creating a Node, the user has a few responsibilities: - -First, read from the Node.Ready() channel and process the updates it contains. These steps may be performed in parallel, except as noted in step 2. - -1. Write Entries, HardState and Snapshot to persistent storage in order, i.e. Entries first, then HardState and Snapshot if they are not empty. If persistent storage supports atomic writes then all of them can be written together. Note that when writing an Entry with Index i, any previously-persisted entries with Index >= i must be discarded. - -2. Send all Messages to the nodes named in the To field. It is important that no messages be sent until the latest HardState has been persisted to disk, and all Entries written by any previous Ready batch (Messages may be sent while entries from the same batch are being persisted). To reduce the I/O latency, an optimization can be applied to make leader write to disk in parallel with its followers (as explained at section 10.2.1 in Raft thesis). If any Message has type MsgSnap, call Node.ReportSnapshot() after it has been sent (these messages may be large). Note: Marshalling messages is not thread-safe; it is important to make sure that no new entries are persisted while marshalling. The easiest way to achieve this is to serialise the messages directly inside the main raft loop. - -3. Apply Snapshot (if any) and CommittedEntries to the state machine. If any committed Entry has Type EntryConfChange, call Node.ApplyConfChange() to apply it to the node. The configuration change may be cancelled at this point by setting the NodeID field to zero before calling ApplyConfChange (but ApplyConfChange must be called one way or the other, and the decision to cancel must be based solely on the state machine and not external information such as the observed health of the node). - -4. Call Node.Advance() to signal readiness for the next batch of updates. This may be done at any time after step 1, although all updates must be processed in the order they were returned by Ready. - -Second, all persisted log entries must be made available via an implementation of the Storage interface. The provided MemoryStorage type can be used for this (if repopulating its state upon a restart), or a custom disk-backed implementation can be supplied. - -Third, after receiving a message from another node, pass it to Node.Step: - -```go - func recvRaftRPC(ctx context.Context, m raftpb.Message) { - n.Step(ctx, m) - } -``` - -Finally, call `Node.Tick()` at regular intervals (probably via a `time.Ticker`). Raft has two important timeouts: heartbeat and the election timeout. However, internally to the raft package time is represented by an abstract "tick". - -The total state machine handling loop will look something like this: - -```go - for { - select { - case <-s.Ticker: - n.Tick() - case rd := <-s.Node.Ready(): - saveToStorage(rd.HardState, rd.Entries, rd.Snapshot) - send(rd.Messages) - if !raft.IsEmptySnap(rd.Snapshot) { - processSnapshot(rd.Snapshot) - } - for _, entry := range rd.CommittedEntries { - process(entry) - if entry.Type == raftpb.EntryConfChange { - var cc raftpb.ConfChange - cc.Unmarshal(entry.Data) - s.Node.ApplyConfChange(cc) - } - } - s.Node.Advance() - case <-s.done: - return - } - } -``` - -To propose changes to the state machine from the node to take application data, serialize it into a byte slice and call: - -```go - n.Propose(ctx, data) -``` - -If the proposal is committed, data will appear in committed entries with type raftpb.EntryNormal. There is no guarantee that a proposed command will be committed; the command may have to be reproposed after a timeout. - -To add or remove node in a cluster, build ConfChange struct 'cc' and call: - -```go - n.ProposeConfChange(ctx, cc) -``` - -After config change is committed, some committed entry with type raftpb.EntryConfChange will be returned. This must be applied to node through: - -```go - var cc raftpb.ConfChange - cc.Unmarshal(data) - n.ApplyConfChange(cc) -``` - -Note: An ID represents a unique node in a cluster for all time. A -given ID MUST be used only once even if the old node has been removed. -This means that for example IP addresses make poor node IDs since they -may be reused. Node IDs must be non-zero. - -## Implementation notes - -This implementation is up to date with the final Raft thesis (https://github.com/ongardie/dissertation/blob/master/stanford.pdf), although this implementation of the membership change protocol differs somewhat from that described in chapter 4. The key invariant that membership changes happen one node at a time is preserved, but in our implementation the membership change takes effect when its entry is applied, not when it is added to the log (so the entry is committed under the old membership instead of the new). This is equivalent in terms of safety, since the old and new configurations are guaranteed to overlap. - -To ensure there is no attempt to commit two membership changes at once by matching log positions (which would be unsafe since they should have different quorum requirements), any proposed membership change is simply disallowed while any uncommitted change appears in the leader's log. - -This approach introduces a problem when removing a member from a two-member cluster: If one of the members dies before the other one receives the commit of the confchange entry, then the member cannot be removed any more since the cluster cannot make progress. For this reason it is highly recommended to use three or more nodes in every cluster. - -## Go docs - -More detailed development documentation can be found in go docs: https://pkg.go.dev/go.etcd.io/etcd/raft/v3. \ No newline at end of file diff --git a/vendor/go.etcd.io/etcd/raft/v3/bootstrap.go b/vendor/go.etcd.io/etcd/raft/v3/bootstrap.go deleted file mode 100644 index 824bd5f51b..0000000000 --- a/vendor/go.etcd.io/etcd/raft/v3/bootstrap.go +++ /dev/null @@ -1,80 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package raft - -import ( - "errors" - - pb "go.etcd.io/etcd/raft/v3/raftpb" -) - -// Bootstrap initializes the RawNode for first use by appending configuration -// changes for the supplied peers. This method returns an error if the Storage -// is nonempty. -// -// It is recommended that instead of calling this method, applications bootstrap -// their state manually by setting up a Storage that has a first index > 1 and -// which stores the desired ConfState as its InitialState. -func (rn *RawNode) Bootstrap(peers []Peer) error { - if len(peers) == 0 { - return errors.New("must provide at least one peer to Bootstrap") - } - lastIndex, err := rn.raft.raftLog.storage.LastIndex() - if err != nil { - return err - } - - if lastIndex != 0 { - return errors.New("can't bootstrap a nonempty Storage") - } - - // We've faked out initial entries above, but nothing has been - // persisted. Start with an empty HardState (thus the first Ready will - // emit a HardState update for the app to persist). - rn.prevHardSt = emptyState - - // TODO(tbg): remove StartNode and give the application the right tools to - // bootstrap the initial membership in a cleaner way. - rn.raft.becomeFollower(1, None) - ents := make([]pb.Entry, len(peers)) - for i, peer := range peers { - cc := pb.ConfChange{Type: pb.ConfChangeAddNode, NodeID: peer.ID, Context: peer.Context} - data, err := cc.Marshal() - if err != nil { - return err - } - - ents[i] = pb.Entry{Type: pb.EntryConfChange, Term: 1, Index: uint64(i + 1), Data: data} - } - rn.raft.raftLog.append(ents...) - - // Now apply them, mainly so that the application can call Campaign - // immediately after StartNode in tests. Note that these nodes will - // be added to raft twice: here and when the application's Ready - // loop calls ApplyConfChange. The calls to addNode must come after - // all calls to raftLog.append so progress.next is set after these - // bootstrapping entries (it is an error if we try to append these - // entries since they have already been committed). - // We do not set raftLog.applied so the application will be able - // to observe all conf changes via Ready.CommittedEntries. - // - // TODO(bdarnell): These entries are still unstable; do we need to preserve - // the invariant that committed < unstable? - rn.raft.raftLog.committed = uint64(len(ents)) - for _, peer := range peers { - rn.raft.applyConfChange(pb.ConfChange{NodeID: peer.ID, Type: pb.ConfChangeAddNode}.AsV2()) - } - return nil -} diff --git a/vendor/go.etcd.io/etcd/raft/v3/confchange/confchange.go b/vendor/go.etcd.io/etcd/raft/v3/confchange/confchange.go deleted file mode 100644 index 55e6830ce8..0000000000 --- a/vendor/go.etcd.io/etcd/raft/v3/confchange/confchange.go +++ /dev/null @@ -1,421 +0,0 @@ -// Copyright 2019 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package confchange - -import ( - "errors" - "fmt" - "strings" - - "go.etcd.io/etcd/raft/v3/quorum" - pb "go.etcd.io/etcd/raft/v3/raftpb" - "go.etcd.io/etcd/raft/v3/tracker" -) - -// Changer facilitates configuration changes. It exposes methods to handle -// simple and joint consensus while performing the proper validation that allows -// refusing invalid configuration changes before they affect the active -// configuration. -type Changer struct { - Tracker tracker.ProgressTracker - LastIndex uint64 -} - -// EnterJoint verifies that the outgoing (=right) majority config of the joint -// config is empty and initializes it with a copy of the incoming (=left) -// majority config. That is, it transitions from -// -// (1 2 3)&&() -// to -// (1 2 3)&&(1 2 3). -// -// The supplied changes are then applied to the incoming majority config, -// resulting in a joint configuration that in terms of the Raft thesis[1] -// (Section 4.3) corresponds to `C_{new,old}`. -// -// [1]: https://github.com/ongardie/dissertation/blob/master/online-trim.pdf -func (c Changer) EnterJoint(autoLeave bool, ccs ...pb.ConfChangeSingle) (tracker.Config, tracker.ProgressMap, error) { - cfg, prs, err := c.checkAndCopy() - if err != nil { - return c.err(err) - } - if joint(cfg) { - err := errors.New("config is already joint") - return c.err(err) - } - if len(incoming(cfg.Voters)) == 0 { - // We allow adding nodes to an empty config for convenience (testing and - // bootstrap), but you can't enter a joint state. - err := errors.New("can't make a zero-voter config joint") - return c.err(err) - } - // Clear the outgoing config. - *outgoingPtr(&cfg.Voters) = quorum.MajorityConfig{} - // Copy incoming to outgoing. - for id := range incoming(cfg.Voters) { - outgoing(cfg.Voters)[id] = struct{}{} - } - - if err := c.apply(&cfg, prs, ccs...); err != nil { - return c.err(err) - } - cfg.AutoLeave = autoLeave - return checkAndReturn(cfg, prs) -} - -// LeaveJoint transitions out of a joint configuration. It is an error to call -// this method if the configuration is not joint, i.e. if the outgoing majority -// config Voters[1] is empty. -// -// The outgoing majority config of the joint configuration will be removed, -// that is, the incoming config is promoted as the sole decision maker. In the -// notation of the Raft thesis[1] (Section 4.3), this method transitions from -// `C_{new,old}` into `C_new`. -// -// At the same time, any staged learners (LearnersNext) the addition of which -// was held back by an overlapping voter in the former outgoing config will be -// inserted into Learners. -// -// [1]: https://github.com/ongardie/dissertation/blob/master/online-trim.pdf -func (c Changer) LeaveJoint() (tracker.Config, tracker.ProgressMap, error) { - cfg, prs, err := c.checkAndCopy() - if err != nil { - return c.err(err) - } - if !joint(cfg) { - err := errors.New("can't leave a non-joint config") - return c.err(err) - } - if len(outgoing(cfg.Voters)) == 0 { - err := fmt.Errorf("configuration is not joint: %v", cfg) - return c.err(err) - } - for id := range cfg.LearnersNext { - nilAwareAdd(&cfg.Learners, id) - prs[id].IsLearner = true - } - cfg.LearnersNext = nil - - for id := range outgoing(cfg.Voters) { - _, isVoter := incoming(cfg.Voters)[id] - _, isLearner := cfg.Learners[id] - - if !isVoter && !isLearner { - delete(prs, id) - } - } - *outgoingPtr(&cfg.Voters) = nil - cfg.AutoLeave = false - - return checkAndReturn(cfg, prs) -} - -// Simple carries out a series of configuration changes that (in aggregate) -// mutates the incoming majority config Voters[0] by at most one. This method -// will return an error if that is not the case, if the resulting quorum is -// zero, or if the configuration is in a joint state (i.e. if there is an -// outgoing configuration). -func (c Changer) Simple(ccs ...pb.ConfChangeSingle) (tracker.Config, tracker.ProgressMap, error) { - cfg, prs, err := c.checkAndCopy() - if err != nil { - return c.err(err) - } - if joint(cfg) { - err := errors.New("can't apply simple config change in joint config") - return c.err(err) - } - if err := c.apply(&cfg, prs, ccs...); err != nil { - return c.err(err) - } - if n := symdiff(incoming(c.Tracker.Voters), incoming(cfg.Voters)); n > 1 { - return tracker.Config{}, nil, errors.New("more than one voter changed without entering joint config") - } - - return checkAndReturn(cfg, prs) -} - -// apply a change to the configuration. By convention, changes to voters are -// always made to the incoming majority config Voters[0]. Voters[1] is either -// empty or preserves the outgoing majority configuration while in a joint state. -func (c Changer) apply(cfg *tracker.Config, prs tracker.ProgressMap, ccs ...pb.ConfChangeSingle) error { - for _, cc := range ccs { - if cc.NodeID == 0 { - // etcd replaces the NodeID with zero if it decides (downstream of - // raft) to not apply a change, so we have to have explicit code - // here to ignore these. - continue - } - switch cc.Type { - case pb.ConfChangeAddNode: - c.makeVoter(cfg, prs, cc.NodeID) - case pb.ConfChangeAddLearnerNode: - c.makeLearner(cfg, prs, cc.NodeID) - case pb.ConfChangeRemoveNode: - c.remove(cfg, prs, cc.NodeID) - case pb.ConfChangeUpdateNode: - default: - return fmt.Errorf("unexpected conf type %d", cc.Type) - } - } - if len(incoming(cfg.Voters)) == 0 { - return errors.New("removed all voters") - } - return nil -} - -// makeVoter adds or promotes the given ID to be a voter in the incoming -// majority config. -func (c Changer) makeVoter(cfg *tracker.Config, prs tracker.ProgressMap, id uint64) { - pr := prs[id] - if pr == nil { - c.initProgress(cfg, prs, id, false /* isLearner */) - return - } - - pr.IsLearner = false - nilAwareDelete(&cfg.Learners, id) - nilAwareDelete(&cfg.LearnersNext, id) - incoming(cfg.Voters)[id] = struct{}{} -} - -// makeLearner makes the given ID a learner or stages it to be a learner once -// an active joint configuration is exited. -// -// The former happens when the peer is not a part of the outgoing config, in -// which case we either add a new learner or demote a voter in the incoming -// config. -// -// The latter case occurs when the configuration is joint and the peer is a -// voter in the outgoing config. In that case, we do not want to add the peer -// as a learner because then we'd have to track a peer as a voter and learner -// simultaneously. Instead, we add the learner to LearnersNext, so that it will -// be added to Learners the moment the outgoing config is removed by -// LeaveJoint(). -func (c Changer) makeLearner(cfg *tracker.Config, prs tracker.ProgressMap, id uint64) { - pr := prs[id] - if pr == nil { - c.initProgress(cfg, prs, id, true /* isLearner */) - return - } - if pr.IsLearner { - return - } - // Remove any existing voter in the incoming config... - c.remove(cfg, prs, id) - // ... but save the Progress. - prs[id] = pr - // Use LearnersNext if we can't add the learner to Learners directly, i.e. - // if the peer is still tracked as a voter in the outgoing config. It will - // be turned into a learner in LeaveJoint(). - // - // Otherwise, add a regular learner right away. - if _, onRight := outgoing(cfg.Voters)[id]; onRight { - nilAwareAdd(&cfg.LearnersNext, id) - } else { - pr.IsLearner = true - nilAwareAdd(&cfg.Learners, id) - } -} - -// remove this peer as a voter or learner from the incoming config. -func (c Changer) remove(cfg *tracker.Config, prs tracker.ProgressMap, id uint64) { - if _, ok := prs[id]; !ok { - return - } - - delete(incoming(cfg.Voters), id) - nilAwareDelete(&cfg.Learners, id) - nilAwareDelete(&cfg.LearnersNext, id) - - // If the peer is still a voter in the outgoing config, keep the Progress. - if _, onRight := outgoing(cfg.Voters)[id]; !onRight { - delete(prs, id) - } -} - -// initProgress initializes a new progress for the given node or learner. -func (c Changer) initProgress(cfg *tracker.Config, prs tracker.ProgressMap, id uint64, isLearner bool) { - if !isLearner { - incoming(cfg.Voters)[id] = struct{}{} - } else { - nilAwareAdd(&cfg.Learners, id) - } - prs[id] = &tracker.Progress{ - // Initializing the Progress with the last index means that the follower - // can be probed (with the last index). - // - // TODO(tbg): seems awfully optimistic. Using the first index would be - // better. The general expectation here is that the follower has no log - // at all (and will thus likely need a snapshot), though the app may - // have applied a snapshot out of band before adding the replica (thus - // making the first index the better choice). - Next: c.LastIndex, - Match: 0, - Inflights: tracker.NewInflights(c.Tracker.MaxInflight), - IsLearner: isLearner, - // When a node is first added, we should mark it as recently active. - // Otherwise, CheckQuorum may cause us to step down if it is invoked - // before the added node has had a chance to communicate with us. - RecentActive: true, - } -} - -// checkInvariants makes sure that the config and progress are compatible with -// each other. This is used to check both what the Changer is initialized with, -// as well as what it returns. -func checkInvariants(cfg tracker.Config, prs tracker.ProgressMap) error { - // NB: intentionally allow the empty config. In production we'll never see a - // non-empty config (we prevent it from being created) but we will need to - // be able to *create* an initial config, for example during bootstrap (or - // during tests). Instead of having to hand-code this, we allow - // transitioning from an empty config into any other legal and non-empty - // config. - for _, ids := range []map[uint64]struct{}{ - cfg.Voters.IDs(), - cfg.Learners, - cfg.LearnersNext, - } { - for id := range ids { - if _, ok := prs[id]; !ok { - return fmt.Errorf("no progress for %d", id) - } - } - } - - // Any staged learner was staged because it could not be directly added due - // to a conflicting voter in the outgoing config. - for id := range cfg.LearnersNext { - if _, ok := outgoing(cfg.Voters)[id]; !ok { - return fmt.Errorf("%d is in LearnersNext, but not Voters[1]", id) - } - if prs[id].IsLearner { - return fmt.Errorf("%d is in LearnersNext, but is already marked as learner", id) - } - } - // Conversely Learners and Voters doesn't intersect at all. - for id := range cfg.Learners { - if _, ok := outgoing(cfg.Voters)[id]; ok { - return fmt.Errorf("%d is in Learners and Voters[1]", id) - } - if _, ok := incoming(cfg.Voters)[id]; ok { - return fmt.Errorf("%d is in Learners and Voters[0]", id) - } - if !prs[id].IsLearner { - return fmt.Errorf("%d is in Learners, but is not marked as learner", id) - } - } - - if !joint(cfg) { - // We enforce that empty maps are nil instead of zero. - if outgoing(cfg.Voters) != nil { - return fmt.Errorf("cfg.Voters[1] must be nil when not joint") - } - if cfg.LearnersNext != nil { - return fmt.Errorf("cfg.LearnersNext must be nil when not joint") - } - if cfg.AutoLeave { - return fmt.Errorf("AutoLeave must be false when not joint") - } - } - - return nil -} - -// checkAndCopy copies the tracker's config and progress map (deeply enough for -// the purposes of the Changer) and returns those copies. It returns an error -// if checkInvariants does. -func (c Changer) checkAndCopy() (tracker.Config, tracker.ProgressMap, error) { - cfg := c.Tracker.Config.Clone() - prs := tracker.ProgressMap{} - - for id, pr := range c.Tracker.Progress { - // A shallow copy is enough because we only mutate the Learner field. - ppr := *pr - prs[id] = &ppr - } - return checkAndReturn(cfg, prs) -} - -// checkAndReturn calls checkInvariants on the input and returns either the -// resulting error or the input. -func checkAndReturn(cfg tracker.Config, prs tracker.ProgressMap) (tracker.Config, tracker.ProgressMap, error) { - if err := checkInvariants(cfg, prs); err != nil { - return tracker.Config{}, tracker.ProgressMap{}, err - } - return cfg, prs, nil -} - -// err returns zero values and an error. -func (c Changer) err(err error) (tracker.Config, tracker.ProgressMap, error) { - return tracker.Config{}, nil, err -} - -// nilAwareAdd populates a map entry, creating the map if necessary. -func nilAwareAdd(m *map[uint64]struct{}, id uint64) { - if *m == nil { - *m = map[uint64]struct{}{} - } - (*m)[id] = struct{}{} -} - -// nilAwareDelete deletes from a map, nil'ing the map itself if it is empty after. -func nilAwareDelete(m *map[uint64]struct{}, id uint64) { - if *m == nil { - return - } - delete(*m, id) - if len(*m) == 0 { - *m = nil - } -} - -// symdiff returns the count of the symmetric difference between the sets of -// uint64s, i.e. len( (l - r) \union (r - l)). -func symdiff(l, r map[uint64]struct{}) int { - var n int - pairs := [][2]quorum.MajorityConfig{ - {l, r}, // count elems in l but not in r - {r, l}, // count elems in r but not in l - } - for _, p := range pairs { - for id := range p[0] { - if _, ok := p[1][id]; !ok { - n++ - } - } - } - return n -} - -func joint(cfg tracker.Config) bool { - return len(outgoing(cfg.Voters)) > 0 -} - -func incoming(voters quorum.JointConfig) quorum.MajorityConfig { return voters[0] } -func outgoing(voters quorum.JointConfig) quorum.MajorityConfig { return voters[1] } -func outgoingPtr(voters *quorum.JointConfig) *quorum.MajorityConfig { return &voters[1] } - -// Describe prints the type and NodeID of the configuration changes as a -// space-delimited string. -func Describe(ccs ...pb.ConfChangeSingle) string { - var buf strings.Builder - for _, cc := range ccs { - if buf.Len() > 0 { - buf.WriteByte(' ') - } - fmt.Fprintf(&buf, "%s(%d)", cc.Type, cc.NodeID) - } - return buf.String() -} diff --git a/vendor/go.etcd.io/etcd/raft/v3/confchange/restore.go b/vendor/go.etcd.io/etcd/raft/v3/confchange/restore.go deleted file mode 100644 index ea317fc289..0000000000 --- a/vendor/go.etcd.io/etcd/raft/v3/confchange/restore.go +++ /dev/null @@ -1,155 +0,0 @@ -// Copyright 2019 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package confchange - -import ( - pb "go.etcd.io/etcd/raft/v3/raftpb" - "go.etcd.io/etcd/raft/v3/tracker" -) - -// toConfChangeSingle translates a conf state into 1) a slice of operations creating -// first the config that will become the outgoing one, and then the incoming one, and -// b) another slice that, when applied to the config resulted from 1), represents the -// ConfState. -func toConfChangeSingle(cs pb.ConfState) (out []pb.ConfChangeSingle, in []pb.ConfChangeSingle) { - // Example to follow along this code: - // voters=(1 2 3) learners=(5) outgoing=(1 2 4 6) learners_next=(4) - // - // This means that before entering the joint config, the configuration - // had voters (1 2 4 6) and perhaps some learners that are already gone. - // The new set of voters is (1 2 3), i.e. (1 2) were kept around, and (4 6) - // are no longer voters; however 4 is poised to become a learner upon leaving - // the joint state. - // We can't tell whether 5 was a learner before entering the joint config, - // but it doesn't matter (we'll pretend that it wasn't). - // - // The code below will construct - // outgoing = add 1; add 2; add 4; add 6 - // incoming = remove 1; remove 2; remove 4; remove 6 - // add 1; add 2; add 3; - // add-learner 5; - // add-learner 4; - // - // So, when starting with an empty config, after applying 'outgoing' we have - // - // quorum=(1 2 4 6) - // - // From which we enter a joint state via 'incoming' - // - // quorum=(1 2 3)&&(1 2 4 6) learners=(5) learners_next=(4) - // - // as desired. - - for _, id := range cs.VotersOutgoing { - // If there are outgoing voters, first add them one by one so that the - // (non-joint) config has them all. - out = append(out, pb.ConfChangeSingle{ - Type: pb.ConfChangeAddNode, - NodeID: id, - }) - - } - - // We're done constructing the outgoing slice, now on to the incoming one - // (which will apply on top of the config created by the outgoing slice). - - // First, we'll remove all of the outgoing voters. - for _, id := range cs.VotersOutgoing { - in = append(in, pb.ConfChangeSingle{ - Type: pb.ConfChangeRemoveNode, - NodeID: id, - }) - } - // Then we'll add the incoming voters and learners. - for _, id := range cs.Voters { - in = append(in, pb.ConfChangeSingle{ - Type: pb.ConfChangeAddNode, - NodeID: id, - }) - } - for _, id := range cs.Learners { - in = append(in, pb.ConfChangeSingle{ - Type: pb.ConfChangeAddLearnerNode, - NodeID: id, - }) - } - // Same for LearnersNext; these are nodes we want to be learners but which - // are currently voters in the outgoing config. - for _, id := range cs.LearnersNext { - in = append(in, pb.ConfChangeSingle{ - Type: pb.ConfChangeAddLearnerNode, - NodeID: id, - }) - } - return out, in -} - -func chain(chg Changer, ops ...func(Changer) (tracker.Config, tracker.ProgressMap, error)) (tracker.Config, tracker.ProgressMap, error) { - for _, op := range ops { - cfg, prs, err := op(chg) - if err != nil { - return tracker.Config{}, nil, err - } - chg.Tracker.Config = cfg - chg.Tracker.Progress = prs - } - return chg.Tracker.Config, chg.Tracker.Progress, nil -} - -// Restore takes a Changer (which must represent an empty configuration), and -// runs a sequence of changes enacting the configuration described in the -// ConfState. -// -// TODO(tbg) it's silly that this takes a Changer. Unravel this by making sure -// the Changer only needs a ProgressMap (not a whole Tracker) at which point -// this can just take LastIndex and MaxInflight directly instead and cook up -// the results from that alone. -func Restore(chg Changer, cs pb.ConfState) (tracker.Config, tracker.ProgressMap, error) { - outgoing, incoming := toConfChangeSingle(cs) - - var ops []func(Changer) (tracker.Config, tracker.ProgressMap, error) - - if len(outgoing) == 0 { - // No outgoing config, so just apply the incoming changes one by one. - for _, cc := range incoming { - cc := cc // loop-local copy - ops = append(ops, func(chg Changer) (tracker.Config, tracker.ProgressMap, error) { - return chg.Simple(cc) - }) - } - } else { - // The ConfState describes a joint configuration. - // - // First, apply all of the changes of the outgoing config one by one, so - // that it temporarily becomes the incoming active config. For example, - // if the config is (1 2 3)&(2 3 4), this will establish (2 3 4)&(). - for _, cc := range outgoing { - cc := cc // loop-local copy - ops = append(ops, func(chg Changer) (tracker.Config, tracker.ProgressMap, error) { - return chg.Simple(cc) - }) - } - // Now enter the joint state, which rotates the above additions into the - // outgoing config, and adds the incoming config in. Continuing the - // example above, we'd get (1 2 3)&(2 3 4), i.e. the incoming operations - // would be removing 2,3,4 and then adding in 1,2,3 while transitioning - // into a joint state. - ops = append(ops, func(chg Changer) (tracker.Config, tracker.ProgressMap, error) { - return chg.EnterJoint(cs.AutoLeave, incoming...) - }) - } - - return chain(chg, ops...) -} diff --git a/vendor/go.etcd.io/etcd/raft/v3/design.md b/vendor/go.etcd.io/etcd/raft/v3/design.md deleted file mode 100644 index 7bc0531dce..0000000000 --- a/vendor/go.etcd.io/etcd/raft/v3/design.md +++ /dev/null @@ -1,57 +0,0 @@ -## Progress - -Progress represents a follower’s progress in the view of the leader. Leader maintains progresses of all followers, and sends `replication message` to the follower based on its progress. - -`replication message` is a `msgApp` with log entries. - -A progress has two attribute: `match` and `next`. `match` is the index of the highest known matched entry. If leader knows nothing about follower’s replication status, `match` is set to zero. `next` is the index of the first entry that will be replicated to the follower. Leader puts entries from `next` to its latest one in next `replication message`. - -A progress is in one of the three state: `probe`, `replicate`, `snapshot`. - -``` - +--------------------------------------------------------+ - | send snapshot | - | | - +---------+----------+ +----------v---------+ - +---> probe | | snapshot | - | | max inflight = 1 <----------------------------------+ max inflight = 0 | - | +---------+----------+ +--------------------+ - | | 1. snapshot success - | | (next=snapshot.index + 1) - | | 2. snapshot failure - | | (no change) - | | 3. receives msgAppResp(rej=false&&index>lastsnap.index) - | | (match=m.index,next=match+1) -receives msgAppResp(rej=true) -(next=match+1)| | - | | - | | - | | receives msgAppResp(rej=false&&index>match) - | | (match=m.index,next=match+1) - | | - | | - | | - | +---------v----------+ - | | replicate | - +---+ max inflight = n | - +--------------------+ -``` - -When the progress of a follower is in `probe` state, leader sends at most one `replication message` per heartbeat interval. The leader sends `replication message` slowly and probing the actual progress of the follower. A `msgHeartbeatResp` or a `msgAppResp` with reject might trigger the sending of the next `replication message`. - -When the progress of a follower is in `replicate` state, leader sends `replication message`, then optimistically increases `next` to the latest entry sent. This is an optimized state for fast replicating log entries to the follower. - -When the progress of a follower is in `snapshot` state, leader stops sending any `replication message`. - -A newly elected leader sets the progresses of all the followers to `probe` state with `match` = 0 and `next` = last index. The leader slowly (at most once per heartbeat) sends `replication message` to the follower and probes its progress. - -A progress changes to `replicate` when the follower replies with a non-rejection `msgAppResp`, which implies that it has matched the index sent. At this point, leader starts to stream log entries to the follower fast. The progress will fall back to `probe` when the follower replies a rejection `msgAppResp` or the link layer reports the follower is unreachable. We aggressively reset `next` to `match`+1 since if we receive any `msgAppResp` soon, both `match` and `next` will increase directly to the `index` in `msgAppResp`. (We might end up with sending some duplicate entries when aggressively reset `next` too low. see open question) - -A progress changes from `probe` to `snapshot` when the follower falls very far behind and requires a snapshot. After sending `msgSnap`, the leader waits until the success, failure or abortion of the previous snapshot sent. The progress will go back to `probe` after the sending result is applied. - -### Flow Control - -1. limit the max size of message sent per message. Max should be configurable. -Lower the cost at probing state as we limit the size per message; lower the penalty when aggressively decreased to a too low `next` - -2. limit the # of in flight messages < N when in `replicate` state. N should be configurable. Most implementation will have a sending buffer on top of its actual network transport layer (not blocking raft node). We want to make sure raft does not overflow that buffer, which can cause message dropping and triggering a bunch of unnecessary resending repeatedly. diff --git a/vendor/go.etcd.io/etcd/raft/v3/doc.go b/vendor/go.etcd.io/etcd/raft/v3/doc.go deleted file mode 100644 index d491352d44..0000000000 --- a/vendor/go.etcd.io/etcd/raft/v3/doc.go +++ /dev/null @@ -1,300 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/* -Package raft sends and receives messages in the Protocol Buffer format -defined in the raftpb package. - -Raft is a protocol with which a cluster of nodes can maintain a replicated state machine. -The state machine is kept in sync through the use of a replicated log. -For more details on Raft, see "In Search of an Understandable Consensus Algorithm" -(https://raft.github.io/raft.pdf) by Diego Ongaro and John Ousterhout. - -A simple example application, _raftexample_, is also available to help illustrate -how to use this package in practice: -https://github.com/etcd-io/etcd/tree/main/contrib/raftexample - -Usage - -The primary object in raft is a Node. You either start a Node from scratch -using raft.StartNode or start a Node from some initial state using raft.RestartNode. - -To start a node from scratch: - - storage := raft.NewMemoryStorage() - c := &Config{ - ID: 0x01, - ElectionTick: 10, - HeartbeatTick: 1, - Storage: storage, - MaxSizePerMsg: 4096, - MaxInflightMsgs: 256, - } - n := raft.StartNode(c, []raft.Peer{{ID: 0x02}, {ID: 0x03}}) - -To restart a node from previous state: - - storage := raft.NewMemoryStorage() - - // recover the in-memory storage from persistent - // snapshot, state and entries. - storage.ApplySnapshot(snapshot) - storage.SetHardState(state) - storage.Append(entries) - - c := &Config{ - ID: 0x01, - ElectionTick: 10, - HeartbeatTick: 1, - Storage: storage, - MaxSizePerMsg: 4096, - MaxInflightMsgs: 256, - } - - // restart raft without peer information. - // peer information is already included in the storage. - n := raft.RestartNode(c) - -Now that you are holding onto a Node you have a few responsibilities: - -First, you must read from the Node.Ready() channel and process the updates -it contains. These steps may be performed in parallel, except as noted in step -2. - -1. Write HardState, Entries, and Snapshot to persistent storage if they are -not empty. Note that when writing an Entry with Index i, any -previously-persisted entries with Index >= i must be discarded. - -2. Send all Messages to the nodes named in the To field. It is important that -no messages be sent until the latest HardState has been persisted to disk, -and all Entries written by any previous Ready batch (Messages may be sent while -entries from the same batch are being persisted). To reduce the I/O latency, an -optimization can be applied to make leader write to disk in parallel with its -followers (as explained at section 10.2.1 in Raft thesis). If any Message has type -MsgSnap, call Node.ReportSnapshot() after it has been sent (these messages may be -large). - -Note: Marshalling messages is not thread-safe; it is important that you -make sure that no new entries are persisted while marshalling. -The easiest way to achieve this is to serialize the messages directly inside -your main raft loop. - -3. Apply Snapshot (if any) and CommittedEntries to the state machine. -If any committed Entry has Type EntryConfChange, call Node.ApplyConfChange() -to apply it to the node. The configuration change may be cancelled at this point -by setting the NodeID field to zero before calling ApplyConfChange -(but ApplyConfChange must be called one way or the other, and the decision to cancel -must be based solely on the state machine and not external information such as -the observed health of the node). - -4. Call Node.Advance() to signal readiness for the next batch of updates. -This may be done at any time after step 1, although all updates must be processed -in the order they were returned by Ready. - -Second, all persisted log entries must be made available via an -implementation of the Storage interface. The provided MemoryStorage -type can be used for this (if you repopulate its state upon a -restart), or you can supply your own disk-backed implementation. - -Third, when you receive a message from another node, pass it to Node.Step: - - func recvRaftRPC(ctx context.Context, m raftpb.Message) { - n.Step(ctx, m) - } - -Finally, you need to call Node.Tick() at regular intervals (probably -via a time.Ticker). Raft has two important timeouts: heartbeat and the -election timeout. However, internally to the raft package time is -represented by an abstract "tick". - -The total state machine handling loop will look something like this: - - for { - select { - case <-s.Ticker: - n.Tick() - case rd := <-s.Node.Ready(): - saveToStorage(rd.State, rd.Entries, rd.Snapshot) - send(rd.Messages) - if !raft.IsEmptySnap(rd.Snapshot) { - processSnapshot(rd.Snapshot) - } - for _, entry := range rd.CommittedEntries { - process(entry) - if entry.Type == raftpb.EntryConfChange { - var cc raftpb.ConfChange - cc.Unmarshal(entry.Data) - s.Node.ApplyConfChange(cc) - } - } - s.Node.Advance() - case <-s.done: - return - } - } - -To propose changes to the state machine from your node take your application -data, serialize it into a byte slice and call: - - n.Propose(ctx, data) - -If the proposal is committed, data will appear in committed entries with type -raftpb.EntryNormal. There is no guarantee that a proposed command will be -committed; you may have to re-propose after a timeout. - -To add or remove a node in a cluster, build ConfChange struct 'cc' and call: - - n.ProposeConfChange(ctx, cc) - -After config change is committed, some committed entry with type -raftpb.EntryConfChange will be returned. You must apply it to node through: - - var cc raftpb.ConfChange - cc.Unmarshal(data) - n.ApplyConfChange(cc) - -Note: An ID represents a unique node in a cluster for all time. A -given ID MUST be used only once even if the old node has been removed. -This means that for example IP addresses make poor node IDs since they -may be reused. Node IDs must be non-zero. - -Implementation notes - -This implementation is up to date with the final Raft thesis -(https://github.com/ongardie/dissertation/blob/master/stanford.pdf), although our -implementation of the membership change protocol differs somewhat from -that described in chapter 4. The key invariant that membership changes -happen one node at a time is preserved, but in our implementation the -membership change takes effect when its entry is applied, not when it -is added to the log (so the entry is committed under the old -membership instead of the new). This is equivalent in terms of safety, -since the old and new configurations are guaranteed to overlap. - -To ensure that we do not attempt to commit two membership changes at -once by matching log positions (which would be unsafe since they -should have different quorum requirements), we simply disallow any -proposed membership change while any uncommitted change appears in -the leader's log. - -This approach introduces a problem when you try to remove a member -from a two-member cluster: If one of the members dies before the -other one receives the commit of the confchange entry, then the member -cannot be removed any more since the cluster cannot make progress. -For this reason it is highly recommended to use three or more nodes in -every cluster. - -MessageType - -Package raft sends and receives message in Protocol Buffer format (defined -in raftpb package). Each state (follower, candidate, leader) implements its -own 'step' method ('stepFollower', 'stepCandidate', 'stepLeader') when -advancing with the given raftpb.Message. Each step is determined by its -raftpb.MessageType. Note that every step is checked by one common method -'Step' that safety-checks the terms of node and incoming message to prevent -stale log entries: - - 'MsgHup' is used for election. If a node is a follower or candidate, the - 'tick' function in 'raft' struct is set as 'tickElection'. If a follower or - candidate has not received any heartbeat before the election timeout, it - passes 'MsgHup' to its Step method and becomes (or remains) a candidate to - start a new election. - - 'MsgBeat' is an internal type that signals the leader to send a heartbeat of - the 'MsgHeartbeat' type. If a node is a leader, the 'tick' function in - the 'raft' struct is set as 'tickHeartbeat', and triggers the leader to - send periodic 'MsgHeartbeat' messages to its followers. - - 'MsgProp' proposes to append data to its log entries. This is a special - type to redirect proposals to leader. Therefore, send method overwrites - raftpb.Message's term with its HardState's term to avoid attaching its - local term to 'MsgProp'. When 'MsgProp' is passed to the leader's 'Step' - method, the leader first calls the 'appendEntry' method to append entries - to its log, and then calls 'bcastAppend' method to send those entries to - its peers. When passed to candidate, 'MsgProp' is dropped. When passed to - follower, 'MsgProp' is stored in follower's mailbox(msgs) by the send - method. It is stored with sender's ID and later forwarded to leader by - rafthttp package. - - 'MsgApp' contains log entries to replicate. A leader calls bcastAppend, - which calls sendAppend, which sends soon-to-be-replicated logs in 'MsgApp' - type. When 'MsgApp' is passed to candidate's Step method, candidate reverts - back to follower, because it indicates that there is a valid leader sending - 'MsgApp' messages. Candidate and follower respond to this message in - 'MsgAppResp' type. - - 'MsgAppResp' is response to log replication request('MsgApp'). When - 'MsgApp' is passed to candidate or follower's Step method, it responds by - calling 'handleAppendEntries' method, which sends 'MsgAppResp' to raft - mailbox. - - 'MsgVote' requests votes for election. When a node is a follower or - candidate and 'MsgHup' is passed to its Step method, then the node calls - 'campaign' method to campaign itself to become a leader. Once 'campaign' - method is called, the node becomes candidate and sends 'MsgVote' to peers - in cluster to request votes. When passed to leader or candidate's Step - method and the message's Term is lower than leader's or candidate's, - 'MsgVote' will be rejected ('MsgVoteResp' is returned with Reject true). - If leader or candidate receives 'MsgVote' with higher term, it will revert - back to follower. When 'MsgVote' is passed to follower, it votes for the - sender only when sender's last term is greater than MsgVote's term or - sender's last term is equal to MsgVote's term but sender's last committed - index is greater than or equal to follower's. - - 'MsgVoteResp' contains responses from voting request. When 'MsgVoteResp' is - passed to candidate, the candidate calculates how many votes it has won. If - it's more than majority (quorum), it becomes leader and calls 'bcastAppend'. - If candidate receives majority of votes of denials, it reverts back to - follower. - - 'MsgPreVote' and 'MsgPreVoteResp' are used in an optional two-phase election - protocol. When Config.PreVote is true, a pre-election is carried out first - (using the same rules as a regular election), and no node increases its term - number unless the pre-election indicates that the campaigning node would win. - This minimizes disruption when a partitioned node rejoins the cluster. - - 'MsgSnap' requests to install a snapshot message. When a node has just - become a leader or the leader receives 'MsgProp' message, it calls - 'bcastAppend' method, which then calls 'sendAppend' method to each - follower. In 'sendAppend', if a leader fails to get term or entries, - the leader requests snapshot by sending 'MsgSnap' type message. - - 'MsgSnapStatus' tells the result of snapshot install message. When a - follower rejected 'MsgSnap', it indicates the snapshot request with - 'MsgSnap' had failed from network issues which causes the network layer - to fail to send out snapshots to its followers. Then leader considers - follower's progress as probe. When 'MsgSnap' were not rejected, it - indicates that the snapshot succeeded and the leader sets follower's - progress to probe and resumes its log replication. - - 'MsgHeartbeat' sends heartbeat from leader. When 'MsgHeartbeat' is passed - to candidate and message's term is higher than candidate's, the candidate - reverts back to follower and updates its committed index from the one in - this heartbeat. And it sends the message to its mailbox. When - 'MsgHeartbeat' is passed to follower's Step method and message's term is - higher than follower's, the follower updates its leaderID with the ID - from the message. - - 'MsgHeartbeatResp' is a response to 'MsgHeartbeat'. When 'MsgHeartbeatResp' - is passed to leader's Step method, the leader knows which follower - responded. And only when the leader's last committed index is greater than - follower's Match index, the leader runs 'sendAppend` method. - - 'MsgUnreachable' tells that request(message) wasn't delivered. When - 'MsgUnreachable' is passed to leader's Step method, the leader discovers - that the follower that sent this 'MsgUnreachable' is not reachable, often - indicating 'MsgApp' is lost. When follower's progress state is replicate, - the leader sets it back to probe. - -*/ -package raft diff --git a/vendor/go.etcd.io/etcd/raft/v3/go.mod b/vendor/go.etcd.io/etcd/raft/v3/go.mod deleted file mode 100644 index c7fd9b4a00..0000000000 --- a/vendor/go.etcd.io/etcd/raft/v3/go.mod +++ /dev/null @@ -1,20 +0,0 @@ -module go.etcd.io/etcd/raft/v3 - -go 1.16 - -require ( - github.com/certifi/gocertifi v0.0.0-20200922220541-2c3bb06c6054 // indirect - github.com/cockroachdb/datadriven v0.0.0-20200714090401-bf6692d28da5 - github.com/gogo/protobuf v1.3.2 - github.com/golang/protobuf v1.5.2 - github.com/pkg/errors v0.9.1 // indirect - go.etcd.io/etcd/client/pkg/v3 v3.5.0 -) - -// Bad imports are sometimes causing attempts to pull that code. -// This makes the error more explicit. -replace go.etcd.io/etcd => ./FORBIDDEN_DEPENDENCY - -replace go.etcd.io/etcd/v3 => ./FORBIDDEN_DEPENDENCY - -replace go.etcd.io/etcd/client/pkg/v3 => ../client/pkg diff --git a/vendor/go.etcd.io/etcd/raft/v3/go.sum b/vendor/go.etcd.io/etcd/raft/v3/go.sum deleted file mode 100644 index 7e28e8a713..0000000000 --- a/vendor/go.etcd.io/etcd/raft/v3/go.sum +++ /dev/null @@ -1,79 +0,0 @@ -github.com/certifi/gocertifi v0.0.0-20191021191039-0944d244cd40/go.mod h1:sGbDF6GwGcLpkNXPUTkMRoywsNa/ol15pxFe6ERfguA= -github.com/certifi/gocertifi v0.0.0-20200922220541-2c3bb06c6054 h1:uH66TXeswKn5PW5zdZ39xEwfS9an067BirqA+P4QaLI= -github.com/certifi/gocertifi v0.0.0-20200922220541-2c3bb06c6054/go.mod h1:sGbDF6GwGcLpkNXPUTkMRoywsNa/ol15pxFe6ERfguA= -github.com/cockroachdb/datadriven v0.0.0-20200714090401-bf6692d28da5 h1:xD/lrqdvwsc+O2bjSSi3YqY73Ke3LAiSCx49aCesA0E= -github.com/cockroachdb/datadriven v0.0.0-20200714090401-bf6692d28da5/go.mod h1:h6jFvWxBdQXxjopDMZyH2UVceIRfR84bdzbkoKrsWNo= -github.com/cockroachdb/errors v1.2.4 h1:Lap807SXTH5tri2TivECb/4abUkMZC9zRoLarvcKDqs= -github.com/cockroachdb/errors v1.2.4/go.mod h1:rQD95gz6FARkaKkQXUksEje/d9a6wBJoCr5oaCLELYA= -github.com/cockroachdb/logtags v0.0.0-20190617123548-eb05cc24525f h1:o/kfcElHqOiXqcou5a3rIlMc7oJbMQkeLk0VQJ7zgqY= -github.com/cockroachdb/logtags v0.0.0-20190617123548-eb05cc24525f/go.mod h1:i/u985jwjWRlyHXQbwatDASoW0RMlZ/3i9yJHE2xLkI= -github.com/coreos/go-systemd/v22 v22.3.2/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/getsentry/raven-go v0.2.0 h1:no+xWJRb5ZI7eE8TWgIq1jLulQiIoLG0IfYxv5JYMGs= -github.com/getsentry/raven-go v0.2.0/go.mod h1:KungGk8q33+aIAZUIVWZDr2OfAEBsO49PX4NzFV5kcQ= -github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= -github.com/gogo/protobuf v1.3.1/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o= -github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= -github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= -github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= -github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw= -github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= -github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= -github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00= -github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= -github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= -github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= -github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= -github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= -github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= -github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= -github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= -github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= -github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= -github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= -github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= -go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= -go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU= -go.uber.org/zap v1.17.0/go.mod h1:MXVU+bhUf/A7Xi2HNOnopQOrmycQ5Ih87HtOu4q5SSo= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= -golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210403161142-5e06dd20ab57/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20181030221726-6c7e314b6563/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= -golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= -golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= -golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= -google.golang.org/protobuf v1.26.0 h1:bxAC2xTBsZGibn2RTntX0oH50xLsqy1OxA9tTL3p/lk= -google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/vendor/go.etcd.io/etcd/raft/v3/log.go b/vendor/go.etcd.io/etcd/raft/v3/log.go deleted file mode 100644 index c94c41f778..0000000000 --- a/vendor/go.etcd.io/etcd/raft/v3/log.go +++ /dev/null @@ -1,406 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package raft - -import ( - "fmt" - "log" - - pb "go.etcd.io/etcd/raft/v3/raftpb" -) - -type raftLog struct { - // storage contains all stable entries since the last snapshot. - storage Storage - - // unstable contains all unstable entries and snapshot. - // they will be saved into storage. - unstable unstable - - // committed is the highest log position that is known to be in - // stable storage on a quorum of nodes. - committed uint64 - // applied is the highest log position that the application has - // been instructed to apply to its state machine. - // Invariant: applied <= committed - applied uint64 - - logger Logger - - // maxNextEntsSize is the maximum number aggregate byte size of the messages - // returned from calls to nextEnts. - maxNextEntsSize uint64 -} - -// newLog returns log using the given storage and default options. It -// recovers the log to the state that it just commits and applies the -// latest snapshot. -func newLog(storage Storage, logger Logger) *raftLog { - return newLogWithSize(storage, logger, noLimit) -} - -// newLogWithSize returns a log using the given storage and max -// message size. -func newLogWithSize(storage Storage, logger Logger, maxNextEntsSize uint64) *raftLog { - if storage == nil { - log.Panic("storage must not be nil") - } - log := &raftLog{ - storage: storage, - logger: logger, - maxNextEntsSize: maxNextEntsSize, - } - firstIndex, err := storage.FirstIndex() - if err != nil { - panic(err) // TODO(bdarnell) - } - lastIndex, err := storage.LastIndex() - if err != nil { - panic(err) // TODO(bdarnell) - } - log.unstable.offset = lastIndex + 1 - log.unstable.logger = logger - // Initialize our committed and applied pointers to the time of the last compaction. - log.committed = firstIndex - 1 - log.applied = firstIndex - 1 - - return log -} - -func (l *raftLog) String() string { - return fmt.Sprintf("committed=%d, applied=%d, unstable.offset=%d, len(unstable.Entries)=%d", l.committed, l.applied, l.unstable.offset, len(l.unstable.entries)) -} - -// maybeAppend returns (0, false) if the entries cannot be appended. Otherwise, -// it returns (last index of new entries, true). -func (l *raftLog) maybeAppend(index, logTerm, committed uint64, ents ...pb.Entry) (lastnewi uint64, ok bool) { - if l.matchTerm(index, logTerm) { - lastnewi = index + uint64(len(ents)) - ci := l.findConflict(ents) - switch { - case ci == 0: - case ci <= l.committed: - l.logger.Panicf("entry %d conflict with committed entry [committed(%d)]", ci, l.committed) - default: - offset := index + 1 - l.append(ents[ci-offset:]...) - } - l.commitTo(min(committed, lastnewi)) - return lastnewi, true - } - return 0, false -} - -func (l *raftLog) append(ents ...pb.Entry) uint64 { - if len(ents) == 0 { - return l.lastIndex() - } - if after := ents[0].Index - 1; after < l.committed { - l.logger.Panicf("after(%d) is out of range [committed(%d)]", after, l.committed) - } - l.unstable.truncateAndAppend(ents) - return l.lastIndex() -} - -// findConflict finds the index of the conflict. -// It returns the first pair of conflicting entries between the existing -// entries and the given entries, if there are any. -// If there is no conflicting entries, and the existing entries contains -// all the given entries, zero will be returned. -// If there is no conflicting entries, but the given entries contains new -// entries, the index of the first new entry will be returned. -// An entry is considered to be conflicting if it has the same index but -// a different term. -// The index of the given entries MUST be continuously increasing. -func (l *raftLog) findConflict(ents []pb.Entry) uint64 { - for _, ne := range ents { - if !l.matchTerm(ne.Index, ne.Term) { - if ne.Index <= l.lastIndex() { - l.logger.Infof("found conflict at index %d [existing term: %d, conflicting term: %d]", - ne.Index, l.zeroTermOnErrCompacted(l.term(ne.Index)), ne.Term) - } - return ne.Index - } - } - return 0 -} - -// findConflictByTerm takes an (index, term) pair (indicating a conflicting log -// entry on a leader/follower during an append) and finds the largest index in -// log l with a term <= `term` and an index <= `index`. If no such index exists -// in the log, the log's first index is returned. -// -// The index provided MUST be equal to or less than l.lastIndex(). Invalid -// inputs log a warning and the input index is returned. -func (l *raftLog) findConflictByTerm(index uint64, term uint64) uint64 { - if li := l.lastIndex(); index > li { - // NB: such calls should not exist, but since there is a straightfoward - // way to recover, do it. - // - // It is tempting to also check something about the first index, but - // there is odd behavior with peers that have no log, in which case - // lastIndex will return zero and firstIndex will return one, which - // leads to calls with an index of zero into this method. - l.logger.Warningf("index(%d) is out of range [0, lastIndex(%d)] in findConflictByTerm", - index, li) - return index - } - for { - logTerm, err := l.term(index) - if logTerm <= term || err != nil { - break - } - index-- - } - return index -} - -func (l *raftLog) unstableEntries() []pb.Entry { - if len(l.unstable.entries) == 0 { - return nil - } - return l.unstable.entries -} - -// nextEnts returns all the available entries for execution. -// If applied is smaller than the index of snapshot, it returns all committed -// entries after the index of snapshot. -func (l *raftLog) nextEnts() (ents []pb.Entry) { - off := max(l.applied+1, l.firstIndex()) - if l.committed+1 > off { - ents, err := l.slice(off, l.committed+1, l.maxNextEntsSize) - if err != nil { - l.logger.Panicf("unexpected error when getting unapplied entries (%v)", err) - } - return ents - } - return nil -} - -// hasNextEnts returns if there is any available entries for execution. This -// is a fast check without heavy raftLog.slice() in raftLog.nextEnts(). -func (l *raftLog) hasNextEnts() bool { - off := max(l.applied+1, l.firstIndex()) - return l.committed+1 > off -} - -// hasPendingSnapshot returns if there is pending snapshot waiting for applying. -func (l *raftLog) hasPendingSnapshot() bool { - return l.unstable.snapshot != nil && !IsEmptySnap(*l.unstable.snapshot) -} - -func (l *raftLog) snapshot() (pb.Snapshot, error) { - if l.unstable.snapshot != nil { - return *l.unstable.snapshot, nil - } - return l.storage.Snapshot() -} - -func (l *raftLog) firstIndex() uint64 { - if i, ok := l.unstable.maybeFirstIndex(); ok { - return i - } - index, err := l.storage.FirstIndex() - if err != nil { - panic(err) // TODO(bdarnell) - } - return index -} - -func (l *raftLog) lastIndex() uint64 { - if i, ok := l.unstable.maybeLastIndex(); ok { - return i - } - i, err := l.storage.LastIndex() - if err != nil { - panic(err) // TODO(bdarnell) - } - return i -} - -func (l *raftLog) commitTo(tocommit uint64) { - // never decrease commit - if l.committed < tocommit { - if l.lastIndex() < tocommit { - l.logger.Panicf("tocommit(%d) is out of range [lastIndex(%d)]. Was the raft log corrupted, truncated, or lost?", tocommit, l.lastIndex()) - } - l.committed = tocommit - } -} - -func (l *raftLog) appliedTo(i uint64) { - if i == 0 { - return - } - if l.committed < i || i < l.applied { - l.logger.Panicf("applied(%d) is out of range [prevApplied(%d), committed(%d)]", i, l.applied, l.committed) - } - l.applied = i -} - -func (l *raftLog) stableTo(i, t uint64) { l.unstable.stableTo(i, t) } - -func (l *raftLog) stableSnapTo(i uint64) { l.unstable.stableSnapTo(i) } - -func (l *raftLog) lastTerm() uint64 { - t, err := l.term(l.lastIndex()) - if err != nil { - l.logger.Panicf("unexpected error when getting the last term (%v)", err) - } - return t -} - -func (l *raftLog) term(i uint64) (uint64, error) { - // the valid term range is [index of dummy entry, last index] - dummyIndex := l.firstIndex() - 1 - if i < dummyIndex || i > l.lastIndex() { - // TODO: return an error instead? - return 0, nil - } - - if t, ok := l.unstable.maybeTerm(i); ok { - return t, nil - } - - t, err := l.storage.Term(i) - if err == nil { - return t, nil - } - if err == ErrCompacted || err == ErrUnavailable { - return 0, err - } - panic(err) // TODO(bdarnell) -} - -func (l *raftLog) entries(i, maxsize uint64) ([]pb.Entry, error) { - if i > l.lastIndex() { - return nil, nil - } - return l.slice(i, l.lastIndex()+1, maxsize) -} - -// allEntries returns all entries in the log. -func (l *raftLog) allEntries() []pb.Entry { - ents, err := l.entries(l.firstIndex(), noLimit) - if err == nil { - return ents - } - if err == ErrCompacted { // try again if there was a racing compaction - return l.allEntries() - } - // TODO (xiangli): handle error? - panic(err) -} - -// isUpToDate determines if the given (lastIndex,term) log is more up-to-date -// by comparing the index and term of the last entries in the existing logs. -// If the logs have last entries with different terms, then the log with the -// later term is more up-to-date. If the logs end with the same term, then -// whichever log has the larger lastIndex is more up-to-date. If the logs are -// the same, the given log is up-to-date. -func (l *raftLog) isUpToDate(lasti, term uint64) bool { - return term > l.lastTerm() || (term == l.lastTerm() && lasti >= l.lastIndex()) -} - -func (l *raftLog) matchTerm(i, term uint64) bool { - t, err := l.term(i) - if err != nil { - return false - } - return t == term -} - -func (l *raftLog) maybeCommit(maxIndex, term uint64) bool { - if maxIndex > l.committed && l.zeroTermOnErrCompacted(l.term(maxIndex)) == term { - l.commitTo(maxIndex) - return true - } - return false -} - -func (l *raftLog) restore(s pb.Snapshot) { - l.logger.Infof("log [%s] starts to restore snapshot [index: %d, term: %d]", l, s.Metadata.Index, s.Metadata.Term) - l.committed = s.Metadata.Index - l.unstable.restore(s) -} - -// slice returns a slice of log entries from lo through hi-1, inclusive. -func (l *raftLog) slice(lo, hi, maxSize uint64) ([]pb.Entry, error) { - err := l.mustCheckOutOfBounds(lo, hi) - if err != nil { - return nil, err - } - if lo == hi { - return nil, nil - } - var ents []pb.Entry - if lo < l.unstable.offset { - storedEnts, err := l.storage.Entries(lo, min(hi, l.unstable.offset), maxSize) - if err == ErrCompacted { - return nil, err - } else if err == ErrUnavailable { - l.logger.Panicf("entries[%d:%d) is unavailable from storage", lo, min(hi, l.unstable.offset)) - } else if err != nil { - panic(err) // TODO(bdarnell) - } - - // check if ents has reached the size limitation - if uint64(len(storedEnts)) < min(hi, l.unstable.offset)-lo { - return storedEnts, nil - } - - ents = storedEnts - } - if hi > l.unstable.offset { - unstable := l.unstable.slice(max(lo, l.unstable.offset), hi) - if len(ents) > 0 { - combined := make([]pb.Entry, len(ents)+len(unstable)) - n := copy(combined, ents) - copy(combined[n:], unstable) - ents = combined - } else { - ents = unstable - } - } - return limitSize(ents, maxSize), nil -} - -// l.firstIndex <= lo <= hi <= l.firstIndex + len(l.entries) -func (l *raftLog) mustCheckOutOfBounds(lo, hi uint64) error { - if lo > hi { - l.logger.Panicf("invalid slice %d > %d", lo, hi) - } - fi := l.firstIndex() - if lo < fi { - return ErrCompacted - } - - length := l.lastIndex() + 1 - fi - if hi > fi+length { - l.logger.Panicf("slice[%d,%d) out of bound [%d,%d]", lo, hi, fi, l.lastIndex()) - } - return nil -} - -func (l *raftLog) zeroTermOnErrCompacted(t uint64, err error) uint64 { - if err == nil { - return t - } - if err == ErrCompacted { - return 0 - } - l.logger.Panicf("unexpected error (%v)", err) - return 0 -} diff --git a/vendor/go.etcd.io/etcd/raft/v3/log_unstable.go b/vendor/go.etcd.io/etcd/raft/v3/log_unstable.go deleted file mode 100644 index 230fd21f99..0000000000 --- a/vendor/go.etcd.io/etcd/raft/v3/log_unstable.go +++ /dev/null @@ -1,157 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package raft - -import pb "go.etcd.io/etcd/raft/v3/raftpb" - -// unstable.entries[i] has raft log position i+unstable.offset. -// Note that unstable.offset may be less than the highest log -// position in storage; this means that the next write to storage -// might need to truncate the log before persisting unstable.entries. -type unstable struct { - // the incoming unstable snapshot, if any. - snapshot *pb.Snapshot - // all entries that have not yet been written to storage. - entries []pb.Entry - offset uint64 - - logger Logger -} - -// maybeFirstIndex returns the index of the first possible entry in entries -// if it has a snapshot. -func (u *unstable) maybeFirstIndex() (uint64, bool) { - if u.snapshot != nil { - return u.snapshot.Metadata.Index + 1, true - } - return 0, false -} - -// maybeLastIndex returns the last index if it has at least one -// unstable entry or snapshot. -func (u *unstable) maybeLastIndex() (uint64, bool) { - if l := len(u.entries); l != 0 { - return u.offset + uint64(l) - 1, true - } - if u.snapshot != nil { - return u.snapshot.Metadata.Index, true - } - return 0, false -} - -// maybeTerm returns the term of the entry at index i, if there -// is any. -func (u *unstable) maybeTerm(i uint64) (uint64, bool) { - if i < u.offset { - if u.snapshot != nil && u.snapshot.Metadata.Index == i { - return u.snapshot.Metadata.Term, true - } - return 0, false - } - - last, ok := u.maybeLastIndex() - if !ok { - return 0, false - } - if i > last { - return 0, false - } - - return u.entries[i-u.offset].Term, true -} - -func (u *unstable) stableTo(i, t uint64) { - gt, ok := u.maybeTerm(i) - if !ok { - return - } - // if i < offset, term is matched with the snapshot - // only update the unstable entries if term is matched with - // an unstable entry. - if gt == t && i >= u.offset { - u.entries = u.entries[i+1-u.offset:] - u.offset = i + 1 - u.shrinkEntriesArray() - } -} - -// shrinkEntriesArray discards the underlying array used by the entries slice -// if most of it isn't being used. This avoids holding references to a bunch of -// potentially large entries that aren't needed anymore. Simply clearing the -// entries wouldn't be safe because clients might still be using them. -func (u *unstable) shrinkEntriesArray() { - // We replace the array if we're using less than half of the space in - // it. This number is fairly arbitrary, chosen as an attempt to balance - // memory usage vs number of allocations. It could probably be improved - // with some focused tuning. - const lenMultiple = 2 - if len(u.entries) == 0 { - u.entries = nil - } else if len(u.entries)*lenMultiple < cap(u.entries) { - newEntries := make([]pb.Entry, len(u.entries)) - copy(newEntries, u.entries) - u.entries = newEntries - } -} - -func (u *unstable) stableSnapTo(i uint64) { - if u.snapshot != nil && u.snapshot.Metadata.Index == i { - u.snapshot = nil - } -} - -func (u *unstable) restore(s pb.Snapshot) { - u.offset = s.Metadata.Index + 1 - u.entries = nil - u.snapshot = &s -} - -func (u *unstable) truncateAndAppend(ents []pb.Entry) { - after := ents[0].Index - switch { - case after == u.offset+uint64(len(u.entries)): - // after is the next index in the u.entries - // directly append - u.entries = append(u.entries, ents...) - case after <= u.offset: - u.logger.Infof("replace the unstable entries from index %d", after) - // The log is being truncated to before our current offset - // portion, so set the offset and replace the entries - u.offset = after - u.entries = ents - default: - // truncate to after and copy to u.entries - // then append - u.logger.Infof("truncate the unstable entries before index %d", after) - u.entries = append([]pb.Entry{}, u.slice(u.offset, after)...) - u.entries = append(u.entries, ents...) - } -} - -func (u *unstable) slice(lo uint64, hi uint64) []pb.Entry { - u.mustCheckOutOfBounds(lo, hi) - return u.entries[lo-u.offset : hi-u.offset] -} - -// u.offset <= lo <= hi <= u.offset+len(u.entries) -func (u *unstable) mustCheckOutOfBounds(lo, hi uint64) { - if lo > hi { - u.logger.Panicf("invalid unstable.slice %d > %d", lo, hi) - } - upper := u.offset + uint64(len(u.entries)) - if lo < u.offset || hi > upper { - u.logger.Panicf("unstable.slice[%d,%d) out of bound [%d,%d]", lo, hi, u.offset, upper) - } -} diff --git a/vendor/go.etcd.io/etcd/raft/v3/logger.go b/vendor/go.etcd.io/etcd/raft/v3/logger.go deleted file mode 100644 index dc73b1f210..0000000000 --- a/vendor/go.etcd.io/etcd/raft/v3/logger.go +++ /dev/null @@ -1,142 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package raft - -import ( - "fmt" - "io/ioutil" - "log" - "os" - "sync" -) - -type Logger interface { - Debug(v ...interface{}) - Debugf(format string, v ...interface{}) - - Error(v ...interface{}) - Errorf(format string, v ...interface{}) - - Info(v ...interface{}) - Infof(format string, v ...interface{}) - - Warning(v ...interface{}) - Warningf(format string, v ...interface{}) - - Fatal(v ...interface{}) - Fatalf(format string, v ...interface{}) - - Panic(v ...interface{}) - Panicf(format string, v ...interface{}) -} - -func SetLogger(l Logger) { - raftLoggerMu.Lock() - raftLogger = l - raftLoggerMu.Unlock() -} - -func ResetDefaultLogger() { - SetLogger(defaultLogger) -} - -func getLogger() Logger { - raftLoggerMu.Lock() - defer raftLoggerMu.Unlock() - return raftLogger -} - -var ( - defaultLogger = &DefaultLogger{Logger: log.New(os.Stderr, "raft", log.LstdFlags)} - discardLogger = &DefaultLogger{Logger: log.New(ioutil.Discard, "", 0)} - raftLoggerMu sync.Mutex - raftLogger = Logger(defaultLogger) -) - -const ( - calldepth = 2 -) - -// DefaultLogger is a default implementation of the Logger interface. -type DefaultLogger struct { - *log.Logger - debug bool -} - -func (l *DefaultLogger) EnableTimestamps() { - l.SetFlags(l.Flags() | log.Ldate | log.Ltime) -} - -func (l *DefaultLogger) EnableDebug() { - l.debug = true -} - -func (l *DefaultLogger) Debug(v ...interface{}) { - if l.debug { - l.Output(calldepth, header("DEBUG", fmt.Sprint(v...))) - } -} - -func (l *DefaultLogger) Debugf(format string, v ...interface{}) { - if l.debug { - l.Output(calldepth, header("DEBUG", fmt.Sprintf(format, v...))) - } -} - -func (l *DefaultLogger) Info(v ...interface{}) { - l.Output(calldepth, header("INFO", fmt.Sprint(v...))) -} - -func (l *DefaultLogger) Infof(format string, v ...interface{}) { - l.Output(calldepth, header("INFO", fmt.Sprintf(format, v...))) -} - -func (l *DefaultLogger) Error(v ...interface{}) { - l.Output(calldepth, header("ERROR", fmt.Sprint(v...))) -} - -func (l *DefaultLogger) Errorf(format string, v ...interface{}) { - l.Output(calldepth, header("ERROR", fmt.Sprintf(format, v...))) -} - -func (l *DefaultLogger) Warning(v ...interface{}) { - l.Output(calldepth, header("WARN", fmt.Sprint(v...))) -} - -func (l *DefaultLogger) Warningf(format string, v ...interface{}) { - l.Output(calldepth, header("WARN", fmt.Sprintf(format, v...))) -} - -func (l *DefaultLogger) Fatal(v ...interface{}) { - l.Output(calldepth, header("FATAL", fmt.Sprint(v...))) - os.Exit(1) -} - -func (l *DefaultLogger) Fatalf(format string, v ...interface{}) { - l.Output(calldepth, header("FATAL", fmt.Sprintf(format, v...))) - os.Exit(1) -} - -func (l *DefaultLogger) Panic(v ...interface{}) { - l.Logger.Panic(v...) -} - -func (l *DefaultLogger) Panicf(format string, v ...interface{}) { - l.Logger.Panicf(format, v...) -} - -func header(lvl, msg string) string { - return fmt.Sprintf("%s: %s", lvl, msg) -} diff --git a/vendor/go.etcd.io/etcd/raft/v3/node.go b/vendor/go.etcd.io/etcd/raft/v3/node.go deleted file mode 100644 index dca5954f7a..0000000000 --- a/vendor/go.etcd.io/etcd/raft/v3/node.go +++ /dev/null @@ -1,590 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package raft - -import ( - "context" - "errors" - - pb "go.etcd.io/etcd/raft/v3/raftpb" -) - -type SnapshotStatus int - -const ( - SnapshotFinish SnapshotStatus = 1 - SnapshotFailure SnapshotStatus = 2 -) - -var ( - emptyState = pb.HardState{} - - // ErrStopped is returned by methods on Nodes that have been stopped. - ErrStopped = errors.New("raft: stopped") -) - -// SoftState provides state that is useful for logging and debugging. -// The state is volatile and does not need to be persisted to the WAL. -type SoftState struct { - Lead uint64 // must use atomic operations to access; keep 64-bit aligned. - RaftState StateType -} - -func (a *SoftState) equal(b *SoftState) bool { - return a.Lead == b.Lead && a.RaftState == b.RaftState -} - -// Ready encapsulates the entries and messages that are ready to read, -// be saved to stable storage, committed or sent to other peers. -// All fields in Ready are read-only. -type Ready struct { - // The current volatile state of a Node. - // SoftState will be nil if there is no update. - // It is not required to consume or store SoftState. - *SoftState - - // The current state of a Node to be saved to stable storage BEFORE - // Messages are sent. - // HardState will be equal to empty state if there is no update. - pb.HardState - - // ReadStates can be used for node to serve linearizable read requests locally - // when its applied index is greater than the index in ReadState. - // Note that the readState will be returned when raft receives msgReadIndex. - // The returned is only valid for the request that requested to read. - ReadStates []ReadState - - // Entries specifies entries to be saved to stable storage BEFORE - // Messages are sent. - Entries []pb.Entry - - // Snapshot specifies the snapshot to be saved to stable storage. - Snapshot pb.Snapshot - - // CommittedEntries specifies entries to be committed to a - // store/state-machine. These have previously been committed to stable - // store. - CommittedEntries []pb.Entry - - // Messages specifies outbound messages to be sent AFTER Entries are - // committed to stable storage. - // If it contains a MsgSnap message, the application MUST report back to raft - // when the snapshot has been received or has failed by calling ReportSnapshot. - Messages []pb.Message - - // MustSync indicates whether the HardState and Entries must be synchronously - // written to disk or if an asynchronous write is permissible. - MustSync bool -} - -func isHardStateEqual(a, b pb.HardState) bool { - return a.Term == b.Term && a.Vote == b.Vote && a.Commit == b.Commit -} - -// IsEmptyHardState returns true if the given HardState is empty. -func IsEmptyHardState(st pb.HardState) bool { - return isHardStateEqual(st, emptyState) -} - -// IsEmptySnap returns true if the given Snapshot is empty. -func IsEmptySnap(sp pb.Snapshot) bool { - return sp.Metadata.Index == 0 -} - -func (rd Ready) containsUpdates() bool { - return rd.SoftState != nil || !IsEmptyHardState(rd.HardState) || - !IsEmptySnap(rd.Snapshot) || len(rd.Entries) > 0 || - len(rd.CommittedEntries) > 0 || len(rd.Messages) > 0 || len(rd.ReadStates) != 0 -} - -// appliedCursor extracts from the Ready the highest index the client has -// applied (once the Ready is confirmed via Advance). If no information is -// contained in the Ready, returns zero. -func (rd Ready) appliedCursor() uint64 { - if n := len(rd.CommittedEntries); n > 0 { - return rd.CommittedEntries[n-1].Index - } - if index := rd.Snapshot.Metadata.Index; index > 0 { - return index - } - return 0 -} - -// Node represents a node in a raft cluster. -type Node interface { - // Tick increments the internal logical clock for the Node by a single tick. Election - // timeouts and heartbeat timeouts are in units of ticks. - Tick() - // Campaign causes the Node to transition to candidate state and start campaigning to become leader. - Campaign(ctx context.Context) error - // Propose proposes that data be appended to the log. Note that proposals can be lost without - // notice, therefore it is user's job to ensure proposal retries. - Propose(ctx context.Context, data []byte) error - // ProposeConfChange proposes a configuration change. Like any proposal, the - // configuration change may be dropped with or without an error being - // returned. In particular, configuration changes are dropped unless the - // leader has certainty that there is no prior unapplied configuration - // change in its log. - // - // The method accepts either a pb.ConfChange (deprecated) or pb.ConfChangeV2 - // message. The latter allows arbitrary configuration changes via joint - // consensus, notably including replacing a voter. Passing a ConfChangeV2 - // message is only allowed if all Nodes participating in the cluster run a - // version of this library aware of the V2 API. See pb.ConfChangeV2 for - // usage details and semantics. - ProposeConfChange(ctx context.Context, cc pb.ConfChangeI) error - - // Step advances the state machine using the given message. ctx.Err() will be returned, if any. - Step(ctx context.Context, msg pb.Message) error - - // Ready returns a channel that returns the current point-in-time state. - // Users of the Node must call Advance after retrieving the state returned by Ready. - // - // NOTE: No committed entries from the next Ready may be applied until all committed entries - // and snapshots from the previous one have finished. - Ready() <-chan Ready - - // Advance notifies the Node that the application has saved progress up to the last Ready. - // It prepares the node to return the next available Ready. - // - // The application should generally call Advance after it applies the entries in last Ready. - // - // However, as an optimization, the application may call Advance while it is applying the - // commands. For example. when the last Ready contains a snapshot, the application might take - // a long time to apply the snapshot data. To continue receiving Ready without blocking raft - // progress, it can call Advance before finishing applying the last ready. - Advance() - // ApplyConfChange applies a config change (previously passed to - // ProposeConfChange) to the node. This must be called whenever a config - // change is observed in Ready.CommittedEntries, except when the app decides - // to reject the configuration change (i.e. treats it as a noop instead), in - // which case it must not be called. - // - // Returns an opaque non-nil ConfState protobuf which must be recorded in - // snapshots. - ApplyConfChange(cc pb.ConfChangeI) *pb.ConfState - - // TransferLeadership attempts to transfer leadership to the given transferee. - TransferLeadership(ctx context.Context, lead, transferee uint64) - - // ReadIndex request a read state. The read state will be set in the ready. - // Read state has a read index. Once the application advances further than the read - // index, any linearizable read requests issued before the read request can be - // processed safely. The read state will have the same rctx attached. - // Note that request can be lost without notice, therefore it is user's job - // to ensure read index retries. - ReadIndex(ctx context.Context, rctx []byte) error - - // Status returns the current status of the raft state machine. - Status() Status - // ReportUnreachable reports the given node is not reachable for the last send. - ReportUnreachable(id uint64) - // ReportSnapshot reports the status of the sent snapshot. The id is the raft ID of the follower - // who is meant to receive the snapshot, and the status is SnapshotFinish or SnapshotFailure. - // Calling ReportSnapshot with SnapshotFinish is a no-op. But, any failure in applying a - // snapshot (for e.g., while streaming it from leader to follower), should be reported to the - // leader with SnapshotFailure. When leader sends a snapshot to a follower, it pauses any raft - // log probes until the follower can apply the snapshot and advance its state. If the follower - // can't do that, for e.g., due to a crash, it could end up in a limbo, never getting any - // updates from the leader. Therefore, it is crucial that the application ensures that any - // failure in snapshot sending is caught and reported back to the leader; so it can resume raft - // log probing in the follower. - ReportSnapshot(id uint64, status SnapshotStatus) - // Stop performs any necessary termination of the Node. - Stop() -} - -type Peer struct { - ID uint64 - Context []byte -} - -// StartNode returns a new Node given configuration and a list of raft peers. -// It appends a ConfChangeAddNode entry for each given peer to the initial log. -// -// Peers must not be zero length; call RestartNode in that case. -func StartNode(c *Config, peers []Peer) Node { - if len(peers) == 0 { - panic("no peers given; use RestartNode instead") - } - rn, err := NewRawNode(c) - if err != nil { - panic(err) - } - rn.Bootstrap(peers) - - n := newNode(rn) - - go n.run() - return &n -} - -// RestartNode is similar to StartNode but does not take a list of peers. -// The current membership of the cluster will be restored from the Storage. -// If the caller has an existing state machine, pass in the last log index that -// has been applied to it; otherwise use zero. -func RestartNode(c *Config) Node { - rn, err := NewRawNode(c) - if err != nil { - panic(err) - } - n := newNode(rn) - go n.run() - return &n -} - -type msgWithResult struct { - m pb.Message - result chan error -} - -// node is the canonical implementation of the Node interface -type node struct { - propc chan msgWithResult - recvc chan pb.Message - confc chan pb.ConfChangeV2 - confstatec chan pb.ConfState - readyc chan Ready - advancec chan struct{} - tickc chan struct{} - done chan struct{} - stop chan struct{} - status chan chan Status - - rn *RawNode -} - -func newNode(rn *RawNode) node { - return node{ - propc: make(chan msgWithResult), - recvc: make(chan pb.Message), - confc: make(chan pb.ConfChangeV2), - confstatec: make(chan pb.ConfState), - readyc: make(chan Ready), - advancec: make(chan struct{}), - // make tickc a buffered chan, so raft node can buffer some ticks when the node - // is busy processing raft messages. Raft node will resume process buffered - // ticks when it becomes idle. - tickc: make(chan struct{}, 128), - done: make(chan struct{}), - stop: make(chan struct{}), - status: make(chan chan Status), - rn: rn, - } -} - -func (n *node) Stop() { - select { - case n.stop <- struct{}{}: - // Not already stopped, so trigger it - case <-n.done: - // Node has already been stopped - no need to do anything - return - } - // Block until the stop has been acknowledged by run() - <-n.done -} - -func (n *node) run() { - var propc chan msgWithResult - var readyc chan Ready - var advancec chan struct{} - var rd Ready - - r := n.rn.raft - - lead := None - - for { - if advancec != nil { - readyc = nil - } else if n.rn.HasReady() { - // Populate a Ready. Note that this Ready is not guaranteed to - // actually be handled. We will arm readyc, but there's no guarantee - // that we will actually send on it. It's possible that we will - // service another channel instead, loop around, and then populate - // the Ready again. We could instead force the previous Ready to be - // handled first, but it's generally good to emit larger Readys plus - // it simplifies testing (by emitting less frequently and more - // predictably). - rd = n.rn.readyWithoutAccept() - readyc = n.readyc - } - - if lead != r.lead { - if r.hasLeader() { - if lead == None { - r.logger.Infof("raft.node: %x elected leader %x at term %d", r.id, r.lead, r.Term) - } else { - r.logger.Infof("raft.node: %x changed leader from %x to %x at term %d", r.id, lead, r.lead, r.Term) - } - propc = n.propc - } else { - r.logger.Infof("raft.node: %x lost leader %x at term %d", r.id, lead, r.Term) - propc = nil - } - lead = r.lead - } - - select { - // TODO: maybe buffer the config propose if there exists one (the way - // described in raft dissertation) - // Currently it is dropped in Step silently. - case pm := <-propc: - m := pm.m - m.From = r.id - err := r.Step(m) - if pm.result != nil { - pm.result <- err - close(pm.result) - } - case m := <-n.recvc: - // filter out response message from unknown From. - if pr := r.prs.Progress[m.From]; pr != nil || !IsResponseMsg(m.Type) { - r.Step(m) - } - case cc := <-n.confc: - _, okBefore := r.prs.Progress[r.id] - cs := r.applyConfChange(cc) - // If the node was removed, block incoming proposals. Note that we - // only do this if the node was in the config before. Nodes may be - // a member of the group without knowing this (when they're catching - // up on the log and don't have the latest config) and we don't want - // to block the proposal channel in that case. - // - // NB: propc is reset when the leader changes, which, if we learn - // about it, sort of implies that we got readded, maybe? This isn't - // very sound and likely has bugs. - if _, okAfter := r.prs.Progress[r.id]; okBefore && !okAfter { - var found bool - outer: - for _, sl := range [][]uint64{cs.Voters, cs.VotersOutgoing} { - for _, id := range sl { - if id == r.id { - found = true - break outer - } - } - } - if !found { - propc = nil - } - } - select { - case n.confstatec <- cs: - case <-n.done: - } - case <-n.tickc: - n.rn.Tick() - case readyc <- rd: - n.rn.acceptReady(rd) - advancec = n.advancec - case <-advancec: - n.rn.Advance(rd) - rd = Ready{} - advancec = nil - case c := <-n.status: - c <- getStatus(r) - case <-n.stop: - close(n.done) - return - } - } -} - -// Tick increments the internal logical clock for this Node. Election timeouts -// and heartbeat timeouts are in units of ticks. -func (n *node) Tick() { - select { - case n.tickc <- struct{}{}: - case <-n.done: - default: - n.rn.raft.logger.Warningf("%x A tick missed to fire. Node blocks too long!", n.rn.raft.id) - } -} - -func (n *node) Campaign(ctx context.Context) error { return n.step(ctx, pb.Message{Type: pb.MsgHup}) } - -func (n *node) Propose(ctx context.Context, data []byte) error { - return n.stepWait(ctx, pb.Message{Type: pb.MsgProp, Entries: []pb.Entry{{Data: data}}}) -} - -func (n *node) Step(ctx context.Context, m pb.Message) error { - // ignore unexpected local messages receiving over network - if IsLocalMsg(m.Type) { - // TODO: return an error? - return nil - } - return n.step(ctx, m) -} - -func confChangeToMsg(c pb.ConfChangeI) (pb.Message, error) { - typ, data, err := pb.MarshalConfChange(c) - if err != nil { - return pb.Message{}, err - } - return pb.Message{Type: pb.MsgProp, Entries: []pb.Entry{{Type: typ, Data: data}}}, nil -} - -func (n *node) ProposeConfChange(ctx context.Context, cc pb.ConfChangeI) error { - msg, err := confChangeToMsg(cc) - if err != nil { - return err - } - return n.Step(ctx, msg) -} - -func (n *node) step(ctx context.Context, m pb.Message) error { - return n.stepWithWaitOption(ctx, m, false) -} - -func (n *node) stepWait(ctx context.Context, m pb.Message) error { - return n.stepWithWaitOption(ctx, m, true) -} - -// Step advances the state machine using msgs. The ctx.Err() will be returned, -// if any. -func (n *node) stepWithWaitOption(ctx context.Context, m pb.Message, wait bool) error { - if m.Type != pb.MsgProp { - select { - case n.recvc <- m: - return nil - case <-ctx.Done(): - return ctx.Err() - case <-n.done: - return ErrStopped - } - } - ch := n.propc - pm := msgWithResult{m: m} - if wait { - pm.result = make(chan error, 1) - } - select { - case ch <- pm: - if !wait { - return nil - } - case <-ctx.Done(): - return ctx.Err() - case <-n.done: - return ErrStopped - } - select { - case err := <-pm.result: - if err != nil { - return err - } - case <-ctx.Done(): - return ctx.Err() - case <-n.done: - return ErrStopped - } - return nil -} - -func (n *node) Ready() <-chan Ready { return n.readyc } - -func (n *node) Advance() { - select { - case n.advancec <- struct{}{}: - case <-n.done: - } -} - -func (n *node) ApplyConfChange(cc pb.ConfChangeI) *pb.ConfState { - var cs pb.ConfState - select { - case n.confc <- cc.AsV2(): - case <-n.done: - } - select { - case cs = <-n.confstatec: - case <-n.done: - } - return &cs -} - -func (n *node) Status() Status { - c := make(chan Status) - select { - case n.status <- c: - return <-c - case <-n.done: - return Status{} - } -} - -func (n *node) ReportUnreachable(id uint64) { - select { - case n.recvc <- pb.Message{Type: pb.MsgUnreachable, From: id}: - case <-n.done: - } -} - -func (n *node) ReportSnapshot(id uint64, status SnapshotStatus) { - rej := status == SnapshotFailure - - select { - case n.recvc <- pb.Message{Type: pb.MsgSnapStatus, From: id, Reject: rej}: - case <-n.done: - } -} - -func (n *node) TransferLeadership(ctx context.Context, lead, transferee uint64) { - select { - // manually set 'from' and 'to', so that leader can voluntarily transfers its leadership - case n.recvc <- pb.Message{Type: pb.MsgTransferLeader, From: transferee, To: lead}: - case <-n.done: - case <-ctx.Done(): - } -} - -func (n *node) ReadIndex(ctx context.Context, rctx []byte) error { - return n.step(ctx, pb.Message{Type: pb.MsgReadIndex, Entries: []pb.Entry{{Data: rctx}}}) -} - -func newReady(r *raft, prevSoftSt *SoftState, prevHardSt pb.HardState) Ready { - rd := Ready{ - Entries: r.raftLog.unstableEntries(), - CommittedEntries: r.raftLog.nextEnts(), - Messages: r.msgs, - } - if softSt := r.softState(); !softSt.equal(prevSoftSt) { - rd.SoftState = softSt - } - if hardSt := r.hardState(); !isHardStateEqual(hardSt, prevHardSt) { - rd.HardState = hardSt - } - if r.raftLog.unstable.snapshot != nil { - rd.Snapshot = *r.raftLog.unstable.snapshot - } - if len(r.readStates) != 0 { - rd.ReadStates = r.readStates - } - rd.MustSync = MustSync(r.hardState(), prevHardSt, len(rd.Entries)) - return rd -} - -// MustSync returns true if the hard state and count of Raft entries indicate -// that a synchronous write to persistent storage is required. -func MustSync(st, prevst pb.HardState, entsnum int) bool { - // Persistent state on all servers: - // (Updated on stable storage before responding to RPCs) - // currentTerm - // votedFor - // log entries[] - return entsnum != 0 || st.Vote != prevst.Vote || st.Term != prevst.Term -} diff --git a/vendor/go.etcd.io/etcd/raft/v3/quorum/joint.go b/vendor/go.etcd.io/etcd/raft/v3/quorum/joint.go deleted file mode 100644 index e3741e0b0a..0000000000 --- a/vendor/go.etcd.io/etcd/raft/v3/quorum/joint.go +++ /dev/null @@ -1,75 +0,0 @@ -// Copyright 2019 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package quorum - -// JointConfig is a configuration of two groups of (possibly overlapping) -// majority configurations. Decisions require the support of both majorities. -type JointConfig [2]MajorityConfig - -func (c JointConfig) String() string { - if len(c[1]) > 0 { - return c[0].String() + "&&" + c[1].String() - } - return c[0].String() -} - -// IDs returns a newly initialized map representing the set of voters present -// in the joint configuration. -func (c JointConfig) IDs() map[uint64]struct{} { - m := map[uint64]struct{}{} - for _, cc := range c { - for id := range cc { - m[id] = struct{}{} - } - } - return m -} - -// Describe returns a (multi-line) representation of the commit indexes for the -// given lookuper. -func (c JointConfig) Describe(l AckedIndexer) string { - return MajorityConfig(c.IDs()).Describe(l) -} - -// CommittedIndex returns the largest committed index for the given joint -// quorum. An index is jointly committed if it is committed in both constituent -// majorities. -func (c JointConfig) CommittedIndex(l AckedIndexer) Index { - idx0 := c[0].CommittedIndex(l) - idx1 := c[1].CommittedIndex(l) - if idx0 < idx1 { - return idx0 - } - return idx1 -} - -// VoteResult takes a mapping of voters to yes/no (true/false) votes and returns -// a result indicating whether the vote is pending, lost, or won. A joint quorum -// requires both majority quorums to vote in favor. -func (c JointConfig) VoteResult(votes map[uint64]bool) VoteResult { - r1 := c[0].VoteResult(votes) - r2 := c[1].VoteResult(votes) - - if r1 == r2 { - // If they agree, return the agreed state. - return r1 - } - if r1 == VoteLost || r2 == VoteLost { - // If either config has lost, loss is the only possible outcome. - return VoteLost - } - // One side won, the other one is pending, so the whole outcome is. - return VotePending -} diff --git a/vendor/go.etcd.io/etcd/raft/v3/quorum/majority.go b/vendor/go.etcd.io/etcd/raft/v3/quorum/majority.go deleted file mode 100644 index 8858a36b63..0000000000 --- a/vendor/go.etcd.io/etcd/raft/v3/quorum/majority.go +++ /dev/null @@ -1,210 +0,0 @@ -// Copyright 2019 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package quorum - -import ( - "fmt" - "math" - "sort" - "strings" -) - -// MajorityConfig is a set of IDs that uses majority quorums to make decisions. -type MajorityConfig map[uint64]struct{} - -func (c MajorityConfig) String() string { - sl := make([]uint64, 0, len(c)) - for id := range c { - sl = append(sl, id) - } - sort.Slice(sl, func(i, j int) bool { return sl[i] < sl[j] }) - var buf strings.Builder - buf.WriteByte('(') - for i := range sl { - if i > 0 { - buf.WriteByte(' ') - } - fmt.Fprint(&buf, sl[i]) - } - buf.WriteByte(')') - return buf.String() -} - -// Describe returns a (multi-line) representation of the commit indexes for the -// given lookuper. -func (c MajorityConfig) Describe(l AckedIndexer) string { - if len(c) == 0 { - return "" - } - type tup struct { - id uint64 - idx Index - ok bool // idx found? - bar int // length of bar displayed for this tup - } - - // Below, populate .bar so that the i-th largest commit index has bar i (we - // plot this as sort of a progress bar). The actual code is a bit more - // complicated and also makes sure that equal index => equal bar. - - n := len(c) - info := make([]tup, 0, n) - for id := range c { - idx, ok := l.AckedIndex(id) - info = append(info, tup{id: id, idx: idx, ok: ok}) - } - - // Sort by index - sort.Slice(info, func(i, j int) bool { - if info[i].idx == info[j].idx { - return info[i].id < info[j].id - } - return info[i].idx < info[j].idx - }) - - // Populate .bar. - for i := range info { - if i > 0 && info[i-1].idx < info[i].idx { - info[i].bar = i - } - } - - // Sort by ID. - sort.Slice(info, func(i, j int) bool { - return info[i].id < info[j].id - }) - - var buf strings.Builder - - // Print. - fmt.Fprint(&buf, strings.Repeat(" ", n)+" idx\n") - for i := range info { - bar := info[i].bar - if !info[i].ok { - fmt.Fprint(&buf, "?"+strings.Repeat(" ", n)) - } else { - fmt.Fprint(&buf, strings.Repeat("x", bar)+">"+strings.Repeat(" ", n-bar)) - } - fmt.Fprintf(&buf, " %5d (id=%d)\n", info[i].idx, info[i].id) - } - return buf.String() -} - -// Slice returns the MajorityConfig as a sorted slice. -func (c MajorityConfig) Slice() []uint64 { - var sl []uint64 - for id := range c { - sl = append(sl, id) - } - sort.Slice(sl, func(i, j int) bool { return sl[i] < sl[j] }) - return sl -} - -func insertionSort(sl []uint64) { - a, b := 0, len(sl) - for i := a + 1; i < b; i++ { - for j := i; j > a && sl[j] < sl[j-1]; j-- { - sl[j], sl[j-1] = sl[j-1], sl[j] - } - } -} - -// CommittedIndex computes the committed index from those supplied via the -// provided AckedIndexer (for the active config). -func (c MajorityConfig) CommittedIndex(l AckedIndexer) Index { - n := len(c) - if n == 0 { - // This plays well with joint quorums which, when one half is the zero - // MajorityConfig, should behave like the other half. - return math.MaxUint64 - } - - // Use an on-stack slice to collect the committed indexes when n <= 7 - // (otherwise we alloc). The alternative is to stash a slice on - // MajorityConfig, but this impairs usability (as is, MajorityConfig is just - // a map, and that's nice). The assumption is that running with a - // replication factor of >7 is rare, and in cases in which it happens - // performance is a lesser concern (additionally the performance - // implications of an allocation here are far from drastic). - var stk [7]uint64 - var srt []uint64 - if len(stk) >= n { - srt = stk[:n] - } else { - srt = make([]uint64, n) - } - - { - // Fill the slice with the indexes observed. Any unused slots will be - // left as zero; these correspond to voters that may report in, but - // haven't yet. We fill from the right (since the zeroes will end up on - // the left after sorting below anyway). - i := n - 1 - for id := range c { - if idx, ok := l.AckedIndex(id); ok { - srt[i] = uint64(idx) - i-- - } - } - } - - // Sort by index. Use a bespoke algorithm (copied from the stdlib's sort - // package) to keep srt on the stack. - insertionSort(srt) - - // The smallest index into the array for which the value is acked by a - // quorum. In other words, from the end of the slice, move n/2+1 to the - // left (accounting for zero-indexing). - pos := n - (n/2 + 1) - return Index(srt[pos]) -} - -// VoteResult takes a mapping of voters to yes/no (true/false) votes and returns -// a result indicating whether the vote is pending (i.e. neither a quorum of -// yes/no has been reached), won (a quorum of yes has been reached), or lost (a -// quorum of no has been reached). -func (c MajorityConfig) VoteResult(votes map[uint64]bool) VoteResult { - if len(c) == 0 { - // By convention, the elections on an empty config win. This comes in - // handy with joint quorums because it'll make a half-populated joint - // quorum behave like a majority quorum. - return VoteWon - } - - ny := [2]int{} // vote counts for no and yes, respectively - - var missing int - for id := range c { - v, ok := votes[id] - if !ok { - missing++ - continue - } - if v { - ny[1]++ - } else { - ny[0]++ - } - } - - q := len(c)/2 + 1 - if ny[1] >= q { - return VoteWon - } - if ny[1]+missing >= q { - return VotePending - } - return VoteLost -} diff --git a/vendor/go.etcd.io/etcd/raft/v3/quorum/quorum.go b/vendor/go.etcd.io/etcd/raft/v3/quorum/quorum.go deleted file mode 100644 index 2899e46c96..0000000000 --- a/vendor/go.etcd.io/etcd/raft/v3/quorum/quorum.go +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright 2019 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package quorum - -import ( - "math" - "strconv" -) - -// Index is a Raft log position. -type Index uint64 - -func (i Index) String() string { - if i == math.MaxUint64 { - return "∞" - } - return strconv.FormatUint(uint64(i), 10) -} - -// AckedIndexer allows looking up a commit index for a given ID of a voter -// from a corresponding MajorityConfig. -type AckedIndexer interface { - AckedIndex(voterID uint64) (idx Index, found bool) -} - -type mapAckIndexer map[uint64]Index - -func (m mapAckIndexer) AckedIndex(id uint64) (Index, bool) { - idx, ok := m[id] - return idx, ok -} - -// VoteResult indicates the outcome of a vote. -// -//go:generate stringer -type=VoteResult -type VoteResult uint8 - -const ( - // VotePending indicates that the decision of the vote depends on future - // votes, i.e. neither "yes" or "no" has reached quorum yet. - VotePending VoteResult = 1 + iota - // VoteLost indicates that the quorum has voted "no". - VoteLost - // VoteWon indicates that the quorum has voted "yes". - VoteWon -) diff --git a/vendor/go.etcd.io/etcd/raft/v3/quorum/voteresult_string.go b/vendor/go.etcd.io/etcd/raft/v3/quorum/voteresult_string.go deleted file mode 100644 index 9eca8fd0c9..0000000000 --- a/vendor/go.etcd.io/etcd/raft/v3/quorum/voteresult_string.go +++ /dev/null @@ -1,26 +0,0 @@ -// Code generated by "stringer -type=VoteResult"; DO NOT EDIT. - -package quorum - -import "strconv" - -func _() { - // An "invalid array index" compiler error signifies that the constant values have changed. - // Re-run the stringer command to generate them again. - var x [1]struct{} - _ = x[VotePending-1] - _ = x[VoteLost-2] - _ = x[VoteWon-3] -} - -const _VoteResult_name = "VotePendingVoteLostVoteWon" - -var _VoteResult_index = [...]uint8{0, 11, 19, 26} - -func (i VoteResult) String() string { - i -= 1 - if i >= VoteResult(len(_VoteResult_index)-1) { - return "VoteResult(" + strconv.FormatInt(int64(i+1), 10) + ")" - } - return _VoteResult_name[_VoteResult_index[i]:_VoteResult_index[i+1]] -} diff --git a/vendor/go.etcd.io/etcd/raft/v3/raft.go b/vendor/go.etcd.io/etcd/raft/v3/raft.go deleted file mode 100644 index c80262ebaf..0000000000 --- a/vendor/go.etcd.io/etcd/raft/v3/raft.go +++ /dev/null @@ -1,1837 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package raft - -import ( - "bytes" - "errors" - "fmt" - "math" - "math/rand" - "sort" - "strings" - "sync" - "time" - - "go.etcd.io/etcd/raft/v3/confchange" - "go.etcd.io/etcd/raft/v3/quorum" - pb "go.etcd.io/etcd/raft/v3/raftpb" - "go.etcd.io/etcd/raft/v3/tracker" -) - -// None is a placeholder node ID used when there is no leader. -const None uint64 = 0 -const noLimit = math.MaxUint64 - -// Possible values for StateType. -const ( - StateFollower StateType = iota - StateCandidate - StateLeader - StatePreCandidate - numStates -) - -type ReadOnlyOption int - -const ( - // ReadOnlySafe guarantees the linearizability of the read only request by - // communicating with the quorum. It is the default and suggested option. - ReadOnlySafe ReadOnlyOption = iota - // ReadOnlyLeaseBased ensures linearizability of the read only request by - // relying on the leader lease. It can be affected by clock drift. - // If the clock drift is unbounded, leader might keep the lease longer than it - // should (clock can move backward/pause without any bound). ReadIndex is not safe - // in that case. - ReadOnlyLeaseBased -) - -// Possible values for CampaignType -const ( - // campaignPreElection represents the first phase of a normal election when - // Config.PreVote is true. - campaignPreElection CampaignType = "CampaignPreElection" - // campaignElection represents a normal (time-based) election (the second phase - // of the election when Config.PreVote is true). - campaignElection CampaignType = "CampaignElection" - // campaignTransfer represents the type of leader transfer - campaignTransfer CampaignType = "CampaignTransfer" -) - -// ErrProposalDropped is returned when the proposal is ignored by some cases, -// so that the proposer can be notified and fail fast. -var ErrProposalDropped = errors.New("raft proposal dropped") - -// lockedRand is a small wrapper around rand.Rand to provide -// synchronization among multiple raft groups. Only the methods needed -// by the code are exposed (e.g. Intn). -type lockedRand struct { - mu sync.Mutex - rand *rand.Rand -} - -func (r *lockedRand) Intn(n int) int { - r.mu.Lock() - v := r.rand.Intn(n) - r.mu.Unlock() - return v -} - -var globalRand = &lockedRand{ - rand: rand.New(rand.NewSource(time.Now().UnixNano())), -} - -// CampaignType represents the type of campaigning -// the reason we use the type of string instead of uint64 -// is because it's simpler to compare and fill in raft entries -type CampaignType string - -// StateType represents the role of a node in a cluster. -type StateType uint64 - -var stmap = [...]string{ - "StateFollower", - "StateCandidate", - "StateLeader", - "StatePreCandidate", -} - -func (st StateType) String() string { - return stmap[uint64(st)] -} - -// Config contains the parameters to start a raft. -type Config struct { - // ID is the identity of the local raft. ID cannot be 0. - ID uint64 - - // ElectionTick is the number of Node.Tick invocations that must pass between - // elections. That is, if a follower does not receive any message from the - // leader of current term before ElectionTick has elapsed, it will become - // candidate and start an election. ElectionTick must be greater than - // HeartbeatTick. We suggest ElectionTick = 10 * HeartbeatTick to avoid - // unnecessary leader switching. - ElectionTick int - // HeartbeatTick is the number of Node.Tick invocations that must pass between - // heartbeats. That is, a leader sends heartbeat messages to maintain its - // leadership every HeartbeatTick ticks. - HeartbeatTick int - - // Storage is the storage for raft. raft generates entries and states to be - // stored in storage. raft reads the persisted entries and states out of - // Storage when it needs. raft reads out the previous state and configuration - // out of storage when restarting. - Storage Storage - // Applied is the last applied index. It should only be set when restarting - // raft. raft will not return entries to the application smaller or equal to - // Applied. If Applied is unset when restarting, raft might return previous - // applied entries. This is a very application dependent configuration. - Applied uint64 - - // MaxSizePerMsg limits the max byte size of each append message. Smaller - // value lowers the raft recovery cost(initial probing and message lost - // during normal operation). On the other side, it might affect the - // throughput during normal replication. Note: math.MaxUint64 for unlimited, - // 0 for at most one entry per message. - MaxSizePerMsg uint64 - // MaxCommittedSizePerReady limits the size of the committed entries which - // can be applied. - MaxCommittedSizePerReady uint64 - // MaxUncommittedEntriesSize limits the aggregate byte size of the - // uncommitted entries that may be appended to a leader's log. Once this - // limit is exceeded, proposals will begin to return ErrProposalDropped - // errors. Note: 0 for no limit. - MaxUncommittedEntriesSize uint64 - // MaxInflightMsgs limits the max number of in-flight append messages during - // optimistic replication phase. The application transportation layer usually - // has its own sending buffer over TCP/UDP. Setting MaxInflightMsgs to avoid - // overflowing that sending buffer. TODO (xiangli): feedback to application to - // limit the proposal rate? - MaxInflightMsgs int - - // CheckQuorum specifies if the leader should check quorum activity. Leader - // steps down when quorum is not active for an electionTimeout. - CheckQuorum bool - - // PreVote enables the Pre-Vote algorithm described in raft thesis section - // 9.6. This prevents disruption when a node that has been partitioned away - // rejoins the cluster. - PreVote bool - - // ReadOnlyOption specifies how the read only request is processed. - // - // ReadOnlySafe guarantees the linearizability of the read only request by - // communicating with the quorum. It is the default and suggested option. - // - // ReadOnlyLeaseBased ensures linearizability of the read only request by - // relying on the leader lease. It can be affected by clock drift. - // If the clock drift is unbounded, leader might keep the lease longer than it - // should (clock can move backward/pause without any bound). ReadIndex is not safe - // in that case. - // CheckQuorum MUST be enabled if ReadOnlyOption is ReadOnlyLeaseBased. - ReadOnlyOption ReadOnlyOption - - // Logger is the logger used for raft log. For multinode which can host - // multiple raft group, each raft group can have its own logger - Logger Logger - - // DisableProposalForwarding set to true means that followers will drop - // proposals, rather than forwarding them to the leader. One use case for - // this feature would be in a situation where the Raft leader is used to - // compute the data of a proposal, for example, adding a timestamp from a - // hybrid logical clock to data in a monotonically increasing way. Forwarding - // should be disabled to prevent a follower with an inaccurate hybrid - // logical clock from assigning the timestamp and then forwarding the data - // to the leader. - DisableProposalForwarding bool -} - -func (c *Config) validate() error { - if c.ID == None { - return errors.New("cannot use none as id") - } - - if c.HeartbeatTick <= 0 { - return errors.New("heartbeat tick must be greater than 0") - } - - if c.ElectionTick <= c.HeartbeatTick { - return errors.New("election tick must be greater than heartbeat tick") - } - - if c.Storage == nil { - return errors.New("storage cannot be nil") - } - - if c.MaxUncommittedEntriesSize == 0 { - c.MaxUncommittedEntriesSize = noLimit - } - - // default MaxCommittedSizePerReady to MaxSizePerMsg because they were - // previously the same parameter. - if c.MaxCommittedSizePerReady == 0 { - c.MaxCommittedSizePerReady = c.MaxSizePerMsg - } - - if c.MaxInflightMsgs <= 0 { - return errors.New("max inflight messages must be greater than 0") - } - - if c.Logger == nil { - c.Logger = getLogger() - } - - if c.ReadOnlyOption == ReadOnlyLeaseBased && !c.CheckQuorum { - return errors.New("CheckQuorum must be enabled when ReadOnlyOption is ReadOnlyLeaseBased") - } - - return nil -} - -type raft struct { - id uint64 - - Term uint64 - Vote uint64 - - readStates []ReadState - - // the log - raftLog *raftLog - - maxMsgSize uint64 - maxUncommittedSize uint64 - // TODO(tbg): rename to trk. - prs tracker.ProgressTracker - - state StateType - - // isLearner is true if the local raft node is a learner. - isLearner bool - - msgs []pb.Message - - // the leader id - lead uint64 - // leadTransferee is id of the leader transfer target when its value is not zero. - // Follow the procedure defined in raft thesis 3.10. - leadTransferee uint64 - // Only one conf change may be pending (in the log, but not yet - // applied) at a time. This is enforced via pendingConfIndex, which - // is set to a value >= the log index of the latest pending - // configuration change (if any). Config changes are only allowed to - // be proposed if the leader's applied index is greater than this - // value. - pendingConfIndex uint64 - // an estimate of the size of the uncommitted tail of the Raft log. Used to - // prevent unbounded log growth. Only maintained by the leader. Reset on - // term changes. - uncommittedSize uint64 - - readOnly *readOnly - - // number of ticks since it reached last electionTimeout when it is leader - // or candidate. - // number of ticks since it reached last electionTimeout or received a - // valid message from current leader when it is a follower. - electionElapsed int - - // number of ticks since it reached last heartbeatTimeout. - // only leader keeps heartbeatElapsed. - heartbeatElapsed int - - checkQuorum bool - preVote bool - - heartbeatTimeout int - electionTimeout int - // randomizedElectionTimeout is a random number between - // [electiontimeout, 2 * electiontimeout - 1]. It gets reset - // when raft changes its state to follower or candidate. - randomizedElectionTimeout int - disableProposalForwarding bool - - tick func() - step stepFunc - - logger Logger - - // pendingReadIndexMessages is used to store messages of type MsgReadIndex - // that can't be answered as new leader didn't committed any log in - // current term. Those will be handled as fast as first log is committed in - // current term. - pendingReadIndexMessages []pb.Message -} - -func newRaft(c *Config) *raft { - if err := c.validate(); err != nil { - panic(err.Error()) - } - raftlog := newLogWithSize(c.Storage, c.Logger, c.MaxCommittedSizePerReady) - hs, cs, err := c.Storage.InitialState() - if err != nil { - panic(err) // TODO(bdarnell) - } - - r := &raft{ - id: c.ID, - lead: None, - isLearner: false, - raftLog: raftlog, - maxMsgSize: c.MaxSizePerMsg, - maxUncommittedSize: c.MaxUncommittedEntriesSize, - prs: tracker.MakeProgressTracker(c.MaxInflightMsgs), - electionTimeout: c.ElectionTick, - heartbeatTimeout: c.HeartbeatTick, - logger: c.Logger, - checkQuorum: c.CheckQuorum, - preVote: c.PreVote, - readOnly: newReadOnly(c.ReadOnlyOption), - disableProposalForwarding: c.DisableProposalForwarding, - } - - cfg, prs, err := confchange.Restore(confchange.Changer{ - Tracker: r.prs, - LastIndex: raftlog.lastIndex(), - }, cs) - if err != nil { - panic(err) - } - assertConfStatesEquivalent(r.logger, cs, r.switchToConfig(cfg, prs)) - - if !IsEmptyHardState(hs) { - r.loadState(hs) - } - if c.Applied > 0 { - raftlog.appliedTo(c.Applied) - } - r.becomeFollower(r.Term, None) - - var nodesStrs []string - for _, n := range r.prs.VoterNodes() { - nodesStrs = append(nodesStrs, fmt.Sprintf("%x", n)) - } - - r.logger.Infof("newRaft %x [peers: [%s], term: %d, commit: %d, applied: %d, lastindex: %d, lastterm: %d]", - r.id, strings.Join(nodesStrs, ","), r.Term, r.raftLog.committed, r.raftLog.applied, r.raftLog.lastIndex(), r.raftLog.lastTerm()) - return r -} - -func (r *raft) hasLeader() bool { return r.lead != None } - -func (r *raft) softState() *SoftState { return &SoftState{Lead: r.lead, RaftState: r.state} } - -func (r *raft) hardState() pb.HardState { - return pb.HardState{ - Term: r.Term, - Vote: r.Vote, - Commit: r.raftLog.committed, - } -} - -// send schedules persisting state to a stable storage and AFTER that -// sending the message (as part of next Ready message processing). -func (r *raft) send(m pb.Message) { - if m.From == None { - m.From = r.id - } - if m.Type == pb.MsgVote || m.Type == pb.MsgVoteResp || m.Type == pb.MsgPreVote || m.Type == pb.MsgPreVoteResp { - if m.Term == 0 { - // All {pre-,}campaign messages need to have the term set when - // sending. - // - MsgVote: m.Term is the term the node is campaigning for, - // non-zero as we increment the term when campaigning. - // - MsgVoteResp: m.Term is the new r.Term if the MsgVote was - // granted, non-zero for the same reason MsgVote is - // - MsgPreVote: m.Term is the term the node will campaign, - // non-zero as we use m.Term to indicate the next term we'll be - // campaigning for - // - MsgPreVoteResp: m.Term is the term received in the original - // MsgPreVote if the pre-vote was granted, non-zero for the - // same reasons MsgPreVote is - panic(fmt.Sprintf("term should be set when sending %s", m.Type)) - } - } else { - if m.Term != 0 { - panic(fmt.Sprintf("term should not be set when sending %s (was %d)", m.Type, m.Term)) - } - // do not attach term to MsgProp, MsgReadIndex - // proposals are a way to forward to the leader and - // should be treated as local message. - // MsgReadIndex is also forwarded to leader. - if m.Type != pb.MsgProp && m.Type != pb.MsgReadIndex { - m.Term = r.Term - } - } - r.msgs = append(r.msgs, m) -} - -// sendAppend sends an append RPC with new entries (if any) and the -// current commit index to the given peer. -func (r *raft) sendAppend(to uint64) { - r.maybeSendAppend(to, true) -} - -// maybeSendAppend sends an append RPC with new entries to the given peer, -// if necessary. Returns true if a message was sent. The sendIfEmpty -// argument controls whether messages with no entries will be sent -// ("empty" messages are useful to convey updated Commit indexes, but -// are undesirable when we're sending multiple messages in a batch). -func (r *raft) maybeSendAppend(to uint64, sendIfEmpty bool) bool { - pr := r.prs.Progress[to] - if pr.IsPaused() { - return false - } - m := pb.Message{} - m.To = to - - term, errt := r.raftLog.term(pr.Next - 1) - ents, erre := r.raftLog.entries(pr.Next, r.maxMsgSize) - if len(ents) == 0 && !sendIfEmpty { - return false - } - - if errt != nil || erre != nil { // send snapshot if we failed to get term or entries - if !pr.RecentActive { - r.logger.Debugf("ignore sending snapshot to %x since it is not recently active", to) - return false - } - - m.Type = pb.MsgSnap - snapshot, err := r.raftLog.snapshot() - if err != nil { - if err == ErrSnapshotTemporarilyUnavailable { - r.logger.Debugf("%x failed to send snapshot to %x because snapshot is temporarily unavailable", r.id, to) - return false - } - panic(err) // TODO(bdarnell) - } - if IsEmptySnap(snapshot) { - panic("need non-empty snapshot") - } - m.Snapshot = snapshot - sindex, sterm := snapshot.Metadata.Index, snapshot.Metadata.Term - r.logger.Debugf("%x [firstindex: %d, commit: %d] sent snapshot[index: %d, term: %d] to %x [%s]", - r.id, r.raftLog.firstIndex(), r.raftLog.committed, sindex, sterm, to, pr) - pr.BecomeSnapshot(sindex) - r.logger.Debugf("%x paused sending replication messages to %x [%s]", r.id, to, pr) - } else { - m.Type = pb.MsgApp - m.Index = pr.Next - 1 - m.LogTerm = term - m.Entries = ents - m.Commit = r.raftLog.committed - if n := len(m.Entries); n != 0 { - switch pr.State { - // optimistically increase the next when in StateReplicate - case tracker.StateReplicate: - last := m.Entries[n-1].Index - pr.OptimisticUpdate(last) - pr.Inflights.Add(last) - case tracker.StateProbe: - pr.ProbeSent = true - default: - r.logger.Panicf("%x is sending append in unhandled state %s", r.id, pr.State) - } - } - } - r.send(m) - return true -} - -// sendHeartbeat sends a heartbeat RPC to the given peer. -func (r *raft) sendHeartbeat(to uint64, ctx []byte) { - // Attach the commit as min(to.matched, r.committed). - // When the leader sends out heartbeat message, - // the receiver(follower) might not be matched with the leader - // or it might not have all the committed entries. - // The leader MUST NOT forward the follower's commit to - // an unmatched index. - commit := min(r.prs.Progress[to].Match, r.raftLog.committed) - m := pb.Message{ - To: to, - Type: pb.MsgHeartbeat, - Commit: commit, - Context: ctx, - } - - r.send(m) -} - -// bcastAppend sends RPC, with entries to all peers that are not up-to-date -// according to the progress recorded in r.prs. -func (r *raft) bcastAppend() { - r.prs.Visit(func(id uint64, _ *tracker.Progress) { - if id == r.id { - return - } - r.sendAppend(id) - }) -} - -// bcastHeartbeat sends RPC, without entries to all the peers. -func (r *raft) bcastHeartbeat() { - lastCtx := r.readOnly.lastPendingRequestCtx() - if len(lastCtx) == 0 { - r.bcastHeartbeatWithCtx(nil) - } else { - r.bcastHeartbeatWithCtx([]byte(lastCtx)) - } -} - -func (r *raft) bcastHeartbeatWithCtx(ctx []byte) { - r.prs.Visit(func(id uint64, _ *tracker.Progress) { - if id == r.id { - return - } - r.sendHeartbeat(id, ctx) - }) -} - -func (r *raft) advance(rd Ready) { - r.reduceUncommittedSize(rd.CommittedEntries) - - // If entries were applied (or a snapshot), update our cursor for - // the next Ready. Note that if the current HardState contains a - // new Commit index, this does not mean that we're also applying - // all of the new entries due to commit pagination by size. - if newApplied := rd.appliedCursor(); newApplied > 0 { - oldApplied := r.raftLog.applied - r.raftLog.appliedTo(newApplied) - - if r.prs.Config.AutoLeave && oldApplied <= r.pendingConfIndex && newApplied >= r.pendingConfIndex && r.state == StateLeader { - // If the current (and most recent, at least for this leader's term) - // configuration should be auto-left, initiate that now. We use a - // nil Data which unmarshals into an empty ConfChangeV2 and has the - // benefit that appendEntry can never refuse it based on its size - // (which registers as zero). - ent := pb.Entry{ - Type: pb.EntryConfChangeV2, - Data: nil, - } - // There's no way in which this proposal should be able to be rejected. - if !r.appendEntry(ent) { - panic("refused un-refusable auto-leaving ConfChangeV2") - } - r.pendingConfIndex = r.raftLog.lastIndex() - r.logger.Infof("initiating automatic transition out of joint configuration %s", r.prs.Config) - } - } - - if len(rd.Entries) > 0 { - e := rd.Entries[len(rd.Entries)-1] - r.raftLog.stableTo(e.Index, e.Term) - } - if !IsEmptySnap(rd.Snapshot) { - r.raftLog.stableSnapTo(rd.Snapshot.Metadata.Index) - } -} - -// maybeCommit attempts to advance the commit index. Returns true if -// the commit index changed (in which case the caller should call -// r.bcastAppend). -func (r *raft) maybeCommit() bool { - mci := r.prs.Committed() - return r.raftLog.maybeCommit(mci, r.Term) -} - -func (r *raft) reset(term uint64) { - if r.Term != term { - r.Term = term - r.Vote = None - } - r.lead = None - - r.electionElapsed = 0 - r.heartbeatElapsed = 0 - r.resetRandomizedElectionTimeout() - - r.abortLeaderTransfer() - - r.prs.ResetVotes() - r.prs.Visit(func(id uint64, pr *tracker.Progress) { - *pr = tracker.Progress{ - Match: 0, - Next: r.raftLog.lastIndex() + 1, - Inflights: tracker.NewInflights(r.prs.MaxInflight), - IsLearner: pr.IsLearner, - } - if id == r.id { - pr.Match = r.raftLog.lastIndex() - } - }) - - r.pendingConfIndex = 0 - r.uncommittedSize = 0 - r.readOnly = newReadOnly(r.readOnly.option) -} - -func (r *raft) appendEntry(es ...pb.Entry) (accepted bool) { - li := r.raftLog.lastIndex() - for i := range es { - es[i].Term = r.Term - es[i].Index = li + 1 + uint64(i) - } - // Track the size of this uncommitted proposal. - if !r.increaseUncommittedSize(es) { - r.logger.Debugf( - "%x appending new entries to log would exceed uncommitted entry size limit; dropping proposal", - r.id, - ) - // Drop the proposal. - return false - } - // use latest "last" index after truncate/append - li = r.raftLog.append(es...) - r.prs.Progress[r.id].MaybeUpdate(li) - // Regardless of maybeCommit's return, our caller will call bcastAppend. - r.maybeCommit() - return true -} - -// tickElection is run by followers and candidates after r.electionTimeout. -func (r *raft) tickElection() { - r.electionElapsed++ - - if r.promotable() && r.pastElectionTimeout() { - r.electionElapsed = 0 - r.Step(pb.Message{From: r.id, Type: pb.MsgHup}) - } -} - -// tickHeartbeat is run by leaders to send a MsgBeat after r.heartbeatTimeout. -func (r *raft) tickHeartbeat() { - r.heartbeatElapsed++ - r.electionElapsed++ - - if r.electionElapsed >= r.electionTimeout { - r.electionElapsed = 0 - if r.checkQuorum { - r.Step(pb.Message{From: r.id, Type: pb.MsgCheckQuorum}) - } - // If current leader cannot transfer leadership in electionTimeout, it becomes leader again. - if r.state == StateLeader && r.leadTransferee != None { - r.abortLeaderTransfer() - } - } - - if r.state != StateLeader { - return - } - - if r.heartbeatElapsed >= r.heartbeatTimeout { - r.heartbeatElapsed = 0 - r.Step(pb.Message{From: r.id, Type: pb.MsgBeat}) - } -} - -func (r *raft) becomeFollower(term uint64, lead uint64) { - r.step = stepFollower - r.reset(term) - r.tick = r.tickElection - r.lead = lead - r.state = StateFollower - r.logger.Infof("%x became follower at term %d", r.id, r.Term) -} - -func (r *raft) becomeCandidate() { - // TODO(xiangli) remove the panic when the raft implementation is stable - if r.state == StateLeader { - panic("invalid transition [leader -> candidate]") - } - r.step = stepCandidate - r.reset(r.Term + 1) - r.tick = r.tickElection - r.Vote = r.id - r.state = StateCandidate - r.logger.Infof("%x became candidate at term %d", r.id, r.Term) -} - -func (r *raft) becomePreCandidate() { - // TODO(xiangli) remove the panic when the raft implementation is stable - if r.state == StateLeader { - panic("invalid transition [leader -> pre-candidate]") - } - // Becoming a pre-candidate changes our step functions and state, - // but doesn't change anything else. In particular it does not increase - // r.Term or change r.Vote. - r.step = stepCandidate - r.prs.ResetVotes() - r.tick = r.tickElection - r.lead = None - r.state = StatePreCandidate - r.logger.Infof("%x became pre-candidate at term %d", r.id, r.Term) -} - -func (r *raft) becomeLeader() { - // TODO(xiangli) remove the panic when the raft implementation is stable - if r.state == StateFollower { - panic("invalid transition [follower -> leader]") - } - r.step = stepLeader - r.reset(r.Term) - r.tick = r.tickHeartbeat - r.lead = r.id - r.state = StateLeader - // Followers enter replicate mode when they've been successfully probed - // (perhaps after having received a snapshot as a result). The leader is - // trivially in this state. Note that r.reset() has initialized this - // progress with the last index already. - r.prs.Progress[r.id].BecomeReplicate() - - // Conservatively set the pendingConfIndex to the last index in the - // log. There may or may not be a pending config change, but it's - // safe to delay any future proposals until we commit all our - // pending log entries, and scanning the entire tail of the log - // could be expensive. - r.pendingConfIndex = r.raftLog.lastIndex() - - emptyEnt := pb.Entry{Data: nil} - if !r.appendEntry(emptyEnt) { - // This won't happen because we just called reset() above. - r.logger.Panic("empty entry was dropped") - } - // As a special case, don't count the initial empty entry towards the - // uncommitted log quota. This is because we want to preserve the - // behavior of allowing one entry larger than quota if the current - // usage is zero. - r.reduceUncommittedSize([]pb.Entry{emptyEnt}) - r.logger.Infof("%x became leader at term %d", r.id, r.Term) -} - -func (r *raft) hup(t CampaignType) { - if r.state == StateLeader { - r.logger.Debugf("%x ignoring MsgHup because already leader", r.id) - return - } - - if !r.promotable() { - r.logger.Warningf("%x is unpromotable and can not campaign", r.id) - return - } - ents, err := r.raftLog.slice(r.raftLog.applied+1, r.raftLog.committed+1, noLimit) - if err != nil { - r.logger.Panicf("unexpected error getting unapplied entries (%v)", err) - } - if n := numOfPendingConf(ents); n != 0 && r.raftLog.committed > r.raftLog.applied { - r.logger.Warningf("%x cannot campaign at term %d since there are still %d pending configuration changes to apply", r.id, r.Term, n) - return - } - - r.logger.Infof("%x is starting a new election at term %d", r.id, r.Term) - r.campaign(t) -} - -// campaign transitions the raft instance to candidate state. This must only be -// called after verifying that this is a legitimate transition. -func (r *raft) campaign(t CampaignType) { - if !r.promotable() { - // This path should not be hit (callers are supposed to check), but - // better safe than sorry. - r.logger.Warningf("%x is unpromotable; campaign() should have been called", r.id) - } - var term uint64 - var voteMsg pb.MessageType - if t == campaignPreElection { - r.becomePreCandidate() - voteMsg = pb.MsgPreVote - // PreVote RPCs are sent for the next term before we've incremented r.Term. - term = r.Term + 1 - } else { - r.becomeCandidate() - voteMsg = pb.MsgVote - term = r.Term - } - if _, _, res := r.poll(r.id, voteRespMsgType(voteMsg), true); res == quorum.VoteWon { - // We won the election after voting for ourselves (which must mean that - // this is a single-node cluster). Advance to the next state. - if t == campaignPreElection { - r.campaign(campaignElection) - } else { - r.becomeLeader() - } - return - } - var ids []uint64 - { - idMap := r.prs.Voters.IDs() - ids = make([]uint64, 0, len(idMap)) - for id := range idMap { - ids = append(ids, id) - } - sort.Slice(ids, func(i, j int) bool { return ids[i] < ids[j] }) - } - for _, id := range ids { - if id == r.id { - continue - } - r.logger.Infof("%x [logterm: %d, index: %d] sent %s request to %x at term %d", - r.id, r.raftLog.lastTerm(), r.raftLog.lastIndex(), voteMsg, id, r.Term) - - var ctx []byte - if t == campaignTransfer { - ctx = []byte(t) - } - r.send(pb.Message{Term: term, To: id, Type: voteMsg, Index: r.raftLog.lastIndex(), LogTerm: r.raftLog.lastTerm(), Context: ctx}) - } -} - -func (r *raft) poll(id uint64, t pb.MessageType, v bool) (granted int, rejected int, result quorum.VoteResult) { - if v { - r.logger.Infof("%x received %s from %x at term %d", r.id, t, id, r.Term) - } else { - r.logger.Infof("%x received %s rejection from %x at term %d", r.id, t, id, r.Term) - } - r.prs.RecordVote(id, v) - return r.prs.TallyVotes() -} - -func (r *raft) Step(m pb.Message) error { - // Handle the message term, which may result in our stepping down to a follower. - switch { - case m.Term == 0: - // local message - case m.Term > r.Term: - if m.Type == pb.MsgVote || m.Type == pb.MsgPreVote { - force := bytes.Equal(m.Context, []byte(campaignTransfer)) - inLease := r.checkQuorum && r.lead != None && r.electionElapsed < r.electionTimeout - if !force && inLease { - // If a server receives a RequestVote request within the minimum election timeout - // of hearing from a current leader, it does not update its term or grant its vote - r.logger.Infof("%x [logterm: %d, index: %d, vote: %x] ignored %s from %x [logterm: %d, index: %d] at term %d: lease is not expired (remaining ticks: %d)", - r.id, r.raftLog.lastTerm(), r.raftLog.lastIndex(), r.Vote, m.Type, m.From, m.LogTerm, m.Index, r.Term, r.electionTimeout-r.electionElapsed) - return nil - } - } - switch { - case m.Type == pb.MsgPreVote: - // Never change our term in response to a PreVote - case m.Type == pb.MsgPreVoteResp && !m.Reject: - // We send pre-vote requests with a term in our future. If the - // pre-vote is granted, we will increment our term when we get a - // quorum. If it is not, the term comes from the node that - // rejected our vote so we should become a follower at the new - // term. - default: - r.logger.Infof("%x [term: %d] received a %s message with higher term from %x [term: %d]", - r.id, r.Term, m.Type, m.From, m.Term) - if m.Type == pb.MsgApp || m.Type == pb.MsgHeartbeat || m.Type == pb.MsgSnap { - r.becomeFollower(m.Term, m.From) - } else { - r.becomeFollower(m.Term, None) - } - } - - case m.Term < r.Term: - if (r.checkQuorum || r.preVote) && (m.Type == pb.MsgHeartbeat || m.Type == pb.MsgApp) { - // We have received messages from a leader at a lower term. It is possible - // that these messages were simply delayed in the network, but this could - // also mean that this node has advanced its term number during a network - // partition, and it is now unable to either win an election or to rejoin - // the majority on the old term. If checkQuorum is false, this will be - // handled by incrementing term numbers in response to MsgVote with a - // higher term, but if checkQuorum is true we may not advance the term on - // MsgVote and must generate other messages to advance the term. The net - // result of these two features is to minimize the disruption caused by - // nodes that have been removed from the cluster's configuration: a - // removed node will send MsgVotes (or MsgPreVotes) which will be ignored, - // but it will not receive MsgApp or MsgHeartbeat, so it will not create - // disruptive term increases, by notifying leader of this node's activeness. - // The above comments also true for Pre-Vote - // - // When follower gets isolated, it soon starts an election ending - // up with a higher term than leader, although it won't receive enough - // votes to win the election. When it regains connectivity, this response - // with "pb.MsgAppResp" of higher term would force leader to step down. - // However, this disruption is inevitable to free this stuck node with - // fresh election. This can be prevented with Pre-Vote phase. - r.send(pb.Message{To: m.From, Type: pb.MsgAppResp}) - } else if m.Type == pb.MsgPreVote { - // Before Pre-Vote enable, there may have candidate with higher term, - // but less log. After update to Pre-Vote, the cluster may deadlock if - // we drop messages with a lower term. - r.logger.Infof("%x [logterm: %d, index: %d, vote: %x] rejected %s from %x [logterm: %d, index: %d] at term %d", - r.id, r.raftLog.lastTerm(), r.raftLog.lastIndex(), r.Vote, m.Type, m.From, m.LogTerm, m.Index, r.Term) - r.send(pb.Message{To: m.From, Term: r.Term, Type: pb.MsgPreVoteResp, Reject: true}) - } else { - // ignore other cases - r.logger.Infof("%x [term: %d] ignored a %s message with lower term from %x [term: %d]", - r.id, r.Term, m.Type, m.From, m.Term) - } - return nil - } - - switch m.Type { - case pb.MsgHup: - if r.preVote { - r.hup(campaignPreElection) - } else { - r.hup(campaignElection) - } - - case pb.MsgVote, pb.MsgPreVote: - // We can vote if this is a repeat of a vote we've already cast... - canVote := r.Vote == m.From || - // ...we haven't voted and we don't think there's a leader yet in this term... - (r.Vote == None && r.lead == None) || - // ...or this is a PreVote for a future term... - (m.Type == pb.MsgPreVote && m.Term > r.Term) - // ...and we believe the candidate is up to date. - if canVote && r.raftLog.isUpToDate(m.Index, m.LogTerm) { - // Note: it turns out that that learners must be allowed to cast votes. - // This seems counter- intuitive but is necessary in the situation in which - // a learner has been promoted (i.e. is now a voter) but has not learned - // about this yet. - // For example, consider a group in which id=1 is a learner and id=2 and - // id=3 are voters. A configuration change promoting 1 can be committed on - // the quorum `{2,3}` without the config change being appended to the - // learner's log. If the leader (say 2) fails, there are de facto two - // voters remaining. Only 3 can win an election (due to its log containing - // all committed entries), but to do so it will need 1 to vote. But 1 - // considers itself a learner and will continue to do so until 3 has - // stepped up as leader, replicates the conf change to 1, and 1 applies it. - // Ultimately, by receiving a request to vote, the learner realizes that - // the candidate believes it to be a voter, and that it should act - // accordingly. The candidate's config may be stale, too; but in that case - // it won't win the election, at least in the absence of the bug discussed - // in: - // https://github.com/etcd-io/etcd/issues/7625#issuecomment-488798263. - r.logger.Infof("%x [logterm: %d, index: %d, vote: %x] cast %s for %x [logterm: %d, index: %d] at term %d", - r.id, r.raftLog.lastTerm(), r.raftLog.lastIndex(), r.Vote, m.Type, m.From, m.LogTerm, m.Index, r.Term) - // When responding to Msg{Pre,}Vote messages we include the term - // from the message, not the local term. To see why, consider the - // case where a single node was previously partitioned away and - // it's local term is now out of date. If we include the local term - // (recall that for pre-votes we don't update the local term), the - // (pre-)campaigning node on the other end will proceed to ignore - // the message (it ignores all out of date messages). - // The term in the original message and current local term are the - // same in the case of regular votes, but different for pre-votes. - r.send(pb.Message{To: m.From, Term: m.Term, Type: voteRespMsgType(m.Type)}) - if m.Type == pb.MsgVote { - // Only record real votes. - r.electionElapsed = 0 - r.Vote = m.From - } - } else { - r.logger.Infof("%x [logterm: %d, index: %d, vote: %x] rejected %s from %x [logterm: %d, index: %d] at term %d", - r.id, r.raftLog.lastTerm(), r.raftLog.lastIndex(), r.Vote, m.Type, m.From, m.LogTerm, m.Index, r.Term) - r.send(pb.Message{To: m.From, Term: r.Term, Type: voteRespMsgType(m.Type), Reject: true}) - } - - default: - err := r.step(r, m) - if err != nil { - return err - } - } - return nil -} - -type stepFunc func(r *raft, m pb.Message) error - -func stepLeader(r *raft, m pb.Message) error { - // These message types do not require any progress for m.From. - switch m.Type { - case pb.MsgBeat: - r.bcastHeartbeat() - return nil - case pb.MsgCheckQuorum: - // The leader should always see itself as active. As a precaution, handle - // the case in which the leader isn't in the configuration any more (for - // example if it just removed itself). - // - // TODO(tbg): I added a TODO in removeNode, it doesn't seem that the - // leader steps down when removing itself. I might be missing something. - if pr := r.prs.Progress[r.id]; pr != nil { - pr.RecentActive = true - } - if !r.prs.QuorumActive() { - r.logger.Warningf("%x stepped down to follower since quorum is not active", r.id) - r.becomeFollower(r.Term, None) - } - // Mark everyone (but ourselves) as inactive in preparation for the next - // CheckQuorum. - r.prs.Visit(func(id uint64, pr *tracker.Progress) { - if id != r.id { - pr.RecentActive = false - } - }) - return nil - case pb.MsgProp: - if len(m.Entries) == 0 { - r.logger.Panicf("%x stepped empty MsgProp", r.id) - } - if r.prs.Progress[r.id] == nil { - // If we are not currently a member of the range (i.e. this node - // was removed from the configuration while serving as leader), - // drop any new proposals. - return ErrProposalDropped - } - if r.leadTransferee != None { - r.logger.Debugf("%x [term %d] transfer leadership to %x is in progress; dropping proposal", r.id, r.Term, r.leadTransferee) - return ErrProposalDropped - } - - for i := range m.Entries { - e := &m.Entries[i] - var cc pb.ConfChangeI - if e.Type == pb.EntryConfChange { - var ccc pb.ConfChange - if err := ccc.Unmarshal(e.Data); err != nil { - panic(err) - } - cc = ccc - } else if e.Type == pb.EntryConfChangeV2 { - var ccc pb.ConfChangeV2 - if err := ccc.Unmarshal(e.Data); err != nil { - panic(err) - } - cc = ccc - } - if cc != nil { - alreadyPending := r.pendingConfIndex > r.raftLog.applied - alreadyJoint := len(r.prs.Config.Voters[1]) > 0 - wantsLeaveJoint := len(cc.AsV2().Changes) == 0 - - var refused string - if alreadyPending { - refused = fmt.Sprintf("possible unapplied conf change at index %d (applied to %d)", r.pendingConfIndex, r.raftLog.applied) - } else if alreadyJoint && !wantsLeaveJoint { - refused = "must transition out of joint config first" - } else if !alreadyJoint && wantsLeaveJoint { - refused = "not in joint state; refusing empty conf change" - } - - if refused != "" { - r.logger.Infof("%x ignoring conf change %v at config %s: %s", r.id, cc, r.prs.Config, refused) - m.Entries[i] = pb.Entry{Type: pb.EntryNormal} - } else { - r.pendingConfIndex = r.raftLog.lastIndex() + uint64(i) + 1 - } - } - } - - if !r.appendEntry(m.Entries...) { - return ErrProposalDropped - } - r.bcastAppend() - return nil - case pb.MsgReadIndex: - // only one voting member (the leader) in the cluster - if r.prs.IsSingleton() { - if resp := r.responseToReadIndexReq(m, r.raftLog.committed); resp.To != None { - r.send(resp) - } - return nil - } - - // Postpone read only request when this leader has not committed - // any log entry at its term. - if !r.committedEntryInCurrentTerm() { - r.pendingReadIndexMessages = append(r.pendingReadIndexMessages, m) - return nil - } - - sendMsgReadIndexResponse(r, m) - - return nil - } - - // All other message types require a progress for m.From (pr). - pr := r.prs.Progress[m.From] - if pr == nil { - r.logger.Debugf("%x no progress available for %x", r.id, m.From) - return nil - } - switch m.Type { - case pb.MsgAppResp: - pr.RecentActive = true - - if m.Reject { - // RejectHint is the suggested next base entry for appending (i.e. - // we try to append entry RejectHint+1 next), and LogTerm is the - // term that the follower has at index RejectHint. Older versions - // of this library did not populate LogTerm for rejections and it - // is zero for followers with an empty log. - // - // Under normal circumstances, the leader's log is longer than the - // follower's and the follower's log is a prefix of the leader's - // (i.e. there is no divergent uncommitted suffix of the log on the - // follower). In that case, the first probe reveals where the - // follower's log ends (RejectHint=follower's last index) and the - // subsequent probe succeeds. - // - // However, when networks are partitioned or systems overloaded, - // large divergent log tails can occur. The naive attempt, probing - // entry by entry in decreasing order, will be the product of the - // length of the diverging tails and the network round-trip latency, - // which can easily result in hours of time spent probing and can - // even cause outright outages. The probes are thus optimized as - // described below. - r.logger.Debugf("%x received MsgAppResp(rejected, hint: (index %d, term %d)) from %x for index %d", - r.id, m.RejectHint, m.LogTerm, m.From, m.Index) - nextProbeIdx := m.RejectHint - if m.LogTerm > 0 { - // If the follower has an uncommitted log tail, we would end up - // probing one by one until we hit the common prefix. - // - // For example, if the leader has: - // - // idx 1 2 3 4 5 6 7 8 9 - // ----------------- - // term (L) 1 3 3 3 5 5 5 5 5 - // term (F) 1 1 1 1 2 2 - // - // Then, after sending an append anchored at (idx=9,term=5) we - // would receive a RejectHint of 6 and LogTerm of 2. Without the - // code below, we would try an append at index 6, which would - // fail again. - // - // However, looking only at what the leader knows about its own - // log and the rejection hint, it is clear that a probe at index - // 6, 5, 4, 3, and 2 must fail as well: - // - // For all of these indexes, the leader's log term is larger than - // the rejection's log term. If a probe at one of these indexes - // succeeded, its log term at that index would match the leader's, - // i.e. 3 or 5 in this example. But the follower already told the - // leader that it is still at term 2 at index 9, and since the - // log term only ever goes up (within a log), this is a contradiction. - // - // At index 1, however, the leader can draw no such conclusion, - // as its term 1 is not larger than the term 2 from the - // follower's rejection. We thus probe at 1, which will succeed - // in this example. In general, with this approach we probe at - // most once per term found in the leader's log. - // - // There is a similar mechanism on the follower (implemented in - // handleAppendEntries via a call to findConflictByTerm) that is - // useful if the follower has a large divergent uncommitted log - // tail[1], as in this example: - // - // idx 1 2 3 4 5 6 7 8 9 - // ----------------- - // term (L) 1 3 3 3 3 3 3 3 7 - // term (F) 1 3 3 4 4 5 5 5 6 - // - // Naively, the leader would probe at idx=9, receive a rejection - // revealing the log term of 6 at the follower. Since the leader's - // term at the previous index is already smaller than 6, the leader- - // side optimization discussed above is ineffective. The leader thus - // probes at index 8 and, naively, receives a rejection for the same - // index and log term 5. Again, the leader optimization does not improve - // over linear probing as term 5 is above the leader's term 3 for that - // and many preceding indexes; the leader would have to probe linearly - // until it would finally hit index 3, where the probe would succeed. - // - // Instead, we apply a similar optimization on the follower. When the - // follower receives the probe at index 8 (log term 3), it concludes - // that all of the leader's log preceding that index has log terms of - // 3 or below. The largest index in the follower's log with a log term - // of 3 or below is index 3. The follower will thus return a rejection - // for index=3, log term=3 instead. The leader's next probe will then - // succeed at that index. - // - // [1]: more precisely, if the log terms in the large uncommitted - // tail on the follower are larger than the leader's. At first, - // it may seem unintuitive that a follower could even have such - // a large tail, but it can happen: - // - // 1. Leader appends (but does not commit) entries 2 and 3, crashes. - // idx 1 2 3 4 5 6 7 8 9 - // ----------------- - // term (L) 1 2 2 [crashes] - // term (F) 1 - // term (F) 1 - // - // 2. a follower becomes leader and appends entries at term 3. - // ----------------- - // term (x) 1 2 2 [down] - // term (F) 1 3 3 3 3 - // term (F) 1 - // - // 3. term 3 leader goes down, term 2 leader returns as term 4 - // leader. It commits the log & entries at term 4. - // - // ----------------- - // term (L) 1 2 2 2 - // term (x) 1 3 3 3 3 [down] - // term (F) 1 - // ----------------- - // term (L) 1 2 2 2 4 4 4 - // term (F) 1 3 3 3 3 [gets probed] - // term (F) 1 2 2 2 4 4 4 - // - // 4. the leader will now probe the returning follower at index - // 7, the rejection points it at the end of the follower's log - // which is at a higher log term than the actually committed - // log. - nextProbeIdx = r.raftLog.findConflictByTerm(m.RejectHint, m.LogTerm) - } - if pr.MaybeDecrTo(m.Index, nextProbeIdx) { - r.logger.Debugf("%x decreased progress of %x to [%s]", r.id, m.From, pr) - if pr.State == tracker.StateReplicate { - pr.BecomeProbe() - } - r.sendAppend(m.From) - } - } else { - oldPaused := pr.IsPaused() - if pr.MaybeUpdate(m.Index) { - switch { - case pr.State == tracker.StateProbe: - pr.BecomeReplicate() - case pr.State == tracker.StateSnapshot && pr.Match >= pr.PendingSnapshot: - // TODO(tbg): we should also enter this branch if a snapshot is - // received that is below pr.PendingSnapshot but which makes it - // possible to use the log again. - r.logger.Debugf("%x recovered from needing snapshot, resumed sending replication messages to %x [%s]", r.id, m.From, pr) - // Transition back to replicating state via probing state - // (which takes the snapshot into account). If we didn't - // move to replicating state, that would only happen with - // the next round of appends (but there may not be a next - // round for a while, exposing an inconsistent RaftStatus). - pr.BecomeProbe() - pr.BecomeReplicate() - case pr.State == tracker.StateReplicate: - pr.Inflights.FreeLE(m.Index) - } - - if r.maybeCommit() { - // committed index has progressed for the term, so it is safe - // to respond to pending read index requests - releasePendingReadIndexMessages(r) - r.bcastAppend() - } else if oldPaused { - // If we were paused before, this node may be missing the - // latest commit index, so send it. - r.sendAppend(m.From) - } - // We've updated flow control information above, which may - // allow us to send multiple (size-limited) in-flight messages - // at once (such as when transitioning from probe to - // replicate, or when freeTo() covers multiple messages). If - // we have more entries to send, send as many messages as we - // can (without sending empty messages for the commit index) - for r.maybeSendAppend(m.From, false) { - } - // Transfer leadership is in progress. - if m.From == r.leadTransferee && pr.Match == r.raftLog.lastIndex() { - r.logger.Infof("%x sent MsgTimeoutNow to %x after received MsgAppResp", r.id, m.From) - r.sendTimeoutNow(m.From) - } - } - } - case pb.MsgHeartbeatResp: - pr.RecentActive = true - pr.ProbeSent = false - - // free one slot for the full inflights window to allow progress. - if pr.State == tracker.StateReplicate && pr.Inflights.Full() { - pr.Inflights.FreeFirstOne() - } - if pr.Match < r.raftLog.lastIndex() { - r.sendAppend(m.From) - } - - if r.readOnly.option != ReadOnlySafe || len(m.Context) == 0 { - return nil - } - - if r.prs.Voters.VoteResult(r.readOnly.recvAck(m.From, m.Context)) != quorum.VoteWon { - return nil - } - - rss := r.readOnly.advance(m) - for _, rs := range rss { - if resp := r.responseToReadIndexReq(rs.req, rs.index); resp.To != None { - r.send(resp) - } - } - case pb.MsgSnapStatus: - if pr.State != tracker.StateSnapshot { - return nil - } - // TODO(tbg): this code is very similar to the snapshot handling in - // MsgAppResp above. In fact, the code there is more correct than the - // code here and should likely be updated to match (or even better, the - // logic pulled into a newly created Progress state machine handler). - if !m.Reject { - pr.BecomeProbe() - r.logger.Debugf("%x snapshot succeeded, resumed sending replication messages to %x [%s]", r.id, m.From, pr) - } else { - // NB: the order here matters or we'll be probing erroneously from - // the snapshot index, but the snapshot never applied. - pr.PendingSnapshot = 0 - pr.BecomeProbe() - r.logger.Debugf("%x snapshot failed, resumed sending replication messages to %x [%s]", r.id, m.From, pr) - } - // If snapshot finish, wait for the MsgAppResp from the remote node before sending - // out the next MsgApp. - // If snapshot failure, wait for a heartbeat interval before next try - pr.ProbeSent = true - case pb.MsgUnreachable: - // During optimistic replication, if the remote becomes unreachable, - // there is huge probability that a MsgApp is lost. - if pr.State == tracker.StateReplicate { - pr.BecomeProbe() - } - r.logger.Debugf("%x failed to send message to %x because it is unreachable [%s]", r.id, m.From, pr) - case pb.MsgTransferLeader: - if pr.IsLearner { - r.logger.Debugf("%x is learner. Ignored transferring leadership", r.id) - return nil - } - leadTransferee := m.From - lastLeadTransferee := r.leadTransferee - if lastLeadTransferee != None { - if lastLeadTransferee == leadTransferee { - r.logger.Infof("%x [term %d] transfer leadership to %x is in progress, ignores request to same node %x", - r.id, r.Term, leadTransferee, leadTransferee) - return nil - } - r.abortLeaderTransfer() - r.logger.Infof("%x [term %d] abort previous transferring leadership to %x", r.id, r.Term, lastLeadTransferee) - } - if leadTransferee == r.id { - r.logger.Debugf("%x is already leader. Ignored transferring leadership to self", r.id) - return nil - } - // Transfer leadership to third party. - r.logger.Infof("%x [term %d] starts to transfer leadership to %x", r.id, r.Term, leadTransferee) - // Transfer leadership should be finished in one electionTimeout, so reset r.electionElapsed. - r.electionElapsed = 0 - r.leadTransferee = leadTransferee - if pr.Match == r.raftLog.lastIndex() { - r.sendTimeoutNow(leadTransferee) - r.logger.Infof("%x sends MsgTimeoutNow to %x immediately as %x already has up-to-date log", r.id, leadTransferee, leadTransferee) - } else { - r.sendAppend(leadTransferee) - } - } - return nil -} - -// stepCandidate is shared by StateCandidate and StatePreCandidate; the difference is -// whether they respond to MsgVoteResp or MsgPreVoteResp. -func stepCandidate(r *raft, m pb.Message) error { - // Only handle vote responses corresponding to our candidacy (while in - // StateCandidate, we may get stale MsgPreVoteResp messages in this term from - // our pre-candidate state). - var myVoteRespType pb.MessageType - if r.state == StatePreCandidate { - myVoteRespType = pb.MsgPreVoteResp - } else { - myVoteRespType = pb.MsgVoteResp - } - switch m.Type { - case pb.MsgProp: - r.logger.Infof("%x no leader at term %d; dropping proposal", r.id, r.Term) - return ErrProposalDropped - case pb.MsgApp: - r.becomeFollower(m.Term, m.From) // always m.Term == r.Term - r.handleAppendEntries(m) - case pb.MsgHeartbeat: - r.becomeFollower(m.Term, m.From) // always m.Term == r.Term - r.handleHeartbeat(m) - case pb.MsgSnap: - r.becomeFollower(m.Term, m.From) // always m.Term == r.Term - r.handleSnapshot(m) - case myVoteRespType: - gr, rj, res := r.poll(m.From, m.Type, !m.Reject) - r.logger.Infof("%x has received %d %s votes and %d vote rejections", r.id, gr, m.Type, rj) - switch res { - case quorum.VoteWon: - if r.state == StatePreCandidate { - r.campaign(campaignElection) - } else { - r.becomeLeader() - r.bcastAppend() - } - case quorum.VoteLost: - // pb.MsgPreVoteResp contains future term of pre-candidate - // m.Term > r.Term; reuse r.Term - r.becomeFollower(r.Term, None) - } - case pb.MsgTimeoutNow: - r.logger.Debugf("%x [term %d state %v] ignored MsgTimeoutNow from %x", r.id, r.Term, r.state, m.From) - } - return nil -} - -func stepFollower(r *raft, m pb.Message) error { - switch m.Type { - case pb.MsgProp: - if r.lead == None { - r.logger.Infof("%x no leader at term %d; dropping proposal", r.id, r.Term) - return ErrProposalDropped - } else if r.disableProposalForwarding { - r.logger.Infof("%x not forwarding to leader %x at term %d; dropping proposal", r.id, r.lead, r.Term) - return ErrProposalDropped - } - m.To = r.lead - r.send(m) - case pb.MsgApp: - r.electionElapsed = 0 - r.lead = m.From - r.handleAppendEntries(m) - case pb.MsgHeartbeat: - r.electionElapsed = 0 - r.lead = m.From - r.handleHeartbeat(m) - case pb.MsgSnap: - r.electionElapsed = 0 - r.lead = m.From - r.handleSnapshot(m) - case pb.MsgTransferLeader: - if r.lead == None { - r.logger.Infof("%x no leader at term %d; dropping leader transfer msg", r.id, r.Term) - return nil - } - m.To = r.lead - r.send(m) - case pb.MsgTimeoutNow: - r.logger.Infof("%x [term %d] received MsgTimeoutNow from %x and starts an election to get leadership.", r.id, r.Term, m.From) - // Leadership transfers never use pre-vote even if r.preVote is true; we - // know we are not recovering from a partition so there is no need for the - // extra round trip. - r.hup(campaignTransfer) - case pb.MsgReadIndex: - if r.lead == None { - r.logger.Infof("%x no leader at term %d; dropping index reading msg", r.id, r.Term) - return nil - } - m.To = r.lead - r.send(m) - case pb.MsgReadIndexResp: - if len(m.Entries) != 1 { - r.logger.Errorf("%x invalid format of MsgReadIndexResp from %x, entries count: %d", r.id, m.From, len(m.Entries)) - return nil - } - r.readStates = append(r.readStates, ReadState{Index: m.Index, RequestCtx: m.Entries[0].Data}) - } - return nil -} - -func (r *raft) handleAppendEntries(m pb.Message) { - if m.Index < r.raftLog.committed { - r.send(pb.Message{To: m.From, Type: pb.MsgAppResp, Index: r.raftLog.committed}) - return - } - - if mlastIndex, ok := r.raftLog.maybeAppend(m.Index, m.LogTerm, m.Commit, m.Entries...); ok { - r.send(pb.Message{To: m.From, Type: pb.MsgAppResp, Index: mlastIndex}) - } else { - r.logger.Debugf("%x [logterm: %d, index: %d] rejected MsgApp [logterm: %d, index: %d] from %x", - r.id, r.raftLog.zeroTermOnErrCompacted(r.raftLog.term(m.Index)), m.Index, m.LogTerm, m.Index, m.From) - - // Return a hint to the leader about the maximum index and term that the - // two logs could be divergent at. Do this by searching through the - // follower's log for the maximum (index, term) pair with a term <= the - // MsgApp's LogTerm and an index <= the MsgApp's Index. This can help - // skip all indexes in the follower's uncommitted tail with terms - // greater than the MsgApp's LogTerm. - // - // See the other caller for findConflictByTerm (in stepLeader) for a much - // more detailed explanation of this mechanism. - hintIndex := min(m.Index, r.raftLog.lastIndex()) - hintIndex = r.raftLog.findConflictByTerm(hintIndex, m.LogTerm) - hintTerm, err := r.raftLog.term(hintIndex) - if err != nil { - panic(fmt.Sprintf("term(%d) must be valid, but got %v", hintIndex, err)) - } - r.send(pb.Message{ - To: m.From, - Type: pb.MsgAppResp, - Index: m.Index, - Reject: true, - RejectHint: hintIndex, - LogTerm: hintTerm, - }) - } -} - -func (r *raft) handleHeartbeat(m pb.Message) { - r.raftLog.commitTo(m.Commit) - r.send(pb.Message{To: m.From, Type: pb.MsgHeartbeatResp, Context: m.Context}) -} - -func (r *raft) handleSnapshot(m pb.Message) { - sindex, sterm := m.Snapshot.Metadata.Index, m.Snapshot.Metadata.Term - if r.restore(m.Snapshot) { - r.logger.Infof("%x [commit: %d] restored snapshot [index: %d, term: %d]", - r.id, r.raftLog.committed, sindex, sterm) - r.send(pb.Message{To: m.From, Type: pb.MsgAppResp, Index: r.raftLog.lastIndex()}) - } else { - r.logger.Infof("%x [commit: %d] ignored snapshot [index: %d, term: %d]", - r.id, r.raftLog.committed, sindex, sterm) - r.send(pb.Message{To: m.From, Type: pb.MsgAppResp, Index: r.raftLog.committed}) - } -} - -// restore recovers the state machine from a snapshot. It restores the log and the -// configuration of state machine. If this method returns false, the snapshot was -// ignored, either because it was obsolete or because of an error. -func (r *raft) restore(s pb.Snapshot) bool { - if s.Metadata.Index <= r.raftLog.committed { - return false - } - if r.state != StateFollower { - // This is defense-in-depth: if the leader somehow ended up applying a - // snapshot, it could move into a new term without moving into a - // follower state. This should never fire, but if it did, we'd have - // prevented damage by returning early, so log only a loud warning. - // - // At the time of writing, the instance is guaranteed to be in follower - // state when this method is called. - r.logger.Warningf("%x attempted to restore snapshot as leader; should never happen", r.id) - r.becomeFollower(r.Term+1, None) - return false - } - - // More defense-in-depth: throw away snapshot if recipient is not in the - // config. This shouldn't ever happen (at the time of writing) but lots of - // code here and there assumes that r.id is in the progress tracker. - found := false - cs := s.Metadata.ConfState - - for _, set := range [][]uint64{ - cs.Voters, - cs.Learners, - cs.VotersOutgoing, - // `LearnersNext` doesn't need to be checked. According to the rules, if a peer in - // `LearnersNext`, it has to be in `VotersOutgoing`. - } { - for _, id := range set { - if id == r.id { - found = true - break - } - } - if found { - break - } - } - if !found { - r.logger.Warningf( - "%x attempted to restore snapshot but it is not in the ConfState %v; should never happen", - r.id, cs, - ) - return false - } - - // Now go ahead and actually restore. - - if r.raftLog.matchTerm(s.Metadata.Index, s.Metadata.Term) { - r.logger.Infof("%x [commit: %d, lastindex: %d, lastterm: %d] fast-forwarded commit to snapshot [index: %d, term: %d]", - r.id, r.raftLog.committed, r.raftLog.lastIndex(), r.raftLog.lastTerm(), s.Metadata.Index, s.Metadata.Term) - r.raftLog.commitTo(s.Metadata.Index) - return false - } - - r.raftLog.restore(s) - - // Reset the configuration and add the (potentially updated) peers in anew. - r.prs = tracker.MakeProgressTracker(r.prs.MaxInflight) - cfg, prs, err := confchange.Restore(confchange.Changer{ - Tracker: r.prs, - LastIndex: r.raftLog.lastIndex(), - }, cs) - - if err != nil { - // This should never happen. Either there's a bug in our config change - // handling or the client corrupted the conf change. - panic(fmt.Sprintf("unable to restore config %+v: %s", cs, err)) - } - - assertConfStatesEquivalent(r.logger, cs, r.switchToConfig(cfg, prs)) - - pr := r.prs.Progress[r.id] - pr.MaybeUpdate(pr.Next - 1) // TODO(tbg): this is untested and likely unneeded - - r.logger.Infof("%x [commit: %d, lastindex: %d, lastterm: %d] restored snapshot [index: %d, term: %d]", - r.id, r.raftLog.committed, r.raftLog.lastIndex(), r.raftLog.lastTerm(), s.Metadata.Index, s.Metadata.Term) - return true -} - -// promotable indicates whether state machine can be promoted to leader, -// which is true when its own id is in progress list. -func (r *raft) promotable() bool { - pr := r.prs.Progress[r.id] - return pr != nil && !pr.IsLearner && !r.raftLog.hasPendingSnapshot() -} - -func (r *raft) applyConfChange(cc pb.ConfChangeV2) pb.ConfState { - cfg, prs, err := func() (tracker.Config, tracker.ProgressMap, error) { - changer := confchange.Changer{ - Tracker: r.prs, - LastIndex: r.raftLog.lastIndex(), - } - if cc.LeaveJoint() { - return changer.LeaveJoint() - } else if autoLeave, ok := cc.EnterJoint(); ok { - return changer.EnterJoint(autoLeave, cc.Changes...) - } - return changer.Simple(cc.Changes...) - }() - - if err != nil { - // TODO(tbg): return the error to the caller. - panic(err) - } - - return r.switchToConfig(cfg, prs) -} - -// switchToConfig reconfigures this node to use the provided configuration. It -// updates the in-memory state and, when necessary, carries out additional -// actions such as reacting to the removal of nodes or changed quorum -// requirements. -// -// The inputs usually result from restoring a ConfState or applying a ConfChange. -func (r *raft) switchToConfig(cfg tracker.Config, prs tracker.ProgressMap) pb.ConfState { - r.prs.Config = cfg - r.prs.Progress = prs - - r.logger.Infof("%x switched to configuration %s", r.id, r.prs.Config) - cs := r.prs.ConfState() - pr, ok := r.prs.Progress[r.id] - - // Update whether the node itself is a learner, resetting to false when the - // node is removed. - r.isLearner = ok && pr.IsLearner - - if (!ok || r.isLearner) && r.state == StateLeader { - // This node is leader and was removed or demoted. We prevent demotions - // at the time writing but hypothetically we handle them the same way as - // removing the leader: stepping down into the next Term. - // - // TODO(tbg): step down (for sanity) and ask follower with largest Match - // to TimeoutNow (to avoid interruption). This might still drop some - // proposals but it's better than nothing. - // - // TODO(tbg): test this branch. It is untested at the time of writing. - return cs - } - - // The remaining steps only make sense if this node is the leader and there - // are other nodes. - if r.state != StateLeader || len(cs.Voters) == 0 { - return cs - } - - if r.maybeCommit() { - // If the configuration change means that more entries are committed now, - // broadcast/append to everyone in the updated config. - r.bcastAppend() - } else { - // Otherwise, still probe the newly added replicas; there's no reason to - // let them wait out a heartbeat interval (or the next incoming - // proposal). - r.prs.Visit(func(id uint64, pr *tracker.Progress) { - r.maybeSendAppend(id, false /* sendIfEmpty */) - }) - } - // If the the leadTransferee was removed or demoted, abort the leadership transfer. - if _, tOK := r.prs.Config.Voters.IDs()[r.leadTransferee]; !tOK && r.leadTransferee != 0 { - r.abortLeaderTransfer() - } - - return cs -} - -func (r *raft) loadState(state pb.HardState) { - if state.Commit < r.raftLog.committed || state.Commit > r.raftLog.lastIndex() { - r.logger.Panicf("%x state.commit %d is out of range [%d, %d]", r.id, state.Commit, r.raftLog.committed, r.raftLog.lastIndex()) - } - r.raftLog.committed = state.Commit - r.Term = state.Term - r.Vote = state.Vote -} - -// pastElectionTimeout returns true iff r.electionElapsed is greater -// than or equal to the randomized election timeout in -// [electiontimeout, 2 * electiontimeout - 1]. -func (r *raft) pastElectionTimeout() bool { - return r.electionElapsed >= r.randomizedElectionTimeout -} - -func (r *raft) resetRandomizedElectionTimeout() { - r.randomizedElectionTimeout = r.electionTimeout + globalRand.Intn(r.electionTimeout) -} - -func (r *raft) sendTimeoutNow(to uint64) { - r.send(pb.Message{To: to, Type: pb.MsgTimeoutNow}) -} - -func (r *raft) abortLeaderTransfer() { - r.leadTransferee = None -} - -// committedEntryInCurrentTerm return true if the peer has committed an entry in its term. -func (r *raft) committedEntryInCurrentTerm() bool { - return r.raftLog.zeroTermOnErrCompacted(r.raftLog.term(r.raftLog.committed)) == r.Term -} - -// responseToReadIndexReq constructs a response for `req`. If `req` comes from the peer -// itself, a blank value will be returned. -func (r *raft) responseToReadIndexReq(req pb.Message, readIndex uint64) pb.Message { - if req.From == None || req.From == r.id { - r.readStates = append(r.readStates, ReadState{ - Index: readIndex, - RequestCtx: req.Entries[0].Data, - }) - return pb.Message{} - } - return pb.Message{ - Type: pb.MsgReadIndexResp, - To: req.From, - Index: readIndex, - Entries: req.Entries, - } -} - -// increaseUncommittedSize computes the size of the proposed entries and -// determines whether they would push leader over its maxUncommittedSize limit. -// If the new entries would exceed the limit, the method returns false. If not, -// the increase in uncommitted entry size is recorded and the method returns -// true. -// -// Empty payloads are never refused. This is used both for appending an empty -// entry at a new leader's term, as well as leaving a joint configuration. -func (r *raft) increaseUncommittedSize(ents []pb.Entry) bool { - var s uint64 - for _, e := range ents { - s += uint64(PayloadSize(e)) - } - - if r.uncommittedSize > 0 && s > 0 && r.uncommittedSize+s > r.maxUncommittedSize { - // If the uncommitted tail of the Raft log is empty, allow any size - // proposal. Otherwise, limit the size of the uncommitted tail of the - // log and drop any proposal that would push the size over the limit. - // Note the added requirement s>0 which is used to make sure that - // appending single empty entries to the log always succeeds, used both - // for replicating a new leader's initial empty entry, and for - // auto-leaving joint configurations. - return false - } - r.uncommittedSize += s - return true -} - -// reduceUncommittedSize accounts for the newly committed entries by decreasing -// the uncommitted entry size limit. -func (r *raft) reduceUncommittedSize(ents []pb.Entry) { - if r.uncommittedSize == 0 { - // Fast-path for followers, who do not track or enforce the limit. - return - } - - var s uint64 - for _, e := range ents { - s += uint64(PayloadSize(e)) - } - if s > r.uncommittedSize { - // uncommittedSize may underestimate the size of the uncommitted Raft - // log tail but will never overestimate it. Saturate at 0 instead of - // allowing overflow. - r.uncommittedSize = 0 - } else { - r.uncommittedSize -= s - } -} - -func numOfPendingConf(ents []pb.Entry) int { - n := 0 - for i := range ents { - if ents[i].Type == pb.EntryConfChange || ents[i].Type == pb.EntryConfChangeV2 { - n++ - } - } - return n -} - -func releasePendingReadIndexMessages(r *raft) { - if !r.committedEntryInCurrentTerm() { - r.logger.Error("pending MsgReadIndex should be released only after first commit in current term") - return - } - - msgs := r.pendingReadIndexMessages - r.pendingReadIndexMessages = nil - - for _, m := range msgs { - sendMsgReadIndexResponse(r, m) - } -} - -func sendMsgReadIndexResponse(r *raft, m pb.Message) { - // thinking: use an internally defined context instead of the user given context. - // We can express this in terms of the term and index instead of a user-supplied value. - // This would allow multiple reads to piggyback on the same message. - switch r.readOnly.option { - // If more than the local vote is needed, go through a full broadcast. - case ReadOnlySafe: - r.readOnly.addRequest(r.raftLog.committed, m) - // The local node automatically acks the request. - r.readOnly.recvAck(r.id, m.Entries[0].Data) - r.bcastHeartbeatWithCtx(m.Entries[0].Data) - case ReadOnlyLeaseBased: - if resp := r.responseToReadIndexReq(m, r.raftLog.committed); resp.To != None { - r.send(resp) - } - } -} diff --git a/vendor/go.etcd.io/etcd/raft/v3/raftpb/confchange.go b/vendor/go.etcd.io/etcd/raft/v3/raftpb/confchange.go deleted file mode 100644 index 47fae65dfe..0000000000 --- a/vendor/go.etcd.io/etcd/raft/v3/raftpb/confchange.go +++ /dev/null @@ -1,170 +0,0 @@ -// Copyright 2019 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package raftpb - -import ( - "fmt" - "strconv" - "strings" - - "github.com/gogo/protobuf/proto" -) - -// ConfChangeI abstracts over ConfChangeV2 and (legacy) ConfChange to allow -// treating them in a unified manner. -type ConfChangeI interface { - AsV2() ConfChangeV2 - AsV1() (ConfChange, bool) -} - -// MarshalConfChange calls Marshal on the underlying ConfChange or ConfChangeV2 -// and returns the result along with the corresponding EntryType. -func MarshalConfChange(c ConfChangeI) (EntryType, []byte, error) { - var typ EntryType - var ccdata []byte - var err error - if ccv1, ok := c.AsV1(); ok { - typ = EntryConfChange - ccdata, err = ccv1.Marshal() - } else { - ccv2 := c.AsV2() - typ = EntryConfChangeV2 - ccdata, err = ccv2.Marshal() - } - return typ, ccdata, err -} - -// AsV2 returns a V2 configuration change carrying out the same operation. -func (c ConfChange) AsV2() ConfChangeV2 { - return ConfChangeV2{ - Changes: []ConfChangeSingle{{ - Type: c.Type, - NodeID: c.NodeID, - }}, - Context: c.Context, - } -} - -// AsV1 returns the ConfChange and true. -func (c ConfChange) AsV1() (ConfChange, bool) { - return c, true -} - -// AsV2 is the identity. -func (c ConfChangeV2) AsV2() ConfChangeV2 { return c } - -// AsV1 returns ConfChange{} and false. -func (c ConfChangeV2) AsV1() (ConfChange, bool) { return ConfChange{}, false } - -// EnterJoint returns two bools. The second bool is true if and only if this -// config change will use Joint Consensus, which is the case if it contains more -// than one change or if the use of Joint Consensus was requested explicitly. -// The first bool can only be true if second one is, and indicates whether the -// Joint State will be left automatically. -func (c ConfChangeV2) EnterJoint() (autoLeave bool, ok bool) { - // NB: in theory, more config changes could qualify for the "simple" - // protocol but it depends on the config on top of which the changes apply. - // For example, adding two learners is not OK if both nodes are part of the - // base config (i.e. two voters are turned into learners in the process of - // applying the conf change). In practice, these distinctions should not - // matter, so we keep it simple and use Joint Consensus liberally. - if c.Transition != ConfChangeTransitionAuto || len(c.Changes) > 1 { - // Use Joint Consensus. - var autoLeave bool - switch c.Transition { - case ConfChangeTransitionAuto: - autoLeave = true - case ConfChangeTransitionJointImplicit: - autoLeave = true - case ConfChangeTransitionJointExplicit: - default: - panic(fmt.Sprintf("unknown transition: %+v", c)) - } - return autoLeave, true - } - return false, false -} - -// LeaveJoint is true if the configuration change leaves a joint configuration. -// This is the case if the ConfChangeV2 is zero, with the possible exception of -// the Context field. -func (c ConfChangeV2) LeaveJoint() bool { - // NB: c is already a copy. - c.Context = nil - return proto.Equal(&c, &ConfChangeV2{}) -} - -// ConfChangesFromString parses a Space-delimited sequence of operations into a -// slice of ConfChangeSingle. The supported operations are: -// - vn: make n a voter, -// - ln: make n a learner, -// - rn: remove n, and -// - un: update n. -func ConfChangesFromString(s string) ([]ConfChangeSingle, error) { - var ccs []ConfChangeSingle - toks := strings.Split(strings.TrimSpace(s), " ") - if toks[0] == "" { - toks = nil - } - for _, tok := range toks { - if len(tok) < 2 { - return nil, fmt.Errorf("unknown token %s", tok) - } - var cc ConfChangeSingle - switch tok[0] { - case 'v': - cc.Type = ConfChangeAddNode - case 'l': - cc.Type = ConfChangeAddLearnerNode - case 'r': - cc.Type = ConfChangeRemoveNode - case 'u': - cc.Type = ConfChangeUpdateNode - default: - return nil, fmt.Errorf("unknown input: %s", tok) - } - id, err := strconv.ParseUint(tok[1:], 10, 64) - if err != nil { - return nil, err - } - cc.NodeID = id - ccs = append(ccs, cc) - } - return ccs, nil -} - -// ConfChangesToString is the inverse to ConfChangesFromString. -func ConfChangesToString(ccs []ConfChangeSingle) string { - var buf strings.Builder - for i, cc := range ccs { - if i > 0 { - buf.WriteByte(' ') - } - switch cc.Type { - case ConfChangeAddNode: - buf.WriteByte('v') - case ConfChangeAddLearnerNode: - buf.WriteByte('l') - case ConfChangeRemoveNode: - buf.WriteByte('r') - case ConfChangeUpdateNode: - buf.WriteByte('u') - default: - buf.WriteString("unknown") - } - fmt.Fprintf(&buf, "%d", cc.NodeID) - } - return buf.String() -} diff --git a/vendor/go.etcd.io/etcd/raft/v3/raftpb/confstate.go b/vendor/go.etcd.io/etcd/raft/v3/raftpb/confstate.go deleted file mode 100644 index 39b9dd7000..0000000000 --- a/vendor/go.etcd.io/etcd/raft/v3/raftpb/confstate.go +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright 2019 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package raftpb - -import ( - "fmt" - "reflect" - "sort" -) - -// Equivalent returns a nil error if the inputs describe the same configuration. -// On mismatch, returns a descriptive error showing the differences. -func (cs ConfState) Equivalent(cs2 ConfState) error { - cs1 := cs - orig1, orig2 := cs1, cs2 - s := func(sl *[]uint64) { - *sl = append([]uint64(nil), *sl...) - sort.Slice(*sl, func(i, j int) bool { return (*sl)[i] < (*sl)[j] }) - } - - for _, cs := range []*ConfState{&cs1, &cs2} { - s(&cs.Voters) - s(&cs.Learners) - s(&cs.VotersOutgoing) - s(&cs.LearnersNext) - } - - if !reflect.DeepEqual(cs1, cs2) { - return fmt.Errorf("ConfStates not equivalent after sorting:\n%+#v\n%+#v\nInputs were:\n%+#v\n%+#v", cs1, cs2, orig1, orig2) - } - return nil -} diff --git a/vendor/go.etcd.io/etcd/raft/v3/raftpb/raft.pb.go b/vendor/go.etcd.io/etcd/raft/v3/raftpb/raft.pb.go deleted file mode 100644 index 1ee77a9a45..0000000000 --- a/vendor/go.etcd.io/etcd/raft/v3/raftpb/raft.pb.go +++ /dev/null @@ -1,2988 +0,0 @@ -// Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: raft.proto - -package raftpb - -import ( - fmt "fmt" - io "io" - math "math" - math_bits "math/bits" - - _ "github.com/gogo/protobuf/gogoproto" - proto "github.com/golang/protobuf/proto" -) - -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package - -type EntryType int32 - -const ( - EntryNormal EntryType = 0 - EntryConfChange EntryType = 1 - EntryConfChangeV2 EntryType = 2 -) - -var EntryType_name = map[int32]string{ - 0: "EntryNormal", - 1: "EntryConfChange", - 2: "EntryConfChangeV2", -} - -var EntryType_value = map[string]int32{ - "EntryNormal": 0, - "EntryConfChange": 1, - "EntryConfChangeV2": 2, -} - -func (x EntryType) Enum() *EntryType { - p := new(EntryType) - *p = x - return p -} - -func (x EntryType) String() string { - return proto.EnumName(EntryType_name, int32(x)) -} - -func (x *EntryType) UnmarshalJSON(data []byte) error { - value, err := proto.UnmarshalJSONEnum(EntryType_value, data, "EntryType") - if err != nil { - return err - } - *x = EntryType(value) - return nil -} - -func (EntryType) EnumDescriptor() ([]byte, []int) { - return fileDescriptor_b042552c306ae59b, []int{0} -} - -// For description of different message types, see: -// https://pkg.go.dev/go.etcd.io/etcd/raft/v3#hdr-MessageType -type MessageType int32 - -const ( - MsgHup MessageType = 0 - MsgBeat MessageType = 1 - MsgProp MessageType = 2 - MsgApp MessageType = 3 - MsgAppResp MessageType = 4 - MsgVote MessageType = 5 - MsgVoteResp MessageType = 6 - MsgSnap MessageType = 7 - MsgHeartbeat MessageType = 8 - MsgHeartbeatResp MessageType = 9 - MsgUnreachable MessageType = 10 - MsgSnapStatus MessageType = 11 - MsgCheckQuorum MessageType = 12 - MsgTransferLeader MessageType = 13 - MsgTimeoutNow MessageType = 14 - MsgReadIndex MessageType = 15 - MsgReadIndexResp MessageType = 16 - MsgPreVote MessageType = 17 - MsgPreVoteResp MessageType = 18 -) - -var MessageType_name = map[int32]string{ - 0: "MsgHup", - 1: "MsgBeat", - 2: "MsgProp", - 3: "MsgApp", - 4: "MsgAppResp", - 5: "MsgVote", - 6: "MsgVoteResp", - 7: "MsgSnap", - 8: "MsgHeartbeat", - 9: "MsgHeartbeatResp", - 10: "MsgUnreachable", - 11: "MsgSnapStatus", - 12: "MsgCheckQuorum", - 13: "MsgTransferLeader", - 14: "MsgTimeoutNow", - 15: "MsgReadIndex", - 16: "MsgReadIndexResp", - 17: "MsgPreVote", - 18: "MsgPreVoteResp", -} - -var MessageType_value = map[string]int32{ - "MsgHup": 0, - "MsgBeat": 1, - "MsgProp": 2, - "MsgApp": 3, - "MsgAppResp": 4, - "MsgVote": 5, - "MsgVoteResp": 6, - "MsgSnap": 7, - "MsgHeartbeat": 8, - "MsgHeartbeatResp": 9, - "MsgUnreachable": 10, - "MsgSnapStatus": 11, - "MsgCheckQuorum": 12, - "MsgTransferLeader": 13, - "MsgTimeoutNow": 14, - "MsgReadIndex": 15, - "MsgReadIndexResp": 16, - "MsgPreVote": 17, - "MsgPreVoteResp": 18, -} - -func (x MessageType) Enum() *MessageType { - p := new(MessageType) - *p = x - return p -} - -func (x MessageType) String() string { - return proto.EnumName(MessageType_name, int32(x)) -} - -func (x *MessageType) UnmarshalJSON(data []byte) error { - value, err := proto.UnmarshalJSONEnum(MessageType_value, data, "MessageType") - if err != nil { - return err - } - *x = MessageType(value) - return nil -} - -func (MessageType) EnumDescriptor() ([]byte, []int) { - return fileDescriptor_b042552c306ae59b, []int{1} -} - -// ConfChangeTransition specifies the behavior of a configuration change with -// respect to joint consensus. -type ConfChangeTransition int32 - -const ( - // Automatically use the simple protocol if possible, otherwise fall back - // to ConfChangeJointImplicit. Most applications will want to use this. - ConfChangeTransitionAuto ConfChangeTransition = 0 - // Use joint consensus unconditionally, and transition out of them - // automatically (by proposing a zero configuration change). - // - // This option is suitable for applications that want to minimize the time - // spent in the joint configuration and do not store the joint configuration - // in the state machine (outside of InitialState). - ConfChangeTransitionJointImplicit ConfChangeTransition = 1 - // Use joint consensus and remain in the joint configuration until the - // application proposes a no-op configuration change. This is suitable for - // applications that want to explicitly control the transitions, for example - // to use a custom payload (via the Context field). - ConfChangeTransitionJointExplicit ConfChangeTransition = 2 -) - -var ConfChangeTransition_name = map[int32]string{ - 0: "ConfChangeTransitionAuto", - 1: "ConfChangeTransitionJointImplicit", - 2: "ConfChangeTransitionJointExplicit", -} - -var ConfChangeTransition_value = map[string]int32{ - "ConfChangeTransitionAuto": 0, - "ConfChangeTransitionJointImplicit": 1, - "ConfChangeTransitionJointExplicit": 2, -} - -func (x ConfChangeTransition) Enum() *ConfChangeTransition { - p := new(ConfChangeTransition) - *p = x - return p -} - -func (x ConfChangeTransition) String() string { - return proto.EnumName(ConfChangeTransition_name, int32(x)) -} - -func (x *ConfChangeTransition) UnmarshalJSON(data []byte) error { - value, err := proto.UnmarshalJSONEnum(ConfChangeTransition_value, data, "ConfChangeTransition") - if err != nil { - return err - } - *x = ConfChangeTransition(value) - return nil -} - -func (ConfChangeTransition) EnumDescriptor() ([]byte, []int) { - return fileDescriptor_b042552c306ae59b, []int{2} -} - -type ConfChangeType int32 - -const ( - ConfChangeAddNode ConfChangeType = 0 - ConfChangeRemoveNode ConfChangeType = 1 - ConfChangeUpdateNode ConfChangeType = 2 - ConfChangeAddLearnerNode ConfChangeType = 3 -) - -var ConfChangeType_name = map[int32]string{ - 0: "ConfChangeAddNode", - 1: "ConfChangeRemoveNode", - 2: "ConfChangeUpdateNode", - 3: "ConfChangeAddLearnerNode", -} - -var ConfChangeType_value = map[string]int32{ - "ConfChangeAddNode": 0, - "ConfChangeRemoveNode": 1, - "ConfChangeUpdateNode": 2, - "ConfChangeAddLearnerNode": 3, -} - -func (x ConfChangeType) Enum() *ConfChangeType { - p := new(ConfChangeType) - *p = x - return p -} - -func (x ConfChangeType) String() string { - return proto.EnumName(ConfChangeType_name, int32(x)) -} - -func (x *ConfChangeType) UnmarshalJSON(data []byte) error { - value, err := proto.UnmarshalJSONEnum(ConfChangeType_value, data, "ConfChangeType") - if err != nil { - return err - } - *x = ConfChangeType(value) - return nil -} - -func (ConfChangeType) EnumDescriptor() ([]byte, []int) { - return fileDescriptor_b042552c306ae59b, []int{3} -} - -type Entry struct { - Term uint64 `protobuf:"varint,2,opt,name=Term" json:"Term"` - Index uint64 `protobuf:"varint,3,opt,name=Index" json:"Index"` - Type EntryType `protobuf:"varint,1,opt,name=Type,enum=raftpb.EntryType" json:"Type"` - Data []byte `protobuf:"bytes,4,opt,name=Data" json:"Data,omitempty"` -} - -func (m *Entry) Reset() { *m = Entry{} } -func (m *Entry) String() string { return proto.CompactTextString(m) } -func (*Entry) ProtoMessage() {} -func (*Entry) Descriptor() ([]byte, []int) { - return fileDescriptor_b042552c306ae59b, []int{0} -} -func (m *Entry) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *Entry) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_Entry.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *Entry) XXX_Merge(src proto.Message) { - xxx_messageInfo_Entry.Merge(m, src) -} -func (m *Entry) XXX_Size() int { - return m.Size() -} -func (m *Entry) XXX_DiscardUnknown() { - xxx_messageInfo_Entry.DiscardUnknown(m) -} - -var xxx_messageInfo_Entry proto.InternalMessageInfo - -type SnapshotMetadata struct { - ConfState ConfState `protobuf:"bytes,1,opt,name=conf_state,json=confState" json:"conf_state"` - Index uint64 `protobuf:"varint,2,opt,name=index" json:"index"` - Term uint64 `protobuf:"varint,3,opt,name=term" json:"term"` -} - -func (m *SnapshotMetadata) Reset() { *m = SnapshotMetadata{} } -func (m *SnapshotMetadata) String() string { return proto.CompactTextString(m) } -func (*SnapshotMetadata) ProtoMessage() {} -func (*SnapshotMetadata) Descriptor() ([]byte, []int) { - return fileDescriptor_b042552c306ae59b, []int{1} -} -func (m *SnapshotMetadata) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *SnapshotMetadata) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_SnapshotMetadata.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *SnapshotMetadata) XXX_Merge(src proto.Message) { - xxx_messageInfo_SnapshotMetadata.Merge(m, src) -} -func (m *SnapshotMetadata) XXX_Size() int { - return m.Size() -} -func (m *SnapshotMetadata) XXX_DiscardUnknown() { - xxx_messageInfo_SnapshotMetadata.DiscardUnknown(m) -} - -var xxx_messageInfo_SnapshotMetadata proto.InternalMessageInfo - -type Snapshot struct { - Data []byte `protobuf:"bytes,1,opt,name=data" json:"data,omitempty"` - Metadata SnapshotMetadata `protobuf:"bytes,2,opt,name=metadata" json:"metadata"` -} - -func (m *Snapshot) Reset() { *m = Snapshot{} } -func (m *Snapshot) String() string { return proto.CompactTextString(m) } -func (*Snapshot) ProtoMessage() {} -func (*Snapshot) Descriptor() ([]byte, []int) { - return fileDescriptor_b042552c306ae59b, []int{2} -} -func (m *Snapshot) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *Snapshot) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_Snapshot.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *Snapshot) XXX_Merge(src proto.Message) { - xxx_messageInfo_Snapshot.Merge(m, src) -} -func (m *Snapshot) XXX_Size() int { - return m.Size() -} -func (m *Snapshot) XXX_DiscardUnknown() { - xxx_messageInfo_Snapshot.DiscardUnknown(m) -} - -var xxx_messageInfo_Snapshot proto.InternalMessageInfo - -type Message struct { - Type MessageType `protobuf:"varint,1,opt,name=type,enum=raftpb.MessageType" json:"type"` - To uint64 `protobuf:"varint,2,opt,name=to" json:"to"` - From uint64 `protobuf:"varint,3,opt,name=from" json:"from"` - Term uint64 `protobuf:"varint,4,opt,name=term" json:"term"` - // logTerm is generally used for appending Raft logs to followers. For example, - // (type=MsgApp,index=100,logTerm=5) means leader appends entries starting at - // index=101, and the term of entry at index 100 is 5. - // (type=MsgAppResp,reject=true,index=100,logTerm=5) means follower rejects some - // entries from its leader as it already has an entry with term 5 at index 100. - LogTerm uint64 `protobuf:"varint,5,opt,name=logTerm" json:"logTerm"` - Index uint64 `protobuf:"varint,6,opt,name=index" json:"index"` - Entries []Entry `protobuf:"bytes,7,rep,name=entries" json:"entries"` - Commit uint64 `protobuf:"varint,8,opt,name=commit" json:"commit"` - Snapshot Snapshot `protobuf:"bytes,9,opt,name=snapshot" json:"snapshot"` - Reject bool `protobuf:"varint,10,opt,name=reject" json:"reject"` - RejectHint uint64 `protobuf:"varint,11,opt,name=rejectHint" json:"rejectHint"` - Context []byte `protobuf:"bytes,12,opt,name=context" json:"context,omitempty"` -} - -func (m *Message) Reset() { *m = Message{} } -func (m *Message) String() string { return proto.CompactTextString(m) } -func (*Message) ProtoMessage() {} -func (*Message) Descriptor() ([]byte, []int) { - return fileDescriptor_b042552c306ae59b, []int{3} -} -func (m *Message) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *Message) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_Message.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *Message) XXX_Merge(src proto.Message) { - xxx_messageInfo_Message.Merge(m, src) -} -func (m *Message) XXX_Size() int { - return m.Size() -} -func (m *Message) XXX_DiscardUnknown() { - xxx_messageInfo_Message.DiscardUnknown(m) -} - -var xxx_messageInfo_Message proto.InternalMessageInfo - -type HardState struct { - Term uint64 `protobuf:"varint,1,opt,name=term" json:"term"` - Vote uint64 `protobuf:"varint,2,opt,name=vote" json:"vote"` - Commit uint64 `protobuf:"varint,3,opt,name=commit" json:"commit"` -} - -func (m *HardState) Reset() { *m = HardState{} } -func (m *HardState) String() string { return proto.CompactTextString(m) } -func (*HardState) ProtoMessage() {} -func (*HardState) Descriptor() ([]byte, []int) { - return fileDescriptor_b042552c306ae59b, []int{4} -} -func (m *HardState) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *HardState) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_HardState.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *HardState) XXX_Merge(src proto.Message) { - xxx_messageInfo_HardState.Merge(m, src) -} -func (m *HardState) XXX_Size() int { - return m.Size() -} -func (m *HardState) XXX_DiscardUnknown() { - xxx_messageInfo_HardState.DiscardUnknown(m) -} - -var xxx_messageInfo_HardState proto.InternalMessageInfo - -type ConfState struct { - // The voters in the incoming config. (If the configuration is not joint, - // then the outgoing config is empty). - Voters []uint64 `protobuf:"varint,1,rep,name=voters" json:"voters,omitempty"` - // The learners in the incoming config. - Learners []uint64 `protobuf:"varint,2,rep,name=learners" json:"learners,omitempty"` - // The voters in the outgoing config. - VotersOutgoing []uint64 `protobuf:"varint,3,rep,name=voters_outgoing,json=votersOutgoing" json:"voters_outgoing,omitempty"` - // The nodes that will become learners when the outgoing config is removed. - // These nodes are necessarily currently in nodes_joint (or they would have - // been added to the incoming config right away). - LearnersNext []uint64 `protobuf:"varint,4,rep,name=learners_next,json=learnersNext" json:"learners_next,omitempty"` - // If set, the config is joint and Raft will automatically transition into - // the final config (i.e. remove the outgoing config) when this is safe. - AutoLeave bool `protobuf:"varint,5,opt,name=auto_leave,json=autoLeave" json:"auto_leave"` -} - -func (m *ConfState) Reset() { *m = ConfState{} } -func (m *ConfState) String() string { return proto.CompactTextString(m) } -func (*ConfState) ProtoMessage() {} -func (*ConfState) Descriptor() ([]byte, []int) { - return fileDescriptor_b042552c306ae59b, []int{5} -} -func (m *ConfState) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *ConfState) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_ConfState.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *ConfState) XXX_Merge(src proto.Message) { - xxx_messageInfo_ConfState.Merge(m, src) -} -func (m *ConfState) XXX_Size() int { - return m.Size() -} -func (m *ConfState) XXX_DiscardUnknown() { - xxx_messageInfo_ConfState.DiscardUnknown(m) -} - -var xxx_messageInfo_ConfState proto.InternalMessageInfo - -type ConfChange struct { - Type ConfChangeType `protobuf:"varint,2,opt,name=type,enum=raftpb.ConfChangeType" json:"type"` - NodeID uint64 `protobuf:"varint,3,opt,name=node_id,json=nodeId" json:"node_id"` - Context []byte `protobuf:"bytes,4,opt,name=context" json:"context,omitempty"` - // NB: this is used only by etcd to thread through a unique identifier. - // Ideally it should really use the Context instead. No counterpart to - // this field exists in ConfChangeV2. - ID uint64 `protobuf:"varint,1,opt,name=id" json:"id"` -} - -func (m *ConfChange) Reset() { *m = ConfChange{} } -func (m *ConfChange) String() string { return proto.CompactTextString(m) } -func (*ConfChange) ProtoMessage() {} -func (*ConfChange) Descriptor() ([]byte, []int) { - return fileDescriptor_b042552c306ae59b, []int{6} -} -func (m *ConfChange) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *ConfChange) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_ConfChange.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *ConfChange) XXX_Merge(src proto.Message) { - xxx_messageInfo_ConfChange.Merge(m, src) -} -func (m *ConfChange) XXX_Size() int { - return m.Size() -} -func (m *ConfChange) XXX_DiscardUnknown() { - xxx_messageInfo_ConfChange.DiscardUnknown(m) -} - -var xxx_messageInfo_ConfChange proto.InternalMessageInfo - -// ConfChangeSingle is an individual configuration change operation. Multiple -// such operations can be carried out atomically via a ConfChangeV2. -type ConfChangeSingle struct { - Type ConfChangeType `protobuf:"varint,1,opt,name=type,enum=raftpb.ConfChangeType" json:"type"` - NodeID uint64 `protobuf:"varint,2,opt,name=node_id,json=nodeId" json:"node_id"` -} - -func (m *ConfChangeSingle) Reset() { *m = ConfChangeSingle{} } -func (m *ConfChangeSingle) String() string { return proto.CompactTextString(m) } -func (*ConfChangeSingle) ProtoMessage() {} -func (*ConfChangeSingle) Descriptor() ([]byte, []int) { - return fileDescriptor_b042552c306ae59b, []int{7} -} -func (m *ConfChangeSingle) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *ConfChangeSingle) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_ConfChangeSingle.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *ConfChangeSingle) XXX_Merge(src proto.Message) { - xxx_messageInfo_ConfChangeSingle.Merge(m, src) -} -func (m *ConfChangeSingle) XXX_Size() int { - return m.Size() -} -func (m *ConfChangeSingle) XXX_DiscardUnknown() { - xxx_messageInfo_ConfChangeSingle.DiscardUnknown(m) -} - -var xxx_messageInfo_ConfChangeSingle proto.InternalMessageInfo - -// ConfChangeV2 messages initiate configuration changes. They support both the -// simple "one at a time" membership change protocol and full Joint Consensus -// allowing for arbitrary changes in membership. -// -// The supplied context is treated as an opaque payload and can be used to -// attach an action on the state machine to the application of the config change -// proposal. Note that contrary to Joint Consensus as outlined in the Raft -// paper[1], configuration changes become active when they are *applied* to the -// state machine (not when they are appended to the log). -// -// The simple protocol can be used whenever only a single change is made. -// -// Non-simple changes require the use of Joint Consensus, for which two -// configuration changes are run. The first configuration change specifies the -// desired changes and transitions the Raft group into the joint configuration, -// in which quorum requires a majority of both the pre-changes and post-changes -// configuration. Joint Consensus avoids entering fragile intermediate -// configurations that could compromise survivability. For example, without the -// use of Joint Consensus and running across three availability zones with a -// replication factor of three, it is not possible to replace a voter without -// entering an intermediate configuration that does not survive the outage of -// one availability zone. -// -// The provided ConfChangeTransition specifies how (and whether) Joint Consensus -// is used, and assigns the task of leaving the joint configuration either to -// Raft or the application. Leaving the joint configuration is accomplished by -// proposing a ConfChangeV2 with only and optionally the Context field -// populated. -// -// For details on Raft membership changes, see: -// -// [1]: https://github.com/ongardie/dissertation/blob/master/online-trim.pdf -type ConfChangeV2 struct { - Transition ConfChangeTransition `protobuf:"varint,1,opt,name=transition,enum=raftpb.ConfChangeTransition" json:"transition"` - Changes []ConfChangeSingle `protobuf:"bytes,2,rep,name=changes" json:"changes"` - Context []byte `protobuf:"bytes,3,opt,name=context" json:"context,omitempty"` -} - -func (m *ConfChangeV2) Reset() { *m = ConfChangeV2{} } -func (m *ConfChangeV2) String() string { return proto.CompactTextString(m) } -func (*ConfChangeV2) ProtoMessage() {} -func (*ConfChangeV2) Descriptor() ([]byte, []int) { - return fileDescriptor_b042552c306ae59b, []int{8} -} -func (m *ConfChangeV2) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *ConfChangeV2) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_ConfChangeV2.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *ConfChangeV2) XXX_Merge(src proto.Message) { - xxx_messageInfo_ConfChangeV2.Merge(m, src) -} -func (m *ConfChangeV2) XXX_Size() int { - return m.Size() -} -func (m *ConfChangeV2) XXX_DiscardUnknown() { - xxx_messageInfo_ConfChangeV2.DiscardUnknown(m) -} - -var xxx_messageInfo_ConfChangeV2 proto.InternalMessageInfo - -func init() { - proto.RegisterEnum("raftpb.EntryType", EntryType_name, EntryType_value) - proto.RegisterEnum("raftpb.MessageType", MessageType_name, MessageType_value) - proto.RegisterEnum("raftpb.ConfChangeTransition", ConfChangeTransition_name, ConfChangeTransition_value) - proto.RegisterEnum("raftpb.ConfChangeType", ConfChangeType_name, ConfChangeType_value) - proto.RegisterType((*Entry)(nil), "raftpb.Entry") - proto.RegisterType((*SnapshotMetadata)(nil), "raftpb.SnapshotMetadata") - proto.RegisterType((*Snapshot)(nil), "raftpb.Snapshot") - proto.RegisterType((*Message)(nil), "raftpb.Message") - proto.RegisterType((*HardState)(nil), "raftpb.HardState") - proto.RegisterType((*ConfState)(nil), "raftpb.ConfState") - proto.RegisterType((*ConfChange)(nil), "raftpb.ConfChange") - proto.RegisterType((*ConfChangeSingle)(nil), "raftpb.ConfChangeSingle") - proto.RegisterType((*ConfChangeV2)(nil), "raftpb.ConfChangeV2") -} - -func init() { proto.RegisterFile("raft.proto", fileDescriptor_b042552c306ae59b) } - -var fileDescriptor_b042552c306ae59b = []byte{ - // 1026 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x55, 0xcd, 0x6e, 0xdb, 0x46, - 0x17, 0x25, 0x29, 0x5a, 0x3f, 0x57, 0xb2, 0x3c, 0xbe, 0xf1, 0x17, 0x10, 0x86, 0xc1, 0xe8, 0x53, - 0x52, 0x44, 0x70, 0x11, 0xb7, 0xd0, 0xa2, 0x28, 0xba, 0xf3, 0x4f, 0x00, 0xab, 0xb0, 0xdc, 0x54, - 0x76, 0xbc, 0x28, 0x50, 0x08, 0x63, 0x71, 0x44, 0xb3, 0x15, 0x39, 0x04, 0x39, 0x72, 0xed, 0x4d, - 0x51, 0xf4, 0x09, 0xba, 0xec, 0x26, 0xdb, 0x3e, 0x40, 0x9f, 0xc2, 0x4b, 0x03, 0xdd, 0x74, 0x15, - 0x34, 0xf6, 0x8b, 0x14, 0x33, 0x1c, 0x4a, 0x94, 0x6c, 0x64, 0xd1, 0xdd, 0xcc, 0xb9, 0x67, 0xee, - 0x9c, 0x73, 0xef, 0xe5, 0x10, 0x20, 0xa1, 0x63, 0xb1, 0x13, 0x27, 0x5c, 0x70, 0x2c, 0xcb, 0x75, - 0x7c, 0xbe, 0xb9, 0xe1, 0x73, 0x9f, 0x2b, 0xe8, 0x33, 0xb9, 0xca, 0xa2, 0xed, 0x9f, 0x61, 0xe5, - 0x75, 0x24, 0x92, 0x6b, 0x74, 0xc0, 0x3e, 0x65, 0x49, 0xe8, 0x58, 0x2d, 0xb3, 0x63, 0xef, 0xd9, - 0x37, 0xef, 0x9f, 0x19, 0x03, 0x85, 0xe0, 0x26, 0xac, 0xf4, 0x22, 0x8f, 0x5d, 0x39, 0xa5, 0x42, - 0x28, 0x83, 0xf0, 0x53, 0xb0, 0x4f, 0xaf, 0x63, 0xe6, 0x98, 0x2d, 0xb3, 0xd3, 0xec, 0xae, 0xef, - 0x64, 0x77, 0xed, 0xa8, 0x94, 0x32, 0x30, 0x4b, 0x74, 0x1d, 0x33, 0x44, 0xb0, 0x0f, 0xa8, 0xa0, - 0x8e, 0xdd, 0x32, 0x3b, 0x8d, 0x81, 0x5a, 0xb7, 0x7f, 0x31, 0x81, 0x9c, 0x44, 0x34, 0x4e, 0x2f, - 0xb8, 0xe8, 0x33, 0x41, 0x3d, 0x2a, 0x28, 0x7e, 0x01, 0x30, 0xe2, 0xd1, 0x78, 0x98, 0x0a, 0x2a, - 0xb2, 0xdc, 0xf5, 0x79, 0xee, 0x7d, 0x1e, 0x8d, 0x4f, 0x64, 0x40, 0xe7, 0xae, 0x8d, 0x72, 0x40, - 0x2a, 0x0d, 0x94, 0xd2, 0xa2, 0x89, 0x0c, 0x92, 0xfe, 0x84, 0xf4, 0x57, 0x34, 0xa1, 0x90, 0xf6, - 0x77, 0x50, 0xcd, 0x15, 0x48, 0x89, 0x52, 0x81, 0xba, 0xb3, 0x31, 0x50, 0x6b, 0xfc, 0x0a, 0xaa, - 0xa1, 0x56, 0xa6, 0x12, 0xd7, 0xbb, 0x4e, 0xae, 0x65, 0x59, 0xb9, 0xce, 0x3b, 0xe3, 0xb7, 0xdf, - 0x95, 0xa0, 0xd2, 0x67, 0x69, 0x4a, 0x7d, 0x86, 0xaf, 0xc0, 0x16, 0xf3, 0x5a, 0x3d, 0xc9, 0x73, - 0xe8, 0x70, 0xb1, 0x5a, 0x92, 0x86, 0x1b, 0x60, 0x09, 0xbe, 0xe0, 0xc4, 0x12, 0x5c, 0xda, 0x18, - 0x27, 0x7c, 0xc9, 0x86, 0x44, 0x66, 0x06, 0xed, 0x65, 0x83, 0xe8, 0x42, 0x65, 0xc2, 0x7d, 0xd5, - 0xdd, 0x95, 0x42, 0x30, 0x07, 0xe7, 0x65, 0x2b, 0x3f, 0x2c, 0xdb, 0x2b, 0xa8, 0xb0, 0x48, 0x24, - 0x01, 0x4b, 0x9d, 0x4a, 0xab, 0xd4, 0xa9, 0x77, 0x57, 0x17, 0x7a, 0x9c, 0xa7, 0xd2, 0x1c, 0xdc, - 0x82, 0xf2, 0x88, 0x87, 0x61, 0x20, 0x9c, 0x6a, 0x21, 0x97, 0xc6, 0xb0, 0x0b, 0xd5, 0x54, 0x57, - 0xcc, 0xa9, 0xa9, 0x4a, 0x92, 0xe5, 0x4a, 0xe6, 0x15, 0xcc, 0x79, 0x32, 0x63, 0xc2, 0x7e, 0x60, - 0x23, 0xe1, 0x40, 0xcb, 0xec, 0x54, 0xf3, 0x8c, 0x19, 0x86, 0x2f, 0x00, 0xb2, 0xd5, 0x61, 0x10, - 0x09, 0xa7, 0x5e, 0xb8, 0xb3, 0x80, 0xa3, 0x03, 0x95, 0x11, 0x8f, 0x04, 0xbb, 0x12, 0x4e, 0x43, - 0x35, 0x36, 0xdf, 0xb6, 0xbf, 0x87, 0xda, 0x21, 0x4d, 0xbc, 0x6c, 0x7c, 0xf2, 0x0a, 0x9a, 0x0f, - 0x2a, 0xe8, 0x80, 0x7d, 0xc9, 0x05, 0x5b, 0xfc, 0x38, 0x24, 0x52, 0x30, 0x5c, 0x7a, 0x68, 0xb8, - 0xfd, 0xa7, 0x09, 0xb5, 0xd9, 0xbc, 0xe2, 0x53, 0x28, 0xcb, 0x33, 0x49, 0xea, 0x98, 0xad, 0x52, - 0xc7, 0x1e, 0xe8, 0x1d, 0x6e, 0x42, 0x75, 0xc2, 0x68, 0x12, 0xc9, 0x88, 0xa5, 0x22, 0xb3, 0x3d, - 0xbe, 0x84, 0xb5, 0x8c, 0x35, 0xe4, 0x53, 0xe1, 0xf3, 0x20, 0xf2, 0x9d, 0x92, 0xa2, 0x34, 0x33, - 0xf8, 0x1b, 0x8d, 0xe2, 0x73, 0x58, 0xcd, 0x0f, 0x0d, 0x23, 0xe9, 0xd4, 0x56, 0xb4, 0x46, 0x0e, - 0x1e, 0xb3, 0x2b, 0x81, 0xcf, 0x01, 0xe8, 0x54, 0xf0, 0xe1, 0x84, 0xd1, 0x4b, 0xa6, 0x86, 0x21, - 0x2f, 0x68, 0x4d, 0xe2, 0x47, 0x12, 0x6e, 0xbf, 0x33, 0x01, 0xa4, 0xe8, 0xfd, 0x0b, 0x1a, 0xf9, - 0x0c, 0x3f, 0xd7, 0x63, 0x6b, 0xa9, 0xb1, 0x7d, 0x5a, 0xfc, 0x0c, 0x33, 0xc6, 0x83, 0xc9, 0x7d, - 0x09, 0x95, 0x88, 0x7b, 0x6c, 0x18, 0x78, 0xba, 0x28, 0x4d, 0x19, 0xbc, 0x7b, 0xff, 0xac, 0x7c, - 0xcc, 0x3d, 0xd6, 0x3b, 0x18, 0x94, 0x65, 0xb8, 0xe7, 0x15, 0xfb, 0x62, 0x2f, 0xf4, 0x05, 0x37, - 0xc1, 0x0a, 0x3c, 0xdd, 0x08, 0xd0, 0xa7, 0xad, 0xde, 0xc1, 0xc0, 0x0a, 0xbc, 0x76, 0x08, 0x64, - 0x7e, 0xf9, 0x49, 0x10, 0xf9, 0x93, 0xb9, 0x48, 0xf3, 0xbf, 0x88, 0xb4, 0x3e, 0x26, 0xb2, 0xfd, - 0x87, 0x09, 0x8d, 0x79, 0x9e, 0xb3, 0x2e, 0xee, 0x01, 0x88, 0x84, 0x46, 0x69, 0x20, 0x02, 0x1e, - 0xe9, 0x1b, 0xb7, 0x1e, 0xb9, 0x71, 0xc6, 0xc9, 0x27, 0x72, 0x7e, 0x0a, 0xbf, 0x84, 0xca, 0x48, - 0xb1, 0xb2, 0x8e, 0x17, 0x9e, 0x94, 0x65, 0x6b, 0xf9, 0x17, 0xa6, 0xe9, 0xc5, 0x9a, 0x95, 0x16, - 0x6a, 0xb6, 0x7d, 0x08, 0xb5, 0xd9, 0xbb, 0x8b, 0x6b, 0x50, 0x57, 0x9b, 0x63, 0x9e, 0x84, 0x74, - 0x42, 0x0c, 0x7c, 0x02, 0x6b, 0x0a, 0x98, 0xe7, 0x27, 0x26, 0xfe, 0x0f, 0xd6, 0x97, 0xc0, 0xb3, - 0x2e, 0xb1, 0xb6, 0xff, 0xb2, 0xa0, 0x5e, 0x78, 0x96, 0x10, 0xa0, 0xdc, 0x4f, 0xfd, 0xc3, 0x69, - 0x4c, 0x0c, 0xac, 0x43, 0xa5, 0x9f, 0xfa, 0x7b, 0x8c, 0x0a, 0x62, 0xea, 0xcd, 0x9b, 0x84, 0xc7, - 0xc4, 0xd2, 0xac, 0xdd, 0x38, 0x26, 0x25, 0x6c, 0x02, 0x64, 0xeb, 0x01, 0x4b, 0x63, 0x62, 0x6b, - 0xe2, 0x19, 0x17, 0x8c, 0xac, 0x48, 0x6d, 0x7a, 0xa3, 0xa2, 0x65, 0x1d, 0x95, 0x4f, 0x00, 0xa9, - 0x20, 0x81, 0x86, 0xbc, 0x8c, 0xd1, 0x44, 0x9c, 0xcb, 0x5b, 0xaa, 0xb8, 0x01, 0xa4, 0x88, 0xa8, - 0x43, 0x35, 0x44, 0x68, 0xf6, 0x53, 0xff, 0x6d, 0x94, 0x30, 0x3a, 0xba, 0xa0, 0xe7, 0x13, 0x46, - 0x00, 0xd7, 0x61, 0x55, 0x27, 0x92, 0x5f, 0xdc, 0x34, 0x25, 0x75, 0x4d, 0xdb, 0xbf, 0x60, 0xa3, - 0x1f, 0xbf, 0x9d, 0xf2, 0x64, 0x1a, 0x92, 0x86, 0xb4, 0xdd, 0x4f, 0x7d, 0xd5, 0xa0, 0x31, 0x4b, - 0x8e, 0x18, 0xf5, 0x58, 0x42, 0x56, 0xf5, 0xe9, 0xd3, 0x20, 0x64, 0x7c, 0x2a, 0x8e, 0xf9, 0x4f, - 0xa4, 0xa9, 0xc5, 0x0c, 0x18, 0xf5, 0xd4, 0xff, 0x8e, 0xac, 0x69, 0x31, 0x33, 0x44, 0x89, 0x21, - 0xda, 0xef, 0x9b, 0x84, 0x29, 0x8b, 0xeb, 0xfa, 0x56, 0xbd, 0x57, 0x1c, 0xdc, 0xfe, 0xd5, 0x84, - 0x8d, 0xc7, 0xc6, 0x03, 0xb7, 0xc0, 0x79, 0x0c, 0xdf, 0x9d, 0x0a, 0x4e, 0x0c, 0xfc, 0x04, 0xfe, - 0xff, 0x58, 0xf4, 0x6b, 0x1e, 0x44, 0xa2, 0x17, 0xc6, 0x93, 0x60, 0x14, 0xc8, 0x56, 0x7c, 0x8c, - 0xf6, 0xfa, 0x4a, 0xd3, 0xac, 0xed, 0x6b, 0x68, 0x2e, 0x7e, 0x14, 0xb2, 0x18, 0x73, 0x64, 0xd7, - 0xf3, 0xe4, 0xf8, 0x13, 0x03, 0x9d, 0xa2, 0xd8, 0x01, 0x0b, 0xf9, 0x25, 0x53, 0x11, 0x73, 0x31, - 0xf2, 0x36, 0xf6, 0xa8, 0xc8, 0x22, 0xd6, 0xa2, 0x91, 0x5d, 0xcf, 0x3b, 0xca, 0xde, 0x1e, 0x15, - 0x2d, 0xed, 0xbd, 0xb8, 0xf9, 0xe0, 0x1a, 0xb7, 0x1f, 0x5c, 0xe3, 0xe6, 0xce, 0x35, 0x6f, 0xef, - 0x5c, 0xf3, 0x9f, 0x3b, 0xd7, 0xfc, 0xed, 0xde, 0x35, 0x7e, 0xbf, 0x77, 0x8d, 0xdb, 0x7b, 0xd7, - 0xf8, 0xfb, 0xde, 0x35, 0xfe, 0x0d, 0x00, 0x00, 0xff, 0xff, 0xee, 0xe3, 0x39, 0x8b, 0xbb, 0x08, - 0x00, 0x00, -} - -func (m *Entry) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *Entry) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *Entry) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.Data != nil { - i -= len(m.Data) - copy(dAtA[i:], m.Data) - i = encodeVarintRaft(dAtA, i, uint64(len(m.Data))) - i-- - dAtA[i] = 0x22 - } - i = encodeVarintRaft(dAtA, i, uint64(m.Index)) - i-- - dAtA[i] = 0x18 - i = encodeVarintRaft(dAtA, i, uint64(m.Term)) - i-- - dAtA[i] = 0x10 - i = encodeVarintRaft(dAtA, i, uint64(m.Type)) - i-- - dAtA[i] = 0x8 - return len(dAtA) - i, nil -} - -func (m *SnapshotMetadata) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *SnapshotMetadata) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *SnapshotMetadata) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - i = encodeVarintRaft(dAtA, i, uint64(m.Term)) - i-- - dAtA[i] = 0x18 - i = encodeVarintRaft(dAtA, i, uint64(m.Index)) - i-- - dAtA[i] = 0x10 - { - size, err := m.ConfState.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintRaft(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0xa - return len(dAtA) - i, nil -} - -func (m *Snapshot) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *Snapshot) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *Snapshot) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - { - size, err := m.Metadata.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintRaft(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x12 - if m.Data != nil { - i -= len(m.Data) - copy(dAtA[i:], m.Data) - i = encodeVarintRaft(dAtA, i, uint64(len(m.Data))) - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - -func (m *Message) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *Message) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *Message) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.Context != nil { - i -= len(m.Context) - copy(dAtA[i:], m.Context) - i = encodeVarintRaft(dAtA, i, uint64(len(m.Context))) - i-- - dAtA[i] = 0x62 - } - i = encodeVarintRaft(dAtA, i, uint64(m.RejectHint)) - i-- - dAtA[i] = 0x58 - i-- - if m.Reject { - dAtA[i] = 1 - } else { - dAtA[i] = 0 - } - i-- - dAtA[i] = 0x50 - { - size, err := m.Snapshot.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintRaft(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x4a - i = encodeVarintRaft(dAtA, i, uint64(m.Commit)) - i-- - dAtA[i] = 0x40 - if len(m.Entries) > 0 { - for iNdEx := len(m.Entries) - 1; iNdEx >= 0; iNdEx-- { - { - size, err := m.Entries[iNdEx].MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintRaft(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x3a - } - } - i = encodeVarintRaft(dAtA, i, uint64(m.Index)) - i-- - dAtA[i] = 0x30 - i = encodeVarintRaft(dAtA, i, uint64(m.LogTerm)) - i-- - dAtA[i] = 0x28 - i = encodeVarintRaft(dAtA, i, uint64(m.Term)) - i-- - dAtA[i] = 0x20 - i = encodeVarintRaft(dAtA, i, uint64(m.From)) - i-- - dAtA[i] = 0x18 - i = encodeVarintRaft(dAtA, i, uint64(m.To)) - i-- - dAtA[i] = 0x10 - i = encodeVarintRaft(dAtA, i, uint64(m.Type)) - i-- - dAtA[i] = 0x8 - return len(dAtA) - i, nil -} - -func (m *HardState) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *HardState) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *HardState) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - i = encodeVarintRaft(dAtA, i, uint64(m.Commit)) - i-- - dAtA[i] = 0x18 - i = encodeVarintRaft(dAtA, i, uint64(m.Vote)) - i-- - dAtA[i] = 0x10 - i = encodeVarintRaft(dAtA, i, uint64(m.Term)) - i-- - dAtA[i] = 0x8 - return len(dAtA) - i, nil -} - -func (m *ConfState) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *ConfState) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *ConfState) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - i-- - if m.AutoLeave { - dAtA[i] = 1 - } else { - dAtA[i] = 0 - } - i-- - dAtA[i] = 0x28 - if len(m.LearnersNext) > 0 { - for iNdEx := len(m.LearnersNext) - 1; iNdEx >= 0; iNdEx-- { - i = encodeVarintRaft(dAtA, i, uint64(m.LearnersNext[iNdEx])) - i-- - dAtA[i] = 0x20 - } - } - if len(m.VotersOutgoing) > 0 { - for iNdEx := len(m.VotersOutgoing) - 1; iNdEx >= 0; iNdEx-- { - i = encodeVarintRaft(dAtA, i, uint64(m.VotersOutgoing[iNdEx])) - i-- - dAtA[i] = 0x18 - } - } - if len(m.Learners) > 0 { - for iNdEx := len(m.Learners) - 1; iNdEx >= 0; iNdEx-- { - i = encodeVarintRaft(dAtA, i, uint64(m.Learners[iNdEx])) - i-- - dAtA[i] = 0x10 - } - } - if len(m.Voters) > 0 { - for iNdEx := len(m.Voters) - 1; iNdEx >= 0; iNdEx-- { - i = encodeVarintRaft(dAtA, i, uint64(m.Voters[iNdEx])) - i-- - dAtA[i] = 0x8 - } - } - return len(dAtA) - i, nil -} - -func (m *ConfChange) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *ConfChange) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *ConfChange) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.Context != nil { - i -= len(m.Context) - copy(dAtA[i:], m.Context) - i = encodeVarintRaft(dAtA, i, uint64(len(m.Context))) - i-- - dAtA[i] = 0x22 - } - i = encodeVarintRaft(dAtA, i, uint64(m.NodeID)) - i-- - dAtA[i] = 0x18 - i = encodeVarintRaft(dAtA, i, uint64(m.Type)) - i-- - dAtA[i] = 0x10 - i = encodeVarintRaft(dAtA, i, uint64(m.ID)) - i-- - dAtA[i] = 0x8 - return len(dAtA) - i, nil -} - -func (m *ConfChangeSingle) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *ConfChangeSingle) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *ConfChangeSingle) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - i = encodeVarintRaft(dAtA, i, uint64(m.NodeID)) - i-- - dAtA[i] = 0x10 - i = encodeVarintRaft(dAtA, i, uint64(m.Type)) - i-- - dAtA[i] = 0x8 - return len(dAtA) - i, nil -} - -func (m *ConfChangeV2) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *ConfChangeV2) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *ConfChangeV2) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.Context != nil { - i -= len(m.Context) - copy(dAtA[i:], m.Context) - i = encodeVarintRaft(dAtA, i, uint64(len(m.Context))) - i-- - dAtA[i] = 0x1a - } - if len(m.Changes) > 0 { - for iNdEx := len(m.Changes) - 1; iNdEx >= 0; iNdEx-- { - { - size, err := m.Changes[iNdEx].MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintRaft(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x12 - } - } - i = encodeVarintRaft(dAtA, i, uint64(m.Transition)) - i-- - dAtA[i] = 0x8 - return len(dAtA) - i, nil -} - -func encodeVarintRaft(dAtA []byte, offset int, v uint64) int { - offset -= sovRaft(v) - base := offset - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return base -} -func (m *Entry) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - n += 1 + sovRaft(uint64(m.Type)) - n += 1 + sovRaft(uint64(m.Term)) - n += 1 + sovRaft(uint64(m.Index)) - if m.Data != nil { - l = len(m.Data) - n += 1 + l + sovRaft(uint64(l)) - } - return n -} - -func (m *SnapshotMetadata) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = m.ConfState.Size() - n += 1 + l + sovRaft(uint64(l)) - n += 1 + sovRaft(uint64(m.Index)) - n += 1 + sovRaft(uint64(m.Term)) - return n -} - -func (m *Snapshot) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.Data != nil { - l = len(m.Data) - n += 1 + l + sovRaft(uint64(l)) - } - l = m.Metadata.Size() - n += 1 + l + sovRaft(uint64(l)) - return n -} - -func (m *Message) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - n += 1 + sovRaft(uint64(m.Type)) - n += 1 + sovRaft(uint64(m.To)) - n += 1 + sovRaft(uint64(m.From)) - n += 1 + sovRaft(uint64(m.Term)) - n += 1 + sovRaft(uint64(m.LogTerm)) - n += 1 + sovRaft(uint64(m.Index)) - if len(m.Entries) > 0 { - for _, e := range m.Entries { - l = e.Size() - n += 1 + l + sovRaft(uint64(l)) - } - } - n += 1 + sovRaft(uint64(m.Commit)) - l = m.Snapshot.Size() - n += 1 + l + sovRaft(uint64(l)) - n += 2 - n += 1 + sovRaft(uint64(m.RejectHint)) - if m.Context != nil { - l = len(m.Context) - n += 1 + l + sovRaft(uint64(l)) - } - return n -} - -func (m *HardState) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - n += 1 + sovRaft(uint64(m.Term)) - n += 1 + sovRaft(uint64(m.Vote)) - n += 1 + sovRaft(uint64(m.Commit)) - return n -} - -func (m *ConfState) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if len(m.Voters) > 0 { - for _, e := range m.Voters { - n += 1 + sovRaft(uint64(e)) - } - } - if len(m.Learners) > 0 { - for _, e := range m.Learners { - n += 1 + sovRaft(uint64(e)) - } - } - if len(m.VotersOutgoing) > 0 { - for _, e := range m.VotersOutgoing { - n += 1 + sovRaft(uint64(e)) - } - } - if len(m.LearnersNext) > 0 { - for _, e := range m.LearnersNext { - n += 1 + sovRaft(uint64(e)) - } - } - n += 2 - return n -} - -func (m *ConfChange) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - n += 1 + sovRaft(uint64(m.ID)) - n += 1 + sovRaft(uint64(m.Type)) - n += 1 + sovRaft(uint64(m.NodeID)) - if m.Context != nil { - l = len(m.Context) - n += 1 + l + sovRaft(uint64(l)) - } - return n -} - -func (m *ConfChangeSingle) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - n += 1 + sovRaft(uint64(m.Type)) - n += 1 + sovRaft(uint64(m.NodeID)) - return n -} - -func (m *ConfChangeV2) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - n += 1 + sovRaft(uint64(m.Transition)) - if len(m.Changes) > 0 { - for _, e := range m.Changes { - l = e.Size() - n += 1 + l + sovRaft(uint64(l)) - } - } - if m.Context != nil { - l = len(m.Context) - n += 1 + l + sovRaft(uint64(l)) - } - return n -} - -func sovRaft(x uint64) (n int) { - return (math_bits.Len64(x|1) + 6) / 7 -} -func sozRaft(x uint64) (n int) { - return sovRaft(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} -func (m *Entry) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: Entry: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: Entry: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Type", wireType) - } - m.Type = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Type |= EntryType(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Term", wireType) - } - m.Term = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Term |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 3: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Index", wireType) - } - m.Index = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Index |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 4: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Data", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthRaft - } - postIndex := iNdEx + byteLen - if postIndex < 0 { - return ErrInvalidLengthRaft - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Data = append(m.Data[:0], dAtA[iNdEx:postIndex]...) - if m.Data == nil { - m.Data = []byte{} - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRaft(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthRaft - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *SnapshotMetadata) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: SnapshotMetadata: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: SnapshotMetadata: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ConfState", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRaft - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthRaft - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if err := m.ConfState.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Index", wireType) - } - m.Index = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Index |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 3: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Term", wireType) - } - m.Term = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Term |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - default: - iNdEx = preIndex - skippy, err := skipRaft(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthRaft - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *Snapshot) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: Snapshot: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: Snapshot: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Data", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthRaft - } - postIndex := iNdEx + byteLen - if postIndex < 0 { - return ErrInvalidLengthRaft - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Data = append(m.Data[:0], dAtA[iNdEx:postIndex]...) - if m.Data == nil { - m.Data = []byte{} - } - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Metadata", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRaft - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthRaft - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if err := m.Metadata.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRaft(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthRaft - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *Message) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: Message: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: Message: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Type", wireType) - } - m.Type = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Type |= MessageType(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field To", wireType) - } - m.To = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.To |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 3: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field From", wireType) - } - m.From = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.From |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 4: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Term", wireType) - } - m.Term = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Term |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 5: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field LogTerm", wireType) - } - m.LogTerm = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.LogTerm |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 6: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Index", wireType) - } - m.Index = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Index |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 7: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Entries", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRaft - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthRaft - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Entries = append(m.Entries, Entry{}) - if err := m.Entries[len(m.Entries)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 8: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Commit", wireType) - } - m.Commit = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Commit |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 9: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Snapshot", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRaft - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthRaft - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if err := m.Snapshot.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 10: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Reject", wireType) - } - var v int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - m.Reject = bool(v != 0) - case 11: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field RejectHint", wireType) - } - m.RejectHint = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.RejectHint |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 12: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Context", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthRaft - } - postIndex := iNdEx + byteLen - if postIndex < 0 { - return ErrInvalidLengthRaft - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Context = append(m.Context[:0], dAtA[iNdEx:postIndex]...) - if m.Context == nil { - m.Context = []byte{} - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRaft(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthRaft - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *HardState) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: HardState: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: HardState: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Term", wireType) - } - m.Term = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Term |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Vote", wireType) - } - m.Vote = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Vote |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 3: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Commit", wireType) - } - m.Commit = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Commit |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - default: - iNdEx = preIndex - skippy, err := skipRaft(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthRaft - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *ConfState) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: ConfState: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: ConfState: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType == 0 { - var v uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - m.Voters = append(m.Voters, v) - } else if wireType == 2 { - var packedLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - packedLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if packedLen < 0 { - return ErrInvalidLengthRaft - } - postIndex := iNdEx + packedLen - if postIndex < 0 { - return ErrInvalidLengthRaft - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - var elementCount int - var count int - for _, integer := range dAtA[iNdEx:postIndex] { - if integer < 128 { - count++ - } - } - elementCount = count - if elementCount != 0 && len(m.Voters) == 0 { - m.Voters = make([]uint64, 0, elementCount) - } - for iNdEx < postIndex { - var v uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - m.Voters = append(m.Voters, v) - } - } else { - return fmt.Errorf("proto: wrong wireType = %d for field Voters", wireType) - } - case 2: - if wireType == 0 { - var v uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - m.Learners = append(m.Learners, v) - } else if wireType == 2 { - var packedLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - packedLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if packedLen < 0 { - return ErrInvalidLengthRaft - } - postIndex := iNdEx + packedLen - if postIndex < 0 { - return ErrInvalidLengthRaft - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - var elementCount int - var count int - for _, integer := range dAtA[iNdEx:postIndex] { - if integer < 128 { - count++ - } - } - elementCount = count - if elementCount != 0 && len(m.Learners) == 0 { - m.Learners = make([]uint64, 0, elementCount) - } - for iNdEx < postIndex { - var v uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - m.Learners = append(m.Learners, v) - } - } else { - return fmt.Errorf("proto: wrong wireType = %d for field Learners", wireType) - } - case 3: - if wireType == 0 { - var v uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - m.VotersOutgoing = append(m.VotersOutgoing, v) - } else if wireType == 2 { - var packedLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - packedLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if packedLen < 0 { - return ErrInvalidLengthRaft - } - postIndex := iNdEx + packedLen - if postIndex < 0 { - return ErrInvalidLengthRaft - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - var elementCount int - var count int - for _, integer := range dAtA[iNdEx:postIndex] { - if integer < 128 { - count++ - } - } - elementCount = count - if elementCount != 0 && len(m.VotersOutgoing) == 0 { - m.VotersOutgoing = make([]uint64, 0, elementCount) - } - for iNdEx < postIndex { - var v uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - m.VotersOutgoing = append(m.VotersOutgoing, v) - } - } else { - return fmt.Errorf("proto: wrong wireType = %d for field VotersOutgoing", wireType) - } - case 4: - if wireType == 0 { - var v uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - m.LearnersNext = append(m.LearnersNext, v) - } else if wireType == 2 { - var packedLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - packedLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if packedLen < 0 { - return ErrInvalidLengthRaft - } - postIndex := iNdEx + packedLen - if postIndex < 0 { - return ErrInvalidLengthRaft - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - var elementCount int - var count int - for _, integer := range dAtA[iNdEx:postIndex] { - if integer < 128 { - count++ - } - } - elementCount = count - if elementCount != 0 && len(m.LearnersNext) == 0 { - m.LearnersNext = make([]uint64, 0, elementCount) - } - for iNdEx < postIndex { - var v uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - m.LearnersNext = append(m.LearnersNext, v) - } - } else { - return fmt.Errorf("proto: wrong wireType = %d for field LearnersNext", wireType) - } - case 5: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field AutoLeave", wireType) - } - var v int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - m.AutoLeave = bool(v != 0) - default: - iNdEx = preIndex - skippy, err := skipRaft(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthRaft - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *ConfChange) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: ConfChange: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: ConfChange: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field ID", wireType) - } - m.ID = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.ID |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Type", wireType) - } - m.Type = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Type |= ConfChangeType(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 3: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field NodeID", wireType) - } - m.NodeID = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.NodeID |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 4: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Context", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthRaft - } - postIndex := iNdEx + byteLen - if postIndex < 0 { - return ErrInvalidLengthRaft - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Context = append(m.Context[:0], dAtA[iNdEx:postIndex]...) - if m.Context == nil { - m.Context = []byte{} - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRaft(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthRaft - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *ConfChangeSingle) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: ConfChangeSingle: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: ConfChangeSingle: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Type", wireType) - } - m.Type = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Type |= ConfChangeType(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field NodeID", wireType) - } - m.NodeID = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.NodeID |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - default: - iNdEx = preIndex - skippy, err := skipRaft(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthRaft - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *ConfChangeV2) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: ConfChangeV2: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: ConfChangeV2: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Transition", wireType) - } - m.Transition = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Transition |= ConfChangeTransition(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Changes", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRaft - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthRaft - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Changes = append(m.Changes, ConfChangeSingle{}) - if err := m.Changes[len(m.Changes)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Context", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRaft - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthRaft - } - postIndex := iNdEx + byteLen - if postIndex < 0 { - return ErrInvalidLengthRaft - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Context = append(m.Context[:0], dAtA[iNdEx:postIndex]...) - if m.Context == nil { - m.Context = []byte{} - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRaft(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthRaft - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func skipRaft(dAtA []byte) (n int, err error) { - l := len(dAtA) - iNdEx := 0 - depth := 0 - for iNdEx < l { - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowRaft - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - wireType := int(wire & 0x7) - switch wireType { - case 0: - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowRaft - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - iNdEx++ - if dAtA[iNdEx-1] < 0x80 { - break - } - } - case 1: - iNdEx += 8 - case 2: - var length int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowRaft - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - length |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if length < 0 { - return 0, ErrInvalidLengthRaft - } - iNdEx += length - case 3: - depth++ - case 4: - if depth == 0 { - return 0, ErrUnexpectedEndOfGroupRaft - } - depth-- - case 5: - iNdEx += 4 - default: - return 0, fmt.Errorf("proto: illegal wireType %d", wireType) - } - if iNdEx < 0 { - return 0, ErrInvalidLengthRaft - } - if depth == 0 { - return iNdEx, nil - } - } - return 0, io.ErrUnexpectedEOF -} - -var ( - ErrInvalidLengthRaft = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowRaft = fmt.Errorf("proto: integer overflow") - ErrUnexpectedEndOfGroupRaft = fmt.Errorf("proto: unexpected end of group") -) diff --git a/vendor/go.etcd.io/etcd/raft/v3/raftpb/raft.proto b/vendor/go.etcd.io/etcd/raft/v3/raftpb/raft.proto deleted file mode 100644 index f46a54c948..0000000000 --- a/vendor/go.etcd.io/etcd/raft/v3/raftpb/raft.proto +++ /dev/null @@ -1,187 +0,0 @@ -syntax = "proto2"; -package raftpb; - -import "gogoproto/gogo.proto"; - -option (gogoproto.marshaler_all) = true; -option (gogoproto.sizer_all) = true; -option (gogoproto.unmarshaler_all) = true; -option (gogoproto.goproto_getters_all) = false; -option (gogoproto.goproto_enum_prefix_all) = false; -option (gogoproto.goproto_unkeyed_all) = false; -option (gogoproto.goproto_unrecognized_all) = false; -option (gogoproto.goproto_sizecache_all) = false; - -enum EntryType { - EntryNormal = 0; - EntryConfChange = 1; // corresponds to pb.ConfChange - EntryConfChangeV2 = 2; // corresponds to pb.ConfChangeV2 -} - -message Entry { - optional uint64 Term = 2 [(gogoproto.nullable) = false]; // must be 64-bit aligned for atomic operations - optional uint64 Index = 3 [(gogoproto.nullable) = false]; // must be 64-bit aligned for atomic operations - optional EntryType Type = 1 [(gogoproto.nullable) = false]; - optional bytes Data = 4; -} - -message SnapshotMetadata { - optional ConfState conf_state = 1 [(gogoproto.nullable) = false]; - optional uint64 index = 2 [(gogoproto.nullable) = false]; - optional uint64 term = 3 [(gogoproto.nullable) = false]; -} - -message Snapshot { - optional bytes data = 1; - optional SnapshotMetadata metadata = 2 [(gogoproto.nullable) = false]; -} - -// For description of different message types, see: -// https://pkg.go.dev/go.etcd.io/etcd/raft/v3#hdr-MessageType -enum MessageType { - MsgHup = 0; - MsgBeat = 1; - MsgProp = 2; - MsgApp = 3; - MsgAppResp = 4; - MsgVote = 5; - MsgVoteResp = 6; - MsgSnap = 7; - MsgHeartbeat = 8; - MsgHeartbeatResp = 9; - MsgUnreachable = 10; - MsgSnapStatus = 11; - MsgCheckQuorum = 12; - MsgTransferLeader = 13; - MsgTimeoutNow = 14; - MsgReadIndex = 15; - MsgReadIndexResp = 16; - MsgPreVote = 17; - MsgPreVoteResp = 18; -} - -message Message { - optional MessageType type = 1 [(gogoproto.nullable) = false]; - optional uint64 to = 2 [(gogoproto.nullable) = false]; - optional uint64 from = 3 [(gogoproto.nullable) = false]; - optional uint64 term = 4 [(gogoproto.nullable) = false]; - // logTerm is generally used for appending Raft logs to followers. For example, - // (type=MsgApp,index=100,logTerm=5) means leader appends entries starting at - // index=101, and the term of entry at index 100 is 5. - // (type=MsgAppResp,reject=true,index=100,logTerm=5) means follower rejects some - // entries from its leader as it already has an entry with term 5 at index 100. - optional uint64 logTerm = 5 [(gogoproto.nullable) = false]; - optional uint64 index = 6 [(gogoproto.nullable) = false]; - repeated Entry entries = 7 [(gogoproto.nullable) = false]; - optional uint64 commit = 8 [(gogoproto.nullable) = false]; - optional Snapshot snapshot = 9 [(gogoproto.nullable) = false]; - optional bool reject = 10 [(gogoproto.nullable) = false]; - optional uint64 rejectHint = 11 [(gogoproto.nullable) = false]; - optional bytes context = 12; -} - -message HardState { - optional uint64 term = 1 [(gogoproto.nullable) = false]; - optional uint64 vote = 2 [(gogoproto.nullable) = false]; - optional uint64 commit = 3 [(gogoproto.nullable) = false]; -} - -// ConfChangeTransition specifies the behavior of a configuration change with -// respect to joint consensus. -enum ConfChangeTransition { - // Automatically use the simple protocol if possible, otherwise fall back - // to ConfChangeJointImplicit. Most applications will want to use this. - ConfChangeTransitionAuto = 0; - // Use joint consensus unconditionally, and transition out of them - // automatically (by proposing a zero configuration change). - // - // This option is suitable for applications that want to minimize the time - // spent in the joint configuration and do not store the joint configuration - // in the state machine (outside of InitialState). - ConfChangeTransitionJointImplicit = 1; - // Use joint consensus and remain in the joint configuration until the - // application proposes a no-op configuration change. This is suitable for - // applications that want to explicitly control the transitions, for example - // to use a custom payload (via the Context field). - ConfChangeTransitionJointExplicit = 2; -} - -message ConfState { - // The voters in the incoming config. (If the configuration is not joint, - // then the outgoing config is empty). - repeated uint64 voters = 1; - // The learners in the incoming config. - repeated uint64 learners = 2; - // The voters in the outgoing config. - repeated uint64 voters_outgoing = 3; - // The nodes that will become learners when the outgoing config is removed. - // These nodes are necessarily currently in nodes_joint (or they would have - // been added to the incoming config right away). - repeated uint64 learners_next = 4; - // If set, the config is joint and Raft will automatically transition into - // the final config (i.e. remove the outgoing config) when this is safe. - optional bool auto_leave = 5 [(gogoproto.nullable) = false]; -} - -enum ConfChangeType { - ConfChangeAddNode = 0; - ConfChangeRemoveNode = 1; - ConfChangeUpdateNode = 2; - ConfChangeAddLearnerNode = 3; -} - -message ConfChange { - optional ConfChangeType type = 2 [(gogoproto.nullable) = false]; - optional uint64 node_id = 3 [(gogoproto.nullable) = false, (gogoproto.customname) = "NodeID" ]; - optional bytes context = 4; - - // NB: this is used only by etcd to thread through a unique identifier. - // Ideally it should really use the Context instead. No counterpart to - // this field exists in ConfChangeV2. - optional uint64 id = 1 [(gogoproto.nullable) = false, (gogoproto.customname) = "ID" ]; -} - -// ConfChangeSingle is an individual configuration change operation. Multiple -// such operations can be carried out atomically via a ConfChangeV2. -message ConfChangeSingle { - optional ConfChangeType type = 1 [(gogoproto.nullable) = false]; - optional uint64 node_id = 2 [(gogoproto.nullable) = false, (gogoproto.customname) = "NodeID"]; -} - -// ConfChangeV2 messages initiate configuration changes. They support both the -// simple "one at a time" membership change protocol and full Joint Consensus -// allowing for arbitrary changes in membership. -// -// The supplied context is treated as an opaque payload and can be used to -// attach an action on the state machine to the application of the config change -// proposal. Note that contrary to Joint Consensus as outlined in the Raft -// paper[1], configuration changes become active when they are *applied* to the -// state machine (not when they are appended to the log). -// -// The simple protocol can be used whenever only a single change is made. -// -// Non-simple changes require the use of Joint Consensus, for which two -// configuration changes are run. The first configuration change specifies the -// desired changes and transitions the Raft group into the joint configuration, -// in which quorum requires a majority of both the pre-changes and post-changes -// configuration. Joint Consensus avoids entering fragile intermediate -// configurations that could compromise survivability. For example, without the -// use of Joint Consensus and running across three availability zones with a -// replication factor of three, it is not possible to replace a voter without -// entering an intermediate configuration that does not survive the outage of -// one availability zone. -// -// The provided ConfChangeTransition specifies how (and whether) Joint Consensus -// is used, and assigns the task of leaving the joint configuration either to -// Raft or the application. Leaving the joint configuration is accomplished by -// proposing a ConfChangeV2 with only and optionally the Context field -// populated. -// -// For details on Raft membership changes, see: -// -// [1]: https://github.com/ongardie/dissertation/blob/master/online-trim.pdf -message ConfChangeV2 { - optional ConfChangeTransition transition = 1 [(gogoproto.nullable) = false]; - repeated ConfChangeSingle changes = 2 [(gogoproto.nullable) = false]; - optional bytes context = 3; -} diff --git a/vendor/go.etcd.io/etcd/raft/v3/rawnode.go b/vendor/go.etcd.io/etcd/raft/v3/rawnode.go deleted file mode 100644 index 4111d029dd..0000000000 --- a/vendor/go.etcd.io/etcd/raft/v3/rawnode.go +++ /dev/null @@ -1,241 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package raft - -import ( - "errors" - - pb "go.etcd.io/etcd/raft/v3/raftpb" - "go.etcd.io/etcd/raft/v3/tracker" -) - -// ErrStepLocalMsg is returned when try to step a local raft message -var ErrStepLocalMsg = errors.New("raft: cannot step raft local message") - -// ErrStepPeerNotFound is returned when try to step a response message -// but there is no peer found in raft.prs for that node. -var ErrStepPeerNotFound = errors.New("raft: cannot step as peer not found") - -// RawNode is a thread-unsafe Node. -// The methods of this struct correspond to the methods of Node and are described -// more fully there. -type RawNode struct { - raft *raft - prevSoftSt *SoftState - prevHardSt pb.HardState -} - -// NewRawNode instantiates a RawNode from the given configuration. -// -// See Bootstrap() for bootstrapping an initial state; this replaces the former -// 'peers' argument to this method (with identical behavior). However, It is -// recommended that instead of calling Bootstrap, applications bootstrap their -// state manually by setting up a Storage that has a first index > 1 and which -// stores the desired ConfState as its InitialState. -func NewRawNode(config *Config) (*RawNode, error) { - r := newRaft(config) - rn := &RawNode{ - raft: r, - } - rn.prevSoftSt = r.softState() - rn.prevHardSt = r.hardState() - return rn, nil -} - -// Tick advances the internal logical clock by a single tick. -func (rn *RawNode) Tick() { - rn.raft.tick() -} - -// TickQuiesced advances the internal logical clock by a single tick without -// performing any other state machine processing. It allows the caller to avoid -// periodic heartbeats and elections when all of the peers in a Raft group are -// known to be at the same state. Expected usage is to periodically invoke Tick -// or TickQuiesced depending on whether the group is "active" or "quiesced". -// -// WARNING: Be very careful about using this method as it subverts the Raft -// state machine. You should probably be using Tick instead. -func (rn *RawNode) TickQuiesced() { - rn.raft.electionElapsed++ -} - -// Campaign causes this RawNode to transition to candidate state. -func (rn *RawNode) Campaign() error { - return rn.raft.Step(pb.Message{ - Type: pb.MsgHup, - }) -} - -// Propose proposes data be appended to the raft log. -func (rn *RawNode) Propose(data []byte) error { - return rn.raft.Step(pb.Message{ - Type: pb.MsgProp, - From: rn.raft.id, - Entries: []pb.Entry{ - {Data: data}, - }}) -} - -// ProposeConfChange proposes a config change. See (Node).ProposeConfChange for -// details. -func (rn *RawNode) ProposeConfChange(cc pb.ConfChangeI) error { - m, err := confChangeToMsg(cc) - if err != nil { - return err - } - return rn.raft.Step(m) -} - -// ApplyConfChange applies a config change to the local node. The app must call -// this when it applies a configuration change, except when it decides to reject -// the configuration change, in which case no call must take place. -func (rn *RawNode) ApplyConfChange(cc pb.ConfChangeI) *pb.ConfState { - cs := rn.raft.applyConfChange(cc.AsV2()) - return &cs -} - -// Step advances the state machine using the given message. -func (rn *RawNode) Step(m pb.Message) error { - // ignore unexpected local messages receiving over network - if IsLocalMsg(m.Type) { - return ErrStepLocalMsg - } - if pr := rn.raft.prs.Progress[m.From]; pr != nil || !IsResponseMsg(m.Type) { - return rn.raft.Step(m) - } - return ErrStepPeerNotFound -} - -// Ready returns the outstanding work that the application needs to handle. This -// includes appending and applying entries or a snapshot, updating the HardState, -// and sending messages. The returned Ready() *must* be handled and subsequently -// passed back via Advance(). -func (rn *RawNode) Ready() Ready { - rd := rn.readyWithoutAccept() - rn.acceptReady(rd) - return rd -} - -// readyWithoutAccept returns a Ready. This is a read-only operation, i.e. there -// is no obligation that the Ready must be handled. -func (rn *RawNode) readyWithoutAccept() Ready { - return newReady(rn.raft, rn.prevSoftSt, rn.prevHardSt) -} - -// acceptReady is called when the consumer of the RawNode has decided to go -// ahead and handle a Ready. Nothing must alter the state of the RawNode between -// this call and the prior call to Ready(). -func (rn *RawNode) acceptReady(rd Ready) { - if rd.SoftState != nil { - rn.prevSoftSt = rd.SoftState - } - if len(rd.ReadStates) != 0 { - rn.raft.readStates = nil - } - rn.raft.msgs = nil -} - -// HasReady called when RawNode user need to check if any Ready pending. -// Checking logic in this method should be consistent with Ready.containsUpdates(). -func (rn *RawNode) HasReady() bool { - r := rn.raft - if !r.softState().equal(rn.prevSoftSt) { - return true - } - if hardSt := r.hardState(); !IsEmptyHardState(hardSt) && !isHardStateEqual(hardSt, rn.prevHardSt) { - return true - } - if r.raftLog.hasPendingSnapshot() { - return true - } - if len(r.msgs) > 0 || len(r.raftLog.unstableEntries()) > 0 || r.raftLog.hasNextEnts() { - return true - } - if len(r.readStates) != 0 { - return true - } - return false -} - -// Advance notifies the RawNode that the application has applied and saved progress in the -// last Ready results. -func (rn *RawNode) Advance(rd Ready) { - if !IsEmptyHardState(rd.HardState) { - rn.prevHardSt = rd.HardState - } - rn.raft.advance(rd) -} - -// Status returns the current status of the given group. This allocates, see -// BasicStatus and WithProgress for allocation-friendlier choices. -func (rn *RawNode) Status() Status { - status := getStatus(rn.raft) - return status -} - -// BasicStatus returns a BasicStatus. Notably this does not contain the -// Progress map; see WithProgress for an allocation-free way to inspect it. -func (rn *RawNode) BasicStatus() BasicStatus { - return getBasicStatus(rn.raft) -} - -// ProgressType indicates the type of replica a Progress corresponds to. -type ProgressType byte - -const ( - // ProgressTypePeer accompanies a Progress for a regular peer replica. - ProgressTypePeer ProgressType = iota - // ProgressTypeLearner accompanies a Progress for a learner replica. - ProgressTypeLearner -) - -// WithProgress is a helper to introspect the Progress for this node and its -// peers. -func (rn *RawNode) WithProgress(visitor func(id uint64, typ ProgressType, pr tracker.Progress)) { - rn.raft.prs.Visit(func(id uint64, pr *tracker.Progress) { - typ := ProgressTypePeer - if pr.IsLearner { - typ = ProgressTypeLearner - } - p := *pr - p.Inflights = nil - visitor(id, typ, p) - }) -} - -// ReportUnreachable reports the given node is not reachable for the last send. -func (rn *RawNode) ReportUnreachable(id uint64) { - _ = rn.raft.Step(pb.Message{Type: pb.MsgUnreachable, From: id}) -} - -// ReportSnapshot reports the status of the sent snapshot. -func (rn *RawNode) ReportSnapshot(id uint64, status SnapshotStatus) { - rej := status == SnapshotFailure - - _ = rn.raft.Step(pb.Message{Type: pb.MsgSnapStatus, From: id, Reject: rej}) -} - -// TransferLeader tries to transfer leadership to the given transferee. -func (rn *RawNode) TransferLeader(transferee uint64) { - _ = rn.raft.Step(pb.Message{Type: pb.MsgTransferLeader, From: transferee}) -} - -// ReadIndex requests a read state. The read state will be set in ready. -// Read State has a read index. Once the application advances further than the read -// index, any linearizable read requests issued before the read request can be -// processed safely. The read state will have the same rctx attached. -func (rn *RawNode) ReadIndex(rctx []byte) { - _ = rn.raft.Step(pb.Message{Type: pb.MsgReadIndex, Entries: []pb.Entry{{Data: rctx}}}) -} diff --git a/vendor/go.etcd.io/etcd/raft/v3/read_only.go b/vendor/go.etcd.io/etcd/raft/v3/read_only.go deleted file mode 100644 index ad0688522d..0000000000 --- a/vendor/go.etcd.io/etcd/raft/v3/read_only.go +++ /dev/null @@ -1,121 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package raft - -import pb "go.etcd.io/etcd/raft/v3/raftpb" - -// ReadState provides state for read only query. -// It's caller's responsibility to call ReadIndex first before getting -// this state from ready, it's also caller's duty to differentiate if this -// state is what it requests through RequestCtx, eg. given a unique id as -// RequestCtx -type ReadState struct { - Index uint64 - RequestCtx []byte -} - -type readIndexStatus struct { - req pb.Message - index uint64 - // NB: this never records 'false', but it's more convenient to use this - // instead of a map[uint64]struct{} due to the API of quorum.VoteResult. If - // this becomes performance sensitive enough (doubtful), quorum.VoteResult - // can change to an API that is closer to that of CommittedIndex. - acks map[uint64]bool -} - -type readOnly struct { - option ReadOnlyOption - pendingReadIndex map[string]*readIndexStatus - readIndexQueue []string -} - -func newReadOnly(option ReadOnlyOption) *readOnly { - return &readOnly{ - option: option, - pendingReadIndex: make(map[string]*readIndexStatus), - } -} - -// addRequest adds a read only request into readonly struct. -// `index` is the commit index of the raft state machine when it received -// the read only request. -// `m` is the original read only request message from the local or remote node. -func (ro *readOnly) addRequest(index uint64, m pb.Message) { - s := string(m.Entries[0].Data) - if _, ok := ro.pendingReadIndex[s]; ok { - return - } - ro.pendingReadIndex[s] = &readIndexStatus{index: index, req: m, acks: make(map[uint64]bool)} - ro.readIndexQueue = append(ro.readIndexQueue, s) -} - -// recvAck notifies the readonly struct that the raft state machine received -// an acknowledgment of the heartbeat that attached with the read only request -// context. -func (ro *readOnly) recvAck(id uint64, context []byte) map[uint64]bool { - rs, ok := ro.pendingReadIndex[string(context)] - if !ok { - return nil - } - - rs.acks[id] = true - return rs.acks -} - -// advance advances the read only request queue kept by the readonly struct. -// It dequeues the requests until it finds the read only request that has -// the same context as the given `m`. -func (ro *readOnly) advance(m pb.Message) []*readIndexStatus { - var ( - i int - found bool - ) - - ctx := string(m.Context) - rss := []*readIndexStatus{} - - for _, okctx := range ro.readIndexQueue { - i++ - rs, ok := ro.pendingReadIndex[okctx] - if !ok { - panic("cannot find corresponding read state from pending map") - } - rss = append(rss, rs) - if okctx == ctx { - found = true - break - } - } - - if found { - ro.readIndexQueue = ro.readIndexQueue[i:] - for _, rs := range rss { - delete(ro.pendingReadIndex, string(rs.req.Entries[0].Data)) - } - return rss - } - - return nil -} - -// lastPendingRequestCtx returns the context of the last pending read only -// request in readonly struct. -func (ro *readOnly) lastPendingRequestCtx() string { - if len(ro.readIndexQueue) == 0 { - return "" - } - return ro.readIndexQueue[len(ro.readIndexQueue)-1] -} diff --git a/vendor/go.etcd.io/etcd/raft/v3/status.go b/vendor/go.etcd.io/etcd/raft/v3/status.go deleted file mode 100644 index acfb56c391..0000000000 --- a/vendor/go.etcd.io/etcd/raft/v3/status.go +++ /dev/null @@ -1,105 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package raft - -import ( - "fmt" - - pb "go.etcd.io/etcd/raft/v3/raftpb" - "go.etcd.io/etcd/raft/v3/tracker" -) - -// Status contains information about this Raft peer and its view of the system. -// The Progress is only populated on the leader. -type Status struct { - BasicStatus - Config tracker.Config - Progress map[uint64]tracker.Progress -} - -// BasicStatus contains basic information about the Raft peer. It does not allocate. -type BasicStatus struct { - ID uint64 - - pb.HardState - SoftState - - Applied uint64 - - LeadTransferee uint64 -} - -func getProgressCopy(r *raft) map[uint64]tracker.Progress { - m := make(map[uint64]tracker.Progress) - r.prs.Visit(func(id uint64, pr *tracker.Progress) { - p := *pr - p.Inflights = pr.Inflights.Clone() - pr = nil - - m[id] = p - }) - return m -} - -func getBasicStatus(r *raft) BasicStatus { - s := BasicStatus{ - ID: r.id, - LeadTransferee: r.leadTransferee, - } - s.HardState = r.hardState() - s.SoftState = *r.softState() - s.Applied = r.raftLog.applied - return s -} - -// getStatus gets a copy of the current raft status. -func getStatus(r *raft) Status { - var s Status - s.BasicStatus = getBasicStatus(r) - if s.RaftState == StateLeader { - s.Progress = getProgressCopy(r) - } - s.Config = r.prs.Config.Clone() - return s -} - -// MarshalJSON translates the raft status into JSON. -// TODO: try to simplify this by introducing ID type into raft -func (s Status) MarshalJSON() ([]byte, error) { - j := fmt.Sprintf(`{"id":"%x","term":%d,"vote":"%x","commit":%d,"lead":"%x","raftState":%q,"applied":%d,"progress":{`, - s.ID, s.Term, s.Vote, s.Commit, s.Lead, s.RaftState, s.Applied) - - if len(s.Progress) == 0 { - j += "}," - } else { - for k, v := range s.Progress { - subj := fmt.Sprintf(`"%x":{"match":%d,"next":%d,"state":%q},`, k, v.Match, v.Next, v.State) - j += subj - } - // remove the trailing "," - j = j[:len(j)-1] + "}," - } - - j += fmt.Sprintf(`"leadtransferee":"%x"}`, s.LeadTransferee) - return []byte(j), nil -} - -func (s Status) String() string { - b, err := s.MarshalJSON() - if err != nil { - getLogger().Panicf("unexpected error: %v", err) - } - return string(b) -} diff --git a/vendor/go.etcd.io/etcd/raft/v3/storage.go b/vendor/go.etcd.io/etcd/raft/v3/storage.go deleted file mode 100644 index 8b16d4fa24..0000000000 --- a/vendor/go.etcd.io/etcd/raft/v3/storage.go +++ /dev/null @@ -1,273 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package raft - -import ( - "errors" - "sync" - - pb "go.etcd.io/etcd/raft/v3/raftpb" -) - -// ErrCompacted is returned by Storage.Entries/Compact when a requested -// index is unavailable because it predates the last snapshot. -var ErrCompacted = errors.New("requested index is unavailable due to compaction") - -// ErrSnapOutOfDate is returned by Storage.CreateSnapshot when a requested -// index is older than the existing snapshot. -var ErrSnapOutOfDate = errors.New("requested index is older than the existing snapshot") - -// ErrUnavailable is returned by Storage interface when the requested log entries -// are unavailable. -var ErrUnavailable = errors.New("requested entry at index is unavailable") - -// ErrSnapshotTemporarilyUnavailable is returned by the Storage interface when the required -// snapshot is temporarily unavailable. -var ErrSnapshotTemporarilyUnavailable = errors.New("snapshot is temporarily unavailable") - -// Storage is an interface that may be implemented by the application -// to retrieve log entries from storage. -// -// If any Storage method returns an error, the raft instance will -// become inoperable and refuse to participate in elections; the -// application is responsible for cleanup and recovery in this case. -type Storage interface { - // TODO(tbg): split this into two interfaces, LogStorage and StateStorage. - - // InitialState returns the saved HardState and ConfState information. - InitialState() (pb.HardState, pb.ConfState, error) - // Entries returns a slice of log entries in the range [lo,hi). - // MaxSize limits the total size of the log entries returned, but - // Entries returns at least one entry if any. - Entries(lo, hi, maxSize uint64) ([]pb.Entry, error) - // Term returns the term of entry i, which must be in the range - // [FirstIndex()-1, LastIndex()]. The term of the entry before - // FirstIndex is retained for matching purposes even though the - // rest of that entry may not be available. - Term(i uint64) (uint64, error) - // LastIndex returns the index of the last entry in the log. - LastIndex() (uint64, error) - // FirstIndex returns the index of the first log entry that is - // possibly available via Entries (older entries have been incorporated - // into the latest Snapshot; if storage only contains the dummy entry the - // first log entry is not available). - FirstIndex() (uint64, error) - // Snapshot returns the most recent snapshot. - // If snapshot is temporarily unavailable, it should return ErrSnapshotTemporarilyUnavailable, - // so raft state machine could know that Storage needs some time to prepare - // snapshot and call Snapshot later. - Snapshot() (pb.Snapshot, error) -} - -// MemoryStorage implements the Storage interface backed by an -// in-memory array. -type MemoryStorage struct { - // Protects access to all fields. Most methods of MemoryStorage are - // run on the raft goroutine, but Append() is run on an application - // goroutine. - sync.Mutex - - hardState pb.HardState - snapshot pb.Snapshot - // ents[i] has raft log position i+snapshot.Metadata.Index - ents []pb.Entry -} - -// NewMemoryStorage creates an empty MemoryStorage. -func NewMemoryStorage() *MemoryStorage { - return &MemoryStorage{ - // When starting from scratch populate the list with a dummy entry at term zero. - ents: make([]pb.Entry, 1), - } -} - -// InitialState implements the Storage interface. -func (ms *MemoryStorage) InitialState() (pb.HardState, pb.ConfState, error) { - return ms.hardState, ms.snapshot.Metadata.ConfState, nil -} - -// SetHardState saves the current HardState. -func (ms *MemoryStorage) SetHardState(st pb.HardState) error { - ms.Lock() - defer ms.Unlock() - ms.hardState = st - return nil -} - -// Entries implements the Storage interface. -func (ms *MemoryStorage) Entries(lo, hi, maxSize uint64) ([]pb.Entry, error) { - ms.Lock() - defer ms.Unlock() - offset := ms.ents[0].Index - if lo <= offset { - return nil, ErrCompacted - } - if hi > ms.lastIndex()+1 { - getLogger().Panicf("entries' hi(%d) is out of bound lastindex(%d)", hi, ms.lastIndex()) - } - // only contains dummy entries. - if len(ms.ents) == 1 { - return nil, ErrUnavailable - } - - ents := ms.ents[lo-offset : hi-offset] - return limitSize(ents, maxSize), nil -} - -// Term implements the Storage interface. -func (ms *MemoryStorage) Term(i uint64) (uint64, error) { - ms.Lock() - defer ms.Unlock() - offset := ms.ents[0].Index - if i < offset { - return 0, ErrCompacted - } - if int(i-offset) >= len(ms.ents) { - return 0, ErrUnavailable - } - return ms.ents[i-offset].Term, nil -} - -// LastIndex implements the Storage interface. -func (ms *MemoryStorage) LastIndex() (uint64, error) { - ms.Lock() - defer ms.Unlock() - return ms.lastIndex(), nil -} - -func (ms *MemoryStorage) lastIndex() uint64 { - return ms.ents[0].Index + uint64(len(ms.ents)) - 1 -} - -// FirstIndex implements the Storage interface. -func (ms *MemoryStorage) FirstIndex() (uint64, error) { - ms.Lock() - defer ms.Unlock() - return ms.firstIndex(), nil -} - -func (ms *MemoryStorage) firstIndex() uint64 { - return ms.ents[0].Index + 1 -} - -// Snapshot implements the Storage interface. -func (ms *MemoryStorage) Snapshot() (pb.Snapshot, error) { - ms.Lock() - defer ms.Unlock() - return ms.snapshot, nil -} - -// ApplySnapshot overwrites the contents of this Storage object with -// those of the given snapshot. -func (ms *MemoryStorage) ApplySnapshot(snap pb.Snapshot) error { - ms.Lock() - defer ms.Unlock() - - //handle check for old snapshot being applied - msIndex := ms.snapshot.Metadata.Index - snapIndex := snap.Metadata.Index - if msIndex >= snapIndex { - return ErrSnapOutOfDate - } - - ms.snapshot = snap - ms.ents = []pb.Entry{{Term: snap.Metadata.Term, Index: snap.Metadata.Index}} - return nil -} - -// CreateSnapshot makes a snapshot which can be retrieved with Snapshot() and -// can be used to reconstruct the state at that point. -// If any configuration changes have been made since the last compaction, -// the result of the last ApplyConfChange must be passed in. -func (ms *MemoryStorage) CreateSnapshot(i uint64, cs *pb.ConfState, data []byte) (pb.Snapshot, error) { - ms.Lock() - defer ms.Unlock() - if i <= ms.snapshot.Metadata.Index { - return pb.Snapshot{}, ErrSnapOutOfDate - } - - offset := ms.ents[0].Index - if i > ms.lastIndex() { - getLogger().Panicf("snapshot %d is out of bound lastindex(%d)", i, ms.lastIndex()) - } - - ms.snapshot.Metadata.Index = i - ms.snapshot.Metadata.Term = ms.ents[i-offset].Term - if cs != nil { - ms.snapshot.Metadata.ConfState = *cs - } - ms.snapshot.Data = data - return ms.snapshot, nil -} - -// Compact discards all log entries prior to compactIndex. -// It is the application's responsibility to not attempt to compact an index -// greater than raftLog.applied. -func (ms *MemoryStorage) Compact(compactIndex uint64) error { - ms.Lock() - defer ms.Unlock() - offset := ms.ents[0].Index - if compactIndex <= offset { - return ErrCompacted - } - if compactIndex > ms.lastIndex() { - getLogger().Panicf("compact %d is out of bound lastindex(%d)", compactIndex, ms.lastIndex()) - } - - i := compactIndex - offset - ents := make([]pb.Entry, 1, 1+uint64(len(ms.ents))-i) - ents[0].Index = ms.ents[i].Index - ents[0].Term = ms.ents[i].Term - ents = append(ents, ms.ents[i+1:]...) - ms.ents = ents - return nil -} - -// Append the new entries to storage. -// TODO (xiangli): ensure the entries are continuous and -// entries[0].Index > ms.entries[0].Index -func (ms *MemoryStorage) Append(entries []pb.Entry) error { - if len(entries) == 0 { - return nil - } - - ms.Lock() - defer ms.Unlock() - - first := ms.firstIndex() - last := entries[0].Index + uint64(len(entries)) - 1 - - // shortcut if there is no new entry. - if last < first { - return nil - } - // truncate compacted entries - if first > entries[0].Index { - entries = entries[first-entries[0].Index:] - } - - offset := entries[0].Index - ms.ents[0].Index - switch { - case uint64(len(ms.ents)) > offset: - ms.ents = append([]pb.Entry{}, ms.ents[:offset]...) - ms.ents = append(ms.ents, entries...) - case uint64(len(ms.ents)) == offset: - ms.ents = append(ms.ents, entries...) - default: - getLogger().Panicf("missing log entry [last: %d, append at: %d]", - ms.lastIndex(), entries[0].Index) - } - return nil -} diff --git a/vendor/go.etcd.io/etcd/raft/v3/tracker/inflights.go b/vendor/go.etcd.io/etcd/raft/v3/tracker/inflights.go deleted file mode 100644 index 1a056341ab..0000000000 --- a/vendor/go.etcd.io/etcd/raft/v3/tracker/inflights.go +++ /dev/null @@ -1,132 +0,0 @@ -// Copyright 2019 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package tracker - -// Inflights limits the number of MsgApp (represented by the largest index -// contained within) sent to followers but not yet acknowledged by them. Callers -// use Full() to check whether more messages can be sent, call Add() whenever -// they are sending a new append, and release "quota" via FreeLE() whenever an -// ack is received. -type Inflights struct { - // the starting index in the buffer - start int - // number of inflights in the buffer - count int - - // the size of the buffer - size int - - // buffer contains the index of the last entry - // inside one message. - buffer []uint64 -} - -// NewInflights sets up an Inflights that allows up to 'size' inflight messages. -func NewInflights(size int) *Inflights { - return &Inflights{ - size: size, - } -} - -// Clone returns an *Inflights that is identical to but shares no memory with -// the receiver. -func (in *Inflights) Clone() *Inflights { - ins := *in - ins.buffer = append([]uint64(nil), in.buffer...) - return &ins -} - -// Add notifies the Inflights that a new message with the given index is being -// dispatched. Full() must be called prior to Add() to verify that there is room -// for one more message, and consecutive calls to add Add() must provide a -// monotonic sequence of indexes. -func (in *Inflights) Add(inflight uint64) { - if in.Full() { - panic("cannot add into a Full inflights") - } - next := in.start + in.count - size := in.size - if next >= size { - next -= size - } - if next >= len(in.buffer) { - in.grow() - } - in.buffer[next] = inflight - in.count++ -} - -// grow the inflight buffer by doubling up to inflights.size. We grow on demand -// instead of preallocating to inflights.size to handle systems which have -// thousands of Raft groups per process. -func (in *Inflights) grow() { - newSize := len(in.buffer) * 2 - if newSize == 0 { - newSize = 1 - } else if newSize > in.size { - newSize = in.size - } - newBuffer := make([]uint64, newSize) - copy(newBuffer, in.buffer) - in.buffer = newBuffer -} - -// FreeLE frees the inflights smaller or equal to the given `to` flight. -func (in *Inflights) FreeLE(to uint64) { - if in.count == 0 || to < in.buffer[in.start] { - // out of the left side of the window - return - } - - idx := in.start - var i int - for i = 0; i < in.count; i++ { - if to < in.buffer[idx] { // found the first large inflight - break - } - - // increase index and maybe rotate - size := in.size - if idx++; idx >= size { - idx -= size - } - } - // free i inflights and set new start index - in.count -= i - in.start = idx - if in.count == 0 { - // inflights is empty, reset the start index so that we don't grow the - // buffer unnecessarily. - in.start = 0 - } -} - -// FreeFirstOne releases the first inflight. This is a no-op if nothing is -// inflight. -func (in *Inflights) FreeFirstOne() { in.FreeLE(in.buffer[in.start]) } - -// Full returns true if no more messages can be sent at the moment. -func (in *Inflights) Full() bool { - return in.count == in.size -} - -// Count returns the number of inflight messages. -func (in *Inflights) Count() int { return in.count } - -// reset frees all inflights. -func (in *Inflights) reset() { - in.count = 0 - in.start = 0 -} diff --git a/vendor/go.etcd.io/etcd/raft/v3/tracker/progress.go b/vendor/go.etcd.io/etcd/raft/v3/tracker/progress.go deleted file mode 100644 index a36e5261ac..0000000000 --- a/vendor/go.etcd.io/etcd/raft/v3/tracker/progress.go +++ /dev/null @@ -1,255 +0,0 @@ -// Copyright 2019 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package tracker - -import ( - "fmt" - "sort" - "strings" -) - -// Progress represents a follower’s progress in the view of the leader. Leader -// maintains progresses of all followers, and sends entries to the follower -// based on its progress. -// -// NB(tbg): Progress is basically a state machine whose transitions are mostly -// strewn around `*raft.raft`. Additionally, some fields are only used when in a -// certain State. All of this isn't ideal. -type Progress struct { - Match, Next uint64 - // State defines how the leader should interact with the follower. - // - // When in StateProbe, leader sends at most one replication message - // per heartbeat interval. It also probes actual progress of the follower. - // - // When in StateReplicate, leader optimistically increases next - // to the latest entry sent after sending replication message. This is - // an optimized state for fast replicating log entries to the follower. - // - // When in StateSnapshot, leader should have sent out snapshot - // before and stops sending any replication message. - State StateType - - // PendingSnapshot is used in StateSnapshot. - // If there is a pending snapshot, the pendingSnapshot will be set to the - // index of the snapshot. If pendingSnapshot is set, the replication process of - // this Progress will be paused. raft will not resend snapshot until the pending one - // is reported to be failed. - PendingSnapshot uint64 - - // RecentActive is true if the progress is recently active. Receiving any messages - // from the corresponding follower indicates the progress is active. - // RecentActive can be reset to false after an election timeout. - // - // TODO(tbg): the leader should always have this set to true. - RecentActive bool - - // ProbeSent is used while this follower is in StateProbe. When ProbeSent is - // true, raft should pause sending replication message to this peer until - // ProbeSent is reset. See ProbeAcked() and IsPaused(). - ProbeSent bool - - // Inflights is a sliding window for the inflight messages. - // Each inflight message contains one or more log entries. - // The max number of entries per message is defined in raft config as MaxSizePerMsg. - // Thus inflight effectively limits both the number of inflight messages - // and the bandwidth each Progress can use. - // When inflights is Full, no more message should be sent. - // When a leader sends out a message, the index of the last - // entry should be added to inflights. The index MUST be added - // into inflights in order. - // When a leader receives a reply, the previous inflights should - // be freed by calling inflights.FreeLE with the index of the last - // received entry. - Inflights *Inflights - - // IsLearner is true if this progress is tracked for a learner. - IsLearner bool -} - -// ResetState moves the Progress into the specified State, resetting ProbeSent, -// PendingSnapshot, and Inflights. -func (pr *Progress) ResetState(state StateType) { - pr.ProbeSent = false - pr.PendingSnapshot = 0 - pr.State = state - pr.Inflights.reset() -} - -func max(a, b uint64) uint64 { - if a > b { - return a - } - return b -} - -func min(a, b uint64) uint64 { - if a > b { - return b - } - return a -} - -// ProbeAcked is called when this peer has accepted an append. It resets -// ProbeSent to signal that additional append messages should be sent without -// further delay. -func (pr *Progress) ProbeAcked() { - pr.ProbeSent = false -} - -// BecomeProbe transitions into StateProbe. Next is reset to Match+1 or, -// optionally and if larger, the index of the pending snapshot. -func (pr *Progress) BecomeProbe() { - // If the original state is StateSnapshot, progress knows that - // the pending snapshot has been sent to this peer successfully, then - // probes from pendingSnapshot + 1. - if pr.State == StateSnapshot { - pendingSnapshot := pr.PendingSnapshot - pr.ResetState(StateProbe) - pr.Next = max(pr.Match+1, pendingSnapshot+1) - } else { - pr.ResetState(StateProbe) - pr.Next = pr.Match + 1 - } -} - -// BecomeReplicate transitions into StateReplicate, resetting Next to Match+1. -func (pr *Progress) BecomeReplicate() { - pr.ResetState(StateReplicate) - pr.Next = pr.Match + 1 -} - -// BecomeSnapshot moves the Progress to StateSnapshot with the specified pending -// snapshot index. -func (pr *Progress) BecomeSnapshot(snapshoti uint64) { - pr.ResetState(StateSnapshot) - pr.PendingSnapshot = snapshoti -} - -// MaybeUpdate is called when an MsgAppResp arrives from the follower, with the -// index acked by it. The method returns false if the given n index comes from -// an outdated message. Otherwise it updates the progress and returns true. -func (pr *Progress) MaybeUpdate(n uint64) bool { - var updated bool - if pr.Match < n { - pr.Match = n - updated = true - pr.ProbeAcked() - } - pr.Next = max(pr.Next, n+1) - return updated -} - -// OptimisticUpdate signals that appends all the way up to and including index n -// are in-flight. As a result, Next is increased to n+1. -func (pr *Progress) OptimisticUpdate(n uint64) { pr.Next = n + 1 } - -// MaybeDecrTo adjusts the Progress to the receipt of a MsgApp rejection. The -// arguments are the index of the append message rejected by the follower, and -// the hint that we want to decrease to. -// -// Rejections can happen spuriously as messages are sent out of order or -// duplicated. In such cases, the rejection pertains to an index that the -// Progress already knows were previously acknowledged, and false is returned -// without changing the Progress. -// -// If the rejection is genuine, Next is lowered sensibly, and the Progress is -// cleared for sending log entries. -func (pr *Progress) MaybeDecrTo(rejected, matchHint uint64) bool { - if pr.State == StateReplicate { - // The rejection must be stale if the progress has matched and "rejected" - // is smaller than "match". - if rejected <= pr.Match { - return false - } - // Directly decrease next to match + 1. - // - // TODO(tbg): why not use matchHint if it's larger? - pr.Next = pr.Match + 1 - return true - } - - // The rejection must be stale if "rejected" does not match next - 1. This - // is because non-replicating followers are probed one entry at a time. - if pr.Next-1 != rejected { - return false - } - - pr.Next = max(min(rejected, matchHint+1), 1) - pr.ProbeSent = false - return true -} - -// IsPaused returns whether sending log entries to this node has been throttled. -// This is done when a node has rejected recent MsgApps, is currently waiting -// for a snapshot, or has reached the MaxInflightMsgs limit. In normal -// operation, this is false. A throttled node will be contacted less frequently -// until it has reached a state in which it's able to accept a steady stream of -// log entries again. -func (pr *Progress) IsPaused() bool { - switch pr.State { - case StateProbe: - return pr.ProbeSent - case StateReplicate: - return pr.Inflights.Full() - case StateSnapshot: - return true - default: - panic("unexpected state") - } -} - -func (pr *Progress) String() string { - var buf strings.Builder - fmt.Fprintf(&buf, "%s match=%d next=%d", pr.State, pr.Match, pr.Next) - if pr.IsLearner { - fmt.Fprint(&buf, " learner") - } - if pr.IsPaused() { - fmt.Fprint(&buf, " paused") - } - if pr.PendingSnapshot > 0 { - fmt.Fprintf(&buf, " pendingSnap=%d", pr.PendingSnapshot) - } - if !pr.RecentActive { - fmt.Fprintf(&buf, " inactive") - } - if n := pr.Inflights.Count(); n > 0 { - fmt.Fprintf(&buf, " inflight=%d", n) - if pr.Inflights.Full() { - fmt.Fprint(&buf, "[full]") - } - } - return buf.String() -} - -// ProgressMap is a map of *Progress. -type ProgressMap map[uint64]*Progress - -// String prints the ProgressMap in sorted key order, one Progress per line. -func (m ProgressMap) String() string { - ids := make([]uint64, 0, len(m)) - for k := range m { - ids = append(ids, k) - } - sort.Slice(ids, func(i, j int) bool { - return ids[i] < ids[j] - }) - var buf strings.Builder - for _, id := range ids { - fmt.Fprintf(&buf, "%d: %s\n", id, m[id]) - } - return buf.String() -} diff --git a/vendor/go.etcd.io/etcd/raft/v3/tracker/state.go b/vendor/go.etcd.io/etcd/raft/v3/tracker/state.go deleted file mode 100644 index 285b4b8f58..0000000000 --- a/vendor/go.etcd.io/etcd/raft/v3/tracker/state.go +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright 2019 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package tracker - -// StateType is the state of a tracked follower. -type StateType uint64 - -const ( - // StateProbe indicates a follower whose last index isn't known. Such a - // follower is "probed" (i.e. an append sent periodically) to narrow down - // its last index. In the ideal (and common) case, only one round of probing - // is necessary as the follower will react with a hint. Followers that are - // probed over extended periods of time are often offline. - StateProbe StateType = iota - // StateReplicate is the state steady in which a follower eagerly receives - // log entries to append to its log. - StateReplicate - // StateSnapshot indicates a follower that needs log entries not available - // from the leader's Raft log. Such a follower needs a full snapshot to - // return to StateReplicate. - StateSnapshot -) - -var prstmap = [...]string{ - "StateProbe", - "StateReplicate", - "StateSnapshot", -} - -func (st StateType) String() string { return prstmap[uint64(st)] } diff --git a/vendor/go.etcd.io/etcd/raft/v3/tracker/tracker.go b/vendor/go.etcd.io/etcd/raft/v3/tracker/tracker.go deleted file mode 100644 index 72dcc73b86..0000000000 --- a/vendor/go.etcd.io/etcd/raft/v3/tracker/tracker.go +++ /dev/null @@ -1,288 +0,0 @@ -// Copyright 2019 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package tracker - -import ( - "fmt" - "sort" - "strings" - - "go.etcd.io/etcd/raft/v3/quorum" - pb "go.etcd.io/etcd/raft/v3/raftpb" -) - -// Config reflects the configuration tracked in a ProgressTracker. -type Config struct { - Voters quorum.JointConfig - // AutoLeave is true if the configuration is joint and a transition to the - // incoming configuration should be carried out automatically by Raft when - // this is possible. If false, the configuration will be joint until the - // application initiates the transition manually. - AutoLeave bool - // Learners is a set of IDs corresponding to the learners active in the - // current configuration. - // - // Invariant: Learners and Voters does not intersect, i.e. if a peer is in - // either half of the joint config, it can't be a learner; if it is a - // learner it can't be in either half of the joint config. This invariant - // simplifies the implementation since it allows peers to have clarity about - // its current role without taking into account joint consensus. - Learners map[uint64]struct{} - // When we turn a voter into a learner during a joint consensus transition, - // we cannot add the learner directly when entering the joint state. This is - // because this would violate the invariant that the intersection of - // voters and learners is empty. For example, assume a Voter is removed and - // immediately re-added as a learner (or in other words, it is demoted): - // - // Initially, the configuration will be - // - // voters: {1 2 3} - // learners: {} - // - // and we want to demote 3. Entering the joint configuration, we naively get - // - // voters: {1 2} & {1 2 3} - // learners: {3} - // - // but this violates the invariant (3 is both voter and learner). Instead, - // we get - // - // voters: {1 2} & {1 2 3} - // learners: {} - // next_learners: {3} - // - // Where 3 is now still purely a voter, but we are remembering the intention - // to make it a learner upon transitioning into the final configuration: - // - // voters: {1 2} - // learners: {3} - // next_learners: {} - // - // Note that next_learners is not used while adding a learner that is not - // also a voter in the joint config. In this case, the learner is added - // right away when entering the joint configuration, so that it is caught up - // as soon as possible. - LearnersNext map[uint64]struct{} -} - -func (c Config) String() string { - var buf strings.Builder - fmt.Fprintf(&buf, "voters=%s", c.Voters) - if c.Learners != nil { - fmt.Fprintf(&buf, " learners=%s", quorum.MajorityConfig(c.Learners).String()) - } - if c.LearnersNext != nil { - fmt.Fprintf(&buf, " learners_next=%s", quorum.MajorityConfig(c.LearnersNext).String()) - } - if c.AutoLeave { - fmt.Fprintf(&buf, " autoleave") - } - return buf.String() -} - -// Clone returns a copy of the Config that shares no memory with the original. -func (c *Config) Clone() Config { - clone := func(m map[uint64]struct{}) map[uint64]struct{} { - if m == nil { - return nil - } - mm := make(map[uint64]struct{}, len(m)) - for k := range m { - mm[k] = struct{}{} - } - return mm - } - return Config{ - Voters: quorum.JointConfig{clone(c.Voters[0]), clone(c.Voters[1])}, - Learners: clone(c.Learners), - LearnersNext: clone(c.LearnersNext), - } -} - -// ProgressTracker tracks the currently active configuration and the information -// known about the nodes and learners in it. In particular, it tracks the match -// index for each peer which in turn allows reasoning about the committed index. -type ProgressTracker struct { - Config - - Progress ProgressMap - - Votes map[uint64]bool - - MaxInflight int -} - -// MakeProgressTracker initializes a ProgressTracker. -func MakeProgressTracker(maxInflight int) ProgressTracker { - p := ProgressTracker{ - MaxInflight: maxInflight, - Config: Config{ - Voters: quorum.JointConfig{ - quorum.MajorityConfig{}, - nil, // only populated when used - }, - Learners: nil, // only populated when used - LearnersNext: nil, // only populated when used - }, - Votes: map[uint64]bool{}, - Progress: map[uint64]*Progress{}, - } - return p -} - -// ConfState returns a ConfState representing the active configuration. -func (p *ProgressTracker) ConfState() pb.ConfState { - return pb.ConfState{ - Voters: p.Voters[0].Slice(), - VotersOutgoing: p.Voters[1].Slice(), - Learners: quorum.MajorityConfig(p.Learners).Slice(), - LearnersNext: quorum.MajorityConfig(p.LearnersNext).Slice(), - AutoLeave: p.AutoLeave, - } -} - -// IsSingleton returns true if (and only if) there is only one voting member -// (i.e. the leader) in the current configuration. -func (p *ProgressTracker) IsSingleton() bool { - return len(p.Voters[0]) == 1 && len(p.Voters[1]) == 0 -} - -type matchAckIndexer map[uint64]*Progress - -var _ quorum.AckedIndexer = matchAckIndexer(nil) - -// AckedIndex implements IndexLookuper. -func (l matchAckIndexer) AckedIndex(id uint64) (quorum.Index, bool) { - pr, ok := l[id] - if !ok { - return 0, false - } - return quorum.Index(pr.Match), true -} - -// Committed returns the largest log index known to be committed based on what -// the voting members of the group have acknowledged. -func (p *ProgressTracker) Committed() uint64 { - return uint64(p.Voters.CommittedIndex(matchAckIndexer(p.Progress))) -} - -func insertionSort(sl []uint64) { - a, b := 0, len(sl) - for i := a + 1; i < b; i++ { - for j := i; j > a && sl[j] < sl[j-1]; j-- { - sl[j], sl[j-1] = sl[j-1], sl[j] - } - } -} - -// Visit invokes the supplied closure for all tracked progresses in stable order. -func (p *ProgressTracker) Visit(f func(id uint64, pr *Progress)) { - n := len(p.Progress) - // We need to sort the IDs and don't want to allocate since this is hot code. - // The optimization here mirrors that in `(MajorityConfig).CommittedIndex`, - // see there for details. - var sl [7]uint64 - var ids []uint64 - if len(sl) >= n { - ids = sl[:n] - } else { - ids = make([]uint64, n) - } - for id := range p.Progress { - n-- - ids[n] = id - } - insertionSort(ids) - for _, id := range ids { - f(id, p.Progress[id]) - } -} - -// QuorumActive returns true if the quorum is active from the view of the local -// raft state machine. Otherwise, it returns false. -func (p *ProgressTracker) QuorumActive() bool { - votes := map[uint64]bool{} - p.Visit(func(id uint64, pr *Progress) { - if pr.IsLearner { - return - } - votes[id] = pr.RecentActive - }) - - return p.Voters.VoteResult(votes) == quorum.VoteWon -} - -// VoterNodes returns a sorted slice of voters. -func (p *ProgressTracker) VoterNodes() []uint64 { - m := p.Voters.IDs() - nodes := make([]uint64, 0, len(m)) - for id := range m { - nodes = append(nodes, id) - } - sort.Slice(nodes, func(i, j int) bool { return nodes[i] < nodes[j] }) - return nodes -} - -// LearnerNodes returns a sorted slice of learners. -func (p *ProgressTracker) LearnerNodes() []uint64 { - if len(p.Learners) == 0 { - return nil - } - nodes := make([]uint64, 0, len(p.Learners)) - for id := range p.Learners { - nodes = append(nodes, id) - } - sort.Slice(nodes, func(i, j int) bool { return nodes[i] < nodes[j] }) - return nodes -} - -// ResetVotes prepares for a new round of vote counting via recordVote. -func (p *ProgressTracker) ResetVotes() { - p.Votes = map[uint64]bool{} -} - -// RecordVote records that the node with the given id voted for this Raft -// instance if v == true (and declined it otherwise). -func (p *ProgressTracker) RecordVote(id uint64, v bool) { - _, ok := p.Votes[id] - if !ok { - p.Votes[id] = v - } -} - -// TallyVotes returns the number of granted and rejected Votes, and whether the -// election outcome is known. -func (p *ProgressTracker) TallyVotes() (granted int, rejected int, _ quorum.VoteResult) { - // Make sure to populate granted/rejected correctly even if the Votes slice - // contains members no longer part of the configuration. This doesn't really - // matter in the way the numbers are used (they're informational), but might - // as well get it right. - for id, pr := range p.Progress { - if pr.IsLearner { - continue - } - v, voted := p.Votes[id] - if !voted { - continue - } - if v { - granted++ - } else { - rejected++ - } - } - result := p.Voters.VoteResult(p.Votes) - return granted, rejected, result -} diff --git a/vendor/go.etcd.io/etcd/raft/v3/util.go b/vendor/go.etcd.io/etcd/raft/v3/util.go deleted file mode 100644 index 94ab368f60..0000000000 --- a/vendor/go.etcd.io/etcd/raft/v3/util.go +++ /dev/null @@ -1,233 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package raft - -import ( - "bytes" - "fmt" - "strings" - - pb "go.etcd.io/etcd/raft/v3/raftpb" -) - -func (st StateType) MarshalJSON() ([]byte, error) { - return []byte(fmt.Sprintf("%q", st.String())), nil -} - -func min(a, b uint64) uint64 { - if a > b { - return b - } - return a -} - -func max(a, b uint64) uint64 { - if a > b { - return a - } - return b -} - -func IsLocalMsg(msgt pb.MessageType) bool { - return msgt == pb.MsgHup || msgt == pb.MsgBeat || msgt == pb.MsgUnreachable || - msgt == pb.MsgSnapStatus || msgt == pb.MsgCheckQuorum -} - -func IsResponseMsg(msgt pb.MessageType) bool { - return msgt == pb.MsgAppResp || msgt == pb.MsgVoteResp || msgt == pb.MsgHeartbeatResp || msgt == pb.MsgUnreachable || msgt == pb.MsgPreVoteResp -} - -// voteResponseType maps vote and prevote message types to their corresponding responses. -func voteRespMsgType(msgt pb.MessageType) pb.MessageType { - switch msgt { - case pb.MsgVote: - return pb.MsgVoteResp - case pb.MsgPreVote: - return pb.MsgPreVoteResp - default: - panic(fmt.Sprintf("not a vote message: %s", msgt)) - } -} - -func DescribeHardState(hs pb.HardState) string { - var buf strings.Builder - fmt.Fprintf(&buf, "Term:%d", hs.Term) - if hs.Vote != 0 { - fmt.Fprintf(&buf, " Vote:%d", hs.Vote) - } - fmt.Fprintf(&buf, " Commit:%d", hs.Commit) - return buf.String() -} - -func DescribeSoftState(ss SoftState) string { - return fmt.Sprintf("Lead:%d State:%s", ss.Lead, ss.RaftState) -} - -func DescribeConfState(state pb.ConfState) string { - return fmt.Sprintf( - "Voters:%v VotersOutgoing:%v Learners:%v LearnersNext:%v AutoLeave:%v", - state.Voters, state.VotersOutgoing, state.Learners, state.LearnersNext, state.AutoLeave, - ) -} - -func DescribeSnapshot(snap pb.Snapshot) string { - m := snap.Metadata - return fmt.Sprintf("Index:%d Term:%d ConfState:%s", m.Index, m.Term, DescribeConfState(m.ConfState)) -} - -func DescribeReady(rd Ready, f EntryFormatter) string { - var buf strings.Builder - if rd.SoftState != nil { - fmt.Fprint(&buf, DescribeSoftState(*rd.SoftState)) - buf.WriteByte('\n') - } - if !IsEmptyHardState(rd.HardState) { - fmt.Fprintf(&buf, "HardState %s", DescribeHardState(rd.HardState)) - buf.WriteByte('\n') - } - if len(rd.ReadStates) > 0 { - fmt.Fprintf(&buf, "ReadStates %v\n", rd.ReadStates) - } - if len(rd.Entries) > 0 { - buf.WriteString("Entries:\n") - fmt.Fprint(&buf, DescribeEntries(rd.Entries, f)) - } - if !IsEmptySnap(rd.Snapshot) { - fmt.Fprintf(&buf, "Snapshot %s\n", DescribeSnapshot(rd.Snapshot)) - } - if len(rd.CommittedEntries) > 0 { - buf.WriteString("CommittedEntries:\n") - fmt.Fprint(&buf, DescribeEntries(rd.CommittedEntries, f)) - } - if len(rd.Messages) > 0 { - buf.WriteString("Messages:\n") - for _, msg := range rd.Messages { - fmt.Fprint(&buf, DescribeMessage(msg, f)) - buf.WriteByte('\n') - } - } - if buf.Len() > 0 { - return fmt.Sprintf("Ready MustSync=%t:\n%s", rd.MustSync, buf.String()) - } - return "" -} - -// EntryFormatter can be implemented by the application to provide human-readable formatting -// of entry data. Nil is a valid EntryFormatter and will use a default format. -type EntryFormatter func([]byte) string - -// DescribeMessage returns a concise human-readable description of a -// Message for debugging. -func DescribeMessage(m pb.Message, f EntryFormatter) string { - var buf bytes.Buffer - fmt.Fprintf(&buf, "%x->%x %v Term:%d Log:%d/%d", m.From, m.To, m.Type, m.Term, m.LogTerm, m.Index) - if m.Reject { - fmt.Fprintf(&buf, " Rejected (Hint: %d)", m.RejectHint) - } - if m.Commit != 0 { - fmt.Fprintf(&buf, " Commit:%d", m.Commit) - } - if len(m.Entries) > 0 { - fmt.Fprintf(&buf, " Entries:[") - for i, e := range m.Entries { - if i != 0 { - buf.WriteString(", ") - } - buf.WriteString(DescribeEntry(e, f)) - } - fmt.Fprintf(&buf, "]") - } - if !IsEmptySnap(m.Snapshot) { - fmt.Fprintf(&buf, " Snapshot: %s", DescribeSnapshot(m.Snapshot)) - } - return buf.String() -} - -// PayloadSize is the size of the payload of this Entry. Notably, it does not -// depend on its Index or Term. -func PayloadSize(e pb.Entry) int { - return len(e.Data) -} - -// DescribeEntry returns a concise human-readable description of an -// Entry for debugging. -func DescribeEntry(e pb.Entry, f EntryFormatter) string { - if f == nil { - f = func(data []byte) string { return fmt.Sprintf("%q", data) } - } - - formatConfChange := func(cc pb.ConfChangeI) string { - // TODO(tbg): give the EntryFormatter a type argument so that it gets - // a chance to expose the Context. - return pb.ConfChangesToString(cc.AsV2().Changes) - } - - var formatted string - switch e.Type { - case pb.EntryNormal: - formatted = f(e.Data) - case pb.EntryConfChange: - var cc pb.ConfChange - if err := cc.Unmarshal(e.Data); err != nil { - formatted = err.Error() - } else { - formatted = formatConfChange(cc) - } - case pb.EntryConfChangeV2: - var cc pb.ConfChangeV2 - if err := cc.Unmarshal(e.Data); err != nil { - formatted = err.Error() - } else { - formatted = formatConfChange(cc) - } - } - if formatted != "" { - formatted = " " + formatted - } - return fmt.Sprintf("%d/%d %s%s", e.Term, e.Index, e.Type, formatted) -} - -// DescribeEntries calls DescribeEntry for each Entry, adding a newline to -// each. -func DescribeEntries(ents []pb.Entry, f EntryFormatter) string { - var buf bytes.Buffer - for _, e := range ents { - _, _ = buf.WriteString(DescribeEntry(e, f) + "\n") - } - return buf.String() -} - -func limitSize(ents []pb.Entry, maxSize uint64) []pb.Entry { - if len(ents) == 0 { - return ents - } - size := ents[0].Size() - var limit int - for limit = 1; limit < len(ents); limit++ { - size += ents[limit].Size() - if uint64(size) > maxSize { - break - } - } - return ents[:limit] -} - -func assertConfStatesEquivalent(l Logger, cs1, cs2 pb.ConfState) { - err := cs1.Equivalent(cs2) - if err == nil { - return - } - l.Panic(err) -} diff --git a/vendor/go.etcd.io/etcd/server/v3/LICENSE b/vendor/go.etcd.io/etcd/server/v3/LICENSE deleted file mode 100644 index d645695673..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/LICENSE +++ /dev/null @@ -1,202 +0,0 @@ - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. diff --git a/vendor/go.etcd.io/etcd/server/v3/auth/doc.go b/vendor/go.etcd.io/etcd/server/v3/auth/doc.go deleted file mode 100644 index 72741a1077..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/auth/doc.go +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package auth provides client role authentication for accessing keys in etcd. -package auth diff --git a/vendor/go.etcd.io/etcd/server/v3/auth/jwt.go b/vendor/go.etcd.io/etcd/server/v3/auth/jwt.go deleted file mode 100644 index d286f92c2e..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/auth/jwt.go +++ /dev/null @@ -1,163 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package auth - -import ( - "context" - "crypto/ecdsa" - "crypto/rsa" - "errors" - "time" - - jwt "github.com/form3tech-oss/jwt-go" - "go.uber.org/zap" -) - -type tokenJWT struct { - lg *zap.Logger - signMethod jwt.SigningMethod - key interface{} - ttl time.Duration - verifyOnly bool -} - -func (t *tokenJWT) enable() {} -func (t *tokenJWT) disable() {} -func (t *tokenJWT) invalidateUser(string) {} -func (t *tokenJWT) genTokenPrefix() (string, error) { return "", nil } - -func (t *tokenJWT) info(ctx context.Context, token string, rev uint64) (*AuthInfo, bool) { - // rev isn't used in JWT, it is only used in simple token - var ( - username string - revision uint64 - ) - - parsed, err := jwt.Parse(token, func(token *jwt.Token) (interface{}, error) { - if token.Method.Alg() != t.signMethod.Alg() { - return nil, errors.New("invalid signing method") - } - switch k := t.key.(type) { - case *rsa.PrivateKey: - return &k.PublicKey, nil - case *ecdsa.PrivateKey: - return &k.PublicKey, nil - default: - return t.key, nil - } - }) - - if err != nil { - t.lg.Warn( - "failed to parse a JWT token", - zap.String("token", token), - zap.Error(err), - ) - return nil, false - } - - claims, ok := parsed.Claims.(jwt.MapClaims) - if !parsed.Valid || !ok { - t.lg.Warn("invalid JWT token", zap.String("token", token)) - return nil, false - } - - username = claims["username"].(string) - revision = uint64(claims["revision"].(float64)) - - return &AuthInfo{Username: username, Revision: revision}, true -} - -func (t *tokenJWT) assign(ctx context.Context, username string, revision uint64) (string, error) { - if t.verifyOnly { - return "", ErrVerifyOnly - } - - // Future work: let a jwt token include permission information would be useful for - // permission checking in proxy side. - tk := jwt.NewWithClaims(t.signMethod, - jwt.MapClaims{ - "username": username, - "revision": revision, - "exp": time.Now().Add(t.ttl).Unix(), - }) - - token, err := tk.SignedString(t.key) - if err != nil { - t.lg.Debug( - "failed to sign a JWT token", - zap.String("user-name", username), - zap.Uint64("revision", revision), - zap.Error(err), - ) - return "", err - } - - t.lg.Debug( - "created/assigned a new JWT token", - zap.String("user-name", username), - zap.Uint64("revision", revision), - zap.String("token", token), - ) - return token, err -} - -func newTokenProviderJWT(lg *zap.Logger, optMap map[string]string) (*tokenJWT, error) { - if lg == nil { - lg = zap.NewNop() - } - var err error - var opts jwtOptions - err = opts.ParseWithDefaults(optMap) - if err != nil { - lg.Error("problem loading JWT options", zap.Error(err)) - return nil, ErrInvalidAuthOpts - } - - var keys = make([]string, 0, len(optMap)) - for k := range optMap { - if !knownOptions[k] { - keys = append(keys, k) - } - } - if len(keys) > 0 { - lg.Warn("unknown JWT options", zap.Strings("keys", keys)) - } - - key, err := opts.Key() - if err != nil { - return nil, err - } - - t := &tokenJWT{ - lg: lg, - ttl: opts.TTL, - signMethod: opts.SignMethod, - key: key, - } - - switch t.signMethod.(type) { - case *jwt.SigningMethodECDSA: - if _, ok := t.key.(*ecdsa.PublicKey); ok { - t.verifyOnly = true - } - case *jwt.SigningMethodRSA, *jwt.SigningMethodRSAPSS: - if _, ok := t.key.(*rsa.PublicKey); ok { - t.verifyOnly = true - } - } - - return t, nil -} diff --git a/vendor/go.etcd.io/etcd/server/v3/auth/metrics.go b/vendor/go.etcd.io/etcd/server/v3/auth/metrics.go deleted file mode 100644 index f7ce279202..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/auth/metrics.go +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package auth - -import ( - "sync" - - "github.com/prometheus/client_golang/prometheus" -) - -var ( - currentAuthRevision = prometheus.NewGaugeFunc(prometheus.GaugeOpts{ - Namespace: "etcd_debugging", - Subsystem: "auth", - Name: "revision", - Help: "The current revision of auth store.", - }, - func() float64 { - reportCurrentAuthRevMu.RLock() - defer reportCurrentAuthRevMu.RUnlock() - return reportCurrentAuthRev() - }, - ) - // overridden by auth store initialization - reportCurrentAuthRevMu sync.RWMutex - reportCurrentAuthRev = func() float64 { return 0 } -) - -func init() { - prometheus.MustRegister(currentAuthRevision) -} diff --git a/vendor/go.etcd.io/etcd/server/v3/auth/nop.go b/vendor/go.etcd.io/etcd/server/v3/auth/nop.go deleted file mode 100644 index d4378747bd..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/auth/nop.go +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright 2018 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package auth - -import ( - "context" -) - -type tokenNop struct{} - -func (t *tokenNop) enable() {} -func (t *tokenNop) disable() {} -func (t *tokenNop) invalidateUser(string) {} -func (t *tokenNop) genTokenPrefix() (string, error) { return "", nil } -func (t *tokenNop) info(ctx context.Context, token string, rev uint64) (*AuthInfo, bool) { - return nil, false -} -func (t *tokenNop) assign(ctx context.Context, username string, revision uint64) (string, error) { - return "", ErrAuthFailed -} -func newTokenProviderNop() (*tokenNop, error) { - return &tokenNop{}, nil -} diff --git a/vendor/go.etcd.io/etcd/server/v3/auth/options.go b/vendor/go.etcd.io/etcd/server/v3/auth/options.go deleted file mode 100644 index c0b039f759..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/auth/options.go +++ /dev/null @@ -1,192 +0,0 @@ -// Copyright 2018 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package auth - -import ( - "crypto/ecdsa" - "crypto/rsa" - "fmt" - "io/ioutil" - "time" - - jwt "github.com/form3tech-oss/jwt-go" -) - -const ( - optSignMethod = "sign-method" - optPublicKey = "pub-key" - optPrivateKey = "priv-key" - optTTL = "ttl" -) - -var knownOptions = map[string]bool{ - optSignMethod: true, - optPublicKey: true, - optPrivateKey: true, - optTTL: true, -} - -var ( - // DefaultTTL will be used when a 'ttl' is not specified - DefaultTTL = 5 * time.Minute -) - -type jwtOptions struct { - SignMethod jwt.SigningMethod - PublicKey []byte - PrivateKey []byte - TTL time.Duration -} - -// ParseWithDefaults will load options from the specified map or set defaults where appropriate -func (opts *jwtOptions) ParseWithDefaults(optMap map[string]string) error { - if opts.TTL == 0 && optMap[optTTL] == "" { - opts.TTL = DefaultTTL - } - - return opts.Parse(optMap) -} - -// Parse will load options from the specified map -func (opts *jwtOptions) Parse(optMap map[string]string) error { - var err error - if ttl := optMap[optTTL]; ttl != "" { - opts.TTL, err = time.ParseDuration(ttl) - if err != nil { - return err - } - } - - if file := optMap[optPublicKey]; file != "" { - opts.PublicKey, err = ioutil.ReadFile(file) - if err != nil { - return err - } - } - - if file := optMap[optPrivateKey]; file != "" { - opts.PrivateKey, err = ioutil.ReadFile(file) - if err != nil { - return err - } - } - - // signing method is a required field - method := optMap[optSignMethod] - opts.SignMethod = jwt.GetSigningMethod(method) - if opts.SignMethod == nil { - return ErrInvalidAuthMethod - } - - return nil -} - -// Key will parse and return the appropriately typed key for the selected signature method -func (opts *jwtOptions) Key() (interface{}, error) { - switch opts.SignMethod.(type) { - case *jwt.SigningMethodRSA, *jwt.SigningMethodRSAPSS: - return opts.rsaKey() - case *jwt.SigningMethodECDSA: - return opts.ecKey() - case *jwt.SigningMethodHMAC: - return opts.hmacKey() - default: - return nil, fmt.Errorf("unsupported signing method: %T", opts.SignMethod) - } -} - -func (opts *jwtOptions) hmacKey() (interface{}, error) { - if len(opts.PrivateKey) == 0 { - return nil, ErrMissingKey - } - return opts.PrivateKey, nil -} - -func (opts *jwtOptions) rsaKey() (interface{}, error) { - var ( - priv *rsa.PrivateKey - pub *rsa.PublicKey - err error - ) - - if len(opts.PrivateKey) > 0 { - priv, err = jwt.ParseRSAPrivateKeyFromPEM(opts.PrivateKey) - if err != nil { - return nil, err - } - } - - if len(opts.PublicKey) > 0 { - pub, err = jwt.ParseRSAPublicKeyFromPEM(opts.PublicKey) - if err != nil { - return nil, err - } - } - - if priv == nil { - if pub == nil { - // Neither key given - return nil, ErrMissingKey - } - // Public key only, can verify tokens - return pub, nil - } - - // both keys provided, make sure they match - if pub != nil && pub.E != priv.E && pub.N.Cmp(priv.N) != 0 { - return nil, ErrKeyMismatch - } - - return priv, nil -} - -func (opts *jwtOptions) ecKey() (interface{}, error) { - var ( - priv *ecdsa.PrivateKey - pub *ecdsa.PublicKey - err error - ) - - if len(opts.PrivateKey) > 0 { - priv, err = jwt.ParseECPrivateKeyFromPEM(opts.PrivateKey) - if err != nil { - return nil, err - } - } - - if len(opts.PublicKey) > 0 { - pub, err = jwt.ParseECPublicKeyFromPEM(opts.PublicKey) - if err != nil { - return nil, err - } - } - - if priv == nil { - if pub == nil { - // Neither key given - return nil, ErrMissingKey - } - // Public key only, can verify tokens - return pub, nil - } - - // both keys provided, make sure they match - if pub != nil && pub.Curve != priv.Curve && - pub.X.Cmp(priv.X) != 0 && pub.Y.Cmp(priv.Y) != 0 { - return nil, ErrKeyMismatch - } - - return priv, nil -} diff --git a/vendor/go.etcd.io/etcd/server/v3/auth/range_perm_cache.go b/vendor/go.etcd.io/etcd/server/v3/auth/range_perm_cache.go deleted file mode 100644 index 7d77b16ea1..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/auth/range_perm_cache.go +++ /dev/null @@ -1,141 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package auth - -import ( - "go.etcd.io/etcd/api/v3/authpb" - "go.etcd.io/etcd/pkg/v3/adt" - "go.etcd.io/etcd/server/v3/mvcc/backend" - - "go.uber.org/zap" -) - -func getMergedPerms(lg *zap.Logger, tx backend.BatchTx, userName string) *unifiedRangePermissions { - user := getUser(lg, tx, userName) - if user == nil { - return nil - } - - readPerms := adt.NewIntervalTree() - writePerms := adt.NewIntervalTree() - - for _, roleName := range user.Roles { - role := getRole(lg, tx, roleName) - if role == nil { - continue - } - - for _, perm := range role.KeyPermission { - var ivl adt.Interval - var rangeEnd []byte - - if len(perm.RangeEnd) != 1 || perm.RangeEnd[0] != 0 { - rangeEnd = perm.RangeEnd - } - - if len(perm.RangeEnd) != 0 { - ivl = adt.NewBytesAffineInterval(perm.Key, rangeEnd) - } else { - ivl = adt.NewBytesAffinePoint(perm.Key) - } - - switch perm.PermType { - case authpb.READWRITE: - readPerms.Insert(ivl, struct{}{}) - writePerms.Insert(ivl, struct{}{}) - - case authpb.READ: - readPerms.Insert(ivl, struct{}{}) - - case authpb.WRITE: - writePerms.Insert(ivl, struct{}{}) - } - } - } - - return &unifiedRangePermissions{ - readPerms: readPerms, - writePerms: writePerms, - } -} - -func checkKeyInterval( - lg *zap.Logger, - cachedPerms *unifiedRangePermissions, - key, rangeEnd []byte, - permtyp authpb.Permission_Type) bool { - if len(rangeEnd) == 1 && rangeEnd[0] == 0 { - rangeEnd = nil - } - - ivl := adt.NewBytesAffineInterval(key, rangeEnd) - switch permtyp { - case authpb.READ: - return cachedPerms.readPerms.Contains(ivl) - case authpb.WRITE: - return cachedPerms.writePerms.Contains(ivl) - default: - lg.Panic("unknown auth type", zap.String("auth-type", permtyp.String())) - } - return false -} - -func checkKeyPoint(lg *zap.Logger, cachedPerms *unifiedRangePermissions, key []byte, permtyp authpb.Permission_Type) bool { - pt := adt.NewBytesAffinePoint(key) - switch permtyp { - case authpb.READ: - return cachedPerms.readPerms.Intersects(pt) - case authpb.WRITE: - return cachedPerms.writePerms.Intersects(pt) - default: - lg.Panic("unknown auth type", zap.String("auth-type", permtyp.String())) - } - return false -} - -func (as *authStore) isRangeOpPermitted(tx backend.BatchTx, userName string, key, rangeEnd []byte, permtyp authpb.Permission_Type) bool { - // assumption: tx is Lock()ed - _, ok := as.rangePermCache[userName] - if !ok { - perms := getMergedPerms(as.lg, tx, userName) - if perms == nil { - as.lg.Error( - "failed to create a merged permission", - zap.String("user-name", userName), - ) - return false - } - as.rangePermCache[userName] = perms - } - - if len(rangeEnd) == 0 { - return checkKeyPoint(as.lg, as.rangePermCache[userName], key, permtyp) - } - - return checkKeyInterval(as.lg, as.rangePermCache[userName], key, rangeEnd, permtyp) -} - -func (as *authStore) clearCachedPerm() { - as.rangePermCache = make(map[string]*unifiedRangePermissions) -} - -func (as *authStore) invalidateCachedPerm(userName string) { - delete(as.rangePermCache, userName) -} - -type unifiedRangePermissions struct { - readPerms adt.IntervalTree - writePerms adt.IntervalTree -} diff --git a/vendor/go.etcd.io/etcd/server/v3/auth/simple_token.go b/vendor/go.etcd.io/etcd/server/v3/auth/simple_token.go deleted file mode 100644 index 7b1b094ae1..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/auth/simple_token.go +++ /dev/null @@ -1,247 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package auth - -// CAUTION: This random number based token mechanism is only for testing purpose. -// JWT based mechanism will be added in the near future. - -import ( - "context" - "crypto/rand" - "fmt" - "math/big" - "strconv" - "strings" - "sync" - "time" - - "go.uber.org/zap" -) - -const ( - letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" - defaultSimpleTokenLength = 16 -) - -// var for testing purposes -// TODO: Remove this mutable global state - as it's race-prone. -var ( - simpleTokenTTLDefault = 300 * time.Second - simpleTokenTTLResolution = 1 * time.Second -) - -type simpleTokenTTLKeeper struct { - tokens map[string]time.Time - donec chan struct{} - stopc chan struct{} - deleteTokenFunc func(string) - mu *sync.Mutex - simpleTokenTTL time.Duration -} - -func (tm *simpleTokenTTLKeeper) stop() { - select { - case tm.stopc <- struct{}{}: - case <-tm.donec: - } - <-tm.donec -} - -func (tm *simpleTokenTTLKeeper) addSimpleToken(token string) { - tm.tokens[token] = time.Now().Add(tm.simpleTokenTTL) -} - -func (tm *simpleTokenTTLKeeper) resetSimpleToken(token string) { - if _, ok := tm.tokens[token]; ok { - tm.tokens[token] = time.Now().Add(tm.simpleTokenTTL) - } -} - -func (tm *simpleTokenTTLKeeper) deleteSimpleToken(token string) { - delete(tm.tokens, token) -} - -func (tm *simpleTokenTTLKeeper) run() { - tokenTicker := time.NewTicker(simpleTokenTTLResolution) - defer func() { - tokenTicker.Stop() - close(tm.donec) - }() - for { - select { - case <-tokenTicker.C: - nowtime := time.Now() - tm.mu.Lock() - for t, tokenendtime := range tm.tokens { - if nowtime.After(tokenendtime) { - tm.deleteTokenFunc(t) - delete(tm.tokens, t) - } - } - tm.mu.Unlock() - case <-tm.stopc: - return - } - } -} - -type tokenSimple struct { - lg *zap.Logger - indexWaiter func(uint64) <-chan struct{} - simpleTokenKeeper *simpleTokenTTLKeeper - simpleTokensMu sync.Mutex - simpleTokens map[string]string // token -> username - simpleTokenTTL time.Duration -} - -func (t *tokenSimple) genTokenPrefix() (string, error) { - ret := make([]byte, defaultSimpleTokenLength) - - for i := 0; i < defaultSimpleTokenLength; i++ { - bInt, err := rand.Int(rand.Reader, big.NewInt(int64(len(letters)))) - if err != nil { - return "", err - } - - ret[i] = letters[bInt.Int64()] - } - - return string(ret), nil -} - -func (t *tokenSimple) assignSimpleTokenToUser(username, token string) { - t.simpleTokensMu.Lock() - defer t.simpleTokensMu.Unlock() - if t.simpleTokenKeeper == nil { - return - } - - _, ok := t.simpleTokens[token] - if ok { - t.lg.Panic( - "failed to assign already-used simple token to a user", - zap.String("user-name", username), - zap.String("token", token), - ) - } - - t.simpleTokens[token] = username - t.simpleTokenKeeper.addSimpleToken(token) -} - -func (t *tokenSimple) invalidateUser(username string) { - if t.simpleTokenKeeper == nil { - return - } - t.simpleTokensMu.Lock() - for token, name := range t.simpleTokens { - if name == username { - delete(t.simpleTokens, token) - t.simpleTokenKeeper.deleteSimpleToken(token) - } - } - t.simpleTokensMu.Unlock() -} - -func (t *tokenSimple) enable() { - if t.simpleTokenTTL <= 0 { - t.simpleTokenTTL = simpleTokenTTLDefault - } - - delf := func(tk string) { - if username, ok := t.simpleTokens[tk]; ok { - t.lg.Info( - "deleted a simple token", - zap.String("user-name", username), - zap.String("token", tk), - ) - delete(t.simpleTokens, tk) - } - } - t.simpleTokenKeeper = &simpleTokenTTLKeeper{ - tokens: make(map[string]time.Time), - donec: make(chan struct{}), - stopc: make(chan struct{}), - deleteTokenFunc: delf, - mu: &t.simpleTokensMu, - simpleTokenTTL: t.simpleTokenTTL, - } - go t.simpleTokenKeeper.run() -} - -func (t *tokenSimple) disable() { - t.simpleTokensMu.Lock() - tk := t.simpleTokenKeeper - t.simpleTokenKeeper = nil - t.simpleTokens = make(map[string]string) // invalidate all tokens - t.simpleTokensMu.Unlock() - if tk != nil { - tk.stop() - } -} - -func (t *tokenSimple) info(ctx context.Context, token string, revision uint64) (*AuthInfo, bool) { - if !t.isValidSimpleToken(ctx, token) { - return nil, false - } - t.simpleTokensMu.Lock() - username, ok := t.simpleTokens[token] - if ok && t.simpleTokenKeeper != nil { - t.simpleTokenKeeper.resetSimpleToken(token) - } - t.simpleTokensMu.Unlock() - return &AuthInfo{Username: username, Revision: revision}, ok -} - -func (t *tokenSimple) assign(ctx context.Context, username string, rev uint64) (string, error) { - // rev isn't used in simple token, it is only used in JWT - index := ctx.Value(AuthenticateParamIndex{}).(uint64) - simpleTokenPrefix := ctx.Value(AuthenticateParamSimpleTokenPrefix{}).(string) - token := fmt.Sprintf("%s.%d", simpleTokenPrefix, index) - t.assignSimpleTokenToUser(username, token) - - return token, nil -} - -func (t *tokenSimple) isValidSimpleToken(ctx context.Context, token string) bool { - splitted := strings.Split(token, ".") - if len(splitted) != 2 { - return false - } - index, err := strconv.ParseUint(splitted[1], 10, 0) - if err != nil { - return false - } - - select { - case <-t.indexWaiter(uint64(index)): - return true - case <-ctx.Done(): - } - - return false -} - -func newTokenProviderSimple(lg *zap.Logger, indexWaiter func(uint64) <-chan struct{}, TokenTTL time.Duration) *tokenSimple { - if lg == nil { - lg = zap.NewNop() - } - return &tokenSimple{ - lg: lg, - simpleTokens: make(map[string]string), - indexWaiter: indexWaiter, - simpleTokenTTL: TokenTTL, - } -} diff --git a/vendor/go.etcd.io/etcd/server/v3/auth/store.go b/vendor/go.etcd.io/etcd/server/v3/auth/store.go deleted file mode 100644 index 44c1d35fda..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/auth/store.go +++ /dev/null @@ -1,1315 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package auth - -import ( - "bytes" - "context" - "encoding/base64" - "encoding/binary" - "errors" - "sort" - "strings" - "sync" - "sync/atomic" - "time" - - "go.etcd.io/etcd/api/v3/authpb" - pb "go.etcd.io/etcd/api/v3/etcdserverpb" - "go.etcd.io/etcd/api/v3/v3rpc/rpctypes" - "go.etcd.io/etcd/server/v3/mvcc/backend" - "go.etcd.io/etcd/server/v3/mvcc/buckets" - - "go.uber.org/zap" - "golang.org/x/crypto/bcrypt" - "google.golang.org/grpc/credentials" - "google.golang.org/grpc/metadata" - "google.golang.org/grpc/peer" -) - -var ( - enableFlagKey = []byte("authEnabled") - authEnabled = []byte{1} - authDisabled = []byte{0} - - revisionKey = []byte("authRevision") - - ErrRootUserNotExist = errors.New("auth: root user does not exist") - ErrRootRoleNotExist = errors.New("auth: root user does not have root role") - ErrUserAlreadyExist = errors.New("auth: user already exists") - ErrUserEmpty = errors.New("auth: user name is empty") - ErrUserNotFound = errors.New("auth: user not found") - ErrRoleAlreadyExist = errors.New("auth: role already exists") - ErrRoleNotFound = errors.New("auth: role not found") - ErrRoleEmpty = errors.New("auth: role name is empty") - ErrPermissionNotGiven = errors.New("auth: permission not given") - ErrAuthFailed = errors.New("auth: authentication failed, invalid user ID or password") - ErrNoPasswordUser = errors.New("auth: authentication failed, password was given for no password user") - ErrPermissionDenied = errors.New("auth: permission denied") - ErrRoleNotGranted = errors.New("auth: role is not granted to the user") - ErrPermissionNotGranted = errors.New("auth: permission is not granted to the role") - ErrAuthNotEnabled = errors.New("auth: authentication is not enabled") - ErrAuthOldRevision = errors.New("auth: revision in header is old") - ErrInvalidAuthToken = errors.New("auth: invalid auth token") - ErrInvalidAuthOpts = errors.New("auth: invalid auth options") - ErrInvalidAuthMgmt = errors.New("auth: invalid auth management") - ErrInvalidAuthMethod = errors.New("auth: invalid auth signature method") - ErrMissingKey = errors.New("auth: missing key data") - ErrKeyMismatch = errors.New("auth: public and private keys don't match") - ErrVerifyOnly = errors.New("auth: token signing attempted with verify-only key") -) - -const ( - rootUser = "root" - rootRole = "root" - - tokenTypeSimple = "simple" - tokenTypeJWT = "jwt" - - revBytesLen = 8 -) - -type AuthInfo struct { - Username string - Revision uint64 -} - -// AuthenticateParamIndex is used for a key of context in the parameters of Authenticate() -type AuthenticateParamIndex struct{} - -// AuthenticateParamSimpleTokenPrefix is used for a key of context in the parameters of Authenticate() -type AuthenticateParamSimpleTokenPrefix struct{} - -// AuthStore defines auth storage interface. -type AuthStore interface { - // AuthEnable turns on the authentication feature - AuthEnable() error - - // AuthDisable turns off the authentication feature - AuthDisable() - - // IsAuthEnabled returns true if the authentication feature is enabled. - IsAuthEnabled() bool - - // Authenticate does authentication based on given user name and password - Authenticate(ctx context.Context, username, password string) (*pb.AuthenticateResponse, error) - - // Recover recovers the state of auth store from the given backend - Recover(b backend.Backend) - - // UserAdd adds a new user - UserAdd(r *pb.AuthUserAddRequest) (*pb.AuthUserAddResponse, error) - - // UserDelete deletes a user - UserDelete(r *pb.AuthUserDeleteRequest) (*pb.AuthUserDeleteResponse, error) - - // UserChangePassword changes a password of a user - UserChangePassword(r *pb.AuthUserChangePasswordRequest) (*pb.AuthUserChangePasswordResponse, error) - - // UserGrantRole grants a role to the user - UserGrantRole(r *pb.AuthUserGrantRoleRequest) (*pb.AuthUserGrantRoleResponse, error) - - // UserGet gets the detailed information of a users - UserGet(r *pb.AuthUserGetRequest) (*pb.AuthUserGetResponse, error) - - // UserRevokeRole revokes a role of a user - UserRevokeRole(r *pb.AuthUserRevokeRoleRequest) (*pb.AuthUserRevokeRoleResponse, error) - - // RoleAdd adds a new role - RoleAdd(r *pb.AuthRoleAddRequest) (*pb.AuthRoleAddResponse, error) - - // RoleGrantPermission grants a permission to a role - RoleGrantPermission(r *pb.AuthRoleGrantPermissionRequest) (*pb.AuthRoleGrantPermissionResponse, error) - - // RoleGet gets the detailed information of a role - RoleGet(r *pb.AuthRoleGetRequest) (*pb.AuthRoleGetResponse, error) - - // RoleRevokePermission gets the detailed information of a role - RoleRevokePermission(r *pb.AuthRoleRevokePermissionRequest) (*pb.AuthRoleRevokePermissionResponse, error) - - // RoleDelete gets the detailed information of a role - RoleDelete(r *pb.AuthRoleDeleteRequest) (*pb.AuthRoleDeleteResponse, error) - - // UserList gets a list of all users - UserList(r *pb.AuthUserListRequest) (*pb.AuthUserListResponse, error) - - // RoleList gets a list of all roles - RoleList(r *pb.AuthRoleListRequest) (*pb.AuthRoleListResponse, error) - - // IsPutPermitted checks put permission of the user - IsPutPermitted(authInfo *AuthInfo, key []byte) error - - // IsRangePermitted checks range permission of the user - IsRangePermitted(authInfo *AuthInfo, key, rangeEnd []byte) error - - // IsDeleteRangePermitted checks delete-range permission of the user - IsDeleteRangePermitted(authInfo *AuthInfo, key, rangeEnd []byte) error - - // IsAdminPermitted checks admin permission of the user - IsAdminPermitted(authInfo *AuthInfo) error - - // GenTokenPrefix produces a random string in a case of simple token - // in a case of JWT, it produces an empty string - GenTokenPrefix() (string, error) - - // Revision gets current revision of authStore - Revision() uint64 - - // CheckPassword checks a given pair of username and password is correct - CheckPassword(username, password string) (uint64, error) - - // Close does cleanup of AuthStore - Close() error - - // AuthInfoFromCtx gets AuthInfo from gRPC's context - AuthInfoFromCtx(ctx context.Context) (*AuthInfo, error) - - // AuthInfoFromTLS gets AuthInfo from TLS info of gRPC's context - AuthInfoFromTLS(ctx context.Context) *AuthInfo - - // WithRoot generates and installs a token that can be used as a root credential - WithRoot(ctx context.Context) context.Context - - // HasRole checks that user has role - HasRole(user, role string) bool - - // BcryptCost gets strength of hashing bcrypted auth password - BcryptCost() int -} - -type TokenProvider interface { - info(ctx context.Context, token string, revision uint64) (*AuthInfo, bool) - assign(ctx context.Context, username string, revision uint64) (string, error) - enable() - disable() - - invalidateUser(string) - genTokenPrefix() (string, error) -} - -type authStore struct { - // atomic operations; need 64-bit align, or 32-bit tests will crash - revision uint64 - - lg *zap.Logger - be backend.Backend - enabled bool - enabledMu sync.RWMutex - - rangePermCache map[string]*unifiedRangePermissions // username -> unifiedRangePermissions - - tokenProvider TokenProvider - bcryptCost int // the algorithm cost / strength for hashing auth passwords -} - -func (as *authStore) AuthEnable() error { - as.enabledMu.Lock() - defer as.enabledMu.Unlock() - if as.enabled { - as.lg.Info("authentication is already enabled; ignored auth enable request") - return nil - } - b := as.be - tx := b.BatchTx() - tx.Lock() - defer func() { - tx.Unlock() - b.ForceCommit() - }() - - u := getUser(as.lg, tx, rootUser) - if u == nil { - return ErrRootUserNotExist - } - - if !hasRootRole(u) { - return ErrRootRoleNotExist - } - - tx.UnsafePut(buckets.Auth, enableFlagKey, authEnabled) - - as.enabled = true - as.tokenProvider.enable() - - as.rangePermCache = make(map[string]*unifiedRangePermissions) - - as.setRevision(getRevision(tx)) - - as.lg.Info("enabled authentication") - return nil -} - -func (as *authStore) AuthDisable() { - as.enabledMu.Lock() - defer as.enabledMu.Unlock() - if !as.enabled { - return - } - b := as.be - tx := b.BatchTx() - tx.Lock() - tx.UnsafePut(buckets.Auth, enableFlagKey, authDisabled) - as.commitRevision(tx) - tx.Unlock() - b.ForceCommit() - - as.enabled = false - as.tokenProvider.disable() - - as.lg.Info("disabled authentication") -} - -func (as *authStore) Close() error { - as.enabledMu.Lock() - defer as.enabledMu.Unlock() - if !as.enabled { - return nil - } - as.tokenProvider.disable() - return nil -} - -func (as *authStore) Authenticate(ctx context.Context, username, password string) (*pb.AuthenticateResponse, error) { - if !as.IsAuthEnabled() { - return nil, ErrAuthNotEnabled - } - - tx := as.be.BatchTx() - tx.Lock() - defer tx.Unlock() - - user := getUser(as.lg, tx, username) - if user == nil { - return nil, ErrAuthFailed - } - - if user.Options != nil && user.Options.NoPassword { - return nil, ErrAuthFailed - } - - // Password checking is already performed in the API layer, so we don't need to check for now. - // Staleness of password can be detected with OCC in the API layer, too. - - token, err := as.tokenProvider.assign(ctx, username, as.Revision()) - if err != nil { - return nil, err - } - - as.lg.Debug( - "authenticated a user", - zap.String("user-name", username), - zap.String("token", token), - ) - return &pb.AuthenticateResponse{Token: token}, nil -} - -func (as *authStore) CheckPassword(username, password string) (uint64, error) { - if !as.IsAuthEnabled() { - return 0, ErrAuthNotEnabled - } - - var user *authpb.User - // CompareHashAndPassword is very expensive, so we use closures - // to avoid putting it in the critical section of the tx lock. - revision, err := func() (uint64, error) { - tx := as.be.BatchTx() - tx.Lock() - defer tx.Unlock() - - user = getUser(as.lg, tx, username) - if user == nil { - return 0, ErrAuthFailed - } - - if user.Options != nil && user.Options.NoPassword { - return 0, ErrNoPasswordUser - } - - return getRevision(tx), nil - }() - if err != nil { - return 0, err - } - - if bcrypt.CompareHashAndPassword(user.Password, []byte(password)) != nil { - as.lg.Info("invalid password", zap.String("user-name", username)) - return 0, ErrAuthFailed - } - return revision, nil -} - -func (as *authStore) Recover(be backend.Backend) { - enabled := false - as.be = be - tx := be.BatchTx() - tx.Lock() - _, vs := tx.UnsafeRange(buckets.Auth, enableFlagKey, nil, 0) - if len(vs) == 1 { - if bytes.Equal(vs[0], authEnabled) { - enabled = true - } - } - - as.setRevision(getRevision(tx)) - - tx.Unlock() - - as.enabledMu.Lock() - as.enabled = enabled - as.enabledMu.Unlock() -} - -func (as *authStore) selectPassword(password string, hashedPassword string) ([]byte, error) { - if password != "" && hashedPassword == "" { - // This path is for processing log entries created by etcd whose version is older than 3.5 - return bcrypt.GenerateFromPassword([]byte(password), as.bcryptCost) - } - return base64.StdEncoding.DecodeString(hashedPassword) -} - -func (as *authStore) UserAdd(r *pb.AuthUserAddRequest) (*pb.AuthUserAddResponse, error) { - if len(r.Name) == 0 { - return nil, ErrUserEmpty - } - - tx := as.be.BatchTx() - tx.Lock() - defer tx.Unlock() - - user := getUser(as.lg, tx, r.Name) - if user != nil { - return nil, ErrUserAlreadyExist - } - - options := r.Options - if options == nil { - options = &authpb.UserAddOptions{ - NoPassword: false, - } - } - - var password []byte - var err error - - if !options.NoPassword { - password, err = as.selectPassword(r.Password, r.HashedPassword) - if err != nil { - return nil, ErrNoPasswordUser - } - } - - newUser := &authpb.User{ - Name: []byte(r.Name), - Password: password, - Options: options, - } - - putUser(as.lg, tx, newUser) - - as.commitRevision(tx) - - as.lg.Info("added a user", zap.String("user-name", r.Name)) - return &pb.AuthUserAddResponse{}, nil -} - -func (as *authStore) UserDelete(r *pb.AuthUserDeleteRequest) (*pb.AuthUserDeleteResponse, error) { - if as.enabled && r.Name == rootUser { - as.lg.Error("cannot delete 'root' user", zap.String("user-name", r.Name)) - return nil, ErrInvalidAuthMgmt - } - - tx := as.be.BatchTx() - tx.Lock() - defer tx.Unlock() - - user := getUser(as.lg, tx, r.Name) - if user == nil { - return nil, ErrUserNotFound - } - - delUser(tx, r.Name) - - as.commitRevision(tx) - - as.invalidateCachedPerm(r.Name) - as.tokenProvider.invalidateUser(r.Name) - - as.lg.Info( - "deleted a user", - zap.String("user-name", r.Name), - zap.Strings("user-roles", user.Roles), - ) - return &pb.AuthUserDeleteResponse{}, nil -} - -func (as *authStore) UserChangePassword(r *pb.AuthUserChangePasswordRequest) (*pb.AuthUserChangePasswordResponse, error) { - tx := as.be.BatchTx() - tx.Lock() - defer tx.Unlock() - - user := getUser(as.lg, tx, r.Name) - if user == nil { - return nil, ErrUserNotFound - } - - var password []byte - var err error - - if !user.Options.NoPassword { - password, err = as.selectPassword(r.Password, r.HashedPassword) - if err != nil { - return nil, ErrNoPasswordUser - } - } - - updatedUser := &authpb.User{ - Name: []byte(r.Name), - Roles: user.Roles, - Password: password, - Options: user.Options, - } - - putUser(as.lg, tx, updatedUser) - - as.commitRevision(tx) - - as.invalidateCachedPerm(r.Name) - as.tokenProvider.invalidateUser(r.Name) - - as.lg.Info( - "changed a password of a user", - zap.String("user-name", r.Name), - zap.Strings("user-roles", user.Roles), - ) - return &pb.AuthUserChangePasswordResponse{}, nil -} - -func (as *authStore) UserGrantRole(r *pb.AuthUserGrantRoleRequest) (*pb.AuthUserGrantRoleResponse, error) { - tx := as.be.BatchTx() - tx.Lock() - defer tx.Unlock() - - user := getUser(as.lg, tx, r.User) - if user == nil { - return nil, ErrUserNotFound - } - - if r.Role != rootRole { - role := getRole(as.lg, tx, r.Role) - if role == nil { - return nil, ErrRoleNotFound - } - } - - idx := sort.SearchStrings(user.Roles, r.Role) - if idx < len(user.Roles) && user.Roles[idx] == r.Role { - as.lg.Warn( - "ignored grant role request to a user", - zap.String("user-name", r.User), - zap.Strings("user-roles", user.Roles), - zap.String("duplicate-role-name", r.Role), - ) - return &pb.AuthUserGrantRoleResponse{}, nil - } - - user.Roles = append(user.Roles, r.Role) - sort.Strings(user.Roles) - - putUser(as.lg, tx, user) - - as.invalidateCachedPerm(r.User) - - as.commitRevision(tx) - - as.lg.Info( - "granted a role to a user", - zap.String("user-name", r.User), - zap.Strings("user-roles", user.Roles), - zap.String("added-role-name", r.Role), - ) - return &pb.AuthUserGrantRoleResponse{}, nil -} - -func (as *authStore) UserGet(r *pb.AuthUserGetRequest) (*pb.AuthUserGetResponse, error) { - tx := as.be.BatchTx() - tx.Lock() - user := getUser(as.lg, tx, r.Name) - tx.Unlock() - - if user == nil { - return nil, ErrUserNotFound - } - - var resp pb.AuthUserGetResponse - resp.Roles = append(resp.Roles, user.Roles...) - return &resp, nil -} - -func (as *authStore) UserList(r *pb.AuthUserListRequest) (*pb.AuthUserListResponse, error) { - tx := as.be.BatchTx() - tx.Lock() - users := getAllUsers(as.lg, tx) - tx.Unlock() - - resp := &pb.AuthUserListResponse{Users: make([]string, len(users))} - for i := range users { - resp.Users[i] = string(users[i].Name) - } - return resp, nil -} - -func (as *authStore) UserRevokeRole(r *pb.AuthUserRevokeRoleRequest) (*pb.AuthUserRevokeRoleResponse, error) { - if as.enabled && r.Name == rootUser && r.Role == rootRole { - as.lg.Error( - "'root' user cannot revoke 'root' role", - zap.String("user-name", r.Name), - zap.String("role-name", r.Role), - ) - return nil, ErrInvalidAuthMgmt - } - - tx := as.be.BatchTx() - tx.Lock() - defer tx.Unlock() - - user := getUser(as.lg, tx, r.Name) - if user == nil { - return nil, ErrUserNotFound - } - - updatedUser := &authpb.User{ - Name: user.Name, - Password: user.Password, - Options: user.Options, - } - - for _, role := range user.Roles { - if role != r.Role { - updatedUser.Roles = append(updatedUser.Roles, role) - } - } - - if len(updatedUser.Roles) == len(user.Roles) { - return nil, ErrRoleNotGranted - } - - putUser(as.lg, tx, updatedUser) - - as.invalidateCachedPerm(r.Name) - - as.commitRevision(tx) - - as.lg.Info( - "revoked a role from a user", - zap.String("user-name", r.Name), - zap.Strings("old-user-roles", user.Roles), - zap.Strings("new-user-roles", updatedUser.Roles), - zap.String("revoked-role-name", r.Role), - ) - return &pb.AuthUserRevokeRoleResponse{}, nil -} - -func (as *authStore) RoleGet(r *pb.AuthRoleGetRequest) (*pb.AuthRoleGetResponse, error) { - tx := as.be.BatchTx() - tx.Lock() - defer tx.Unlock() - - var resp pb.AuthRoleGetResponse - - role := getRole(as.lg, tx, r.Role) - if role == nil { - return nil, ErrRoleNotFound - } - resp.Perm = append(resp.Perm, role.KeyPermission...) - return &resp, nil -} - -func (as *authStore) RoleList(r *pb.AuthRoleListRequest) (*pb.AuthRoleListResponse, error) { - tx := as.be.BatchTx() - tx.Lock() - roles := getAllRoles(as.lg, tx) - tx.Unlock() - - resp := &pb.AuthRoleListResponse{Roles: make([]string, len(roles))} - for i := range roles { - resp.Roles[i] = string(roles[i].Name) - } - return resp, nil -} - -func (as *authStore) RoleRevokePermission(r *pb.AuthRoleRevokePermissionRequest) (*pb.AuthRoleRevokePermissionResponse, error) { - tx := as.be.BatchTx() - tx.Lock() - defer tx.Unlock() - - role := getRole(as.lg, tx, r.Role) - if role == nil { - return nil, ErrRoleNotFound - } - - updatedRole := &authpb.Role{ - Name: role.Name, - } - - for _, perm := range role.KeyPermission { - if !bytes.Equal(perm.Key, r.Key) || !bytes.Equal(perm.RangeEnd, r.RangeEnd) { - updatedRole.KeyPermission = append(updatedRole.KeyPermission, perm) - } - } - - if len(role.KeyPermission) == len(updatedRole.KeyPermission) { - return nil, ErrPermissionNotGranted - } - - putRole(as.lg, tx, updatedRole) - - // TODO(mitake): currently single role update invalidates every cache - // It should be optimized. - as.clearCachedPerm() - - as.commitRevision(tx) - - as.lg.Info( - "revoked a permission on range", - zap.String("role-name", r.Role), - zap.String("key", string(r.Key)), - zap.String("range-end", string(r.RangeEnd)), - ) - return &pb.AuthRoleRevokePermissionResponse{}, nil -} - -func (as *authStore) RoleDelete(r *pb.AuthRoleDeleteRequest) (*pb.AuthRoleDeleteResponse, error) { - if as.enabled && r.Role == rootRole { - as.lg.Error("cannot delete 'root' role", zap.String("role-name", r.Role)) - return nil, ErrInvalidAuthMgmt - } - - tx := as.be.BatchTx() - tx.Lock() - defer tx.Unlock() - - role := getRole(as.lg, tx, r.Role) - if role == nil { - return nil, ErrRoleNotFound - } - - delRole(tx, r.Role) - - users := getAllUsers(as.lg, tx) - for _, user := range users { - updatedUser := &authpb.User{ - Name: user.Name, - Password: user.Password, - Options: user.Options, - } - - for _, role := range user.Roles { - if role != r.Role { - updatedUser.Roles = append(updatedUser.Roles, role) - } - } - - if len(updatedUser.Roles) == len(user.Roles) { - continue - } - - putUser(as.lg, tx, updatedUser) - - as.invalidateCachedPerm(string(user.Name)) - } - - as.commitRevision(tx) - - as.lg.Info("deleted a role", zap.String("role-name", r.Role)) - return &pb.AuthRoleDeleteResponse{}, nil -} - -func (as *authStore) RoleAdd(r *pb.AuthRoleAddRequest) (*pb.AuthRoleAddResponse, error) { - if len(r.Name) == 0 { - return nil, ErrRoleEmpty - } - - tx := as.be.BatchTx() - tx.Lock() - defer tx.Unlock() - - role := getRole(as.lg, tx, r.Name) - if role != nil { - return nil, ErrRoleAlreadyExist - } - - newRole := &authpb.Role{ - Name: []byte(r.Name), - } - - putRole(as.lg, tx, newRole) - - as.commitRevision(tx) - - as.lg.Info("created a role", zap.String("role-name", r.Name)) - return &pb.AuthRoleAddResponse{}, nil -} - -func (as *authStore) authInfoFromToken(ctx context.Context, token string) (*AuthInfo, bool) { - return as.tokenProvider.info(ctx, token, as.Revision()) -} - -type permSlice []*authpb.Permission - -func (perms permSlice) Len() int { - return len(perms) -} - -func (perms permSlice) Less(i, j int) bool { - return bytes.Compare(perms[i].Key, perms[j].Key) < 0 -} - -func (perms permSlice) Swap(i, j int) { - perms[i], perms[j] = perms[j], perms[i] -} - -func (as *authStore) RoleGrantPermission(r *pb.AuthRoleGrantPermissionRequest) (*pb.AuthRoleGrantPermissionResponse, error) { - if r.Perm == nil { - return nil, ErrPermissionNotGiven - } - - tx := as.be.BatchTx() - tx.Lock() - defer tx.Unlock() - - role := getRole(as.lg, tx, r.Name) - if role == nil { - return nil, ErrRoleNotFound - } - - idx := sort.Search(len(role.KeyPermission), func(i int) bool { - return bytes.Compare(role.KeyPermission[i].Key, r.Perm.Key) >= 0 - }) - - if idx < len(role.KeyPermission) && bytes.Equal(role.KeyPermission[idx].Key, r.Perm.Key) && bytes.Equal(role.KeyPermission[idx].RangeEnd, r.Perm.RangeEnd) { - // update existing permission - role.KeyPermission[idx].PermType = r.Perm.PermType - } else { - // append new permission to the role - newPerm := &authpb.Permission{ - Key: r.Perm.Key, - RangeEnd: r.Perm.RangeEnd, - PermType: r.Perm.PermType, - } - - role.KeyPermission = append(role.KeyPermission, newPerm) - sort.Sort(permSlice(role.KeyPermission)) - } - - putRole(as.lg, tx, role) - - // TODO(mitake): currently single role update invalidates every cache - // It should be optimized. - as.clearCachedPerm() - - as.commitRevision(tx) - - as.lg.Info( - "granted/updated a permission to a user", - zap.String("user-name", r.Name), - zap.String("permission-name", authpb.Permission_Type_name[int32(r.Perm.PermType)]), - ) - return &pb.AuthRoleGrantPermissionResponse{}, nil -} - -func (as *authStore) isOpPermitted(userName string, revision uint64, key, rangeEnd []byte, permTyp authpb.Permission_Type) error { - // TODO(mitake): this function would be costly so we need a caching mechanism - if !as.IsAuthEnabled() { - return nil - } - - // only gets rev == 0 when passed AuthInfo{}; no user given - if revision == 0 { - return ErrUserEmpty - } - rev := as.Revision() - if revision < rev { - as.lg.Warn("request auth revision is less than current node auth revision", - zap.Uint64("current node auth revision", rev), - zap.Uint64("request auth revision", revision), - zap.ByteString("request key", key), - zap.Error(ErrAuthOldRevision)) - return ErrAuthOldRevision - } - - tx := as.be.BatchTx() - tx.Lock() - defer tx.Unlock() - - user := getUser(as.lg, tx, userName) - if user == nil { - as.lg.Error("cannot find a user for permission check", zap.String("user-name", userName)) - return ErrPermissionDenied - } - - // root role should have permission on all ranges - if hasRootRole(user) { - return nil - } - - if as.isRangeOpPermitted(tx, userName, key, rangeEnd, permTyp) { - return nil - } - - return ErrPermissionDenied -} - -func (as *authStore) IsPutPermitted(authInfo *AuthInfo, key []byte) error { - return as.isOpPermitted(authInfo.Username, authInfo.Revision, key, nil, authpb.WRITE) -} - -func (as *authStore) IsRangePermitted(authInfo *AuthInfo, key, rangeEnd []byte) error { - return as.isOpPermitted(authInfo.Username, authInfo.Revision, key, rangeEnd, authpb.READ) -} - -func (as *authStore) IsDeleteRangePermitted(authInfo *AuthInfo, key, rangeEnd []byte) error { - return as.isOpPermitted(authInfo.Username, authInfo.Revision, key, rangeEnd, authpb.WRITE) -} - -func (as *authStore) IsAdminPermitted(authInfo *AuthInfo) error { - if !as.IsAuthEnabled() { - return nil - } - if authInfo == nil || authInfo.Username == "" { - return ErrUserEmpty - } - - tx := as.be.BatchTx() - tx.Lock() - u := getUser(as.lg, tx, authInfo.Username) - tx.Unlock() - - if u == nil { - return ErrUserNotFound - } - - if !hasRootRole(u) { - return ErrPermissionDenied - } - - return nil -} - -func getUser(lg *zap.Logger, tx backend.BatchTx, username string) *authpb.User { - _, vs := tx.UnsafeRange(buckets.AuthUsers, []byte(username), nil, 0) - if len(vs) == 0 { - return nil - } - - user := &authpb.User{} - err := user.Unmarshal(vs[0]) - if err != nil { - lg.Panic( - "failed to unmarshal 'authpb.User'", - zap.String("user-name", username), - zap.Error(err), - ) - } - return user -} - -func getAllUsers(lg *zap.Logger, tx backend.BatchTx) []*authpb.User { - _, vs := tx.UnsafeRange(buckets.AuthUsers, []byte{0}, []byte{0xff}, -1) - if len(vs) == 0 { - return nil - } - - users := make([]*authpb.User, len(vs)) - for i := range vs { - user := &authpb.User{} - err := user.Unmarshal(vs[i]) - if err != nil { - lg.Panic("failed to unmarshal 'authpb.User'", zap.Error(err)) - } - users[i] = user - } - return users -} - -func putUser(lg *zap.Logger, tx backend.BatchTx, user *authpb.User) { - b, err := user.Marshal() - if err != nil { - lg.Panic("failed to unmarshal 'authpb.User'", zap.Error(err)) - } - tx.UnsafePut(buckets.AuthUsers, user.Name, b) -} - -func delUser(tx backend.BatchTx, username string) { - tx.UnsafeDelete(buckets.AuthUsers, []byte(username)) -} - -func getRole(lg *zap.Logger, tx backend.BatchTx, rolename string) *authpb.Role { - _, vs := tx.UnsafeRange(buckets.AuthRoles, []byte(rolename), nil, 0) - if len(vs) == 0 { - return nil - } - - role := &authpb.Role{} - err := role.Unmarshal(vs[0]) - if err != nil { - lg.Panic("failed to unmarshal 'authpb.Role'", zap.Error(err)) - } - return role -} - -func getAllRoles(lg *zap.Logger, tx backend.BatchTx) []*authpb.Role { - _, vs := tx.UnsafeRange(buckets.AuthRoles, []byte{0}, []byte{0xff}, -1) - if len(vs) == 0 { - return nil - } - - roles := make([]*authpb.Role, len(vs)) - for i := range vs { - role := &authpb.Role{} - err := role.Unmarshal(vs[i]) - if err != nil { - lg.Panic("failed to unmarshal 'authpb.Role'", zap.Error(err)) - } - roles[i] = role - } - return roles -} - -func putRole(lg *zap.Logger, tx backend.BatchTx, role *authpb.Role) { - b, err := role.Marshal() - if err != nil { - lg.Panic( - "failed to marshal 'authpb.Role'", - zap.String("role-name", string(role.Name)), - zap.Error(err), - ) - } - - tx.UnsafePut(buckets.AuthRoles, role.Name, b) -} - -func delRole(tx backend.BatchTx, rolename string) { - tx.UnsafeDelete(buckets.AuthRoles, []byte(rolename)) -} - -func (as *authStore) IsAuthEnabled() bool { - as.enabledMu.RLock() - defer as.enabledMu.RUnlock() - return as.enabled -} - -// NewAuthStore creates a new AuthStore. -func NewAuthStore(lg *zap.Logger, be backend.Backend, tp TokenProvider, bcryptCost int) *authStore { - if lg == nil { - lg = zap.NewNop() - } - - if bcryptCost < bcrypt.MinCost || bcryptCost > bcrypt.MaxCost { - lg.Warn( - "use default bcrypt cost instead of the invalid given cost", - zap.Int("min-cost", bcrypt.MinCost), - zap.Int("max-cost", bcrypt.MaxCost), - zap.Int("default-cost", bcrypt.DefaultCost), - zap.Int("given-cost", bcryptCost), - ) - bcryptCost = bcrypt.DefaultCost - } - - tx := be.BatchTx() - tx.Lock() - - tx.UnsafeCreateBucket(buckets.Auth) - tx.UnsafeCreateBucket(buckets.AuthUsers) - tx.UnsafeCreateBucket(buckets.AuthRoles) - - enabled := false - _, vs := tx.UnsafeRange(buckets.Auth, enableFlagKey, nil, 0) - if len(vs) == 1 { - if bytes.Equal(vs[0], authEnabled) { - enabled = true - } - } - - as := &authStore{ - revision: getRevision(tx), - lg: lg, - be: be, - enabled: enabled, - rangePermCache: make(map[string]*unifiedRangePermissions), - tokenProvider: tp, - bcryptCost: bcryptCost, - } - - if enabled { - as.tokenProvider.enable() - } - - if as.Revision() == 0 { - as.commitRevision(tx) - } - - as.setupMetricsReporter() - - tx.Unlock() - be.ForceCommit() - - return as -} - -func hasRootRole(u *authpb.User) bool { - // u.Roles is sorted in UserGrantRole(), so we can use binary search. - idx := sort.SearchStrings(u.Roles, rootRole) - return idx != len(u.Roles) && u.Roles[idx] == rootRole -} - -func (as *authStore) commitRevision(tx backend.BatchTx) { - atomic.AddUint64(&as.revision, 1) - revBytes := make([]byte, revBytesLen) - binary.BigEndian.PutUint64(revBytes, as.Revision()) - tx.UnsafePut(buckets.Auth, revisionKey, revBytes) -} - -func getRevision(tx backend.BatchTx) uint64 { - _, vs := tx.UnsafeRange(buckets.Auth, revisionKey, nil, 0) - if len(vs) != 1 { - // this can happen in the initialization phase - return 0 - } - return binary.BigEndian.Uint64(vs[0]) -} - -func (as *authStore) setRevision(rev uint64) { - atomic.StoreUint64(&as.revision, rev) -} - -func (as *authStore) Revision() uint64 { - return atomic.LoadUint64(&as.revision) -} - -func (as *authStore) AuthInfoFromTLS(ctx context.Context) (ai *AuthInfo) { - peer, ok := peer.FromContext(ctx) - if !ok || peer == nil || peer.AuthInfo == nil { - return nil - } - - tlsInfo := peer.AuthInfo.(credentials.TLSInfo) - for _, chains := range tlsInfo.State.VerifiedChains { - if len(chains) < 1 { - continue - } - ai = &AuthInfo{ - Username: chains[0].Subject.CommonName, - Revision: as.Revision(), - } - md, ok := metadata.FromIncomingContext(ctx) - if !ok { - return nil - } - - // gRPC-gateway proxy request to etcd server includes Grpcgateway-Accept - // header. The proxy uses etcd client server certificate. If the certificate - // has a CommonName we should never use this for authentication. - if gw := md["grpcgateway-accept"]; len(gw) > 0 { - as.lg.Warn( - "ignoring common name in gRPC-gateway proxy request", - zap.String("common-name", ai.Username), - zap.String("user-name", ai.Username), - zap.Uint64("revision", ai.Revision), - ) - return nil - } - as.lg.Debug( - "found command name", - zap.String("common-name", ai.Username), - zap.String("user-name", ai.Username), - zap.Uint64("revision", ai.Revision), - ) - break - } - return ai -} - -func (as *authStore) AuthInfoFromCtx(ctx context.Context) (*AuthInfo, error) { - md, ok := metadata.FromIncomingContext(ctx) - if !ok { - return nil, nil - } - - //TODO(mitake|hexfusion) review unifying key names - ts, ok := md[rpctypes.TokenFieldNameGRPC] - if !ok { - ts, ok = md[rpctypes.TokenFieldNameSwagger] - } - if !ok { - return nil, nil - } - - token := ts[0] - authInfo, uok := as.authInfoFromToken(ctx, token) - if !uok { - as.lg.Warn("invalid auth token", zap.String("token", token)) - return nil, ErrInvalidAuthToken - } - - return authInfo, nil -} - -func (as *authStore) GenTokenPrefix() (string, error) { - return as.tokenProvider.genTokenPrefix() -} - -func decomposeOpts(lg *zap.Logger, optstr string) (string, map[string]string, error) { - opts := strings.Split(optstr, ",") - tokenType := opts[0] - - typeSpecificOpts := make(map[string]string) - for i := 1; i < len(opts); i++ { - pair := strings.Split(opts[i], "=") - - if len(pair) != 2 { - if lg != nil { - lg.Error("invalid token option", zap.String("option", optstr)) - } - return "", nil, ErrInvalidAuthOpts - } - - if _, ok := typeSpecificOpts[pair[0]]; ok { - if lg != nil { - lg.Error( - "invalid token option", - zap.String("option", optstr), - zap.String("duplicate-parameter", pair[0]), - ) - } - return "", nil, ErrInvalidAuthOpts - } - - typeSpecificOpts[pair[0]] = pair[1] - } - - return tokenType, typeSpecificOpts, nil - -} - -// NewTokenProvider creates a new token provider. -func NewTokenProvider( - lg *zap.Logger, - tokenOpts string, - indexWaiter func(uint64) <-chan struct{}, - TokenTTL time.Duration) (TokenProvider, error) { - tokenType, typeSpecificOpts, err := decomposeOpts(lg, tokenOpts) - if err != nil { - return nil, ErrInvalidAuthOpts - } - - switch tokenType { - case tokenTypeSimple: - if lg != nil { - lg.Warn("simple token is not cryptographically signed") - } - return newTokenProviderSimple(lg, indexWaiter, TokenTTL), nil - - case tokenTypeJWT: - return newTokenProviderJWT(lg, typeSpecificOpts) - - case "": - return newTokenProviderNop() - - default: - if lg != nil { - lg.Warn( - "unknown token type", - zap.String("type", tokenType), - zap.Error(ErrInvalidAuthOpts), - ) - } - return nil, ErrInvalidAuthOpts - } -} - -func (as *authStore) WithRoot(ctx context.Context) context.Context { - if !as.IsAuthEnabled() { - return ctx - } - - var ctxForAssign context.Context - if ts, ok := as.tokenProvider.(*tokenSimple); ok && ts != nil { - ctx1 := context.WithValue(ctx, AuthenticateParamIndex{}, uint64(0)) - prefix, err := ts.genTokenPrefix() - if err != nil { - as.lg.Error( - "failed to generate prefix of internally used token", - zap.Error(err), - ) - return ctx - } - ctxForAssign = context.WithValue(ctx1, AuthenticateParamSimpleTokenPrefix{}, prefix) - } else { - ctxForAssign = ctx - } - - token, err := as.tokenProvider.assign(ctxForAssign, "root", as.Revision()) - if err != nil { - // this must not happen - as.lg.Error( - "failed to assign token for lease revoking", - zap.Error(err), - ) - return ctx - } - - mdMap := map[string]string{ - rpctypes.TokenFieldNameGRPC: token, - } - tokenMD := metadata.New(mdMap) - - // use "mdIncomingKey{}" since it's called from local etcdserver - return metadata.NewIncomingContext(ctx, tokenMD) -} - -func (as *authStore) HasRole(user, role string) bool { - tx := as.be.BatchTx() - tx.Lock() - u := getUser(as.lg, tx, user) - tx.Unlock() - - if u == nil { - as.lg.Warn( - "'has-role' requested for non-existing user", - zap.String("user-name", user), - zap.String("role-name", role), - ) - return false - } - - for _, r := range u.Roles { - if role == r { - return true - } - } - return false -} - -func (as *authStore) BcryptCost() int { - return as.bcryptCost -} - -func (as *authStore) setupMetricsReporter() { - reportCurrentAuthRevMu.Lock() - reportCurrentAuthRev = func() float64 { - return float64(as.Revision()) - } - reportCurrentAuthRevMu.Unlock() -} diff --git a/vendor/go.etcd.io/etcd/server/v3/config/config.go b/vendor/go.etcd.io/etcd/server/v3/config/config.go deleted file mode 100644 index b6e2109c22..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/config/config.go +++ /dev/null @@ -1,335 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package config - -import ( - "context" - "fmt" - "path/filepath" - "sort" - "strings" - "time" - - "go.etcd.io/etcd/client/pkg/v3/transport" - "go.etcd.io/etcd/client/pkg/v3/types" - "go.etcd.io/etcd/pkg/v3/netutil" - "go.etcd.io/etcd/server/v3/datadir" - "go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc" - - bolt "go.etcd.io/bbolt" - "go.uber.org/zap" -) - -// ServerConfig holds the configuration of etcd as taken from the command line or discovery. -type ServerConfig struct { - Name string - DiscoveryURL string - DiscoveryProxy string - ClientURLs types.URLs - PeerURLs types.URLs - DataDir string - // DedicatedWALDir config will make the etcd to write the WAL to the WALDir - // rather than the dataDir/member/wal. - DedicatedWALDir string - - SnapshotCount uint64 - - // SnapshotCatchUpEntries is the number of entries for a slow follower - // to catch-up after compacting the raft storage entries. - // We expect the follower has a millisecond level latency with the leader. - // The max throughput is around 10K. Keep a 5K entries is enough for helping - // follower to catch up. - // WARNING: only change this for tests. Always use "DefaultSnapshotCatchUpEntries" - SnapshotCatchUpEntries uint64 - - MaxSnapFiles uint - MaxWALFiles uint - - // BackendBatchInterval is the maximum time before commit the backend transaction. - BackendBatchInterval time.Duration - // BackendBatchLimit is the maximum operations before commit the backend transaction. - BackendBatchLimit int - - // BackendFreelistType is the type of the backend boltdb freelist. - BackendFreelistType bolt.FreelistType - - InitialPeerURLsMap types.URLsMap - InitialClusterToken string - NewCluster bool - PeerTLSInfo transport.TLSInfo - - CORS map[string]struct{} - - // HostWhitelist lists acceptable hostnames from client requests. - // If server is insecure (no TLS), server only accepts requests - // whose Host header value exists in this white list. - HostWhitelist map[string]struct{} - - TickMs uint - ElectionTicks int - - // InitialElectionTickAdvance is true, then local member fast-forwards - // election ticks to speed up "initial" leader election trigger. This - // benefits the case of larger election ticks. For instance, cross - // datacenter deployment may require longer election timeout of 10-second. - // If true, local node does not need wait up to 10-second. Instead, - // forwards its election ticks to 8-second, and have only 2-second left - // before leader election. - // - // Major assumptions are that: - // - cluster has no active leader thus advancing ticks enables faster - // leader election, or - // - cluster already has an established leader, and rejoining follower - // is likely to receive heartbeats from the leader after tick advance - // and before election timeout. - // - // However, when network from leader to rejoining follower is congested, - // and the follower does not receive leader heartbeat within left election - // ticks, disruptive election has to happen thus affecting cluster - // availabilities. - // - // Disabling this would slow down initial bootstrap process for cross - // datacenter deployments. Make your own tradeoffs by configuring - // --initial-election-tick-advance at the cost of slow initial bootstrap. - // - // If single-node, it advances ticks regardless. - // - // See https://github.com/etcd-io/etcd/issues/9333 for more detail. - InitialElectionTickAdvance bool - - BootstrapTimeout time.Duration - - AutoCompactionRetention time.Duration - AutoCompactionMode string - CompactionBatchLimit int - QuotaBackendBytes int64 - MaxTxnOps uint - - // MaxRequestBytes is the maximum request size to send over raft. - MaxRequestBytes uint - - WarningApplyDuration time.Duration - - StrictReconfigCheck bool - - // ClientCertAuthEnabled is true when cert has been signed by the client CA. - ClientCertAuthEnabled bool - - AuthToken string - BcryptCost uint - TokenTTL uint - - // InitialCorruptCheck is true to check data corruption on boot - // before serving any peer/client traffic. - InitialCorruptCheck bool - CorruptCheckTime time.Duration - - // PreVote is true to enable Raft Pre-Vote. - PreVote bool - - // SocketOpts are socket options passed to listener config. - SocketOpts transport.SocketOpts - - // Logger logs server-side operations. - Logger *zap.Logger - - ForceNewCluster bool - - // EnableLeaseCheckpoint enables primary lessor to persist lease remainingTTL to prevent indefinite auto-renewal of long lived leases. - EnableLeaseCheckpoint bool - // LeaseCheckpointInterval time.Duration is the wait duration between lease checkpoints. - LeaseCheckpointInterval time.Duration - - EnableGRPCGateway bool - - // ExperimentalEnableDistributedTracing enables distributed tracing using OpenTelemetry protocol. - ExperimentalEnableDistributedTracing bool - // ExperimentalTracerOptions are options for OpenTelemetry gRPC interceptor. - ExperimentalTracerOptions []otelgrpc.Option - - WatchProgressNotifyInterval time.Duration - - // UnsafeNoFsync disables all uses of fsync. - // Setting this is unsafe and will cause data loss. - UnsafeNoFsync bool `json:"unsafe-no-fsync"` - - DowngradeCheckTime time.Duration - - // ExperimentalMemoryMlock enables mlocking of etcd owned memory pages. - // The setting improves etcd tail latency in environments were: - // - memory pressure might lead to swapping pages to disk - // - disk latency might be unstable - // Currently all etcd memory gets mlocked, but in future the flag can - // be refined to mlock in-use area of bbolt only. - ExperimentalMemoryMlock bool `json:"experimental-memory-mlock"` - - // ExperimentalTxnModeWriteWithSharedBuffer enable write transaction to use - // a shared buffer in its readonly check operations. - ExperimentalTxnModeWriteWithSharedBuffer bool `json:"experimental-txn-mode-write-with-shared-buffer"` - - // ExperimentalBootstrapDefragThresholdMegabytes is the minimum number of megabytes needed to be freed for etcd server to - // consider running defrag during bootstrap. Needs to be set to non-zero value to take effect. - ExperimentalBootstrapDefragThresholdMegabytes uint `json:"experimental-bootstrap-defrag-threshold-megabytes"` - - // V2Deprecation defines a phase of v2store deprecation process. - V2Deprecation V2DeprecationEnum `json:"v2-deprecation"` -} - -// VerifyBootstrap sanity-checks the initial config for bootstrap case -// and returns an error for things that should never happen. -func (c *ServerConfig) VerifyBootstrap() error { - if err := c.hasLocalMember(); err != nil { - return err - } - if err := c.advertiseMatchesCluster(); err != nil { - return err - } - if CheckDuplicateURL(c.InitialPeerURLsMap) { - return fmt.Errorf("initial cluster %s has duplicate url", c.InitialPeerURLsMap) - } - if c.InitialPeerURLsMap.String() == "" && c.DiscoveryURL == "" { - return fmt.Errorf("initial cluster unset and no discovery URL found") - } - return nil -} - -// VerifyJoinExisting sanity-checks the initial config for join existing cluster -// case and returns an error for things that should never happen. -func (c *ServerConfig) VerifyJoinExisting() error { - // The member has announced its peer urls to the cluster before starting; no need to - // set the configuration again. - if err := c.hasLocalMember(); err != nil { - return err - } - if CheckDuplicateURL(c.InitialPeerURLsMap) { - return fmt.Errorf("initial cluster %s has duplicate url", c.InitialPeerURLsMap) - } - if c.DiscoveryURL != "" { - return fmt.Errorf("discovery URL should not be set when joining existing initial cluster") - } - return nil -} - -// hasLocalMember checks that the cluster at least contains the local server. -func (c *ServerConfig) hasLocalMember() error { - if urls := c.InitialPeerURLsMap[c.Name]; urls == nil { - return fmt.Errorf("couldn't find local name %q in the initial cluster configuration", c.Name) - } - return nil -} - -// advertiseMatchesCluster confirms peer URLs match those in the cluster peer list. -func (c *ServerConfig) advertiseMatchesCluster() error { - urls, apurls := c.InitialPeerURLsMap[c.Name], c.PeerURLs.StringSlice() - urls.Sort() - sort.Strings(apurls) - ctx, cancel := context.WithTimeout(context.TODO(), 30*time.Second) - defer cancel() - ok, err := netutil.URLStringsEqual(ctx, c.Logger, apurls, urls.StringSlice()) - if ok { - return nil - } - - initMap, apMap := make(map[string]struct{}), make(map[string]struct{}) - for _, url := range c.PeerURLs { - apMap[url.String()] = struct{}{} - } - for _, url := range c.InitialPeerURLsMap[c.Name] { - initMap[url.String()] = struct{}{} - } - - missing := []string{} - for url := range initMap { - if _, ok := apMap[url]; !ok { - missing = append(missing, url) - } - } - if len(missing) > 0 { - for i := range missing { - missing[i] = c.Name + "=" + missing[i] - } - mstr := strings.Join(missing, ",") - apStr := strings.Join(apurls, ",") - return fmt.Errorf("--initial-cluster has %s but missing from --initial-advertise-peer-urls=%s (%v)", mstr, apStr, err) - } - - for url := range apMap { - if _, ok := initMap[url]; !ok { - missing = append(missing, url) - } - } - if len(missing) > 0 { - mstr := strings.Join(missing, ",") - umap := types.URLsMap(map[string]types.URLs{c.Name: c.PeerURLs}) - return fmt.Errorf("--initial-advertise-peer-urls has %s but missing from --initial-cluster=%s", mstr, umap.String()) - } - - // resolved URLs from "--initial-advertise-peer-urls" and "--initial-cluster" did not match or failed - apStr := strings.Join(apurls, ",") - umap := types.URLsMap(map[string]types.URLs{c.Name: c.PeerURLs}) - return fmt.Errorf("failed to resolve %s to match --initial-cluster=%s (%v)", apStr, umap.String(), err) -} - -func (c *ServerConfig) MemberDir() string { return datadir.ToMemberDir(c.DataDir) } - -func (c *ServerConfig) WALDir() string { - if c.DedicatedWALDir != "" { - return c.DedicatedWALDir - } - return datadir.ToWalDir(c.DataDir) -} - -func (c *ServerConfig) SnapDir() string { return filepath.Join(c.MemberDir(), "snap") } - -func (c *ServerConfig) ShouldDiscover() bool { return c.DiscoveryURL != "" } - -// ReqTimeout returns timeout for request to finish. -func (c *ServerConfig) ReqTimeout() time.Duration { - // 5s for queue waiting, computation and disk IO delay - // + 2 * election timeout for possible leader election - return 5*time.Second + 2*time.Duration(c.ElectionTicks*int(c.TickMs))*time.Millisecond -} - -func (c *ServerConfig) ElectionTimeout() time.Duration { - return time.Duration(c.ElectionTicks*int(c.TickMs)) * time.Millisecond -} - -func (c *ServerConfig) PeerDialTimeout() time.Duration { - // 1s for queue wait and election timeout - return time.Second + time.Duration(c.ElectionTicks*int(c.TickMs))*time.Millisecond -} - -func CheckDuplicateURL(urlsmap types.URLsMap) bool { - um := make(map[string]bool) - for _, urls := range urlsmap { - for _, url := range urls { - u := url.String() - if um[u] { - return true - } - um[u] = true - } - } - return false -} - -func (c *ServerConfig) BootstrapTimeoutEffective() time.Duration { - if c.BootstrapTimeout != 0 { - return c.BootstrapTimeout - } - return time.Second -} - -func (c *ServerConfig) BackendPath() string { return datadir.ToBackendFileName(c.DataDir) } diff --git a/vendor/go.etcd.io/etcd/server/v3/config/v2_deprecation.go b/vendor/go.etcd.io/etcd/server/v3/config/v2_deprecation.go deleted file mode 100644 index 828bd9a8f4..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/config/v2_deprecation.go +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright 2021 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package config - -type V2DeprecationEnum string - -const ( - // Default in v3.5. Issues a warning if v2store have meaningful content. - V2_DEPR_0_NOT_YET = V2DeprecationEnum("not-yet") - // Default in v3.6. Meaningful v2 state is not allowed. - // The V2 files are maintained for v3.5 rollback. - V2_DEPR_1_WRITE_ONLY = V2DeprecationEnum("write-only") - // V2store is WIPED if found !!! - V2_DEPR_1_WRITE_ONLY_DROP = V2DeprecationEnum("write-only-drop-data") - // V2store is neither written nor read. Usage of this configuration is blocking - // ability to rollback to etcd v3.5. - V2_DEPR_2_GONE = V2DeprecationEnum("gone") - - V2_DEPR_DEFAULT = V2_DEPR_0_NOT_YET -) - -func (e V2DeprecationEnum) IsAtLeast(v2d V2DeprecationEnum) bool { - return e.level() >= v2d.level() -} - -func (e V2DeprecationEnum) level() int { - switch e { - case V2_DEPR_0_NOT_YET: - return 0 - case V2_DEPR_1_WRITE_ONLY: - return 1 - case V2_DEPR_1_WRITE_ONLY_DROP: - return 2 - case V2_DEPR_2_GONE: - return 3 - } - panic("Unknown V2DeprecationEnum: " + e) -} diff --git a/vendor/go.etcd.io/etcd/server/v3/datadir/datadir.go b/vendor/go.etcd.io/etcd/server/v3/datadir/datadir.go deleted file mode 100644 index fa4c51ad1a..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/datadir/datadir.go +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright 2021 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package datadir - -import "path/filepath" - -const ( - memberDirSegment = "member" - snapDirSegment = "snap" - walDirSegment = "wal" - backendFileSegment = "db" -) - -func ToBackendFileName(dataDir string) string { - return filepath.Join(ToSnapDir(dataDir), backendFileSegment) -} - -func ToSnapDir(dataDir string) string { - return filepath.Join(ToMemberDir(dataDir), snapDirSegment) -} - -func ToWalDir(dataDir string) string { - return filepath.Join(ToMemberDir(dataDir), walDirSegment) -} - -func ToMemberDir(dataDir string) string { - return filepath.Join(dataDir, memberDirSegment) -} diff --git a/vendor/go.etcd.io/etcd/server/v3/datadir/doc.go b/vendor/go.etcd.io/etcd/server/v3/datadir/doc.go deleted file mode 100644 index 92ca4b253d..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/datadir/doc.go +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright 2021 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package datadir - -// datadir contains functions to navigate file-layout of etcd data-directory. diff --git a/vendor/go.etcd.io/etcd/server/v3/embed/config.go b/vendor/go.etcd.io/etcd/server/v3/embed/config.go deleted file mode 100644 index 380c0c3aaa..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/embed/config.go +++ /dev/null @@ -1,968 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package embed - -import ( - "fmt" - "io/ioutil" - "net" - "net/http" - "net/url" - "os" - "path/filepath" - "strings" - "sync" - "time" - - "go.etcd.io/etcd/client/pkg/v3/logutil" - "go.etcd.io/etcd/client/pkg/v3/srv" - "go.etcd.io/etcd/client/pkg/v3/tlsutil" - "go.etcd.io/etcd/client/pkg/v3/transport" - "go.etcd.io/etcd/client/pkg/v3/types" - "go.etcd.io/etcd/pkg/v3/flags" - "go.etcd.io/etcd/pkg/v3/netutil" - "go.etcd.io/etcd/server/v3/config" - "go.etcd.io/etcd/server/v3/etcdserver" - "go.etcd.io/etcd/server/v3/etcdserver/api/v3compactor" - - bolt "go.etcd.io/bbolt" - "go.uber.org/multierr" - "go.uber.org/zap" - "golang.org/x/crypto/bcrypt" - "google.golang.org/grpc" - "sigs.k8s.io/yaml" -) - -const ( - ClusterStateFlagNew = "new" - ClusterStateFlagExisting = "existing" - - DefaultName = "default" - DefaultMaxSnapshots = 5 - DefaultMaxWALs = 5 - DefaultMaxTxnOps = uint(128) - DefaultWarningApplyDuration = 100 * time.Millisecond - DefaultMaxRequestBytes = 1.5 * 1024 * 1024 - DefaultGRPCKeepAliveMinTime = 5 * time.Second - DefaultGRPCKeepAliveInterval = 2 * time.Hour - DefaultGRPCKeepAliveTimeout = 20 * time.Second - DefaultDowngradeCheckTime = 5 * time.Second - - DefaultListenPeerURLs = "http://localhost:2380" - DefaultListenClientURLs = "http://localhost:2379" - - DefaultLogOutput = "default" - JournalLogOutput = "systemd/journal" - StdErrLogOutput = "stderr" - StdOutLogOutput = "stdout" - - // DefaultLogRotationConfig is the default configuration used for log rotation. - // Log rotation is disabled by default. - // MaxSize = 100 // MB - // MaxAge = 0 // days (no limit) - // MaxBackups = 0 // no limit - // LocalTime = false // use computers local time, UTC by default - // Compress = false // compress the rotated log in gzip format - DefaultLogRotationConfig = `{"maxsize": 100, "maxage": 0, "maxbackups": 0, "localtime": false, "compress": false}` - - // ExperimentalDistributedTracingAddress is the default collector address. - ExperimentalDistributedTracingAddress = "localhost:4317" - // ExperimentalDistributedTracingServiceName is the default etcd service name. - ExperimentalDistributedTracingServiceName = "etcd" - - // DefaultStrictReconfigCheck is the default value for "--strict-reconfig-check" flag. - // It's enabled by default. - DefaultStrictReconfigCheck = true - // DefaultEnableV2 is the default value for "--enable-v2" flag. - // v2 API is disabled by default. - DefaultEnableV2 = false - - // maxElectionMs specifies the maximum value of election timeout. - // More details are listed in ../Documentation/tuning.md#time-parameters. - maxElectionMs = 50000 - // backend freelist map type - freelistArrayType = "array" -) - -var ( - ErrConflictBootstrapFlags = fmt.Errorf("multiple discovery or bootstrap flags are set. " + - "Choose one of \"initial-cluster\", \"discovery\" or \"discovery-srv\"") - ErrUnsetAdvertiseClientURLsFlag = fmt.Errorf("--advertise-client-urls is required when --listen-client-urls is set explicitly") - ErrLogRotationInvalidLogOutput = fmt.Errorf("--log-outputs requires a single file path when --log-rotate-config-json is defined") - - DefaultInitialAdvertisePeerURLs = "http://localhost:2380" - DefaultAdvertiseClientURLs = "http://localhost:2379" - - defaultHostname string - defaultHostStatus error - - // indirection for testing - getCluster = srv.GetCluster -) - -var ( - // CompactorModePeriodic is periodic compaction mode - // for "Config.AutoCompactionMode" field. - // If "AutoCompactionMode" is CompactorModePeriodic and - // "AutoCompactionRetention" is "1h", it automatically compacts - // compacts storage every hour. - CompactorModePeriodic = v3compactor.ModePeriodic - - // CompactorModeRevision is revision-based compaction mode - // for "Config.AutoCompactionMode" field. - // If "AutoCompactionMode" is CompactorModeRevision and - // "AutoCompactionRetention" is "1000", it compacts log on - // revision 5000 when the current revision is 6000. - // This runs every 5-minute if enough of logs have proceeded. - CompactorModeRevision = v3compactor.ModeRevision -) - -func init() { - defaultHostname, defaultHostStatus = netutil.GetDefaultHost() -} - -// Config holds the arguments for configuring an etcd server. -type Config struct { - Name string `json:"name"` - Dir string `json:"data-dir"` - WalDir string `json:"wal-dir"` - - SnapshotCount uint64 `json:"snapshot-count"` - - // SnapshotCatchUpEntries is the number of entries for a slow follower - // to catch-up after compacting the raft storage entries. - // We expect the follower has a millisecond level latency with the leader. - // The max throughput is around 10K. Keep a 5K entries is enough for helping - // follower to catch up. - // WARNING: only change this for tests. - // Always use "DefaultSnapshotCatchUpEntries" - SnapshotCatchUpEntries uint64 - - MaxSnapFiles uint `json:"max-snapshots"` - MaxWalFiles uint `json:"max-wals"` - - // TickMs is the number of milliseconds between heartbeat ticks. - // TODO: decouple tickMs and heartbeat tick (current heartbeat tick = 1). - // make ticks a cluster wide configuration. - TickMs uint `json:"heartbeat-interval"` - ElectionMs uint `json:"election-timeout"` - - // InitialElectionTickAdvance is true, then local member fast-forwards - // election ticks to speed up "initial" leader election trigger. This - // benefits the case of larger election ticks. For instance, cross - // datacenter deployment may require longer election timeout of 10-second. - // If true, local node does not need wait up to 10-second. Instead, - // forwards its election ticks to 8-second, and have only 2-second left - // before leader election. - // - // Major assumptions are that: - // - cluster has no active leader thus advancing ticks enables faster - // leader election, or - // - cluster already has an established leader, and rejoining follower - // is likely to receive heartbeats from the leader after tick advance - // and before election timeout. - // - // However, when network from leader to rejoining follower is congested, - // and the follower does not receive leader heartbeat within left election - // ticks, disruptive election has to happen thus affecting cluster - // availabilities. - // - // Disabling this would slow down initial bootstrap process for cross - // datacenter deployments. Make your own tradeoffs by configuring - // --initial-election-tick-advance at the cost of slow initial bootstrap. - // - // If single-node, it advances ticks regardless. - // - // See https://github.com/etcd-io/etcd/issues/9333 for more detail. - InitialElectionTickAdvance bool `json:"initial-election-tick-advance"` - - // BackendBatchInterval is the maximum time before commit the backend transaction. - BackendBatchInterval time.Duration `json:"backend-batch-interval"` - // BackendBatchLimit is the maximum operations before commit the backend transaction. - BackendBatchLimit int `json:"backend-batch-limit"` - // BackendFreelistType specifies the type of freelist that boltdb backend uses (array and map are supported types). - BackendFreelistType string `json:"backend-bbolt-freelist-type"` - QuotaBackendBytes int64 `json:"quota-backend-bytes"` - MaxTxnOps uint `json:"max-txn-ops"` - MaxRequestBytes uint `json:"max-request-bytes"` - - LPUrls, LCUrls []url.URL - APUrls, ACUrls []url.URL - ClientTLSInfo transport.TLSInfo - ClientAutoTLS bool - PeerTLSInfo transport.TLSInfo - PeerAutoTLS bool - // SelfSignedCertValidity specifies the validity period of the client and peer certificates - // that are automatically generated by etcd when you specify ClientAutoTLS and PeerAutoTLS, - // the unit is year, and the default is 1 - SelfSignedCertValidity uint - - // CipherSuites is a list of supported TLS cipher suites between - // client/server and peers. If empty, Go auto-populates the list. - // Note that cipher suites are prioritized in the given order. - CipherSuites []string `json:"cipher-suites"` - - ClusterState string `json:"initial-cluster-state"` - DNSCluster string `json:"discovery-srv"` - DNSClusterServiceName string `json:"discovery-srv-name"` - Dproxy string `json:"discovery-proxy"` - Durl string `json:"discovery"` - InitialCluster string `json:"initial-cluster"` - InitialClusterToken string `json:"initial-cluster-token"` - StrictReconfigCheck bool `json:"strict-reconfig-check"` - - // EnableV2 exposes the deprecated V2 API surface. - // TODO: Delete in 3.6 (https://github.com/etcd-io/etcd/issues/12913) - // Deprecated in 3.5. - EnableV2 bool `json:"enable-v2"` - - // AutoCompactionMode is either 'periodic' or 'revision'. - AutoCompactionMode string `json:"auto-compaction-mode"` - // AutoCompactionRetention is either duration string with time unit - // (e.g. '5m' for 5-minute), or revision unit (e.g. '5000'). - // If no time unit is provided and compaction mode is 'periodic', - // the unit defaults to hour. For example, '5' translates into 5-hour. - AutoCompactionRetention string `json:"auto-compaction-retention"` - - // GRPCKeepAliveMinTime is the minimum interval that a client should - // wait before pinging server. When client pings "too fast", server - // sends goaway and closes the connection (errors: too_many_pings, - // http2.ErrCodeEnhanceYourCalm). When too slow, nothing happens. - // Server expects client pings only when there is any active streams - // (PermitWithoutStream is set false). - GRPCKeepAliveMinTime time.Duration `json:"grpc-keepalive-min-time"` - // GRPCKeepAliveInterval is the frequency of server-to-client ping - // to check if a connection is alive. Close a non-responsive connection - // after an additional duration of Timeout. 0 to disable. - GRPCKeepAliveInterval time.Duration `json:"grpc-keepalive-interval"` - // GRPCKeepAliveTimeout is the additional duration of wait - // before closing a non-responsive connection. 0 to disable. - GRPCKeepAliveTimeout time.Duration `json:"grpc-keepalive-timeout"` - - // SocketOpts are socket options passed to listener config. - SocketOpts transport.SocketOpts - - // PreVote is true to enable Raft Pre-Vote. - // If enabled, Raft runs an additional election phase - // to check whether it would get enough votes to win - // an election, thus minimizing disruptions. - PreVote bool `json:"pre-vote"` - - CORS map[string]struct{} - - // HostWhitelist lists acceptable hostnames from HTTP client requests. - // Client origin policy protects against "DNS Rebinding" attacks - // to insecure etcd servers. That is, any website can simply create - // an authorized DNS name, and direct DNS to "localhost" (or any - // other address). Then, all HTTP endpoints of etcd server listening - // on "localhost" becomes accessible, thus vulnerable to DNS rebinding - // attacks. See "CVE-2018-5702" for more detail. - // - // 1. If client connection is secure via HTTPS, allow any hostnames. - // 2. If client connection is not secure and "HostWhitelist" is not empty, - // only allow HTTP requests whose Host field is listed in whitelist. - // - // Note that the client origin policy is enforced whether authentication - // is enabled or not, for tighter controls. - // - // By default, "HostWhitelist" is "*", which allows any hostnames. - // Note that when specifying hostnames, loopback addresses are not added - // automatically. To allow loopback interfaces, leave it empty or set it "*", - // or add them to whitelist manually (e.g. "localhost", "127.0.0.1", etc.). - // - // CVE-2018-5702 reference: - // - https://bugs.chromium.org/p/project-zero/issues/detail?id=1447#c2 - // - https://github.com/transmission/transmission/pull/468 - // - https://github.com/etcd-io/etcd/issues/9353 - HostWhitelist map[string]struct{} - - // UserHandlers is for registering users handlers and only used for - // embedding etcd into other applications. - // The map key is the route path for the handler, and - // you must ensure it can't be conflicted with etcd's. - UserHandlers map[string]http.Handler `json:"-"` - // ServiceRegister is for registering users' gRPC services. A simple usage example: - // cfg := embed.NewConfig() - // cfg.ServerRegister = func(s *grpc.Server) { - // pb.RegisterFooServer(s, &fooServer{}) - // pb.RegisterBarServer(s, &barServer{}) - // } - // embed.StartEtcd(cfg) - ServiceRegister func(*grpc.Server) `json:"-"` - - AuthToken string `json:"auth-token"` - BcryptCost uint `json:"bcrypt-cost"` - - //The AuthTokenTTL in seconds of the simple token - AuthTokenTTL uint `json:"auth-token-ttl"` - - ExperimentalInitialCorruptCheck bool `json:"experimental-initial-corrupt-check"` - ExperimentalCorruptCheckTime time.Duration `json:"experimental-corrupt-check-time"` - // ExperimentalEnableV2V3 configures URLs that expose deprecated V2 API working on V3 store. - // Deprecated in v3.5. - // TODO: Delete in v3.6 (https://github.com/etcd-io/etcd/issues/12913) - ExperimentalEnableV2V3 string `json:"experimental-enable-v2v3"` - // ExperimentalEnableLeaseCheckpoint enables primary lessor to persist lease remainingTTL to prevent indefinite auto-renewal of long lived leases. - ExperimentalEnableLeaseCheckpoint bool `json:"experimental-enable-lease-checkpoint"` - ExperimentalCompactionBatchLimit int `json:"experimental-compaction-batch-limit"` - ExperimentalWatchProgressNotifyInterval time.Duration `json:"experimental-watch-progress-notify-interval"` - // ExperimentalWarningApplyDuration is the time duration after which a warning is generated if applying request - // takes more time than this value. - ExperimentalWarningApplyDuration time.Duration `json:"experimental-warning-apply-duration"` - // ExperimentalBootstrapDefragThresholdMegabytes is the minimum number of megabytes needed to be freed for etcd server to - // consider running defrag during bootstrap. Needs to be set to non-zero value to take effect. - ExperimentalBootstrapDefragThresholdMegabytes uint `json:"experimental-bootstrap-defrag-threshold-megabytes"` - - // ForceNewCluster starts a new cluster even if previously started; unsafe. - ForceNewCluster bool `json:"force-new-cluster"` - - EnablePprof bool `json:"enable-pprof"` - Metrics string `json:"metrics"` - ListenMetricsUrls []url.URL - ListenMetricsUrlsJSON string `json:"listen-metrics-urls"` - - // ExperimentalEnableDistributedTracing indicates if experimental tracing using OpenTelemetry is enabled. - ExperimentalEnableDistributedTracing bool `json:"experimental-enable-distributed-tracing"` - // ExperimentalDistributedTracingAddress is the address of the OpenTelemetry Collector. - // Can only be set if ExperimentalEnableDistributedTracing is true. - ExperimentalDistributedTracingAddress string `json:"experimental-distributed-tracing-address"` - // ExperimentalDistributedTracingServiceName is the name of the service. - // Can only be used if ExperimentalEnableDistributedTracing is true. - ExperimentalDistributedTracingServiceName string `json:"experimental-distributed-tracing-service-name"` - // ExperimentalDistributedTracingServiceInstanceID is the ID key of the service. - // This ID must be unique, as helps to distinguish instances of the same service - // that exist at the same time. - // Can only be used if ExperimentalEnableDistributedTracing is true. - ExperimentalDistributedTracingServiceInstanceID string `json:"experimental-distributed-tracing-instance-id"` - - // Logger is logger options: currently only supports "zap". - // "capnslog" is removed in v3.5. - Logger string `json:"logger"` - // LogLevel configures log level. Only supports debug, info, warn, error, panic, or fatal. Default 'info'. - LogLevel string `json:"log-level"` - // LogOutputs is either: - // - "default" as os.Stderr, - // - "stderr" as os.Stderr, - // - "stdout" as os.Stdout, - // - file path to append server logs to. - // It can be multiple when "Logger" is zap. - LogOutputs []string `json:"log-outputs"` - // EnableLogRotation enables log rotation of a single LogOutputs file target. - EnableLogRotation bool `json:"enable-log-rotation"` - // LogRotationConfigJSON is a passthrough allowing a log rotation JSON config to be passed directly. - LogRotationConfigJSON string `json:"log-rotation-config-json"` - // ZapLoggerBuilder is used to build the zap logger. - ZapLoggerBuilder func(*Config) error - - // logger logs server-side operations. The default is nil, - // and "setupLogging" must be called before starting server. - // Do not set logger directly. - loggerMu *sync.RWMutex - logger *zap.Logger - // EnableGRPCGateway enables grpc gateway. - // The gateway translates a RESTful HTTP API into gRPC. - EnableGRPCGateway bool `json:"enable-grpc-gateway"` - - // UnsafeNoFsync disables all uses of fsync. - // Setting this is unsafe and will cause data loss. - UnsafeNoFsync bool `json:"unsafe-no-fsync"` - - ExperimentalDowngradeCheckTime time.Duration `json:"experimental-downgrade-check-time"` - - // ExperimentalMemoryMlock enables mlocking of etcd owned memory pages. - // The setting improves etcd tail latency in environments were: - // - memory pressure might lead to swapping pages to disk - // - disk latency might be unstable - // Currently all etcd memory gets mlocked, but in future the flag can - // be refined to mlock in-use area of bbolt only. - ExperimentalMemoryMlock bool `json:"experimental-memory-mlock"` - - // ExperimentalTxnModeWriteWithSharedBuffer enables write transaction to use a shared buffer in its readonly check operations. - ExperimentalTxnModeWriteWithSharedBuffer bool `json:"experimental-txn-mode-write-with-shared-buffer"` - - // V2Deprecation describes phase of API & Storage V2 support - V2Deprecation config.V2DeprecationEnum `json:"v2-deprecation"` -} - -// configYAML holds the config suitable for yaml parsing -type configYAML struct { - Config - configJSON -} - -// configJSON has file options that are translated into Config options -type configJSON struct { - LPUrlsJSON string `json:"listen-peer-urls"` - LCUrlsJSON string `json:"listen-client-urls"` - APUrlsJSON string `json:"initial-advertise-peer-urls"` - ACUrlsJSON string `json:"advertise-client-urls"` - - CORSJSON string `json:"cors"` - HostWhitelistJSON string `json:"host-whitelist"` - - ClientSecurityJSON securityConfig `json:"client-transport-security"` - PeerSecurityJSON securityConfig `json:"peer-transport-security"` -} - -type securityConfig struct { - CertFile string `json:"cert-file"` - KeyFile string `json:"key-file"` - ClientCertFile string `json:"client-cert-file"` - ClientKeyFile string `json:"client-key-file"` - CertAuth bool `json:"client-cert-auth"` - TrustedCAFile string `json:"trusted-ca-file"` - AutoTLS bool `json:"auto-tls"` -} - -// NewConfig creates a new Config populated with default values. -func NewConfig() *Config { - lpurl, _ := url.Parse(DefaultListenPeerURLs) - apurl, _ := url.Parse(DefaultInitialAdvertisePeerURLs) - lcurl, _ := url.Parse(DefaultListenClientURLs) - acurl, _ := url.Parse(DefaultAdvertiseClientURLs) - cfg := &Config{ - MaxSnapFiles: DefaultMaxSnapshots, - MaxWalFiles: DefaultMaxWALs, - - Name: DefaultName, - - SnapshotCount: etcdserver.DefaultSnapshotCount, - SnapshotCatchUpEntries: etcdserver.DefaultSnapshotCatchUpEntries, - - MaxTxnOps: DefaultMaxTxnOps, - MaxRequestBytes: DefaultMaxRequestBytes, - ExperimentalWarningApplyDuration: DefaultWarningApplyDuration, - - GRPCKeepAliveMinTime: DefaultGRPCKeepAliveMinTime, - GRPCKeepAliveInterval: DefaultGRPCKeepAliveInterval, - GRPCKeepAliveTimeout: DefaultGRPCKeepAliveTimeout, - - SocketOpts: transport.SocketOpts{}, - - TickMs: 100, - ElectionMs: 1000, - InitialElectionTickAdvance: true, - - LPUrls: []url.URL{*lpurl}, - LCUrls: []url.URL{*lcurl}, - APUrls: []url.URL{*apurl}, - ACUrls: []url.URL{*acurl}, - - ClusterState: ClusterStateFlagNew, - InitialClusterToken: "etcd-cluster", - - StrictReconfigCheck: DefaultStrictReconfigCheck, - Metrics: "basic", - EnableV2: DefaultEnableV2, - - CORS: map[string]struct{}{"*": {}}, - HostWhitelist: map[string]struct{}{"*": {}}, - - AuthToken: "simple", - BcryptCost: uint(bcrypt.DefaultCost), - AuthTokenTTL: 300, - - PreVote: true, - - loggerMu: new(sync.RWMutex), - logger: nil, - Logger: "zap", - LogOutputs: []string{DefaultLogOutput}, - LogLevel: logutil.DefaultLogLevel, - EnableLogRotation: false, - LogRotationConfigJSON: DefaultLogRotationConfig, - EnableGRPCGateway: true, - - ExperimentalDowngradeCheckTime: DefaultDowngradeCheckTime, - ExperimentalMemoryMlock: false, - ExperimentalTxnModeWriteWithSharedBuffer: true, - - V2Deprecation: config.V2_DEPR_DEFAULT, - } - cfg.InitialCluster = cfg.InitialClusterFromName(cfg.Name) - return cfg -} - -func ConfigFromFile(path string) (*Config, error) { - cfg := &configYAML{Config: *NewConfig()} - if err := cfg.configFromFile(path); err != nil { - return nil, err - } - return &cfg.Config, nil -} - -func (cfg *configYAML) configFromFile(path string) error { - b, err := ioutil.ReadFile(path) - if err != nil { - return err - } - - defaultInitialCluster := cfg.InitialCluster - - err = yaml.Unmarshal(b, cfg) - if err != nil { - return err - } - - if cfg.LPUrlsJSON != "" { - u, err := types.NewURLs(strings.Split(cfg.LPUrlsJSON, ",")) - if err != nil { - fmt.Fprintf(os.Stderr, "unexpected error setting up listen-peer-urls: %v\n", err) - os.Exit(1) - } - cfg.LPUrls = []url.URL(u) - } - - if cfg.LCUrlsJSON != "" { - u, err := types.NewURLs(strings.Split(cfg.LCUrlsJSON, ",")) - if err != nil { - fmt.Fprintf(os.Stderr, "unexpected error setting up listen-client-urls: %v\n", err) - os.Exit(1) - } - cfg.LCUrls = []url.URL(u) - } - - if cfg.APUrlsJSON != "" { - u, err := types.NewURLs(strings.Split(cfg.APUrlsJSON, ",")) - if err != nil { - fmt.Fprintf(os.Stderr, "unexpected error setting up initial-advertise-peer-urls: %v\n", err) - os.Exit(1) - } - cfg.APUrls = []url.URL(u) - } - - if cfg.ACUrlsJSON != "" { - u, err := types.NewURLs(strings.Split(cfg.ACUrlsJSON, ",")) - if err != nil { - fmt.Fprintf(os.Stderr, "unexpected error setting up advertise-peer-urls: %v\n", err) - os.Exit(1) - } - cfg.ACUrls = []url.URL(u) - } - - if cfg.ListenMetricsUrlsJSON != "" { - u, err := types.NewURLs(strings.Split(cfg.ListenMetricsUrlsJSON, ",")) - if err != nil { - fmt.Fprintf(os.Stderr, "unexpected error setting up listen-metrics-urls: %v\n", err) - os.Exit(1) - } - cfg.ListenMetricsUrls = []url.URL(u) - } - - if cfg.CORSJSON != "" { - uv := flags.NewUniqueURLsWithExceptions(cfg.CORSJSON, "*") - cfg.CORS = uv.Values - } - - if cfg.HostWhitelistJSON != "" { - uv := flags.NewUniqueStringsValue(cfg.HostWhitelistJSON) - cfg.HostWhitelist = uv.Values - } - - // If a discovery flag is set, clear default initial cluster set by InitialClusterFromName - if (cfg.Durl != "" || cfg.DNSCluster != "") && cfg.InitialCluster == defaultInitialCluster { - cfg.InitialCluster = "" - } - if cfg.ClusterState == "" { - cfg.ClusterState = ClusterStateFlagNew - } - - copySecurityDetails := func(tls *transport.TLSInfo, ysc *securityConfig) { - tls.CertFile = ysc.CertFile - tls.KeyFile = ysc.KeyFile - tls.ClientCertFile = ysc.ClientCertFile - tls.ClientKeyFile = ysc.ClientKeyFile - tls.ClientCertAuth = ysc.CertAuth - tls.TrustedCAFile = ysc.TrustedCAFile - } - copySecurityDetails(&cfg.ClientTLSInfo, &cfg.ClientSecurityJSON) - copySecurityDetails(&cfg.PeerTLSInfo, &cfg.PeerSecurityJSON) - cfg.ClientAutoTLS = cfg.ClientSecurityJSON.AutoTLS - cfg.PeerAutoTLS = cfg.PeerSecurityJSON.AutoTLS - - return cfg.Validate() -} - -func updateCipherSuites(tls *transport.TLSInfo, ss []string) error { - if len(tls.CipherSuites) > 0 && len(ss) > 0 { - return fmt.Errorf("TLSInfo.CipherSuites is already specified (given %v)", ss) - } - if len(ss) > 0 { - cs := make([]uint16, len(ss)) - for i, s := range ss { - var ok bool - cs[i], ok = tlsutil.GetCipherSuite(s) - if !ok { - return fmt.Errorf("unexpected TLS cipher suite %q", s) - } - } - tls.CipherSuites = cs - } - return nil -} - -// Validate ensures that '*embed.Config' fields are properly configured. -func (cfg *Config) Validate() error { - if err := cfg.setupLogging(); err != nil { - return err - } - if err := checkBindURLs(cfg.LPUrls); err != nil { - return err - } - if err := checkBindURLs(cfg.LCUrls); err != nil { - return err - } - if err := checkBindURLs(cfg.ListenMetricsUrls); err != nil { - return err - } - if err := checkHostURLs(cfg.APUrls); err != nil { - addrs := cfg.getAPURLs() - return fmt.Errorf(`--initial-advertise-peer-urls %q must be "host:port" (%v)`, strings.Join(addrs, ","), err) - } - if err := checkHostURLs(cfg.ACUrls); err != nil { - addrs := cfg.getACURLs() - return fmt.Errorf(`--advertise-client-urls %q must be "host:port" (%v)`, strings.Join(addrs, ","), err) - } - // Check if conflicting flags are passed. - nSet := 0 - for _, v := range []bool{cfg.Durl != "", cfg.InitialCluster != "", cfg.DNSCluster != ""} { - if v { - nSet++ - } - } - - if cfg.ClusterState != ClusterStateFlagNew && cfg.ClusterState != ClusterStateFlagExisting { - return fmt.Errorf("unexpected clusterState %q", cfg.ClusterState) - } - - if nSet > 1 { - return ErrConflictBootstrapFlags - } - - if cfg.TickMs == 0 { - return fmt.Errorf("--heartbeat-interval must be >0 (set to %dms)", cfg.TickMs) - } - if cfg.ElectionMs == 0 { - return fmt.Errorf("--election-timeout must be >0 (set to %dms)", cfg.ElectionMs) - } - if 5*cfg.TickMs > cfg.ElectionMs { - return fmt.Errorf("--election-timeout[%vms] should be at least as 5 times as --heartbeat-interval[%vms]", cfg.ElectionMs, cfg.TickMs) - } - if cfg.ElectionMs > maxElectionMs { - return fmt.Errorf("--election-timeout[%vms] is too long, and should be set less than %vms", cfg.ElectionMs, maxElectionMs) - } - - // check this last since proxying in etcdmain may make this OK - if cfg.LCUrls != nil && cfg.ACUrls == nil { - return ErrUnsetAdvertiseClientURLsFlag - } - - switch cfg.AutoCompactionMode { - case "": - case CompactorModeRevision, CompactorModePeriodic: - default: - return fmt.Errorf("unknown auto-compaction-mode %q", cfg.AutoCompactionMode) - } - - return nil -} - -// PeerURLsMapAndToken sets up an initial peer URLsMap and cluster token for bootstrap or discovery. -func (cfg *Config) PeerURLsMapAndToken(which string) (urlsmap types.URLsMap, token string, err error) { - token = cfg.InitialClusterToken - switch { - case cfg.Durl != "": - urlsmap = types.URLsMap{} - // If using discovery, generate a temporary cluster based on - // self's advertised peer URLs - urlsmap[cfg.Name] = cfg.APUrls - token = cfg.Durl - - case cfg.DNSCluster != "": - clusterStrs, cerr := cfg.GetDNSClusterNames() - lg := cfg.logger - if cerr != nil { - lg.Warn("failed to resolve during SRV discovery", zap.Error(cerr)) - } - if len(clusterStrs) == 0 { - return nil, "", cerr - } - for _, s := range clusterStrs { - lg.Info("got bootstrap from DNS for etcd-server", zap.String("node", s)) - } - clusterStr := strings.Join(clusterStrs, ",") - if strings.Contains(clusterStr, "https://") && cfg.PeerTLSInfo.TrustedCAFile == "" { - cfg.PeerTLSInfo.ServerName = cfg.DNSCluster - } - urlsmap, err = types.NewURLsMap(clusterStr) - // only etcd member must belong to the discovered cluster. - // proxy does not need to belong to the discovered cluster. - if which == "etcd" { - if _, ok := urlsmap[cfg.Name]; !ok { - return nil, "", fmt.Errorf("cannot find local etcd member %q in SRV records", cfg.Name) - } - } - - default: - // We're statically configured, and cluster has appropriately been set. - urlsmap, err = types.NewURLsMap(cfg.InitialCluster) - } - return urlsmap, token, err -} - -// GetDNSClusterNames uses DNS SRV records to get a list of initial nodes for cluster bootstrapping. -// This function will return a list of one or more nodes, as well as any errors encountered while -// performing service discovery. -// Note: Because this checks multiple sets of SRV records, discovery should only be considered to have -// failed if the returned node list is empty. -func (cfg *Config) GetDNSClusterNames() ([]string, error) { - var ( - clusterStrs []string - cerr error - serviceNameSuffix string - ) - if cfg.DNSClusterServiceName != "" { - serviceNameSuffix = "-" + cfg.DNSClusterServiceName - } - - lg := cfg.GetLogger() - - // Use both etcd-server-ssl and etcd-server for discovery. - // Combine the results if both are available. - clusterStrs, cerr = getCluster("https", "etcd-server-ssl"+serviceNameSuffix, cfg.Name, cfg.DNSCluster, cfg.APUrls) - if cerr != nil { - clusterStrs = make([]string, 0) - } - lg.Info( - "get cluster for etcd-server-ssl SRV", - zap.String("service-scheme", "https"), - zap.String("service-name", "etcd-server-ssl"+serviceNameSuffix), - zap.String("server-name", cfg.Name), - zap.String("discovery-srv", cfg.DNSCluster), - zap.Strings("advertise-peer-urls", cfg.getAPURLs()), - zap.Strings("found-cluster", clusterStrs), - zap.Error(cerr), - ) - - defaultHTTPClusterStrs, httpCerr := getCluster("http", "etcd-server"+serviceNameSuffix, cfg.Name, cfg.DNSCluster, cfg.APUrls) - if httpCerr == nil { - clusterStrs = append(clusterStrs, defaultHTTPClusterStrs...) - } - lg.Info( - "get cluster for etcd-server SRV", - zap.String("service-scheme", "http"), - zap.String("service-name", "etcd-server"+serviceNameSuffix), - zap.String("server-name", cfg.Name), - zap.String("discovery-srv", cfg.DNSCluster), - zap.Strings("advertise-peer-urls", cfg.getAPURLs()), - zap.Strings("found-cluster", clusterStrs), - zap.Error(httpCerr), - ) - - return clusterStrs, multierr.Combine(cerr, httpCerr) -} - -func (cfg Config) InitialClusterFromName(name string) (ret string) { - if len(cfg.APUrls) == 0 { - return "" - } - n := name - if name == "" { - n = DefaultName - } - for i := range cfg.APUrls { - ret = ret + "," + n + "=" + cfg.APUrls[i].String() - } - return ret[1:] -} - -func (cfg Config) IsNewCluster() bool { return cfg.ClusterState == ClusterStateFlagNew } -func (cfg Config) ElectionTicks() int { return int(cfg.ElectionMs / cfg.TickMs) } - -func (cfg Config) V2DeprecationEffective() config.V2DeprecationEnum { - if cfg.V2Deprecation == "" { - return config.V2_DEPR_DEFAULT - } - return cfg.V2Deprecation -} - -func (cfg Config) defaultPeerHost() bool { - return len(cfg.APUrls) == 1 && cfg.APUrls[0].String() == DefaultInitialAdvertisePeerURLs -} - -func (cfg Config) defaultClientHost() bool { - return len(cfg.ACUrls) == 1 && cfg.ACUrls[0].String() == DefaultAdvertiseClientURLs -} - -func (cfg *Config) ClientSelfCert() (err error) { - if !cfg.ClientAutoTLS { - return nil - } - if !cfg.ClientTLSInfo.Empty() { - cfg.logger.Warn("ignoring client auto TLS since certs given") - return nil - } - chosts := make([]string, len(cfg.LCUrls)) - for i, u := range cfg.LCUrls { - chosts[i] = u.Host - } - cfg.ClientTLSInfo, err = transport.SelfCert(cfg.logger, filepath.Join(cfg.Dir, "fixtures", "client"), chosts, cfg.SelfSignedCertValidity) - if err != nil { - return err - } - return updateCipherSuites(&cfg.ClientTLSInfo, cfg.CipherSuites) -} - -func (cfg *Config) PeerSelfCert() (err error) { - if !cfg.PeerAutoTLS { - return nil - } - if !cfg.PeerTLSInfo.Empty() { - cfg.logger.Warn("ignoring peer auto TLS since certs given") - return nil - } - phosts := make([]string, len(cfg.LPUrls)) - for i, u := range cfg.LPUrls { - phosts[i] = u.Host - } - cfg.PeerTLSInfo, err = transport.SelfCert(cfg.logger, filepath.Join(cfg.Dir, "fixtures", "peer"), phosts, cfg.SelfSignedCertValidity) - if err != nil { - return err - } - return updateCipherSuites(&cfg.PeerTLSInfo, cfg.CipherSuites) -} - -// UpdateDefaultClusterFromName updates cluster advertise URLs with, if available, default host, -// if advertise URLs are default values(localhost:2379,2380) AND if listen URL is 0.0.0.0. -// e.g. advertise peer URL localhost:2380 or listen peer URL 0.0.0.0:2380 -// then the advertise peer host would be updated with machine's default host, -// while keeping the listen URL's port. -// User can work around this by explicitly setting URL with 127.0.0.1. -// It returns the default hostname, if used, and the error, if any, from getting the machine's default host. -// TODO: check whether fields are set instead of whether fields have default value -func (cfg *Config) UpdateDefaultClusterFromName(defaultInitialCluster string) (string, error) { - if defaultHostname == "" || defaultHostStatus != nil { - // update 'initial-cluster' when only the name is specified (e.g. 'etcd --name=abc') - if cfg.Name != DefaultName && cfg.InitialCluster == defaultInitialCluster { - cfg.InitialCluster = cfg.InitialClusterFromName(cfg.Name) - } - return "", defaultHostStatus - } - - used := false - pip, pport := cfg.LPUrls[0].Hostname(), cfg.LPUrls[0].Port() - if cfg.defaultPeerHost() && pip == "0.0.0.0" { - cfg.APUrls[0] = url.URL{Scheme: cfg.APUrls[0].Scheme, Host: fmt.Sprintf("%s:%s", defaultHostname, pport)} - used = true - } - // update 'initial-cluster' when only the name is specified (e.g. 'etcd --name=abc') - if cfg.Name != DefaultName && cfg.InitialCluster == defaultInitialCluster { - cfg.InitialCluster = cfg.InitialClusterFromName(cfg.Name) - } - - cip, cport := cfg.LCUrls[0].Hostname(), cfg.LCUrls[0].Port() - if cfg.defaultClientHost() && cip == "0.0.0.0" { - cfg.ACUrls[0] = url.URL{Scheme: cfg.ACUrls[0].Scheme, Host: fmt.Sprintf("%s:%s", defaultHostname, cport)} - used = true - } - dhost := defaultHostname - if !used { - dhost = "" - } - return dhost, defaultHostStatus -} - -// checkBindURLs returns an error if any URL uses a domain name. -func checkBindURLs(urls []url.URL) error { - for _, url := range urls { - if url.Scheme == "unix" || url.Scheme == "unixs" { - continue - } - host, _, err := net.SplitHostPort(url.Host) - if err != nil { - return err - } - if host == "localhost" { - // special case for local address - // TODO: support /etc/hosts ? - continue - } - if net.ParseIP(host) == nil { - return fmt.Errorf("expected IP in URL for binding (%s)", url.String()) - } - } - return nil -} - -func checkHostURLs(urls []url.URL) error { - for _, url := range urls { - host, _, err := net.SplitHostPort(url.Host) - if err != nil { - return err - } - if host == "" { - return fmt.Errorf("unexpected empty host (%s)", url.String()) - } - } - return nil -} - -func (cfg *Config) getAPURLs() (ss []string) { - ss = make([]string, len(cfg.APUrls)) - for i := range cfg.APUrls { - ss[i] = cfg.APUrls[i].String() - } - return ss -} - -func (cfg *Config) getLPURLs() (ss []string) { - ss = make([]string, len(cfg.LPUrls)) - for i := range cfg.LPUrls { - ss[i] = cfg.LPUrls[i].String() - } - return ss -} - -func (cfg *Config) getACURLs() (ss []string) { - ss = make([]string, len(cfg.ACUrls)) - for i := range cfg.ACUrls { - ss[i] = cfg.ACUrls[i].String() - } - return ss -} - -func (cfg *Config) getLCURLs() (ss []string) { - ss = make([]string, len(cfg.LCUrls)) - for i := range cfg.LCUrls { - ss[i] = cfg.LCUrls[i].String() - } - return ss -} - -func (cfg *Config) getMetricsURLs() (ss []string) { - ss = make([]string, len(cfg.ListenMetricsUrls)) - for i := range cfg.ListenMetricsUrls { - ss[i] = cfg.ListenMetricsUrls[i].String() - } - return ss -} - -func parseBackendFreelistType(freelistType string) bolt.FreelistType { - if freelistType == freelistArrayType { - return bolt.FreelistArrayType - } - - return bolt.FreelistMapType -} diff --git a/vendor/go.etcd.io/etcd/server/v3/embed/config_logging.go b/vendor/go.etcd.io/etcd/server/v3/embed/config_logging.go deleted file mode 100644 index 9cb6e57776..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/embed/config_logging.go +++ /dev/null @@ -1,265 +0,0 @@ -// Copyright 2018 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package embed - -import ( - "crypto/tls" - "encoding/json" - "errors" - "fmt" - "io/ioutil" - "net/url" - "os" - - "go.etcd.io/etcd/client/pkg/v3/logutil" - "go.uber.org/zap" - "go.uber.org/zap/zapcore" - "go.uber.org/zap/zapgrpc" - "google.golang.org/grpc" - "google.golang.org/grpc/grpclog" - "gopkg.in/natefinch/lumberjack.v2" -) - -// GetLogger returns the logger. -func (cfg Config) GetLogger() *zap.Logger { - cfg.loggerMu.RLock() - l := cfg.logger - cfg.loggerMu.RUnlock() - return l -} - -// setupLogging initializes etcd logging. -// Must be called after flag parsing or finishing configuring embed.Config. -func (cfg *Config) setupLogging() error { - switch cfg.Logger { - case "capnslog": // removed in v3.5 - return fmt.Errorf("--logger=capnslog is removed in v3.5") - - case "zap": - if len(cfg.LogOutputs) == 0 { - cfg.LogOutputs = []string{DefaultLogOutput} - } - if len(cfg.LogOutputs) > 1 { - for _, v := range cfg.LogOutputs { - if v == DefaultLogOutput { - return fmt.Errorf("multi logoutput for %q is not supported yet", DefaultLogOutput) - } - } - } - if cfg.EnableLogRotation { - if err := setupLogRotation(cfg.LogOutputs, cfg.LogRotationConfigJSON); err != nil { - return err - } - } - - outputPaths, errOutputPaths := make([]string, 0), make([]string, 0) - isJournal := false - for _, v := range cfg.LogOutputs { - switch v { - case DefaultLogOutput: - outputPaths = append(outputPaths, StdErrLogOutput) - errOutputPaths = append(errOutputPaths, StdErrLogOutput) - - case JournalLogOutput: - isJournal = true - - case StdErrLogOutput: - outputPaths = append(outputPaths, StdErrLogOutput) - errOutputPaths = append(errOutputPaths, StdErrLogOutput) - - case StdOutLogOutput: - outputPaths = append(outputPaths, StdOutLogOutput) - errOutputPaths = append(errOutputPaths, StdOutLogOutput) - - default: - var path string - if cfg.EnableLogRotation { - // append rotate scheme to logs managed by lumberjack log rotation - if v[0:1] == "/" { - path = fmt.Sprintf("rotate:/%%2F%s", v[1:]) - } else { - path = fmt.Sprintf("rotate:/%s", v) - } - } else { - path = v - } - outputPaths = append(outputPaths, path) - errOutputPaths = append(errOutputPaths, path) - } - } - - if !isJournal { - copied := logutil.DefaultZapLoggerConfig - copied.OutputPaths = outputPaths - copied.ErrorOutputPaths = errOutputPaths - copied = logutil.MergeOutputPaths(copied) - copied.Level = zap.NewAtomicLevelAt(logutil.ConvertToZapLevel(cfg.LogLevel)) - if cfg.ZapLoggerBuilder == nil { - lg, err := copied.Build() - if err != nil { - return err - } - cfg.ZapLoggerBuilder = NewZapLoggerBuilder(lg) - } - } else { - if len(cfg.LogOutputs) > 1 { - for _, v := range cfg.LogOutputs { - if v != DefaultLogOutput { - return fmt.Errorf("running with systemd/journal but other '--log-outputs' values (%q) are configured with 'default'; override 'default' value with something else", cfg.LogOutputs) - } - } - } - - // use stderr as fallback - syncer, lerr := getJournalWriteSyncer() - if lerr != nil { - return lerr - } - - lvl := zap.NewAtomicLevelAt(logutil.ConvertToZapLevel(cfg.LogLevel)) - - // WARN: do not change field names in encoder config - // journald logging writer assumes field names of "level" and "caller" - cr := zapcore.NewCore( - zapcore.NewJSONEncoder(logutil.DefaultZapLoggerConfig.EncoderConfig), - syncer, - lvl, - ) - if cfg.ZapLoggerBuilder == nil { - cfg.ZapLoggerBuilder = NewZapLoggerBuilder(zap.New(cr, zap.AddCaller(), zap.ErrorOutput(syncer))) - } - } - - err := cfg.ZapLoggerBuilder(cfg) - if err != nil { - return err - } - - logTLSHandshakeFailure := func(conn *tls.Conn, err error) { - state := conn.ConnectionState() - remoteAddr := conn.RemoteAddr().String() - serverName := state.ServerName - if len(state.PeerCertificates) > 0 { - cert := state.PeerCertificates[0] - ips := make([]string, len(cert.IPAddresses)) - for i := range cert.IPAddresses { - ips[i] = cert.IPAddresses[i].String() - } - cfg.logger.Warn( - "rejected connection", - zap.String("remote-addr", remoteAddr), - zap.String("server-name", serverName), - zap.Strings("ip-addresses", ips), - zap.Strings("dns-names", cert.DNSNames), - zap.Error(err), - ) - } else { - cfg.logger.Warn( - "rejected connection", - zap.String("remote-addr", remoteAddr), - zap.String("server-name", serverName), - zap.Error(err), - ) - } - } - cfg.ClientTLSInfo.HandshakeFailure = logTLSHandshakeFailure - cfg.PeerTLSInfo.HandshakeFailure = logTLSHandshakeFailure - - default: - return fmt.Errorf("unknown logger option %q", cfg.Logger) - } - - return nil -} - -// NewZapLoggerBuilder generates a zap logger builder that sets given loger -// for embedded etcd. -func NewZapLoggerBuilder(lg *zap.Logger) func(*Config) error { - return func(cfg *Config) error { - cfg.loggerMu.Lock() - defer cfg.loggerMu.Unlock() - cfg.logger = lg - return nil - } -} - -// NewZapCoreLoggerBuilder - is a deprecated setter for the logger. -// Deprecated: Use simpler NewZapLoggerBuilder. To be removed in etcd-3.6. -func NewZapCoreLoggerBuilder(lg *zap.Logger, _ zapcore.Core, _ zapcore.WriteSyncer) func(*Config) error { - return NewZapLoggerBuilder(lg) -} - -// SetupGlobalLoggers configures 'global' loggers (grpc, zapGlobal) based on the cfg. -// -// The method is not executed by embed server by default (since 3.5) to -// enable setups where grpc/zap.Global logging is configured independently -// or spans separate lifecycle (like in tests). -func (cfg *Config) SetupGlobalLoggers() { - lg := cfg.GetLogger() - if lg != nil { - if cfg.LogLevel == "debug" { - grpc.EnableTracing = true - grpclog.SetLoggerV2(zapgrpc.NewLogger(lg)) - } else { - grpclog.SetLoggerV2(grpclog.NewLoggerV2(ioutil.Discard, os.Stderr, os.Stderr)) - } - zap.ReplaceGlobals(lg) - } -} - -type logRotationConfig struct { - *lumberjack.Logger -} - -// Sync implements zap.Sink -func (logRotationConfig) Sync() error { return nil } - -// setupLogRotation initializes log rotation for a single file path target. -func setupLogRotation(logOutputs []string, logRotateConfigJSON string) error { - var logRotationConfig logRotationConfig - outputFilePaths := 0 - for _, v := range logOutputs { - switch v { - case DefaultLogOutput, StdErrLogOutput, StdOutLogOutput: - continue - default: - outputFilePaths++ - } - } - // log rotation requires file target - if len(logOutputs) == 1 && outputFilePaths == 0 { - return ErrLogRotationInvalidLogOutput - } - // support max 1 file target for log rotation - if outputFilePaths > 1 { - return ErrLogRotationInvalidLogOutput - } - - if err := json.Unmarshal([]byte(logRotateConfigJSON), &logRotationConfig); err != nil { - var unmarshalTypeError *json.UnmarshalTypeError - var syntaxError *json.SyntaxError - switch { - case errors.As(err, &syntaxError): - return fmt.Errorf("improperly formatted log rotation config: %w", err) - case errors.As(err, &unmarshalTypeError): - return fmt.Errorf("invalid log rotation config: %w", err) - } - } - zap.RegisterSink("rotate", func(u *url.URL) (zap.Sink, error) { - logRotationConfig.Filename = u.Path[1:] - return &logRotationConfig, nil - }) - return nil -} diff --git a/vendor/go.etcd.io/etcd/server/v3/embed/config_logging_journal_unix.go b/vendor/go.etcd.io/etcd/server/v3/embed/config_logging_journal_unix.go deleted file mode 100644 index 76bb73265f..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/embed/config_logging_journal_unix.go +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright 2018 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -//go:build !windows -// +build !windows - -package embed - -import ( - "fmt" - "os" - - "go.etcd.io/etcd/client/pkg/v3/logutil" - - "go.uber.org/zap/zapcore" -) - -// use stderr as fallback -func getJournalWriteSyncer() (zapcore.WriteSyncer, error) { - jw, err := logutil.NewJournalWriter(os.Stderr) - if err != nil { - return nil, fmt.Errorf("can't find journal (%v)", err) - } - return zapcore.AddSync(jw), nil -} diff --git a/vendor/go.etcd.io/etcd/server/v3/embed/config_logging_journal_windows.go b/vendor/go.etcd.io/etcd/server/v3/embed/config_logging_journal_windows.go deleted file mode 100644 index 58ed08631b..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/embed/config_logging_journal_windows.go +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright 2018 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -//go:build windows -// +build windows - -package embed - -import ( - "os" - - "go.uber.org/zap/zapcore" -) - -func getJournalWriteSyncer() (zapcore.WriteSyncer, error) { - return zapcore.AddSync(os.Stderr), nil -} diff --git a/vendor/go.etcd.io/etcd/server/v3/embed/doc.go b/vendor/go.etcd.io/etcd/server/v3/embed/doc.go deleted file mode 100644 index 3449855b5c..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/embed/doc.go +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/* -Package embed provides bindings for embedding an etcd server in a program. - -Launch an embedded etcd server using the configuration defaults: - - import ( - "log" - "time" - - "go.etcd.io/etcd/server/v3/embed" - ) - - func main() { - cfg := embed.NewConfig() - cfg.Dir = "default.etcd" - e, err := embed.StartEtcd(cfg) - if err != nil { - log.Fatal(err) - } - defer e.Close() - select { - case <-e.Server.ReadyNotify(): - log.Printf("Server is ready!") - case <-time.After(60 * time.Second): - e.Server.Stop() // trigger a shutdown - log.Printf("Server took too long to start!") - } - log.Fatal(<-e.Err()) - } -*/ -package embed diff --git a/vendor/go.etcd.io/etcd/server/v3/embed/etcd.go b/vendor/go.etcd.io/etcd/server/v3/embed/etcd.go deleted file mode 100644 index 001302f991..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/embed/etcd.go +++ /dev/null @@ -1,859 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package embed - -import ( - "context" - "crypto/tls" - "fmt" - "io/ioutil" - defaultLog "log" - "net" - "net/http" - "net/url" - "runtime" - "sort" - "strconv" - "sync" - "time" - - "go.etcd.io/etcd/api/v3/version" - "go.etcd.io/etcd/client/pkg/v3/transport" - "go.etcd.io/etcd/client/pkg/v3/types" - "go.etcd.io/etcd/pkg/v3/debugutil" - runtimeutil "go.etcd.io/etcd/pkg/v3/runtime" - "go.etcd.io/etcd/server/v3/config" - "go.etcd.io/etcd/server/v3/etcdserver" - "go.etcd.io/etcd/server/v3/etcdserver/api/etcdhttp" - "go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp" - "go.etcd.io/etcd/server/v3/etcdserver/api/v2http" - "go.etcd.io/etcd/server/v3/etcdserver/api/v2v3" - "go.etcd.io/etcd/server/v3/etcdserver/api/v3client" - "go.etcd.io/etcd/server/v3/etcdserver/api/v3rpc" - "go.etcd.io/etcd/server/v3/verify" - - grpc_prometheus "github.com/grpc-ecosystem/go-grpc-prometheus" - "github.com/soheilhy/cmux" - "go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc" - "go.opentelemetry.io/otel/exporters/otlp" - "go.opentelemetry.io/otel/exporters/otlp/otlpgrpc" - "go.opentelemetry.io/otel/propagation" - "go.opentelemetry.io/otel/sdk/resource" - tracesdk "go.opentelemetry.io/otel/sdk/trace" - "go.opentelemetry.io/otel/semconv" - "go.uber.org/zap" - "google.golang.org/grpc" - "google.golang.org/grpc/keepalive" -) - -const ( - // internal fd usage includes disk usage and transport usage. - // To read/write snapshot, snap pkg needs 1. In normal case, wal pkg needs - // at most 2 to read/lock/write WALs. One case that it needs to 2 is to - // read all logs after some snapshot index, which locates at the end of - // the second last and the head of the last. For purging, it needs to read - // directory, so it needs 1. For fd monitor, it needs 1. - // For transport, rafthttp builds two long-polling connections and at most - // four temporary connections with each member. There are at most 9 members - // in a cluster, so it should reserve 96. - // For the safety, we set the total reserved number to 150. - reservedInternalFDNum = 150 -) - -// Etcd contains a running etcd server and its listeners. -type Etcd struct { - Peers []*peerListener - Clients []net.Listener - // a map of contexts for the servers that serves client requests. - sctxs map[string]*serveCtx - metricsListeners []net.Listener - - tracingExporterShutdown func() - - Server *etcdserver.EtcdServer - - cfg Config - stopc chan struct{} - errc chan error - - closeOnce sync.Once -} - -type peerListener struct { - net.Listener - serve func() error - close func(context.Context) error -} - -// StartEtcd launches the etcd server and HTTP handlers for client/server communication. -// The returned Etcd.Server is not guaranteed to have joined the cluster. Wait -// on the Etcd.Server.ReadyNotify() channel to know when it completes and is ready for use. -func StartEtcd(inCfg *Config) (e *Etcd, err error) { - if err = inCfg.Validate(); err != nil { - return nil, err - } - serving := false - e = &Etcd{cfg: *inCfg, stopc: make(chan struct{})} - cfg := &e.cfg - defer func() { - if e == nil || err == nil { - return - } - if !serving { - // errored before starting gRPC server for serveCtx.serversC - for _, sctx := range e.sctxs { - close(sctx.serversC) - } - } - e.Close() - e = nil - }() - - if !cfg.SocketOpts.Empty() { - cfg.logger.Info( - "configuring socket options", - zap.Bool("reuse-address", cfg.SocketOpts.ReuseAddress), - zap.Bool("reuse-port", cfg.SocketOpts.ReusePort), - ) - } - e.cfg.logger.Info( - "configuring peer listeners", - zap.Strings("listen-peer-urls", e.cfg.getLPURLs()), - ) - if e.Peers, err = configurePeerListeners(cfg); err != nil { - return e, err - } - - e.cfg.logger.Info( - "configuring client listeners", - zap.Strings("listen-client-urls", e.cfg.getLCURLs()), - ) - if e.sctxs, err = configureClientListeners(cfg); err != nil { - return e, err - } - - for _, sctx := range e.sctxs { - e.Clients = append(e.Clients, sctx.l) - } - - var ( - urlsmap types.URLsMap - token string - ) - memberInitialized := true - if !isMemberInitialized(cfg) { - memberInitialized = false - urlsmap, token, err = cfg.PeerURLsMapAndToken("etcd") - if err != nil { - return e, fmt.Errorf("error setting up initial cluster: %v", err) - } - } - - // AutoCompactionRetention defaults to "0" if not set. - if len(cfg.AutoCompactionRetention) == 0 { - cfg.AutoCompactionRetention = "0" - } - autoCompactionRetention, err := parseCompactionRetention(cfg.AutoCompactionMode, cfg.AutoCompactionRetention) - if err != nil { - return e, err - } - - backendFreelistType := parseBackendFreelistType(cfg.BackendFreelistType) - - srvcfg := config.ServerConfig{ - Name: cfg.Name, - ClientURLs: cfg.ACUrls, - PeerURLs: cfg.APUrls, - DataDir: cfg.Dir, - DedicatedWALDir: cfg.WalDir, - SnapshotCount: cfg.SnapshotCount, - SnapshotCatchUpEntries: cfg.SnapshotCatchUpEntries, - MaxSnapFiles: cfg.MaxSnapFiles, - MaxWALFiles: cfg.MaxWalFiles, - InitialPeerURLsMap: urlsmap, - InitialClusterToken: token, - DiscoveryURL: cfg.Durl, - DiscoveryProxy: cfg.Dproxy, - NewCluster: cfg.IsNewCluster(), - PeerTLSInfo: cfg.PeerTLSInfo, - TickMs: cfg.TickMs, - ElectionTicks: cfg.ElectionTicks(), - InitialElectionTickAdvance: cfg.InitialElectionTickAdvance, - AutoCompactionRetention: autoCompactionRetention, - AutoCompactionMode: cfg.AutoCompactionMode, - QuotaBackendBytes: cfg.QuotaBackendBytes, - BackendBatchLimit: cfg.BackendBatchLimit, - BackendFreelistType: backendFreelistType, - BackendBatchInterval: cfg.BackendBatchInterval, - MaxTxnOps: cfg.MaxTxnOps, - MaxRequestBytes: cfg.MaxRequestBytes, - SocketOpts: cfg.SocketOpts, - StrictReconfigCheck: cfg.StrictReconfigCheck, - ClientCertAuthEnabled: cfg.ClientTLSInfo.ClientCertAuth, - AuthToken: cfg.AuthToken, - BcryptCost: cfg.BcryptCost, - TokenTTL: cfg.AuthTokenTTL, - CORS: cfg.CORS, - HostWhitelist: cfg.HostWhitelist, - InitialCorruptCheck: cfg.ExperimentalInitialCorruptCheck, - CorruptCheckTime: cfg.ExperimentalCorruptCheckTime, - PreVote: cfg.PreVote, - Logger: cfg.logger, - ForceNewCluster: cfg.ForceNewCluster, - EnableGRPCGateway: cfg.EnableGRPCGateway, - ExperimentalEnableDistributedTracing: cfg.ExperimentalEnableDistributedTracing, - UnsafeNoFsync: cfg.UnsafeNoFsync, - EnableLeaseCheckpoint: cfg.ExperimentalEnableLeaseCheckpoint, - CompactionBatchLimit: cfg.ExperimentalCompactionBatchLimit, - WatchProgressNotifyInterval: cfg.ExperimentalWatchProgressNotifyInterval, - DowngradeCheckTime: cfg.ExperimentalDowngradeCheckTime, - WarningApplyDuration: cfg.ExperimentalWarningApplyDuration, - ExperimentalMemoryMlock: cfg.ExperimentalMemoryMlock, - ExperimentalTxnModeWriteWithSharedBuffer: cfg.ExperimentalTxnModeWriteWithSharedBuffer, - ExperimentalBootstrapDefragThresholdMegabytes: cfg.ExperimentalBootstrapDefragThresholdMegabytes, - V2Deprecation: cfg.V2DeprecationEffective(), - } - - if srvcfg.ExperimentalEnableDistributedTracing { - tctx := context.Background() - tracingExporter, opts, err := e.setupTracing(tctx) - if err != nil { - return e, err - } - if tracingExporter == nil || len(opts) == 0 { - return e, fmt.Errorf("error setting up distributed tracing") - } - e.tracingExporterShutdown = func() { tracingExporter.Shutdown(tctx) } - srvcfg.ExperimentalTracerOptions = opts - } - - print(e.cfg.logger, *cfg, srvcfg, memberInitialized) - - if e.Server, err = etcdserver.NewServer(srvcfg); err != nil { - return e, err - } - - // buffer channel so goroutines on closed connections won't wait forever - e.errc = make(chan error, len(e.Peers)+len(e.Clients)+2*len(e.sctxs)) - - // newly started member ("memberInitialized==false") - // does not need corruption check - if memberInitialized { - if err = e.Server.CheckInitialHashKV(); err != nil { - // set "EtcdServer" to nil, so that it does not block on "EtcdServer.Close()" - // (nothing to close since rafthttp transports have not been started) - - e.cfg.logger.Error("checkInitialHashKV failed", zap.Error(err)) - e.Server.Cleanup() - e.Server = nil - return e, err - } - } - e.Server.Start() - - if err = e.servePeers(); err != nil { - return e, err - } - if err = e.serveClients(); err != nil { - return e, err - } - if err = e.serveMetrics(); err != nil { - return e, err - } - - e.cfg.logger.Info( - "now serving peer/client/metrics", - zap.String("local-member-id", e.Server.ID().String()), - zap.Strings("initial-advertise-peer-urls", e.cfg.getAPURLs()), - zap.Strings("listen-peer-urls", e.cfg.getLPURLs()), - zap.Strings("advertise-client-urls", e.cfg.getACURLs()), - zap.Strings("listen-client-urls", e.cfg.getLCURLs()), - zap.Strings("listen-metrics-urls", e.cfg.getMetricsURLs()), - ) - serving = true - return e, nil -} - -func print(lg *zap.Logger, ec Config, sc config.ServerConfig, memberInitialized bool) { - cors := make([]string, 0, len(ec.CORS)) - for v := range ec.CORS { - cors = append(cors, v) - } - sort.Strings(cors) - - hss := make([]string, 0, len(ec.HostWhitelist)) - for v := range ec.HostWhitelist { - hss = append(hss, v) - } - sort.Strings(hss) - - quota := ec.QuotaBackendBytes - if quota == 0 { - quota = etcdserver.DefaultQuotaBytes - } - - lg.Info( - "starting an etcd server", - zap.String("etcd-version", version.Version), - zap.String("git-sha", version.GitSHA), - zap.String("go-version", runtime.Version()), - zap.String("go-os", runtime.GOOS), - zap.String("go-arch", runtime.GOARCH), - zap.Int("max-cpu-set", runtime.GOMAXPROCS(0)), - zap.Int("max-cpu-available", runtime.NumCPU()), - zap.Bool("member-initialized", memberInitialized), - zap.String("name", sc.Name), - zap.String("data-dir", sc.DataDir), - zap.String("wal-dir", ec.WalDir), - zap.String("wal-dir-dedicated", sc.DedicatedWALDir), - zap.String("member-dir", sc.MemberDir()), - zap.Bool("force-new-cluster", sc.ForceNewCluster), - zap.String("heartbeat-interval", fmt.Sprintf("%v", time.Duration(sc.TickMs)*time.Millisecond)), - zap.String("election-timeout", fmt.Sprintf("%v", time.Duration(sc.ElectionTicks*int(sc.TickMs))*time.Millisecond)), - zap.Bool("initial-election-tick-advance", sc.InitialElectionTickAdvance), - zap.Uint64("snapshot-count", sc.SnapshotCount), - zap.Uint64("snapshot-catchup-entries", sc.SnapshotCatchUpEntries), - zap.Strings("initial-advertise-peer-urls", ec.getAPURLs()), - zap.Strings("listen-peer-urls", ec.getLPURLs()), - zap.Strings("advertise-client-urls", ec.getACURLs()), - zap.Strings("listen-client-urls", ec.getLCURLs()), - zap.Strings("listen-metrics-urls", ec.getMetricsURLs()), - zap.Strings("cors", cors), - zap.Strings("host-whitelist", hss), - zap.String("initial-cluster", sc.InitialPeerURLsMap.String()), - zap.String("initial-cluster-state", ec.ClusterState), - zap.String("initial-cluster-token", sc.InitialClusterToken), - zap.Int64("quota-size-bytes", quota), - zap.Bool("pre-vote", sc.PreVote), - zap.Bool("initial-corrupt-check", sc.InitialCorruptCheck), - zap.String("corrupt-check-time-interval", sc.CorruptCheckTime.String()), - zap.String("auto-compaction-mode", sc.AutoCompactionMode), - zap.Duration("auto-compaction-retention", sc.AutoCompactionRetention), - zap.String("auto-compaction-interval", sc.AutoCompactionRetention.String()), - zap.String("discovery-url", sc.DiscoveryURL), - zap.String("discovery-proxy", sc.DiscoveryProxy), - zap.String("downgrade-check-interval", sc.DowngradeCheckTime.String()), - ) -} - -// Config returns the current configuration. -func (e *Etcd) Config() Config { - return e.cfg -} - -// Close gracefully shuts down all servers/listeners. -// Client requests will be terminated with request timeout. -// After timeout, enforce remaning requests be closed immediately. -func (e *Etcd) Close() { - fields := []zap.Field{ - zap.String("name", e.cfg.Name), - zap.String("data-dir", e.cfg.Dir), - zap.Strings("advertise-peer-urls", e.cfg.getAPURLs()), - zap.Strings("advertise-client-urls", e.cfg.getACURLs()), - } - lg := e.GetLogger() - lg.Info("closing etcd server", fields...) - defer func() { - lg.Info("closed etcd server", fields...) - verify.MustVerifyIfEnabled(verify.Config{ - Logger: lg, - DataDir: e.cfg.Dir, - ExactIndex: false, - }) - lg.Sync() - }() - - e.closeOnce.Do(func() { - close(e.stopc) - }) - - // close client requests with request timeout - timeout := 2 * time.Second - if e.Server != nil { - timeout = e.Server.Cfg.ReqTimeout() - } - for _, sctx := range e.sctxs { - for ss := range sctx.serversC { - ctx, cancel := context.WithTimeout(context.Background(), timeout) - stopServers(ctx, ss) - cancel() - } - } - - for _, sctx := range e.sctxs { - sctx.cancel() - } - - for i := range e.Clients { - if e.Clients[i] != nil { - e.Clients[i].Close() - } - } - - for i := range e.metricsListeners { - e.metricsListeners[i].Close() - } - - // shutdown tracing exporter - if e.tracingExporterShutdown != nil { - e.tracingExporterShutdown() - } - - // close rafthttp transports - if e.Server != nil { - e.Server.Stop() - } - - // close all idle connections in peer handler (wait up to 1-second) - for i := range e.Peers { - if e.Peers[i] != nil && e.Peers[i].close != nil { - ctx, cancel := context.WithTimeout(context.Background(), time.Second) - e.Peers[i].close(ctx) - cancel() - } - } - if e.errc != nil { - close(e.errc) - } -} - -func stopServers(ctx context.Context, ss *servers) { - // first, close the http.Server - ss.http.Shutdown(ctx) - // do not grpc.Server.GracefulStop with TLS enabled etcd server - // See https://github.com/grpc/grpc-go/issues/1384#issuecomment-317124531 - // and https://github.com/etcd-io/etcd/issues/8916 - if ss.secure { - ss.grpc.Stop() - return - } - - ch := make(chan struct{}) - go func() { - defer close(ch) - // close listeners to stop accepting new connections, - // will block on any existing transports - ss.grpc.GracefulStop() - }() - - // wait until all pending RPCs are finished - select { - case <-ch: - case <-ctx.Done(): - // took too long, manually close open transports - // e.g. watch streams - ss.grpc.Stop() - - // concurrent GracefulStop should be interrupted - <-ch - } -} - -// Err - return channel used to report errors during etcd run/shutdown. -// Since etcd 3.5 the channel is being closed when the etcd is over. -func (e *Etcd) Err() <-chan error { - return e.errc -} - -func configurePeerListeners(cfg *Config) (peers []*peerListener, err error) { - if err = updateCipherSuites(&cfg.PeerTLSInfo, cfg.CipherSuites); err != nil { - return nil, err - } - if err = cfg.PeerSelfCert(); err != nil { - cfg.logger.Fatal("failed to get peer self-signed certs", zap.Error(err)) - } - if !cfg.PeerTLSInfo.Empty() { - cfg.logger.Info( - "starting with peer TLS", - zap.String("tls-info", fmt.Sprintf("%+v", cfg.PeerTLSInfo)), - zap.Strings("cipher-suites", cfg.CipherSuites), - ) - } - - peers = make([]*peerListener, len(cfg.LPUrls)) - defer func() { - if err == nil { - return - } - for i := range peers { - if peers[i] != nil && peers[i].close != nil { - cfg.logger.Warn( - "closing peer listener", - zap.String("address", cfg.LPUrls[i].String()), - zap.Error(err), - ) - ctx, cancel := context.WithTimeout(context.Background(), time.Second) - peers[i].close(ctx) - cancel() - } - } - }() - - for i, u := range cfg.LPUrls { - if u.Scheme == "http" { - if !cfg.PeerTLSInfo.Empty() { - cfg.logger.Warn("scheme is HTTP while key and cert files are present; ignoring key and cert files", zap.String("peer-url", u.String())) - } - if cfg.PeerTLSInfo.ClientCertAuth { - cfg.logger.Warn("scheme is HTTP while --peer-client-cert-auth is enabled; ignoring client cert auth for this URL", zap.String("peer-url", u.String())) - } - } - peers[i] = &peerListener{close: func(context.Context) error { return nil }} - peers[i].Listener, err = transport.NewListenerWithOpts(u.Host, u.Scheme, - transport.WithTLSInfo(&cfg.PeerTLSInfo), - transport.WithSocketOpts(&cfg.SocketOpts), - transport.WithTimeout(rafthttp.ConnReadTimeout, rafthttp.ConnWriteTimeout), - ) - if err != nil { - return nil, err - } - // once serve, overwrite with 'http.Server.Shutdown' - peers[i].close = func(context.Context) error { - return peers[i].Listener.Close() - } - } - return peers, nil -} - -// configure peer handlers after rafthttp.Transport started -func (e *Etcd) servePeers() (err error) { - ph := etcdhttp.NewPeerHandler(e.GetLogger(), e.Server) - var peerTLScfg *tls.Config - if !e.cfg.PeerTLSInfo.Empty() { - if peerTLScfg, err = e.cfg.PeerTLSInfo.ServerConfig(); err != nil { - return err - } - } - - for _, p := range e.Peers { - u := p.Listener.Addr().String() - gs := v3rpc.Server(e.Server, peerTLScfg) - m := cmux.New(p.Listener) - go gs.Serve(m.Match(cmux.HTTP2())) - srv := &http.Server{ - Handler: grpcHandlerFunc(gs, ph), - ReadTimeout: 5 * time.Minute, - ErrorLog: defaultLog.New(ioutil.Discard, "", 0), // do not log user error - } - go srv.Serve(m.Match(cmux.Any())) - p.serve = func() error { - e.cfg.logger.Info( - "cmux::serve", - zap.String("address", u), - ) - return m.Serve() - } - p.close = func(ctx context.Context) error { - // gracefully shutdown http.Server - // close open listeners, idle connections - // until context cancel or time-out - e.cfg.logger.Info( - "stopping serving peer traffic", - zap.String("address", u), - ) - stopServers(ctx, &servers{secure: peerTLScfg != nil, grpc: gs, http: srv}) - e.cfg.logger.Info( - "stopped serving peer traffic", - zap.String("address", u), - ) - m.Close() - return nil - } - } - - // start peer servers in a goroutine - for _, pl := range e.Peers { - go func(l *peerListener) { - u := l.Addr().String() - e.cfg.logger.Info( - "serving peer traffic", - zap.String("address", u), - ) - e.errHandler(l.serve()) - }(pl) - } - return nil -} - -func configureClientListeners(cfg *Config) (sctxs map[string]*serveCtx, err error) { - if err = updateCipherSuites(&cfg.ClientTLSInfo, cfg.CipherSuites); err != nil { - return nil, err - } - if err = cfg.ClientSelfCert(); err != nil { - cfg.logger.Fatal("failed to get client self-signed certs", zap.Error(err)) - } - if cfg.EnablePprof { - cfg.logger.Info("pprof is enabled", zap.String("path", debugutil.HTTPPrefixPProf)) - } - - sctxs = make(map[string]*serveCtx) - for _, u := range cfg.LCUrls { - sctx := newServeCtx(cfg.logger) - if u.Scheme == "http" || u.Scheme == "unix" { - if !cfg.ClientTLSInfo.Empty() { - cfg.logger.Warn("scheme is HTTP while key and cert files are present; ignoring key and cert files", zap.String("client-url", u.String())) - } - if cfg.ClientTLSInfo.ClientCertAuth { - cfg.logger.Warn("scheme is HTTP while --client-cert-auth is enabled; ignoring client cert auth for this URL", zap.String("client-url", u.String())) - } - } - if (u.Scheme == "https" || u.Scheme == "unixs") && cfg.ClientTLSInfo.Empty() { - return nil, fmt.Errorf("TLS key/cert (--cert-file, --key-file) must be provided for client url %s with HTTPS scheme", u.String()) - } - - network := "tcp" - addr := u.Host - if u.Scheme == "unix" || u.Scheme == "unixs" { - network = "unix" - addr = u.Host + u.Path - } - sctx.network = network - - sctx.secure = u.Scheme == "https" || u.Scheme == "unixs" - sctx.insecure = !sctx.secure - if oldctx := sctxs[addr]; oldctx != nil { - oldctx.secure = oldctx.secure || sctx.secure - oldctx.insecure = oldctx.insecure || sctx.insecure - continue - } - - if sctx.l, err = transport.NewListenerWithOpts(addr, u.Scheme, - transport.WithSocketOpts(&cfg.SocketOpts), - transport.WithSkipTLSInfoCheck(true), - ); err != nil { - return nil, err - } - // net.Listener will rewrite ipv4 0.0.0.0 to ipv6 [::], breaking - // hosts that disable ipv6. So, use the address given by the user. - sctx.addr = addr - - if fdLimit, fderr := runtimeutil.FDLimit(); fderr == nil { - if fdLimit <= reservedInternalFDNum { - cfg.logger.Fatal( - "file descriptor limit of etcd process is too low; please set higher", - zap.Uint64("limit", fdLimit), - zap.Int("recommended-limit", reservedInternalFDNum), - ) - } - sctx.l = transport.LimitListener(sctx.l, int(fdLimit-reservedInternalFDNum)) - } - - if network == "tcp" { - if sctx.l, err = transport.NewKeepAliveListener(sctx.l, network, nil); err != nil { - return nil, err - } - } - - defer func(u url.URL) { - if err == nil { - return - } - sctx.l.Close() - cfg.logger.Warn( - "closing peer listener", - zap.String("address", u.Host), - zap.Error(err), - ) - }(u) - for k := range cfg.UserHandlers { - sctx.userHandlers[k] = cfg.UserHandlers[k] - } - sctx.serviceRegister = cfg.ServiceRegister - if cfg.EnablePprof || cfg.LogLevel == "debug" { - sctx.registerPprof() - } - if cfg.LogLevel == "debug" { - sctx.registerTrace() - } - sctxs[addr] = sctx - } - return sctxs, nil -} - -func (e *Etcd) serveClients() (err error) { - if !e.cfg.ClientTLSInfo.Empty() { - e.cfg.logger.Info( - "starting with client TLS", - zap.String("tls-info", fmt.Sprintf("%+v", e.cfg.ClientTLSInfo)), - zap.Strings("cipher-suites", e.cfg.CipherSuites), - ) - } - - // Start a client server goroutine for each listen address - var h http.Handler - if e.Config().EnableV2 { - if e.Config().V2DeprecationEffective().IsAtLeast(config.V2_DEPR_1_WRITE_ONLY) { - return fmt.Errorf("--enable-v2 and --v2-deprecation=%s are mutually exclusive", e.Config().V2DeprecationEffective()) - } - e.cfg.logger.Warn("Flag `enable-v2` is deprecated and will get removed in etcd 3.6.") - if len(e.Config().ExperimentalEnableV2V3) > 0 { - e.cfg.logger.Warn("Flag `experimental-enable-v2v3` is deprecated and will get removed in etcd 3.6.") - srv := v2v3.NewServer(e.cfg.logger, v3client.New(e.Server), e.cfg.ExperimentalEnableV2V3) - h = v2http.NewClientHandler(e.GetLogger(), srv, e.Server.Cfg.ReqTimeout()) - } else { - h = v2http.NewClientHandler(e.GetLogger(), e.Server, e.Server.Cfg.ReqTimeout()) - } - } else { - mux := http.NewServeMux() - etcdhttp.HandleBasic(e.cfg.logger, mux, e.Server) - etcdhttp.HandleMetricsHealthForV3(e.cfg.logger, mux, e.Server) - h = mux - } - - gopts := []grpc.ServerOption{} - if e.cfg.GRPCKeepAliveMinTime > time.Duration(0) { - gopts = append(gopts, grpc.KeepaliveEnforcementPolicy(keepalive.EnforcementPolicy{ - MinTime: e.cfg.GRPCKeepAliveMinTime, - PermitWithoutStream: false, - })) - } - if e.cfg.GRPCKeepAliveInterval > time.Duration(0) && - e.cfg.GRPCKeepAliveTimeout > time.Duration(0) { - gopts = append(gopts, grpc.KeepaliveParams(keepalive.ServerParameters{ - Time: e.cfg.GRPCKeepAliveInterval, - Timeout: e.cfg.GRPCKeepAliveTimeout, - })) - } - - // start client servers in each goroutine - for _, sctx := range e.sctxs { - go func(s *serveCtx) { - e.errHandler(s.serve(e.Server, &e.cfg.ClientTLSInfo, h, e.errHandler, gopts...)) - }(sctx) - } - return nil -} - -func (e *Etcd) serveMetrics() (err error) { - if e.cfg.Metrics == "extensive" { - grpc_prometheus.EnableHandlingTimeHistogram() - } - - if len(e.cfg.ListenMetricsUrls) > 0 { - metricsMux := http.NewServeMux() - etcdhttp.HandleMetricsHealthForV3(e.cfg.logger, metricsMux, e.Server) - - for _, murl := range e.cfg.ListenMetricsUrls { - tlsInfo := &e.cfg.ClientTLSInfo - if murl.Scheme == "http" { - tlsInfo = nil - } - ml, err := transport.NewListenerWithOpts(murl.Host, murl.Scheme, - transport.WithTLSInfo(tlsInfo), - transport.WithSocketOpts(&e.cfg.SocketOpts), - ) - if err != nil { - return err - } - e.metricsListeners = append(e.metricsListeners, ml) - go func(u url.URL, ln net.Listener) { - e.cfg.logger.Info( - "serving metrics", - zap.String("address", u.String()), - ) - e.errHandler(http.Serve(ln, metricsMux)) - }(murl, ml) - } - } - return nil -} - -func (e *Etcd) errHandler(err error) { - select { - case <-e.stopc: - return - default: - } - select { - case <-e.stopc: - case e.errc <- err: - } -} - -// GetLogger returns the logger. -func (e *Etcd) GetLogger() *zap.Logger { - e.cfg.loggerMu.RLock() - l := e.cfg.logger - e.cfg.loggerMu.RUnlock() - return l -} - -func parseCompactionRetention(mode, retention string) (ret time.Duration, err error) { - h, err := strconv.Atoi(retention) - if err == nil && h >= 0 { - switch mode { - case CompactorModeRevision: - ret = time.Duration(int64(h)) - case CompactorModePeriodic: - ret = time.Duration(int64(h)) * time.Hour - } - } else { - // periodic compaction - ret, err = time.ParseDuration(retention) - if err != nil { - return 0, fmt.Errorf("error parsing CompactionRetention: %v", err) - } - } - return ret, nil -} - -func (e *Etcd) setupTracing(ctx context.Context) (exporter tracesdk.SpanExporter, options []otelgrpc.Option, err error) { - exporter, err = otlp.NewExporter(ctx, - otlpgrpc.NewDriver( - otlpgrpc.WithEndpoint(e.cfg.ExperimentalDistributedTracingAddress), - otlpgrpc.WithInsecure(), - )) - if err != nil { - return nil, nil, err - } - res := resource.NewWithAttributes( - semconv.ServiceNameKey.String(e.cfg.ExperimentalDistributedTracingServiceName), - ) - // As Tracing service Instance ID must be unique, it should - // never use the empty default string value, so we only set it - // if it's a non empty string. - if e.cfg.ExperimentalDistributedTracingServiceInstanceID != "" { - resWithIDKey := resource.NewWithAttributes( - (semconv.ServiceInstanceIDKey.String(e.cfg.ExperimentalDistributedTracingServiceInstanceID)), - ) - // Merge resources to combine into a new - // resource in case of duplicates. - res = resource.Merge(res, resWithIDKey) - } - - options = append(options, - otelgrpc.WithPropagators( - propagation.NewCompositeTextMapPropagator( - propagation.TraceContext{}, - propagation.Baggage{}, - ), - ), - otelgrpc.WithTracerProvider( - tracesdk.NewTracerProvider( - tracesdk.WithBatcher(exporter), - tracesdk.WithResource(res), - ), - ), - ) - - e.cfg.logger.Info( - "distributed tracing enabled", - zap.String("distributed-tracing-address", e.cfg.ExperimentalDistributedTracingAddress), - zap.String("distributed-tracing-service-name", e.cfg.ExperimentalDistributedTracingServiceName), - zap.String("distributed-tracing-service-instance-id", e.cfg.ExperimentalDistributedTracingServiceInstanceID), - ) - - return exporter, options, err -} diff --git a/vendor/go.etcd.io/etcd/server/v3/embed/serve.go b/vendor/go.etcd.io/etcd/server/v3/embed/serve.go deleted file mode 100644 index 17b55384eb..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/embed/serve.go +++ /dev/null @@ -1,427 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package embed - -import ( - "context" - "fmt" - "io/ioutil" - defaultLog "log" - "math" - "net" - "net/http" - "strings" - - etcdservergw "go.etcd.io/etcd/api/v3/etcdserverpb/gw" - "go.etcd.io/etcd/client/pkg/v3/transport" - "go.etcd.io/etcd/client/v3/credentials" - "go.etcd.io/etcd/pkg/v3/debugutil" - "go.etcd.io/etcd/pkg/v3/httputil" - "go.etcd.io/etcd/server/v3/etcdserver" - "go.etcd.io/etcd/server/v3/etcdserver/api/v3client" - "go.etcd.io/etcd/server/v3/etcdserver/api/v3election" - "go.etcd.io/etcd/server/v3/etcdserver/api/v3election/v3electionpb" - v3electiongw "go.etcd.io/etcd/server/v3/etcdserver/api/v3election/v3electionpb/gw" - "go.etcd.io/etcd/server/v3/etcdserver/api/v3lock" - "go.etcd.io/etcd/server/v3/etcdserver/api/v3lock/v3lockpb" - v3lockgw "go.etcd.io/etcd/server/v3/etcdserver/api/v3lock/v3lockpb/gw" - "go.etcd.io/etcd/server/v3/etcdserver/api/v3rpc" - - gw "github.com/grpc-ecosystem/grpc-gateway/runtime" - "github.com/soheilhy/cmux" - "github.com/tmc/grpc-websocket-proxy/wsproxy" - "go.uber.org/zap" - "golang.org/x/net/trace" - "google.golang.org/grpc" -) - -type serveCtx struct { - lg *zap.Logger - l net.Listener - addr string - network string - secure bool - insecure bool - - ctx context.Context - cancel context.CancelFunc - - userHandlers map[string]http.Handler - serviceRegister func(*grpc.Server) - serversC chan *servers -} - -type servers struct { - secure bool - grpc *grpc.Server - http *http.Server -} - -func newServeCtx(lg *zap.Logger) *serveCtx { - ctx, cancel := context.WithCancel(context.Background()) - if lg == nil { - lg = zap.NewNop() - } - return &serveCtx{ - lg: lg, - ctx: ctx, - cancel: cancel, - userHandlers: make(map[string]http.Handler), - serversC: make(chan *servers, 2), // in case sctx.insecure,sctx.secure true - } -} - -// serve accepts incoming connections on the listener l, -// creating a new service goroutine for each. The service goroutines -// read requests and then call handler to reply to them. -func (sctx *serveCtx) serve( - s *etcdserver.EtcdServer, - tlsinfo *transport.TLSInfo, - handler http.Handler, - errHandler func(error), - gopts ...grpc.ServerOption) (err error) { - logger := defaultLog.New(ioutil.Discard, "etcdhttp", 0) - <-s.ReadyNotify() - - sctx.lg.Info("ready to serve client requests") - - m := cmux.New(sctx.l) - v3c := v3client.New(s) - servElection := v3election.NewElectionServer(v3c) - servLock := v3lock.NewLockServer(v3c) - - var gs *grpc.Server - defer func() { - if err != nil && gs != nil { - gs.Stop() - } - }() - - if sctx.insecure { - gs = v3rpc.Server(s, nil, gopts...) - v3electionpb.RegisterElectionServer(gs, servElection) - v3lockpb.RegisterLockServer(gs, servLock) - if sctx.serviceRegister != nil { - sctx.serviceRegister(gs) - } - grpcl := m.Match(cmux.HTTP2()) - go func() { errHandler(gs.Serve(grpcl)) }() - - var gwmux *gw.ServeMux - if s.Cfg.EnableGRPCGateway { - gwmux, err = sctx.registerGateway([]grpc.DialOption{grpc.WithInsecure()}) - if err != nil { - return err - } - } - - httpmux := sctx.createMux(gwmux, handler) - - srvhttp := &http.Server{ - Handler: createAccessController(sctx.lg, s, httpmux), - ErrorLog: logger, // do not log user error - } - httpl := m.Match(cmux.HTTP1()) - go func() { errHandler(srvhttp.Serve(httpl)) }() - - sctx.serversC <- &servers{grpc: gs, http: srvhttp} - sctx.lg.Info( - "serving client traffic insecurely; this is strongly discouraged!", - zap.String("address", sctx.l.Addr().String()), - ) - } - - if sctx.secure { - tlscfg, tlsErr := tlsinfo.ServerConfig() - if tlsErr != nil { - return tlsErr - } - gs = v3rpc.Server(s, tlscfg, gopts...) - v3electionpb.RegisterElectionServer(gs, servElection) - v3lockpb.RegisterLockServer(gs, servLock) - if sctx.serviceRegister != nil { - sctx.serviceRegister(gs) - } - handler = grpcHandlerFunc(gs, handler) - - var gwmux *gw.ServeMux - if s.Cfg.EnableGRPCGateway { - dtls := tlscfg.Clone() - // trust local server - dtls.InsecureSkipVerify = true - bundle := credentials.NewBundle(credentials.Config{TLSConfig: dtls}) - opts := []grpc.DialOption{grpc.WithTransportCredentials(bundle.TransportCredentials())} - gwmux, err = sctx.registerGateway(opts) - if err != nil { - return err - } - } - - var tlsl net.Listener - tlsl, err = transport.NewTLSListener(m.Match(cmux.Any()), tlsinfo) - if err != nil { - return err - } - // TODO: add debug flag; enable logging when debug flag is set - httpmux := sctx.createMux(gwmux, handler) - - srv := &http.Server{ - Handler: createAccessController(sctx.lg, s, httpmux), - TLSConfig: tlscfg, - ErrorLog: logger, // do not log user error - } - go func() { errHandler(srv.Serve(tlsl)) }() - - sctx.serversC <- &servers{secure: true, grpc: gs, http: srv} - sctx.lg.Info( - "serving client traffic securely", - zap.String("address", sctx.l.Addr().String()), - ) - } - - close(sctx.serversC) - return m.Serve() -} - -// grpcHandlerFunc returns an http.Handler that delegates to grpcServer on incoming gRPC -// connections or otherHandler otherwise. Given in gRPC docs. -func grpcHandlerFunc(grpcServer *grpc.Server, otherHandler http.Handler) http.Handler { - if otherHandler == nil { - return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - grpcServer.ServeHTTP(w, r) - }) - } - return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - if r.ProtoMajor == 2 && strings.Contains(r.Header.Get("Content-Type"), "application/grpc") { - grpcServer.ServeHTTP(w, r) - } else { - otherHandler.ServeHTTP(w, r) - } - }) -} - -type registerHandlerFunc func(context.Context, *gw.ServeMux, *grpc.ClientConn) error - -func (sctx *serveCtx) registerGateway(opts []grpc.DialOption) (*gw.ServeMux, error) { - ctx := sctx.ctx - - addr := sctx.addr - if network := sctx.network; network == "unix" { - // explicitly define unix network for gRPC socket support - addr = fmt.Sprintf("%s://%s", network, addr) - } - - opts = append(opts, grpc.WithDefaultCallOptions([]grpc.CallOption{ - grpc.MaxCallRecvMsgSize(math.MaxInt32), - }...)) - - conn, err := grpc.DialContext(ctx, addr, opts...) - if err != nil { - return nil, err - } - gwmux := gw.NewServeMux() - - handlers := []registerHandlerFunc{ - etcdservergw.RegisterKVHandler, - etcdservergw.RegisterWatchHandler, - etcdservergw.RegisterLeaseHandler, - etcdservergw.RegisterClusterHandler, - etcdservergw.RegisterMaintenanceHandler, - etcdservergw.RegisterAuthHandler, - v3lockgw.RegisterLockHandler, - v3electiongw.RegisterElectionHandler, - } - for _, h := range handlers { - if err := h(ctx, gwmux, conn); err != nil { - return nil, err - } - } - go func() { - <-ctx.Done() - if cerr := conn.Close(); cerr != nil { - sctx.lg.Warn( - "failed to close connection", - zap.String("address", sctx.l.Addr().String()), - zap.Error(cerr), - ) - } - }() - - return gwmux, nil -} - -func (sctx *serveCtx) createMux(gwmux *gw.ServeMux, handler http.Handler) *http.ServeMux { - httpmux := http.NewServeMux() - for path, h := range sctx.userHandlers { - httpmux.Handle(path, h) - } - - if gwmux != nil { - httpmux.Handle( - "/v3/", - wsproxy.WebsocketProxy( - gwmux, - wsproxy.WithRequestMutator( - // Default to the POST method for streams - func(_ *http.Request, outgoing *http.Request) *http.Request { - outgoing.Method = "POST" - return outgoing - }, - ), - wsproxy.WithMaxRespBodyBufferSize(0x7fffffff), - ), - ) - } - if handler != nil { - httpmux.Handle("/", handler) - } - return httpmux -} - -// createAccessController wraps HTTP multiplexer: -// - mutate gRPC gateway request paths -// - check hostname whitelist -// client HTTP requests goes here first -func createAccessController(lg *zap.Logger, s *etcdserver.EtcdServer, mux *http.ServeMux) http.Handler { - if lg == nil { - lg = zap.NewNop() - } - return &accessController{lg: lg, s: s, mux: mux} -} - -type accessController struct { - lg *zap.Logger - s *etcdserver.EtcdServer - mux *http.ServeMux -} - -func (ac *accessController) ServeHTTP(rw http.ResponseWriter, req *http.Request) { - if req == nil { - http.Error(rw, "Request is nil", http.StatusBadRequest) - return - } - // redirect for backward compatibilities - if req.URL != nil && strings.HasPrefix(req.URL.Path, "/v3beta/") { - req.URL.Path = strings.Replace(req.URL.Path, "/v3beta/", "/v3/", 1) - } - - if req.TLS == nil { // check origin if client connection is not secure - host := httputil.GetHostname(req) - if !ac.s.AccessController.IsHostWhitelisted(host) { - ac.lg.Warn( - "rejecting HTTP request to prevent DNS rebinding attacks", - zap.String("host", host), - ) - http.Error(rw, errCVE20185702(host), http.StatusMisdirectedRequest) - return - } - } else if ac.s.Cfg.ClientCertAuthEnabled && ac.s.Cfg.EnableGRPCGateway && - ac.s.AuthStore().IsAuthEnabled() && strings.HasPrefix(req.URL.Path, "/v3/") { - for _, chains := range req.TLS.VerifiedChains { - if len(chains) < 1 { - continue - } - if len(chains[0].Subject.CommonName) != 0 { - http.Error(rw, "CommonName of client sending a request against gateway will be ignored and not used as expected", http.StatusBadRequest) - return - } - } - } - - // Write CORS header. - if ac.s.AccessController.OriginAllowed("*") { - addCORSHeader(rw, "*") - } else if origin := req.Header.Get("Origin"); ac.s.OriginAllowed(origin) { - addCORSHeader(rw, origin) - } - - if req.Method == "OPTIONS" { - rw.WriteHeader(http.StatusOK) - return - } - - ac.mux.ServeHTTP(rw, req) -} - -// addCORSHeader adds the correct cors headers given an origin -func addCORSHeader(w http.ResponseWriter, origin string) { - w.Header().Add("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE") - w.Header().Add("Access-Control-Allow-Origin", origin) - w.Header().Add("Access-Control-Allow-Headers", "accept, content-type, authorization") -} - -// https://github.com/transmission/transmission/pull/468 -func errCVE20185702(host string) string { - return fmt.Sprintf(` -etcd received your request, but the Host header was unrecognized. - -To fix this, choose one of the following options: -- Enable TLS, then any HTTPS request will be allowed. -- Add the hostname you want to use to the whitelist in settings. - - e.g. etcd --host-whitelist %q - -This requirement has been added to help prevent "DNS Rebinding" attacks (CVE-2018-5702). -`, host) -} - -// WrapCORS wraps existing handler with CORS. -// TODO: deprecate this after v2 proxy deprecate -func WrapCORS(cors map[string]struct{}, h http.Handler) http.Handler { - return &corsHandler{ - ac: &etcdserver.AccessController{CORS: cors}, - h: h, - } -} - -type corsHandler struct { - ac *etcdserver.AccessController - h http.Handler -} - -func (ch *corsHandler) ServeHTTP(rw http.ResponseWriter, req *http.Request) { - if ch.ac.OriginAllowed("*") { - addCORSHeader(rw, "*") - } else if origin := req.Header.Get("Origin"); ch.ac.OriginAllowed(origin) { - addCORSHeader(rw, origin) - } - - if req.Method == "OPTIONS" { - rw.WriteHeader(http.StatusOK) - return - } - - ch.h.ServeHTTP(rw, req) -} - -func (sctx *serveCtx) registerUserHandler(s string, h http.Handler) { - if sctx.userHandlers[s] != nil { - sctx.lg.Warn("path is already registered by user handler", zap.String("path", s)) - return - } - sctx.userHandlers[s] = h -} - -func (sctx *serveCtx) registerPprof() { - for p, h := range debugutil.PProfHandlers() { - sctx.registerUserHandler(p, h) - } -} - -func (sctx *serveCtx) registerTrace() { - reqf := func(w http.ResponseWriter, r *http.Request) { trace.Render(w, r, true) } - sctx.registerUserHandler("/debug/requests", http.HandlerFunc(reqf)) - evf := func(w http.ResponseWriter, r *http.Request) { trace.RenderEvents(w, r, true) } - sctx.registerUserHandler("/debug/events", http.HandlerFunc(evf)) -} diff --git a/vendor/go.etcd.io/etcd/server/v3/embed/util.go b/vendor/go.etcd.io/etcd/server/v3/embed/util.go deleted file mode 100644 index ad46153455..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/embed/util.go +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package embed - -import ( - "path/filepath" - - "go.etcd.io/etcd/server/v3/wal" -) - -func isMemberInitialized(cfg *Config) bool { - waldir := cfg.WalDir - if waldir == "" { - waldir = filepath.Join(cfg.Dir, "member", "wal") - } - return wal.Exist(waldir) -} diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/capability.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/capability.go deleted file mode 100644 index ea2f0e97e4..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/capability.go +++ /dev/null @@ -1,95 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package api - -import ( - "sync" - - "go.etcd.io/etcd/api/v3/version" - "go.etcd.io/etcd/server/v3/etcdserver/api/membership" - "go.uber.org/zap" - - "github.com/coreos/go-semver/semver" -) - -type Capability string - -const ( - AuthCapability Capability = "auth" - V3rpcCapability Capability = "v3rpc" -) - -var ( - // capabilityMaps is a static map of version to capability map. - capabilityMaps = map[string]map[Capability]bool{ - "3.0.0": {AuthCapability: true, V3rpcCapability: true}, - "3.1.0": {AuthCapability: true, V3rpcCapability: true}, - "3.2.0": {AuthCapability: true, V3rpcCapability: true}, - "3.3.0": {AuthCapability: true, V3rpcCapability: true}, - "3.4.0": {AuthCapability: true, V3rpcCapability: true}, - "3.5.0": {AuthCapability: true, V3rpcCapability: true}, - } - - enableMapMu sync.RWMutex - // enabledMap points to a map in capabilityMaps - enabledMap map[Capability]bool - - curVersion *semver.Version -) - -func init() { - enabledMap = map[Capability]bool{ - AuthCapability: true, - V3rpcCapability: true, - } -} - -// UpdateCapability updates the enabledMap when the cluster version increases. -func UpdateCapability(lg *zap.Logger, v *semver.Version) { - if v == nil { - // if recovered but version was never set by cluster - return - } - enableMapMu.Lock() - if curVersion != nil && !membership.IsValidVersionChange(v, curVersion) { - enableMapMu.Unlock() - return - } - curVersion = v - enabledMap = capabilityMaps[curVersion.String()] - enableMapMu.Unlock() - - if lg != nil { - lg.Info( - "enabled capabilities for version", - zap.String("cluster-version", version.Cluster(v.String())), - ) - } -} - -func IsCapabilityEnabled(c Capability) bool { - enableMapMu.RLock() - defer enableMapMu.RUnlock() - if enabledMap == nil { - return false - } - return enabledMap[c] -} - -func EnableCapability(c Capability) { - enableMapMu.Lock() - defer enableMapMu.Unlock() - enabledMap[c] = true -} diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/cluster.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/cluster.go deleted file mode 100644 index f05997da52..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/cluster.go +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package api - -import ( - "go.etcd.io/etcd/client/pkg/v3/types" - "go.etcd.io/etcd/server/v3/etcdserver/api/membership" - - "github.com/coreos/go-semver/semver" -) - -// Cluster is an interface representing a collection of members in one etcd cluster. -type Cluster interface { - // ID returns the cluster ID - ID() types.ID - // ClientURLs returns an aggregate set of all URLs on which this - // cluster is listening for client requests - ClientURLs() []string - // Members returns a slice of members sorted by their ID - Members() []*membership.Member - // Member retrieves a particular member based on ID, or nil if the - // member does not exist in the cluster - Member(id types.ID) *membership.Member - // Version is the cluster-wide minimum major.minor version. - Version() *semver.Version -} diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/doc.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/doc.go deleted file mode 100644 index f44881be66..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/doc.go +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package api manages the capabilities and features that are exposed to clients by the etcd cluster. -package api diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/etcdhttp/base.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/etcdhttp/base.go deleted file mode 100644 index dcfa3f0695..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/etcdhttp/base.go +++ /dev/null @@ -1,156 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package etcdhttp - -import ( - "encoding/json" - "expvar" - "fmt" - "net/http" - - "go.etcd.io/etcd/api/v3/version" - "go.etcd.io/etcd/server/v3/etcdserver" - "go.etcd.io/etcd/server/v3/etcdserver/api" - "go.etcd.io/etcd/server/v3/etcdserver/api/v2error" - "go.etcd.io/etcd/server/v3/etcdserver/api/v2http/httptypes" - "go.uber.org/zap" -) - -const ( - configPath = "/config" - varsPath = "/debug/vars" - versionPath = "/version" -) - -// HandleBasic adds handlers to a mux for serving JSON etcd client requests -// that do not access the v2 store. -func HandleBasic(lg *zap.Logger, mux *http.ServeMux, server etcdserver.ServerPeer) { - mux.HandleFunc(varsPath, serveVars) - mux.HandleFunc(versionPath, versionHandler(server.Cluster(), serveVersion)) -} - -func versionHandler(c api.Cluster, fn func(http.ResponseWriter, *http.Request, string)) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - v := c.Version() - if v != nil { - fn(w, r, v.String()) - } else { - fn(w, r, "not_decided") - } - } -} - -func serveVersion(w http.ResponseWriter, r *http.Request, clusterV string) { - if !allowMethod(w, r, "GET") { - return - } - vs := version.Versions{ - Server: version.Version, - Cluster: clusterV, - } - - w.Header().Set("Content-Type", "application/json") - b, err := json.Marshal(&vs) - if err != nil { - panic(fmt.Sprintf("cannot marshal versions to json (%v)", err)) - } - w.Write(b) -} - -func serveVars(w http.ResponseWriter, r *http.Request) { - if !allowMethod(w, r, "GET") { - return - } - - w.Header().Set("Content-Type", "application/json; charset=utf-8") - fmt.Fprintf(w, "{\n") - first := true - expvar.Do(func(kv expvar.KeyValue) { - if !first { - fmt.Fprintf(w, ",\n") - } - first = false - fmt.Fprintf(w, "%q: %s", kv.Key, kv.Value) - }) - fmt.Fprintf(w, "\n}\n") -} - -func allowMethod(w http.ResponseWriter, r *http.Request, m string) bool { - if m == r.Method { - return true - } - w.Header().Set("Allow", m) - http.Error(w, "Method Not Allowed", http.StatusMethodNotAllowed) - return false -} - -// WriteError logs and writes the given Error to the ResponseWriter -// If Error is an etcdErr, it is rendered to the ResponseWriter -// Otherwise, it is assumed to be a StatusInternalServerError -func WriteError(lg *zap.Logger, w http.ResponseWriter, r *http.Request, err error) { - if err == nil { - return - } - switch e := err.(type) { - case *v2error.Error: - e.WriteTo(w) - - case *httptypes.HTTPError: - if et := e.WriteTo(w); et != nil { - if lg != nil { - lg.Debug( - "failed to write v2 HTTP error", - zap.String("remote-addr", r.RemoteAddr), - zap.String("internal-server-error", e.Error()), - zap.Error(et), - ) - } - } - - default: - switch err { - case etcdserver.ErrTimeoutDueToLeaderFail, etcdserver.ErrTimeoutDueToConnectionLost, etcdserver.ErrNotEnoughStartedMembers, - etcdserver.ErrUnhealthy: - if lg != nil { - lg.Warn( - "v2 response error", - zap.String("remote-addr", r.RemoteAddr), - zap.String("internal-server-error", err.Error()), - ) - } - - default: - if lg != nil { - lg.Warn( - "unexpected v2 response error", - zap.String("remote-addr", r.RemoteAddr), - zap.String("internal-server-error", err.Error()), - ) - } - } - - herr := httptypes.NewHTTPError(http.StatusInternalServerError, "Internal Server Error") - if et := herr.WriteTo(w); et != nil { - if lg != nil { - lg.Debug( - "failed to write v2 HTTP error", - zap.String("remote-addr", r.RemoteAddr), - zap.String("internal-server-error", err.Error()), - zap.Error(et), - ) - } - } - } -} diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/etcdhttp/doc.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/etcdhttp/doc.go deleted file mode 100644 index a03b626204..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/etcdhttp/doc.go +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package etcdhttp implements HTTP transportation layer for etcdserver. -package etcdhttp diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/etcdhttp/metrics.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/etcdhttp/metrics.go deleted file mode 100644 index b14a13c9c5..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/etcdhttp/metrics.go +++ /dev/null @@ -1,204 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package etcdhttp - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - "time" - - "github.com/prometheus/client_golang/prometheus" - "github.com/prometheus/client_golang/prometheus/promhttp" - "go.etcd.io/etcd/api/v3/etcdserverpb" - "go.etcd.io/etcd/raft/v3" - "go.etcd.io/etcd/server/v3/etcdserver" - "go.uber.org/zap" -) - -const ( - PathMetrics = "/metrics" - PathHealth = "/health" - PathProxyMetrics = "/proxy/metrics" - PathProxyHealth = "/proxy/health" -) - -// HandleMetricsHealth registers metrics and health handlers. -func HandleMetricsHealth(lg *zap.Logger, mux *http.ServeMux, srv etcdserver.ServerV2) { - mux.Handle(PathMetrics, promhttp.Handler()) - mux.Handle(PathHealth, NewHealthHandler(lg, func(excludedAlarms AlarmSet) Health { return checkV2Health(lg, srv, excludedAlarms) })) -} - -// HandleMetricsHealthForV3 registers metrics and health handlers. it checks health by using v3 range request -// and its corresponding timeout. -func HandleMetricsHealthForV3(lg *zap.Logger, mux *http.ServeMux, srv *etcdserver.EtcdServer) { - mux.Handle(PathMetrics, promhttp.Handler()) - mux.Handle(PathHealth, NewHealthHandler(lg, func(excludedAlarms AlarmSet) Health { return checkV3Health(lg, srv, excludedAlarms) })) -} - -// HandlePrometheus registers prometheus handler on '/metrics'. -func HandlePrometheus(mux *http.ServeMux) { - mux.Handle(PathMetrics, promhttp.Handler()) -} - -// NewHealthHandler handles '/health' requests. -func NewHealthHandler(lg *zap.Logger, hfunc func(excludedAlarms AlarmSet) Health) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - if r.Method != http.MethodGet { - w.Header().Set("Allow", http.MethodGet) - http.Error(w, "Method Not Allowed", http.StatusMethodNotAllowed) - lg.Warn("/health error", zap.Int("status-code", http.StatusMethodNotAllowed)) - return - } - excludedAlarms := getExcludedAlarms(r) - h := hfunc(excludedAlarms) - defer func() { - if h.Health == "true" { - healthSuccess.Inc() - } else { - healthFailed.Inc() - } - }() - d, _ := json.Marshal(h) - if h.Health != "true" { - http.Error(w, string(d), http.StatusServiceUnavailable) - lg.Warn("/health error", zap.String("output", string(d)), zap.Int("status-code", http.StatusServiceUnavailable)) - return - } - w.WriteHeader(http.StatusOK) - w.Write(d) - lg.Debug("/health OK", zap.Int("status-code", http.StatusOK)) - } -} - -var ( - healthSuccess = prometheus.NewCounter(prometheus.CounterOpts{ - Namespace: "etcd", - Subsystem: "server", - Name: "health_success", - Help: "The total number of successful health checks", - }) - healthFailed = prometheus.NewCounter(prometheus.CounterOpts{ - Namespace: "etcd", - Subsystem: "server", - Name: "health_failures", - Help: "The total number of failed health checks", - }) -) - -func init() { - prometheus.MustRegister(healthSuccess) - prometheus.MustRegister(healthFailed) -} - -// Health defines etcd server health status. -// TODO: remove manual parsing in etcdctl cluster-health -type Health struct { - Health string `json:"health"` - Reason string `json:"reason"` -} - -type AlarmSet map[string]struct{} - -func getExcludedAlarms(r *http.Request) (alarms AlarmSet) { - alarms = make(map[string]struct{}, 2) - alms, found := r.URL.Query()["exclude"] - if found { - for _, alm := range alms { - if len(alms) == 0 { - continue - } - alarms[alm] = struct{}{} - } - } - return alarms -} - -// TODO: etcdserver.ErrNoLeader in health API - -func checkHealth(lg *zap.Logger, srv etcdserver.ServerV2, excludedAlarms AlarmSet) Health { - h := Health{} - h.Health = "true" - as := srv.Alarms() - if len(as) > 0 { - for _, v := range as { - alarmName := v.Alarm.String() - if _, found := excludedAlarms[alarmName]; found { - lg.Debug("/health excluded alarm", zap.String("alarm", alarmName)) - delete(excludedAlarms, alarmName) - continue - } - - h.Health = "false" - switch v.Alarm { - case etcdserverpb.AlarmType_NOSPACE: - h.Reason = "ALARM NOSPACE" - case etcdserverpb.AlarmType_CORRUPT: - h.Reason = "ALARM CORRUPT" - default: - h.Reason = "ALARM UNKNOWN" - } - lg.Warn("serving /health false due to an alarm", zap.String("alarm", v.String())) - return h - } - } - - if len(excludedAlarms) > 0 { - lg.Warn("fail exclude alarms from health check", zap.String("exclude alarms", fmt.Sprintf("%+v", excludedAlarms))) - } - - if uint64(srv.Leader()) == raft.None { - h.Health = "false" - h.Reason = "RAFT NO LEADER" - lg.Warn("serving /health false; no leader") - return h - } - return h -} - -func checkV2Health(lg *zap.Logger, srv etcdserver.ServerV2, excludedAlarms AlarmSet) (h Health) { - if h = checkHealth(lg, srv, excludedAlarms); h.Health != "true" { - return - } - ctx, cancel := context.WithTimeout(context.Background(), time.Second) - _, err := srv.Do(ctx, etcdserverpb.Request{Method: "QGET"}) - cancel() - if err != nil { - h.Health = "false" - h.Reason = fmt.Sprintf("QGET ERROR:%s", err) - lg.Warn("serving /health false; QGET fails", zap.Error(err)) - return - } - lg.Debug("serving /health true") - return -} - -func checkV3Health(lg *zap.Logger, srv *etcdserver.EtcdServer, excludedAlarms AlarmSet) (h Health) { - if h = checkHealth(lg, srv, excludedAlarms); h.Health != "true" { - return - } - ctx, cancel := context.WithTimeout(context.Background(), srv.Cfg.ReqTimeout()) - _, err := srv.Range(ctx, &etcdserverpb.RangeRequest{KeysOnly: true, Limit: 1}) - cancel() - if err != nil { - h.Health = "false" - h.Reason = fmt.Sprintf("RANGE ERROR:%s", err) - lg.Warn("serving /health false; Range fails", zap.Error(err)) - return - } - lg.Debug("serving /health true") - return -} diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/etcdhttp/peer.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/etcdhttp/peer.go deleted file mode 100644 index badc98634b..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/etcdhttp/peer.go +++ /dev/null @@ -1,163 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package etcdhttp - -import ( - "encoding/json" - "fmt" - "net/http" - "strconv" - "strings" - - "go.etcd.io/etcd/client/pkg/v3/types" - "go.etcd.io/etcd/server/v3/etcdserver" - "go.etcd.io/etcd/server/v3/etcdserver/api" - "go.etcd.io/etcd/server/v3/etcdserver/api/membership" - "go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp" - "go.etcd.io/etcd/server/v3/lease/leasehttp" - - "go.uber.org/zap" -) - -const ( - peerMembersPath = "/members" - peerMemberPromotePrefix = "/members/promote/" -) - -// NewPeerHandler generates an http.Handler to handle etcd peer requests. -func NewPeerHandler(lg *zap.Logger, s etcdserver.ServerPeerV2) http.Handler { - return newPeerHandler(lg, s, s.RaftHandler(), s.LeaseHandler(), s.HashKVHandler(), s.DowngradeEnabledHandler()) -} - -func newPeerHandler( - lg *zap.Logger, - s etcdserver.Server, - raftHandler http.Handler, - leaseHandler http.Handler, - hashKVHandler http.Handler, - downgradeEnabledHandler http.Handler, -) http.Handler { - if lg == nil { - lg = zap.NewNop() - } - peerMembersHandler := newPeerMembersHandler(lg, s.Cluster()) - peerMemberPromoteHandler := newPeerMemberPromoteHandler(lg, s) - - mux := http.NewServeMux() - mux.HandleFunc("/", http.NotFound) - mux.Handle(rafthttp.RaftPrefix, raftHandler) - mux.Handle(rafthttp.RaftPrefix+"/", raftHandler) - mux.Handle(peerMembersPath, peerMembersHandler) - mux.Handle(peerMemberPromotePrefix, peerMemberPromoteHandler) - if leaseHandler != nil { - mux.Handle(leasehttp.LeasePrefix, leaseHandler) - mux.Handle(leasehttp.LeaseInternalPrefix, leaseHandler) - } - if downgradeEnabledHandler != nil { - mux.Handle(etcdserver.DowngradeEnabledPath, downgradeEnabledHandler) - } - if hashKVHandler != nil { - mux.Handle(etcdserver.PeerHashKVPath, hashKVHandler) - } - mux.HandleFunc(versionPath, versionHandler(s.Cluster(), serveVersion)) - return mux -} - -func newPeerMembersHandler(lg *zap.Logger, cluster api.Cluster) http.Handler { - return &peerMembersHandler{ - lg: lg, - cluster: cluster, - } -} - -type peerMembersHandler struct { - lg *zap.Logger - cluster api.Cluster -} - -func newPeerMemberPromoteHandler(lg *zap.Logger, s etcdserver.Server) http.Handler { - return &peerMemberPromoteHandler{ - lg: lg, - cluster: s.Cluster(), - server: s, - } -} - -type peerMemberPromoteHandler struct { - lg *zap.Logger - cluster api.Cluster - server etcdserver.Server -} - -func (h *peerMembersHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { - if !allowMethod(w, r, "GET") { - return - } - w.Header().Set("X-Etcd-Cluster-ID", h.cluster.ID().String()) - - if r.URL.Path != peerMembersPath { - http.Error(w, "bad path", http.StatusBadRequest) - return - } - ms := h.cluster.Members() - w.Header().Set("Content-Type", "application/json") - if err := json.NewEncoder(w).Encode(ms); err != nil { - h.lg.Warn("failed to encode membership members", zap.Error(err)) - } -} - -func (h *peerMemberPromoteHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { - if !allowMethod(w, r, "POST") { - return - } - w.Header().Set("X-Etcd-Cluster-ID", h.cluster.ID().String()) - - if !strings.HasPrefix(r.URL.Path, peerMemberPromotePrefix) { - http.Error(w, "bad path", http.StatusBadRequest) - return - } - idStr := strings.TrimPrefix(r.URL.Path, peerMemberPromotePrefix) - id, err := strconv.ParseUint(idStr, 10, 64) - if err != nil { - http.Error(w, fmt.Sprintf("member %s not found in cluster", idStr), http.StatusNotFound) - return - } - - resp, err := h.server.PromoteMember(r.Context(), id) - if err != nil { - switch err { - case membership.ErrIDNotFound: - http.Error(w, err.Error(), http.StatusNotFound) - case membership.ErrMemberNotLearner: - http.Error(w, err.Error(), http.StatusPreconditionFailed) - case etcdserver.ErrLearnerNotReady: - http.Error(w, err.Error(), http.StatusPreconditionFailed) - default: - WriteError(h.lg, w, r, err) - } - h.lg.Warn( - "failed to promote a member", - zap.String("member-id", types.ID(id).String()), - zap.Error(err), - ) - return - } - - w.Header().Set("Content-Type", "application/json") - w.WriteHeader(http.StatusOK) - if err := json.NewEncoder(w).Encode(resp); err != nil { - h.lg.Warn("failed to encode members response", zap.Error(err)) - } -} diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/membership/cluster.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/membership/cluster.go deleted file mode 100644 index 3df9588be8..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/membership/cluster.go +++ /dev/null @@ -1,882 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package membership - -import ( - "bytes" - "context" - "crypto/sha1" - "encoding/binary" - "encoding/json" - "fmt" - "path" - "sort" - "strings" - "sync" - "time" - - "go.etcd.io/etcd/api/v3/version" - "go.etcd.io/etcd/client/pkg/v3/types" - "go.etcd.io/etcd/pkg/v3/netutil" - "go.etcd.io/etcd/raft/v3" - "go.etcd.io/etcd/raft/v3/raftpb" - "go.etcd.io/etcd/server/v3/etcdserver/api/v2store" - "go.etcd.io/etcd/server/v3/mvcc/backend" - "go.etcd.io/etcd/server/v3/mvcc/buckets" - - "github.com/coreos/go-semver/semver" - "github.com/prometheus/client_golang/prometheus" - "go.uber.org/zap" -) - -const maxLearners = 1 - -// RaftCluster is a list of Members that belong to the same raft cluster -type RaftCluster struct { - lg *zap.Logger - - localID types.ID - cid types.ID - - v2store v2store.Store - be backend.Backend - - sync.Mutex // guards the fields below - version *semver.Version - members map[types.ID]*Member - // removed contains the ids of removed members in the cluster. - // removed id cannot be reused. - removed map[types.ID]bool - - downgradeInfo *DowngradeInfo -} - -// ConfigChangeContext represents a context for confChange. -type ConfigChangeContext struct { - Member - // IsPromote indicates if the config change is for promoting a learner member. - // This flag is needed because both adding a new member and promoting a learner member - // uses the same config change type 'ConfChangeAddNode'. - IsPromote bool `json:"isPromote"` -} - -type ShouldApplyV3 bool - -const ( - ApplyBoth = ShouldApplyV3(true) - ApplyV2storeOnly = ShouldApplyV3(false) -) - -// NewClusterFromURLsMap creates a new raft cluster using provided urls map. Currently, it does not support creating -// cluster with raft learner member. -func NewClusterFromURLsMap(lg *zap.Logger, token string, urlsmap types.URLsMap) (*RaftCluster, error) { - c := NewCluster(lg) - for name, urls := range urlsmap { - m := NewMember(name, urls, token, nil) - if _, ok := c.members[m.ID]; ok { - return nil, fmt.Errorf("member exists with identical ID %v", m) - } - if uint64(m.ID) == raft.None { - return nil, fmt.Errorf("cannot use %x as member id", raft.None) - } - c.members[m.ID] = m - } - c.genID() - return c, nil -} - -func NewClusterFromMembers(lg *zap.Logger, id types.ID, membs []*Member) *RaftCluster { - c := NewCluster(lg) - c.cid = id - for _, m := range membs { - c.members[m.ID] = m - } - return c -} - -func NewCluster(lg *zap.Logger) *RaftCluster { - if lg == nil { - lg = zap.NewNop() - } - return &RaftCluster{ - lg: lg, - members: make(map[types.ID]*Member), - removed: make(map[types.ID]bool), - downgradeInfo: &DowngradeInfo{Enabled: false}, - } -} - -func (c *RaftCluster) ID() types.ID { return c.cid } - -func (c *RaftCluster) Members() []*Member { - c.Lock() - defer c.Unlock() - var ms MembersByID - for _, m := range c.members { - ms = append(ms, m.Clone()) - } - sort.Sort(ms) - return []*Member(ms) -} - -func (c *RaftCluster) Member(id types.ID) *Member { - c.Lock() - defer c.Unlock() - return c.members[id].Clone() -} - -func (c *RaftCluster) VotingMembers() []*Member { - c.Lock() - defer c.Unlock() - var ms MembersByID - for _, m := range c.members { - if !m.IsLearner { - ms = append(ms, m.Clone()) - } - } - sort.Sort(ms) - return []*Member(ms) -} - -// MemberByName returns a Member with the given name if exists. -// If more than one member has the given name, it will panic. -func (c *RaftCluster) MemberByName(name string) *Member { - c.Lock() - defer c.Unlock() - var memb *Member - for _, m := range c.members { - if m.Name == name { - if memb != nil { - c.lg.Panic("two member with same name found", zap.String("name", name)) - } - memb = m - } - } - return memb.Clone() -} - -func (c *RaftCluster) MemberIDs() []types.ID { - c.Lock() - defer c.Unlock() - var ids []types.ID - for _, m := range c.members { - ids = append(ids, m.ID) - } - sort.Sort(types.IDSlice(ids)) - return ids -} - -func (c *RaftCluster) IsIDRemoved(id types.ID) bool { - c.Lock() - defer c.Unlock() - return c.removed[id] -} - -// PeerURLs returns a list of all peer addresses. -// The returned list is sorted in ascending lexicographical order. -func (c *RaftCluster) PeerURLs() []string { - c.Lock() - defer c.Unlock() - urls := make([]string, 0) - for _, p := range c.members { - urls = append(urls, p.PeerURLs...) - } - sort.Strings(urls) - return urls -} - -// ClientURLs returns a list of all client addresses. -// The returned list is sorted in ascending lexicographical order. -func (c *RaftCluster) ClientURLs() []string { - c.Lock() - defer c.Unlock() - urls := make([]string, 0) - for _, p := range c.members { - urls = append(urls, p.ClientURLs...) - } - sort.Strings(urls) - return urls -} - -func (c *RaftCluster) String() string { - c.Lock() - defer c.Unlock() - b := &bytes.Buffer{} - fmt.Fprintf(b, "{ClusterID:%s ", c.cid) - var ms []string - for _, m := range c.members { - ms = append(ms, fmt.Sprintf("%+v", m)) - } - fmt.Fprintf(b, "Members:[%s] ", strings.Join(ms, " ")) - var ids []string - for id := range c.removed { - ids = append(ids, id.String()) - } - fmt.Fprintf(b, "RemovedMemberIDs:[%s]}", strings.Join(ids, " ")) - return b.String() -} - -func (c *RaftCluster) genID() { - mIDs := c.MemberIDs() - b := make([]byte, 8*len(mIDs)) - for i, id := range mIDs { - binary.BigEndian.PutUint64(b[8*i:], uint64(id)) - } - hash := sha1.Sum(b) - c.cid = types.ID(binary.BigEndian.Uint64(hash[:8])) -} - -func (c *RaftCluster) SetID(localID, cid types.ID) { - c.localID = localID - c.cid = cid -} - -func (c *RaftCluster) SetStore(st v2store.Store) { c.v2store = st } - -func (c *RaftCluster) SetBackend(be backend.Backend) { - c.be = be - mustCreateBackendBuckets(c.be) -} - -func (c *RaftCluster) Recover(onSet func(*zap.Logger, *semver.Version)) { - c.Lock() - defer c.Unlock() - - if c.be != nil { - c.version = clusterVersionFromBackend(c.lg, c.be) - c.members, c.removed = membersFromBackend(c.lg, c.be) - } else { - c.version = clusterVersionFromStore(c.lg, c.v2store) - c.members, c.removed = membersFromStore(c.lg, c.v2store) - } - - if c.be != nil { - c.downgradeInfo = downgradeInfoFromBackend(c.lg, c.be) - } - d := &DowngradeInfo{Enabled: false} - if c.downgradeInfo != nil { - d = &DowngradeInfo{Enabled: c.downgradeInfo.Enabled, TargetVersion: c.downgradeInfo.TargetVersion} - } - mustDetectDowngrade(c.lg, c.version, d) - onSet(c.lg, c.version) - - for _, m := range c.members { - c.lg.Info( - "recovered/added member from store", - zap.String("cluster-id", c.cid.String()), - zap.String("local-member-id", c.localID.String()), - zap.String("recovered-remote-peer-id", m.ID.String()), - zap.Strings("recovered-remote-peer-urls", m.PeerURLs), - ) - } - if c.version != nil { - c.lg.Info( - "set cluster version from store", - zap.String("cluster-version", version.Cluster(c.version.String())), - ) - } -} - -// ValidateConfigurationChange takes a proposed ConfChange and -// ensures that it is still valid. -func (c *RaftCluster) ValidateConfigurationChange(cc raftpb.ConfChange) error { - // TODO: this must be switched to backend as well. - members, removed := membersFromStore(c.lg, c.v2store) - id := types.ID(cc.NodeID) - if removed[id] { - return ErrIDRemoved - } - switch cc.Type { - case raftpb.ConfChangeAddNode, raftpb.ConfChangeAddLearnerNode: - confChangeContext := new(ConfigChangeContext) - if err := json.Unmarshal(cc.Context, confChangeContext); err != nil { - c.lg.Panic("failed to unmarshal confChangeContext", zap.Error(err)) - } - - if confChangeContext.IsPromote { // promoting a learner member to voting member - if members[id] == nil { - return ErrIDNotFound - } - if !members[id].IsLearner { - return ErrMemberNotLearner - } - } else { // adding a new member - if members[id] != nil { - return ErrIDExists - } - - urls := make(map[string]bool) - for _, m := range members { - for _, u := range m.PeerURLs { - urls[u] = true - } - } - for _, u := range confChangeContext.Member.PeerURLs { - if urls[u] { - return ErrPeerURLexists - } - } - - if confChangeContext.Member.IsLearner { // the new member is a learner - numLearners := 0 - for _, m := range members { - if m.IsLearner { - numLearners++ - } - } - if numLearners+1 > maxLearners { - return ErrTooManyLearners - } - } - } - case raftpb.ConfChangeRemoveNode: - if members[id] == nil { - return ErrIDNotFound - } - - case raftpb.ConfChangeUpdateNode: - if members[id] == nil { - return ErrIDNotFound - } - urls := make(map[string]bool) - for _, m := range members { - if m.ID == id { - continue - } - for _, u := range m.PeerURLs { - urls[u] = true - } - } - m := new(Member) - if err := json.Unmarshal(cc.Context, m); err != nil { - c.lg.Panic("failed to unmarshal member", zap.Error(err)) - } - for _, u := range m.PeerURLs { - if urls[u] { - return ErrPeerURLexists - } - } - - default: - c.lg.Panic("unknown ConfChange type", zap.String("type", cc.Type.String())) - } - return nil -} - -// AddMember adds a new Member into the cluster, and saves the given member's -// raftAttributes into the store. The given member should have empty attributes. -// A Member with a matching id must not exist. -func (c *RaftCluster) AddMember(m *Member, shouldApplyV3 ShouldApplyV3) { - c.Lock() - defer c.Unlock() - if c.v2store != nil { - mustSaveMemberToStore(c.lg, c.v2store, m) - } - if c.be != nil && shouldApplyV3 { - mustSaveMemberToBackend(c.lg, c.be, m) - } - - c.members[m.ID] = m - - c.lg.Info( - "added member", - zap.String("cluster-id", c.cid.String()), - zap.String("local-member-id", c.localID.String()), - zap.String("added-peer-id", m.ID.String()), - zap.Strings("added-peer-peer-urls", m.PeerURLs), - ) -} - -// RemoveMember removes a member from the store. -// The given id MUST exist, or the function panics. -func (c *RaftCluster) RemoveMember(id types.ID, shouldApplyV3 ShouldApplyV3) { - c.Lock() - defer c.Unlock() - if c.v2store != nil { - mustDeleteMemberFromStore(c.lg, c.v2store, id) - } - if c.be != nil && shouldApplyV3 { - mustDeleteMemberFromBackend(c.be, id) - } - - m, ok := c.members[id] - delete(c.members, id) - c.removed[id] = true - - if ok { - c.lg.Info( - "removed member", - zap.String("cluster-id", c.cid.String()), - zap.String("local-member-id", c.localID.String()), - zap.String("removed-remote-peer-id", id.String()), - zap.Strings("removed-remote-peer-urls", m.PeerURLs), - ) - } else { - c.lg.Warn( - "skipped removing already removed member", - zap.String("cluster-id", c.cid.String()), - zap.String("local-member-id", c.localID.String()), - zap.String("removed-remote-peer-id", id.String()), - ) - } -} - -func (c *RaftCluster) UpdateAttributes(id types.ID, attr Attributes, shouldApplyV3 ShouldApplyV3) { - c.Lock() - defer c.Unlock() - - if m, ok := c.members[id]; ok { - m.Attributes = attr - if c.v2store != nil { - mustUpdateMemberAttrInStore(c.lg, c.v2store, m) - } - if c.be != nil && shouldApplyV3 { - mustSaveMemberToBackend(c.lg, c.be, m) - } - return - } - - _, ok := c.removed[id] - if !ok { - c.lg.Panic( - "failed to update; member unknown", - zap.String("cluster-id", c.cid.String()), - zap.String("local-member-id", c.localID.String()), - zap.String("unknown-remote-peer-id", id.String()), - ) - } - - c.lg.Warn( - "skipped attributes update of removed member", - zap.String("cluster-id", c.cid.String()), - zap.String("local-member-id", c.localID.String()), - zap.String("updated-peer-id", id.String()), - ) -} - -// PromoteMember marks the member's IsLearner RaftAttributes to false. -func (c *RaftCluster) PromoteMember(id types.ID, shouldApplyV3 ShouldApplyV3) { - c.Lock() - defer c.Unlock() - - c.members[id].RaftAttributes.IsLearner = false - if c.v2store != nil { - mustUpdateMemberInStore(c.lg, c.v2store, c.members[id]) - } - if c.be != nil && shouldApplyV3 { - mustSaveMemberToBackend(c.lg, c.be, c.members[id]) - } - - c.lg.Info( - "promote member", - zap.String("cluster-id", c.cid.String()), - zap.String("local-member-id", c.localID.String()), - ) -} - -func (c *RaftCluster) UpdateRaftAttributes(id types.ID, raftAttr RaftAttributes, shouldApplyV3 ShouldApplyV3) { - c.Lock() - defer c.Unlock() - - c.members[id].RaftAttributes = raftAttr - if c.v2store != nil { - mustUpdateMemberInStore(c.lg, c.v2store, c.members[id]) - } - if c.be != nil && shouldApplyV3 { - mustSaveMemberToBackend(c.lg, c.be, c.members[id]) - } - - c.lg.Info( - "updated member", - zap.String("cluster-id", c.cid.String()), - zap.String("local-member-id", c.localID.String()), - zap.String("updated-remote-peer-id", id.String()), - zap.Strings("updated-remote-peer-urls", raftAttr.PeerURLs), - ) -} - -func (c *RaftCluster) Version() *semver.Version { - c.Lock() - defer c.Unlock() - if c.version == nil { - return nil - } - return semver.Must(semver.NewVersion(c.version.String())) -} - -func (c *RaftCluster) SetVersion(ver *semver.Version, onSet func(*zap.Logger, *semver.Version), shouldApplyV3 ShouldApplyV3) { - c.Lock() - defer c.Unlock() - if c.version != nil { - c.lg.Info( - "updated cluster version", - zap.String("cluster-id", c.cid.String()), - zap.String("local-member-id", c.localID.String()), - zap.String("from", version.Cluster(c.version.String())), - zap.String("to", version.Cluster(ver.String())), - ) - } else { - c.lg.Info( - "set initial cluster version", - zap.String("cluster-id", c.cid.String()), - zap.String("local-member-id", c.localID.String()), - zap.String("cluster-version", version.Cluster(ver.String())), - ) - } - oldVer := c.version - c.version = ver - mustDetectDowngrade(c.lg, c.version, c.downgradeInfo) - if c.v2store != nil { - mustSaveClusterVersionToStore(c.lg, c.v2store, ver) - } - if c.be != nil && shouldApplyV3 { - mustSaveClusterVersionToBackend(c.be, ver) - } - if oldVer != nil { - ClusterVersionMetrics.With(prometheus.Labels{"cluster_version": version.Cluster(oldVer.String())}).Set(0) - } - ClusterVersionMetrics.With(prometheus.Labels{"cluster_version": version.Cluster(ver.String())}).Set(1) - onSet(c.lg, ver) -} - -func (c *RaftCluster) IsReadyToAddVotingMember() bool { - nmembers := 1 - nstarted := 0 - - for _, member := range c.VotingMembers() { - if member.IsStarted() { - nstarted++ - } - nmembers++ - } - - if nstarted == 1 && nmembers == 2 { - // a case of adding a new node to 1-member cluster for restoring cluster data - // https://github.com/etcd-io/website/blob/main/content/docs/v2/admin_guide.md#restoring-the-cluster - c.lg.Debug("number of started member is 1; can accept add member request") - return true - } - - nquorum := nmembers/2 + 1 - if nstarted < nquorum { - c.lg.Warn( - "rejecting member add; started member will be less than quorum", - zap.Int("number-of-started-member", nstarted), - zap.Int("quorum", nquorum), - zap.String("cluster-id", c.cid.String()), - zap.String("local-member-id", c.localID.String()), - ) - return false - } - - return true -} - -func (c *RaftCluster) IsReadyToRemoveVotingMember(id uint64) bool { - nmembers := 0 - nstarted := 0 - - for _, member := range c.VotingMembers() { - if uint64(member.ID) == id { - continue - } - - if member.IsStarted() { - nstarted++ - } - nmembers++ - } - - nquorum := nmembers/2 + 1 - if nstarted < nquorum { - c.lg.Warn( - "rejecting member remove; started member will be less than quorum", - zap.Int("number-of-started-member", nstarted), - zap.Int("quorum", nquorum), - zap.String("cluster-id", c.cid.String()), - zap.String("local-member-id", c.localID.String()), - ) - return false - } - - return true -} - -func (c *RaftCluster) IsReadyToPromoteMember(id uint64) bool { - nmembers := 1 // We count the learner to be promoted for the future quorum - nstarted := 1 // and we also count it as started. - - for _, member := range c.VotingMembers() { - if member.IsStarted() { - nstarted++ - } - nmembers++ - } - - nquorum := nmembers/2 + 1 - if nstarted < nquorum { - c.lg.Warn( - "rejecting member promote; started member will be less than quorum", - zap.Int("number-of-started-member", nstarted), - zap.Int("quorum", nquorum), - zap.String("cluster-id", c.cid.String()), - zap.String("local-member-id", c.localID.String()), - ) - return false - } - - return true -} - -func membersFromStore(lg *zap.Logger, st v2store.Store) (map[types.ID]*Member, map[types.ID]bool) { - members := make(map[types.ID]*Member) - removed := make(map[types.ID]bool) - e, err := st.Get(StoreMembersPrefix, true, true) - if err != nil { - if isKeyNotFound(err) { - return members, removed - } - lg.Panic("failed to get members from store", zap.String("path", StoreMembersPrefix), zap.Error(err)) - } - for _, n := range e.Node.Nodes { - var m *Member - m, err = nodeToMember(lg, n) - if err != nil { - lg.Panic("failed to nodeToMember", zap.Error(err)) - } - members[m.ID] = m - } - - e, err = st.Get(storeRemovedMembersPrefix, true, true) - if err != nil { - if isKeyNotFound(err) { - return members, removed - } - lg.Panic( - "failed to get removed members from store", - zap.String("path", storeRemovedMembersPrefix), - zap.Error(err), - ) - } - for _, n := range e.Node.Nodes { - removed[MustParseMemberIDFromKey(lg, n.Key)] = true - } - return members, removed -} - -func membersFromBackend(lg *zap.Logger, be backend.Backend) (map[types.ID]*Member, map[types.ID]bool) { - return mustReadMembersFromBackend(lg, be) -} - -func clusterVersionFromStore(lg *zap.Logger, st v2store.Store) *semver.Version { - e, err := st.Get(path.Join(storePrefix, "version"), false, false) - if err != nil { - if isKeyNotFound(err) { - return nil - } - lg.Panic( - "failed to get cluster version from store", - zap.String("path", path.Join(storePrefix, "version")), - zap.Error(err), - ) - } - return semver.Must(semver.NewVersion(*e.Node.Value)) -} - -// The field is populated since etcd v3.5. -func clusterVersionFromBackend(lg *zap.Logger, be backend.Backend) *semver.Version { - ckey := backendClusterVersionKey() - tx := be.ReadTx() - tx.RLock() - defer tx.RUnlock() - keys, vals := tx.UnsafeRange(buckets.Cluster, ckey, nil, 0) - if len(keys) == 0 { - return nil - } - if len(keys) != 1 { - lg.Panic( - "unexpected number of keys when getting cluster version from backend", - zap.Int("number-of-key", len(keys)), - ) - } - return semver.Must(semver.NewVersion(string(vals[0]))) -} - -// The field is populated since etcd v3.5. -func downgradeInfoFromBackend(lg *zap.Logger, be backend.Backend) *DowngradeInfo { - dkey := backendDowngradeKey() - tx := be.ReadTx() - tx.Lock() - defer tx.Unlock() - keys, vals := tx.UnsafeRange(buckets.Cluster, dkey, nil, 0) - if len(keys) == 0 { - return nil - } - - if len(keys) != 1 { - lg.Panic( - "unexpected number of keys when getting cluster version from backend", - zap.Int("number-of-key", len(keys)), - ) - } - var d DowngradeInfo - if err := json.Unmarshal(vals[0], &d); err != nil { - lg.Panic("failed to unmarshal downgrade information", zap.Error(err)) - } - - // verify the downgrade info from backend - if d.Enabled { - if _, err := semver.NewVersion(d.TargetVersion); err != nil { - lg.Panic( - "unexpected version format of the downgrade target version from backend", - zap.String("target-version", d.TargetVersion), - ) - } - } - return &d -} - -// ValidateClusterAndAssignIDs validates the local cluster by matching the PeerURLs -// with the existing cluster. If the validation succeeds, it assigns the IDs -// from the existing cluster to the local cluster. -// If the validation fails, an error will be returned. -func ValidateClusterAndAssignIDs(lg *zap.Logger, local *RaftCluster, existing *RaftCluster) error { - ems := existing.Members() - lms := local.Members() - if len(ems) != len(lms) { - return fmt.Errorf("member count is unequal") - } - - ctx, cancel := context.WithTimeout(context.TODO(), 30*time.Second) - defer cancel() - for i := range ems { - var err error - ok := false - for j := range lms { - if ok, err = netutil.URLStringsEqual(ctx, lg, ems[i].PeerURLs, lms[j].PeerURLs); ok { - lms[j].ID = ems[i].ID - break - } - } - if !ok { - return fmt.Errorf("PeerURLs: no match found for existing member (%v, %v), last resolver error (%v)", ems[i].ID, ems[i].PeerURLs, err) - } - } - local.members = make(map[types.ID]*Member) - for _, m := range lms { - local.members[m.ID] = m - } - return nil -} - -// IsValidVersionChange checks the two scenario when version is valid to change: -// 1. Downgrade: cluster version is 1 minor version higher than local version, -// cluster version should change. -// 2. Cluster start: when not all members version are available, cluster version -// is set to MinVersion(3.0), when all members are at higher version, cluster version -// is lower than local version, cluster version should change -func IsValidVersionChange(cv *semver.Version, lv *semver.Version) bool { - cv = &semver.Version{Major: cv.Major, Minor: cv.Minor} - lv = &semver.Version{Major: lv.Major, Minor: lv.Minor} - - if isValidDowngrade(cv, lv) || (cv.Major == lv.Major && cv.LessThan(*lv)) { - return true - } - return false -} - -// IsLocalMemberLearner returns if the local member is raft learner -func (c *RaftCluster) IsLocalMemberLearner() bool { - c.Lock() - defer c.Unlock() - localMember, ok := c.members[c.localID] - if !ok { - c.lg.Panic( - "failed to find local ID in cluster members", - zap.String("cluster-id", c.cid.String()), - zap.String("local-member-id", c.localID.String()), - ) - } - return localMember.IsLearner -} - -// DowngradeInfo returns the downgrade status of the cluster -func (c *RaftCluster) DowngradeInfo() *DowngradeInfo { - c.Lock() - defer c.Unlock() - if c.downgradeInfo == nil { - return &DowngradeInfo{Enabled: false} - } - d := &DowngradeInfo{Enabled: c.downgradeInfo.Enabled, TargetVersion: c.downgradeInfo.TargetVersion} - return d -} - -func (c *RaftCluster) SetDowngradeInfo(d *DowngradeInfo, shouldApplyV3 ShouldApplyV3) { - c.Lock() - defer c.Unlock() - - if c.be != nil && shouldApplyV3 { - mustSaveDowngradeToBackend(c.lg, c.be, d) - } - - c.downgradeInfo = d - - if d.Enabled { - c.lg.Info( - "The server is ready to downgrade", - zap.String("target-version", d.TargetVersion), - zap.String("server-version", version.Version), - ) - } -} - -// IsMemberExist returns if the member with the given id exists in cluster. -func (c *RaftCluster) IsMemberExist(id types.ID) bool { - c.Lock() - defer c.Unlock() - _, ok := c.members[id] - return ok -} - -// VotingMemberIDs returns the ID of voting members in cluster. -func (c *RaftCluster) VotingMemberIDs() []types.ID { - c.Lock() - defer c.Unlock() - var ids []types.ID - for _, m := range c.members { - if !m.IsLearner { - ids = append(ids, m.ID) - } - } - sort.Sort(types.IDSlice(ids)) - return ids -} - -// PushMembershipToStorage is overriding storage information about cluster's -// members, such that they fully reflect internal RaftCluster's storage. -func (c *RaftCluster) PushMembershipToStorage() { - if c.be != nil { - TrimMembershipFromBackend(c.lg, c.be) - for _, m := range c.members { - mustSaveMemberToBackend(c.lg, c.be, m) - } - } - if c.v2store != nil { - TrimMembershipFromV2Store(c.lg, c.v2store) - for _, m := range c.members { - mustSaveMemberToStore(c.lg, c.v2store, m) - } - } -} diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/membership/confstate.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/membership/confstate.go deleted file mode 100644 index 3aa8c649b2..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/membership/confstate.go +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright 2021 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package membership - -import ( - "encoding/json" - "log" - - "go.etcd.io/etcd/raft/v3/raftpb" - "go.etcd.io/etcd/server/v3/mvcc/backend" - "go.etcd.io/etcd/server/v3/mvcc/buckets" - "go.uber.org/zap" -) - -var ( - confStateKey = []byte("confState") -) - -// MustUnsafeSaveConfStateToBackend persists confState using given transaction (tx). -// confState in backend is persisted since etcd v3.5. -func MustUnsafeSaveConfStateToBackend(lg *zap.Logger, tx backend.BatchTx, confState *raftpb.ConfState) { - confStateBytes, err := json.Marshal(confState) - if err != nil { - lg.Panic("Cannot marshal raftpb.ConfState", zap.Stringer("conf-state", confState), zap.Error(err)) - } - - tx.UnsafePut(buckets.Meta, confStateKey, confStateBytes) -} - -// UnsafeConfStateFromBackend retrieves ConfState from the backend. -// Returns nil if confState in backend is not persisted (e.g. backend writen by 0 { - return false, nil - } - } - - return true, nil -} diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp/coder.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp/coder.go deleted file mode 100644 index cc28249697..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp/coder.go +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package rafthttp - -import "go.etcd.io/etcd/raft/v3/raftpb" - -type encoder interface { - // encode encodes the given message to an output stream. - encode(m *raftpb.Message) error -} - -type decoder interface { - // decode decodes the message from an input stream. - decode() (raftpb.Message, error) -} diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp/doc.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp/doc.go deleted file mode 100644 index a9486a8bb6..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp/doc.go +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package rafthttp implements HTTP transportation layer for etcd/raft pkg. -package rafthttp diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp/http.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp/http.go deleted file mode 100644 index 149c50b79c..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp/http.go +++ /dev/null @@ -1,531 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package rafthttp - -import ( - "context" - "errors" - "fmt" - "io/ioutil" - "net/http" - "path" - "strings" - "time" - - "go.etcd.io/etcd/api/v3/version" - "go.etcd.io/etcd/client/pkg/v3/types" - pioutil "go.etcd.io/etcd/pkg/v3/ioutil" - "go.etcd.io/etcd/raft/v3/raftpb" - "go.etcd.io/etcd/server/v3/etcdserver/api/snap" - - humanize "github.com/dustin/go-humanize" - "go.uber.org/zap" -) - -const ( - // connReadLimitByte limits the number of bytes - // a single read can read out. - // - // 64KB should be large enough for not causing - // throughput bottleneck as well as small enough - // for not causing a read timeout. - connReadLimitByte = 64 * 1024 - - // snapshotLimitByte limits the snapshot size to 1TB - snapshotLimitByte = 1 * 1024 * 1024 * 1024 * 1024 -) - -var ( - RaftPrefix = "/raft" - ProbingPrefix = path.Join(RaftPrefix, "probing") - RaftStreamPrefix = path.Join(RaftPrefix, "stream") - RaftSnapshotPrefix = path.Join(RaftPrefix, "snapshot") - - errIncompatibleVersion = errors.New("incompatible version") - errClusterIDMismatch = errors.New("cluster ID mismatch") -) - -type peerGetter interface { - Get(id types.ID) Peer -} - -type writerToResponse interface { - WriteTo(w http.ResponseWriter) -} - -type pipelineHandler struct { - lg *zap.Logger - localID types.ID - tr Transporter - r Raft - cid types.ID -} - -// newPipelineHandler returns a handler for handling raft messages -// from pipeline for RaftPrefix. -// -// The handler reads out the raft message from request body, -// and forwards it to the given raft state machine for processing. -func newPipelineHandler(t *Transport, r Raft, cid types.ID) http.Handler { - h := &pipelineHandler{ - lg: t.Logger, - localID: t.ID, - tr: t, - r: r, - cid: cid, - } - if h.lg == nil { - h.lg = zap.NewNop() - } - return h -} - -func (h *pipelineHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { - if r.Method != "POST" { - w.Header().Set("Allow", "POST") - http.Error(w, "Method Not Allowed", http.StatusMethodNotAllowed) - return - } - - w.Header().Set("X-Etcd-Cluster-ID", h.cid.String()) - - if err := checkClusterCompatibilityFromHeader(h.lg, h.localID, r.Header, h.cid); err != nil { - http.Error(w, err.Error(), http.StatusPreconditionFailed) - return - } - - addRemoteFromRequest(h.tr, r) - - // Limit the data size that could be read from the request body, which ensures that read from - // connection will not time out accidentally due to possible blocking in underlying implementation. - limitedr := pioutil.NewLimitedBufferReader(r.Body, connReadLimitByte) - b, err := ioutil.ReadAll(limitedr) - if err != nil { - h.lg.Warn( - "failed to read Raft message", - zap.String("local-member-id", h.localID.String()), - zap.Error(err), - ) - http.Error(w, "error reading raft message", http.StatusBadRequest) - recvFailures.WithLabelValues(r.RemoteAddr).Inc() - return - } - - var m raftpb.Message - if err := m.Unmarshal(b); err != nil { - h.lg.Warn( - "failed to unmarshal Raft message", - zap.String("local-member-id", h.localID.String()), - zap.Error(err), - ) - http.Error(w, "error unmarshalling raft message", http.StatusBadRequest) - recvFailures.WithLabelValues(r.RemoteAddr).Inc() - return - } - - receivedBytes.WithLabelValues(types.ID(m.From).String()).Add(float64(len(b))) - - if err := h.r.Process(context.TODO(), m); err != nil { - switch v := err.(type) { - case writerToResponse: - v.WriteTo(w) - default: - h.lg.Warn( - "failed to process Raft message", - zap.String("local-member-id", h.localID.String()), - zap.Error(err), - ) - http.Error(w, "error processing raft message", http.StatusInternalServerError) - w.(http.Flusher).Flush() - // disconnect the http stream - panic(err) - } - return - } - - // Write StatusNoContent header after the message has been processed by - // raft, which facilitates the client to report MsgSnap status. - w.WriteHeader(http.StatusNoContent) -} - -type snapshotHandler struct { - lg *zap.Logger - tr Transporter - r Raft - snapshotter *snap.Snapshotter - - localID types.ID - cid types.ID -} - -func newSnapshotHandler(t *Transport, r Raft, snapshotter *snap.Snapshotter, cid types.ID) http.Handler { - h := &snapshotHandler{ - lg: t.Logger, - tr: t, - r: r, - snapshotter: snapshotter, - localID: t.ID, - cid: cid, - } - if h.lg == nil { - h.lg = zap.NewNop() - } - return h -} - -const unknownSnapshotSender = "UNKNOWN_SNAPSHOT_SENDER" - -// ServeHTTP serves HTTP request to receive and process snapshot message. -// -// If request sender dies without closing underlying TCP connection, -// the handler will keep waiting for the request body until TCP keepalive -// finds out that the connection is broken after several minutes. -// This is acceptable because -// 1. snapshot messages sent through other TCP connections could still be -// received and processed. -// 2. this case should happen rarely, so no further optimization is done. -func (h *snapshotHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { - start := time.Now() - - if r.Method != "POST" { - w.Header().Set("Allow", "POST") - http.Error(w, "Method Not Allowed", http.StatusMethodNotAllowed) - snapshotReceiveFailures.WithLabelValues(unknownSnapshotSender).Inc() - return - } - - w.Header().Set("X-Etcd-Cluster-ID", h.cid.String()) - - if err := checkClusterCompatibilityFromHeader(h.lg, h.localID, r.Header, h.cid); err != nil { - http.Error(w, err.Error(), http.StatusPreconditionFailed) - snapshotReceiveFailures.WithLabelValues(unknownSnapshotSender).Inc() - return - } - - addRemoteFromRequest(h.tr, r) - - dec := &messageDecoder{r: r.Body} - // let snapshots be very large since they can exceed 512MB for large installations - m, err := dec.decodeLimit(snapshotLimitByte) - from := types.ID(m.From).String() - if err != nil { - msg := fmt.Sprintf("failed to decode raft message (%v)", err) - h.lg.Warn( - "failed to decode Raft message", - zap.String("local-member-id", h.localID.String()), - zap.String("remote-snapshot-sender-id", from), - zap.Error(err), - ) - http.Error(w, msg, http.StatusBadRequest) - recvFailures.WithLabelValues(r.RemoteAddr).Inc() - snapshotReceiveFailures.WithLabelValues(from).Inc() - return - } - - msgSize := m.Size() - receivedBytes.WithLabelValues(from).Add(float64(msgSize)) - - if m.Type != raftpb.MsgSnap { - h.lg.Warn( - "unexpected Raft message type", - zap.String("local-member-id", h.localID.String()), - zap.String("remote-snapshot-sender-id", from), - zap.String("message-type", m.Type.String()), - ) - http.Error(w, "wrong raft message type", http.StatusBadRequest) - snapshotReceiveFailures.WithLabelValues(from).Inc() - return - } - - snapshotReceiveInflights.WithLabelValues(from).Inc() - defer func() { - snapshotReceiveInflights.WithLabelValues(from).Dec() - }() - - h.lg.Info( - "receiving database snapshot", - zap.String("local-member-id", h.localID.String()), - zap.String("remote-snapshot-sender-id", from), - zap.Uint64("incoming-snapshot-index", m.Snapshot.Metadata.Index), - zap.Int("incoming-snapshot-message-size-bytes", msgSize), - zap.String("incoming-snapshot-message-size", humanize.Bytes(uint64(msgSize))), - ) - - // save incoming database snapshot. - - n, err := h.snapshotter.SaveDBFrom(r.Body, m.Snapshot.Metadata.Index) - if err != nil { - msg := fmt.Sprintf("failed to save KV snapshot (%v)", err) - h.lg.Warn( - "failed to save incoming database snapshot", - zap.String("local-member-id", h.localID.String()), - zap.String("remote-snapshot-sender-id", from), - zap.Uint64("incoming-snapshot-index", m.Snapshot.Metadata.Index), - zap.Error(err), - ) - http.Error(w, msg, http.StatusInternalServerError) - snapshotReceiveFailures.WithLabelValues(from).Inc() - return - } - - receivedBytes.WithLabelValues(from).Add(float64(n)) - - downloadTook := time.Since(start) - h.lg.Info( - "received and saved database snapshot", - zap.String("local-member-id", h.localID.String()), - zap.String("remote-snapshot-sender-id", from), - zap.Uint64("incoming-snapshot-index", m.Snapshot.Metadata.Index), - zap.Int64("incoming-snapshot-size-bytes", n), - zap.String("incoming-snapshot-size", humanize.Bytes(uint64(n))), - zap.String("download-took", downloadTook.String()), - ) - - if err := h.r.Process(context.TODO(), m); err != nil { - switch v := err.(type) { - // Process may return writerToResponse error when doing some - // additional checks before calling raft.Node.Step. - case writerToResponse: - v.WriteTo(w) - default: - msg := fmt.Sprintf("failed to process raft message (%v)", err) - h.lg.Warn( - "failed to process Raft message", - zap.String("local-member-id", h.localID.String()), - zap.String("remote-snapshot-sender-id", from), - zap.Error(err), - ) - http.Error(w, msg, http.StatusInternalServerError) - snapshotReceiveFailures.WithLabelValues(from).Inc() - } - return - } - - // Write StatusNoContent header after the message has been processed by - // raft, which facilitates the client to report MsgSnap status. - w.WriteHeader(http.StatusNoContent) - - snapshotReceive.WithLabelValues(from).Inc() - snapshotReceiveSeconds.WithLabelValues(from).Observe(time.Since(start).Seconds()) -} - -type streamHandler struct { - lg *zap.Logger - tr *Transport - peerGetter peerGetter - r Raft - id types.ID - cid types.ID -} - -func newStreamHandler(t *Transport, pg peerGetter, r Raft, id, cid types.ID) http.Handler { - h := &streamHandler{ - lg: t.Logger, - tr: t, - peerGetter: pg, - r: r, - id: id, - cid: cid, - } - if h.lg == nil { - h.lg = zap.NewNop() - } - return h -} - -func (h *streamHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { - if r.Method != "GET" { - w.Header().Set("Allow", "GET") - http.Error(w, "Method Not Allowed", http.StatusMethodNotAllowed) - return - } - - w.Header().Set("X-Server-Version", version.Version) - w.Header().Set("X-Etcd-Cluster-ID", h.cid.String()) - - if err := checkClusterCompatibilityFromHeader(h.lg, h.tr.ID, r.Header, h.cid); err != nil { - http.Error(w, err.Error(), http.StatusPreconditionFailed) - return - } - - var t streamType - switch path.Dir(r.URL.Path) { - case streamTypeMsgAppV2.endpoint(h.lg): - t = streamTypeMsgAppV2 - case streamTypeMessage.endpoint(h.lg): - t = streamTypeMessage - default: - h.lg.Debug( - "ignored unexpected streaming request path", - zap.String("local-member-id", h.tr.ID.String()), - zap.String("remote-peer-id-stream-handler", h.id.String()), - zap.String("path", r.URL.Path), - ) - http.Error(w, "invalid path", http.StatusNotFound) - return - } - - fromStr := path.Base(r.URL.Path) - from, err := types.IDFromString(fromStr) - if err != nil { - h.lg.Warn( - "failed to parse path into ID", - zap.String("local-member-id", h.tr.ID.String()), - zap.String("remote-peer-id-stream-handler", h.id.String()), - zap.String("path", fromStr), - zap.Error(err), - ) - http.Error(w, "invalid from", http.StatusNotFound) - return - } - if h.r.IsIDRemoved(uint64(from)) { - h.lg.Warn( - "rejected stream from remote peer because it was removed", - zap.String("local-member-id", h.tr.ID.String()), - zap.String("remote-peer-id-stream-handler", h.id.String()), - zap.String("remote-peer-id-from", from.String()), - ) - http.Error(w, "removed member", http.StatusGone) - return - } - p := h.peerGetter.Get(from) - if p == nil { - // This may happen in following cases: - // 1. user starts a remote peer that belongs to a different cluster - // with the same cluster ID. - // 2. local etcd falls behind of the cluster, and cannot recognize - // the members that joined after its current progress. - if urls := r.Header.Get("X-PeerURLs"); urls != "" { - h.tr.AddRemote(from, strings.Split(urls, ",")) - } - h.lg.Warn( - "failed to find remote peer in cluster", - zap.String("local-member-id", h.tr.ID.String()), - zap.String("remote-peer-id-stream-handler", h.id.String()), - zap.String("remote-peer-id-from", from.String()), - zap.String("cluster-id", h.cid.String()), - ) - http.Error(w, "error sender not found", http.StatusNotFound) - return - } - - wto := h.id.String() - if gto := r.Header.Get("X-Raft-To"); gto != wto { - h.lg.Warn( - "ignored streaming request; ID mismatch", - zap.String("local-member-id", h.tr.ID.String()), - zap.String("remote-peer-id-stream-handler", h.id.String()), - zap.String("remote-peer-id-header", gto), - zap.String("remote-peer-id-from", from.String()), - zap.String("cluster-id", h.cid.String()), - ) - http.Error(w, "to field mismatch", http.StatusPreconditionFailed) - return - } - - w.WriteHeader(http.StatusOK) - w.(http.Flusher).Flush() - - c := newCloseNotifier() - conn := &outgoingConn{ - t: t, - Writer: w, - Flusher: w.(http.Flusher), - Closer: c, - localID: h.tr.ID, - peerID: from, - } - p.attachOutgoingConn(conn) - <-c.closeNotify() -} - -// checkClusterCompatibilityFromHeader checks the cluster compatibility of -// the local member from the given header. -// It checks whether the version of local member is compatible with -// the versions in the header, and whether the cluster ID of local member -// matches the one in the header. -func checkClusterCompatibilityFromHeader(lg *zap.Logger, localID types.ID, header http.Header, cid types.ID) error { - remoteName := header.Get("X-Server-From") - - remoteServer := serverVersion(header) - remoteVs := "" - if remoteServer != nil { - remoteVs = remoteServer.String() - } - - remoteMinClusterVer := minClusterVersion(header) - remoteMinClusterVs := "" - if remoteMinClusterVer != nil { - remoteMinClusterVs = remoteMinClusterVer.String() - } - - localServer, localMinCluster, err := checkVersionCompatibility(remoteName, remoteServer, remoteMinClusterVer) - - localVs := "" - if localServer != nil { - localVs = localServer.String() - } - localMinClusterVs := "" - if localMinCluster != nil { - localMinClusterVs = localMinCluster.String() - } - - if err != nil { - lg.Warn( - "failed to check version compatibility", - zap.String("local-member-id", localID.String()), - zap.String("local-member-cluster-id", cid.String()), - zap.String("local-member-server-version", localVs), - zap.String("local-member-server-minimum-cluster-version", localMinClusterVs), - zap.String("remote-peer-server-name", remoteName), - zap.String("remote-peer-server-version", remoteVs), - zap.String("remote-peer-server-minimum-cluster-version", remoteMinClusterVs), - zap.Error(err), - ) - return errIncompatibleVersion - } - if gcid := header.Get("X-Etcd-Cluster-ID"); gcid != cid.String() { - lg.Warn( - "request cluster ID mismatch", - zap.String("local-member-id", localID.String()), - zap.String("local-member-cluster-id", cid.String()), - zap.String("local-member-server-version", localVs), - zap.String("local-member-server-minimum-cluster-version", localMinClusterVs), - zap.String("remote-peer-server-name", remoteName), - zap.String("remote-peer-server-version", remoteVs), - zap.String("remote-peer-server-minimum-cluster-version", remoteMinClusterVs), - zap.String("remote-peer-cluster-id", gcid), - ) - return errClusterIDMismatch - } - return nil -} - -type closeNotifier struct { - done chan struct{} -} - -func newCloseNotifier() *closeNotifier { - return &closeNotifier{ - done: make(chan struct{}), - } -} - -func (n *closeNotifier) Close() error { - close(n.done) - return nil -} - -func (n *closeNotifier) closeNotify() <-chan struct{} { return n.done } diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp/metrics.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp/metrics.go deleted file mode 100644 index 02fff84be7..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp/metrics.go +++ /dev/null @@ -1,186 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package rafthttp - -import "github.com/prometheus/client_golang/prometheus" - -var ( - activePeers = prometheus.NewGaugeVec(prometheus.GaugeOpts{ - Namespace: "etcd", - Subsystem: "network", - Name: "active_peers", - Help: "The current number of active peer connections.", - }, - []string{"Local", "Remote"}, - ) - - disconnectedPeers = prometheus.NewCounterVec(prometheus.CounterOpts{ - Namespace: "etcd", - Subsystem: "network", - Name: "disconnected_peers_total", - Help: "The total number of disconnected peers.", - }, - []string{"Local", "Remote"}, - ) - - sentBytes = prometheus.NewCounterVec(prometheus.CounterOpts{ - Namespace: "etcd", - Subsystem: "network", - Name: "peer_sent_bytes_total", - Help: "The total number of bytes sent to peers.", - }, - []string{"To"}, - ) - - receivedBytes = prometheus.NewCounterVec(prometheus.CounterOpts{ - Namespace: "etcd", - Subsystem: "network", - Name: "peer_received_bytes_total", - Help: "The total number of bytes received from peers.", - }, - []string{"From"}, - ) - - sentFailures = prometheus.NewCounterVec(prometheus.CounterOpts{ - Namespace: "etcd", - Subsystem: "network", - Name: "peer_sent_failures_total", - Help: "The total number of send failures from peers.", - }, - []string{"To"}, - ) - - recvFailures = prometheus.NewCounterVec(prometheus.CounterOpts{ - Namespace: "etcd", - Subsystem: "network", - Name: "peer_received_failures_total", - Help: "The total number of receive failures from peers.", - }, - []string{"From"}, - ) - - snapshotSend = prometheus.NewCounterVec(prometheus.CounterOpts{ - Namespace: "etcd", - Subsystem: "network", - Name: "snapshot_send_success", - Help: "Total number of successful snapshot sends", - }, - []string{"To"}, - ) - - snapshotSendInflights = prometheus.NewGaugeVec(prometheus.GaugeOpts{ - Namespace: "etcd", - Subsystem: "network", - Name: "snapshot_send_inflights_total", - Help: "Total number of inflight snapshot sends", - }, - []string{"To"}, - ) - - snapshotSendFailures = prometheus.NewCounterVec(prometheus.CounterOpts{ - Namespace: "etcd", - Subsystem: "network", - Name: "snapshot_send_failures", - Help: "Total number of snapshot send failures", - }, - []string{"To"}, - ) - - snapshotSendSeconds = prometheus.NewHistogramVec(prometheus.HistogramOpts{ - Namespace: "etcd", - Subsystem: "network", - Name: "snapshot_send_total_duration_seconds", - Help: "Total latency distributions of v3 snapshot sends", - - // lowest bucket start of upper bound 0.1 sec (100 ms) with factor 2 - // highest bucket start of 0.1 sec * 2^9 == 51.2 sec - Buckets: prometheus.ExponentialBuckets(0.1, 2, 10), - }, - []string{"To"}, - ) - - snapshotReceive = prometheus.NewCounterVec(prometheus.CounterOpts{ - Namespace: "etcd", - Subsystem: "network", - Name: "snapshot_receive_success", - Help: "Total number of successful snapshot receives", - }, - []string{"From"}, - ) - - snapshotReceiveInflights = prometheus.NewGaugeVec(prometheus.GaugeOpts{ - Namespace: "etcd", - Subsystem: "network", - Name: "snapshot_receive_inflights_total", - Help: "Total number of inflight snapshot receives", - }, - []string{"From"}, - ) - - snapshotReceiveFailures = prometheus.NewCounterVec(prometheus.CounterOpts{ - Namespace: "etcd", - Subsystem: "network", - Name: "snapshot_receive_failures", - Help: "Total number of snapshot receive failures", - }, - []string{"From"}, - ) - - snapshotReceiveSeconds = prometheus.NewHistogramVec(prometheus.HistogramOpts{ - Namespace: "etcd", - Subsystem: "network", - Name: "snapshot_receive_total_duration_seconds", - Help: "Total latency distributions of v3 snapshot receives", - - // lowest bucket start of upper bound 0.1 sec (100 ms) with factor 2 - // highest bucket start of 0.1 sec * 2^9 == 51.2 sec - Buckets: prometheus.ExponentialBuckets(0.1, 2, 10), - }, - []string{"From"}, - ) - - rttSec = prometheus.NewHistogramVec(prometheus.HistogramOpts{ - Namespace: "etcd", - Subsystem: "network", - Name: "peer_round_trip_time_seconds", - Help: "Round-Trip-Time histogram between peers", - - // lowest bucket start of upper bound 0.0001 sec (0.1 ms) with factor 2 - // highest bucket start of 0.0001 sec * 2^15 == 3.2768 sec - Buckets: prometheus.ExponentialBuckets(0.0001, 2, 16), - }, - []string{"To"}, - ) -) - -func init() { - prometheus.MustRegister(activePeers) - prometheus.MustRegister(disconnectedPeers) - prometheus.MustRegister(sentBytes) - prometheus.MustRegister(receivedBytes) - prometheus.MustRegister(sentFailures) - prometheus.MustRegister(recvFailures) - - prometheus.MustRegister(snapshotSend) - prometheus.MustRegister(snapshotSendInflights) - prometheus.MustRegister(snapshotSendFailures) - prometheus.MustRegister(snapshotSendSeconds) - prometheus.MustRegister(snapshotReceive) - prometheus.MustRegister(snapshotReceiveInflights) - prometheus.MustRegister(snapshotReceiveFailures) - prometheus.MustRegister(snapshotReceiveSeconds) - - prometheus.MustRegister(rttSec) -} diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp/msg_codec.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp/msg_codec.go deleted file mode 100644 index 7db880baa2..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp/msg_codec.go +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package rafthttp - -import ( - "encoding/binary" - "errors" - "io" - - "go.etcd.io/etcd/pkg/v3/pbutil" - "go.etcd.io/etcd/raft/v3/raftpb" -) - -// messageEncoder is a encoder that can encode all kinds of messages. -// It MUST be used with a paired messageDecoder. -type messageEncoder struct { - w io.Writer -} - -func (enc *messageEncoder) encode(m *raftpb.Message) error { - if err := binary.Write(enc.w, binary.BigEndian, uint64(m.Size())); err != nil { - return err - } - _, err := enc.w.Write(pbutil.MustMarshal(m)) - return err -} - -// messageDecoder is a decoder that can decode all kinds of messages. -type messageDecoder struct { - r io.Reader -} - -var ( - readBytesLimit uint64 = 512 * 1024 * 1024 // 512 MB - ErrExceedSizeLimit = errors.New("rafthttp: error limit exceeded") -) - -func (dec *messageDecoder) decode() (raftpb.Message, error) { - return dec.decodeLimit(readBytesLimit) -} - -func (dec *messageDecoder) decodeLimit(numBytes uint64) (raftpb.Message, error) { - var m raftpb.Message - var l uint64 - if err := binary.Read(dec.r, binary.BigEndian, &l); err != nil { - return m, err - } - if l > numBytes { - return m, ErrExceedSizeLimit - } - buf := make([]byte, int(l)) - if _, err := io.ReadFull(dec.r, buf); err != nil { - return m, err - } - return m, m.Unmarshal(buf) -} diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp/msgappv2_codec.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp/msgappv2_codec.go deleted file mode 100644 index 9a7f4a1770..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp/msgappv2_codec.go +++ /dev/null @@ -1,248 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package rafthttp - -import ( - "encoding/binary" - "fmt" - "io" - "time" - - "go.etcd.io/etcd/client/pkg/v3/types" - "go.etcd.io/etcd/pkg/v3/pbutil" - "go.etcd.io/etcd/raft/v3/raftpb" - stats "go.etcd.io/etcd/server/v3/etcdserver/api/v2stats" -) - -const ( - msgTypeLinkHeartbeat uint8 = 0 - msgTypeAppEntries uint8 = 1 - msgTypeApp uint8 = 2 - - msgAppV2BufSize = 1024 * 1024 -) - -// msgappv2 stream sends three types of message: linkHeartbeatMessage, -// AppEntries and MsgApp. AppEntries is the MsgApp that is sent in -// replicate state in raft, whose index and term are fully predictable. -// -// Data format of linkHeartbeatMessage: -// | offset | bytes | description | -// +--------+-------+-------------+ -// | 0 | 1 | \x00 | -// -// Data format of AppEntries: -// | offset | bytes | description | -// +--------+-------+-------------+ -// | 0 | 1 | \x01 | -// | 1 | 8 | length of entries | -// | 9 | 8 | length of first entry | -// | 17 | n1 | first entry | -// ... -// | x | 8 | length of k-th entry data | -// | x+8 | nk | k-th entry data | -// | x+8+nk | 8 | commit index | -// -// Data format of MsgApp: -// | offset | bytes | description | -// +--------+-------+-------------+ -// | 0 | 1 | \x02 | -// | 1 | 8 | length of encoded message | -// | 9 | n | encoded message | -type msgAppV2Encoder struct { - w io.Writer - fs *stats.FollowerStats - - term uint64 - index uint64 - buf []byte - uint64buf []byte - uint8buf []byte -} - -func newMsgAppV2Encoder(w io.Writer, fs *stats.FollowerStats) *msgAppV2Encoder { - return &msgAppV2Encoder{ - w: w, - fs: fs, - buf: make([]byte, msgAppV2BufSize), - uint64buf: make([]byte, 8), - uint8buf: make([]byte, 1), - } -} - -func (enc *msgAppV2Encoder) encode(m *raftpb.Message) error { - start := time.Now() - switch { - case isLinkHeartbeatMessage(m): - enc.uint8buf[0] = msgTypeLinkHeartbeat - if _, err := enc.w.Write(enc.uint8buf); err != nil { - return err - } - case enc.index == m.Index && enc.term == m.LogTerm && m.LogTerm == m.Term: - enc.uint8buf[0] = msgTypeAppEntries - if _, err := enc.w.Write(enc.uint8buf); err != nil { - return err - } - // write length of entries - binary.BigEndian.PutUint64(enc.uint64buf, uint64(len(m.Entries))) - if _, err := enc.w.Write(enc.uint64buf); err != nil { - return err - } - for i := 0; i < len(m.Entries); i++ { - // write length of entry - binary.BigEndian.PutUint64(enc.uint64buf, uint64(m.Entries[i].Size())) - if _, err := enc.w.Write(enc.uint64buf); err != nil { - return err - } - if n := m.Entries[i].Size(); n < msgAppV2BufSize { - if _, err := m.Entries[i].MarshalTo(enc.buf); err != nil { - return err - } - if _, err := enc.w.Write(enc.buf[:n]); err != nil { - return err - } - } else { - if _, err := enc.w.Write(pbutil.MustMarshal(&m.Entries[i])); err != nil { - return err - } - } - enc.index++ - } - // write commit index - binary.BigEndian.PutUint64(enc.uint64buf, m.Commit) - if _, err := enc.w.Write(enc.uint64buf); err != nil { - return err - } - enc.fs.Succ(time.Since(start)) - default: - if err := binary.Write(enc.w, binary.BigEndian, msgTypeApp); err != nil { - return err - } - // write size of message - if err := binary.Write(enc.w, binary.BigEndian, uint64(m.Size())); err != nil { - return err - } - // write message - if _, err := enc.w.Write(pbutil.MustMarshal(m)); err != nil { - return err - } - - enc.term = m.Term - enc.index = m.Index - if l := len(m.Entries); l > 0 { - enc.index = m.Entries[l-1].Index - } - enc.fs.Succ(time.Since(start)) - } - return nil -} - -type msgAppV2Decoder struct { - r io.Reader - local, remote types.ID - - term uint64 - index uint64 - buf []byte - uint64buf []byte - uint8buf []byte -} - -func newMsgAppV2Decoder(r io.Reader, local, remote types.ID) *msgAppV2Decoder { - return &msgAppV2Decoder{ - r: r, - local: local, - remote: remote, - buf: make([]byte, msgAppV2BufSize), - uint64buf: make([]byte, 8), - uint8buf: make([]byte, 1), - } -} - -func (dec *msgAppV2Decoder) decode() (raftpb.Message, error) { - var ( - m raftpb.Message - typ uint8 - ) - if _, err := io.ReadFull(dec.r, dec.uint8buf); err != nil { - return m, err - } - typ = dec.uint8buf[0] - switch typ { - case msgTypeLinkHeartbeat: - return linkHeartbeatMessage, nil - case msgTypeAppEntries: - m = raftpb.Message{ - Type: raftpb.MsgApp, - From: uint64(dec.remote), - To: uint64(dec.local), - Term: dec.term, - LogTerm: dec.term, - Index: dec.index, - } - - // decode entries - if _, err := io.ReadFull(dec.r, dec.uint64buf); err != nil { - return m, err - } - l := binary.BigEndian.Uint64(dec.uint64buf) - m.Entries = make([]raftpb.Entry, int(l)) - for i := 0; i < int(l); i++ { - if _, err := io.ReadFull(dec.r, dec.uint64buf); err != nil { - return m, err - } - size := binary.BigEndian.Uint64(dec.uint64buf) - var buf []byte - if size < msgAppV2BufSize { - buf = dec.buf[:size] - if _, err := io.ReadFull(dec.r, buf); err != nil { - return m, err - } - } else { - buf = make([]byte, int(size)) - if _, err := io.ReadFull(dec.r, buf); err != nil { - return m, err - } - } - dec.index++ - // 1 alloc - pbutil.MustUnmarshal(&m.Entries[i], buf) - } - // decode commit index - if _, err := io.ReadFull(dec.r, dec.uint64buf); err != nil { - return m, err - } - m.Commit = binary.BigEndian.Uint64(dec.uint64buf) - case msgTypeApp: - var size uint64 - if err := binary.Read(dec.r, binary.BigEndian, &size); err != nil { - return m, err - } - buf := make([]byte, int(size)) - if _, err := io.ReadFull(dec.r, buf); err != nil { - return m, err - } - pbutil.MustUnmarshal(&m, buf) - - dec.term = m.Term - dec.index = m.Index - if l := len(m.Entries); l > 0 { - dec.index = m.Entries[l-1].Index - } - default: - return m, fmt.Errorf("failed to parse type %d in msgappv2 stream", typ) - } - return m, nil -} diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp/peer.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp/peer.go deleted file mode 100644 index 444d6bde94..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp/peer.go +++ /dev/null @@ -1,367 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package rafthttp - -import ( - "context" - "sync" - "time" - - "go.etcd.io/etcd/client/pkg/v3/types" - "go.etcd.io/etcd/raft/v3" - "go.etcd.io/etcd/raft/v3/raftpb" - "go.etcd.io/etcd/server/v3/etcdserver/api/snap" - stats "go.etcd.io/etcd/server/v3/etcdserver/api/v2stats" - - "go.uber.org/zap" - "golang.org/x/time/rate" -) - -const ( - // ConnReadTimeout and ConnWriteTimeout are the i/o timeout set on each connection rafthttp pkg creates. - // A 5 seconds timeout is good enough for recycling bad connections. Or we have to wait for - // tcp keepalive failing to detect a bad connection, which is at minutes level. - // For long term streaming connections, rafthttp pkg sends application level linkHeartbeatMessage - // to keep the connection alive. - // For short term pipeline connections, the connection MUST be killed to avoid it being - // put back to http pkg connection pool. - DefaultConnReadTimeout = 5 * time.Second - DefaultConnWriteTimeout = 5 * time.Second - - recvBufSize = 4096 - // maxPendingProposals holds the proposals during one leader election process. - // Generally one leader election takes at most 1 sec. It should have - // 0-2 election conflicts, and each one takes 0.5 sec. - // We assume the number of concurrent proposers is smaller than 4096. - // One client blocks on its proposal for at least 1 sec, so 4096 is enough - // to hold all proposals. - maxPendingProposals = 4096 - - streamAppV2 = "streamMsgAppV2" - streamMsg = "streamMsg" - pipelineMsg = "pipeline" - sendSnap = "sendMsgSnap" -) - -var ( - ConnReadTimeout = DefaultConnReadTimeout - ConnWriteTimeout = DefaultConnWriteTimeout -) - -type Peer interface { - // send sends the message to the remote peer. The function is non-blocking - // and has no promise that the message will be received by the remote. - // When it fails to send message out, it will report the status to underlying - // raft. - send(m raftpb.Message) - - // sendSnap sends the merged snapshot message to the remote peer. Its behavior - // is similar to send. - sendSnap(m snap.Message) - - // update updates the urls of remote peer. - update(urls types.URLs) - - // attachOutgoingConn attaches the outgoing connection to the peer for - // stream usage. After the call, the ownership of the outgoing - // connection hands over to the peer. The peer will close the connection - // when it is no longer used. - attachOutgoingConn(conn *outgoingConn) - // activeSince returns the time that the connection with the - // peer becomes active. - activeSince() time.Time - // stop performs any necessary finalization and terminates the peer - // elegantly. - stop() -} - -// peer is the representative of a remote raft node. Local raft node sends -// messages to the remote through peer. -// Each peer has two underlying mechanisms to send out a message: stream and -// pipeline. -// A stream is a receiver initialized long-polling connection, which -// is always open to transfer messages. Besides general stream, peer also has -// a optimized stream for sending msgApp since msgApp accounts for large part -// of all messages. Only raft leader uses the optimized stream to send msgApp -// to the remote follower node. -// A pipeline is a series of http clients that send http requests to the remote. -// It is only used when the stream has not been established. -type peer struct { - lg *zap.Logger - - localID types.ID - // id of the remote raft peer node - id types.ID - - r Raft - - status *peerStatus - - picker *urlPicker - - msgAppV2Writer *streamWriter - writer *streamWriter - pipeline *pipeline - snapSender *snapshotSender // snapshot sender to send v3 snapshot messages - msgAppV2Reader *streamReader - msgAppReader *streamReader - - recvc chan raftpb.Message - propc chan raftpb.Message - - mu sync.Mutex - paused bool - - cancel context.CancelFunc // cancel pending works in go routine created by peer. - stopc chan struct{} -} - -func startPeer(t *Transport, urls types.URLs, peerID types.ID, fs *stats.FollowerStats) *peer { - if t.Logger != nil { - t.Logger.Info("starting remote peer", zap.String("remote-peer-id", peerID.String())) - } - defer func() { - if t.Logger != nil { - t.Logger.Info("started remote peer", zap.String("remote-peer-id", peerID.String())) - } - }() - - status := newPeerStatus(t.Logger, t.ID, peerID) - picker := newURLPicker(urls) - errorc := t.ErrorC - r := t.Raft - pipeline := &pipeline{ - peerID: peerID, - tr: t, - picker: picker, - status: status, - followerStats: fs, - raft: r, - errorc: errorc, - } - pipeline.start() - - p := &peer{ - lg: t.Logger, - localID: t.ID, - id: peerID, - r: r, - status: status, - picker: picker, - msgAppV2Writer: startStreamWriter(t.Logger, t.ID, peerID, status, fs, r), - writer: startStreamWriter(t.Logger, t.ID, peerID, status, fs, r), - pipeline: pipeline, - snapSender: newSnapshotSender(t, picker, peerID, status), - recvc: make(chan raftpb.Message, recvBufSize), - propc: make(chan raftpb.Message, maxPendingProposals), - stopc: make(chan struct{}), - } - - ctx, cancel := context.WithCancel(context.Background()) - p.cancel = cancel - go func() { - for { - select { - case mm := <-p.recvc: - if err := r.Process(ctx, mm); err != nil { - if t.Logger != nil { - t.Logger.Warn("failed to process Raft message", zap.Error(err)) - } - } - case <-p.stopc: - return - } - } - }() - - // r.Process might block for processing proposal when there is no leader. - // Thus propc must be put into a separate routine with recvc to avoid blocking - // processing other raft messages. - go func() { - for { - select { - case mm := <-p.propc: - if err := r.Process(ctx, mm); err != nil { - if t.Logger != nil { - t.Logger.Warn("failed to process Raft message", zap.Error(err)) - } - } - case <-p.stopc: - return - } - } - }() - - p.msgAppV2Reader = &streamReader{ - lg: t.Logger, - peerID: peerID, - typ: streamTypeMsgAppV2, - tr: t, - picker: picker, - status: status, - recvc: p.recvc, - propc: p.propc, - rl: rate.NewLimiter(t.DialRetryFrequency, 1), - } - p.msgAppReader = &streamReader{ - lg: t.Logger, - peerID: peerID, - typ: streamTypeMessage, - tr: t, - picker: picker, - status: status, - recvc: p.recvc, - propc: p.propc, - rl: rate.NewLimiter(t.DialRetryFrequency, 1), - } - - p.msgAppV2Reader.start() - p.msgAppReader.start() - - return p -} - -func (p *peer) send(m raftpb.Message) { - p.mu.Lock() - paused := p.paused - p.mu.Unlock() - - if paused { - return - } - - writec, name := p.pick(m) - select { - case writec <- m: - default: - p.r.ReportUnreachable(m.To) - if isMsgSnap(m) { - p.r.ReportSnapshot(m.To, raft.SnapshotFailure) - } - if p.status.isActive() { - if p.lg != nil { - p.lg.Warn( - "dropped internal Raft message since sending buffer is full (overloaded network)", - zap.String("message-type", m.Type.String()), - zap.String("local-member-id", p.localID.String()), - zap.String("from", types.ID(m.From).String()), - zap.String("remote-peer-id", p.id.String()), - zap.String("remote-peer-name", name), - zap.Bool("remote-peer-active", p.status.isActive()), - ) - } - } else { - if p.lg != nil { - p.lg.Warn( - "dropped internal Raft message since sending buffer is full (overloaded network)", - zap.String("message-type", m.Type.String()), - zap.String("local-member-id", p.localID.String()), - zap.String("from", types.ID(m.From).String()), - zap.String("remote-peer-id", p.id.String()), - zap.String("remote-peer-name", name), - zap.Bool("remote-peer-active", p.status.isActive()), - ) - } - } - sentFailures.WithLabelValues(types.ID(m.To).String()).Inc() - } -} - -func (p *peer) sendSnap(m snap.Message) { - go p.snapSender.send(m) -} - -func (p *peer) update(urls types.URLs) { - p.picker.update(urls) -} - -func (p *peer) attachOutgoingConn(conn *outgoingConn) { - var ok bool - switch conn.t { - case streamTypeMsgAppV2: - ok = p.msgAppV2Writer.attach(conn) - case streamTypeMessage: - ok = p.writer.attach(conn) - default: - if p.lg != nil { - p.lg.Panic("unknown stream type", zap.String("type", conn.t.String())) - } - } - if !ok { - conn.Close() - } -} - -func (p *peer) activeSince() time.Time { return p.status.activeSince() } - -// Pause pauses the peer. The peer will simply drops all incoming -// messages without returning an error. -func (p *peer) Pause() { - p.mu.Lock() - defer p.mu.Unlock() - p.paused = true - p.msgAppReader.pause() - p.msgAppV2Reader.pause() -} - -// Resume resumes a paused peer. -func (p *peer) Resume() { - p.mu.Lock() - defer p.mu.Unlock() - p.paused = false - p.msgAppReader.resume() - p.msgAppV2Reader.resume() -} - -func (p *peer) stop() { - if p.lg != nil { - p.lg.Info("stopping remote peer", zap.String("remote-peer-id", p.id.String())) - } - - defer func() { - if p.lg != nil { - p.lg.Info("stopped remote peer", zap.String("remote-peer-id", p.id.String())) - } - }() - - close(p.stopc) - p.cancel() - p.msgAppV2Writer.stop() - p.writer.stop() - p.pipeline.stop() - p.snapSender.stop() - p.msgAppV2Reader.stop() - p.msgAppReader.stop() -} - -// pick picks a chan for sending the given message. The picked chan and the picked chan -// string name are returned. -func (p *peer) pick(m raftpb.Message) (writec chan<- raftpb.Message, picked string) { - var ok bool - // Considering MsgSnap may have a big size, e.g., 1G, and will block - // stream for a long time, only use one of the N pipelines to send MsgSnap. - if isMsgSnap(m) { - return p.pipeline.msgc, pipelineMsg - } else if writec, ok = p.msgAppV2Writer.writec(); ok && isMsgApp(m) { - return writec, streamAppV2 - } else if writec, ok = p.writer.writec(); ok { - return writec, streamMsg - } - return p.pipeline.msgc, pipelineMsg -} - -func isMsgApp(m raftpb.Message) bool { return m.Type == raftpb.MsgApp } - -func isMsgSnap(m raftpb.Message) bool { return m.Type == raftpb.MsgSnap } diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp/peer_status.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp/peer_status.go deleted file mode 100644 index cad19b2fbc..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp/peer_status.go +++ /dev/null @@ -1,90 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package rafthttp - -import ( - "errors" - "fmt" - "sync" - "time" - - "go.etcd.io/etcd/client/pkg/v3/types" - - "go.uber.org/zap" -) - -type failureType struct { - source string - action string -} - -type peerStatus struct { - lg *zap.Logger - local types.ID - id types.ID - mu sync.Mutex // protect variables below - active bool - since time.Time -} - -func newPeerStatus(lg *zap.Logger, local, id types.ID) *peerStatus { - if lg == nil { - lg = zap.NewNop() - } - return &peerStatus{lg: lg, local: local, id: id} -} - -func (s *peerStatus) activate() { - s.mu.Lock() - defer s.mu.Unlock() - if !s.active { - s.lg.Info("peer became active", zap.String("peer-id", s.id.String())) - s.active = true - s.since = time.Now() - - activePeers.WithLabelValues(s.local.String(), s.id.String()).Inc() - } -} - -func (s *peerStatus) deactivate(failure failureType, reason string) { - s.mu.Lock() - defer s.mu.Unlock() - msg := fmt.Sprintf("failed to %s %s on %s (%s)", failure.action, s.id, failure.source, reason) - if s.active { - s.lg.Warn("peer became inactive (message send to peer failed)", zap.String("peer-id", s.id.String()), zap.Error(errors.New(msg))) - s.active = false - s.since = time.Time{} - - activePeers.WithLabelValues(s.local.String(), s.id.String()).Dec() - disconnectedPeers.WithLabelValues(s.local.String(), s.id.String()).Inc() - return - } - - if s.lg != nil { - s.lg.Debug("peer deactivated again", zap.String("peer-id", s.id.String()), zap.Error(errors.New(msg))) - } -} - -func (s *peerStatus) isActive() bool { - s.mu.Lock() - defer s.mu.Unlock() - return s.active -} - -func (s *peerStatus) activeSince() time.Time { - s.mu.Lock() - defer s.mu.Unlock() - return s.since -} diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp/pipeline.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp/pipeline.go deleted file mode 100644 index de3b459118..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp/pipeline.go +++ /dev/null @@ -1,178 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package rafthttp - -import ( - "bytes" - "context" - "errors" - "io/ioutil" - "runtime" - "sync" - "time" - - "go.etcd.io/etcd/client/pkg/v3/types" - "go.etcd.io/etcd/pkg/v3/pbutil" - "go.etcd.io/etcd/raft/v3" - "go.etcd.io/etcd/raft/v3/raftpb" - stats "go.etcd.io/etcd/server/v3/etcdserver/api/v2stats" - - "go.uber.org/zap" -) - -const ( - connPerPipeline = 4 - // pipelineBufSize is the size of pipeline buffer, which helps hold the - // temporary network latency. - // The size ensures that pipeline does not drop messages when the network - // is out of work for less than 1 second in good path. - pipelineBufSize = 64 -) - -var errStopped = errors.New("stopped") - -type pipeline struct { - peerID types.ID - - tr *Transport - picker *urlPicker - status *peerStatus - raft Raft - errorc chan error - // deprecate when we depercate v2 API - followerStats *stats.FollowerStats - - msgc chan raftpb.Message - // wait for the handling routines - wg sync.WaitGroup - stopc chan struct{} -} - -func (p *pipeline) start() { - p.stopc = make(chan struct{}) - p.msgc = make(chan raftpb.Message, pipelineBufSize) - p.wg.Add(connPerPipeline) - for i := 0; i < connPerPipeline; i++ { - go p.handle() - } - - if p.tr != nil && p.tr.Logger != nil { - p.tr.Logger.Info( - "started HTTP pipelining with remote peer", - zap.String("local-member-id", p.tr.ID.String()), - zap.String("remote-peer-id", p.peerID.String()), - ) - } -} - -func (p *pipeline) stop() { - close(p.stopc) - p.wg.Wait() - - if p.tr != nil && p.tr.Logger != nil { - p.tr.Logger.Info( - "stopped HTTP pipelining with remote peer", - zap.String("local-member-id", p.tr.ID.String()), - zap.String("remote-peer-id", p.peerID.String()), - ) - } -} - -func (p *pipeline) handle() { - defer p.wg.Done() - - for { - select { - case m := <-p.msgc: - start := time.Now() - err := p.post(pbutil.MustMarshal(&m)) - end := time.Now() - - if err != nil { - p.status.deactivate(failureType{source: pipelineMsg, action: "write"}, err.Error()) - - if m.Type == raftpb.MsgApp && p.followerStats != nil { - p.followerStats.Fail() - } - p.raft.ReportUnreachable(m.To) - if isMsgSnap(m) { - p.raft.ReportSnapshot(m.To, raft.SnapshotFailure) - } - sentFailures.WithLabelValues(types.ID(m.To).String()).Inc() - continue - } - - p.status.activate() - if m.Type == raftpb.MsgApp && p.followerStats != nil { - p.followerStats.Succ(end.Sub(start)) - } - if isMsgSnap(m) { - p.raft.ReportSnapshot(m.To, raft.SnapshotFinish) - } - sentBytes.WithLabelValues(types.ID(m.To).String()).Add(float64(m.Size())) - case <-p.stopc: - return - } - } -} - -// post POSTs a data payload to a url. Returns nil if the POST succeeds, -// error on any failure. -func (p *pipeline) post(data []byte) (err error) { - u := p.picker.pick() - req := createPostRequest(p.tr.Logger, u, RaftPrefix, bytes.NewBuffer(data), "application/protobuf", p.tr.URLs, p.tr.ID, p.tr.ClusterID) - - done := make(chan struct{}, 1) - ctx, cancel := context.WithCancel(context.Background()) - req = req.WithContext(ctx) - go func() { - select { - case <-done: - cancel() - case <-p.stopc: - waitSchedule() - cancel() - } - }() - - resp, err := p.tr.pipelineRt.RoundTrip(req) - done <- struct{}{} - if err != nil { - p.picker.unreachable(u) - return err - } - defer resp.Body.Close() - b, err := ioutil.ReadAll(resp.Body) - if err != nil { - p.picker.unreachable(u) - return err - } - - err = checkPostResponse(p.tr.Logger, resp, b, req, p.peerID) - if err != nil { - p.picker.unreachable(u) - // errMemberRemoved is a critical error since a removed member should - // always be stopped. So we use reportCriticalError to report it to errorc. - if err == errMemberRemoved { - reportCriticalError(err, p.errorc) - } - return err - } - - return nil -} - -// waitSchedule waits other goroutines to be scheduled for a while -func waitSchedule() { runtime.Gosched() } diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp/probing_status.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp/probing_status.go deleted file mode 100644 index 672a579ce6..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp/probing_status.go +++ /dev/null @@ -1,98 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package rafthttp - -import ( - "time" - - "github.com/prometheus/client_golang/prometheus" - "github.com/xiang90/probing" - "go.uber.org/zap" -) - -const ( - // RoundTripperNameRaftMessage is the name of round-tripper that sends - // all other Raft messages, other than "snap.Message". - RoundTripperNameRaftMessage = "ROUND_TRIPPER_RAFT_MESSAGE" - // RoundTripperNameSnapshot is the name of round-tripper that sends merged snapshot message. - RoundTripperNameSnapshot = "ROUND_TRIPPER_SNAPSHOT" -) - -var ( - // proberInterval must be shorter than read timeout. - // Or the connection will time-out. - proberInterval = ConnReadTimeout - time.Second - statusMonitoringInterval = 30 * time.Second - statusErrorInterval = 5 * time.Second -) - -func addPeerToProber(lg *zap.Logger, p probing.Prober, id string, us []string, roundTripperName string, rttSecProm *prometheus.HistogramVec) { - hus := make([]string, len(us)) - for i := range us { - hus[i] = us[i] + ProbingPrefix - } - - p.AddHTTP(id, proberInterval, hus) - - s, err := p.Status(id) - if err != nil { - if lg != nil { - lg.Warn("failed to add peer into prober", zap.String("remote-peer-id", id), zap.Error(err)) - } - return - } - - go monitorProbingStatus(lg, s, id, roundTripperName, rttSecProm) -} - -func monitorProbingStatus(lg *zap.Logger, s probing.Status, id string, roundTripperName string, rttSecProm *prometheus.HistogramVec) { - // set the first interval short to log error early. - interval := statusErrorInterval - for { - select { - case <-time.After(interval): - if !s.Health() { - if lg != nil { - lg.Warn( - "prober detected unhealthy status", - zap.String("round-tripper-name", roundTripperName), - zap.String("remote-peer-id", id), - zap.Duration("rtt", s.SRTT()), - zap.Error(s.Err()), - ) - } - interval = statusErrorInterval - } else { - interval = statusMonitoringInterval - } - if s.ClockDiff() > time.Second { - if lg != nil { - lg.Warn( - "prober found high clock drift", - zap.String("round-tripper-name", roundTripperName), - zap.String("remote-peer-id", id), - zap.Duration("clock-drift", s.ClockDiff()), - zap.Duration("rtt", s.SRTT()), - zap.Error(s.Err()), - ) - } - } - rttSecProm.WithLabelValues(id).Observe(s.SRTT().Seconds()) - - case <-s.StopNotify(): - return - } - } -} diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp/remote.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp/remote.go deleted file mode 100644 index eddb3f4da1..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp/remote.go +++ /dev/null @@ -1,95 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package rafthttp - -import ( - "go.etcd.io/etcd/client/pkg/v3/types" - "go.etcd.io/etcd/raft/v3/raftpb" - - "go.uber.org/zap" -) - -type remote struct { - lg *zap.Logger - localID types.ID - id types.ID - status *peerStatus - pipeline *pipeline -} - -func startRemote(tr *Transport, urls types.URLs, id types.ID) *remote { - picker := newURLPicker(urls) - status := newPeerStatus(tr.Logger, tr.ID, id) - pipeline := &pipeline{ - peerID: id, - tr: tr, - picker: picker, - status: status, - raft: tr.Raft, - errorc: tr.ErrorC, - } - pipeline.start() - - return &remote{ - lg: tr.Logger, - localID: tr.ID, - id: id, - status: status, - pipeline: pipeline, - } -} - -func (g *remote) send(m raftpb.Message) { - select { - case g.pipeline.msgc <- m: - default: - if g.status.isActive() { - if g.lg != nil { - g.lg.Warn( - "dropped internal Raft message since sending buffer is full (overloaded network)", - zap.String("message-type", m.Type.String()), - zap.String("local-member-id", g.localID.String()), - zap.String("from", types.ID(m.From).String()), - zap.String("remote-peer-id", g.id.String()), - zap.Bool("remote-peer-active", g.status.isActive()), - ) - } - } else { - if g.lg != nil { - g.lg.Warn( - "dropped Raft message since sending buffer is full (overloaded network)", - zap.String("message-type", m.Type.String()), - zap.String("local-member-id", g.localID.String()), - zap.String("from", types.ID(m.From).String()), - zap.String("remote-peer-id", g.id.String()), - zap.Bool("remote-peer-active", g.status.isActive()), - ) - } - } - sentFailures.WithLabelValues(types.ID(m.To).String()).Inc() - } -} - -func (g *remote) stop() { - g.pipeline.stop() -} - -func (g *remote) Pause() { - g.stop() -} - -func (g *remote) Resume() { - g.pipeline.start() -} diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp/snapshot_sender.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp/snapshot_sender.go deleted file mode 100644 index 84eb56bd0b..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp/snapshot_sender.go +++ /dev/null @@ -1,201 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package rafthttp - -import ( - "bytes" - "context" - "io" - "io/ioutil" - "net/http" - "time" - - "go.etcd.io/etcd/client/pkg/v3/types" - "go.etcd.io/etcd/pkg/v3/httputil" - pioutil "go.etcd.io/etcd/pkg/v3/ioutil" - "go.etcd.io/etcd/raft/v3" - "go.etcd.io/etcd/server/v3/etcdserver/api/snap" - - "github.com/dustin/go-humanize" - "go.uber.org/zap" -) - -var ( - // timeout for reading snapshot response body - snapResponseReadTimeout = 5 * time.Second -) - -type snapshotSender struct { - from, to types.ID - cid types.ID - - tr *Transport - picker *urlPicker - status *peerStatus - r Raft - errorc chan error - - stopc chan struct{} -} - -func newSnapshotSender(tr *Transport, picker *urlPicker, to types.ID, status *peerStatus) *snapshotSender { - return &snapshotSender{ - from: tr.ID, - to: to, - cid: tr.ClusterID, - tr: tr, - picker: picker, - status: status, - r: tr.Raft, - errorc: tr.ErrorC, - stopc: make(chan struct{}), - } -} - -func (s *snapshotSender) stop() { close(s.stopc) } - -func (s *snapshotSender) send(merged snap.Message) { - start := time.Now() - - m := merged.Message - to := types.ID(m.To).String() - - body := createSnapBody(s.tr.Logger, merged) - defer body.Close() - - u := s.picker.pick() - req := createPostRequest(s.tr.Logger, u, RaftSnapshotPrefix, body, "application/octet-stream", s.tr.URLs, s.from, s.cid) - - snapshotSizeVal := uint64(merged.TotalSize) - snapshotSize := humanize.Bytes(snapshotSizeVal) - if s.tr.Logger != nil { - s.tr.Logger.Info( - "sending database snapshot", - zap.Uint64("snapshot-index", m.Snapshot.Metadata.Index), - zap.String("remote-peer-id", to), - zap.Uint64("bytes", snapshotSizeVal), - zap.String("size", snapshotSize), - ) - } - - snapshotSendInflights.WithLabelValues(to).Inc() - defer func() { - snapshotSendInflights.WithLabelValues(to).Dec() - }() - - err := s.post(req) - defer merged.CloseWithError(err) - if err != nil { - if s.tr.Logger != nil { - s.tr.Logger.Warn( - "failed to send database snapshot", - zap.Uint64("snapshot-index", m.Snapshot.Metadata.Index), - zap.String("remote-peer-id", to), - zap.Uint64("bytes", snapshotSizeVal), - zap.String("size", snapshotSize), - zap.Error(err), - ) - } - - // errMemberRemoved is a critical error since a removed member should - // always be stopped. So we use reportCriticalError to report it to errorc. - if err == errMemberRemoved { - reportCriticalError(err, s.errorc) - } - - s.picker.unreachable(u) - s.status.deactivate(failureType{source: sendSnap, action: "post"}, err.Error()) - s.r.ReportUnreachable(m.To) - // report SnapshotFailure to raft state machine. After raft state - // machine knows about it, it would pause a while and retry sending - // new snapshot message. - s.r.ReportSnapshot(m.To, raft.SnapshotFailure) - sentFailures.WithLabelValues(to).Inc() - snapshotSendFailures.WithLabelValues(to).Inc() - return - } - s.status.activate() - s.r.ReportSnapshot(m.To, raft.SnapshotFinish) - - if s.tr.Logger != nil { - s.tr.Logger.Info( - "sent database snapshot", - zap.Uint64("snapshot-index", m.Snapshot.Metadata.Index), - zap.String("remote-peer-id", to), - zap.Uint64("bytes", snapshotSizeVal), - zap.String("size", snapshotSize), - ) - } - - sentBytes.WithLabelValues(to).Add(float64(merged.TotalSize)) - snapshotSend.WithLabelValues(to).Inc() - snapshotSendSeconds.WithLabelValues(to).Observe(time.Since(start).Seconds()) -} - -// post posts the given request. -// It returns nil when request is sent out and processed successfully. -func (s *snapshotSender) post(req *http.Request) (err error) { - ctx, cancel := context.WithCancel(context.Background()) - req = req.WithContext(ctx) - defer cancel() - - type responseAndError struct { - resp *http.Response - body []byte - err error - } - result := make(chan responseAndError, 1) - - go func() { - resp, err := s.tr.pipelineRt.RoundTrip(req) - if err != nil { - result <- responseAndError{resp, nil, err} - return - } - - // close the response body when timeouts. - // prevents from reading the body forever when the other side dies right after - // successfully receives the request body. - time.AfterFunc(snapResponseReadTimeout, func() { httputil.GracefulClose(resp) }) - body, err := ioutil.ReadAll(resp.Body) - result <- responseAndError{resp, body, err} - }() - - select { - case <-s.stopc: - return errStopped - case r := <-result: - if r.err != nil { - return r.err - } - return checkPostResponse(s.tr.Logger, r.resp, r.body, req, s.to) - } -} - -func createSnapBody(lg *zap.Logger, merged snap.Message) io.ReadCloser { - buf := new(bytes.Buffer) - enc := &messageEncoder{w: buf} - // encode raft message - if err := enc.encode(&merged.Message); err != nil { - if lg != nil { - lg.Panic("failed to encode message", zap.Error(err)) - } - } - - return &pioutil.ReaderAndCloser{ - Reader: io.MultiReader(buf, merged.ReadCloser), - Closer: merged.ReadCloser, - } -} diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp/stream.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp/stream.go deleted file mode 100644 index 321fd5283d..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp/stream.go +++ /dev/null @@ -1,713 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package rafthttp - -import ( - "context" - "fmt" - "io" - "io/ioutil" - "net/http" - "path" - "strings" - "sync" - "time" - - "go.etcd.io/etcd/api/v3/version" - "go.etcd.io/etcd/client/pkg/v3/transport" - "go.etcd.io/etcd/client/pkg/v3/types" - "go.etcd.io/etcd/pkg/v3/httputil" - "go.etcd.io/etcd/raft/v3/raftpb" - stats "go.etcd.io/etcd/server/v3/etcdserver/api/v2stats" - - "github.com/coreos/go-semver/semver" - "go.uber.org/zap" - "golang.org/x/time/rate" -) - -const ( - streamTypeMessage streamType = "message" - streamTypeMsgAppV2 streamType = "msgappv2" - - streamBufSize = 4096 -) - -var ( - errUnsupportedStreamType = fmt.Errorf("unsupported stream type") - - // the key is in string format "major.minor.patch" - supportedStream = map[string][]streamType{ - "2.0.0": {}, - "2.1.0": {streamTypeMsgAppV2, streamTypeMessage}, - "2.2.0": {streamTypeMsgAppV2, streamTypeMessage}, - "2.3.0": {streamTypeMsgAppV2, streamTypeMessage}, - "3.0.0": {streamTypeMsgAppV2, streamTypeMessage}, - "3.1.0": {streamTypeMsgAppV2, streamTypeMessage}, - "3.2.0": {streamTypeMsgAppV2, streamTypeMessage}, - "3.3.0": {streamTypeMsgAppV2, streamTypeMessage}, - "3.4.0": {streamTypeMsgAppV2, streamTypeMessage}, - "3.5.0": {streamTypeMsgAppV2, streamTypeMessage}, - } -) - -type streamType string - -func (t streamType) endpoint(lg *zap.Logger) string { - switch t { - case streamTypeMsgAppV2: - return path.Join(RaftStreamPrefix, "msgapp") - case streamTypeMessage: - return path.Join(RaftStreamPrefix, "message") - default: - if lg != nil { - lg.Panic("unhandled stream type", zap.String("stream-type", t.String())) - } - return "" - } -} - -func (t streamType) String() string { - switch t { - case streamTypeMsgAppV2: - return "stream MsgApp v2" - case streamTypeMessage: - return "stream Message" - default: - return "unknown stream" - } -} - -var ( - // linkHeartbeatMessage is a special message used as heartbeat message in - // link layer. It never conflicts with messages from raft because raft - // doesn't send out messages without From and To fields. - linkHeartbeatMessage = raftpb.Message{Type: raftpb.MsgHeartbeat} -) - -func isLinkHeartbeatMessage(m *raftpb.Message) bool { - return m.Type == raftpb.MsgHeartbeat && m.From == 0 && m.To == 0 -} - -type outgoingConn struct { - t streamType - io.Writer - http.Flusher - io.Closer - - localID types.ID - peerID types.ID -} - -// streamWriter writes messages to the attached outgoingConn. -type streamWriter struct { - lg *zap.Logger - - localID types.ID - peerID types.ID - - status *peerStatus - fs *stats.FollowerStats - r Raft - - mu sync.Mutex // guard field working and closer - closer io.Closer - working bool - - msgc chan raftpb.Message - connc chan *outgoingConn - stopc chan struct{} - done chan struct{} -} - -// startStreamWriter creates a streamWrite and starts a long running go-routine that accepts -// messages and writes to the attached outgoing connection. -func startStreamWriter(lg *zap.Logger, local, id types.ID, status *peerStatus, fs *stats.FollowerStats, r Raft) *streamWriter { - w := &streamWriter{ - lg: lg, - - localID: local, - peerID: id, - - status: status, - fs: fs, - r: r, - msgc: make(chan raftpb.Message, streamBufSize), - connc: make(chan *outgoingConn), - stopc: make(chan struct{}), - done: make(chan struct{}), - } - go w.run() - return w -} - -func (cw *streamWriter) run() { - var ( - msgc chan raftpb.Message - heartbeatc <-chan time.Time - t streamType - enc encoder - flusher http.Flusher - batched int - ) - tickc := time.NewTicker(ConnReadTimeout / 3) - defer tickc.Stop() - unflushed := 0 - - if cw.lg != nil { - cw.lg.Info( - "started stream writer with remote peer", - zap.String("local-member-id", cw.localID.String()), - zap.String("remote-peer-id", cw.peerID.String()), - ) - } - - for { - select { - case <-heartbeatc: - err := enc.encode(&linkHeartbeatMessage) - unflushed += linkHeartbeatMessage.Size() - if err == nil { - flusher.Flush() - batched = 0 - sentBytes.WithLabelValues(cw.peerID.String()).Add(float64(unflushed)) - unflushed = 0 - continue - } - - cw.status.deactivate(failureType{source: t.String(), action: "heartbeat"}, err.Error()) - - sentFailures.WithLabelValues(cw.peerID.String()).Inc() - cw.close() - if cw.lg != nil { - cw.lg.Warn( - "lost TCP streaming connection with remote peer", - zap.String("stream-writer-type", t.String()), - zap.String("local-member-id", cw.localID.String()), - zap.String("remote-peer-id", cw.peerID.String()), - ) - } - heartbeatc, msgc = nil, nil - - case m := <-msgc: - err := enc.encode(&m) - if err == nil { - unflushed += m.Size() - - if len(msgc) == 0 || batched > streamBufSize/2 { - flusher.Flush() - sentBytes.WithLabelValues(cw.peerID.String()).Add(float64(unflushed)) - unflushed = 0 - batched = 0 - } else { - batched++ - } - - continue - } - - cw.status.deactivate(failureType{source: t.String(), action: "write"}, err.Error()) - cw.close() - if cw.lg != nil { - cw.lg.Warn( - "lost TCP streaming connection with remote peer", - zap.String("stream-writer-type", t.String()), - zap.String("local-member-id", cw.localID.String()), - zap.String("remote-peer-id", cw.peerID.String()), - ) - } - heartbeatc, msgc = nil, nil - cw.r.ReportUnreachable(m.To) - sentFailures.WithLabelValues(cw.peerID.String()).Inc() - - case conn := <-cw.connc: - cw.mu.Lock() - closed := cw.closeUnlocked() - t = conn.t - switch conn.t { - case streamTypeMsgAppV2: - enc = newMsgAppV2Encoder(conn.Writer, cw.fs) - case streamTypeMessage: - enc = &messageEncoder{w: conn.Writer} - default: - if cw.lg != nil { - cw.lg.Panic("unhandled stream type", zap.String("stream-type", t.String())) - } - } - if cw.lg != nil { - cw.lg.Info( - "set message encoder", - zap.String("from", conn.localID.String()), - zap.String("to", conn.peerID.String()), - zap.String("stream-type", t.String()), - ) - } - flusher = conn.Flusher - unflushed = 0 - cw.status.activate() - cw.closer = conn.Closer - cw.working = true - cw.mu.Unlock() - - if closed { - if cw.lg != nil { - cw.lg.Warn( - "closed TCP streaming connection with remote peer", - zap.String("stream-writer-type", t.String()), - zap.String("local-member-id", cw.localID.String()), - zap.String("remote-peer-id", cw.peerID.String()), - ) - } - } - if cw.lg != nil { - cw.lg.Info( - "established TCP streaming connection with remote peer", - zap.String("stream-writer-type", t.String()), - zap.String("local-member-id", cw.localID.String()), - zap.String("remote-peer-id", cw.peerID.String()), - ) - } - heartbeatc, msgc = tickc.C, cw.msgc - - case <-cw.stopc: - if cw.close() { - if cw.lg != nil { - cw.lg.Warn( - "closed TCP streaming connection with remote peer", - zap.String("stream-writer-type", t.String()), - zap.String("remote-peer-id", cw.peerID.String()), - ) - } - } - if cw.lg != nil { - cw.lg.Info( - "stopped TCP streaming connection with remote peer", - zap.String("stream-writer-type", t.String()), - zap.String("remote-peer-id", cw.peerID.String()), - ) - } - close(cw.done) - return - } - } -} - -func (cw *streamWriter) writec() (chan<- raftpb.Message, bool) { - cw.mu.Lock() - defer cw.mu.Unlock() - return cw.msgc, cw.working -} - -func (cw *streamWriter) close() bool { - cw.mu.Lock() - defer cw.mu.Unlock() - return cw.closeUnlocked() -} - -func (cw *streamWriter) closeUnlocked() bool { - if !cw.working { - return false - } - if err := cw.closer.Close(); err != nil { - if cw.lg != nil { - cw.lg.Warn( - "failed to close connection with remote peer", - zap.String("remote-peer-id", cw.peerID.String()), - zap.Error(err), - ) - } - } - if len(cw.msgc) > 0 { - cw.r.ReportUnreachable(uint64(cw.peerID)) - } - cw.msgc = make(chan raftpb.Message, streamBufSize) - cw.working = false - return true -} - -func (cw *streamWriter) attach(conn *outgoingConn) bool { - select { - case cw.connc <- conn: - return true - case <-cw.done: - return false - } -} - -func (cw *streamWriter) stop() { - close(cw.stopc) - <-cw.done -} - -// streamReader is a long-running go-routine that dials to the remote stream -// endpoint and reads messages from the response body returned. -type streamReader struct { - lg *zap.Logger - - peerID types.ID - typ streamType - - tr *Transport - picker *urlPicker - status *peerStatus - recvc chan<- raftpb.Message - propc chan<- raftpb.Message - - rl *rate.Limiter // alters the frequency of dial retrial attempts - - errorc chan<- error - - mu sync.Mutex - paused bool - closer io.Closer - - ctx context.Context - cancel context.CancelFunc - done chan struct{} -} - -func (cr *streamReader) start() { - cr.done = make(chan struct{}) - if cr.errorc == nil { - cr.errorc = cr.tr.ErrorC - } - if cr.ctx == nil { - cr.ctx, cr.cancel = context.WithCancel(context.Background()) - } - go cr.run() -} - -func (cr *streamReader) run() { - t := cr.typ - - if cr.lg != nil { - cr.lg.Info( - "started stream reader with remote peer", - zap.String("stream-reader-type", t.String()), - zap.String("local-member-id", cr.tr.ID.String()), - zap.String("remote-peer-id", cr.peerID.String()), - ) - } - - for { - rc, err := cr.dial(t) - if err != nil { - if err != errUnsupportedStreamType { - cr.status.deactivate(failureType{source: t.String(), action: "dial"}, err.Error()) - } - } else { - cr.status.activate() - if cr.lg != nil { - cr.lg.Info( - "established TCP streaming connection with remote peer", - zap.String("stream-reader-type", cr.typ.String()), - zap.String("local-member-id", cr.tr.ID.String()), - zap.String("remote-peer-id", cr.peerID.String()), - ) - } - err = cr.decodeLoop(rc, t) - if cr.lg != nil { - cr.lg.Warn( - "lost TCP streaming connection with remote peer", - zap.String("stream-reader-type", cr.typ.String()), - zap.String("local-member-id", cr.tr.ID.String()), - zap.String("remote-peer-id", cr.peerID.String()), - zap.Error(err), - ) - } - switch { - // all data is read out - case err == io.EOF: - // connection is closed by the remote - case transport.IsClosedConnError(err): - default: - cr.status.deactivate(failureType{source: t.String(), action: "read"}, err.Error()) - } - } - // Wait for a while before new dial attempt - err = cr.rl.Wait(cr.ctx) - if cr.ctx.Err() != nil { - if cr.lg != nil { - cr.lg.Info( - "stopped stream reader with remote peer", - zap.String("stream-reader-type", t.String()), - zap.String("local-member-id", cr.tr.ID.String()), - zap.String("remote-peer-id", cr.peerID.String()), - ) - } - close(cr.done) - return - } - if err != nil { - if cr.lg != nil { - cr.lg.Warn( - "rate limit on stream reader with remote peer", - zap.String("stream-reader-type", t.String()), - zap.String("local-member-id", cr.tr.ID.String()), - zap.String("remote-peer-id", cr.peerID.String()), - zap.Error(err), - ) - } - } - } -} - -func (cr *streamReader) decodeLoop(rc io.ReadCloser, t streamType) error { - var dec decoder - cr.mu.Lock() - switch t { - case streamTypeMsgAppV2: - dec = newMsgAppV2Decoder(rc, cr.tr.ID, cr.peerID) - case streamTypeMessage: - dec = &messageDecoder{r: rc} - default: - if cr.lg != nil { - cr.lg.Panic("unknown stream type", zap.String("type", t.String())) - } - } - select { - case <-cr.ctx.Done(): - cr.mu.Unlock() - if err := rc.Close(); err != nil { - return err - } - return io.EOF - default: - cr.closer = rc - } - cr.mu.Unlock() - - // gofail: labelRaftDropHeartbeat: - for { - m, err := dec.decode() - if err != nil { - cr.mu.Lock() - cr.close() - cr.mu.Unlock() - return err - } - - // gofail-go: var raftDropHeartbeat struct{} - // continue labelRaftDropHeartbeat - receivedBytes.WithLabelValues(types.ID(m.From).String()).Add(float64(m.Size())) - - cr.mu.Lock() - paused := cr.paused - cr.mu.Unlock() - - if paused { - continue - } - - if isLinkHeartbeatMessage(&m) { - // raft is not interested in link layer - // heartbeat message, so we should ignore - // it. - continue - } - - recvc := cr.recvc - if m.Type == raftpb.MsgProp { - recvc = cr.propc - } - - select { - case recvc <- m: - default: - if cr.status.isActive() { - if cr.lg != nil { - cr.lg.Warn( - "dropped internal Raft message since receiving buffer is full (overloaded network)", - zap.String("message-type", m.Type.String()), - zap.String("local-member-id", cr.tr.ID.String()), - zap.String("from", types.ID(m.From).String()), - zap.String("remote-peer-id", types.ID(m.To).String()), - zap.Bool("remote-peer-active", cr.status.isActive()), - ) - } - } else { - if cr.lg != nil { - cr.lg.Warn( - "dropped Raft message since receiving buffer is full (overloaded network)", - zap.String("message-type", m.Type.String()), - zap.String("local-member-id", cr.tr.ID.String()), - zap.String("from", types.ID(m.From).String()), - zap.String("remote-peer-id", types.ID(m.To).String()), - zap.Bool("remote-peer-active", cr.status.isActive()), - ) - } - } - recvFailures.WithLabelValues(types.ID(m.From).String()).Inc() - } - } -} - -func (cr *streamReader) stop() { - cr.mu.Lock() - cr.cancel() - cr.close() - cr.mu.Unlock() - <-cr.done -} - -func (cr *streamReader) dial(t streamType) (io.ReadCloser, error) { - u := cr.picker.pick() - uu := u - uu.Path = path.Join(t.endpoint(cr.lg), cr.tr.ID.String()) - - if cr.lg != nil { - cr.lg.Debug( - "dial stream reader", - zap.String("from", cr.tr.ID.String()), - zap.String("to", cr.peerID.String()), - zap.String("address", uu.String()), - ) - } - req, err := http.NewRequest("GET", uu.String(), nil) - if err != nil { - cr.picker.unreachable(u) - return nil, fmt.Errorf("failed to make http request to %v (%v)", u, err) - } - req.Header.Set("X-Server-From", cr.tr.ID.String()) - req.Header.Set("X-Server-Version", version.Version) - req.Header.Set("X-Min-Cluster-Version", version.MinClusterVersion) - req.Header.Set("X-Etcd-Cluster-ID", cr.tr.ClusterID.String()) - req.Header.Set("X-Raft-To", cr.peerID.String()) - - setPeerURLsHeader(req, cr.tr.URLs) - - req = req.WithContext(cr.ctx) - - cr.mu.Lock() - select { - case <-cr.ctx.Done(): - cr.mu.Unlock() - return nil, fmt.Errorf("stream reader is stopped") - default: - } - cr.mu.Unlock() - - resp, err := cr.tr.streamRt.RoundTrip(req) - if err != nil { - cr.picker.unreachable(u) - return nil, err - } - - rv := serverVersion(resp.Header) - lv := semver.Must(semver.NewVersion(version.Version)) - if compareMajorMinorVersion(rv, lv) == -1 && !checkStreamSupport(rv, t) { - httputil.GracefulClose(resp) - cr.picker.unreachable(u) - return nil, errUnsupportedStreamType - } - - switch resp.StatusCode { - case http.StatusGone: - httputil.GracefulClose(resp) - cr.picker.unreachable(u) - reportCriticalError(errMemberRemoved, cr.errorc) - return nil, errMemberRemoved - - case http.StatusOK: - return resp.Body, nil - - case http.StatusNotFound: - httputil.GracefulClose(resp) - cr.picker.unreachable(u) - return nil, fmt.Errorf("peer %s failed to find local node %s", cr.peerID, cr.tr.ID) - - case http.StatusPreconditionFailed: - b, err := ioutil.ReadAll(resp.Body) - if err != nil { - cr.picker.unreachable(u) - return nil, err - } - httputil.GracefulClose(resp) - cr.picker.unreachable(u) - - switch strings.TrimSuffix(string(b), "\n") { - case errIncompatibleVersion.Error(): - if cr.lg != nil { - cr.lg.Warn( - "request sent was ignored by remote peer due to server version incompatibility", - zap.String("local-member-id", cr.tr.ID.String()), - zap.String("remote-peer-id", cr.peerID.String()), - zap.Error(errIncompatibleVersion), - ) - } - return nil, errIncompatibleVersion - - case errClusterIDMismatch.Error(): - if cr.lg != nil { - cr.lg.Warn( - "request sent was ignored by remote peer due to cluster ID mismatch", - zap.String("remote-peer-id", cr.peerID.String()), - zap.String("remote-peer-cluster-id", resp.Header.Get("X-Etcd-Cluster-ID")), - zap.String("local-member-id", cr.tr.ID.String()), - zap.String("local-member-cluster-id", cr.tr.ClusterID.String()), - zap.Error(errClusterIDMismatch), - ) - } - return nil, errClusterIDMismatch - - default: - return nil, fmt.Errorf("unhandled error %q when precondition failed", string(b)) - } - - default: - httputil.GracefulClose(resp) - cr.picker.unreachable(u) - return nil, fmt.Errorf("unhandled http status %d", resp.StatusCode) - } -} - -func (cr *streamReader) close() { - if cr.closer != nil { - if err := cr.closer.Close(); err != nil { - if cr.lg != nil { - cr.lg.Warn( - "failed to close remote peer connection", - zap.String("local-member-id", cr.tr.ID.String()), - zap.String("remote-peer-id", cr.peerID.String()), - zap.Error(err), - ) - } - } - } - cr.closer = nil -} - -func (cr *streamReader) pause() { - cr.mu.Lock() - defer cr.mu.Unlock() - cr.paused = true -} - -func (cr *streamReader) resume() { - cr.mu.Lock() - defer cr.mu.Unlock() - cr.paused = false -} - -// checkStreamSupport checks whether the stream type is supported in the -// given version. -func checkStreamSupport(v *semver.Version, t streamType) bool { - nv := &semver.Version{Major: v.Major, Minor: v.Minor} - for _, s := range supportedStream[nv.String()] { - if s == t { - return true - } - } - return false -} diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp/transport.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp/transport.go deleted file mode 100644 index 940e8473bc..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp/transport.go +++ /dev/null @@ -1,447 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package rafthttp - -import ( - "context" - "net/http" - "sync" - "time" - - "go.etcd.io/etcd/client/pkg/v3/transport" - "go.etcd.io/etcd/client/pkg/v3/types" - "go.etcd.io/etcd/raft/v3" - "go.etcd.io/etcd/raft/v3/raftpb" - "go.etcd.io/etcd/server/v3/etcdserver/api/snap" - stats "go.etcd.io/etcd/server/v3/etcdserver/api/v2stats" - - "github.com/xiang90/probing" - "go.uber.org/zap" - "golang.org/x/time/rate" -) - -type Raft interface { - Process(ctx context.Context, m raftpb.Message) error - IsIDRemoved(id uint64) bool - ReportUnreachable(id uint64) - ReportSnapshot(id uint64, status raft.SnapshotStatus) -} - -type Transporter interface { - // Start starts the given Transporter. - // Start MUST be called before calling other functions in the interface. - Start() error - // Handler returns the HTTP handler of the transporter. - // A transporter HTTP handler handles the HTTP requests - // from remote peers. - // The handler MUST be used to handle RaftPrefix(/raft) - // endpoint. - Handler() http.Handler - // Send sends out the given messages to the remote peers. - // Each message has a To field, which is an id that maps - // to an existing peer in the transport. - // If the id cannot be found in the transport, the message - // will be ignored. - Send(m []raftpb.Message) - // SendSnapshot sends out the given snapshot message to a remote peer. - // The behavior of SendSnapshot is similar to Send. - SendSnapshot(m snap.Message) - // AddRemote adds a remote with given peer urls into the transport. - // A remote helps newly joined member to catch up the progress of cluster, - // and will not be used after that. - // It is the caller's responsibility to ensure the urls are all valid, - // or it panics. - AddRemote(id types.ID, urls []string) - // AddPeer adds a peer with given peer urls into the transport. - // It is the caller's responsibility to ensure the urls are all valid, - // or it panics. - // Peer urls are used to connect to the remote peer. - AddPeer(id types.ID, urls []string) - // RemovePeer removes the peer with given id. - RemovePeer(id types.ID) - // RemoveAllPeers removes all the existing peers in the transport. - RemoveAllPeers() - // UpdatePeer updates the peer urls of the peer with the given id. - // It is the caller's responsibility to ensure the urls are all valid, - // or it panics. - UpdatePeer(id types.ID, urls []string) - // ActiveSince returns the time that the connection with the peer - // of the given id becomes active. - // If the connection is active since peer was added, it returns the adding time. - // If the connection is currently inactive, it returns zero time. - ActiveSince(id types.ID) time.Time - // ActivePeers returns the number of active peers. - ActivePeers() int - // Stop closes the connections and stops the transporter. - Stop() -} - -// Transport implements Transporter interface. It provides the functionality -// to send raft messages to peers, and receive raft messages from peers. -// User should call Handler method to get a handler to serve requests -// received from peerURLs. -// User needs to call Start before calling other functions, and call -// Stop when the Transport is no longer used. -type Transport struct { - Logger *zap.Logger - - DialTimeout time.Duration // maximum duration before timing out dial of the request - // DialRetryFrequency defines the frequency of streamReader dial retrial attempts; - // a distinct rate limiter is created per every peer (default value: 10 events/sec) - DialRetryFrequency rate.Limit - - TLSInfo transport.TLSInfo // TLS information used when creating connection - - ID types.ID // local member ID - URLs types.URLs // local peer URLs - ClusterID types.ID // raft cluster ID for request validation - Raft Raft // raft state machine, to which the Transport forwards received messages and reports status - Snapshotter *snap.Snapshotter - ServerStats *stats.ServerStats // used to record general transportation statistics - // used to record transportation statistics with followers when - // performing as leader in raft protocol - LeaderStats *stats.LeaderStats - // ErrorC is used to report detected critical errors, e.g., - // the member has been permanently removed from the cluster - // When an error is received from ErrorC, user should stop raft state - // machine and thus stop the Transport. - ErrorC chan error - - streamRt http.RoundTripper // roundTripper used by streams - pipelineRt http.RoundTripper // roundTripper used by pipelines - - mu sync.RWMutex // protect the remote and peer map - remotes map[types.ID]*remote // remotes map that helps newly joined member to catch up - peers map[types.ID]Peer // peers map - - pipelineProber probing.Prober - streamProber probing.Prober -} - -func (t *Transport) Start() error { - var err error - t.streamRt, err = newStreamRoundTripper(t.TLSInfo, t.DialTimeout) - if err != nil { - return err - } - t.pipelineRt, err = NewRoundTripper(t.TLSInfo, t.DialTimeout) - if err != nil { - return err - } - t.remotes = make(map[types.ID]*remote) - t.peers = make(map[types.ID]Peer) - t.pipelineProber = probing.NewProber(t.pipelineRt) - t.streamProber = probing.NewProber(t.streamRt) - - // If client didn't provide dial retry frequency, use the default - // (100ms backoff between attempts to create a new stream), - // so it doesn't bring too much overhead when retry. - if t.DialRetryFrequency == 0 { - t.DialRetryFrequency = rate.Every(100 * time.Millisecond) - } - return nil -} - -func (t *Transport) Handler() http.Handler { - pipelineHandler := newPipelineHandler(t, t.Raft, t.ClusterID) - streamHandler := newStreamHandler(t, t, t.Raft, t.ID, t.ClusterID) - snapHandler := newSnapshotHandler(t, t.Raft, t.Snapshotter, t.ClusterID) - mux := http.NewServeMux() - mux.Handle(RaftPrefix, pipelineHandler) - mux.Handle(RaftStreamPrefix+"/", streamHandler) - mux.Handle(RaftSnapshotPrefix, snapHandler) - mux.Handle(ProbingPrefix, probing.NewHandler()) - return mux -} - -func (t *Transport) Get(id types.ID) Peer { - t.mu.RLock() - defer t.mu.RUnlock() - return t.peers[id] -} - -func (t *Transport) Send(msgs []raftpb.Message) { - for _, m := range msgs { - if m.To == 0 { - // ignore intentionally dropped message - continue - } - to := types.ID(m.To) - - t.mu.RLock() - p, pok := t.peers[to] - g, rok := t.remotes[to] - t.mu.RUnlock() - - if pok { - if m.Type == raftpb.MsgApp { - t.ServerStats.SendAppendReq(m.Size()) - } - p.send(m) - continue - } - - if rok { - g.send(m) - continue - } - - if t.Logger != nil { - t.Logger.Debug( - "ignored message send request; unknown remote peer target", - zap.String("type", m.Type.String()), - zap.String("unknown-target-peer-id", to.String()), - ) - } - } -} - -func (t *Transport) Stop() { - t.mu.Lock() - defer t.mu.Unlock() - for _, r := range t.remotes { - r.stop() - } - for _, p := range t.peers { - p.stop() - } - t.pipelineProber.RemoveAll() - t.streamProber.RemoveAll() - if tr, ok := t.streamRt.(*http.Transport); ok { - tr.CloseIdleConnections() - } - if tr, ok := t.pipelineRt.(*http.Transport); ok { - tr.CloseIdleConnections() - } - t.peers = nil - t.remotes = nil -} - -// CutPeer drops messages to the specified peer. -func (t *Transport) CutPeer(id types.ID) { - t.mu.RLock() - p, pok := t.peers[id] - g, gok := t.remotes[id] - t.mu.RUnlock() - - if pok { - p.(Pausable).Pause() - } - if gok { - g.Pause() - } -} - -// MendPeer recovers the message dropping behavior of the given peer. -func (t *Transport) MendPeer(id types.ID) { - t.mu.RLock() - p, pok := t.peers[id] - g, gok := t.remotes[id] - t.mu.RUnlock() - - if pok { - p.(Pausable).Resume() - } - if gok { - g.Resume() - } -} - -func (t *Transport) AddRemote(id types.ID, us []string) { - t.mu.Lock() - defer t.mu.Unlock() - if t.remotes == nil { - // there's no clean way to shutdown the golang http server - // (see: https://github.com/golang/go/issues/4674) before - // stopping the transport; ignore any new connections. - return - } - if _, ok := t.peers[id]; ok { - return - } - if _, ok := t.remotes[id]; ok { - return - } - urls, err := types.NewURLs(us) - if err != nil { - if t.Logger != nil { - t.Logger.Panic("failed NewURLs", zap.Strings("urls", us), zap.Error(err)) - } - } - t.remotes[id] = startRemote(t, urls, id) - - if t.Logger != nil { - t.Logger.Info( - "added new remote peer", - zap.String("local-member-id", t.ID.String()), - zap.String("remote-peer-id", id.String()), - zap.Strings("remote-peer-urls", us), - ) - } -} - -func (t *Transport) AddPeer(id types.ID, us []string) { - t.mu.Lock() - defer t.mu.Unlock() - - if t.peers == nil { - panic("transport stopped") - } - if _, ok := t.peers[id]; ok { - return - } - urls, err := types.NewURLs(us) - if err != nil { - if t.Logger != nil { - t.Logger.Panic("failed NewURLs", zap.Strings("urls", us), zap.Error(err)) - } - } - fs := t.LeaderStats.Follower(id.String()) - t.peers[id] = startPeer(t, urls, id, fs) - addPeerToProber(t.Logger, t.pipelineProber, id.String(), us, RoundTripperNameSnapshot, rttSec) - addPeerToProber(t.Logger, t.streamProber, id.String(), us, RoundTripperNameRaftMessage, rttSec) - - if t.Logger != nil { - t.Logger.Info( - "added remote peer", - zap.String("local-member-id", t.ID.String()), - zap.String("remote-peer-id", id.String()), - zap.Strings("remote-peer-urls", us), - ) - } -} - -func (t *Transport) RemovePeer(id types.ID) { - t.mu.Lock() - defer t.mu.Unlock() - t.removePeer(id) -} - -func (t *Transport) RemoveAllPeers() { - t.mu.Lock() - defer t.mu.Unlock() - for id := range t.peers { - t.removePeer(id) - } -} - -// the caller of this function must have the peers mutex. -func (t *Transport) removePeer(id types.ID) { - if peer, ok := t.peers[id]; ok { - peer.stop() - } else { - if t.Logger != nil { - t.Logger.Panic("unexpected removal of unknown remote peer", zap.String("remote-peer-id", id.String())) - } - } - delete(t.peers, id) - delete(t.LeaderStats.Followers, id.String()) - t.pipelineProber.Remove(id.String()) - t.streamProber.Remove(id.String()) - - if t.Logger != nil { - t.Logger.Info( - "removed remote peer", - zap.String("local-member-id", t.ID.String()), - zap.String("removed-remote-peer-id", id.String()), - ) - } -} - -func (t *Transport) UpdatePeer(id types.ID, us []string) { - t.mu.Lock() - defer t.mu.Unlock() - // TODO: return error or just panic? - if _, ok := t.peers[id]; !ok { - return - } - urls, err := types.NewURLs(us) - if err != nil { - if t.Logger != nil { - t.Logger.Panic("failed NewURLs", zap.Strings("urls", us), zap.Error(err)) - } - } - t.peers[id].update(urls) - - t.pipelineProber.Remove(id.String()) - addPeerToProber(t.Logger, t.pipelineProber, id.String(), us, RoundTripperNameSnapshot, rttSec) - t.streamProber.Remove(id.String()) - addPeerToProber(t.Logger, t.streamProber, id.String(), us, RoundTripperNameRaftMessage, rttSec) - - if t.Logger != nil { - t.Logger.Info( - "updated remote peer", - zap.String("local-member-id", t.ID.String()), - zap.String("updated-remote-peer-id", id.String()), - zap.Strings("updated-remote-peer-urls", us), - ) - } -} - -func (t *Transport) ActiveSince(id types.ID) time.Time { - t.mu.RLock() - defer t.mu.RUnlock() - if p, ok := t.peers[id]; ok { - return p.activeSince() - } - return time.Time{} -} - -func (t *Transport) SendSnapshot(m snap.Message) { - t.mu.Lock() - defer t.mu.Unlock() - p := t.peers[types.ID(m.To)] - if p == nil { - m.CloseWithError(errMemberNotFound) - return - } - p.sendSnap(m) -} - -// Pausable is a testing interface for pausing transport traffic. -type Pausable interface { - Pause() - Resume() -} - -func (t *Transport) Pause() { - t.mu.RLock() - defer t.mu.RUnlock() - for _, p := range t.peers { - p.(Pausable).Pause() - } -} - -func (t *Transport) Resume() { - t.mu.RLock() - defer t.mu.RUnlock() - for _, p := range t.peers { - p.(Pausable).Resume() - } -} - -// ActivePeers returns a channel that closes when an initial -// peer connection has been established. Use this to wait until the -// first peer connection becomes active. -func (t *Transport) ActivePeers() (cnt int) { - t.mu.RLock() - defer t.mu.RUnlock() - for _, p := range t.peers { - if !p.activeSince().IsZero() { - cnt++ - } - } - return cnt -} diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp/urlpick.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp/urlpick.go deleted file mode 100644 index fc6054a78a..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp/urlpick.go +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package rafthttp - -import ( - "net/url" - "sync" - - "go.etcd.io/etcd/client/pkg/v3/types" -) - -type urlPicker struct { - mu sync.Mutex // guards urls and picked - urls types.URLs - picked int -} - -func newURLPicker(urls types.URLs) *urlPicker { - return &urlPicker{ - urls: urls, - } -} - -func (p *urlPicker) update(urls types.URLs) { - p.mu.Lock() - defer p.mu.Unlock() - p.urls = urls - p.picked = 0 -} - -func (p *urlPicker) pick() url.URL { - p.mu.Lock() - defer p.mu.Unlock() - return p.urls[p.picked] -} - -// unreachable notices the picker that the given url is unreachable, -// and it should use other possible urls. -func (p *urlPicker) unreachable(u url.URL) { - p.mu.Lock() - defer p.mu.Unlock() - if u == p.urls[p.picked] { - p.picked = (p.picked + 1) % len(p.urls) - } -} diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp/util.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp/util.go deleted file mode 100644 index 91bc6884e4..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp/util.go +++ /dev/null @@ -1,204 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package rafthttp - -import ( - "fmt" - "io" - "net" - "net/http" - "net/url" - "strings" - "time" - - "go.etcd.io/etcd/api/v3/version" - "go.etcd.io/etcd/client/pkg/v3/transport" - "go.etcd.io/etcd/client/pkg/v3/types" - - "github.com/coreos/go-semver/semver" - "go.uber.org/zap" -) - -var ( - errMemberRemoved = fmt.Errorf("the member has been permanently removed from the cluster") - errMemberNotFound = fmt.Errorf("member not found") -) - -// NewListener returns a listener for raft message transfer between peers. -// It uses timeout listener to identify broken streams promptly. -func NewListener(u url.URL, tlsinfo *transport.TLSInfo) (net.Listener, error) { - return transport.NewListenerWithOpts(u.Host, u.Scheme, transport.WithTLSInfo(tlsinfo), transport.WithTimeout(ConnReadTimeout, ConnWriteTimeout)) -} - -// NewRoundTripper returns a roundTripper used to send requests -// to rafthttp listener of remote peers. -func NewRoundTripper(tlsInfo transport.TLSInfo, dialTimeout time.Duration) (http.RoundTripper, error) { - // It uses timeout transport to pair with remote timeout listeners. - // It sets no read/write timeout, because message in requests may - // take long time to write out before reading out the response. - return transport.NewTimeoutTransport(tlsInfo, dialTimeout, 0, 0) -} - -// newStreamRoundTripper returns a roundTripper used to send stream requests -// to rafthttp listener of remote peers. -// Read/write timeout is set for stream roundTripper to promptly -// find out broken status, which minimizes the number of messages -// sent on broken connection. -func newStreamRoundTripper(tlsInfo transport.TLSInfo, dialTimeout time.Duration) (http.RoundTripper, error) { - return transport.NewTimeoutTransport(tlsInfo, dialTimeout, ConnReadTimeout, ConnWriteTimeout) -} - -// createPostRequest creates a HTTP POST request that sends raft message. -func createPostRequest(lg *zap.Logger, u url.URL, path string, body io.Reader, ct string, urls types.URLs, from, cid types.ID) *http.Request { - uu := u - uu.Path = path - req, err := http.NewRequest("POST", uu.String(), body) - if err != nil { - if lg != nil { - lg.Panic("unexpected new request error", zap.Error(err)) - } - } - req.Header.Set("Content-Type", ct) - req.Header.Set("X-Server-From", from.String()) - req.Header.Set("X-Server-Version", version.Version) - req.Header.Set("X-Min-Cluster-Version", version.MinClusterVersion) - req.Header.Set("X-Etcd-Cluster-ID", cid.String()) - setPeerURLsHeader(req, urls) - - return req -} - -// checkPostResponse checks the response of the HTTP POST request that sends -// raft message. -func checkPostResponse(lg *zap.Logger, resp *http.Response, body []byte, req *http.Request, to types.ID) error { - switch resp.StatusCode { - case http.StatusPreconditionFailed: - switch strings.TrimSuffix(string(body), "\n") { - case errIncompatibleVersion.Error(): - if lg != nil { - lg.Error( - "request sent was ignored by peer", - zap.String("remote-peer-id", to.String()), - ) - } - return errIncompatibleVersion - case errClusterIDMismatch.Error(): - if lg != nil { - lg.Error( - "request sent was ignored due to cluster ID mismatch", - zap.String("remote-peer-id", to.String()), - zap.String("remote-peer-cluster-id", resp.Header.Get("X-Etcd-Cluster-ID")), - zap.String("local-member-cluster-id", req.Header.Get("X-Etcd-Cluster-ID")), - ) - } - return errClusterIDMismatch - default: - return fmt.Errorf("unhandled error %q when precondition failed", string(body)) - } - case http.StatusForbidden: - return errMemberRemoved - case http.StatusNoContent: - return nil - default: - return fmt.Errorf("unexpected http status %s while posting to %q", http.StatusText(resp.StatusCode), req.URL.String()) - } -} - -// reportCriticalError reports the given error through sending it into -// the given error channel. -// If the error channel is filled up when sending error, it drops the error -// because the fact that error has happened is reported, which is -// good enough. -func reportCriticalError(err error, errc chan<- error) { - select { - case errc <- err: - default: - } -} - -// compareMajorMinorVersion returns an integer comparing two versions based on -// their major and minor version. The result will be 0 if a==b, -1 if a < b, -// and 1 if a > b. -func compareMajorMinorVersion(a, b *semver.Version) int { - na := &semver.Version{Major: a.Major, Minor: a.Minor} - nb := &semver.Version{Major: b.Major, Minor: b.Minor} - switch { - case na.LessThan(*nb): - return -1 - case nb.LessThan(*na): - return 1 - default: - return 0 - } -} - -// serverVersion returns the server version from the given header. -func serverVersion(h http.Header) *semver.Version { - verStr := h.Get("X-Server-Version") - // backward compatibility with etcd 2.0 - if verStr == "" { - verStr = "2.0.0" - } - return semver.Must(semver.NewVersion(verStr)) -} - -// serverVersion returns the min cluster version from the given header. -func minClusterVersion(h http.Header) *semver.Version { - verStr := h.Get("X-Min-Cluster-Version") - // backward compatibility with etcd 2.0 - if verStr == "" { - verStr = "2.0.0" - } - return semver.Must(semver.NewVersion(verStr)) -} - -// checkVersionCompatibility checks whether the given version is compatible -// with the local version. -func checkVersionCompatibility(name string, server, minCluster *semver.Version) ( - localServer *semver.Version, - localMinCluster *semver.Version, - err error) { - localServer = semver.Must(semver.NewVersion(version.Version)) - localMinCluster = semver.Must(semver.NewVersion(version.MinClusterVersion)) - if compareMajorMinorVersion(server, localMinCluster) == -1 { - return localServer, localMinCluster, fmt.Errorf("remote version is too low: remote[%s]=%s, local=%s", name, server, localServer) - } - if compareMajorMinorVersion(minCluster, localServer) == 1 { - return localServer, localMinCluster, fmt.Errorf("local version is too low: remote[%s]=%s, local=%s", name, server, localServer) - } - return localServer, localMinCluster, nil -} - -// setPeerURLsHeader reports local urls for peer discovery -func setPeerURLsHeader(req *http.Request, urls types.URLs) { - if urls == nil { - // often not set in unit tests - return - } - peerURLs := make([]string, urls.Len()) - for i := range urls { - peerURLs[i] = urls[i].String() - } - req.Header.Set("X-PeerURLs", strings.Join(peerURLs, ",")) -} - -// addRemoteFromRequest adds a remote peer according to an http request header -func addRemoteFromRequest(tr Transporter, r *http.Request) { - if from, err := types.IDFromString(r.Header.Get("X-Server-From")); err == nil { - if urls := r.Header.Get("X-PeerURLs"); urls != "" { - tr.AddRemote(from, strings.Split(urls, ",")) - } - } -} diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/snap/db.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/snap/db.go deleted file mode 100644 index af653e1d5f..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/snap/db.go +++ /dev/null @@ -1,100 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package snap - -import ( - "errors" - "fmt" - "io" - "io/ioutil" - "os" - "path/filepath" - "time" - - "go.etcd.io/etcd/client/pkg/v3/fileutil" - - humanize "github.com/dustin/go-humanize" - "go.uber.org/zap" -) - -var ErrNoDBSnapshot = errors.New("snap: snapshot file doesn't exist") - -// SaveDBFrom saves snapshot of the database from the given reader. It -// guarantees the save operation is atomic. -func (s *Snapshotter) SaveDBFrom(r io.Reader, id uint64) (int64, error) { - start := time.Now() - - f, err := ioutil.TempFile(s.dir, "tmp") - if err != nil { - return 0, err - } - var n int64 - n, err = io.Copy(f, r) - if err == nil { - fsyncStart := time.Now() - err = fileutil.Fsync(f) - snapDBFsyncSec.Observe(time.Since(fsyncStart).Seconds()) - } - f.Close() - if err != nil { - os.Remove(f.Name()) - return n, err - } - fn := s.dbFilePath(id) - if fileutil.Exist(fn) { - os.Remove(f.Name()) - return n, nil - } - err = os.Rename(f.Name(), fn) - if err != nil { - os.Remove(f.Name()) - return n, err - } - - s.lg.Info( - "saved database snapshot to disk", - zap.String("path", fn), - zap.Int64("bytes", n), - zap.String("size", humanize.Bytes(uint64(n))), - ) - - snapDBSaveSec.Observe(time.Since(start).Seconds()) - return n, nil -} - -// DBFilePath returns the file path for the snapshot of the database with -// given id. If the snapshot does not exist, it returns error. -func (s *Snapshotter) DBFilePath(id uint64) (string, error) { - if _, err := fileutil.ReadDir(s.dir); err != nil { - return "", err - } - fn := s.dbFilePath(id) - if fileutil.Exist(fn) { - return fn, nil - } - if s.lg != nil { - s.lg.Warn( - "failed to find [SNAPSHOT-INDEX].snap.db", - zap.Uint64("snapshot-index", id), - zap.String("snapshot-file-path", fn), - zap.Error(ErrNoDBSnapshot), - ) - } - return "", ErrNoDBSnapshot -} - -func (s *Snapshotter) dbFilePath(id uint64) string { - return filepath.Join(s.dir, fmt.Sprintf("%016x.snap.db", id)) -} diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/snap/doc.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/snap/doc.go deleted file mode 100644 index dcc5db5798..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/snap/doc.go +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package snap handles Raft nodes' states with snapshots. -// The snapshot logic is internal to etcd server and raft package. -package snap diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/snap/message.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/snap/message.go deleted file mode 100644 index 523b52b85c..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/snap/message.go +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package snap - -import ( - "io" - - "go.etcd.io/etcd/pkg/v3/ioutil" - "go.etcd.io/etcd/raft/v3/raftpb" -) - -// Message is a struct that contains a raft Message and a ReadCloser. The type -// of raft message MUST be MsgSnap, which contains the raft meta-data and an -// additional data []byte field that contains the snapshot of the actual state -// machine. -// Message contains the ReadCloser field for handling large snapshot. This avoid -// copying the entire snapshot into a byte array, which consumes a lot of memory. -// -// User of Message should close the Message after sending it. -type Message struct { - raftpb.Message - ReadCloser io.ReadCloser - TotalSize int64 - closeC chan bool -} - -func NewMessage(rs raftpb.Message, rc io.ReadCloser, rcSize int64) *Message { - return &Message{ - Message: rs, - ReadCloser: ioutil.NewExactReadCloser(rc, rcSize), - TotalSize: int64(rs.Size()) + rcSize, - closeC: make(chan bool, 1), - } -} - -// CloseNotify returns a channel that receives a single value -// when the message sent is finished. true indicates the sent -// is successful. -func (m Message) CloseNotify() <-chan bool { - return m.closeC -} - -func (m Message) CloseWithError(err error) { - if cerr := m.ReadCloser.Close(); cerr != nil { - err = cerr - } - if err == nil { - m.closeC <- true - } else { - m.closeC <- false - } -} diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/snap/metrics.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/snap/metrics.go deleted file mode 100644 index 2affecf472..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/snap/metrics.go +++ /dev/null @@ -1,82 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package snap - -import "github.com/prometheus/client_golang/prometheus" - -var ( - snapMarshallingSec = prometheus.NewHistogram(prometheus.HistogramOpts{ - Namespace: "etcd_debugging", - Subsystem: "snap", - Name: "save_marshalling_duration_seconds", - Help: "The marshalling cost distributions of save called by snapshot.", - - // lowest bucket start of upper bound 0.001 sec (1 ms) with factor 2 - // highest bucket start of 0.001 sec * 2^13 == 8.192 sec - Buckets: prometheus.ExponentialBuckets(0.001, 2, 14), - }) - - snapSaveSec = prometheus.NewHistogram(prometheus.HistogramOpts{ - Namespace: "etcd_debugging", - Subsystem: "snap", - Name: "save_total_duration_seconds", - Help: "The total latency distributions of save called by snapshot.", - - // lowest bucket start of upper bound 0.001 sec (1 ms) with factor 2 - // highest bucket start of 0.001 sec * 2^13 == 8.192 sec - Buckets: prometheus.ExponentialBuckets(0.001, 2, 14), - }) - - snapFsyncSec = prometheus.NewHistogram(prometheus.HistogramOpts{ - Namespace: "etcd", - Subsystem: "snap", - Name: "fsync_duration_seconds", - Help: "The latency distributions of fsync called by snap.", - - // lowest bucket start of upper bound 0.001 sec (1 ms) with factor 2 - // highest bucket start of 0.001 sec * 2^13 == 8.192 sec - Buckets: prometheus.ExponentialBuckets(0.001, 2, 14), - }) - - snapDBSaveSec = prometheus.NewHistogram(prometheus.HistogramOpts{ - Namespace: "etcd", - Subsystem: "snap_db", - Name: "save_total_duration_seconds", - Help: "The total latency distributions of v3 snapshot save", - - // lowest bucket start of upper bound 0.1 sec (100 ms) with factor 2 - // highest bucket start of 0.1 sec * 2^9 == 51.2 sec - Buckets: prometheus.ExponentialBuckets(0.1, 2, 10), - }) - - snapDBFsyncSec = prometheus.NewHistogram(prometheus.HistogramOpts{ - Namespace: "etcd", - Subsystem: "snap_db", - Name: "fsync_duration_seconds", - Help: "The latency distributions of fsyncing .snap.db file", - - // lowest bucket start of upper bound 0.001 sec (1 ms) with factor 2 - // highest bucket start of 0.001 sec * 2^13 == 8.192 sec - Buckets: prometheus.ExponentialBuckets(0.001, 2, 14), - }) -) - -func init() { - prometheus.MustRegister(snapMarshallingSec) - prometheus.MustRegister(snapSaveSec) - prometheus.MustRegister(snapFsyncSec) - prometheus.MustRegister(snapDBSaveSec) - prometheus.MustRegister(snapDBFsyncSec) -} diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/snap/snappb/snap.pb.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/snap/snappb/snap.pb.go deleted file mode 100644 index 6fd2b9c008..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/snap/snappb/snap.pb.go +++ /dev/null @@ -1,344 +0,0 @@ -// Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: snap.proto - -package snappb - -import ( - fmt "fmt" - io "io" - math "math" - math_bits "math/bits" - - _ "github.com/gogo/protobuf/gogoproto" - proto "github.com/golang/protobuf/proto" -) - -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package - -type Snapshot struct { - Crc uint32 `protobuf:"varint,1,opt,name=crc" json:"crc"` - Data []byte `protobuf:"bytes,2,opt,name=data" json:"data,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *Snapshot) Reset() { *m = Snapshot{} } -func (m *Snapshot) String() string { return proto.CompactTextString(m) } -func (*Snapshot) ProtoMessage() {} -func (*Snapshot) Descriptor() ([]byte, []int) { - return fileDescriptor_f2e3c045ebf84d00, []int{0} -} -func (m *Snapshot) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *Snapshot) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_Snapshot.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *Snapshot) XXX_Merge(src proto.Message) { - xxx_messageInfo_Snapshot.Merge(m, src) -} -func (m *Snapshot) XXX_Size() int { - return m.Size() -} -func (m *Snapshot) XXX_DiscardUnknown() { - xxx_messageInfo_Snapshot.DiscardUnknown(m) -} - -var xxx_messageInfo_Snapshot proto.InternalMessageInfo - -func init() { - proto.RegisterType((*Snapshot)(nil), "snappb.snapshot") -} - -func init() { proto.RegisterFile("snap.proto", fileDescriptor_f2e3c045ebf84d00) } - -var fileDescriptor_f2e3c045ebf84d00 = []byte{ - // 126 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x2a, 0xce, 0x4b, 0x2c, - 0xd0, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0x03, 0xb1, 0x0b, 0x92, 0xa4, 0x44, 0xd2, 0xf3, - 0xd3, 0xf3, 0xc1, 0x42, 0xfa, 0x20, 0x16, 0x44, 0x56, 0xc9, 0x8c, 0x8b, 0x03, 0x24, 0x5f, 0x9c, - 0x91, 0x5f, 0x22, 0x24, 0xc6, 0xc5, 0x9c, 0x5c, 0x94, 0x2c, 0xc1, 0xa8, 0xc0, 0xa8, 0xc1, 0xeb, - 0xc4, 0x72, 0xe2, 0x9e, 0x3c, 0x43, 0x10, 0x48, 0x40, 0x48, 0x88, 0x8b, 0x25, 0x25, 0xb1, 0x24, - 0x51, 0x82, 0x49, 0x81, 0x51, 0x83, 0x27, 0x08, 0xcc, 0x76, 0x12, 0x39, 0xf1, 0x50, 0x8e, 0xe1, - 0xc4, 0x23, 0x39, 0xc6, 0x0b, 0x8f, 0xe4, 0x18, 0x1f, 0x3c, 0x92, 0x63, 0x9c, 0xf1, 0x58, 0x8e, - 0x01, 0x10, 0x00, 0x00, 0xff, 0xff, 0xd8, 0x0f, 0x32, 0xb2, 0x78, 0x00, 0x00, 0x00, -} - -func (m *Snapshot) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *Snapshot) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *Snapshot) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.XXX_unrecognized != nil { - i -= len(m.XXX_unrecognized) - copy(dAtA[i:], m.XXX_unrecognized) - } - if m.Data != nil { - i -= len(m.Data) - copy(dAtA[i:], m.Data) - i = encodeVarintSnap(dAtA, i, uint64(len(m.Data))) - i-- - dAtA[i] = 0x12 - } - i = encodeVarintSnap(dAtA, i, uint64(m.Crc)) - i-- - dAtA[i] = 0x8 - return len(dAtA) - i, nil -} - -func encodeVarintSnap(dAtA []byte, offset int, v uint64) int { - offset -= sovSnap(v) - base := offset - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return base -} -func (m *Snapshot) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - n += 1 + sovSnap(uint64(m.Crc)) - if m.Data != nil { - l = len(m.Data) - n += 1 + l + sovSnap(uint64(l)) - } - if m.XXX_unrecognized != nil { - n += len(m.XXX_unrecognized) - } - return n -} - -func sovSnap(x uint64) (n int) { - return (math_bits.Len64(x|1) + 6) / 7 -} -func sozSnap(x uint64) (n int) { - return sovSnap(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} -func (m *Snapshot) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowSnap - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: snapshot: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: snapshot: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Crc", wireType) - } - m.Crc = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowSnap - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Crc |= uint32(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Data", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowSnap - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthSnap - } - postIndex := iNdEx + byteLen - if postIndex < 0 { - return ErrInvalidLengthSnap - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Data = append(m.Data[:0], dAtA[iNdEx:postIndex]...) - if m.Data == nil { - m.Data = []byte{} - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipSnap(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthSnap - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func skipSnap(dAtA []byte) (n int, err error) { - l := len(dAtA) - iNdEx := 0 - depth := 0 - for iNdEx < l { - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowSnap - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - wireType := int(wire & 0x7) - switch wireType { - case 0: - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowSnap - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - iNdEx++ - if dAtA[iNdEx-1] < 0x80 { - break - } - } - case 1: - iNdEx += 8 - case 2: - var length int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowSnap - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - length |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if length < 0 { - return 0, ErrInvalidLengthSnap - } - iNdEx += length - case 3: - depth++ - case 4: - if depth == 0 { - return 0, ErrUnexpectedEndOfGroupSnap - } - depth-- - case 5: - iNdEx += 4 - default: - return 0, fmt.Errorf("proto: illegal wireType %d", wireType) - } - if iNdEx < 0 { - return 0, ErrInvalidLengthSnap - } - if depth == 0 { - return iNdEx, nil - } - } - return 0, io.ErrUnexpectedEOF -} - -var ( - ErrInvalidLengthSnap = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowSnap = fmt.Errorf("proto: integer overflow") - ErrUnexpectedEndOfGroupSnap = fmt.Errorf("proto: unexpected end of group") -) diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/snap/snappb/snap.proto b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/snap/snappb/snap.proto deleted file mode 100644 index cd3d21d0ee..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/snap/snappb/snap.proto +++ /dev/null @@ -1,14 +0,0 @@ -syntax = "proto2"; -package snappb; - -import "gogoproto/gogo.proto"; - -option (gogoproto.marshaler_all) = true; -option (gogoproto.sizer_all) = true; -option (gogoproto.unmarshaler_all) = true; -option (gogoproto.goproto_getters_all) = false; - -message snapshot { - optional uint32 crc = 1 [(gogoproto.nullable) = false]; - optional bytes data = 2; -} diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/snap/snapshotter.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/snap/snapshotter.go deleted file mode 100644 index 52cc0ae267..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/snap/snapshotter.go +++ /dev/null @@ -1,301 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package snap - -import ( - "errors" - "fmt" - "hash/crc32" - "io/ioutil" - "os" - "path/filepath" - "sort" - "strconv" - "strings" - "time" - - pioutil "go.etcd.io/etcd/pkg/v3/ioutil" - "go.etcd.io/etcd/pkg/v3/pbutil" - "go.etcd.io/etcd/raft/v3" - "go.etcd.io/etcd/raft/v3/raftpb" - "go.etcd.io/etcd/server/v3/etcdserver/api/snap/snappb" - "go.etcd.io/etcd/server/v3/wal/walpb" - - "go.uber.org/zap" -) - -const snapSuffix = ".snap" - -var ( - ErrNoSnapshot = errors.New("snap: no available snapshot") - ErrEmptySnapshot = errors.New("snap: empty snapshot") - ErrCRCMismatch = errors.New("snap: crc mismatch") - crcTable = crc32.MakeTable(crc32.Castagnoli) - - // A map of valid files that can be present in the snap folder. - validFiles = map[string]bool{ - "db": true, - } -) - -type Snapshotter struct { - lg *zap.Logger - dir string -} - -func New(lg *zap.Logger, dir string) *Snapshotter { - if lg == nil { - lg = zap.NewNop() - } - return &Snapshotter{ - lg: lg, - dir: dir, - } -} - -func (s *Snapshotter) SaveSnap(snapshot raftpb.Snapshot) error { - if raft.IsEmptySnap(snapshot) { - return nil - } - return s.save(&snapshot) -} - -func (s *Snapshotter) save(snapshot *raftpb.Snapshot) error { - start := time.Now() - - fname := fmt.Sprintf("%016x-%016x%s", snapshot.Metadata.Term, snapshot.Metadata.Index, snapSuffix) - b := pbutil.MustMarshal(snapshot) - crc := crc32.Update(0, crcTable, b) - snap := snappb.Snapshot{Crc: crc, Data: b} - d, err := snap.Marshal() - if err != nil { - return err - } - snapMarshallingSec.Observe(time.Since(start).Seconds()) - - spath := filepath.Join(s.dir, fname) - - fsyncStart := time.Now() - err = pioutil.WriteAndSyncFile(spath, d, 0666) - snapFsyncSec.Observe(time.Since(fsyncStart).Seconds()) - - if err != nil { - s.lg.Warn("failed to write a snap file", zap.String("path", spath), zap.Error(err)) - rerr := os.Remove(spath) - if rerr != nil { - s.lg.Warn("failed to remove a broken snap file", zap.String("path", spath), zap.Error(err)) - } - return err - } - - snapSaveSec.Observe(time.Since(start).Seconds()) - return nil -} - -// Load returns the newest snapshot. -func (s *Snapshotter) Load() (*raftpb.Snapshot, error) { - return s.loadMatching(func(*raftpb.Snapshot) bool { return true }) -} - -// LoadNewestAvailable loads the newest snapshot available that is in walSnaps. -func (s *Snapshotter) LoadNewestAvailable(walSnaps []walpb.Snapshot) (*raftpb.Snapshot, error) { - return s.loadMatching(func(snapshot *raftpb.Snapshot) bool { - m := snapshot.Metadata - for i := len(walSnaps) - 1; i >= 0; i-- { - if m.Term == walSnaps[i].Term && m.Index == walSnaps[i].Index { - return true - } - } - return false - }) -} - -// loadMatching returns the newest snapshot where matchFn returns true. -func (s *Snapshotter) loadMatching(matchFn func(*raftpb.Snapshot) bool) (*raftpb.Snapshot, error) { - names, err := s.snapNames() - if err != nil { - return nil, err - } - var snap *raftpb.Snapshot - for _, name := range names { - if snap, err = loadSnap(s.lg, s.dir, name); err == nil && matchFn(snap) { - return snap, nil - } - } - return nil, ErrNoSnapshot -} - -func loadSnap(lg *zap.Logger, dir, name string) (*raftpb.Snapshot, error) { - fpath := filepath.Join(dir, name) - snap, err := Read(lg, fpath) - if err != nil { - brokenPath := fpath + ".broken" - if lg != nil { - lg.Warn("failed to read a snap file", zap.String("path", fpath), zap.Error(err)) - } - if rerr := os.Rename(fpath, brokenPath); rerr != nil { - if lg != nil { - lg.Warn("failed to rename a broken snap file", zap.String("path", fpath), zap.String("broken-path", brokenPath), zap.Error(rerr)) - } - } else { - if lg != nil { - lg.Warn("renamed to a broken snap file", zap.String("path", fpath), zap.String("broken-path", brokenPath)) - } - } - } - return snap, err -} - -// Read reads the snapshot named by snapname and returns the snapshot. -func Read(lg *zap.Logger, snapname string) (*raftpb.Snapshot, error) { - b, err := ioutil.ReadFile(snapname) - if err != nil { - if lg != nil { - lg.Warn("failed to read a snap file", zap.String("path", snapname), zap.Error(err)) - } - return nil, err - } - - if len(b) == 0 { - if lg != nil { - lg.Warn("failed to read empty snapshot file", zap.String("path", snapname)) - } - return nil, ErrEmptySnapshot - } - - var serializedSnap snappb.Snapshot - if err = serializedSnap.Unmarshal(b); err != nil { - if lg != nil { - lg.Warn("failed to unmarshal snappb.Snapshot", zap.String("path", snapname), zap.Error(err)) - } - return nil, err - } - - if len(serializedSnap.Data) == 0 || serializedSnap.Crc == 0 { - if lg != nil { - lg.Warn("failed to read empty snapshot data", zap.String("path", snapname)) - } - return nil, ErrEmptySnapshot - } - - crc := crc32.Update(0, crcTable, serializedSnap.Data) - if crc != serializedSnap.Crc { - if lg != nil { - lg.Warn("snap file is corrupt", - zap.String("path", snapname), - zap.Uint32("prev-crc", serializedSnap.Crc), - zap.Uint32("new-crc", crc), - ) - } - return nil, ErrCRCMismatch - } - - var snap raftpb.Snapshot - if err = snap.Unmarshal(serializedSnap.Data); err != nil { - if lg != nil { - lg.Warn("failed to unmarshal raftpb.Snapshot", zap.String("path", snapname), zap.Error(err)) - } - return nil, err - } - return &snap, nil -} - -// snapNames returns the filename of the snapshots in logical time order (from newest to oldest). -// If there is no available snapshots, an ErrNoSnapshot will be returned. -func (s *Snapshotter) snapNames() ([]string, error) { - dir, err := os.Open(s.dir) - if err != nil { - return nil, err - } - defer dir.Close() - names, err := dir.Readdirnames(-1) - if err != nil { - return nil, err - } - filenames, err := s.cleanupSnapdir(names) - if err != nil { - return nil, err - } - snaps := checkSuffix(s.lg, filenames) - if len(snaps) == 0 { - return nil, ErrNoSnapshot - } - sort.Sort(sort.Reverse(sort.StringSlice(snaps))) - return snaps, nil -} - -func checkSuffix(lg *zap.Logger, names []string) []string { - snaps := []string{} - for i := range names { - if strings.HasSuffix(names[i], snapSuffix) { - snaps = append(snaps, names[i]) - } else { - // If we find a file which is not a snapshot then check if it's - // a vaild file. If not throw out a warning. - if _, ok := validFiles[names[i]]; !ok { - if lg != nil { - lg.Warn("found unexpected non-snap file; skipping", zap.String("path", names[i])) - } - } - } - } - return snaps -} - -// cleanupSnapdir removes any files that should not be in the snapshot directory: -// - db.tmp prefixed files that can be orphaned by defragmentation -func (s *Snapshotter) cleanupSnapdir(filenames []string) (names []string, err error) { - names = make([]string, 0, len(filenames)) - for _, filename := range filenames { - if strings.HasPrefix(filename, "db.tmp") { - s.lg.Info("found orphaned defragmentation file; deleting", zap.String("path", filename)) - if rmErr := os.Remove(filepath.Join(s.dir, filename)); rmErr != nil && !os.IsNotExist(rmErr) { - return names, fmt.Errorf("failed to remove orphaned .snap.db file %s: %v", filename, rmErr) - } - } else { - names = append(names, filename) - } - } - return names, nil -} - -func (s *Snapshotter) ReleaseSnapDBs(snap raftpb.Snapshot) error { - dir, err := os.Open(s.dir) - if err != nil { - return err - } - defer dir.Close() - filenames, err := dir.Readdirnames(-1) - if err != nil { - return err - } - for _, filename := range filenames { - if strings.HasSuffix(filename, ".snap.db") { - hexIndex := strings.TrimSuffix(filepath.Base(filename), ".snap.db") - index, err := strconv.ParseUint(hexIndex, 16, 64) - if err != nil { - s.lg.Error("failed to parse index from filename", zap.String("path", filename), zap.String("error", err.Error())) - continue - } - if index < snap.Metadata.Index { - s.lg.Info("found orphaned .snap.db file; deleting", zap.String("path", filename)) - if rmErr := os.Remove(filepath.Join(s.dir, filename)); rmErr != nil && !os.IsNotExist(rmErr) { - s.lg.Error("failed to remove orphaned .snap.db file", zap.String("path", filename), zap.String("error", rmErr.Error())) - } - } - } - } - return nil -} diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2auth/auth.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2auth/auth.go deleted file mode 100644 index e76ee8b2a1..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2auth/auth.go +++ /dev/null @@ -1,670 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package v2auth implements etcd authentication. -package v2auth - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - "path" - "reflect" - "sort" - "strings" - "time" - - "go.etcd.io/etcd/api/v3/etcdserverpb" - "go.etcd.io/etcd/client/pkg/v3/types" - "go.etcd.io/etcd/server/v3/etcdserver" - "go.etcd.io/etcd/server/v3/etcdserver/api/v2error" - - "go.uber.org/zap" - "golang.org/x/crypto/bcrypt" -) - -const ( - // StorePermsPrefix is the internal prefix of the storage layer dedicated to storing user data. - StorePermsPrefix = "/2" - - // RootRoleName is the name of the ROOT role, with privileges to manage the cluster. - RootRoleName = "root" - - // GuestRoleName is the name of the role that defines the privileges of an unauthenticated user. - GuestRoleName = "guest" -) - -var rootRole = Role{ - Role: RootRoleName, - Permissions: Permissions{ - KV: RWPermission{ - Read: []string{"/*"}, - Write: []string{"/*"}, - }, - }, -} - -var guestRole = Role{ - Role: GuestRoleName, - Permissions: Permissions{ - KV: RWPermission{ - Read: []string{"/*"}, - Write: []string{"/*"}, - }, - }, -} - -type doer interface { - Do(context.Context, etcdserverpb.Request) (etcdserver.Response, error) -} - -type Store interface { - AllUsers() ([]string, error) - GetUser(name string) (User, error) - CreateOrUpdateUser(user User) (out User, created bool, err error) - CreateUser(user User) (User, error) - DeleteUser(name string) error - UpdateUser(user User) (User, error) - AllRoles() ([]string, error) - GetRole(name string) (Role, error) - CreateRole(role Role) error - DeleteRole(name string) error - UpdateRole(role Role) (Role, error) - AuthEnabled() bool - EnableAuth() error - DisableAuth() error - PasswordStore -} - -type PasswordStore interface { - CheckPassword(user User, password string) bool - HashPassword(password string) (string, error) -} - -type store struct { - lg *zap.Logger - server doer - timeout time.Duration - ensuredOnce bool - - PasswordStore -} - -type User struct { - User string `json:"user"` - Password string `json:"password,omitempty"` - Roles []string `json:"roles"` - Grant []string `json:"grant,omitempty"` - Revoke []string `json:"revoke,omitempty"` -} - -type Role struct { - Role string `json:"role"` - Permissions Permissions `json:"permissions"` - Grant *Permissions `json:"grant,omitempty"` - Revoke *Permissions `json:"revoke,omitempty"` -} - -type Permissions struct { - KV RWPermission `json:"kv"` -} - -func (p *Permissions) IsEmpty() bool { - return p == nil || (len(p.KV.Read) == 0 && len(p.KV.Write) == 0) -} - -type RWPermission struct { - Read []string `json:"read"` - Write []string `json:"write"` -} - -type Error struct { - Status int - Errmsg string -} - -func (ae Error) Error() string { return ae.Errmsg } -func (ae Error) HTTPStatus() int { return ae.Status } - -func authErr(hs int, s string, v ...interface{}) Error { - return Error{Status: hs, Errmsg: fmt.Sprintf("auth: "+s, v...)} -} - -func NewStore(lg *zap.Logger, server doer, timeout time.Duration) Store { - if lg == nil { - lg = zap.NewNop() - } - s := &store{ - lg: lg, - server: server, - timeout: timeout, - PasswordStore: passwordStore{}, - } - return s -} - -// passwordStore implements PasswordStore using bcrypt to hash user passwords -type passwordStore struct{} - -func (passwordStore) CheckPassword(user User, password string) bool { - err := bcrypt.CompareHashAndPassword([]byte(user.Password), []byte(password)) - return err == nil -} - -func (passwordStore) HashPassword(password string) (string, error) { - hash, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost) - return string(hash), err -} - -func (s *store) AllUsers() ([]string, error) { - resp, err := s.requestResource("/users/", false) - if err != nil { - if e, ok := err.(*v2error.Error); ok { - if e.ErrorCode == v2error.EcodeKeyNotFound { - return []string{}, nil - } - } - return nil, err - } - var nodes []string - for _, n := range resp.Event.Node.Nodes { - _, user := path.Split(n.Key) - nodes = append(nodes, user) - } - sort.Strings(nodes) - return nodes, nil -} - -func (s *store) GetUser(name string) (User, error) { return s.getUser(name, false) } - -// CreateOrUpdateUser should be only used for creating the new user or when you are not -// sure if it is a create or update. (When only password is passed in, we are not sure -// if it is a update or create) -func (s *store) CreateOrUpdateUser(user User) (out User, created bool, err error) { - _, err = s.getUser(user.User, true) - if err == nil { - out, err = s.UpdateUser(user) - return out, false, err - } - u, err := s.CreateUser(user) - return u, true, err -} - -func (s *store) CreateUser(user User) (User, error) { - // Attach root role to root user. - if user.User == "root" { - user = attachRootRole(user) - } - u, err := s.createUserInternal(user) - if err == nil { - s.lg.Info("created a user", zap.String("user-name", user.User)) - } - return u, err -} - -func (s *store) createUserInternal(user User) (User, error) { - if user.Password == "" { - return user, authErr(http.StatusBadRequest, "Cannot create user %s with an empty password", user.User) - } - hash, err := s.HashPassword(user.Password) - if err != nil { - return user, err - } - user.Password = hash - - _, err = s.createResource("/users/"+user.User, user) - if err != nil { - if e, ok := err.(*v2error.Error); ok { - if e.ErrorCode == v2error.EcodeNodeExist { - return user, authErr(http.StatusConflict, "User %s already exists.", user.User) - } - } - } - return user, err -} - -func (s *store) DeleteUser(name string) error { - if s.AuthEnabled() && name == "root" { - return authErr(http.StatusForbidden, "Cannot delete root user while auth is enabled.") - } - err := s.deleteResource("/users/" + name) - if err != nil { - if e, ok := err.(*v2error.Error); ok { - if e.ErrorCode == v2error.EcodeKeyNotFound { - return authErr(http.StatusNotFound, "User %s does not exist", name) - } - } - return err - } - s.lg.Info("deleted a user", zap.String("user-name", name)) - return nil -} - -func (s *store) UpdateUser(user User) (User, error) { - old, err := s.getUser(user.User, true) - if err != nil { - if e, ok := err.(*v2error.Error); ok { - if e.ErrorCode == v2error.EcodeKeyNotFound { - return user, authErr(http.StatusNotFound, "User %s doesn't exist.", user.User) - } - } - return old, err - } - - newUser, err := old.merge(s.lg, user, s.PasswordStore) - if err != nil { - return old, err - } - if reflect.DeepEqual(old, newUser) { - return old, authErr(http.StatusBadRequest, "User not updated. Use grant/revoke/password to update the user.") - } - _, err = s.updateResource("/users/"+user.User, newUser) - if err == nil { - s.lg.Info("updated a user", zap.String("user-name", user.User)) - } - return newUser, err -} - -func (s *store) AllRoles() ([]string, error) { - nodes := []string{RootRoleName} - resp, err := s.requestResource("/roles/", false) - if err != nil { - if e, ok := err.(*v2error.Error); ok { - if e.ErrorCode == v2error.EcodeKeyNotFound { - return nodes, nil - } - } - return nil, err - } - for _, n := range resp.Event.Node.Nodes { - _, role := path.Split(n.Key) - nodes = append(nodes, role) - } - sort.Strings(nodes) - return nodes, nil -} - -func (s *store) GetRole(name string) (Role, error) { return s.getRole(name, false) } - -func (s *store) CreateRole(role Role) error { - if role.Role == RootRoleName { - return authErr(http.StatusForbidden, "Cannot modify role %s: is root role.", role.Role) - } - _, err := s.createResource("/roles/"+role.Role, role) - if err != nil { - if e, ok := err.(*v2error.Error); ok { - if e.ErrorCode == v2error.EcodeNodeExist { - return authErr(http.StatusConflict, "Role %s already exists.", role.Role) - } - } - } - if err == nil { - s.lg.Info("created a new role", zap.String("role-name", role.Role)) - } - return err -} - -func (s *store) DeleteRole(name string) error { - if name == RootRoleName { - return authErr(http.StatusForbidden, "Cannot modify role %s: is root role.", name) - } - err := s.deleteResource("/roles/" + name) - if err != nil { - if e, ok := err.(*v2error.Error); ok { - if e.ErrorCode == v2error.EcodeKeyNotFound { - return authErr(http.StatusNotFound, "Role %s doesn't exist.", name) - } - } - } - if err == nil { - s.lg.Info("delete a new role", zap.String("role-name", name)) - } - return err -} - -func (s *store) UpdateRole(role Role) (Role, error) { - if role.Role == RootRoleName { - return Role{}, authErr(http.StatusForbidden, "Cannot modify role %s: is root role.", role.Role) - } - old, err := s.getRole(role.Role, true) - if err != nil { - if e, ok := err.(*v2error.Error); ok { - if e.ErrorCode == v2error.EcodeKeyNotFound { - return role, authErr(http.StatusNotFound, "Role %s doesn't exist.", role.Role) - } - } - return old, err - } - newRole, err := old.merge(s.lg, role) - if err != nil { - return old, err - } - if reflect.DeepEqual(old, newRole) { - return old, authErr(http.StatusBadRequest, "Role not updated. Use grant/revoke to update the role.") - } - _, err = s.updateResource("/roles/"+role.Role, newRole) - if err == nil { - s.lg.Info("updated a new role", zap.String("role-name", role.Role)) - } - return newRole, err -} - -func (s *store) AuthEnabled() bool { - return s.detectAuth() -} - -func (s *store) EnableAuth() error { - if s.AuthEnabled() { - return authErr(http.StatusConflict, "already enabled") - } - - if _, err := s.getUser("root", true); err != nil { - return authErr(http.StatusConflict, "No root user available, please create one") - } - if _, err := s.getRole(GuestRoleName, true); err != nil { - s.lg.Info( - "no guest role access found; creating default", - zap.String("role-name", GuestRoleName), - ) - if err := s.CreateRole(guestRole); err != nil { - s.lg.Warn( - "failed to create a guest role; aborting auth enable", - zap.String("role-name", GuestRoleName), - zap.Error(err), - ) - return err - } - } - - if err := s.enableAuth(); err != nil { - s.lg.Warn("failed to enable auth", zap.Error(err)) - return err - } - - s.lg.Info("enabled auth") - return nil -} - -func (s *store) DisableAuth() error { - if !s.AuthEnabled() { - return authErr(http.StatusConflict, "already disabled") - } - - err := s.disableAuth() - if err == nil { - s.lg.Info("disabled auth") - } else { - s.lg.Warn("failed to disable auth", zap.Error(err)) - } - return err -} - -// merge applies the properties of the passed-in User to the User on which it -// is called and returns a new User with these modifications applied. Think of -// all Users as immutable sets of data. Merge allows you to perform the set -// operations (desired grants and revokes) atomically -func (ou User) merge(lg *zap.Logger, nu User, s PasswordStore) (User, error) { - var out User - if ou.User != nu.User { - return out, authErr(http.StatusConflict, "Merging user data with conflicting usernames: %s %s", ou.User, nu.User) - } - out.User = ou.User - if nu.Password != "" { - hash, err := s.HashPassword(nu.Password) - if err != nil { - return ou, err - } - out.Password = hash - } else { - out.Password = ou.Password - } - currentRoles := types.NewUnsafeSet(ou.Roles...) - for _, g := range nu.Grant { - if currentRoles.Contains(g) { - lg.Warn( - "attempted to grant a duplicate role for a user", - zap.String("user-name", nu.User), - zap.String("role-name", g), - ) - return User{}, authErr(http.StatusConflict, fmt.Sprintf("Granting duplicate role %s for user %s", g, nu.User)) - } - currentRoles.Add(g) - } - for _, r := range nu.Revoke { - if !currentRoles.Contains(r) { - lg.Warn( - "attempted to revoke a ungranted role for a user", - zap.String("user-name", nu.User), - zap.String("role-name", r), - ) - return User{}, authErr(http.StatusConflict, fmt.Sprintf("Revoking ungranted role %s for user %s", r, nu.User)) - } - currentRoles.Remove(r) - } - out.Roles = currentRoles.Values() - sort.Strings(out.Roles) - return out, nil -} - -// merge for a role works the same as User above -- atomic Role application to -// each of the substructures. -func (r Role) merge(lg *zap.Logger, n Role) (Role, error) { - var out Role - var err error - if r.Role != n.Role { - return out, authErr(http.StatusConflict, "Merging role with conflicting names: %s %s", r.Role, n.Role) - } - out.Role = r.Role - out.Permissions, err = r.Permissions.Grant(n.Grant) - if err != nil { - return out, err - } - out.Permissions, err = out.Permissions.Revoke(lg, n.Revoke) - return out, err -} - -func (r Role) HasKeyAccess(key string, write bool) bool { - if r.Role == RootRoleName { - return true - } - return r.Permissions.KV.HasAccess(key, write) -} - -func (r Role) HasRecursiveAccess(key string, write bool) bool { - if r.Role == RootRoleName { - return true - } - return r.Permissions.KV.HasRecursiveAccess(key, write) -} - -// Grant adds a set of permissions to the permission object on which it is called, -// returning a new permission object. -func (p Permissions) Grant(n *Permissions) (Permissions, error) { - var out Permissions - var err error - if n == nil { - return p, nil - } - out.KV, err = p.KV.Grant(n.KV) - return out, err -} - -// Revoke removes a set of permissions to the permission object on which it is called, -// returning a new permission object. -func (p Permissions) Revoke(lg *zap.Logger, n *Permissions) (Permissions, error) { - var out Permissions - var err error - if n == nil { - return p, nil - } - out.KV, err = p.KV.Revoke(lg, n.KV) - return out, err -} - -// Grant adds a set of permissions to the permission object on which it is called, -// returning a new permission object. -func (rw RWPermission) Grant(n RWPermission) (RWPermission, error) { - var out RWPermission - currentRead := types.NewUnsafeSet(rw.Read...) - for _, r := range n.Read { - if currentRead.Contains(r) { - return out, authErr(http.StatusConflict, "Granting duplicate read permission %s", r) - } - currentRead.Add(r) - } - currentWrite := types.NewUnsafeSet(rw.Write...) - for _, w := range n.Write { - if currentWrite.Contains(w) { - return out, authErr(http.StatusConflict, "Granting duplicate write permission %s", w) - } - currentWrite.Add(w) - } - out.Read = currentRead.Values() - out.Write = currentWrite.Values() - sort.Strings(out.Read) - sort.Strings(out.Write) - return out, nil -} - -// Revoke removes a set of permissions to the permission object on which it is called, -// returning a new permission object. -func (rw RWPermission) Revoke(lg *zap.Logger, n RWPermission) (RWPermission, error) { - var out RWPermission - currentRead := types.NewUnsafeSet(rw.Read...) - for _, r := range n.Read { - if !currentRead.Contains(r) { - lg.Info( - "revoking ungranted read permission", - zap.String("read-permission", r), - ) - continue - } - currentRead.Remove(r) - } - currentWrite := types.NewUnsafeSet(rw.Write...) - for _, w := range n.Write { - if !currentWrite.Contains(w) { - lg.Info( - "revoking ungranted write permission", - zap.String("write-permission", w), - ) - continue - } - currentWrite.Remove(w) - } - out.Read = currentRead.Values() - out.Write = currentWrite.Values() - sort.Strings(out.Read) - sort.Strings(out.Write) - return out, nil -} - -func (rw RWPermission) HasAccess(key string, write bool) bool { - var list []string - if write { - list = rw.Write - } else { - list = rw.Read - } - for _, pat := range list { - match, err := simpleMatch(pat, key) - if err == nil && match { - return true - } - } - return false -} - -func (rw RWPermission) HasRecursiveAccess(key string, write bool) bool { - list := rw.Read - if write { - list = rw.Write - } - for _, pat := range list { - match, err := prefixMatch(pat, key) - if err == nil && match { - return true - } - } - return false -} - -func simpleMatch(pattern string, key string) (match bool, err error) { - if pattern[len(pattern)-1] == '*' { - return strings.HasPrefix(key, pattern[:len(pattern)-1]), nil - } - return key == pattern, nil -} - -func prefixMatch(pattern string, key string) (match bool, err error) { - if pattern[len(pattern)-1] != '*' { - return false, nil - } - return strings.HasPrefix(key, pattern[:len(pattern)-1]), nil -} - -func attachRootRole(u User) User { - inRoles := false - for _, r := range u.Roles { - if r == RootRoleName { - inRoles = true - break - } - } - if !inRoles { - u.Roles = append(u.Roles, RootRoleName) - } - return u -} - -func (s *store) getUser(name string, quorum bool) (User, error) { - resp, err := s.requestResource("/users/"+name, quorum) - if err != nil { - if e, ok := err.(*v2error.Error); ok { - if e.ErrorCode == v2error.EcodeKeyNotFound { - return User{}, authErr(http.StatusNotFound, "User %s does not exist.", name) - } - } - return User{}, err - } - var u User - err = json.Unmarshal([]byte(*resp.Event.Node.Value), &u) - if err != nil { - return u, err - } - // Attach root role to root user. - if u.User == "root" { - u = attachRootRole(u) - } - return u, nil -} - -func (s *store) getRole(name string, quorum bool) (Role, error) { - if name == RootRoleName { - return rootRole, nil - } - resp, err := s.requestResource("/roles/"+name, quorum) - if err != nil { - if e, ok := err.(*v2error.Error); ok { - if e.ErrorCode == v2error.EcodeKeyNotFound { - return Role{}, authErr(http.StatusNotFound, "Role %s does not exist.", name) - } - } - return Role{}, err - } - var r Role - err = json.Unmarshal([]byte(*resp.Event.Node.Value), &r) - return r, err -} diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2auth/auth_requests.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2auth/auth_requests.go deleted file mode 100644 index 6c8c50c8cc..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2auth/auth_requests.go +++ /dev/null @@ -1,177 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package v2auth - -import ( - "context" - "encoding/json" - "path" - - "go.etcd.io/etcd/api/v3/etcdserverpb" - "go.etcd.io/etcd/server/v3/etcdserver" - "go.etcd.io/etcd/server/v3/etcdserver/api/v2error" - - "go.uber.org/zap" -) - -func (s *store) ensureAuthDirectories() error { - if s.ensuredOnce { - return nil - } - for _, res := range []string{StorePermsPrefix, StorePermsPrefix + "/users/", StorePermsPrefix + "/roles/"} { - ctx, cancel := context.WithTimeout(context.Background(), s.timeout) - pe := false - rr := etcdserverpb.Request{ - Method: "PUT", - Path: res, - Dir: true, - PrevExist: &pe, - } - _, err := s.server.Do(ctx, rr) - cancel() - if err != nil { - if e, ok := err.(*v2error.Error); ok { - if e.ErrorCode == v2error.EcodeNodeExist { - continue - } - } - s.lg.Warn( - "failed to create auth directories", - zap.Error(err), - ) - return err - } - } - ctx, cancel := context.WithTimeout(context.Background(), s.timeout) - defer cancel() - pe := false - rr := etcdserverpb.Request{ - Method: "PUT", - Path: StorePermsPrefix + "/enabled", - Val: "false", - PrevExist: &pe, - } - _, err := s.server.Do(ctx, rr) - if err != nil { - if e, ok := err.(*v2error.Error); ok { - if e.ErrorCode == v2error.EcodeNodeExist { - s.ensuredOnce = true - return nil - } - } - return err - } - s.ensuredOnce = true - return nil -} - -func (s *store) enableAuth() error { - _, err := s.updateResource("/enabled", true) - return err -} -func (s *store) disableAuth() error { - _, err := s.updateResource("/enabled", false) - return err -} - -func (s *store) detectAuth() bool { - if s.server == nil { - return false - } - value, err := s.requestResource("/enabled", false) - if err != nil { - if e, ok := err.(*v2error.Error); ok { - if e.ErrorCode == v2error.EcodeKeyNotFound { - return false - } - } - s.lg.Warn( - "failed to detect auth settings", - zap.Error(err), - ) - return false - } - - var u bool - err = json.Unmarshal([]byte(*value.Event.Node.Value), &u) - if err != nil { - s.lg.Warn( - "internal bookkeeping value for enabled isn't valid JSON", - zap.Error(err), - ) - return false - } - return u -} - -func (s *store) requestResource(res string, quorum bool) (etcdserver.Response, error) { - ctx, cancel := context.WithTimeout(context.Background(), s.timeout) - defer cancel() - p := path.Join(StorePermsPrefix, res) - method := "GET" - if quorum { - method = "QGET" - } - rr := etcdserverpb.Request{ - Method: method, - Path: p, - Dir: false, // TODO: always false? - } - return s.server.Do(ctx, rr) -} - -func (s *store) updateResource(res string, value interface{}) (etcdserver.Response, error) { - return s.setResource(res, value, true) -} -func (s *store) createResource(res string, value interface{}) (etcdserver.Response, error) { - return s.setResource(res, value, false) -} -func (s *store) setResource(res string, value interface{}, prevexist bool) (etcdserver.Response, error) { - err := s.ensureAuthDirectories() - if err != nil { - return etcdserver.Response{}, err - } - ctx, cancel := context.WithTimeout(context.Background(), s.timeout) - defer cancel() - data, err := json.Marshal(value) - if err != nil { - return etcdserver.Response{}, err - } - p := path.Join(StorePermsPrefix, res) - rr := etcdserverpb.Request{ - Method: "PUT", - Path: p, - Val: string(data), - PrevExist: &prevexist, - } - return s.server.Do(ctx, rr) -} - -func (s *store) deleteResource(res string) error { - err := s.ensureAuthDirectories() - if err != nil { - return err - } - ctx, cancel := context.WithTimeout(context.Background(), s.timeout) - defer cancel() - pex := true - p := path.Join(StorePermsPrefix, res) - _, err = s.server.Do(ctx, etcdserverpb.Request{ - Method: "DELETE", - Path: p, - PrevExist: &pex, - }) - return err -} diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2discovery/discovery.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2discovery/discovery.go deleted file mode 100644 index 9f1bc0adf5..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2discovery/discovery.go +++ /dev/null @@ -1,412 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package v2discovery provides an implementation of the cluster discovery that -// is used by etcd with v2 client. -package v2discovery - -import ( - "context" - "errors" - "fmt" - "math" - "net/http" - "net/url" - "path" - "sort" - "strconv" - "strings" - "time" - - "go.etcd.io/etcd/client/pkg/v3/transport" - "go.etcd.io/etcd/client/pkg/v3/types" - "go.etcd.io/etcd/client/v2" - - "github.com/jonboulle/clockwork" - "go.uber.org/zap" -) - -var ( - ErrInvalidURL = errors.New("discovery: invalid URL") - ErrBadSizeKey = errors.New("discovery: size key is bad") - ErrSizeNotFound = errors.New("discovery: size key not found") - ErrTokenNotFound = errors.New("discovery: token not found") - ErrDuplicateID = errors.New("discovery: found duplicate id") - ErrDuplicateName = errors.New("discovery: found duplicate name") - ErrFullCluster = errors.New("discovery: cluster is full") - ErrTooManyRetries = errors.New("discovery: too many retries") - ErrBadDiscoveryEndpoint = errors.New("discovery: bad discovery endpoint") -) - -var ( - // Number of retries discovery will attempt before giving up and erroring out. - nRetries = uint(math.MaxUint32) - maxExpoentialRetries = uint(8) -) - -// JoinCluster will connect to the discovery service at the given url, and -// register the server represented by the given id and config to the cluster -func JoinCluster(lg *zap.Logger, durl, dproxyurl string, id types.ID, config string) (string, error) { - d, err := newDiscovery(lg, durl, dproxyurl, id) - if err != nil { - return "", err - } - return d.joinCluster(config) -} - -// GetCluster will connect to the discovery service at the given url and -// retrieve a string describing the cluster -func GetCluster(lg *zap.Logger, durl, dproxyurl string) (string, error) { - d, err := newDiscovery(lg, durl, dproxyurl, 0) - if err != nil { - return "", err - } - return d.getCluster() -} - -type discovery struct { - lg *zap.Logger - cluster string - id types.ID - c client.KeysAPI - retries uint - url *url.URL - - clock clockwork.Clock -} - -// newProxyFunc builds a proxy function from the given string, which should -// represent a URL that can be used as a proxy. It performs basic -// sanitization of the URL and returns any error encountered. -func newProxyFunc(lg *zap.Logger, proxy string) (func(*http.Request) (*url.URL, error), error) { - if lg == nil { - lg = zap.NewNop() - } - if proxy == "" { - return nil, nil - } - // Do a small amount of URL sanitization to help the user - // Derived from net/http.ProxyFromEnvironment - proxyURL, err := url.Parse(proxy) - if err != nil || !strings.HasPrefix(proxyURL.Scheme, "http") { - // proxy was bogus. Try prepending "http://" to it and - // see if that parses correctly. If not, we ignore the - // error and complain about the original one - var err2 error - proxyURL, err2 = url.Parse("http://" + proxy) - if err2 == nil { - err = nil - } - } - if err != nil { - return nil, fmt.Errorf("invalid proxy address %q: %v", proxy, err) - } - - lg.Info("running proxy with discovery", zap.String("proxy-url", proxyURL.String())) - return http.ProxyURL(proxyURL), nil -} - -func newDiscovery(lg *zap.Logger, durl, dproxyurl string, id types.ID) (*discovery, error) { - if lg == nil { - lg = zap.NewNop() - } - u, err := url.Parse(durl) - if err != nil { - return nil, err - } - token := u.Path - u.Path = "" - pf, err := newProxyFunc(lg, dproxyurl) - if err != nil { - return nil, err - } - - // TODO: add ResponseHeaderTimeout back when watch on discovery service writes header early - tr, err := transport.NewTransport(transport.TLSInfo{}, 30*time.Second) - if err != nil { - return nil, err - } - tr.Proxy = pf - cfg := client.Config{ - Transport: tr, - Endpoints: []string{u.String()}, - } - c, err := client.New(cfg) - if err != nil { - return nil, err - } - dc := client.NewKeysAPIWithPrefix(c, "") - return &discovery{ - lg: lg, - cluster: token, - c: dc, - id: id, - url: u, - clock: clockwork.NewRealClock(), - }, nil -} - -func (d *discovery) joinCluster(config string) (string, error) { - // fast path: if the cluster is full, return the error - // do not need to register to the cluster in this case. - if _, _, _, err := d.checkCluster(); err != nil { - return "", err - } - - if err := d.createSelf(config); err != nil { - // Fails, even on a timeout, if createSelf times out. - // TODO(barakmich): Retrying the same node might want to succeed here - // (ie, createSelf should be idempotent for discovery). - return "", err - } - - nodes, size, index, err := d.checkCluster() - if err != nil { - return "", err - } - - all, err := d.waitNodes(nodes, size, index) - if err != nil { - return "", err - } - - return nodesToCluster(all, size) -} - -func (d *discovery) getCluster() (string, error) { - nodes, size, index, err := d.checkCluster() - if err != nil { - if err == ErrFullCluster { - return nodesToCluster(nodes, size) - } - return "", err - } - - all, err := d.waitNodes(nodes, size, index) - if err != nil { - return "", err - } - return nodesToCluster(all, size) -} - -func (d *discovery) createSelf(contents string) error { - ctx, cancel := context.WithTimeout(context.Background(), client.DefaultRequestTimeout) - resp, err := d.c.Create(ctx, d.selfKey(), contents) - cancel() - if err != nil { - if eerr, ok := err.(client.Error); ok && eerr.Code == client.ErrorCodeNodeExist { - return ErrDuplicateID - } - return err - } - - // ensure self appears on the server we connected to - w := d.c.Watcher(d.selfKey(), &client.WatcherOptions{AfterIndex: resp.Node.CreatedIndex - 1}) - _, err = w.Next(context.Background()) - return err -} - -func (d *discovery) checkCluster() ([]*client.Node, uint64, uint64, error) { - configKey := path.Join("/", d.cluster, "_config") - ctx, cancel := context.WithTimeout(context.Background(), client.DefaultRequestTimeout) - // find cluster size - resp, err := d.c.Get(ctx, path.Join(configKey, "size"), nil) - cancel() - if err != nil { - if eerr, ok := err.(*client.Error); ok && eerr.Code == client.ErrorCodeKeyNotFound { - return nil, 0, 0, ErrSizeNotFound - } - if err == client.ErrInvalidJSON { - return nil, 0, 0, ErrBadDiscoveryEndpoint - } - if ce, ok := err.(*client.ClusterError); ok { - d.lg.Warn( - "failed to get from discovery server", - zap.String("discovery-url", d.url.String()), - zap.String("path", path.Join(configKey, "size")), - zap.Error(err), - zap.String("err-detail", ce.Detail()), - ) - return d.checkClusterRetry() - } - return nil, 0, 0, err - } - size, err := strconv.ParseUint(resp.Node.Value, 10, 0) - if err != nil { - return nil, 0, 0, ErrBadSizeKey - } - - ctx, cancel = context.WithTimeout(context.Background(), client.DefaultRequestTimeout) - resp, err = d.c.Get(ctx, d.cluster, nil) - cancel() - if err != nil { - if ce, ok := err.(*client.ClusterError); ok { - d.lg.Warn( - "failed to get from discovery server", - zap.String("discovery-url", d.url.String()), - zap.String("path", d.cluster), - zap.Error(err), - zap.String("err-detail", ce.Detail()), - ) - return d.checkClusterRetry() - } - return nil, 0, 0, err - } - var nodes []*client.Node - // append non-config keys to nodes - for _, n := range resp.Node.Nodes { - if path.Base(n.Key) != path.Base(configKey) { - nodes = append(nodes, n) - } - } - - snodes := sortableNodes{nodes} - sort.Sort(snodes) - - // find self position - for i := range nodes { - if path.Base(nodes[i].Key) == path.Base(d.selfKey()) { - break - } - if uint64(i) >= size-1 { - return nodes[:size], size, resp.Index, ErrFullCluster - } - } - return nodes, size, resp.Index, nil -} - -func (d *discovery) logAndBackoffForRetry(step string) { - d.retries++ - // logAndBackoffForRetry stops exponential backoff when the retries are more than maxExpoentialRetries and is set to a constant backoff afterward. - retries := d.retries - if retries > maxExpoentialRetries { - retries = maxExpoentialRetries - } - retryTimeInSecond := time.Duration(0x1< size { - nodes = nodes[:size] - } - // watch from the next index - w := d.c.Watcher(d.cluster, &client.WatcherOptions{AfterIndex: index, Recursive: true}) - all := make([]*client.Node, len(nodes)) - copy(all, nodes) - for _, n := range all { - if path.Base(n.Key) == path.Base(d.selfKey()) { - d.lg.Info( - "found self from discovery server", - zap.String("discovery-url", d.url.String()), - zap.String("self", path.Base(d.selfKey())), - ) - } else { - d.lg.Info( - "found peer from discovery server", - zap.String("discovery-url", d.url.String()), - zap.String("peer", path.Base(n.Key)), - ) - } - } - - // wait for others - for uint64(len(all)) < size { - d.lg.Info( - "found peers from discovery server; waiting for more", - zap.String("discovery-url", d.url.String()), - zap.Int("found-peers", len(all)), - zap.Int("needed-peers", int(size-uint64(len(all)))), - ) - resp, err := w.Next(context.Background()) - if err != nil { - if ce, ok := err.(*client.ClusterError); ok { - d.lg.Warn( - "error while waiting for peers", - zap.String("discovery-url", d.url.String()), - zap.Error(err), - zap.String("err-detail", ce.Detail()), - ) - return d.waitNodesRetry() - } - return nil, err - } - d.lg.Info( - "found peer from discovery server", - zap.String("discovery-url", d.url.String()), - zap.String("peer", path.Base(resp.Node.Key)), - ) - all = append(all, resp.Node) - } - d.lg.Info( - "found all needed peers from discovery server", - zap.String("discovery-url", d.url.String()), - zap.Int("found-peers", len(all)), - ) - return all, nil -} - -func (d *discovery) selfKey() string { - return path.Join("/", d.cluster, d.id.String()) -} - -func nodesToCluster(ns []*client.Node, size uint64) (string, error) { - s := make([]string, len(ns)) - for i, n := range ns { - s[i] = n.Value - } - us := strings.Join(s, ",") - m, err := types.NewURLsMap(us) - if err != nil { - return us, ErrInvalidURL - } - if uint64(m.Len()) != size { - return us, ErrDuplicateName - } - return us, nil -} - -type sortableNodes struct{ Nodes []*client.Node } - -func (ns sortableNodes) Len() int { return len(ns.Nodes) } -func (ns sortableNodes) Less(i, j int) bool { - return ns.Nodes[i].CreatedIndex < ns.Nodes[j].CreatedIndex -} -func (ns sortableNodes) Swap(i, j int) { ns.Nodes[i], ns.Nodes[j] = ns.Nodes[j], ns.Nodes[i] } diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2error/error.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2error/error.go deleted file mode 100644 index 623863254a..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2error/error.go +++ /dev/null @@ -1,165 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package v2error describes errors in etcd project. When any change happens, -// https://github.com/etcd-io/website/blob/main/content/docs/v2/errorcode.md -// needs to be updated correspondingly. -// To be deprecated in favor of v3 APIs. -package v2error - -import ( - "encoding/json" - "fmt" - "net/http" -) - -var errors = map[int]string{ - // command related errors - EcodeKeyNotFound: "Key not found", - EcodeTestFailed: "Compare failed", //test and set - EcodeNotFile: "Not a file", - ecodeNoMorePeer: "Reached the max number of peers in the cluster", - EcodeNotDir: "Not a directory", - EcodeNodeExist: "Key already exists", // create - ecodeKeyIsPreserved: "The prefix of given key is a keyword in etcd", - EcodeRootROnly: "Root is read only", - EcodeDirNotEmpty: "Directory not empty", - ecodeExistingPeerAddr: "Peer address has existed", - EcodeUnauthorized: "The request requires user authentication", - - // Post form related errors - ecodeValueRequired: "Value is Required in POST form", - EcodePrevValueRequired: "PrevValue is Required in POST form", - EcodeTTLNaN: "The given TTL in POST form is not a number", - EcodeIndexNaN: "The given index in POST form is not a number", - ecodeValueOrTTLRequired: "Value or TTL is required in POST form", - ecodeTimeoutNaN: "The given timeout in POST form is not a number", - ecodeNameRequired: "Name is required in POST form", - ecodeIndexOrValueRequired: "Index or value is required", - ecodeIndexValueMutex: "Index and value cannot both be specified", - EcodeInvalidField: "Invalid field", - EcodeInvalidForm: "Invalid POST form", - EcodeRefreshValue: "Value provided on refresh", - EcodeRefreshTTLRequired: "A TTL must be provided on refresh", - - // raft related errors - EcodeRaftInternal: "Raft Internal Error", - EcodeLeaderElect: "During Leader Election", - - // etcd related errors - EcodeWatcherCleared: "watcher is cleared due to etcd recovery", - EcodeEventIndexCleared: "The event in requested index is outdated and cleared", - ecodeStandbyInternal: "Standby Internal Error", - ecodeInvalidActiveSize: "Invalid active size", - ecodeInvalidRemoveDelay: "Standby remove delay", - - // client related errors - ecodeClientInternal: "Client Internal Error", -} - -var errorStatus = map[int]int{ - EcodeKeyNotFound: http.StatusNotFound, - EcodeNotFile: http.StatusForbidden, - EcodeDirNotEmpty: http.StatusForbidden, - EcodeUnauthorized: http.StatusUnauthorized, - EcodeTestFailed: http.StatusPreconditionFailed, - EcodeNodeExist: http.StatusPreconditionFailed, - EcodeRaftInternal: http.StatusInternalServerError, - EcodeLeaderElect: http.StatusInternalServerError, -} - -const ( - EcodeKeyNotFound = 100 - EcodeTestFailed = 101 - EcodeNotFile = 102 - ecodeNoMorePeer = 103 - EcodeNotDir = 104 - EcodeNodeExist = 105 - ecodeKeyIsPreserved = 106 - EcodeRootROnly = 107 - EcodeDirNotEmpty = 108 - ecodeExistingPeerAddr = 109 - EcodeUnauthorized = 110 - - ecodeValueRequired = 200 - EcodePrevValueRequired = 201 - EcodeTTLNaN = 202 - EcodeIndexNaN = 203 - ecodeValueOrTTLRequired = 204 - ecodeTimeoutNaN = 205 - ecodeNameRequired = 206 - ecodeIndexOrValueRequired = 207 - ecodeIndexValueMutex = 208 - EcodeInvalidField = 209 - EcodeInvalidForm = 210 - EcodeRefreshValue = 211 - EcodeRefreshTTLRequired = 212 - - EcodeRaftInternal = 300 - EcodeLeaderElect = 301 - - EcodeWatcherCleared = 400 - EcodeEventIndexCleared = 401 - ecodeStandbyInternal = 402 - ecodeInvalidActiveSize = 403 - ecodeInvalidRemoveDelay = 404 - - ecodeClientInternal = 500 -) - -type Error struct { - ErrorCode int `json:"errorCode"` - Message string `json:"message"` - Cause string `json:"cause,omitempty"` - Index uint64 `json:"index"` -} - -func NewRequestError(errorCode int, cause string) *Error { - return NewError(errorCode, cause, 0) -} - -func NewError(errorCode int, cause string, index uint64) *Error { - return &Error{ - ErrorCode: errorCode, - Message: errors[errorCode], - Cause: cause, - Index: index, - } -} - -// Error is for the error interface -func (e Error) Error() string { - return e.Message + " (" + e.Cause + ")" -} - -func (e Error) toJsonString() string { - b, _ := json.Marshal(e) - return string(b) -} - -func (e Error) StatusCode() int { - status, ok := errorStatus[e.ErrorCode] - if !ok { - status = http.StatusBadRequest - } - return status -} - -func (e Error) WriteTo(w http.ResponseWriter) error { - w.Header().Add("X-Etcd-Index", fmt.Sprint(e.Index)) - w.Header().Set("Content-Type", "application/json") - w.WriteHeader(e.StatusCode()) - _, err := w.Write([]byte(e.toJsonString() + "\n")) - return err -} diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2http/capability.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2http/capability.go deleted file mode 100644 index 718b5ed502..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2http/capability.go +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package v2http - -import ( - "fmt" - "net/http" - - "go.etcd.io/etcd/server/v3/etcdserver/api" - "go.etcd.io/etcd/server/v3/etcdserver/api/v2http/httptypes" -) - -func authCapabilityHandler(fn func(http.ResponseWriter, *http.Request)) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - if !api.IsCapabilityEnabled(api.AuthCapability) { - notCapable(w, r, api.AuthCapability) - return - } - fn(w, r) - } -} - -func notCapable(w http.ResponseWriter, r *http.Request, c api.Capability) { - herr := httptypes.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Not capable of accessing %s feature during rolling upgrades.", c)) - if err := herr.WriteTo(w); err != nil { - // TODO: the following plog was removed, add the logging back if possible - // plog.Debugf("error writing HTTPError (%v) to %s", err, r.RemoteAddr) - } -} diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2http/client.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2http/client.go deleted file mode 100644 index 17b420732e..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2http/client.go +++ /dev/null @@ -1,756 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package v2http - -import ( - "context" - "encoding/json" - "errors" - "fmt" - "io/ioutil" - "net/http" - "net/url" - "path" - "strconv" - "strings" - "time" - - "go.etcd.io/etcd/api/v3/etcdserverpb" - "go.etcd.io/etcd/client/pkg/v3/types" - "go.etcd.io/etcd/server/v3/etcdserver" - "go.etcd.io/etcd/server/v3/etcdserver/api" - "go.etcd.io/etcd/server/v3/etcdserver/api/etcdhttp" - "go.etcd.io/etcd/server/v3/etcdserver/api/membership" - "go.etcd.io/etcd/server/v3/etcdserver/api/v2auth" - "go.etcd.io/etcd/server/v3/etcdserver/api/v2error" - "go.etcd.io/etcd/server/v3/etcdserver/api/v2http/httptypes" - stats "go.etcd.io/etcd/server/v3/etcdserver/api/v2stats" - "go.etcd.io/etcd/server/v3/etcdserver/api/v2store" - - "github.com/jonboulle/clockwork" - "go.uber.org/zap" -) - -const ( - authPrefix = "/v2/auth" - keysPrefix = "/v2/keys" - machinesPrefix = "/v2/machines" - membersPrefix = "/v2/members" - statsPrefix = "/v2/stats" -) - -// NewClientHandler generates a muxed http.Handler with the given parameters to serve etcd client requests. -func NewClientHandler(lg *zap.Logger, server etcdserver.ServerPeer, timeout time.Duration) http.Handler { - if lg == nil { - lg = zap.NewNop() - } - mux := http.NewServeMux() - etcdhttp.HandleBasic(lg, mux, server) - etcdhttp.HandleMetricsHealth(lg, mux, server) - handleV2(lg, mux, server, timeout) - return requestLogger(lg, mux) -} - -func handleV2(lg *zap.Logger, mux *http.ServeMux, server etcdserver.ServerV2, timeout time.Duration) { - sec := v2auth.NewStore(lg, server, timeout) - kh := &keysHandler{ - lg: lg, - sec: sec, - server: server, - cluster: server.Cluster(), - timeout: timeout, - clientCertAuthEnabled: server.ClientCertAuthEnabled(), - } - - sh := &statsHandler{ - lg: lg, - stats: server, - } - - mh := &membersHandler{ - lg: lg, - sec: sec, - server: server, - cluster: server.Cluster(), - timeout: timeout, - clock: clockwork.NewRealClock(), - clientCertAuthEnabled: server.ClientCertAuthEnabled(), - } - - mah := &machinesHandler{cluster: server.Cluster()} - - sech := &authHandler{ - lg: lg, - sec: sec, - cluster: server.Cluster(), - clientCertAuthEnabled: server.ClientCertAuthEnabled(), - } - mux.HandleFunc("/", http.NotFound) - mux.Handle(keysPrefix, kh) - mux.Handle(keysPrefix+"/", kh) - mux.HandleFunc(statsPrefix+"/store", sh.serveStore) - mux.HandleFunc(statsPrefix+"/self", sh.serveSelf) - mux.HandleFunc(statsPrefix+"/leader", sh.serveLeader) - mux.Handle(membersPrefix, mh) - mux.Handle(membersPrefix+"/", mh) - mux.Handle(machinesPrefix, mah) - handleAuth(mux, sech) -} - -type keysHandler struct { - lg *zap.Logger - sec v2auth.Store - server etcdserver.ServerV2 - cluster api.Cluster - timeout time.Duration - clientCertAuthEnabled bool -} - -func (h *keysHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { - if !allowMethod(w, r.Method, "HEAD", "GET", "PUT", "POST", "DELETE") { - return - } - - w.Header().Set("X-Etcd-Cluster-ID", h.cluster.ID().String()) - - ctx, cancel := context.WithTimeout(context.Background(), h.timeout) - defer cancel() - clock := clockwork.NewRealClock() - startTime := clock.Now() - rr, noValueOnSuccess, err := parseKeyRequest(r, clock) - if err != nil { - writeKeyError(h.lg, w, err) - return - } - // The path must be valid at this point (we've parsed the request successfully). - if !hasKeyPrefixAccess(h.lg, h.sec, r, r.URL.Path[len(keysPrefix):], rr.Recursive, h.clientCertAuthEnabled) { - writeKeyNoAuth(w) - return - } - if !rr.Wait { - reportRequestReceived(rr) - } - resp, err := h.server.Do(ctx, rr) - if err != nil { - err = trimErrorPrefix(err, etcdserver.StoreKeysPrefix) - writeKeyError(h.lg, w, err) - reportRequestFailed(rr, err) - return - } - switch { - case resp.Event != nil: - if err := writeKeyEvent(w, resp, noValueOnSuccess); err != nil { - // Should never be reached - h.lg.Warn("failed to write key event", zap.Error(err)) - } - reportRequestCompleted(rr, startTime) - case resp.Watcher != nil: - ctx, cancel := context.WithTimeout(context.Background(), defaultWatchTimeout) - defer cancel() - handleKeyWatch(ctx, h.lg, w, resp, rr.Stream) - default: - writeKeyError(h.lg, w, errors.New("received response with no Event/Watcher")) - } -} - -type machinesHandler struct { - cluster api.Cluster -} - -func (h *machinesHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { - if !allowMethod(w, r.Method, "GET", "HEAD") { - return - } - endpoints := h.cluster.ClientURLs() - w.Write([]byte(strings.Join(endpoints, ", "))) -} - -type membersHandler struct { - lg *zap.Logger - sec v2auth.Store - server etcdserver.ServerV2 - cluster api.Cluster - timeout time.Duration - clock clockwork.Clock - clientCertAuthEnabled bool -} - -func (h *membersHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { - if !allowMethod(w, r.Method, "GET", "POST", "DELETE", "PUT") { - return - } - if !hasWriteRootAccess(h.lg, h.sec, r, h.clientCertAuthEnabled) { - writeNoAuth(h.lg, w, r) - return - } - w.Header().Set("X-Etcd-Cluster-ID", h.cluster.ID().String()) - - ctx, cancel := context.WithTimeout(context.Background(), h.timeout) - defer cancel() - - switch r.Method { - case "GET": - switch trimPrefix(r.URL.Path, membersPrefix) { - case "": - mc := newMemberCollection(h.cluster.Members()) - w.Header().Set("Content-Type", "application/json") - if err := json.NewEncoder(w).Encode(mc); err != nil { - h.lg.Warn("failed to encode members response", zap.Error(err)) - } - case "leader": - id := h.server.Leader() - if id == 0 { - writeError(h.lg, w, r, httptypes.NewHTTPError(http.StatusServiceUnavailable, "During election")) - return - } - m := newMember(h.cluster.Member(id)) - w.Header().Set("Content-Type", "application/json") - if err := json.NewEncoder(w).Encode(m); err != nil { - h.lg.Warn("failed to encode members response", zap.Error(err)) - } - default: - writeError(h.lg, w, r, httptypes.NewHTTPError(http.StatusNotFound, "Not found")) - } - - case "POST": - req := httptypes.MemberCreateRequest{} - if ok := unmarshalRequest(h.lg, r, &req, w); !ok { - return - } - now := h.clock.Now() - m := membership.NewMember("", req.PeerURLs, "", &now) - _, err := h.server.AddMember(ctx, *m) - switch { - case err == membership.ErrIDExists || err == membership.ErrPeerURLexists: - writeError(h.lg, w, r, httptypes.NewHTTPError(http.StatusConflict, err.Error())) - return - case err != nil: - h.lg.Warn( - "failed to add a member", - zap.String("member-id", m.ID.String()), - zap.Error(err), - ) - writeError(h.lg, w, r, err) - return - } - res := newMember(m) - w.Header().Set("Content-Type", "application/json") - w.WriteHeader(http.StatusCreated) - if err := json.NewEncoder(w).Encode(res); err != nil { - h.lg.Warn("failed to encode members response", zap.Error(err)) - } - - case "DELETE": - id, ok := getID(h.lg, r.URL.Path, w) - if !ok { - return - } - _, err := h.server.RemoveMember(ctx, uint64(id)) - switch { - case err == membership.ErrIDRemoved: - writeError(h.lg, w, r, httptypes.NewHTTPError(http.StatusGone, fmt.Sprintf("Member permanently removed: %s", id))) - case err == membership.ErrIDNotFound: - writeError(h.lg, w, r, httptypes.NewHTTPError(http.StatusNotFound, fmt.Sprintf("No such member: %s", id))) - case err != nil: - h.lg.Warn( - "failed to remove a member", - zap.String("member-id", id.String()), - zap.Error(err), - ) - writeError(h.lg, w, r, err) - default: - w.WriteHeader(http.StatusNoContent) - } - - case "PUT": - id, ok := getID(h.lg, r.URL.Path, w) - if !ok { - return - } - req := httptypes.MemberUpdateRequest{} - if ok := unmarshalRequest(h.lg, r, &req, w); !ok { - return - } - m := membership.Member{ - ID: id, - RaftAttributes: membership.RaftAttributes{PeerURLs: req.PeerURLs.StringSlice()}, - } - _, err := h.server.UpdateMember(ctx, m) - switch { - case err == membership.ErrPeerURLexists: - writeError(h.lg, w, r, httptypes.NewHTTPError(http.StatusConflict, err.Error())) - case err == membership.ErrIDNotFound: - writeError(h.lg, w, r, httptypes.NewHTTPError(http.StatusNotFound, fmt.Sprintf("No such member: %s", id))) - case err != nil: - h.lg.Warn( - "failed to update a member", - zap.String("member-id", m.ID.String()), - zap.Error(err), - ) - writeError(h.lg, w, r, err) - default: - w.WriteHeader(http.StatusNoContent) - } - } -} - -type statsHandler struct { - lg *zap.Logger - stats stats.Stats -} - -func (h *statsHandler) serveStore(w http.ResponseWriter, r *http.Request) { - if !allowMethod(w, r.Method, "GET") { - return - } - w.Header().Set("Content-Type", "application/json") - w.Write(h.stats.StoreStats()) -} - -func (h *statsHandler) serveSelf(w http.ResponseWriter, r *http.Request) { - if !allowMethod(w, r.Method, "GET") { - return - } - w.Header().Set("Content-Type", "application/json") - w.Write(h.stats.SelfStats()) -} - -func (h *statsHandler) serveLeader(w http.ResponseWriter, r *http.Request) { - if !allowMethod(w, r.Method, "GET") { - return - } - stats := h.stats.LeaderStats() - if stats == nil { - etcdhttp.WriteError(h.lg, w, r, httptypes.NewHTTPError(http.StatusForbidden, "not current leader")) - return - } - w.Header().Set("Content-Type", "application/json") - w.Write(stats) -} - -// parseKeyRequest converts a received http.Request on keysPrefix to -// a server Request, performing validation of supplied fields as appropriate. -// If any validation fails, an empty Request and non-nil error is returned. -func parseKeyRequest(r *http.Request, clock clockwork.Clock) (etcdserverpb.Request, bool, error) { - var noValueOnSuccess bool - emptyReq := etcdserverpb.Request{} - - err := r.ParseForm() - if err != nil { - return emptyReq, false, v2error.NewRequestError( - v2error.EcodeInvalidForm, - err.Error(), - ) - } - - if !strings.HasPrefix(r.URL.Path, keysPrefix) { - return emptyReq, false, v2error.NewRequestError( - v2error.EcodeInvalidForm, - "incorrect key prefix", - ) - } - p := path.Join(etcdserver.StoreKeysPrefix, r.URL.Path[len(keysPrefix):]) - - var pIdx, wIdx uint64 - if pIdx, err = getUint64(r.Form, "prevIndex"); err != nil { - return emptyReq, false, v2error.NewRequestError( - v2error.EcodeIndexNaN, - `invalid value for "prevIndex"`, - ) - } - if wIdx, err = getUint64(r.Form, "waitIndex"); err != nil { - return emptyReq, false, v2error.NewRequestError( - v2error.EcodeIndexNaN, - `invalid value for "waitIndex"`, - ) - } - - var rec, sort, wait, dir, quorum, stream bool - if rec, err = getBool(r.Form, "recursive"); err != nil { - return emptyReq, false, v2error.NewRequestError( - v2error.EcodeInvalidField, - `invalid value for "recursive"`, - ) - } - if sort, err = getBool(r.Form, "sorted"); err != nil { - return emptyReq, false, v2error.NewRequestError( - v2error.EcodeInvalidField, - `invalid value for "sorted"`, - ) - } - if wait, err = getBool(r.Form, "wait"); err != nil { - return emptyReq, false, v2error.NewRequestError( - v2error.EcodeInvalidField, - `invalid value for "wait"`, - ) - } - // TODO(jonboulle): define what parameters dir is/isn't compatible with? - if dir, err = getBool(r.Form, "dir"); err != nil { - return emptyReq, false, v2error.NewRequestError( - v2error.EcodeInvalidField, - `invalid value for "dir"`, - ) - } - if quorum, err = getBool(r.Form, "quorum"); err != nil { - return emptyReq, false, v2error.NewRequestError( - v2error.EcodeInvalidField, - `invalid value for "quorum"`, - ) - } - if stream, err = getBool(r.Form, "stream"); err != nil { - return emptyReq, false, v2error.NewRequestError( - v2error.EcodeInvalidField, - `invalid value for "stream"`, - ) - } - - if wait && r.Method != "GET" { - return emptyReq, false, v2error.NewRequestError( - v2error.EcodeInvalidField, - `"wait" can only be used with GET requests`, - ) - } - - pV := r.FormValue("prevValue") - if _, ok := r.Form["prevValue"]; ok && pV == "" { - return emptyReq, false, v2error.NewRequestError( - v2error.EcodePrevValueRequired, - `"prevValue" cannot be empty`, - ) - } - - if noValueOnSuccess, err = getBool(r.Form, "noValueOnSuccess"); err != nil { - return emptyReq, false, v2error.NewRequestError( - v2error.EcodeInvalidField, - `invalid value for "noValueOnSuccess"`, - ) - } - - // TTL is nullable, so leave it null if not specified - // or an empty string - var ttl *uint64 - if len(r.FormValue("ttl")) > 0 { - i, err := getUint64(r.Form, "ttl") - if err != nil { - return emptyReq, false, v2error.NewRequestError( - v2error.EcodeTTLNaN, - `invalid value for "ttl"`, - ) - } - ttl = &i - } - - // prevExist is nullable, so leave it null if not specified - var pe *bool - if _, ok := r.Form["prevExist"]; ok { - bv, err := getBool(r.Form, "prevExist") - if err != nil { - return emptyReq, false, v2error.NewRequestError( - v2error.EcodeInvalidField, - "invalid value for prevExist", - ) - } - pe = &bv - } - - // refresh is nullable, so leave it null if not specified - var refresh *bool - if _, ok := r.Form["refresh"]; ok { - bv, err := getBool(r.Form, "refresh") - if err != nil { - return emptyReq, false, v2error.NewRequestError( - v2error.EcodeInvalidField, - "invalid value for refresh", - ) - } - refresh = &bv - if refresh != nil && *refresh { - val := r.FormValue("value") - if _, ok := r.Form["value"]; ok && val != "" { - return emptyReq, false, v2error.NewRequestError( - v2error.EcodeRefreshValue, - `A value was provided on a refresh`, - ) - } - if ttl == nil { - return emptyReq, false, v2error.NewRequestError( - v2error.EcodeRefreshTTLRequired, - `No TTL value set`, - ) - } - } - } - - rr := etcdserverpb.Request{ - Method: r.Method, - Path: p, - Val: r.FormValue("value"), - Dir: dir, - PrevValue: pV, - PrevIndex: pIdx, - PrevExist: pe, - Wait: wait, - Since: wIdx, - Recursive: rec, - Sorted: sort, - Quorum: quorum, - Stream: stream, - } - - if pe != nil { - rr.PrevExist = pe - } - - if refresh != nil { - rr.Refresh = refresh - } - - // Null TTL is equivalent to unset Expiration - if ttl != nil { - expr := time.Duration(*ttl) * time.Second - rr.Expiration = clock.Now().Add(expr).UnixNano() - } - - return rr, noValueOnSuccess, nil -} - -// writeKeyEvent trims the prefix of key path in a single Event under -// StoreKeysPrefix, serializes it and writes the resulting JSON to the given -// ResponseWriter, along with the appropriate headers. -func writeKeyEvent(w http.ResponseWriter, resp etcdserver.Response, noValueOnSuccess bool) error { - ev := resp.Event - if ev == nil { - return errors.New("cannot write empty Event") - } - w.Header().Set("Content-Type", "application/json") - w.Header().Set("X-Etcd-Index", fmt.Sprint(ev.EtcdIndex)) - w.Header().Set("X-Raft-Index", fmt.Sprint(resp.Index)) - w.Header().Set("X-Raft-Term", fmt.Sprint(resp.Term)) - - if ev.IsCreated() { - w.WriteHeader(http.StatusCreated) - } - - ev = trimEventPrefix(ev, etcdserver.StoreKeysPrefix) - if noValueOnSuccess && - (ev.Action == v2store.Set || ev.Action == v2store.CompareAndSwap || - ev.Action == v2store.Create || ev.Action == v2store.Update) { - ev.Node = nil - ev.PrevNode = nil - } - return json.NewEncoder(w).Encode(ev) -} - -func writeKeyNoAuth(w http.ResponseWriter) { - e := v2error.NewError(v2error.EcodeUnauthorized, "Insufficient credentials", 0) - e.WriteTo(w) -} - -// writeKeyError logs and writes the given Error to the ResponseWriter. -// If Error is not an etcdErr, the error will be converted to an etcd error. -func writeKeyError(lg *zap.Logger, w http.ResponseWriter, err error) { - if err == nil { - return - } - switch e := err.(type) { - case *v2error.Error: - e.WriteTo(w) - default: - switch err { - case etcdserver.ErrTimeoutDueToLeaderFail, etcdserver.ErrTimeoutDueToConnectionLost: - if lg != nil { - lg.Warn( - "v2 response error", - zap.String("internal-server-error", err.Error()), - ) - } - default: - if lg != nil { - lg.Warn( - "unexpected v2 response error", - zap.String("internal-server-error", err.Error()), - ) - } - } - ee := v2error.NewError(v2error.EcodeRaftInternal, err.Error(), 0) - ee.WriteTo(w) - } -} - -func handleKeyWatch(ctx context.Context, lg *zap.Logger, w http.ResponseWriter, resp etcdserver.Response, stream bool) { - wa := resp.Watcher - defer wa.Remove() - ech := wa.EventChan() - var nch <-chan bool - if x, ok := w.(http.CloseNotifier); ok { - nch = x.CloseNotify() - } - - w.Header().Set("Content-Type", "application/json") - w.Header().Set("X-Etcd-Index", fmt.Sprint(wa.StartIndex())) - w.Header().Set("X-Raft-Index", fmt.Sprint(resp.Index)) - w.Header().Set("X-Raft-Term", fmt.Sprint(resp.Term)) - w.WriteHeader(http.StatusOK) - - // Ensure headers are flushed early, in case of long polling - w.(http.Flusher).Flush() - - for { - select { - case <-nch: - // Client closed connection. Nothing to do. - return - case <-ctx.Done(): - // Timed out. net/http will close the connection for us, so nothing to do. - return - case ev, ok := <-ech: - if !ok { - // If the channel is closed this may be an indication of - // that notifications are much more than we are able to - // send to the client in time. Then we simply end streaming. - return - } - ev = trimEventPrefix(ev, etcdserver.StoreKeysPrefix) - if err := json.NewEncoder(w).Encode(ev); err != nil { - // Should never be reached - lg.Warn("failed to encode event", zap.Error(err)) - return - } - if !stream { - return - } - w.(http.Flusher).Flush() - } - } -} - -func trimEventPrefix(ev *v2store.Event, prefix string) *v2store.Event { - if ev == nil { - return nil - } - // Since the *Event may reference one in the store history - // history, we must copy it before modifying - e := ev.Clone() - trimNodeExternPrefix(e.Node, prefix) - trimNodeExternPrefix(e.PrevNode, prefix) - return e -} - -func trimNodeExternPrefix(n *v2store.NodeExtern, prefix string) { - if n == nil { - return - } - n.Key = strings.TrimPrefix(n.Key, prefix) - for _, nn := range n.Nodes { - trimNodeExternPrefix(nn, prefix) - } -} - -func trimErrorPrefix(err error, prefix string) error { - if e, ok := err.(*v2error.Error); ok { - e.Cause = strings.TrimPrefix(e.Cause, prefix) - } - return err -} - -func unmarshalRequest(lg *zap.Logger, r *http.Request, req json.Unmarshaler, w http.ResponseWriter) bool { - ctype := r.Header.Get("Content-Type") - semicolonPosition := strings.Index(ctype, ";") - if semicolonPosition != -1 { - ctype = strings.TrimSpace(strings.ToLower(ctype[0:semicolonPosition])) - } - if ctype != "application/json" { - writeError(lg, w, r, httptypes.NewHTTPError(http.StatusUnsupportedMediaType, fmt.Sprintf("Bad Content-Type %s, accept application/json", ctype))) - return false - } - b, err := ioutil.ReadAll(r.Body) - if err != nil { - writeError(lg, w, r, httptypes.NewHTTPError(http.StatusBadRequest, err.Error())) - return false - } - if err := req.UnmarshalJSON(b); err != nil { - writeError(lg, w, r, httptypes.NewHTTPError(http.StatusBadRequest, err.Error())) - return false - } - return true -} - -func getID(lg *zap.Logger, p string, w http.ResponseWriter) (types.ID, bool) { - idStr := trimPrefix(p, membersPrefix) - if idStr == "" { - http.Error(w, "Method Not Allowed", http.StatusMethodNotAllowed) - return 0, false - } - id, err := types.IDFromString(idStr) - if err != nil { - writeError(lg, w, nil, httptypes.NewHTTPError(http.StatusNotFound, fmt.Sprintf("No such member: %s", idStr))) - return 0, false - } - return id, true -} - -// getUint64 extracts a uint64 by the given key from a Form. If the key does -// not exist in the form, 0 is returned. If the key exists but the value is -// badly formed, an error is returned. If multiple values are present only the -// first is considered. -func getUint64(form url.Values, key string) (i uint64, err error) { - if vals, ok := form[key]; ok { - i, err = strconv.ParseUint(vals[0], 10, 64) - } - return -} - -// getBool extracts a bool by the given key from a Form. If the key does not -// exist in the form, false is returned. If the key exists but the value is -// badly formed, an error is returned. If multiple values are present only the -// first is considered. -func getBool(form url.Values, key string) (b bool, err error) { - if vals, ok := form[key]; ok { - b, err = strconv.ParseBool(vals[0]) - } - return -} - -// trimPrefix removes a given prefix and any slash following the prefix -// e.g.: trimPrefix("foo", "foo") == trimPrefix("foo/", "foo") == "" -func trimPrefix(p, prefix string) (s string) { - s = strings.TrimPrefix(p, prefix) - s = strings.TrimPrefix(s, "/") - return -} - -func newMemberCollection(ms []*membership.Member) *httptypes.MemberCollection { - c := httptypes.MemberCollection(make([]httptypes.Member, len(ms))) - - for i, m := range ms { - c[i] = newMember(m) - } - - return &c -} - -func newMember(m *membership.Member) httptypes.Member { - tm := httptypes.Member{ - ID: m.ID.String(), - Name: m.Name, - PeerURLs: make([]string, len(m.PeerURLs)), - ClientURLs: make([]string, len(m.ClientURLs)), - } - - copy(tm.PeerURLs, m.PeerURLs) - copy(tm.ClientURLs, m.ClientURLs) - - return tm -} diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2http/client_auth.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2http/client_auth.go deleted file mode 100644 index 2c6e7744ed..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2http/client_auth.go +++ /dev/null @@ -1,604 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package v2http - -import ( - "encoding/json" - "net/http" - "path" - "strings" - - "go.etcd.io/etcd/server/v3/etcdserver/api" - "go.etcd.io/etcd/server/v3/etcdserver/api/v2auth" - "go.etcd.io/etcd/server/v3/etcdserver/api/v2http/httptypes" - - "go.uber.org/zap" -) - -type authHandler struct { - lg *zap.Logger - sec v2auth.Store - cluster api.Cluster - clientCertAuthEnabled bool -} - -func hasWriteRootAccess(lg *zap.Logger, sec v2auth.Store, r *http.Request, clientCertAuthEnabled bool) bool { - if r.Method == "GET" || r.Method == "HEAD" { - return true - } - return hasRootAccess(lg, sec, r, clientCertAuthEnabled) -} - -func userFromBasicAuth(lg *zap.Logger, sec v2auth.Store, r *http.Request) *v2auth.User { - username, password, ok := r.BasicAuth() - if !ok { - lg.Warn("malformed basic auth encoding") - return nil - } - user, err := sec.GetUser(username) - if err != nil { - return nil - } - - ok = sec.CheckPassword(user, password) - if !ok { - lg.Warn("incorrect password", zap.String("user-name", username)) - return nil - } - return &user -} - -func userFromClientCertificate(lg *zap.Logger, sec v2auth.Store, r *http.Request) *v2auth.User { - if r.TLS == nil { - return nil - } - - for _, chains := range r.TLS.VerifiedChains { - for _, chain := range chains { - lg.Debug("found common name", zap.String("common-name", chain.Subject.CommonName)) - user, err := sec.GetUser(chain.Subject.CommonName) - if err == nil { - lg.Debug( - "authenticated a user via common name", - zap.String("user-name", user.User), - zap.String("common-name", chain.Subject.CommonName), - ) - return &user - } - } - } - return nil -} - -func hasRootAccess(lg *zap.Logger, sec v2auth.Store, r *http.Request, clientCertAuthEnabled bool) bool { - if sec == nil { - // No store means no auth available, eg, tests. - return true - } - if !sec.AuthEnabled() { - return true - } - - var rootUser *v2auth.User - if r.Header.Get("Authorization") == "" && clientCertAuthEnabled { - rootUser = userFromClientCertificate(lg, sec, r) - if rootUser == nil { - return false - } - } else { - rootUser = userFromBasicAuth(lg, sec, r) - if rootUser == nil { - return false - } - } - - for _, role := range rootUser.Roles { - if role == v2auth.RootRoleName { - return true - } - } - - lg.Warn( - "a user does not have root role for resource", - zap.String("root-user", rootUser.User), - zap.String("root-role-name", v2auth.RootRoleName), - zap.String("resource-path", r.URL.Path), - ) - return false -} - -func hasKeyPrefixAccess(lg *zap.Logger, sec v2auth.Store, r *http.Request, key string, recursive, clientCertAuthEnabled bool) bool { - if sec == nil { - // No store means no auth available, eg, tests. - return true - } - if !sec.AuthEnabled() { - return true - } - - var user *v2auth.User - if r.Header.Get("Authorization") == "" { - if clientCertAuthEnabled { - user = userFromClientCertificate(lg, sec, r) - } - if user == nil { - return hasGuestAccess(lg, sec, r, key) - } - } else { - user = userFromBasicAuth(lg, sec, r) - if user == nil { - return false - } - } - - writeAccess := r.Method != "GET" && r.Method != "HEAD" - for _, roleName := range user.Roles { - role, err := sec.GetRole(roleName) - if err != nil { - continue - } - if recursive { - if role.HasRecursiveAccess(key, writeAccess) { - return true - } - } else if role.HasKeyAccess(key, writeAccess) { - return true - } - } - - lg.Warn( - "invalid access for user on key", - zap.String("user-name", user.User), - zap.String("key", key), - ) - return false -} - -func hasGuestAccess(lg *zap.Logger, sec v2auth.Store, r *http.Request, key string) bool { - writeAccess := r.Method != "GET" && r.Method != "HEAD" - role, err := sec.GetRole(v2auth.GuestRoleName) - if err != nil { - return false - } - if role.HasKeyAccess(key, writeAccess) { - return true - } - - lg.Warn( - "invalid access for a guest role on key", - zap.String("role-name", v2auth.GuestRoleName), - zap.String("key", key), - ) - return false -} - -func writeNoAuth(lg *zap.Logger, w http.ResponseWriter, r *http.Request) { - herr := httptypes.NewHTTPError(http.StatusUnauthorized, "Insufficient credentials") - if err := herr.WriteTo(w); err != nil { - lg.Debug( - "failed to write v2 HTTP error", - zap.String("remote-addr", r.RemoteAddr), - zap.Error(err), - ) - } -} - -func handleAuth(mux *http.ServeMux, sh *authHandler) { - mux.HandleFunc(authPrefix+"/roles", authCapabilityHandler(sh.baseRoles)) - mux.HandleFunc(authPrefix+"/roles/", authCapabilityHandler(sh.handleRoles)) - mux.HandleFunc(authPrefix+"/users", authCapabilityHandler(sh.baseUsers)) - mux.HandleFunc(authPrefix+"/users/", authCapabilityHandler(sh.handleUsers)) - mux.HandleFunc(authPrefix+"/enable", authCapabilityHandler(sh.enableDisable)) -} - -func (sh *authHandler) baseRoles(w http.ResponseWriter, r *http.Request) { - if !allowMethod(w, r.Method, "GET") { - return - } - if !hasRootAccess(sh.lg, sh.sec, r, sh.clientCertAuthEnabled) { - writeNoAuth(sh.lg, w, r) - return - } - - w.Header().Set("X-Etcd-Cluster-ID", sh.cluster.ID().String()) - w.Header().Set("Content-Type", "application/json") - - roles, err := sh.sec.AllRoles() - if err != nil { - writeError(sh.lg, w, r, err) - return - } - if roles == nil { - roles = make([]string, 0) - } - - err = r.ParseForm() - if err != nil { - writeError(sh.lg, w, r, err) - return - } - - var rolesCollections struct { - Roles []v2auth.Role `json:"roles"` - } - for _, roleName := range roles { - var role v2auth.Role - role, err = sh.sec.GetRole(roleName) - if err != nil { - writeError(sh.lg, w, r, err) - return - } - rolesCollections.Roles = append(rolesCollections.Roles, role) - } - err = json.NewEncoder(w).Encode(rolesCollections) - - if err != nil { - sh.lg.Warn( - "failed to encode base roles", - zap.String("url", r.URL.String()), - zap.Error(err), - ) - writeError(sh.lg, w, r, err) - return - } -} - -func (sh *authHandler) handleRoles(w http.ResponseWriter, r *http.Request) { - subpath := path.Clean(r.URL.Path[len(authPrefix):]) - // Split "/roles/rolename/command". - // First item is an empty string, second is "roles" - pieces := strings.Split(subpath, "/") - if len(pieces) == 2 { - sh.baseRoles(w, r) - return - } - if len(pieces) != 3 { - writeError(sh.lg, w, r, httptypes.NewHTTPError(http.StatusBadRequest, "Invalid path")) - return - } - sh.forRole(w, r, pieces[2]) -} - -func (sh *authHandler) forRole(w http.ResponseWriter, r *http.Request, role string) { - if !allowMethod(w, r.Method, "GET", "PUT", "DELETE") { - return - } - if !hasRootAccess(sh.lg, sh.sec, r, sh.clientCertAuthEnabled) { - writeNoAuth(sh.lg, w, r) - return - } - w.Header().Set("X-Etcd-Cluster-ID", sh.cluster.ID().String()) - w.Header().Set("Content-Type", "application/json") - - switch r.Method { - case "GET": - data, err := sh.sec.GetRole(role) - if err != nil { - writeError(sh.lg, w, r, err) - return - } - err = json.NewEncoder(w).Encode(data) - if err != nil { - sh.lg.Warn( - "failed to encode a role", - zap.String("url", r.URL.String()), - zap.Error(err), - ) - return - } - return - - case "PUT": - var in v2auth.Role - err := json.NewDecoder(r.Body).Decode(&in) - if err != nil { - writeError(sh.lg, w, r, httptypes.NewHTTPError(http.StatusBadRequest, "Invalid JSON in request body.")) - return - } - if in.Role != role { - writeError(sh.lg, w, r, httptypes.NewHTTPError(http.StatusBadRequest, "Role JSON name does not match the name in the URL")) - return - } - - var out v2auth.Role - - // create - if in.Grant.IsEmpty() && in.Revoke.IsEmpty() { - err = sh.sec.CreateRole(in) - if err != nil { - writeError(sh.lg, w, r, err) - return - } - w.WriteHeader(http.StatusCreated) - out = in - } else { - if !in.Permissions.IsEmpty() { - writeError(sh.lg, w, r, httptypes.NewHTTPError(http.StatusBadRequest, "Role JSON contains both permissions and grant/revoke")) - return - } - out, err = sh.sec.UpdateRole(in) - if err != nil { - writeError(sh.lg, w, r, err) - return - } - w.WriteHeader(http.StatusOK) - } - - err = json.NewEncoder(w).Encode(out) - if err != nil { - sh.lg.Warn( - "failed to encode a role", - zap.String("url", r.URL.String()), - zap.Error(err), - ) - return - } - return - - case "DELETE": - err := sh.sec.DeleteRole(role) - if err != nil { - writeError(sh.lg, w, r, err) - return - } - } -} - -type userWithRoles struct { - User string `json:"user"` - Roles []v2auth.Role `json:"roles,omitempty"` -} - -type usersCollections struct { - Users []userWithRoles `json:"users"` -} - -func (sh *authHandler) baseUsers(w http.ResponseWriter, r *http.Request) { - if !allowMethod(w, r.Method, "GET") { - return - } - if !hasRootAccess(sh.lg, sh.sec, r, sh.clientCertAuthEnabled) { - writeNoAuth(sh.lg, w, r) - return - } - w.Header().Set("X-Etcd-Cluster-ID", sh.cluster.ID().String()) - w.Header().Set("Content-Type", "application/json") - - users, err := sh.sec.AllUsers() - if err != nil { - writeError(sh.lg, w, r, err) - return - } - if users == nil { - users = make([]string, 0) - } - - err = r.ParseForm() - if err != nil { - writeError(sh.lg, w, r, err) - return - } - - ucs := usersCollections{} - for _, userName := range users { - var user v2auth.User - user, err = sh.sec.GetUser(userName) - if err != nil { - writeError(sh.lg, w, r, err) - return - } - - uwr := userWithRoles{User: user.User} - for _, roleName := range user.Roles { - var role v2auth.Role - role, err = sh.sec.GetRole(roleName) - if err != nil { - continue - } - uwr.Roles = append(uwr.Roles, role) - } - - ucs.Users = append(ucs.Users, uwr) - } - err = json.NewEncoder(w).Encode(ucs) - - if err != nil { - sh.lg.Warn( - "failed to encode users", - zap.String("url", r.URL.String()), - zap.Error(err), - ) - writeError(sh.lg, w, r, err) - return - } -} - -func (sh *authHandler) handleUsers(w http.ResponseWriter, r *http.Request) { - subpath := path.Clean(r.URL.Path[len(authPrefix):]) - // Split "/users/username". - // First item is an empty string, second is "users" - pieces := strings.Split(subpath, "/") - if len(pieces) == 2 { - sh.baseUsers(w, r) - return - } - if len(pieces) != 3 { - writeError(sh.lg, w, r, httptypes.NewHTTPError(http.StatusBadRequest, "Invalid path")) - return - } - sh.forUser(w, r, pieces[2]) -} - -func (sh *authHandler) forUser(w http.ResponseWriter, r *http.Request, user string) { - if !allowMethod(w, r.Method, "GET", "PUT", "DELETE") { - return - } - if !hasRootAccess(sh.lg, sh.sec, r, sh.clientCertAuthEnabled) { - writeNoAuth(sh.lg, w, r) - return - } - w.Header().Set("X-Etcd-Cluster-ID", sh.cluster.ID().String()) - w.Header().Set("Content-Type", "application/json") - - switch r.Method { - case "GET": - u, err := sh.sec.GetUser(user) - if err != nil { - writeError(sh.lg, w, r, err) - return - } - - err = r.ParseForm() - if err != nil { - writeError(sh.lg, w, r, err) - return - } - - uwr := userWithRoles{User: u.User} - for _, roleName := range u.Roles { - var role v2auth.Role - role, err = sh.sec.GetRole(roleName) - if err != nil { - writeError(sh.lg, w, r, err) - return - } - uwr.Roles = append(uwr.Roles, role) - } - err = json.NewEncoder(w).Encode(uwr) - - if err != nil { - sh.lg.Warn( - "failed to encode roles", - zap.String("url", r.URL.String()), - zap.Error(err), - ) - return - } - return - - case "PUT": - var u v2auth.User - err := json.NewDecoder(r.Body).Decode(&u) - if err != nil { - writeError(sh.lg, w, r, httptypes.NewHTTPError(http.StatusBadRequest, "Invalid JSON in request body.")) - return - } - if u.User != user { - writeError(sh.lg, w, r, httptypes.NewHTTPError(http.StatusBadRequest, "User JSON name does not match the name in the URL")) - return - } - - var ( - out v2auth.User - created bool - ) - - if len(u.Grant) == 0 && len(u.Revoke) == 0 { - // create or update - if len(u.Roles) != 0 { - out, err = sh.sec.CreateUser(u) - } else { - // if user passes in both password and roles, we are unsure about his/her - // intention. - out, created, err = sh.sec.CreateOrUpdateUser(u) - } - - if err != nil { - writeError(sh.lg, w, r, err) - return - } - } else { - // update case - if len(u.Roles) != 0 { - writeError(sh.lg, w, r, httptypes.NewHTTPError(http.StatusBadRequest, "User JSON contains both roles and grant/revoke")) - return - } - out, err = sh.sec.UpdateUser(u) - if err != nil { - writeError(sh.lg, w, r, err) - return - } - } - - if created { - w.WriteHeader(http.StatusCreated) - } else { - w.WriteHeader(http.StatusOK) - } - - out.Password = "" - - err = json.NewEncoder(w).Encode(out) - if err != nil { - sh.lg.Warn( - "failed to encode a user", - zap.String("url", r.URL.String()), - zap.Error(err), - ) - return - } - return - - case "DELETE": - err := sh.sec.DeleteUser(user) - if err != nil { - writeError(sh.lg, w, r, err) - return - } - } -} - -type enabled struct { - Enabled bool `json:"enabled"` -} - -func (sh *authHandler) enableDisable(w http.ResponseWriter, r *http.Request) { - if !allowMethod(w, r.Method, "GET", "PUT", "DELETE") { - return - } - if !hasWriteRootAccess(sh.lg, sh.sec, r, sh.clientCertAuthEnabled) { - writeNoAuth(sh.lg, w, r) - return - } - w.Header().Set("X-Etcd-Cluster-ID", sh.cluster.ID().String()) - w.Header().Set("Content-Type", "application/json") - isEnabled := sh.sec.AuthEnabled() - switch r.Method { - case "GET": - jsonDict := enabled{isEnabled} - err := json.NewEncoder(w).Encode(jsonDict) - if err != nil { - sh.lg.Warn( - "failed to encode a auth state", - zap.String("url", r.URL.String()), - zap.Error(err), - ) - } - - case "PUT": - err := sh.sec.EnableAuth() - if err != nil { - writeError(sh.lg, w, r, err) - return - } - - case "DELETE": - err := sh.sec.DisableAuth() - if err != nil { - writeError(sh.lg, w, r, err) - return - } - } -} diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2http/doc.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2http/doc.go deleted file mode 100644 index 475c4b1f95..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2http/doc.go +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package v2http provides etcd client and server implementations. -package v2http diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2http/http.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2http/http.go deleted file mode 100644 index 88138b80a8..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2http/http.go +++ /dev/null @@ -1,82 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package v2http - -import ( - "math" - "net/http" - "strings" - "time" - - "go.etcd.io/etcd/server/v3/etcdserver/api/etcdhttp" - "go.etcd.io/etcd/server/v3/etcdserver/api/v2auth" - "go.etcd.io/etcd/server/v3/etcdserver/api/v2http/httptypes" - - "go.uber.org/zap" -) - -const ( - // time to wait for a Watch request - defaultWatchTimeout = time.Duration(math.MaxInt64) -) - -func writeError(lg *zap.Logger, w http.ResponseWriter, r *http.Request, err error) { - if err == nil { - return - } - if e, ok := err.(v2auth.Error); ok { - herr := httptypes.NewHTTPError(e.HTTPStatus(), e.Error()) - if et := herr.WriteTo(w); et != nil { - if lg != nil { - lg.Debug( - "failed to write v2 HTTP error", - zap.String("remote-addr", r.RemoteAddr), - zap.String("v2auth-error", e.Error()), - zap.Error(et), - ) - } - } - return - } - etcdhttp.WriteError(lg, w, r, err) -} - -// allowMethod verifies that the given method is one of the allowed methods, -// and if not, it writes an error to w. A boolean is returned indicating -// whether or not the method is allowed. -func allowMethod(w http.ResponseWriter, m string, ms ...string) bool { - for _, meth := range ms { - if m == meth { - return true - } - } - w.Header().Set("Allow", strings.Join(ms, ",")) - http.Error(w, "Method Not Allowed", http.StatusMethodNotAllowed) - return false -} - -func requestLogger(lg *zap.Logger, handler http.Handler) http.Handler { - return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - if lg != nil { - lg.Debug( - "handling HTTP request", - zap.String("method", r.Method), - zap.String("request-uri", r.RequestURI), - zap.String("remote-addr", r.RemoteAddr), - ) - } - handler.ServeHTTP(w, r) - }) -} diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2http/httptypes/errors.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2http/httptypes/errors.go deleted file mode 100644 index 79e366f24a..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2http/httptypes/errors.go +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package httptypes - -import ( - "encoding/json" - "fmt" - "net/http" -) - -type HTTPError struct { - Message string `json:"message"` - // Code is the HTTP status code - Code int `json:"-"` -} - -func (e HTTPError) Error() string { - return e.Message -} - -func (e HTTPError) WriteTo(w http.ResponseWriter) error { - w.Header().Set("Content-Type", "application/json") - w.WriteHeader(e.Code) - b, err := json.Marshal(e) - if err != nil { - panic(fmt.Sprintf("failed to marshal HTTPError: %v", err)) - } - if _, err := w.Write(b); err != nil { - return err - } - return nil -} - -func NewHTTPError(code int, m string) *HTTPError { - return &HTTPError{ - Message: m, - Code: code, - } -} diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2http/httptypes/member.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2http/httptypes/member.go deleted file mode 100644 index a5467be91e..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2http/httptypes/member.go +++ /dev/null @@ -1,69 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package httptypes defines how etcd's HTTP API entities are serialized to and -// deserialized from JSON. -package httptypes - -import ( - "encoding/json" - - "go.etcd.io/etcd/client/pkg/v3/types" -) - -type Member struct { - ID string `json:"id"` - Name string `json:"name"` - PeerURLs []string `json:"peerURLs"` - ClientURLs []string `json:"clientURLs"` -} - -type MemberCreateRequest struct { - PeerURLs types.URLs -} - -type MemberUpdateRequest struct { - MemberCreateRequest -} - -func (m *MemberCreateRequest) UnmarshalJSON(data []byte) error { - s := struct { - PeerURLs []string `json:"peerURLs"` - }{} - - err := json.Unmarshal(data, &s) - if err != nil { - return err - } - - urls, err := types.NewURLs(s.PeerURLs) - if err != nil { - return err - } - - m.PeerURLs = urls - return nil -} - -type MemberCollection []Member - -func (c *MemberCollection) MarshalJSON() ([]byte, error) { - d := struct { - Members []Member `json:"members"` - }{ - Members: []Member(*c), - } - - return json.Marshal(d) -} diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2http/metrics.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2http/metrics.go deleted file mode 100644 index bdbd8c71c1..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2http/metrics.go +++ /dev/null @@ -1,98 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package v2http - -import ( - "net/http" - "strconv" - "time" - - "go.etcd.io/etcd/api/v3/etcdserverpb" - "go.etcd.io/etcd/server/v3/etcdserver/api/v2error" - "go.etcd.io/etcd/server/v3/etcdserver/api/v2http/httptypes" - - "github.com/prometheus/client_golang/prometheus" -) - -var ( - incomingEvents = prometheus.NewCounterVec( - prometheus.CounterOpts{ - Namespace: "etcd", - Subsystem: "http", - Name: "received_total", - Help: "Counter of requests received into the system (successfully parsed and authd).", - }, []string{"method"}) - - failedEvents = prometheus.NewCounterVec( - prometheus.CounterOpts{ - Namespace: "etcd", - Subsystem: "http", - Name: "failed_total", - Help: "Counter of handle failures of requests (non-watches), by method (GET/PUT etc.) and code (400, 500 etc.).", - }, []string{"method", "code"}) - - successfulEventsHandlingSec = prometheus.NewHistogramVec( - prometheus.HistogramOpts{ - Namespace: "etcd", - Subsystem: "http", - Name: "successful_duration_seconds", - Help: "Bucketed histogram of processing time (s) of successfully handled requests (non-watches), by method (GET/PUT etc.).", - - // lowest bucket start of upper bound 0.0005 sec (0.5 ms) with factor 2 - // highest bucket start of 0.0005 sec * 2^12 == 2.048 sec - Buckets: prometheus.ExponentialBuckets(0.0005, 2, 13), - }, []string{"method"}) -) - -func init() { - prometheus.MustRegister(incomingEvents) - prometheus.MustRegister(failedEvents) - prometheus.MustRegister(successfulEventsHandlingSec) -} - -func reportRequestReceived(request etcdserverpb.Request) { - incomingEvents.WithLabelValues(methodFromRequest(request)).Inc() -} - -func reportRequestCompleted(request etcdserverpb.Request, startTime time.Time) { - method := methodFromRequest(request) - successfulEventsHandlingSec.WithLabelValues(method).Observe(time.Since(startTime).Seconds()) -} - -func reportRequestFailed(request etcdserverpb.Request, err error) { - method := methodFromRequest(request) - failedEvents.WithLabelValues(method, strconv.Itoa(codeFromError(err))).Inc() -} - -func methodFromRequest(request etcdserverpb.Request) string { - if request.Method == "GET" && request.Quorum { - return "QGET" - } - return request.Method -} - -func codeFromError(err error) int { - if err == nil { - return http.StatusInternalServerError - } - switch e := err.(type) { - case *v2error.Error: - return e.StatusCode() - case *httptypes.HTTPError: - return e.Code - default: - return http.StatusInternalServerError - } -} diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2stats/leader.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2stats/leader.go deleted file mode 100644 index f17cecc2c3..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2stats/leader.go +++ /dev/null @@ -1,135 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package v2stats - -import ( - "encoding/json" - "math" - "sync" - "time" - - "go.uber.org/zap" -) - -// LeaderStats is used by the leader in an etcd cluster, and encapsulates -// statistics about communication with its followers -type LeaderStats struct { - lg *zap.Logger - leaderStats - sync.Mutex -} - -type leaderStats struct { - // Leader is the ID of the leader in the etcd cluster. - // TODO(jonboulle): clarify that these are IDs, not names - Leader string `json:"leader"` - Followers map[string]*FollowerStats `json:"followers"` -} - -// NewLeaderStats generates a new LeaderStats with the given id as leader -func NewLeaderStats(lg *zap.Logger, id string) *LeaderStats { - if lg == nil { - lg = zap.NewNop() - } - return &LeaderStats{ - lg: lg, - leaderStats: leaderStats{ - Leader: id, - Followers: make(map[string]*FollowerStats), - }, - } -} - -func (ls *LeaderStats) JSON() []byte { - ls.Lock() - stats := ls.leaderStats - ls.Unlock() - b, err := json.Marshal(stats) - // TODO(jonboulle): appropriate error handling? - if err != nil { - ls.lg.Error("failed to marshal leader stats", zap.Error(err)) - } - return b -} - -func (ls *LeaderStats) Follower(name string) *FollowerStats { - ls.Lock() - defer ls.Unlock() - fs, ok := ls.Followers[name] - if !ok { - fs = &FollowerStats{} - fs.Latency.Minimum = 1 << 63 - ls.Followers[name] = fs - } - return fs -} - -// FollowerStats encapsulates various statistics about a follower in an etcd cluster -type FollowerStats struct { - Latency LatencyStats `json:"latency"` - Counts CountsStats `json:"counts"` - - sync.Mutex -} - -// LatencyStats encapsulates latency statistics. -type LatencyStats struct { - Current float64 `json:"current"` - Average float64 `json:"average"` - averageSquare float64 - StandardDeviation float64 `json:"standardDeviation"` - Minimum float64 `json:"minimum"` - Maximum float64 `json:"maximum"` -} - -// CountsStats encapsulates raft statistics. -type CountsStats struct { - Fail uint64 `json:"fail"` - Success uint64 `json:"success"` -} - -// Succ updates the FollowerStats with a successful send -func (fs *FollowerStats) Succ(d time.Duration) { - fs.Lock() - defer fs.Unlock() - - total := float64(fs.Counts.Success) * fs.Latency.Average - totalSquare := float64(fs.Counts.Success) * fs.Latency.averageSquare - - fs.Counts.Success++ - - fs.Latency.Current = float64(d) / (1000000.0) - - if fs.Latency.Current > fs.Latency.Maximum { - fs.Latency.Maximum = fs.Latency.Current - } - - if fs.Latency.Current < fs.Latency.Minimum { - fs.Latency.Minimum = fs.Latency.Current - } - - fs.Latency.Average = (total + fs.Latency.Current) / float64(fs.Counts.Success) - fs.Latency.averageSquare = (totalSquare + fs.Latency.Current*fs.Latency.Current) / float64(fs.Counts.Success) - - // sdv = sqrt(avg(x^2) - avg(x)^2) - fs.Latency.StandardDeviation = math.Sqrt(fs.Latency.averageSquare - fs.Latency.Average*fs.Latency.Average) -} - -// Fail updates the FollowerStats with an unsuccessful send -func (fs *FollowerStats) Fail() { - fs.Lock() - defer fs.Unlock() - fs.Counts.Fail++ -} diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2stats/queue.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2stats/queue.go deleted file mode 100644 index 2c3dff3d0f..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2stats/queue.go +++ /dev/null @@ -1,110 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package v2stats - -import ( - "sync" - "time" -) - -const ( - queueCapacity = 200 -) - -// RequestStats represent the stats for a request. -// It encapsulates the sending time and the size of the request. -type RequestStats struct { - SendingTime time.Time - Size int -} - -type statsQueue struct { - items [queueCapacity]*RequestStats - size int - front int - back int - totalReqSize int - rwl sync.RWMutex -} - -func (q *statsQueue) Len() int { - return q.size -} - -func (q *statsQueue) ReqSize() int { - return q.totalReqSize -} - -// FrontAndBack gets the front and back elements in the queue -// We must grab front and back together with the protection of the lock -func (q *statsQueue) frontAndBack() (*RequestStats, *RequestStats) { - q.rwl.RLock() - defer q.rwl.RUnlock() - if q.size != 0 { - return q.items[q.front], q.items[q.back] - } - return nil, nil -} - -// Insert function insert a RequestStats into the queue and update the records -func (q *statsQueue) Insert(p *RequestStats) { - q.rwl.Lock() - defer q.rwl.Unlock() - - q.back = (q.back + 1) % queueCapacity - - if q.size == queueCapacity { //dequeue - q.totalReqSize -= q.items[q.front].Size - q.front = (q.back + 1) % queueCapacity - } else { - q.size++ - } - - q.items[q.back] = p - q.totalReqSize += q.items[q.back].Size - -} - -// Rate function returns the package rate and byte rate -func (q *statsQueue) Rate() (float64, float64) { - front, back := q.frontAndBack() - - if front == nil || back == nil { - return 0, 0 - } - - if time.Since(back.SendingTime) > time.Second { - q.Clear() - return 0, 0 - } - - sampleDuration := back.SendingTime.Sub(front.SendingTime) - - pr := float64(q.Len()) / float64(sampleDuration) * float64(time.Second) - - br := float64(q.ReqSize()) / float64(sampleDuration) * float64(time.Second) - - return pr, br -} - -// Clear function clear up the statsQueue -func (q *statsQueue) Clear() { - q.rwl.Lock() - defer q.rwl.Unlock() - q.back = -1 - q.front = 0 - q.size = 0 - q.totalReqSize = 0 -} diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2stats/server.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2stats/server.go deleted file mode 100644 index 45effb1edc..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2stats/server.go +++ /dev/null @@ -1,142 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package v2stats - -import ( - "encoding/json" - "log" - "sync" - "time" - - "go.etcd.io/etcd/raft/v3" -) - -// ServerStats encapsulates various statistics about an EtcdServer and its -// communication with other members of the cluster -type ServerStats struct { - serverStats - sync.Mutex -} - -func NewServerStats(name, id string) *ServerStats { - ss := &ServerStats{ - serverStats: serverStats{ - Name: name, - ID: id, - }, - } - now := time.Now() - ss.StartTime = now - ss.LeaderInfo.StartTime = now - ss.sendRateQueue = &statsQueue{back: -1} - ss.recvRateQueue = &statsQueue{back: -1} - return ss -} - -type serverStats struct { - Name string `json:"name"` - // ID is the raft ID of the node. - // TODO(jonboulle): use ID instead of name? - ID string `json:"id"` - State raft.StateType `json:"state"` - StartTime time.Time `json:"startTime"` - - LeaderInfo struct { - Name string `json:"leader"` - Uptime string `json:"uptime"` - StartTime time.Time `json:"startTime"` - } `json:"leaderInfo"` - - RecvAppendRequestCnt uint64 `json:"recvAppendRequestCnt,"` - RecvingPkgRate float64 `json:"recvPkgRate,omitempty"` - RecvingBandwidthRate float64 `json:"recvBandwidthRate,omitempty"` - - SendAppendRequestCnt uint64 `json:"sendAppendRequestCnt"` - SendingPkgRate float64 `json:"sendPkgRate,omitempty"` - SendingBandwidthRate float64 `json:"sendBandwidthRate,omitempty"` - - sendRateQueue *statsQueue - recvRateQueue *statsQueue -} - -func (ss *ServerStats) JSON() []byte { - ss.Lock() - stats := ss.serverStats - stats.SendingPkgRate, stats.SendingBandwidthRate = stats.sendRateQueue.Rate() - stats.RecvingPkgRate, stats.RecvingBandwidthRate = stats.recvRateQueue.Rate() - stats.LeaderInfo.Uptime = time.Since(stats.LeaderInfo.StartTime).String() - ss.Unlock() - b, err := json.Marshal(stats) - // TODO(jonboulle): appropriate error handling? - if err != nil { - log.Printf("stats: error marshalling server stats: %v", err) - } - return b -} - -// RecvAppendReq updates the ServerStats in response to an AppendRequest -// from the given leader being received -func (ss *ServerStats) RecvAppendReq(leader string, reqSize int) { - ss.Lock() - defer ss.Unlock() - - now := time.Now() - - ss.State = raft.StateFollower - if leader != ss.LeaderInfo.Name { - ss.LeaderInfo.Name = leader - ss.LeaderInfo.StartTime = now - } - - ss.recvRateQueue.Insert( - &RequestStats{ - SendingTime: now, - Size: reqSize, - }, - ) - ss.RecvAppendRequestCnt++ -} - -// SendAppendReq updates the ServerStats in response to an AppendRequest -// being sent by this server -func (ss *ServerStats) SendAppendReq(reqSize int) { - ss.Lock() - defer ss.Unlock() - - ss.becomeLeader() - - ss.sendRateQueue.Insert( - &RequestStats{ - SendingTime: time.Now(), - Size: reqSize, - }, - ) - - ss.SendAppendRequestCnt++ -} - -func (ss *ServerStats) BecomeLeader() { - ss.Lock() - defer ss.Unlock() - ss.becomeLeader() -} - -func (ss *ServerStats) becomeLeader() { - if ss.State != raft.StateLeader { - ss.State = raft.StateLeader - ss.LeaderInfo.Name = ss.ID - ss.LeaderInfo.StartTime = time.Now() - } -} diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2stats/stats.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2stats/stats.go deleted file mode 100644 index cbf60215a2..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2stats/stats.go +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package v2stats defines a standard interface for etcd cluster statistics. -package v2stats - -type Stats interface { - // SelfStats returns the struct representing statistics of this server - SelfStats() []byte - // LeaderStats returns the statistics of all followers in the cluster - // if this server is leader. Otherwise, nil is returned. - LeaderStats() []byte - // StoreStats returns statistics of the store backing this EtcdServer - StoreStats() []byte -} diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2store/doc.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2store/doc.go deleted file mode 100644 index 1933e4cd5a..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2store/doc.go +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package v2store defines etcd's in-memory key/value store in v2 API. -// To be deprecated in favor of v3 storage. -package v2store diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2store/event.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2store/event.go deleted file mode 100644 index 33e901744d..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2store/event.go +++ /dev/null @@ -1,71 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package v2store - -const ( - Get = "get" - Create = "create" - Set = "set" - Update = "update" - Delete = "delete" - CompareAndSwap = "compareAndSwap" - CompareAndDelete = "compareAndDelete" - Expire = "expire" -) - -type Event struct { - Action string `json:"action"` - Node *NodeExtern `json:"node,omitempty"` - PrevNode *NodeExtern `json:"prevNode,omitempty"` - EtcdIndex uint64 `json:"-"` - Refresh bool `json:"refresh,omitempty"` -} - -func newEvent(action string, key string, modifiedIndex, createdIndex uint64) *Event { - n := &NodeExtern{ - Key: key, - ModifiedIndex: modifiedIndex, - CreatedIndex: createdIndex, - } - - return &Event{ - Action: action, - Node: n, - } -} - -func (e *Event) IsCreated() bool { - if e.Action == Create { - return true - } - return e.Action == Set && e.PrevNode == nil -} - -func (e *Event) Index() uint64 { - return e.Node.ModifiedIndex -} - -func (e *Event) Clone() *Event { - return &Event{ - Action: e.Action, - EtcdIndex: e.EtcdIndex, - Node: e.Node.Clone(), - PrevNode: e.PrevNode.Clone(), - } -} - -func (e *Event) SetRefresh() { - e.Refresh = true -} diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2store/event_history.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2store/event_history.go deleted file mode 100644 index c9bcdca051..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2store/event_history.go +++ /dev/null @@ -1,129 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package v2store - -import ( - "fmt" - "path" - "strings" - "sync" - - "go.etcd.io/etcd/server/v3/etcdserver/api/v2error" -) - -type EventHistory struct { - Queue eventQueue - StartIndex uint64 - LastIndex uint64 - rwl sync.RWMutex -} - -func newEventHistory(capacity int) *EventHistory { - return &EventHistory{ - Queue: eventQueue{ - Capacity: capacity, - Events: make([]*Event, capacity), - }, - } -} - -// addEvent function adds event into the eventHistory -func (eh *EventHistory) addEvent(e *Event) *Event { - eh.rwl.Lock() - defer eh.rwl.Unlock() - - eh.Queue.insert(e) - - eh.LastIndex = e.Index() - - eh.StartIndex = eh.Queue.Events[eh.Queue.Front].Index() - - return e -} - -// scan enumerates events from the index history and stops at the first point -// where the key matches. -func (eh *EventHistory) scan(key string, recursive bool, index uint64) (*Event, *v2error.Error) { - eh.rwl.RLock() - defer eh.rwl.RUnlock() - - // index should be after the event history's StartIndex - if index < eh.StartIndex { - return nil, - v2error.NewError(v2error.EcodeEventIndexCleared, - fmt.Sprintf("the requested history has been cleared [%v/%v]", - eh.StartIndex, index), 0) - } - - // the index should come before the size of the queue minus the duplicate count - if index > eh.LastIndex { // future index - return nil, nil - } - - offset := index - eh.StartIndex - i := (eh.Queue.Front + int(offset)) % eh.Queue.Capacity - - for { - e := eh.Queue.Events[i] - - if !e.Refresh { - ok := e.Node.Key == key - - if recursive { - // add tailing slash - nkey := path.Clean(key) - if nkey[len(nkey)-1] != '/' { - nkey = nkey + "/" - } - - ok = ok || strings.HasPrefix(e.Node.Key, nkey) - } - - if (e.Action == Delete || e.Action == Expire) && e.PrevNode != nil && e.PrevNode.Dir { - ok = ok || strings.HasPrefix(key, e.PrevNode.Key) - } - - if ok { - return e, nil - } - } - - i = (i + 1) % eh.Queue.Capacity - - if i == eh.Queue.Back { - return nil, nil - } - } -} - -// clone will be protected by a stop-world lock -// do not need to obtain internal lock -func (eh *EventHistory) clone() *EventHistory { - clonedQueue := eventQueue{ - Capacity: eh.Queue.Capacity, - Events: make([]*Event, eh.Queue.Capacity), - Size: eh.Queue.Size, - Front: eh.Queue.Front, - Back: eh.Queue.Back, - } - - copy(clonedQueue.Events, eh.Queue.Events) - return &EventHistory{ - StartIndex: eh.StartIndex, - Queue: clonedQueue, - LastIndex: eh.LastIndex, - } - -} diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2store/event_queue.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2store/event_queue.go deleted file mode 100644 index 7ea03de8c9..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2store/event_queue.go +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package v2store - -type eventQueue struct { - Events []*Event - Size int - Front int - Back int - Capacity int -} - -func (eq *eventQueue) insert(e *Event) { - eq.Events[eq.Back] = e - eq.Back = (eq.Back + 1) % eq.Capacity - - if eq.Size == eq.Capacity { //dequeue - eq.Front = (eq.Front + 1) % eq.Capacity - } else { - eq.Size++ - } -} diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2store/metrics.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2store/metrics.go deleted file mode 100644 index 5adea1efdd..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2store/metrics.go +++ /dev/null @@ -1,130 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package v2store - -import "github.com/prometheus/client_golang/prometheus" - -// Set of raw Prometheus metrics. -// Labels -// * action = declared in event.go -// * outcome = Outcome -// Do not increment directly, use Report* methods. -var ( - readCounter = prometheus.NewCounterVec( - prometheus.CounterOpts{ - Namespace: "etcd_debugging", - Subsystem: "store", - Name: "reads_total", - Help: "Total number of reads action by (get/getRecursive), local to this member.", - }, []string{"action"}) - - writeCounter = prometheus.NewCounterVec( - prometheus.CounterOpts{ - Namespace: "etcd_debugging", - Subsystem: "store", - Name: "writes_total", - Help: "Total number of writes (e.g. set/compareAndDelete) seen by this member.", - }, []string{"action"}) - - readFailedCounter = prometheus.NewCounterVec( - prometheus.CounterOpts{ - Namespace: "etcd_debugging", - Subsystem: "store", - Name: "reads_failed_total", - Help: "Failed read actions by (get/getRecursive), local to this member.", - }, []string{"action"}) - - writeFailedCounter = prometheus.NewCounterVec( - prometheus.CounterOpts{ - Namespace: "etcd_debugging", - Subsystem: "store", - Name: "writes_failed_total", - Help: "Failed write actions (e.g. set/compareAndDelete), seen by this member.", - }, []string{"action"}) - - expireCounter = prometheus.NewCounter( - prometheus.CounterOpts{ - Namespace: "etcd_debugging", - Subsystem: "store", - Name: "expires_total", - Help: "Total number of expired keys.", - }) - - watchRequests = prometheus.NewCounter( - prometheus.CounterOpts{ - Namespace: "etcd_debugging", - Subsystem: "store", - Name: "watch_requests_total", - Help: "Total number of incoming watch requests (new or reestablished).", - }) - - watcherCount = prometheus.NewGauge( - prometheus.GaugeOpts{ - Namespace: "etcd_debugging", - Subsystem: "store", - Name: "watchers", - Help: "Count of currently active watchers.", - }) -) - -const ( - GetRecursive = "getRecursive" -) - -func init() { - if prometheus.Register(readCounter) != nil { - // Tests will try to double register since the tests use both - // store and store_test packages; ignore second attempts. - return - } - prometheus.MustRegister(writeCounter) - prometheus.MustRegister(expireCounter) - prometheus.MustRegister(watchRequests) - prometheus.MustRegister(watcherCount) -} - -func reportReadSuccess(readAction string) { - readCounter.WithLabelValues(readAction).Inc() -} - -func reportReadFailure(readAction string) { - readCounter.WithLabelValues(readAction).Inc() - readFailedCounter.WithLabelValues(readAction).Inc() -} - -func reportWriteSuccess(writeAction string) { - writeCounter.WithLabelValues(writeAction).Inc() -} - -func reportWriteFailure(writeAction string) { - writeCounter.WithLabelValues(writeAction).Inc() - writeFailedCounter.WithLabelValues(writeAction).Inc() -} - -func reportExpiredKey() { - expireCounter.Inc() -} - -func reportWatchRequest() { - watchRequests.Inc() -} - -func reportWatcherAdded() { - watcherCount.Inc() -} - -func reportWatcherRemoved() { - watcherCount.Dec() -} diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2store/node.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2store/node.go deleted file mode 100644 index 9fe6263e2e..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2store/node.go +++ /dev/null @@ -1,396 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package v2store - -import ( - "path" - "sort" - "time" - - "go.etcd.io/etcd/server/v3/etcdserver/api/v2error" - - "github.com/jonboulle/clockwork" -) - -// explanations of Compare function result -const ( - CompareMatch = iota - CompareIndexNotMatch - CompareValueNotMatch - CompareNotMatch -) - -var Permanent time.Time - -// node is the basic element in the store system. -// A key-value pair will have a string value -// A directory will have a children map -type node struct { - Path string - - CreatedIndex uint64 - ModifiedIndex uint64 - - Parent *node `json:"-"` // should not encode this field! avoid circular dependency. - - ExpireTime time.Time - Value string // for key-value pair - Children map[string]*node // for directory - - // A reference to the store this node is attached to. - store *store -} - -// newKV creates a Key-Value pair -func newKV(store *store, nodePath string, value string, createdIndex uint64, parent *node, expireTime time.Time) *node { - return &node{ - Path: nodePath, - CreatedIndex: createdIndex, - ModifiedIndex: createdIndex, - Parent: parent, - store: store, - ExpireTime: expireTime, - Value: value, - } -} - -// newDir creates a directory -func newDir(store *store, nodePath string, createdIndex uint64, parent *node, expireTime time.Time) *node { - return &node{ - Path: nodePath, - CreatedIndex: createdIndex, - ModifiedIndex: createdIndex, - Parent: parent, - ExpireTime: expireTime, - Children: make(map[string]*node), - store: store, - } -} - -// IsHidden function checks if the node is a hidden node. A hidden node -// will begin with '_' -// A hidden node will not be shown via get command under a directory -// For example if we have /foo/_hidden and /foo/notHidden, get "/foo" -// will only return /foo/notHidden -func (n *node) IsHidden() bool { - _, name := path.Split(n.Path) - - return name[0] == '_' -} - -// IsPermanent function checks if the node is a permanent one. -func (n *node) IsPermanent() bool { - // we use a uninitialized time.Time to indicate the node is a - // permanent one. - // the uninitialized time.Time should equal zero. - return n.ExpireTime.IsZero() -} - -// IsDir function checks whether the node is a directory. -// If the node is a directory, the function will return true. -// Otherwise the function will return false. -func (n *node) IsDir() bool { - return n.Children != nil -} - -// Read function gets the value of the node. -// If the receiver node is not a key-value pair, a "Not A File" error will be returned. -func (n *node) Read() (string, *v2error.Error) { - if n.IsDir() { - return "", v2error.NewError(v2error.EcodeNotFile, "", n.store.CurrentIndex) - } - - return n.Value, nil -} - -// Write function set the value of the node to the given value. -// If the receiver node is a directory, a "Not A File" error will be returned. -func (n *node) Write(value string, index uint64) *v2error.Error { - if n.IsDir() { - return v2error.NewError(v2error.EcodeNotFile, "", n.store.CurrentIndex) - } - - n.Value = value - n.ModifiedIndex = index - - return nil -} - -func (n *node) expirationAndTTL(clock clockwork.Clock) (*time.Time, int64) { - if !n.IsPermanent() { - /* compute ttl as: - ceiling( (expireTime - timeNow) / nanosecondsPerSecond ) - which ranges from 1..n - rather than as: - ( (expireTime - timeNow) / nanosecondsPerSecond ) + 1 - which ranges 1..n+1 - */ - ttlN := n.ExpireTime.Sub(clock.Now()) - ttl := ttlN / time.Second - if (ttlN % time.Second) > 0 { - ttl++ - } - t := n.ExpireTime.UTC() - return &t, int64(ttl) - } - return nil, 0 -} - -// List function return a slice of nodes under the receiver node. -// If the receiver node is not a directory, a "Not A Directory" error will be returned. -func (n *node) List() ([]*node, *v2error.Error) { - if !n.IsDir() { - return nil, v2error.NewError(v2error.EcodeNotDir, "", n.store.CurrentIndex) - } - - nodes := make([]*node, len(n.Children)) - - i := 0 - for _, node := range n.Children { - nodes[i] = node - i++ - } - - return nodes, nil -} - -// GetChild function returns the child node under the directory node. -// On success, it returns the file node -func (n *node) GetChild(name string) (*node, *v2error.Error) { - if !n.IsDir() { - return nil, v2error.NewError(v2error.EcodeNotDir, n.Path, n.store.CurrentIndex) - } - - child, ok := n.Children[name] - - if ok { - return child, nil - } - - return nil, nil -} - -// Add function adds a node to the receiver node. -// If the receiver is not a directory, a "Not A Directory" error will be returned. -// If there is an existing node with the same name under the directory, a "Already Exist" -// error will be returned -func (n *node) Add(child *node) *v2error.Error { - if !n.IsDir() { - return v2error.NewError(v2error.EcodeNotDir, "", n.store.CurrentIndex) - } - - _, name := path.Split(child.Path) - - if _, ok := n.Children[name]; ok { - return v2error.NewError(v2error.EcodeNodeExist, "", n.store.CurrentIndex) - } - - n.Children[name] = child - - return nil -} - -// Remove function remove the node. -func (n *node) Remove(dir, recursive bool, callback func(path string)) *v2error.Error { - if !n.IsDir() { // key-value pair - _, name := path.Split(n.Path) - - // find its parent and remove the node from the map - if n.Parent != nil && n.Parent.Children[name] == n { - delete(n.Parent.Children, name) - } - - if callback != nil { - callback(n.Path) - } - - if !n.IsPermanent() { - n.store.ttlKeyHeap.remove(n) - } - - return nil - } - - if !dir { - // cannot delete a directory without dir set to true - return v2error.NewError(v2error.EcodeNotFile, n.Path, n.store.CurrentIndex) - } - - if len(n.Children) != 0 && !recursive { - // cannot delete a directory if it is not empty and the operation - // is not recursive - return v2error.NewError(v2error.EcodeDirNotEmpty, n.Path, n.store.CurrentIndex) - } - - for _, child := range n.Children { // delete all children - child.Remove(true, true, callback) - } - - // delete self - _, name := path.Split(n.Path) - if n.Parent != nil && n.Parent.Children[name] == n { - delete(n.Parent.Children, name) - - if callback != nil { - callback(n.Path) - } - - if !n.IsPermanent() { - n.store.ttlKeyHeap.remove(n) - } - } - - return nil -} - -func (n *node) Repr(recursive, sorted bool, clock clockwork.Clock) *NodeExtern { - if n.IsDir() { - node := &NodeExtern{ - Key: n.Path, - Dir: true, - ModifiedIndex: n.ModifiedIndex, - CreatedIndex: n.CreatedIndex, - } - node.Expiration, node.TTL = n.expirationAndTTL(clock) - - if !recursive { - return node - } - - children, _ := n.List() - node.Nodes = make(NodeExterns, len(children)) - - // we do not use the index in the children slice directly - // we need to skip the hidden one - i := 0 - - for _, child := range children { - - if child.IsHidden() { // get will not list hidden node - continue - } - - node.Nodes[i] = child.Repr(recursive, sorted, clock) - - i++ - } - - // eliminate hidden nodes - node.Nodes = node.Nodes[:i] - if sorted { - sort.Sort(node.Nodes) - } - - return node - } - - // since n.Value could be changed later, so we need to copy the value out - value := n.Value - node := &NodeExtern{ - Key: n.Path, - Value: &value, - ModifiedIndex: n.ModifiedIndex, - CreatedIndex: n.CreatedIndex, - } - node.Expiration, node.TTL = n.expirationAndTTL(clock) - return node -} - -func (n *node) UpdateTTL(expireTime time.Time) { - if !n.IsPermanent() { - if expireTime.IsZero() { - // from ttl to permanent - n.ExpireTime = expireTime - // remove from ttl heap - n.store.ttlKeyHeap.remove(n) - return - } - - // update ttl - n.ExpireTime = expireTime - // update ttl heap - n.store.ttlKeyHeap.update(n) - return - } - - if expireTime.IsZero() { - return - } - - // from permanent to ttl - n.ExpireTime = expireTime - // push into ttl heap - n.store.ttlKeyHeap.push(n) -} - -// Compare function compares node index and value with provided ones. -// second result value explains result and equals to one of Compare.. constants -func (n *node) Compare(prevValue string, prevIndex uint64) (ok bool, which int) { - indexMatch := prevIndex == 0 || n.ModifiedIndex == prevIndex - valueMatch := prevValue == "" || n.Value == prevValue - ok = valueMatch && indexMatch - switch { - case valueMatch && indexMatch: - which = CompareMatch - case indexMatch && !valueMatch: - which = CompareValueNotMatch - case valueMatch && !indexMatch: - which = CompareIndexNotMatch - default: - which = CompareNotMatch - } - return ok, which -} - -// Clone function clone the node recursively and return the new node. -// If the node is a directory, it will clone all the content under this directory. -// If the node is a key-value pair, it will clone the pair. -func (n *node) Clone() *node { - if !n.IsDir() { - newkv := newKV(n.store, n.Path, n.Value, n.CreatedIndex, n.Parent, n.ExpireTime) - newkv.ModifiedIndex = n.ModifiedIndex - return newkv - } - - clone := newDir(n.store, n.Path, n.CreatedIndex, n.Parent, n.ExpireTime) - clone.ModifiedIndex = n.ModifiedIndex - - for key, child := range n.Children { - clone.Children[key] = child.Clone() - } - - return clone -} - -// recoverAndclean function help to do recovery. -// Two things need to be done: 1. recovery structure; 2. delete expired nodes -// -// If the node is a directory, it will help recover children's parent pointer and recursively -// call this function on its children. -// We check the expire last since we need to recover the whole structure first and add all the -// notifications into the event history. -func (n *node) recoverAndclean() { - if n.IsDir() { - for _, child := range n.Children { - child.Parent = n - child.store = n.store - child.recoverAndclean() - } - } - - if !n.ExpireTime.IsZero() { - n.store.ttlKeyHeap.push(n) - } -} diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2store/node_extern.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2store/node_extern.go deleted file mode 100644 index b3bf5f3c97..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2store/node_extern.go +++ /dev/null @@ -1,116 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package v2store - -import ( - "sort" - "time" - - "github.com/jonboulle/clockwork" -) - -// NodeExtern is the external representation of the -// internal node with additional fields -// PrevValue is the previous value of the node -// TTL is time to live in second -type NodeExtern struct { - Key string `json:"key,omitempty"` - Value *string `json:"value,omitempty"` - Dir bool `json:"dir,omitempty"` - Expiration *time.Time `json:"expiration,omitempty"` - TTL int64 `json:"ttl,omitempty"` - Nodes NodeExterns `json:"nodes,omitempty"` - ModifiedIndex uint64 `json:"modifiedIndex,omitempty"` - CreatedIndex uint64 `json:"createdIndex,omitempty"` -} - -func (eNode *NodeExtern) loadInternalNode(n *node, recursive, sorted bool, clock clockwork.Clock) { - if n.IsDir() { // node is a directory - eNode.Dir = true - - children, _ := n.List() - eNode.Nodes = make(NodeExterns, len(children)) - - // we do not use the index in the children slice directly - // we need to skip the hidden one - i := 0 - - for _, child := range children { - if child.IsHidden() { // get will not return hidden nodes - continue - } - - eNode.Nodes[i] = child.Repr(recursive, sorted, clock) - i++ - } - - // eliminate hidden nodes - eNode.Nodes = eNode.Nodes[:i] - - if sorted { - sort.Sort(eNode.Nodes) - } - - } else { // node is a file - value, _ := n.Read() - eNode.Value = &value - } - - eNode.Expiration, eNode.TTL = n.expirationAndTTL(clock) -} - -func (eNode *NodeExtern) Clone() *NodeExtern { - if eNode == nil { - return nil - } - nn := &NodeExtern{ - Key: eNode.Key, - Dir: eNode.Dir, - TTL: eNode.TTL, - ModifiedIndex: eNode.ModifiedIndex, - CreatedIndex: eNode.CreatedIndex, - } - if eNode.Value != nil { - s := *eNode.Value - nn.Value = &s - } - if eNode.Expiration != nil { - t := *eNode.Expiration - nn.Expiration = &t - } - if eNode.Nodes != nil { - nn.Nodes = make(NodeExterns, len(eNode.Nodes)) - for i, n := range eNode.Nodes { - nn.Nodes[i] = n.Clone() - } - } - return nn -} - -type NodeExterns []*NodeExtern - -// interfaces for sorting - -func (ns NodeExterns) Len() int { - return len(ns) -} - -func (ns NodeExterns) Less(i, j int) bool { - return ns[i].Key < ns[j].Key -} - -func (ns NodeExterns) Swap(i, j int) { - ns[i], ns[j] = ns[j], ns[i] -} diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2store/stats.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2store/stats.go deleted file mode 100644 index 9151799da7..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2store/stats.go +++ /dev/null @@ -1,145 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package v2store - -import ( - "encoding/json" - "sync/atomic" -) - -const ( - SetSuccess = iota - SetFail - DeleteSuccess - DeleteFail - CreateSuccess - CreateFail - UpdateSuccess - UpdateFail - CompareAndSwapSuccess - CompareAndSwapFail - GetSuccess - GetFail - ExpireCount - CompareAndDeleteSuccess - CompareAndDeleteFail -) - -type Stats struct { - // Number of get requests - - GetSuccess uint64 `json:"getsSuccess"` - GetFail uint64 `json:"getsFail"` - - // Number of sets requests - - SetSuccess uint64 `json:"setsSuccess"` - SetFail uint64 `json:"setsFail"` - - // Number of delete requests - - DeleteSuccess uint64 `json:"deleteSuccess"` - DeleteFail uint64 `json:"deleteFail"` - - // Number of update requests - - UpdateSuccess uint64 `json:"updateSuccess"` - UpdateFail uint64 `json:"updateFail"` - - // Number of create requests - - CreateSuccess uint64 `json:"createSuccess"` - CreateFail uint64 `json:"createFail"` - - // Number of testAndSet requests - - CompareAndSwapSuccess uint64 `json:"compareAndSwapSuccess"` - CompareAndSwapFail uint64 `json:"compareAndSwapFail"` - - // Number of compareAndDelete requests - - CompareAndDeleteSuccess uint64 `json:"compareAndDeleteSuccess"` - CompareAndDeleteFail uint64 `json:"compareAndDeleteFail"` - - ExpireCount uint64 `json:"expireCount"` - - Watchers uint64 `json:"watchers"` -} - -func newStats() *Stats { - s := new(Stats) - return s -} - -func (s *Stats) clone() *Stats { - return &Stats{ - GetSuccess: atomic.LoadUint64(&s.GetSuccess), - GetFail: atomic.LoadUint64(&s.GetFail), - SetSuccess: atomic.LoadUint64(&s.SetSuccess), - SetFail: atomic.LoadUint64(&s.SetFail), - DeleteSuccess: atomic.LoadUint64(&s.DeleteSuccess), - DeleteFail: atomic.LoadUint64(&s.DeleteFail), - UpdateSuccess: atomic.LoadUint64(&s.UpdateSuccess), - UpdateFail: atomic.LoadUint64(&s.UpdateFail), - CreateSuccess: atomic.LoadUint64(&s.CreateSuccess), - CreateFail: atomic.LoadUint64(&s.CreateFail), - CompareAndSwapSuccess: atomic.LoadUint64(&s.CompareAndSwapSuccess), - CompareAndSwapFail: atomic.LoadUint64(&s.CompareAndSwapFail), - CompareAndDeleteSuccess: atomic.LoadUint64(&s.CompareAndDeleteSuccess), - CompareAndDeleteFail: atomic.LoadUint64(&s.CompareAndDeleteFail), - ExpireCount: atomic.LoadUint64(&s.ExpireCount), - Watchers: atomic.LoadUint64(&s.Watchers), - } -} - -func (s *Stats) toJson() []byte { - b, _ := json.Marshal(s) - return b -} - -func (s *Stats) Inc(field int) { - switch field { - case SetSuccess: - atomic.AddUint64(&s.SetSuccess, 1) - case SetFail: - atomic.AddUint64(&s.SetFail, 1) - case CreateSuccess: - atomic.AddUint64(&s.CreateSuccess, 1) - case CreateFail: - atomic.AddUint64(&s.CreateFail, 1) - case DeleteSuccess: - atomic.AddUint64(&s.DeleteSuccess, 1) - case DeleteFail: - atomic.AddUint64(&s.DeleteFail, 1) - case GetSuccess: - atomic.AddUint64(&s.GetSuccess, 1) - case GetFail: - atomic.AddUint64(&s.GetFail, 1) - case UpdateSuccess: - atomic.AddUint64(&s.UpdateSuccess, 1) - case UpdateFail: - atomic.AddUint64(&s.UpdateFail, 1) - case CompareAndSwapSuccess: - atomic.AddUint64(&s.CompareAndSwapSuccess, 1) - case CompareAndSwapFail: - atomic.AddUint64(&s.CompareAndSwapFail, 1) - case CompareAndDeleteSuccess: - atomic.AddUint64(&s.CompareAndDeleteSuccess, 1) - case CompareAndDeleteFail: - atomic.AddUint64(&s.CompareAndDeleteFail, 1) - case ExpireCount: - atomic.AddUint64(&s.ExpireCount, 1) - } -} diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2store/store.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2store/store.go deleted file mode 100644 index 32cb26ad96..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2store/store.go +++ /dev/null @@ -1,799 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package v2store - -import ( - "encoding/json" - "fmt" - "path" - "strconv" - "strings" - "sync" - "time" - - "go.etcd.io/etcd/client/pkg/v3/types" - "go.etcd.io/etcd/server/v3/etcdserver/api/v2error" - - "github.com/jonboulle/clockwork" -) - -// The default version to set when the store is first initialized. -const defaultVersion = 2 - -var minExpireTime time.Time - -func init() { - minExpireTime, _ = time.Parse(time.RFC3339, "2000-01-01T00:00:00Z") -} - -type Store interface { - Version() int - Index() uint64 - - Get(nodePath string, recursive, sorted bool) (*Event, error) - Set(nodePath string, dir bool, value string, expireOpts TTLOptionSet) (*Event, error) - Update(nodePath string, newValue string, expireOpts TTLOptionSet) (*Event, error) - Create(nodePath string, dir bool, value string, unique bool, - expireOpts TTLOptionSet) (*Event, error) - CompareAndSwap(nodePath string, prevValue string, prevIndex uint64, - value string, expireOpts TTLOptionSet) (*Event, error) - Delete(nodePath string, dir, recursive bool) (*Event, error) - CompareAndDelete(nodePath string, prevValue string, prevIndex uint64) (*Event, error) - - Watch(prefix string, recursive, stream bool, sinceIndex uint64) (Watcher, error) - - Save() ([]byte, error) - Recovery(state []byte) error - - Clone() Store - SaveNoCopy() ([]byte, error) - - JsonStats() []byte - DeleteExpiredKeys(cutoff time.Time) - - HasTTLKeys() bool -} - -type TTLOptionSet struct { - ExpireTime time.Time - Refresh bool -} - -type store struct { - Root *node - WatcherHub *watcherHub - CurrentIndex uint64 - Stats *Stats - CurrentVersion int - ttlKeyHeap *ttlKeyHeap // need to recovery manually - worldLock sync.RWMutex // stop the world lock - clock clockwork.Clock - readonlySet types.Set -} - -// New creates a store where the given namespaces will be created as initial directories. -func New(namespaces ...string) Store { - s := newStore(namespaces...) - s.clock = clockwork.NewRealClock() - return s -} - -func newStore(namespaces ...string) *store { - s := new(store) - s.CurrentVersion = defaultVersion - s.Root = newDir(s, "/", s.CurrentIndex, nil, Permanent) - for _, namespace := range namespaces { - s.Root.Add(newDir(s, namespace, s.CurrentIndex, s.Root, Permanent)) - } - s.Stats = newStats() - s.WatcherHub = newWatchHub(1000) - s.ttlKeyHeap = newTtlKeyHeap() - s.readonlySet = types.NewUnsafeSet(append(namespaces, "/")...) - return s -} - -// Version retrieves current version of the store. -func (s *store) Version() int { - return s.CurrentVersion -} - -// Index retrieves the current index of the store. -func (s *store) Index() uint64 { - s.worldLock.RLock() - defer s.worldLock.RUnlock() - return s.CurrentIndex -} - -// Get returns a get event. -// If recursive is true, it will return all the content under the node path. -// If sorted is true, it will sort the content by keys. -func (s *store) Get(nodePath string, recursive, sorted bool) (*Event, error) { - var err *v2error.Error - - s.worldLock.RLock() - defer s.worldLock.RUnlock() - - defer func() { - if err == nil { - s.Stats.Inc(GetSuccess) - if recursive { - reportReadSuccess(GetRecursive) - } else { - reportReadSuccess(Get) - } - return - } - - s.Stats.Inc(GetFail) - if recursive { - reportReadFailure(GetRecursive) - } else { - reportReadFailure(Get) - } - }() - - n, err := s.internalGet(nodePath) - if err != nil { - return nil, err - } - - e := newEvent(Get, nodePath, n.ModifiedIndex, n.CreatedIndex) - e.EtcdIndex = s.CurrentIndex - e.Node.loadInternalNode(n, recursive, sorted, s.clock) - - return e, nil -} - -// Create creates the node at nodePath. Create will help to create intermediate directories with no ttl. -// If the node has already existed, create will fail. -// If any node on the path is a file, create will fail. -func (s *store) Create(nodePath string, dir bool, value string, unique bool, expireOpts TTLOptionSet) (*Event, error) { - var err *v2error.Error - - s.worldLock.Lock() - defer s.worldLock.Unlock() - - defer func() { - if err == nil { - s.Stats.Inc(CreateSuccess) - reportWriteSuccess(Create) - return - } - - s.Stats.Inc(CreateFail) - reportWriteFailure(Create) - }() - - e, err := s.internalCreate(nodePath, dir, value, unique, false, expireOpts.ExpireTime, Create) - if err != nil { - return nil, err - } - - e.EtcdIndex = s.CurrentIndex - s.WatcherHub.notify(e) - - return e, nil -} - -// Set creates or replace the node at nodePath. -func (s *store) Set(nodePath string, dir bool, value string, expireOpts TTLOptionSet) (*Event, error) { - var err *v2error.Error - - s.worldLock.Lock() - defer s.worldLock.Unlock() - - defer func() { - if err == nil { - s.Stats.Inc(SetSuccess) - reportWriteSuccess(Set) - return - } - - s.Stats.Inc(SetFail) - reportWriteFailure(Set) - }() - - // Get prevNode value - n, getErr := s.internalGet(nodePath) - if getErr != nil && getErr.ErrorCode != v2error.EcodeKeyNotFound { - err = getErr - return nil, err - } - - if expireOpts.Refresh { - if getErr != nil { - err = getErr - return nil, err - } - value = n.Value - } - - // Set new value - e, err := s.internalCreate(nodePath, dir, value, false, true, expireOpts.ExpireTime, Set) - if err != nil { - return nil, err - } - e.EtcdIndex = s.CurrentIndex - - // Put prevNode into event - if getErr == nil { - prev := newEvent(Get, nodePath, n.ModifiedIndex, n.CreatedIndex) - prev.Node.loadInternalNode(n, false, false, s.clock) - e.PrevNode = prev.Node - } - - if !expireOpts.Refresh { - s.WatcherHub.notify(e) - } else { - e.SetRefresh() - s.WatcherHub.add(e) - } - - return e, nil -} - -// returns user-readable cause of failed comparison -func getCompareFailCause(n *node, which int, prevValue string, prevIndex uint64) string { - switch which { - case CompareIndexNotMatch: - return fmt.Sprintf("[%v != %v]", prevIndex, n.ModifiedIndex) - case CompareValueNotMatch: - return fmt.Sprintf("[%v != %v]", prevValue, n.Value) - default: - return fmt.Sprintf("[%v != %v] [%v != %v]", prevValue, n.Value, prevIndex, n.ModifiedIndex) - } -} - -func (s *store) CompareAndSwap(nodePath string, prevValue string, prevIndex uint64, - value string, expireOpts TTLOptionSet) (*Event, error) { - - var err *v2error.Error - - s.worldLock.Lock() - defer s.worldLock.Unlock() - - defer func() { - if err == nil { - s.Stats.Inc(CompareAndSwapSuccess) - reportWriteSuccess(CompareAndSwap) - return - } - - s.Stats.Inc(CompareAndSwapFail) - reportWriteFailure(CompareAndSwap) - }() - - nodePath = path.Clean(path.Join("/", nodePath)) - // we do not allow the user to change "/" - if s.readonlySet.Contains(nodePath) { - return nil, v2error.NewError(v2error.EcodeRootROnly, "/", s.CurrentIndex) - } - - n, err := s.internalGet(nodePath) - if err != nil { - return nil, err - } - if n.IsDir() { // can only compare and swap file - err = v2error.NewError(v2error.EcodeNotFile, nodePath, s.CurrentIndex) - return nil, err - } - - // If both of the prevValue and prevIndex are given, we will test both of them. - // Command will be executed, only if both of the tests are successful. - if ok, which := n.Compare(prevValue, prevIndex); !ok { - cause := getCompareFailCause(n, which, prevValue, prevIndex) - err = v2error.NewError(v2error.EcodeTestFailed, cause, s.CurrentIndex) - return nil, err - } - - if expireOpts.Refresh { - value = n.Value - } - - // update etcd index - s.CurrentIndex++ - - e := newEvent(CompareAndSwap, nodePath, s.CurrentIndex, n.CreatedIndex) - e.EtcdIndex = s.CurrentIndex - e.PrevNode = n.Repr(false, false, s.clock) - eNode := e.Node - - // if test succeed, write the value - if err := n.Write(value, s.CurrentIndex); err != nil { - return nil, err - } - n.UpdateTTL(expireOpts.ExpireTime) - - // copy the value for safety - valueCopy := value - eNode.Value = &valueCopy - eNode.Expiration, eNode.TTL = n.expirationAndTTL(s.clock) - - if !expireOpts.Refresh { - s.WatcherHub.notify(e) - } else { - e.SetRefresh() - s.WatcherHub.add(e) - } - - return e, nil -} - -// Delete deletes the node at the given path. -// If the node is a directory, recursive must be true to delete it. -func (s *store) Delete(nodePath string, dir, recursive bool) (*Event, error) { - var err *v2error.Error - - s.worldLock.Lock() - defer s.worldLock.Unlock() - - defer func() { - if err == nil { - s.Stats.Inc(DeleteSuccess) - reportWriteSuccess(Delete) - return - } - - s.Stats.Inc(DeleteFail) - reportWriteFailure(Delete) - }() - - nodePath = path.Clean(path.Join("/", nodePath)) - // we do not allow the user to change "/" - if s.readonlySet.Contains(nodePath) { - return nil, v2error.NewError(v2error.EcodeRootROnly, "/", s.CurrentIndex) - } - - // recursive implies dir - if recursive { - dir = true - } - - n, err := s.internalGet(nodePath) - if err != nil { // if the node does not exist, return error - return nil, err - } - - nextIndex := s.CurrentIndex + 1 - e := newEvent(Delete, nodePath, nextIndex, n.CreatedIndex) - e.EtcdIndex = nextIndex - e.PrevNode = n.Repr(false, false, s.clock) - eNode := e.Node - - if n.IsDir() { - eNode.Dir = true - } - - callback := func(path string) { // notify function - // notify the watchers with deleted set true - s.WatcherHub.notifyWatchers(e, path, true) - } - - err = n.Remove(dir, recursive, callback) - if err != nil { - return nil, err - } - - // update etcd index - s.CurrentIndex++ - - s.WatcherHub.notify(e) - - return e, nil -} - -func (s *store) CompareAndDelete(nodePath string, prevValue string, prevIndex uint64) (*Event, error) { - var err *v2error.Error - - s.worldLock.Lock() - defer s.worldLock.Unlock() - - defer func() { - if err == nil { - s.Stats.Inc(CompareAndDeleteSuccess) - reportWriteSuccess(CompareAndDelete) - return - } - - s.Stats.Inc(CompareAndDeleteFail) - reportWriteFailure(CompareAndDelete) - }() - - nodePath = path.Clean(path.Join("/", nodePath)) - - n, err := s.internalGet(nodePath) - if err != nil { // if the node does not exist, return error - return nil, err - } - if n.IsDir() { // can only compare and delete file - return nil, v2error.NewError(v2error.EcodeNotFile, nodePath, s.CurrentIndex) - } - - // If both of the prevValue and prevIndex are given, we will test both of them. - // Command will be executed, only if both of the tests are successful. - if ok, which := n.Compare(prevValue, prevIndex); !ok { - cause := getCompareFailCause(n, which, prevValue, prevIndex) - return nil, v2error.NewError(v2error.EcodeTestFailed, cause, s.CurrentIndex) - } - - // update etcd index - s.CurrentIndex++ - - e := newEvent(CompareAndDelete, nodePath, s.CurrentIndex, n.CreatedIndex) - e.EtcdIndex = s.CurrentIndex - e.PrevNode = n.Repr(false, false, s.clock) - - callback := func(path string) { // notify function - // notify the watchers with deleted set true - s.WatcherHub.notifyWatchers(e, path, true) - } - - err = n.Remove(false, false, callback) - if err != nil { - return nil, err - } - - s.WatcherHub.notify(e) - - return e, nil -} - -func (s *store) Watch(key string, recursive, stream bool, sinceIndex uint64) (Watcher, error) { - s.worldLock.RLock() - defer s.worldLock.RUnlock() - - key = path.Clean(path.Join("/", key)) - if sinceIndex == 0 { - sinceIndex = s.CurrentIndex + 1 - } - // WatcherHub does not know about the current index, so we need to pass it in - w, err := s.WatcherHub.watch(key, recursive, stream, sinceIndex, s.CurrentIndex) - if err != nil { - return nil, err - } - - return w, nil -} - -// walk walks all the nodePath and apply the walkFunc on each directory -func (s *store) walk(nodePath string, walkFunc func(prev *node, component string) (*node, *v2error.Error)) (*node, *v2error.Error) { - components := strings.Split(nodePath, "/") - - curr := s.Root - var err *v2error.Error - - for i := 1; i < len(components); i++ { - if len(components[i]) == 0 { // ignore empty string - return curr, nil - } - - curr, err = walkFunc(curr, components[i]) - if err != nil { - return nil, err - } - } - - return curr, nil -} - -// Update updates the value/ttl of the node. -// If the node is a file, the value and the ttl can be updated. -// If the node is a directory, only the ttl can be updated. -func (s *store) Update(nodePath string, newValue string, expireOpts TTLOptionSet) (*Event, error) { - var err *v2error.Error - - s.worldLock.Lock() - defer s.worldLock.Unlock() - - defer func() { - if err == nil { - s.Stats.Inc(UpdateSuccess) - reportWriteSuccess(Update) - return - } - - s.Stats.Inc(UpdateFail) - reportWriteFailure(Update) - }() - - nodePath = path.Clean(path.Join("/", nodePath)) - // we do not allow the user to change "/" - if s.readonlySet.Contains(nodePath) { - return nil, v2error.NewError(v2error.EcodeRootROnly, "/", s.CurrentIndex) - } - - currIndex, nextIndex := s.CurrentIndex, s.CurrentIndex+1 - - n, err := s.internalGet(nodePath) - if err != nil { // if the node does not exist, return error - return nil, err - } - if n.IsDir() && len(newValue) != 0 { - // if the node is a directory, we cannot update value to non-empty - return nil, v2error.NewError(v2error.EcodeNotFile, nodePath, currIndex) - } - - if expireOpts.Refresh { - newValue = n.Value - } - - e := newEvent(Update, nodePath, nextIndex, n.CreatedIndex) - e.EtcdIndex = nextIndex - e.PrevNode = n.Repr(false, false, s.clock) - eNode := e.Node - - if err := n.Write(newValue, nextIndex); err != nil { - return nil, fmt.Errorf("nodePath %v : %v", nodePath, err) - } - - if n.IsDir() { - eNode.Dir = true - } else { - // copy the value for safety - newValueCopy := newValue - eNode.Value = &newValueCopy - } - - // update ttl - n.UpdateTTL(expireOpts.ExpireTime) - - eNode.Expiration, eNode.TTL = n.expirationAndTTL(s.clock) - - if !expireOpts.Refresh { - s.WatcherHub.notify(e) - } else { - e.SetRefresh() - s.WatcherHub.add(e) - } - - s.CurrentIndex = nextIndex - - return e, nil -} - -func (s *store) internalCreate(nodePath string, dir bool, value string, unique, replace bool, - expireTime time.Time, action string) (*Event, *v2error.Error) { - - currIndex, nextIndex := s.CurrentIndex, s.CurrentIndex+1 - - if unique { // append unique item under the node path - nodePath += "/" + fmt.Sprintf("%020s", strconv.FormatUint(nextIndex, 10)) - } - - nodePath = path.Clean(path.Join("/", nodePath)) - - // we do not allow the user to change "/" - if s.readonlySet.Contains(nodePath) { - return nil, v2error.NewError(v2error.EcodeRootROnly, "/", currIndex) - } - - // Assume expire times that are way in the past are - // This can occur when the time is serialized to JS - if expireTime.Before(minExpireTime) { - expireTime = Permanent - } - - dirName, nodeName := path.Split(nodePath) - - // walk through the nodePath, create dirs and get the last directory node - d, err := s.walk(dirName, s.checkDir) - - if err != nil { - s.Stats.Inc(SetFail) - reportWriteFailure(action) - err.Index = currIndex - return nil, err - } - - e := newEvent(action, nodePath, nextIndex, nextIndex) - eNode := e.Node - - n, _ := d.GetChild(nodeName) - - // force will try to replace an existing file - if n != nil { - if replace { - if n.IsDir() { - return nil, v2error.NewError(v2error.EcodeNotFile, nodePath, currIndex) - } - e.PrevNode = n.Repr(false, false, s.clock) - - if err := n.Remove(false, false, nil); err != nil { - return nil, err - } - } else { - return nil, v2error.NewError(v2error.EcodeNodeExist, nodePath, currIndex) - } - } - - if !dir { // create file - // copy the value for safety - valueCopy := value - eNode.Value = &valueCopy - - n = newKV(s, nodePath, value, nextIndex, d, expireTime) - - } else { // create directory - eNode.Dir = true - - n = newDir(s, nodePath, nextIndex, d, expireTime) - } - - // we are sure d is a directory and does not have the children with name n.Name - if err := d.Add(n); err != nil { - return nil, err - } - - // node with TTL - if !n.IsPermanent() { - s.ttlKeyHeap.push(n) - - eNode.Expiration, eNode.TTL = n.expirationAndTTL(s.clock) - } - - s.CurrentIndex = nextIndex - - return e, nil -} - -// InternalGet gets the node of the given nodePath. -func (s *store) internalGet(nodePath string) (*node, *v2error.Error) { - nodePath = path.Clean(path.Join("/", nodePath)) - - walkFunc := func(parent *node, name string) (*node, *v2error.Error) { - - if !parent.IsDir() { - err := v2error.NewError(v2error.EcodeNotDir, parent.Path, s.CurrentIndex) - return nil, err - } - - child, ok := parent.Children[name] - if ok { - return child, nil - } - - return nil, v2error.NewError(v2error.EcodeKeyNotFound, path.Join(parent.Path, name), s.CurrentIndex) - } - - f, err := s.walk(nodePath, walkFunc) - - if err != nil { - return nil, err - } - return f, nil -} - -// DeleteExpiredKeys will delete all expired keys -func (s *store) DeleteExpiredKeys(cutoff time.Time) { - s.worldLock.Lock() - defer s.worldLock.Unlock() - - for { - node := s.ttlKeyHeap.top() - if node == nil || node.ExpireTime.After(cutoff) { - break - } - - s.CurrentIndex++ - e := newEvent(Expire, node.Path, s.CurrentIndex, node.CreatedIndex) - e.EtcdIndex = s.CurrentIndex - e.PrevNode = node.Repr(false, false, s.clock) - if node.IsDir() { - e.Node.Dir = true - } - - callback := func(path string) { // notify function - // notify the watchers with deleted set true - s.WatcherHub.notifyWatchers(e, path, true) - } - - s.ttlKeyHeap.pop() - node.Remove(true, true, callback) - - reportExpiredKey() - s.Stats.Inc(ExpireCount) - - s.WatcherHub.notify(e) - } - -} - -// checkDir will check whether the component is a directory under parent node. -// If it is a directory, this function will return the pointer to that node. -// If it does not exist, this function will create a new directory and return the pointer to that node. -// If it is a file, this function will return error. -func (s *store) checkDir(parent *node, dirName string) (*node, *v2error.Error) { - node, ok := parent.Children[dirName] - - if ok { - if node.IsDir() { - return node, nil - } - - return nil, v2error.NewError(v2error.EcodeNotDir, node.Path, s.CurrentIndex) - } - - n := newDir(s, path.Join(parent.Path, dirName), s.CurrentIndex+1, parent, Permanent) - - parent.Children[dirName] = n - - return n, nil -} - -// Save saves the static state of the store system. -// It will not be able to save the state of watchers. -// It will not save the parent field of the node. Or there will -// be cyclic dependencies issue for the json package. -func (s *store) Save() ([]byte, error) { - b, err := json.Marshal(s.Clone()) - if err != nil { - return nil, err - } - - return b, nil -} - -func (s *store) SaveNoCopy() ([]byte, error) { - b, err := json.Marshal(s) - if err != nil { - return nil, err - } - - return b, nil -} - -func (s *store) Clone() Store { - s.worldLock.RLock() - - clonedStore := newStore() - clonedStore.CurrentIndex = s.CurrentIndex - clonedStore.Root = s.Root.Clone() - clonedStore.WatcherHub = s.WatcherHub.clone() - clonedStore.Stats = s.Stats.clone() - clonedStore.CurrentVersion = s.CurrentVersion - - s.worldLock.RUnlock() - return clonedStore -} - -// Recovery recovers the store system from a static state -// It needs to recover the parent field of the nodes. -// It needs to delete the expired nodes since the saved time and also -// needs to create monitoring goroutines. -func (s *store) Recovery(state []byte) error { - s.worldLock.Lock() - defer s.worldLock.Unlock() - err := json.Unmarshal(state, s) - - if err != nil { - return err - } - - s.ttlKeyHeap = newTtlKeyHeap() - - s.Root.recoverAndclean() - return nil -} - -func (s *store) JsonStats() []byte { - s.Stats.Watchers = uint64(s.WatcherHub.count) - return s.Stats.toJson() -} - -func (s *store) HasTTLKeys() bool { - s.worldLock.RLock() - defer s.worldLock.RUnlock() - return s.ttlKeyHeap.Len() != 0 -} diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2store/ttl_key_heap.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2store/ttl_key_heap.go deleted file mode 100644 index 477d2b9f3a..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2store/ttl_key_heap.go +++ /dev/null @@ -1,97 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package v2store - -import "container/heap" - -// An TTLKeyHeap is a min-heap of TTLKeys order by expiration time -type ttlKeyHeap struct { - array []*node - keyMap map[*node]int -} - -func newTtlKeyHeap() *ttlKeyHeap { - h := &ttlKeyHeap{keyMap: make(map[*node]int)} - heap.Init(h) - return h -} - -func (h ttlKeyHeap) Len() int { - return len(h.array) -} - -func (h ttlKeyHeap) Less(i, j int) bool { - return h.array[i].ExpireTime.Before(h.array[j].ExpireTime) -} - -func (h ttlKeyHeap) Swap(i, j int) { - // swap node - h.array[i], h.array[j] = h.array[j], h.array[i] - - // update map - h.keyMap[h.array[i]] = i - h.keyMap[h.array[j]] = j -} - -func (h *ttlKeyHeap) Push(x interface{}) { - n, _ := x.(*node) - h.keyMap[n] = len(h.array) - h.array = append(h.array, n) -} - -func (h *ttlKeyHeap) Pop() interface{} { - old := h.array - n := len(old) - x := old[n-1] - // Set slice element to nil, so GC can recycle the node. - // This is due to golang GC doesn't support partial recycling: - // https://github.com/golang/go/issues/9618 - old[n-1] = nil - h.array = old[0 : n-1] - delete(h.keyMap, x) - return x -} - -func (h *ttlKeyHeap) top() *node { - if h.Len() != 0 { - return h.array[0] - } - return nil -} - -func (h *ttlKeyHeap) pop() *node { - x := heap.Pop(h) - n, _ := x.(*node) - return n -} - -func (h *ttlKeyHeap) push(x interface{}) { - heap.Push(h, x) -} - -func (h *ttlKeyHeap) update(n *node) { - index, ok := h.keyMap[n] - if ok { - heap.Remove(h, index) - heap.Push(h, n) - } -} - -func (h *ttlKeyHeap) remove(n *node) { - index, ok := h.keyMap[n] - if ok { - heap.Remove(h, index) - } -} diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2store/watcher.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2store/watcher.go deleted file mode 100644 index 4b1e846a2f..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2store/watcher.go +++ /dev/null @@ -1,95 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package v2store - -type Watcher interface { - EventChan() chan *Event - StartIndex() uint64 // The EtcdIndex at which the Watcher was created - Remove() -} - -type watcher struct { - eventChan chan *Event - stream bool - recursive bool - sinceIndex uint64 - startIndex uint64 - hub *watcherHub - removed bool - remove func() -} - -func (w *watcher) EventChan() chan *Event { - return w.eventChan -} - -func (w *watcher) StartIndex() uint64 { - return w.startIndex -} - -// notify function notifies the watcher. If the watcher interests in the given path, -// the function will return true. -func (w *watcher) notify(e *Event, originalPath bool, deleted bool) bool { - // watcher is interested the path in three cases and under one condition - // the condition is that the event happens after the watcher's sinceIndex - - // 1. the path at which the event happens is the path the watcher is watching at. - // For example if the watcher is watching at "/foo" and the event happens at "/foo", - // the watcher must be interested in that event. - - // 2. the watcher is a recursive watcher, it interests in the event happens after - // its watching path. For example if watcher A watches at "/foo" and it is a recursive - // one, it will interest in the event happens at "/foo/bar". - - // 3. when we delete a directory, we need to force notify all the watchers who watches - // at the file we need to delete. - // For example a watcher is watching at "/foo/bar". And we deletes "/foo". The watcher - // should get notified even if "/foo" is not the path it is watching. - if (w.recursive || originalPath || deleted) && e.Index() >= w.sinceIndex { - // We cannot block here if the eventChan capacity is full, otherwise - // etcd will hang. eventChan capacity is full when the rate of - // notifications are higher than our send rate. - // If this happens, we close the channel. - select { - case w.eventChan <- e: - default: - // We have missed a notification. Remove the watcher. - // Removing the watcher also closes the eventChan. - w.remove() - } - return true - } - return false -} - -// Remove removes the watcher from watcherHub -// The actual remove function is guaranteed to only be executed once -func (w *watcher) Remove() { - w.hub.mutex.Lock() - defer w.hub.mutex.Unlock() - - close(w.eventChan) - if w.remove != nil { - w.remove() - } -} - -// nopWatcher is a watcher that receives nothing, always blocking. -type nopWatcher struct{} - -func NewNopWatcher() Watcher { return &nopWatcher{} } -func (w *nopWatcher) EventChan() chan *Event { return nil } -func (w *nopWatcher) StartIndex() uint64 { return 0 } -func (w *nopWatcher) Remove() {} diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2store/watcher_hub.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2store/watcher_hub.go deleted file mode 100644 index dc5c8f2bb5..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2store/watcher_hub.go +++ /dev/null @@ -1,200 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package v2store - -import ( - "container/list" - "path" - "strings" - "sync" - "sync/atomic" - - "go.etcd.io/etcd/server/v3/etcdserver/api/v2error" -) - -// A watcherHub contains all subscribed watchers -// watchers is a map with watched path as key and watcher as value -// EventHistory keeps the old events for watcherHub. It is used to help -// watcher to get a continuous event history. Or a watcher might miss the -// event happens between the end of the first watch command and the start -// of the second command. -type watcherHub struct { - // count must be the first element to keep 64-bit alignment for atomic - // access - - count int64 // current number of watchers. - - mutex sync.Mutex - watchers map[string]*list.List - EventHistory *EventHistory -} - -// newWatchHub creates a watcherHub. The capacity determines how many events we will -// keep in the eventHistory. -// Typically, we only need to keep a small size of history[smaller than 20K]. -// Ideally, it should smaller than 20K/s[max throughput] * 2 * 50ms[RTT] = 2000 -func newWatchHub(capacity int) *watcherHub { - return &watcherHub{ - watchers: make(map[string]*list.List), - EventHistory: newEventHistory(capacity), - } -} - -// Watch function returns a Watcher. -// If recursive is true, the first change after index under key will be sent to the event channel of the watcher. -// If recursive is false, the first change after index at key will be sent to the event channel of the watcher. -// If index is zero, watch will start from the current index + 1. -func (wh *watcherHub) watch(key string, recursive, stream bool, index, storeIndex uint64) (Watcher, *v2error.Error) { - reportWatchRequest() - event, err := wh.EventHistory.scan(key, recursive, index) - - if err != nil { - err.Index = storeIndex - return nil, err - } - - w := &watcher{ - eventChan: make(chan *Event, 100), // use a buffered channel - recursive: recursive, - stream: stream, - sinceIndex: index, - startIndex: storeIndex, - hub: wh, - } - - wh.mutex.Lock() - defer wh.mutex.Unlock() - // If the event exists in the known history, append the EtcdIndex and return immediately - if event != nil { - ne := event.Clone() - ne.EtcdIndex = storeIndex - w.eventChan <- ne - return w, nil - } - - l, ok := wh.watchers[key] - - var elem *list.Element - - if ok { // add the new watcher to the back of the list - elem = l.PushBack(w) - } else { // create a new list and add the new watcher - l = list.New() - elem = l.PushBack(w) - wh.watchers[key] = l - } - - w.remove = func() { - if w.removed { // avoid removing it twice - return - } - w.removed = true - l.Remove(elem) - atomic.AddInt64(&wh.count, -1) - reportWatcherRemoved() - if l.Len() == 0 { - delete(wh.watchers, key) - } - } - - atomic.AddInt64(&wh.count, 1) - reportWatcherAdded() - - return w, nil -} - -func (wh *watcherHub) add(e *Event) { - wh.EventHistory.addEvent(e) -} - -// notify function accepts an event and notify to the watchers. -func (wh *watcherHub) notify(e *Event) { - e = wh.EventHistory.addEvent(e) // add event into the eventHistory - - segments := strings.Split(e.Node.Key, "/") - - currPath := "/" - - // walk through all the segments of the path and notify the watchers - // if the path is "/foo/bar", it will notify watchers with path "/", - // "/foo" and "/foo/bar" - - for _, segment := range segments { - currPath = path.Join(currPath, segment) - // notify the watchers who interests in the changes of current path - wh.notifyWatchers(e, currPath, false) - } -} - -func (wh *watcherHub) notifyWatchers(e *Event, nodePath string, deleted bool) { - wh.mutex.Lock() - defer wh.mutex.Unlock() - - l, ok := wh.watchers[nodePath] - if ok { - curr := l.Front() - - for curr != nil { - next := curr.Next() // save reference to the next one in the list - - w, _ := curr.Value.(*watcher) - - originalPath := e.Node.Key == nodePath - if (originalPath || !isHidden(nodePath, e.Node.Key)) && w.notify(e, originalPath, deleted) { - if !w.stream { // do not remove the stream watcher - // if we successfully notify a watcher - // we need to remove the watcher from the list - // and decrease the counter - w.removed = true - l.Remove(curr) - atomic.AddInt64(&wh.count, -1) - reportWatcherRemoved() - } - } - - curr = next // update current to the next element in the list - } - - if l.Len() == 0 { - // if we have notified all watcher in the list - // we can delete the list - delete(wh.watchers, nodePath) - } - } -} - -// clone function clones the watcherHub and return the cloned one. -// only clone the static content. do not clone the current watchers. -func (wh *watcherHub) clone() *watcherHub { - clonedHistory := wh.EventHistory.clone() - - return &watcherHub{ - EventHistory: clonedHistory, - } -} - -// isHidden checks to see if key path is considered hidden to watch path i.e. the -// last element is hidden or it's within a hidden directory -func isHidden(watchPath, keyPath string) bool { - // When deleting a directory, watchPath might be deeper than the actual keyPath - // For example, when deleting /foo we also need to notify watchers on /foo/bar. - if len(watchPath) > len(keyPath) { - return false - } - // if watch path is just a "/", after path will start without "/" - // add a "/" to deal with the special case when watchPath is "/" - afterPath := path.Clean("/" + keyPath[len(watchPath):]) - return strings.Contains(afterPath, "/_") -} diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2v3/cluster.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2v3/cluster.go deleted file mode 100644 index d275e05718..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2v3/cluster.go +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package v2v3 - -import ( - "go.etcd.io/etcd/client/pkg/v3/types" - "go.etcd.io/etcd/server/v3/etcdserver/api/membership" - - "github.com/coreos/go-semver/semver" -) - -func (s *v2v3Server) ID() types.ID { - // TODO: use an actual member ID - return types.ID(0xe7cd2f00d) -} -func (s *v2v3Server) ClientURLs() []string { panic("STUB") } -func (s *v2v3Server) Members() []*membership.Member { panic("STUB") } -func (s *v2v3Server) Member(id types.ID) *membership.Member { panic("STUB") } -func (s *v2v3Server) Version() *semver.Version { panic("STUB") } diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2v3/doc.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2v3/doc.go deleted file mode 100644 index 2ff372f187..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2v3/doc.go +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package v2v3 provides a ServerV2 implementation backed by clientv3.Client. -package v2v3 diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2v3/server.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2v3/server.go deleted file mode 100644 index 71557ceb5c..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2v3/server.go +++ /dev/null @@ -1,130 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package v2v3 - -import ( - "context" - "net/http" - "time" - - pb "go.etcd.io/etcd/api/v3/etcdserverpb" - "go.etcd.io/etcd/client/pkg/v3/types" - "go.etcd.io/etcd/client/v3" - "go.etcd.io/etcd/server/v3/etcdserver" - "go.etcd.io/etcd/server/v3/etcdserver/api" - "go.etcd.io/etcd/server/v3/etcdserver/api/membership" - - "github.com/coreos/go-semver/semver" - "go.uber.org/zap" -) - -type fakeStats struct{} - -func (s *fakeStats) SelfStats() []byte { return nil } -func (s *fakeStats) LeaderStats() []byte { return nil } -func (s *fakeStats) StoreStats() []byte { return nil } - -type v2v3Server struct { - lg *zap.Logger - c *clientv3.Client - store *v2v3Store - fakeStats -} - -func NewServer(lg *zap.Logger, c *clientv3.Client, pfx string) etcdserver.ServerPeer { - return &v2v3Server{lg: lg, c: c, store: newStore(c, pfx)} -} - -func (s *v2v3Server) ClientCertAuthEnabled() bool { return false } - -func (s *v2v3Server) LeaseHandler() http.Handler { panic("STUB: lease handler") } -func (s *v2v3Server) RaftHandler() http.Handler { panic("STUB: raft handler") } - -func (s *v2v3Server) Leader() types.ID { - ctx, cancel := context.WithTimeout(context.TODO(), 5*time.Second) - defer cancel() - resp, err := s.c.Status(ctx, s.c.Endpoints()[0]) - if err != nil { - return 0 - } - return types.ID(resp.Leader) -} - -func (s *v2v3Server) AddMember(ctx context.Context, memb membership.Member) ([]*membership.Member, error) { - // adding member as learner is not supported by V2 Server. - resp, err := s.c.MemberAdd(ctx, memb.PeerURLs) - if err != nil { - return nil, err - } - return v3MembersToMembership(resp.Members), nil -} - -func (s *v2v3Server) RemoveMember(ctx context.Context, id uint64) ([]*membership.Member, error) { - resp, err := s.c.MemberRemove(ctx, id) - if err != nil { - return nil, err - } - return v3MembersToMembership(resp.Members), nil -} - -func (s *v2v3Server) PromoteMember(ctx context.Context, id uint64) ([]*membership.Member, error) { - resp, err := s.c.MemberPromote(ctx, id) - if err != nil { - return nil, err - } - return v3MembersToMembership(resp.Members), nil -} - -func (s *v2v3Server) UpdateMember(ctx context.Context, m membership.Member) ([]*membership.Member, error) { - resp, err := s.c.MemberUpdate(ctx, uint64(m.ID), m.PeerURLs) - if err != nil { - return nil, err - } - return v3MembersToMembership(resp.Members), nil -} - -func v3MembersToMembership(v3membs []*pb.Member) []*membership.Member { - membs := make([]*membership.Member, len(v3membs)) - for i, m := range v3membs { - membs[i] = &membership.Member{ - ID: types.ID(m.ID), - RaftAttributes: membership.RaftAttributes{ - PeerURLs: m.PeerURLs, - IsLearner: m.IsLearner, - }, - Attributes: membership.Attributes{ - Name: m.Name, - ClientURLs: m.ClientURLs, - }, - } - } - return membs -} - -func (s *v2v3Server) ClusterVersion() *semver.Version { return s.Version() } -func (s *v2v3Server) Cluster() api.Cluster { return s } -func (s *v2v3Server) Alarms() []*pb.AlarmMember { return nil } -func (s *v2v3Server) LeaderChangedNotify() <-chan struct{} { return nil } - -func (s *v2v3Server) Do(ctx context.Context, r pb.Request) (etcdserver.Response, error) { - applier := etcdserver.NewApplierV2(s.lg, s.store, nil) - reqHandler := etcdserver.NewStoreRequestV2Handler(s.store, applier) - req := (*etcdserver.RequestV2)(&r) - resp, err := req.Handle(ctx, reqHandler) - if resp.Err != nil { - return resp, resp.Err - } - return resp, err -} diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2v3/store.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2v3/store.go deleted file mode 100644 index 6d78cab719..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2v3/store.go +++ /dev/null @@ -1,638 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package v2v3 - -import ( - "context" - "fmt" - "path" - "sort" - "strings" - "time" - - "go.etcd.io/etcd/api/v3/mvccpb" - "go.etcd.io/etcd/client/v3" - "go.etcd.io/etcd/client/v3/concurrency" - "go.etcd.io/etcd/server/v3/etcdserver/api/v2error" - "go.etcd.io/etcd/server/v3/etcdserver/api/v2store" -) - -// store implements the Store interface for V2 using -// a v3 client. -type v2v3Store struct { - c *clientv3.Client - // pfx is the v3 prefix where keys should be stored. - pfx string - ctx context.Context -} - -const maxPathDepth = 63 - -var errUnsupported = fmt.Errorf("TTLs are unsupported") - -func NewStore(c *clientv3.Client, pfx string) v2store.Store { return newStore(c, pfx) } - -func newStore(c *clientv3.Client, pfx string) *v2v3Store { return &v2v3Store{c, pfx, c.Ctx()} } - -func (s *v2v3Store) Index() uint64 { panic("STUB") } - -func (s *v2v3Store) Get(nodePath string, recursive, sorted bool) (*v2store.Event, error) { - key := s.mkPath(nodePath) - resp, err := s.c.Txn(s.ctx).Then( - clientv3.OpGet(key+"/"), - clientv3.OpGet(key), - ).Commit() - if err != nil { - return nil, err - } - - if kvs := resp.Responses[0].GetResponseRange().Kvs; len(kvs) != 0 || isRoot(nodePath) { - nodes, err := s.getDir(nodePath, recursive, sorted, resp.Header.Revision) - if err != nil { - return nil, err - } - cidx, midx := uint64(0), uint64(0) - if len(kvs) > 0 { - cidx, midx = mkV2Rev(kvs[0].CreateRevision), mkV2Rev(kvs[0].ModRevision) - } - return &v2store.Event{ - Action: v2store.Get, - Node: &v2store.NodeExtern{ - Key: nodePath, - Dir: true, - Nodes: nodes, - CreatedIndex: cidx, - ModifiedIndex: midx, - }, - EtcdIndex: mkV2Rev(resp.Header.Revision), - }, nil - } - - kvs := resp.Responses[1].GetResponseRange().Kvs - if len(kvs) == 0 { - return nil, v2error.NewError(v2error.EcodeKeyNotFound, nodePath, mkV2Rev(resp.Header.Revision)) - } - - return &v2store.Event{ - Action: v2store.Get, - Node: s.mkV2Node(kvs[0]), - EtcdIndex: mkV2Rev(resp.Header.Revision), - }, nil -} - -func (s *v2v3Store) getDir(nodePath string, recursive, sorted bool, rev int64) ([]*v2store.NodeExtern, error) { - rootNodes, err := s.getDirDepth(nodePath, 1, rev) - if err != nil || !recursive { - if sorted { - sort.Sort(v2store.NodeExterns(rootNodes)) - } - return rootNodes, err - } - nextNodes := rootNodes - nodes := make(map[string]*v2store.NodeExtern) - // Breadth walk the subdirectories - for i := 2; len(nextNodes) > 0; i++ { - for _, n := range nextNodes { - nodes[n.Key] = n - if parent := nodes[path.Dir(n.Key)]; parent != nil { - parent.Nodes = append(parent.Nodes, n) - } - } - if nextNodes, err = s.getDirDepth(nodePath, i, rev); err != nil { - return nil, err - } - } - - if sorted { - sort.Sort(v2store.NodeExterns(rootNodes)) - } - return rootNodes, nil -} - -func (s *v2v3Store) getDirDepth(nodePath string, depth int, rev int64) ([]*v2store.NodeExtern, error) { - pd := s.mkPathDepth(nodePath, depth) - resp, err := s.c.Get(s.ctx, pd, clientv3.WithPrefix(), clientv3.WithRev(rev)) - if err != nil { - return nil, err - } - - nodes := make([]*v2store.NodeExtern, len(resp.Kvs)) - for i, kv := range resp.Kvs { - nodes[i] = s.mkV2Node(kv) - } - return nodes, nil -} - -func (s *v2v3Store) Set( - nodePath string, - dir bool, - value string, - expireOpts v2store.TTLOptionSet, -) (*v2store.Event, error) { - if expireOpts.Refresh || !expireOpts.ExpireTime.IsZero() { - return nil, errUnsupported - } - - if isRoot(nodePath) { - return nil, v2error.NewError(v2error.EcodeRootROnly, nodePath, 0) - } - - ecode := 0 - applyf := func(stm concurrency.STM) error { - // build path if any directories in path do not exist - dirs := []string{} - for p := path.Dir(nodePath); !isRoot(p); p = path.Dir(p) { - pp := s.mkPath(p) - if stm.Rev(pp) > 0 { - ecode = v2error.EcodeNotDir - return nil - } - if stm.Rev(pp+"/") == 0 { - dirs = append(dirs, pp+"/") - } - } - for _, d := range dirs { - stm.Put(d, "") - } - - key := s.mkPath(nodePath) - if dir { - if stm.Rev(key) != 0 { - // exists as non-dir - ecode = v2error.EcodeNotDir - return nil - } - key = key + "/" - } else if stm.Rev(key+"/") != 0 { - ecode = v2error.EcodeNotFile - return nil - } - stm.Put(key, value, clientv3.WithPrevKV()) - stm.Put(s.mkActionKey(), v2store.Set) - return nil - } - - resp, err := s.newSTM(applyf) - if err != nil { - return nil, err - } - if ecode != 0 { - return nil, v2error.NewError(ecode, nodePath, mkV2Rev(resp.Header.Revision)) - } - - createRev := resp.Header.Revision - var pn *v2store.NodeExtern - if pkv := prevKeyFromPuts(resp); pkv != nil { - pn = s.mkV2Node(pkv) - createRev = pkv.CreateRevision - } - - vp := &value - if dir { - vp = nil - } - return &v2store.Event{ - Action: v2store.Set, - Node: &v2store.NodeExtern{ - Key: nodePath, - Value: vp, - Dir: dir, - ModifiedIndex: mkV2Rev(resp.Header.Revision), - CreatedIndex: mkV2Rev(createRev), - }, - PrevNode: pn, - EtcdIndex: mkV2Rev(resp.Header.Revision), - }, nil -} - -func (s *v2v3Store) Update(nodePath, newValue string, expireOpts v2store.TTLOptionSet) (*v2store.Event, error) { - if isRoot(nodePath) { - return nil, v2error.NewError(v2error.EcodeRootROnly, nodePath, 0) - } - - if expireOpts.Refresh || !expireOpts.ExpireTime.IsZero() { - return nil, errUnsupported - } - - key := s.mkPath(nodePath) - ecode := 0 - applyf := func(stm concurrency.STM) error { - if rev := stm.Rev(key + "/"); rev != 0 { - ecode = v2error.EcodeNotFile - return nil - } - if rev := stm.Rev(key); rev == 0 { - ecode = v2error.EcodeKeyNotFound - return nil - } - stm.Put(key, newValue, clientv3.WithPrevKV()) - stm.Put(s.mkActionKey(), v2store.Update) - return nil - } - - resp, err := s.newSTM(applyf) - if err != nil { - return nil, err - } - if ecode != 0 { - return nil, v2error.NewError(v2error.EcodeNotFile, nodePath, mkV2Rev(resp.Header.Revision)) - } - - pkv := prevKeyFromPuts(resp) - return &v2store.Event{ - Action: v2store.Update, - Node: &v2store.NodeExtern{ - Key: nodePath, - Value: &newValue, - ModifiedIndex: mkV2Rev(resp.Header.Revision), - CreatedIndex: mkV2Rev(pkv.CreateRevision), - }, - PrevNode: s.mkV2Node(pkv), - EtcdIndex: mkV2Rev(resp.Header.Revision), - }, nil -} - -func (s *v2v3Store) Create( - nodePath string, - dir bool, - value string, - unique bool, - expireOpts v2store.TTLOptionSet, -) (*v2store.Event, error) { - if isRoot(nodePath) { - return nil, v2error.NewError(v2error.EcodeRootROnly, nodePath, 0) - } - if expireOpts.Refresh || !expireOpts.ExpireTime.IsZero() { - return nil, errUnsupported - } - ecode := 0 - applyf := func(stm concurrency.STM) error { - ecode = 0 - key := s.mkPath(nodePath) - if unique { - // append unique item under the node path - for { - key = nodePath + "/" + fmt.Sprintf("%020s", time.Now()) - key = path.Clean(path.Join("/", key)) - key = s.mkPath(key) - if stm.Rev(key) == 0 { - break - } - } - } - if stm.Rev(key) > 0 || stm.Rev(key+"/") > 0 { - ecode = v2error.EcodeNodeExist - return nil - } - // build path if any directories in path do not exist - dirs := []string{} - for p := path.Dir(nodePath); !isRoot(p); p = path.Dir(p) { - pp := s.mkPath(p) - if stm.Rev(pp) > 0 { - ecode = v2error.EcodeNotDir - return nil - } - if stm.Rev(pp+"/") == 0 { - dirs = append(dirs, pp+"/") - } - } - for _, d := range dirs { - stm.Put(d, "") - } - - if dir { - // directories marked with extra slash in key name - key += "/" - } - stm.Put(key, value) - stm.Put(s.mkActionKey(), v2store.Create) - return nil - } - - resp, err := s.newSTM(applyf) - if err != nil { - return nil, err - } - if ecode != 0 { - return nil, v2error.NewError(ecode, nodePath, mkV2Rev(resp.Header.Revision)) - } - - var v *string - if !dir { - v = &value - } - - return &v2store.Event{ - Action: v2store.Create, - Node: &v2store.NodeExtern{ - Key: nodePath, - Value: v, - Dir: dir, - ModifiedIndex: mkV2Rev(resp.Header.Revision), - CreatedIndex: mkV2Rev(resp.Header.Revision), - }, - EtcdIndex: mkV2Rev(resp.Header.Revision), - }, nil -} - -func (s *v2v3Store) CompareAndSwap( - nodePath string, - prevValue string, - prevIndex uint64, - value string, - expireOpts v2store.TTLOptionSet, -) (*v2store.Event, error) { - if isRoot(nodePath) { - return nil, v2error.NewError(v2error.EcodeRootROnly, nodePath, 0) - } - if expireOpts.Refresh || !expireOpts.ExpireTime.IsZero() { - return nil, errUnsupported - } - - key := s.mkPath(nodePath) - resp, err := s.c.Txn(s.ctx).If( - s.mkCompare(nodePath, prevValue, prevIndex)..., - ).Then( - clientv3.OpPut(key, value, clientv3.WithPrevKV()), - clientv3.OpPut(s.mkActionKey(), v2store.CompareAndSwap), - ).Else( - clientv3.OpGet(key), - clientv3.OpGet(key+"/"), - ).Commit() - - if err != nil { - return nil, err - } - if !resp.Succeeded { - return nil, compareFail(nodePath, prevValue, prevIndex, resp) - } - - pkv := resp.Responses[0].GetResponsePut().PrevKv - return &v2store.Event{ - Action: v2store.CompareAndSwap, - Node: &v2store.NodeExtern{ - Key: nodePath, - Value: &value, - CreatedIndex: mkV2Rev(pkv.CreateRevision), - ModifiedIndex: mkV2Rev(resp.Header.Revision), - }, - PrevNode: s.mkV2Node(pkv), - EtcdIndex: mkV2Rev(resp.Header.Revision), - }, nil -} - -func (s *v2v3Store) Delete(nodePath string, dir, recursive bool) (*v2store.Event, error) { - if isRoot(nodePath) { - return nil, v2error.NewError(v2error.EcodeRootROnly, nodePath, 0) - } - if !dir && !recursive { - return s.deleteNode(nodePath) - } - if !recursive { - return s.deleteEmptyDir(nodePath) - } - - dels := make([]clientv3.Op, maxPathDepth+1) - dels[0] = clientv3.OpDelete(s.mkPath(nodePath)+"/", clientv3.WithPrevKV()) - for i := 1; i < maxPathDepth; i++ { - dels[i] = clientv3.OpDelete(s.mkPathDepth(nodePath, i), clientv3.WithPrefix()) - } - dels[maxPathDepth] = clientv3.OpPut(s.mkActionKey(), v2store.Delete) - - resp, err := s.c.Txn(s.ctx).If( - clientv3.Compare(clientv3.Version(s.mkPath(nodePath)+"/"), ">", 0), - clientv3.Compare(clientv3.Version(s.mkPathDepth(nodePath, maxPathDepth)+"/"), "=", 0), - ).Then( - dels..., - ).Commit() - if err != nil { - return nil, err - } - if !resp.Succeeded { - return nil, v2error.NewError(v2error.EcodeNodeExist, nodePath, mkV2Rev(resp.Header.Revision)) - } - dresp := resp.Responses[0].GetResponseDeleteRange() - return &v2store.Event{ - Action: v2store.Delete, - PrevNode: s.mkV2Node(dresp.PrevKvs[0]), - EtcdIndex: mkV2Rev(resp.Header.Revision), - }, nil -} - -func (s *v2v3Store) deleteEmptyDir(nodePath string) (*v2store.Event, error) { - resp, err := s.c.Txn(s.ctx).If( - clientv3.Compare(clientv3.Version(s.mkPathDepth(nodePath, 1)), "=", 0).WithPrefix(), - ).Then( - clientv3.OpDelete(s.mkPath(nodePath)+"/", clientv3.WithPrevKV()), - clientv3.OpPut(s.mkActionKey(), v2store.Delete), - ).Commit() - if err != nil { - return nil, err - } - if !resp.Succeeded { - return nil, v2error.NewError(v2error.EcodeDirNotEmpty, nodePath, mkV2Rev(resp.Header.Revision)) - } - dresp := resp.Responses[0].GetResponseDeleteRange() - if len(dresp.PrevKvs) == 0 { - return nil, v2error.NewError(v2error.EcodeNodeExist, nodePath, mkV2Rev(resp.Header.Revision)) - } - return &v2store.Event{ - Action: v2store.Delete, - PrevNode: s.mkV2Node(dresp.PrevKvs[0]), - EtcdIndex: mkV2Rev(resp.Header.Revision), - }, nil -} - -func (s *v2v3Store) deleteNode(nodePath string) (*v2store.Event, error) { - resp, err := s.c.Txn(s.ctx).If( - clientv3.Compare(clientv3.Version(s.mkPath(nodePath)+"/"), "=", 0), - ).Then( - clientv3.OpDelete(s.mkPath(nodePath), clientv3.WithPrevKV()), - clientv3.OpPut(s.mkActionKey(), v2store.Delete), - ).Commit() - if err != nil { - return nil, err - } - if !resp.Succeeded { - return nil, v2error.NewError(v2error.EcodeNotFile, nodePath, mkV2Rev(resp.Header.Revision)) - } - pkvs := resp.Responses[0].GetResponseDeleteRange().PrevKvs - if len(pkvs) == 0 { - return nil, v2error.NewError(v2error.EcodeKeyNotFound, nodePath, mkV2Rev(resp.Header.Revision)) - } - pkv := pkvs[0] - return &v2store.Event{ - Action: v2store.Delete, - Node: &v2store.NodeExtern{ - Key: nodePath, - CreatedIndex: mkV2Rev(pkv.CreateRevision), - ModifiedIndex: mkV2Rev(resp.Header.Revision), - }, - PrevNode: s.mkV2Node(pkv), - EtcdIndex: mkV2Rev(resp.Header.Revision), - }, nil -} - -func (s *v2v3Store) CompareAndDelete(nodePath, prevValue string, prevIndex uint64) (*v2store.Event, error) { - if isRoot(nodePath) { - return nil, v2error.NewError(v2error.EcodeRootROnly, nodePath, 0) - } - - key := s.mkPath(nodePath) - resp, err := s.c.Txn(s.ctx).If( - s.mkCompare(nodePath, prevValue, prevIndex)..., - ).Then( - clientv3.OpDelete(key, clientv3.WithPrevKV()), - clientv3.OpPut(s.mkActionKey(), v2store.CompareAndDelete), - ).Else( - clientv3.OpGet(key), - clientv3.OpGet(key+"/"), - ).Commit() - - if err != nil { - return nil, err - } - if !resp.Succeeded { - return nil, compareFail(nodePath, prevValue, prevIndex, resp) - } - - // len(pkvs) > 1 since txn only succeeds when key exists - pkv := resp.Responses[0].GetResponseDeleteRange().PrevKvs[0] - return &v2store.Event{ - Action: v2store.CompareAndDelete, - Node: &v2store.NodeExtern{ - Key: nodePath, - CreatedIndex: mkV2Rev(pkv.CreateRevision), - ModifiedIndex: mkV2Rev(resp.Header.Revision), - }, - PrevNode: s.mkV2Node(pkv), - EtcdIndex: mkV2Rev(resp.Header.Revision), - }, nil -} - -func compareFail(nodePath, prevValue string, prevIndex uint64, resp *clientv3.TxnResponse) error { - if dkvs := resp.Responses[1].GetResponseRange().Kvs; len(dkvs) > 0 { - return v2error.NewError(v2error.EcodeNotFile, nodePath, mkV2Rev(resp.Header.Revision)) - } - kvs := resp.Responses[0].GetResponseRange().Kvs - if len(kvs) == 0 { - return v2error.NewError(v2error.EcodeKeyNotFound, nodePath, mkV2Rev(resp.Header.Revision)) - } - kv := kvs[0] - indexMatch := prevIndex == 0 || kv.ModRevision == int64(prevIndex) - valueMatch := prevValue == "" || string(kv.Value) == prevValue - var cause string - switch { - case indexMatch && !valueMatch: - cause = fmt.Sprintf("[%v != %v]", prevValue, string(kv.Value)) - case valueMatch && !indexMatch: - cause = fmt.Sprintf("[%v != %v]", prevIndex, kv.ModRevision) - default: - cause = fmt.Sprintf("[%v != %v] [%v != %v]", prevValue, string(kv.Value), prevIndex, kv.ModRevision) - } - return v2error.NewError(v2error.EcodeTestFailed, cause, mkV2Rev(resp.Header.Revision)) -} - -func (s *v2v3Store) mkCompare(nodePath, prevValue string, prevIndex uint64) []clientv3.Cmp { - key := s.mkPath(nodePath) - cmps := []clientv3.Cmp{clientv3.Compare(clientv3.Version(key), ">", 0)} - if prevIndex != 0 { - cmps = append(cmps, clientv3.Compare(clientv3.ModRevision(key), "=", mkV3Rev(prevIndex))) - } - if prevValue != "" { - cmps = append(cmps, clientv3.Compare(clientv3.Value(key), "=", prevValue)) - } - return cmps -} - -func (s *v2v3Store) JsonStats() []byte { panic("STUB") } -func (s *v2v3Store) DeleteExpiredKeys(cutoff time.Time) { panic("STUB") } - -func (s *v2v3Store) Version() int { return 2 } - -// TODO: move this out of the Store interface? - -func (s *v2v3Store) Save() ([]byte, error) { panic("STUB") } -func (s *v2v3Store) Recovery(state []byte) error { panic("STUB") } -func (s *v2v3Store) Clone() v2store.Store { panic("STUB") } -func (s *v2v3Store) SaveNoCopy() ([]byte, error) { panic("STUB") } -func (s *v2v3Store) HasTTLKeys() bool { panic("STUB") } - -func (s *v2v3Store) mkPath(nodePath string) string { return s.mkPathDepth(nodePath, 0) } - -func (s *v2v3Store) mkNodePath(p string) string { - return path.Clean(p[len(s.pfx)+len("/k/000/"):]) -} - -// mkPathDepth makes a path to a key that encodes its directory depth -// for fast directory listing. If a depth is provided, it is added -// to the computed depth. -func (s *v2v3Store) mkPathDepth(nodePath string, depth int) string { - normalForm := path.Clean(path.Join("/", nodePath)) - n := strings.Count(normalForm, "/") + depth - return fmt.Sprintf("%s/%03d/k/%s", s.pfx, n, normalForm) -} - -func (s *v2v3Store) mkActionKey() string { return s.pfx + "/act" } - -func isRoot(s string) bool { return len(s) == 0 || s == "/" || s == "/0" || s == "/1" } - -func mkV2Rev(v3Rev int64) uint64 { - if v3Rev == 0 { - return 0 - } - return uint64(v3Rev - 1) -} - -func mkV3Rev(v2Rev uint64) int64 { - if v2Rev == 0 { - return 0 - } - return int64(v2Rev + 1) -} - -// mkV2Node creates a V2 NodeExtern from a V3 KeyValue -func (s *v2v3Store) mkV2Node(kv *mvccpb.KeyValue) *v2store.NodeExtern { - if kv == nil { - return nil - } - n := &v2store.NodeExtern{ - Key: s.mkNodePath(string(kv.Key)), - Dir: kv.Key[len(kv.Key)-1] == '/', - CreatedIndex: mkV2Rev(kv.CreateRevision), - ModifiedIndex: mkV2Rev(kv.ModRevision), - } - if !n.Dir { - v := string(kv.Value) - n.Value = &v - } - return n -} - -// prevKeyFromPuts gets the prev key that is being put; ignores -// the put action response. -func prevKeyFromPuts(resp *clientv3.TxnResponse) *mvccpb.KeyValue { - for _, r := range resp.Responses { - pkv := r.GetResponsePut().PrevKv - if pkv != nil && pkv.CreateRevision > 0 { - return pkv - } - } - return nil -} - -func (s *v2v3Store) newSTM(applyf func(concurrency.STM) error) (*clientv3.TxnResponse, error) { - return concurrency.NewSTM(s.c, applyf, concurrency.WithIsolation(concurrency.Serializable)) -} diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2v3/watcher.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2v3/watcher.go deleted file mode 100644 index 046c25d450..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v2v3/watcher.go +++ /dev/null @@ -1,142 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package v2v3 - -import ( - "context" - "strings" - - "go.etcd.io/etcd/client/v3" - "go.etcd.io/etcd/server/v3/etcdserver/api/v2error" - "go.etcd.io/etcd/server/v3/etcdserver/api/v2store" -) - -func (s *v2v3Store) Watch(prefix string, recursive, stream bool, sinceIndex uint64) (v2store.Watcher, error) { - ctx, cancel := context.WithCancel(s.ctx) - wch := s.c.Watch( - ctx, - // TODO: very pricey; use a single store-wide watch in future - s.pfx, - clientv3.WithPrefix(), - clientv3.WithRev(int64(sinceIndex)), - clientv3.WithCreatedNotify(), - clientv3.WithPrevKV()) - resp, ok := <-wch - if err := resp.Err(); err != nil || !ok { - cancel() - return nil, v2error.NewError(v2error.EcodeRaftInternal, prefix, 0) - } - - evc, donec := make(chan *v2store.Event), make(chan struct{}) - go func() { - defer func() { - close(evc) - close(donec) - }() - for resp := range wch { - for _, ev := range s.mkV2Events(resp) { - k := ev.Node.Key - if recursive { - if !strings.HasPrefix(k, prefix) { - continue - } - // accept events on hidden keys given in prefix - k = strings.Replace(k, prefix, "/", 1) - // ignore hidden keys deeper than prefix - if strings.Contains(k, "/_") { - continue - } - } - if !recursive && k != prefix { - continue - } - select { - case evc <- ev: - case <-ctx.Done(): - return - } - if !stream { - return - } - } - } - }() - - return &v2v3Watcher{ - startRev: resp.Header.Revision, - evc: evc, - donec: donec, - cancel: cancel, - }, nil -} - -func (s *v2v3Store) mkV2Events(wr clientv3.WatchResponse) (evs []*v2store.Event) { - ak := s.mkActionKey() - for _, rev := range mkRevs(wr) { - var act, key *clientv3.Event - for _, ev := range rev { - if string(ev.Kv.Key) == ak { - act = ev - } else if key != nil && len(key.Kv.Key) < len(ev.Kv.Key) { - // use longest key to ignore intermediate new - // directories from Create. - key = ev - } else if key == nil { - key = ev - } - } - if act != nil && act.Kv != nil && key != nil { - v2ev := &v2store.Event{ - Action: string(act.Kv.Value), - Node: s.mkV2Node(key.Kv), - PrevNode: s.mkV2Node(key.PrevKv), - EtcdIndex: mkV2Rev(wr.Header.Revision), - } - evs = append(evs, v2ev) - } - } - return evs -} - -func mkRevs(wr clientv3.WatchResponse) (revs [][]*clientv3.Event) { - var curRev []*clientv3.Event - for _, ev := range wr.Events { - if curRev != nil && ev.Kv.ModRevision != curRev[0].Kv.ModRevision { - revs = append(revs, curRev) - curRev = nil - } - curRev = append(curRev, ev) - } - if curRev != nil { - revs = append(revs, curRev) - } - return revs -} - -type v2v3Watcher struct { - startRev int64 - evc chan *v2store.Event - donec chan struct{} - cancel context.CancelFunc -} - -func (w *v2v3Watcher) StartIndex() uint64 { return mkV2Rev(w.startRev) } - -func (w *v2v3Watcher) Remove() { - w.cancel() - <-w.donec -} - -func (w *v2v3Watcher) EventChan() chan *v2store.Event { return w.evc } diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3alarm/alarms.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3alarm/alarms.go deleted file mode 100644 index 3038813cc8..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3alarm/alarms.go +++ /dev/null @@ -1,153 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package v3alarm manages health status alarms in etcd. -package v3alarm - -import ( - "sync" - - pb "go.etcd.io/etcd/api/v3/etcdserverpb" - "go.etcd.io/etcd/client/pkg/v3/types" - "go.etcd.io/etcd/server/v3/mvcc/backend" - "go.etcd.io/etcd/server/v3/mvcc/buckets" - - "go.uber.org/zap" -) - -type BackendGetter interface { - Backend() backend.Backend -} - -type alarmSet map[types.ID]*pb.AlarmMember - -// AlarmStore persists alarms to the backend. -type AlarmStore struct { - lg *zap.Logger - mu sync.Mutex - types map[pb.AlarmType]alarmSet - - bg BackendGetter -} - -func NewAlarmStore(lg *zap.Logger, bg BackendGetter) (*AlarmStore, error) { - if lg == nil { - lg = zap.NewNop() - } - ret := &AlarmStore{lg: lg, types: make(map[pb.AlarmType]alarmSet), bg: bg} - err := ret.restore() - return ret, err -} - -func (a *AlarmStore) Activate(id types.ID, at pb.AlarmType) *pb.AlarmMember { - a.mu.Lock() - defer a.mu.Unlock() - - newAlarm := &pb.AlarmMember{MemberID: uint64(id), Alarm: at} - if m := a.addToMap(newAlarm); m != newAlarm { - return m - } - - v, err := newAlarm.Marshal() - if err != nil { - a.lg.Panic("failed to marshal alarm member", zap.Error(err)) - } - - b := a.bg.Backend() - b.BatchTx().Lock() - b.BatchTx().UnsafePut(buckets.Alarm, v, nil) - b.BatchTx().Unlock() - - return newAlarm -} - -func (a *AlarmStore) Deactivate(id types.ID, at pb.AlarmType) *pb.AlarmMember { - a.mu.Lock() - defer a.mu.Unlock() - - t := a.types[at] - if t == nil { - t = make(alarmSet) - a.types[at] = t - } - m := t[id] - if m == nil { - return nil - } - - delete(t, id) - - v, err := m.Marshal() - if err != nil { - a.lg.Panic("failed to marshal alarm member", zap.Error(err)) - } - - b := a.bg.Backend() - b.BatchTx().Lock() - b.BatchTx().UnsafeDelete(buckets.Alarm, v) - b.BatchTx().Unlock() - - return m -} - -func (a *AlarmStore) Get(at pb.AlarmType) (ret []*pb.AlarmMember) { - a.mu.Lock() - defer a.mu.Unlock() - if at == pb.AlarmType_NONE { - for _, t := range a.types { - for _, m := range t { - ret = append(ret, m) - } - } - return ret - } - for _, m := range a.types[at] { - ret = append(ret, m) - } - return ret -} - -func (a *AlarmStore) restore() error { - b := a.bg.Backend() - tx := b.BatchTx() - - tx.Lock() - tx.UnsafeCreateBucket(buckets.Alarm) - err := tx.UnsafeForEach(buckets.Alarm, func(k, v []byte) error { - var m pb.AlarmMember - if err := m.Unmarshal(k); err != nil { - return err - } - a.addToMap(&m) - return nil - }) - tx.Unlock() - - b.ForceCommit() - return err -} - -func (a *AlarmStore) addToMap(newAlarm *pb.AlarmMember) *pb.AlarmMember { - t := a.types[newAlarm.Alarm] - if t == nil { - t = make(alarmSet) - a.types[newAlarm.Alarm] = t - } - m := t[types.ID(newAlarm.MemberID)] - if m != nil { - return m - } - t[types.ID(newAlarm.MemberID)] = newAlarm - return newAlarm -} diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3client/doc.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3client/doc.go deleted file mode 100644 index 279195e1a1..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3client/doc.go +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package v3client provides clientv3 interfaces from an etcdserver. -// -// Use v3client by creating an EtcdServer instance, then wrapping it with v3client.New: -// -// import ( -// "context" -// -// "go.etcd.io/etcd/server/v3/embed" -// "go.etcd.io/etcd/server/v3/etcdserver/api/v3client" -// ) -// -// ... -// -// // create an embedded EtcdServer from the default configuration -// cfg := embed.NewConfig() -// cfg.Dir = "default.etcd" -// e, err := embed.StartEtcd(cfg) -// if err != nil { -// // handle error! -// } -// -// // wrap the EtcdServer with v3client -// cli := v3client.New(e.Server) -// -// // use like an ordinary clientv3 -// resp, err := cli.Put(context.TODO(), "some-key", "it works!") -// if err != nil { -// // handle error! -// } -// -package v3client diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3client/v3client.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3client/v3client.go deleted file mode 100644 index 8342dc434c..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3client/v3client.go +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package v3client - -import ( - "context" - "time" - - "go.etcd.io/etcd/client/v3" - "go.etcd.io/etcd/server/v3/etcdserver" - "go.etcd.io/etcd/server/v3/etcdserver/api/v3rpc" - "go.etcd.io/etcd/server/v3/proxy/grpcproxy/adapter" -) - -// New creates a clientv3 client that wraps an in-process EtcdServer. Instead -// of making gRPC calls through sockets, the client makes direct function calls -// to the etcd server through its api/v3rpc function interfaces. -func New(s *etcdserver.EtcdServer) *clientv3.Client { - c := clientv3.NewCtxClient(context.Background(), clientv3.WithZapLogger(s.Logger())) - - kvc := adapter.KvServerToKvClient(v3rpc.NewQuotaKVServer(s)) - c.KV = clientv3.NewKVFromKVClient(kvc, c) - - lc := adapter.LeaseServerToLeaseClient(v3rpc.NewQuotaLeaseServer(s)) - c.Lease = clientv3.NewLeaseFromLeaseClient(lc, c, time.Second) - - wc := adapter.WatchServerToWatchClient(v3rpc.NewWatchServer(s)) - c.Watcher = &watchWrapper{clientv3.NewWatchFromWatchClient(wc, c)} - - mc := adapter.MaintenanceServerToMaintenanceClient(v3rpc.NewMaintenanceServer(s)) - c.Maintenance = clientv3.NewMaintenanceFromMaintenanceClient(mc, c) - - clc := adapter.ClusterServerToClusterClient(v3rpc.NewClusterServer(s)) - c.Cluster = clientv3.NewClusterFromClusterClient(clc, c) - - a := adapter.AuthServerToAuthClient(v3rpc.NewAuthServer(s)) - c.Auth = clientv3.NewAuthFromAuthClient(a, c) - - return c -} - -// BlankContext implements Stringer on a context so the ctx string doesn't -// depend on the context's WithValue data, which tends to be unsynchronized -// (e.g., x/net/trace), causing ctx.String() to throw data races. -type blankContext struct{ context.Context } - -func (*blankContext) String() string { return "(blankCtx)" } - -// watchWrapper wraps clientv3 watch calls to blank out the context -// to avoid races on trace data. -type watchWrapper struct{ clientv3.Watcher } - -func (ww *watchWrapper) Watch(ctx context.Context, key string, opts ...clientv3.OpOption) clientv3.WatchChan { - return ww.Watcher.Watch(&blankContext{ctx}, key, opts...) -} diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3compactor/compactor.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3compactor/compactor.go deleted file mode 100644 index e352670c12..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3compactor/compactor.go +++ /dev/null @@ -1,73 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package v3compactor - -import ( - "context" - "fmt" - "time" - - pb "go.etcd.io/etcd/api/v3/etcdserverpb" - - "github.com/jonboulle/clockwork" - "go.uber.org/zap" -) - -const ( - ModePeriodic = "periodic" - ModeRevision = "revision" -) - -// Compactor purges old log from the storage periodically. -type Compactor interface { - // Run starts the main loop of the compactor in background. - // Use Stop() to halt the loop and release the resource. - Run() - // Stop halts the main loop of the compactor. - Stop() - // Pause temporally suspend the compactor not to run compaction. Resume() to unpose. - Pause() - // Resume restarts the compactor suspended by Pause(). - Resume() -} - -type Compactable interface { - Compact(ctx context.Context, r *pb.CompactionRequest) (*pb.CompactionResponse, error) -} - -type RevGetter interface { - Rev() int64 -} - -// New returns a new Compactor based on given "mode". -func New( - lg *zap.Logger, - mode string, - retention time.Duration, - rg RevGetter, - c Compactable, -) (Compactor, error) { - if lg == nil { - lg = zap.NewNop() - } - switch mode { - case ModePeriodic: - return newPeriodic(lg, clockwork.NewRealClock(), retention, rg, c), nil - case ModeRevision: - return newRevision(lg, clockwork.NewRealClock(), int64(retention), rg, c), nil - default: - return nil, fmt.Errorf("unsupported compaction mode %s", mode) - } -} diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3compactor/doc.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3compactor/doc.go deleted file mode 100644 index bb28046ce4..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3compactor/doc.go +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package v3compactor implements automated policies for compacting etcd's mvcc storage. -package v3compactor diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3compactor/periodic.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3compactor/periodic.go deleted file mode 100644 index 083c72ede2..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3compactor/periodic.go +++ /dev/null @@ -1,205 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package v3compactor - -import ( - "context" - "sync" - "time" - - pb "go.etcd.io/etcd/api/v3/etcdserverpb" - "go.etcd.io/etcd/server/v3/mvcc" - - "github.com/jonboulle/clockwork" - "go.uber.org/zap" -) - -// Periodic compacts the log by purging revisions older than -// the configured retention time. -type Periodic struct { - lg *zap.Logger - clock clockwork.Clock - period time.Duration - - rg RevGetter - c Compactable - - revs []int64 - ctx context.Context - cancel context.CancelFunc - - // mu protects paused - mu sync.RWMutex - paused bool -} - -// newPeriodic creates a new instance of Periodic compactor that purges -// the log older than h Duration. -func newPeriodic(lg *zap.Logger, clock clockwork.Clock, h time.Duration, rg RevGetter, c Compactable) *Periodic { - pc := &Periodic{ - lg: lg, - clock: clock, - period: h, - rg: rg, - c: c, - revs: make([]int64, 0), - } - pc.ctx, pc.cancel = context.WithCancel(context.Background()) - return pc -} - -/* -Compaction period 1-hour: - 1. compute compaction period, which is 1-hour - 2. record revisions for every 1/10 of 1-hour (6-minute) - 3. keep recording revisions with no compaction for first 1-hour - 4. do compact with revs[0] - - success? contiue on for-loop and move sliding window; revs = revs[1:] - - failure? update revs, and retry after 1/10 of 1-hour (6-minute) - -Compaction period 24-hour: - 1. compute compaction period, which is 1-hour - 2. record revisions for every 1/10 of 1-hour (6-minute) - 3. keep recording revisions with no compaction for first 24-hour - 4. do compact with revs[0] - - success? contiue on for-loop and move sliding window; revs = revs[1:] - - failure? update revs, and retry after 1/10 of 1-hour (6-minute) - -Compaction period 59-min: - 1. compute compaction period, which is 59-min - 2. record revisions for every 1/10 of 59-min (5.9-min) - 3. keep recording revisions with no compaction for first 59-min - 4. do compact with revs[0] - - success? contiue on for-loop and move sliding window; revs = revs[1:] - - failure? update revs, and retry after 1/10 of 59-min (5.9-min) - -Compaction period 5-sec: - 1. compute compaction period, which is 5-sec - 2. record revisions for every 1/10 of 5-sec (0.5-sec) - 3. keep recording revisions with no compaction for first 5-sec - 4. do compact with revs[0] - - success? contiue on for-loop and move sliding window; revs = revs[1:] - - failure? update revs, and retry after 1/10 of 5-sec (0.5-sec) -*/ - -// Run runs periodic compactor. -func (pc *Periodic) Run() { - compactInterval := pc.getCompactInterval() - retryInterval := pc.getRetryInterval() - retentions := pc.getRetentions() - - go func() { - lastSuccess := pc.clock.Now() - baseInterval := pc.period - for { - pc.revs = append(pc.revs, pc.rg.Rev()) - if len(pc.revs) > retentions { - pc.revs = pc.revs[1:] // pc.revs[0] is always the rev at pc.period ago - } - - select { - case <-pc.ctx.Done(): - return - case <-pc.clock.After(retryInterval): - pc.mu.Lock() - p := pc.paused - pc.mu.Unlock() - if p { - continue - } - } - - if pc.clock.Now().Sub(lastSuccess) < baseInterval { - continue - } - - // wait up to initial given period - if baseInterval == pc.period { - baseInterval = compactInterval - } - rev := pc.revs[0] - - pc.lg.Info( - "starting auto periodic compaction", - zap.Int64("revision", rev), - zap.Duration("compact-period", pc.period), - ) - startTime := pc.clock.Now() - _, err := pc.c.Compact(pc.ctx, &pb.CompactionRequest{Revision: rev}) - if err == nil || err == mvcc.ErrCompacted { - pc.lg.Info( - "completed auto periodic compaction", - zap.Int64("revision", rev), - zap.Duration("compact-period", pc.period), - zap.Duration("took", pc.clock.Now().Sub(startTime)), - ) - lastSuccess = pc.clock.Now() - } else { - pc.lg.Warn( - "failed auto periodic compaction", - zap.Int64("revision", rev), - zap.Duration("compact-period", pc.period), - zap.Duration("retry-interval", retryInterval), - zap.Error(err), - ) - } - } - }() -} - -// if given compaction period x is <1-hour, compact every x duration. -// (e.g. --auto-compaction-mode 'periodic' --auto-compaction-retention='10m', then compact every 10-minute) -// if given compaction period x is >1-hour, compact every hour. -// (e.g. --auto-compaction-mode 'periodic' --auto-compaction-retention='2h', then compact every 1-hour) -func (pc *Periodic) getCompactInterval() time.Duration { - itv := pc.period - if itv > time.Hour { - itv = time.Hour - } - return itv -} - -func (pc *Periodic) getRetentions() int { - return int(pc.period/pc.getRetryInterval()) + 1 -} - -const retryDivisor = 10 - -func (pc *Periodic) getRetryInterval() time.Duration { - itv := pc.period - if itv > time.Hour { - itv = time.Hour - } - return itv / retryDivisor -} - -// Stop stops periodic compactor. -func (pc *Periodic) Stop() { - pc.cancel() -} - -// Pause pauses periodic compactor. -func (pc *Periodic) Pause() { - pc.mu.Lock() - pc.paused = true - pc.mu.Unlock() -} - -// Resume resumes periodic compactor. -func (pc *Periodic) Resume() { - pc.mu.Lock() - pc.paused = false - pc.mu.Unlock() -} diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3compactor/revision.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3compactor/revision.go deleted file mode 100644 index 83be627947..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3compactor/revision.go +++ /dev/null @@ -1,130 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package v3compactor - -import ( - "context" - "sync" - "time" - - pb "go.etcd.io/etcd/api/v3/etcdserverpb" - "go.etcd.io/etcd/server/v3/mvcc" - - "github.com/jonboulle/clockwork" - "go.uber.org/zap" -) - -// Revision compacts the log by purging revisions older than -// the configured reivison number. Compaction happens every 5 minutes. -type Revision struct { - lg *zap.Logger - - clock clockwork.Clock - retention int64 - - rg RevGetter - c Compactable - - ctx context.Context - cancel context.CancelFunc - - mu sync.Mutex - paused bool -} - -// newRevision creates a new instance of Revisonal compactor that purges -// the log older than retention revisions from the current revision. -func newRevision(lg *zap.Logger, clock clockwork.Clock, retention int64, rg RevGetter, c Compactable) *Revision { - rc := &Revision{ - lg: lg, - clock: clock, - retention: retention, - rg: rg, - c: c, - } - rc.ctx, rc.cancel = context.WithCancel(context.Background()) - return rc -} - -const revInterval = 5 * time.Minute - -// Run runs revision-based compactor. -func (rc *Revision) Run() { - prev := int64(0) - go func() { - for { - select { - case <-rc.ctx.Done(): - return - case <-rc.clock.After(revInterval): - rc.mu.Lock() - p := rc.paused - rc.mu.Unlock() - if p { - continue - } - } - - rev := rc.rg.Rev() - rc.retention - if rev <= 0 || rev == prev { - continue - } - - now := time.Now() - rc.lg.Info( - "starting auto revision compaction", - zap.Int64("revision", rev), - zap.Int64("revision-compaction-retention", rc.retention), - ) - _, err := rc.c.Compact(rc.ctx, &pb.CompactionRequest{Revision: rev}) - if err == nil || err == mvcc.ErrCompacted { - prev = rev - rc.lg.Info( - "completed auto revision compaction", - zap.Int64("revision", rev), - zap.Int64("revision-compaction-retention", rc.retention), - zap.Duration("took", time.Since(now)), - ) - } else { - rc.lg.Warn( - "failed auto revision compaction", - zap.Int64("revision", rev), - zap.Int64("revision-compaction-retention", rc.retention), - zap.Duration("retry-interval", revInterval), - zap.Error(err), - ) - } - } - }() -} - -// Stop stops revision-based compactor. -func (rc *Revision) Stop() { - rc.cancel() -} - -// Pause pauses revision-based compactor. -func (rc *Revision) Pause() { - rc.mu.Lock() - rc.paused = true - rc.mu.Unlock() -} - -// Resume resumes revision-based compactor. -func (rc *Revision) Resume() { - rc.mu.Lock() - rc.paused = false - rc.mu.Unlock() -} diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3election/doc.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3election/doc.go deleted file mode 100644 index d6fefd7415..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3election/doc.go +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package v3election provides a v3 election service from an etcdserver. -package v3election diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3election/election.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3election/election.go deleted file mode 100644 index 78b26ad7cc..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3election/election.go +++ /dev/null @@ -1,134 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package v3election - -import ( - "context" - "errors" - - "go.etcd.io/etcd/client/v3" - "go.etcd.io/etcd/client/v3/concurrency" - epb "go.etcd.io/etcd/server/v3/etcdserver/api/v3election/v3electionpb" -) - -// ErrMissingLeaderKey is returned when election API request -// is missing the "leader" field. -var ErrMissingLeaderKey = errors.New(`"leader" field must be provided`) - -type electionServer struct { - c *clientv3.Client -} - -func NewElectionServer(c *clientv3.Client) epb.ElectionServer { - return &electionServer{c} -} - -func (es *electionServer) Campaign(ctx context.Context, req *epb.CampaignRequest) (*epb.CampaignResponse, error) { - s, err := es.session(ctx, req.Lease) - if err != nil { - return nil, err - } - e := concurrency.NewElection(s, string(req.Name)) - if err = e.Campaign(ctx, string(req.Value)); err != nil { - return nil, err - } - return &epb.CampaignResponse{ - Header: e.Header(), - Leader: &epb.LeaderKey{ - Name: req.Name, - Key: []byte(e.Key()), - Rev: e.Rev(), - Lease: int64(s.Lease()), - }, - }, nil -} - -func (es *electionServer) Proclaim(ctx context.Context, req *epb.ProclaimRequest) (*epb.ProclaimResponse, error) { - if req.Leader == nil { - return nil, ErrMissingLeaderKey - } - s, err := es.session(ctx, req.Leader.Lease) - if err != nil { - return nil, err - } - e := concurrency.ResumeElection(s, string(req.Leader.Name), string(req.Leader.Key), req.Leader.Rev) - if err := e.Proclaim(ctx, string(req.Value)); err != nil { - return nil, err - } - return &epb.ProclaimResponse{Header: e.Header()}, nil -} - -func (es *electionServer) Observe(req *epb.LeaderRequest, stream epb.Election_ObserveServer) error { - s, err := es.session(stream.Context(), -1) - if err != nil { - return err - } - e := concurrency.NewElection(s, string(req.Name)) - ch := e.Observe(stream.Context()) - for stream.Context().Err() == nil { - select { - case <-stream.Context().Done(): - case resp, ok := <-ch: - if !ok { - return nil - } - lresp := &epb.LeaderResponse{Header: resp.Header, Kv: resp.Kvs[0]} - if err := stream.Send(lresp); err != nil { - return err - } - } - } - return stream.Context().Err() -} - -func (es *electionServer) Leader(ctx context.Context, req *epb.LeaderRequest) (*epb.LeaderResponse, error) { - s, err := es.session(ctx, -1) - if err != nil { - return nil, err - } - l, lerr := concurrency.NewElection(s, string(req.Name)).Leader(ctx) - if lerr != nil { - return nil, lerr - } - return &epb.LeaderResponse{Header: l.Header, Kv: l.Kvs[0]}, nil -} - -func (es *electionServer) Resign(ctx context.Context, req *epb.ResignRequest) (*epb.ResignResponse, error) { - if req.Leader == nil { - return nil, ErrMissingLeaderKey - } - s, err := es.session(ctx, req.Leader.Lease) - if err != nil { - return nil, err - } - e := concurrency.ResumeElection(s, string(req.Leader.Name), string(req.Leader.Key), req.Leader.Rev) - if err := e.Resign(ctx); err != nil { - return nil, err - } - return &epb.ResignResponse{Header: e.Header()}, nil -} - -func (es *electionServer) session(ctx context.Context, lease int64) (*concurrency.Session, error) { - s, err := concurrency.NewSession( - es.c, - concurrency.WithLease(clientv3.LeaseID(lease)), - concurrency.WithContext(ctx), - ) - if err != nil { - return nil, err - } - s.Orphan() - return s, nil -} diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3election/v3electionpb/gw/v3election.pb.gw.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3election/v3electionpb/gw/v3election.pb.gw.go deleted file mode 100644 index 4a6e5e724c..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3election/v3electionpb/gw/v3election.pb.gw.go +++ /dev/null @@ -1,454 +0,0 @@ -// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. -// source: server/etcdserver/api/v3election/v3electionpb/v3election.proto - -/* -Package v3electionpb is a reverse proxy. - -It translates gRPC into RESTful JSON APIs. -*/ -package gw - -import ( - "context" - "go.etcd.io/etcd/server/v3/etcdserver/api/v3election/v3electionpb" - "io" - "net/http" - - "github.com/golang/protobuf/descriptor" - "github.com/golang/protobuf/proto" - "github.com/grpc-ecosystem/grpc-gateway/runtime" - "github.com/grpc-ecosystem/grpc-gateway/utilities" - "google.golang.org/grpc" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/grpclog" - "google.golang.org/grpc/status" -) - -// Suppress "imported and not used" errors -var _ codes.Code -var _ io.Reader -var _ status.Status -var _ = runtime.String -var _ = utilities.NewDoubleArray -var _ = descriptor.ForMessage - -func request_Election_Campaign_0(ctx context.Context, marshaler runtime.Marshaler, client v3electionpb.ElectionClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq v3electionpb.CampaignRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.Campaign(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func local_request_Election_Campaign_0(ctx context.Context, marshaler runtime.Marshaler, server v3electionpb.ElectionServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq v3electionpb.CampaignRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := server.Campaign(ctx, &protoReq) - return msg, metadata, err - -} - -func request_Election_Proclaim_0(ctx context.Context, marshaler runtime.Marshaler, client v3electionpb.ElectionClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq v3electionpb.ProclaimRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.Proclaim(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func local_request_Election_Proclaim_0(ctx context.Context, marshaler runtime.Marshaler, server v3electionpb.ElectionServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq v3electionpb.ProclaimRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := server.Proclaim(ctx, &protoReq) - return msg, metadata, err - -} - -func request_Election_Leader_0(ctx context.Context, marshaler runtime.Marshaler, client v3electionpb.ElectionClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq v3electionpb.LeaderRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.Leader(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func local_request_Election_Leader_0(ctx context.Context, marshaler runtime.Marshaler, server v3electionpb.ElectionServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq v3electionpb.LeaderRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := server.Leader(ctx, &protoReq) - return msg, metadata, err - -} - -func request_Election_Observe_0(ctx context.Context, marshaler runtime.Marshaler, client v3electionpb.ElectionClient, req *http.Request, pathParams map[string]string) (v3electionpb.Election_ObserveClient, runtime.ServerMetadata, error) { - var protoReq v3electionpb.LeaderRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - stream, err := client.Observe(ctx, &protoReq) - if err != nil { - return nil, metadata, err - } - header, err := stream.Header() - if err != nil { - return nil, metadata, err - } - metadata.HeaderMD = header - return stream, metadata, nil - -} - -func request_Election_Resign_0(ctx context.Context, marshaler runtime.Marshaler, client v3electionpb.ElectionClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq v3electionpb.ResignRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.Resign(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func local_request_Election_Resign_0(ctx context.Context, marshaler runtime.Marshaler, server v3electionpb.ElectionServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq v3electionpb.ResignRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := server.Resign(ctx, &protoReq) - return msg, metadata, err - -} - -// v3electionpb.RegisterElectionHandlerServer registers the http handlers for service Election to "mux". -// UnaryRPC :call v3electionpb.ElectionServer directly. -// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. -func RegisterElectionHandlerServer(ctx context.Context, mux *runtime.ServeMux, server v3electionpb.ElectionServer) error { - - mux.Handle("POST", pattern_Election_Campaign_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := local_request_Election_Campaign_0(rctx, inboundMarshaler, server, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Election_Campaign_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Election_Proclaim_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := local_request_Election_Proclaim_0(rctx, inboundMarshaler, server, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Election_Proclaim_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Election_Leader_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := local_request_Election_Leader_0(rctx, inboundMarshaler, server, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Election_Leader_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Election_Observe_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - err := status.Error(codes.Unimplemented, "streaming calls are not yet supported in the in-process transport") - _, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - }) - - mux.Handle("POST", pattern_Election_Resign_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := local_request_Election_Resign_0(rctx, inboundMarshaler, server, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Election_Resign_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - return nil -} - -// RegisterElectionHandlerFromEndpoint is same as RegisterElectionHandler but -// automatically dials to "endpoint" and closes the connection when "ctx" gets done. -func RegisterElectionHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { - conn, err := grpc.Dial(endpoint, opts...) - if err != nil { - return err - } - defer func() { - if err != nil { - if cerr := conn.Close(); cerr != nil { - grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) - } - return - } - go func() { - <-ctx.Done() - if cerr := conn.Close(); cerr != nil { - grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) - } - }() - }() - - return RegisterElectionHandler(ctx, mux, conn) -} - -// RegisterElectionHandler registers the http handlers for service Election to "mux". -// The handlers forward requests to the grpc endpoint over "conn". -func RegisterElectionHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { - return RegisterElectionHandlerClient(ctx, mux, v3electionpb.NewElectionClient(conn)) -} - -// v3electionpb.RegisterElectionHandlerClient registers the http handlers for service Election -// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "ElectionClient". -// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "ElectionClient" -// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in -// "ElectionClient" to call the correct interceptors. -func RegisterElectionHandlerClient(ctx context.Context, mux *runtime.ServeMux, client v3electionpb.ElectionClient) error { - - mux.Handle("POST", pattern_Election_Campaign_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Election_Campaign_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Election_Campaign_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Election_Proclaim_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Election_Proclaim_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Election_Proclaim_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Election_Leader_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Election_Leader_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Election_Leader_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Election_Observe_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Election_Observe_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Election_Observe_0(ctx, mux, outboundMarshaler, w, req, func() (proto.Message, error) { return resp.Recv() }, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Election_Resign_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Election_Resign_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Election_Resign_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - return nil -} - -var ( - pattern_Election_Campaign_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v3", "election", "campaign"}, "", runtime.AssumeColonVerbOpt(true))) - - pattern_Election_Proclaim_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v3", "election", "proclaim"}, "", runtime.AssumeColonVerbOpt(true))) - - pattern_Election_Leader_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v3", "election", "leader"}, "", runtime.AssumeColonVerbOpt(true))) - - pattern_Election_Observe_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v3", "election", "observe"}, "", runtime.AssumeColonVerbOpt(true))) - - pattern_Election_Resign_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v3", "election", "resign"}, "", runtime.AssumeColonVerbOpt(true))) -) - -var ( - forward_Election_Campaign_0 = runtime.ForwardResponseMessage - - forward_Election_Proclaim_0 = runtime.ForwardResponseMessage - - forward_Election_Leader_0 = runtime.ForwardResponseMessage - - forward_Election_Observe_0 = runtime.ForwardResponseStream - - forward_Election_Resign_0 = runtime.ForwardResponseMessage -) diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3election/v3electionpb/v3election.pb.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3election/v3electionpb/v3election.pb.go deleted file mode 100644 index 81cf59b9b2..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3election/v3electionpb/v3election.pb.go +++ /dev/null @@ -1,2541 +0,0 @@ -// Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: v3election.proto - -package v3electionpb - -import ( - context "context" - fmt "fmt" - io "io" - math "math" - math_bits "math/bits" - - _ "github.com/gogo/protobuf/gogoproto" - proto "github.com/golang/protobuf/proto" - etcdserverpb "go.etcd.io/etcd/api/v3/etcdserverpb" - mvccpb "go.etcd.io/etcd/api/v3/mvccpb" - _ "google.golang.org/genproto/googleapis/api/annotations" - grpc "google.golang.org/grpc" - codes "google.golang.org/grpc/codes" - status "google.golang.org/grpc/status" -) - -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package - -type CampaignRequest struct { - // name is the election's identifier for the campaign. - Name []byte `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` - // lease is the ID of the lease attached to leadership of the election. If the - // lease expires or is revoked before resigning leadership, then the - // leadership is transferred to the next campaigner, if any. - Lease int64 `protobuf:"varint,2,opt,name=lease,proto3" json:"lease,omitempty"` - // value is the initial proclaimed value set when the campaigner wins the - // election. - Value []byte `protobuf:"bytes,3,opt,name=value,proto3" json:"value,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *CampaignRequest) Reset() { *m = CampaignRequest{} } -func (m *CampaignRequest) String() string { return proto.CompactTextString(m) } -func (*CampaignRequest) ProtoMessage() {} -func (*CampaignRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_c9b1f26cc432a035, []int{0} -} -func (m *CampaignRequest) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *CampaignRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_CampaignRequest.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *CampaignRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_CampaignRequest.Merge(m, src) -} -func (m *CampaignRequest) XXX_Size() int { - return m.Size() -} -func (m *CampaignRequest) XXX_DiscardUnknown() { - xxx_messageInfo_CampaignRequest.DiscardUnknown(m) -} - -var xxx_messageInfo_CampaignRequest proto.InternalMessageInfo - -func (m *CampaignRequest) GetName() []byte { - if m != nil { - return m.Name - } - return nil -} - -func (m *CampaignRequest) GetLease() int64 { - if m != nil { - return m.Lease - } - return 0 -} - -func (m *CampaignRequest) GetValue() []byte { - if m != nil { - return m.Value - } - return nil -} - -type CampaignResponse struct { - Header *etcdserverpb.ResponseHeader `protobuf:"bytes,1,opt,name=header,proto3" json:"header,omitempty"` - // leader describes the resources used for holding leadereship of the election. - Leader *LeaderKey `protobuf:"bytes,2,opt,name=leader,proto3" json:"leader,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *CampaignResponse) Reset() { *m = CampaignResponse{} } -func (m *CampaignResponse) String() string { return proto.CompactTextString(m) } -func (*CampaignResponse) ProtoMessage() {} -func (*CampaignResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_c9b1f26cc432a035, []int{1} -} -func (m *CampaignResponse) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *CampaignResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_CampaignResponse.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *CampaignResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_CampaignResponse.Merge(m, src) -} -func (m *CampaignResponse) XXX_Size() int { - return m.Size() -} -func (m *CampaignResponse) XXX_DiscardUnknown() { - xxx_messageInfo_CampaignResponse.DiscardUnknown(m) -} - -var xxx_messageInfo_CampaignResponse proto.InternalMessageInfo - -func (m *CampaignResponse) GetHeader() *etcdserverpb.ResponseHeader { - if m != nil { - return m.Header - } - return nil -} - -func (m *CampaignResponse) GetLeader() *LeaderKey { - if m != nil { - return m.Leader - } - return nil -} - -type LeaderKey struct { - // name is the election identifier that correponds to the leadership key. - Name []byte `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` - // key is an opaque key representing the ownership of the election. If the key - // is deleted, then leadership is lost. - Key []byte `protobuf:"bytes,2,opt,name=key,proto3" json:"key,omitempty"` - // rev is the creation revision of the key. It can be used to test for ownership - // of an election during transactions by testing the key's creation revision - // matches rev. - Rev int64 `protobuf:"varint,3,opt,name=rev,proto3" json:"rev,omitempty"` - // lease is the lease ID of the election leader. - Lease int64 `protobuf:"varint,4,opt,name=lease,proto3" json:"lease,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *LeaderKey) Reset() { *m = LeaderKey{} } -func (m *LeaderKey) String() string { return proto.CompactTextString(m) } -func (*LeaderKey) ProtoMessage() {} -func (*LeaderKey) Descriptor() ([]byte, []int) { - return fileDescriptor_c9b1f26cc432a035, []int{2} -} -func (m *LeaderKey) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *LeaderKey) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_LeaderKey.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *LeaderKey) XXX_Merge(src proto.Message) { - xxx_messageInfo_LeaderKey.Merge(m, src) -} -func (m *LeaderKey) XXX_Size() int { - return m.Size() -} -func (m *LeaderKey) XXX_DiscardUnknown() { - xxx_messageInfo_LeaderKey.DiscardUnknown(m) -} - -var xxx_messageInfo_LeaderKey proto.InternalMessageInfo - -func (m *LeaderKey) GetName() []byte { - if m != nil { - return m.Name - } - return nil -} - -func (m *LeaderKey) GetKey() []byte { - if m != nil { - return m.Key - } - return nil -} - -func (m *LeaderKey) GetRev() int64 { - if m != nil { - return m.Rev - } - return 0 -} - -func (m *LeaderKey) GetLease() int64 { - if m != nil { - return m.Lease - } - return 0 -} - -type LeaderRequest struct { - // name is the election identifier for the leadership information. - Name []byte `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *LeaderRequest) Reset() { *m = LeaderRequest{} } -func (m *LeaderRequest) String() string { return proto.CompactTextString(m) } -func (*LeaderRequest) ProtoMessage() {} -func (*LeaderRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_c9b1f26cc432a035, []int{3} -} -func (m *LeaderRequest) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *LeaderRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_LeaderRequest.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *LeaderRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_LeaderRequest.Merge(m, src) -} -func (m *LeaderRequest) XXX_Size() int { - return m.Size() -} -func (m *LeaderRequest) XXX_DiscardUnknown() { - xxx_messageInfo_LeaderRequest.DiscardUnknown(m) -} - -var xxx_messageInfo_LeaderRequest proto.InternalMessageInfo - -func (m *LeaderRequest) GetName() []byte { - if m != nil { - return m.Name - } - return nil -} - -type LeaderResponse struct { - Header *etcdserverpb.ResponseHeader `protobuf:"bytes,1,opt,name=header,proto3" json:"header,omitempty"` - // kv is the key-value pair representing the latest leader update. - Kv *mvccpb.KeyValue `protobuf:"bytes,2,opt,name=kv,proto3" json:"kv,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *LeaderResponse) Reset() { *m = LeaderResponse{} } -func (m *LeaderResponse) String() string { return proto.CompactTextString(m) } -func (*LeaderResponse) ProtoMessage() {} -func (*LeaderResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_c9b1f26cc432a035, []int{4} -} -func (m *LeaderResponse) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *LeaderResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_LeaderResponse.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *LeaderResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_LeaderResponse.Merge(m, src) -} -func (m *LeaderResponse) XXX_Size() int { - return m.Size() -} -func (m *LeaderResponse) XXX_DiscardUnknown() { - xxx_messageInfo_LeaderResponse.DiscardUnknown(m) -} - -var xxx_messageInfo_LeaderResponse proto.InternalMessageInfo - -func (m *LeaderResponse) GetHeader() *etcdserverpb.ResponseHeader { - if m != nil { - return m.Header - } - return nil -} - -func (m *LeaderResponse) GetKv() *mvccpb.KeyValue { - if m != nil { - return m.Kv - } - return nil -} - -type ResignRequest struct { - // leader is the leadership to relinquish by resignation. - Leader *LeaderKey `protobuf:"bytes,1,opt,name=leader,proto3" json:"leader,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *ResignRequest) Reset() { *m = ResignRequest{} } -func (m *ResignRequest) String() string { return proto.CompactTextString(m) } -func (*ResignRequest) ProtoMessage() {} -func (*ResignRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_c9b1f26cc432a035, []int{5} -} -func (m *ResignRequest) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *ResignRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_ResignRequest.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *ResignRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_ResignRequest.Merge(m, src) -} -func (m *ResignRequest) XXX_Size() int { - return m.Size() -} -func (m *ResignRequest) XXX_DiscardUnknown() { - xxx_messageInfo_ResignRequest.DiscardUnknown(m) -} - -var xxx_messageInfo_ResignRequest proto.InternalMessageInfo - -func (m *ResignRequest) GetLeader() *LeaderKey { - if m != nil { - return m.Leader - } - return nil -} - -type ResignResponse struct { - Header *etcdserverpb.ResponseHeader `protobuf:"bytes,1,opt,name=header,proto3" json:"header,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *ResignResponse) Reset() { *m = ResignResponse{} } -func (m *ResignResponse) String() string { return proto.CompactTextString(m) } -func (*ResignResponse) ProtoMessage() {} -func (*ResignResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_c9b1f26cc432a035, []int{6} -} -func (m *ResignResponse) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *ResignResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_ResignResponse.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *ResignResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_ResignResponse.Merge(m, src) -} -func (m *ResignResponse) XXX_Size() int { - return m.Size() -} -func (m *ResignResponse) XXX_DiscardUnknown() { - xxx_messageInfo_ResignResponse.DiscardUnknown(m) -} - -var xxx_messageInfo_ResignResponse proto.InternalMessageInfo - -func (m *ResignResponse) GetHeader() *etcdserverpb.ResponseHeader { - if m != nil { - return m.Header - } - return nil -} - -type ProclaimRequest struct { - // leader is the leadership hold on the election. - Leader *LeaderKey `protobuf:"bytes,1,opt,name=leader,proto3" json:"leader,omitempty"` - // value is an update meant to overwrite the leader's current value. - Value []byte `protobuf:"bytes,2,opt,name=value,proto3" json:"value,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *ProclaimRequest) Reset() { *m = ProclaimRequest{} } -func (m *ProclaimRequest) String() string { return proto.CompactTextString(m) } -func (*ProclaimRequest) ProtoMessage() {} -func (*ProclaimRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_c9b1f26cc432a035, []int{7} -} -func (m *ProclaimRequest) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *ProclaimRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_ProclaimRequest.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *ProclaimRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_ProclaimRequest.Merge(m, src) -} -func (m *ProclaimRequest) XXX_Size() int { - return m.Size() -} -func (m *ProclaimRequest) XXX_DiscardUnknown() { - xxx_messageInfo_ProclaimRequest.DiscardUnknown(m) -} - -var xxx_messageInfo_ProclaimRequest proto.InternalMessageInfo - -func (m *ProclaimRequest) GetLeader() *LeaderKey { - if m != nil { - return m.Leader - } - return nil -} - -func (m *ProclaimRequest) GetValue() []byte { - if m != nil { - return m.Value - } - return nil -} - -type ProclaimResponse struct { - Header *etcdserverpb.ResponseHeader `protobuf:"bytes,1,opt,name=header,proto3" json:"header,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *ProclaimResponse) Reset() { *m = ProclaimResponse{} } -func (m *ProclaimResponse) String() string { return proto.CompactTextString(m) } -func (*ProclaimResponse) ProtoMessage() {} -func (*ProclaimResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_c9b1f26cc432a035, []int{8} -} -func (m *ProclaimResponse) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *ProclaimResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_ProclaimResponse.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *ProclaimResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_ProclaimResponse.Merge(m, src) -} -func (m *ProclaimResponse) XXX_Size() int { - return m.Size() -} -func (m *ProclaimResponse) XXX_DiscardUnknown() { - xxx_messageInfo_ProclaimResponse.DiscardUnknown(m) -} - -var xxx_messageInfo_ProclaimResponse proto.InternalMessageInfo - -func (m *ProclaimResponse) GetHeader() *etcdserverpb.ResponseHeader { - if m != nil { - return m.Header - } - return nil -} - -func init() { - proto.RegisterType((*CampaignRequest)(nil), "v3electionpb.CampaignRequest") - proto.RegisterType((*CampaignResponse)(nil), "v3electionpb.CampaignResponse") - proto.RegisterType((*LeaderKey)(nil), "v3electionpb.LeaderKey") - proto.RegisterType((*LeaderRequest)(nil), "v3electionpb.LeaderRequest") - proto.RegisterType((*LeaderResponse)(nil), "v3electionpb.LeaderResponse") - proto.RegisterType((*ResignRequest)(nil), "v3electionpb.ResignRequest") - proto.RegisterType((*ResignResponse)(nil), "v3electionpb.ResignResponse") - proto.RegisterType((*ProclaimRequest)(nil), "v3electionpb.ProclaimRequest") - proto.RegisterType((*ProclaimResponse)(nil), "v3electionpb.ProclaimResponse") -} - -func init() { proto.RegisterFile("v3election.proto", fileDescriptor_c9b1f26cc432a035) } - -var fileDescriptor_c9b1f26cc432a035 = []byte{ - // 531 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x94, 0xcf, 0x6e, 0xd3, 0x40, - 0x10, 0xc6, 0x59, 0x27, 0x84, 0x32, 0xa4, 0xad, 0x65, 0x82, 0x08, 0x21, 0xb8, 0xd1, 0x72, 0xa9, - 0x72, 0xb0, 0x51, 0xc3, 0x29, 0x27, 0x04, 0x02, 0x55, 0x2a, 0x12, 0xe0, 0x03, 0x82, 0xe3, 0xda, - 0x1d, 0xb9, 0x91, 0x1d, 0xaf, 0xb1, 0x5d, 0x4b, 0xb9, 0xf2, 0x0a, 0x1c, 0xe0, 0x91, 0x38, 0x22, - 0xf1, 0x02, 0x28, 0xf0, 0x20, 0x68, 0x77, 0xed, 0xfa, 0x8f, 0x12, 0x84, 0x9a, 0xdb, 0x78, 0xe7, - 0xdb, 0xf9, 0xcd, 0x37, 0x3b, 0x09, 0xe8, 0xf9, 0x0c, 0x43, 0xf4, 0xb2, 0x05, 0x8f, 0xac, 0x38, - 0xe1, 0x19, 0x37, 0xfa, 0xd5, 0x49, 0xec, 0x8e, 0x06, 0x3e, 0xf7, 0xb9, 0x4c, 0xd8, 0x22, 0x52, - 0x9a, 0xd1, 0x11, 0x66, 0xde, 0xb9, 0xcd, 0xe2, 0x85, 0x2d, 0x82, 0x14, 0x93, 0x1c, 0x93, 0xd8, - 0xb5, 0x93, 0xd8, 0x2b, 0x04, 0xc3, 0x2b, 0xc1, 0x32, 0xf7, 0xbc, 0xd8, 0xb5, 0x83, 0xbc, 0xc8, - 0x8c, 0x7d, 0xce, 0xfd, 0x10, 0x65, 0x8e, 0x45, 0x11, 0xcf, 0x98, 0x20, 0xa5, 0x2a, 0x4b, 0xdf, - 0xc1, 0xe1, 0x0b, 0xb6, 0x8c, 0xd9, 0xc2, 0x8f, 0x1c, 0xfc, 0x74, 0x89, 0x69, 0x66, 0x18, 0xd0, - 0x8d, 0xd8, 0x12, 0x87, 0x64, 0x42, 0x8e, 0xfb, 0x8e, 0x8c, 0x8d, 0x01, 0xdc, 0x0c, 0x91, 0xa5, - 0x38, 0xd4, 0x26, 0xe4, 0xb8, 0xe3, 0xa8, 0x0f, 0x71, 0x9a, 0xb3, 0xf0, 0x12, 0x87, 0x1d, 0x29, - 0x55, 0x1f, 0x74, 0x05, 0x7a, 0x55, 0x32, 0x8d, 0x79, 0x94, 0xa2, 0xf1, 0x14, 0x7a, 0x17, 0xc8, - 0xce, 0x31, 0x91, 0x55, 0xef, 0x9c, 0x8c, 0xad, 0xba, 0x0f, 0xab, 0xd4, 0x9d, 0x4a, 0x8d, 0x53, - 0x68, 0x0d, 0x1b, 0x7a, 0xa1, 0xba, 0xa5, 0xc9, 0x5b, 0xf7, 0xad, 0xfa, 0xa8, 0xac, 0xd7, 0x32, - 0x77, 0x86, 0x2b, 0xa7, 0x90, 0xd1, 0x8f, 0x70, 0xfb, 0xea, 0x70, 0xa3, 0x0f, 0x1d, 0x3a, 0x01, - 0xae, 0x64, 0xb9, 0xbe, 0x23, 0x42, 0x71, 0x92, 0x60, 0x2e, 0x1d, 0x74, 0x1c, 0x11, 0x56, 0x5e, - 0xbb, 0x35, 0xaf, 0xf4, 0x31, 0xec, 0xab, 0xd2, 0xff, 0x18, 0x13, 0xbd, 0x80, 0x83, 0x52, 0xb4, - 0x93, 0xf1, 0x09, 0x68, 0x41, 0x5e, 0x98, 0xd6, 0x2d, 0xf5, 0xa2, 0xd6, 0x19, 0xae, 0xde, 0x8b, - 0x01, 0x3b, 0x5a, 0x90, 0xd3, 0x67, 0xb0, 0xef, 0x60, 0x5a, 0x7b, 0xb5, 0x6a, 0x56, 0xe4, 0xff, - 0x66, 0xf5, 0x0a, 0x0e, 0xca, 0x0a, 0xbb, 0xf4, 0x4a, 0x3f, 0xc0, 0xe1, 0xdb, 0x84, 0x7b, 0x21, - 0x5b, 0x2c, 0xaf, 0xdb, 0x4b, 0xb5, 0x48, 0x5a, 0x7d, 0x91, 0x4e, 0x41, 0xaf, 0x2a, 0xef, 0xd2, - 0xe3, 0xc9, 0xd7, 0x2e, 0xec, 0xbd, 0x2c, 0x1a, 0x30, 0x02, 0xd8, 0x2b, 0xf7, 0xd3, 0x78, 0xd4, - 0xec, 0xac, 0xf5, 0x53, 0x18, 0x99, 0xdb, 0xd2, 0x8a, 0x42, 0x27, 0x9f, 0x7f, 0xfe, 0xf9, 0xa2, - 0x8d, 0xe8, 0x3d, 0x3b, 0x9f, 0xd9, 0xa5, 0xd0, 0xf6, 0x0a, 0xd9, 0x9c, 0x4c, 0x05, 0xac, 0xf4, - 0xd0, 0x86, 0xb5, 0xa6, 0xd6, 0x86, 0xb5, 0xad, 0x6f, 0x81, 0xc5, 0x85, 0x4c, 0xc0, 0x3c, 0xe8, - 0xa9, 0xd9, 0x1a, 0x0f, 0x37, 0x4d, 0xbc, 0x04, 0x8d, 0x37, 0x27, 0x0b, 0x8c, 0x29, 0x31, 0x43, - 0x7a, 0xb7, 0x81, 0x51, 0x0f, 0x25, 0x20, 0x3e, 0xdc, 0x7a, 0xe3, 0xca, 0x81, 0xef, 0x42, 0x39, - 0x92, 0x94, 0x07, 0x74, 0xd0, 0xa0, 0x70, 0x55, 0x78, 0x4e, 0xa6, 0x4f, 0x88, 0x70, 0xa3, 0x16, - 0xb4, 0xcd, 0x69, 0x2c, 0x7e, 0x9b, 0xd3, 0xdc, 0xe9, 0x2d, 0x6e, 0x12, 0x29, 0x9a, 0x93, 0xe9, - 0x73, 0xfd, 0xfb, 0xda, 0x24, 0x3f, 0xd6, 0x26, 0xf9, 0xb5, 0x36, 0xc9, 0xb7, 0xdf, 0xe6, 0x0d, - 0xb7, 0x27, 0xff, 0x18, 0x67, 0x7f, 0x03, 0x00, 0x00, 0xff, 0xff, 0x9c, 0xe6, 0x7c, 0x66, 0xa9, - 0x05, 0x00, 0x00, -} - -// Reference imports to suppress errors if they are not otherwise used. -var _ context.Context -var _ grpc.ClientConn - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the grpc package it is being compiled against. -const _ = grpc.SupportPackageIsVersion4 - -// ElectionClient is the client API for Election service. -// -// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. -type ElectionClient interface { - // Campaign waits to acquire leadership in an election, returning a LeaderKey - // representing the leadership if successful. The LeaderKey can then be used - // to issue new values on the election, transactionally guard API requests on - // leadership still being held, and resign from the election. - Campaign(ctx context.Context, in *CampaignRequest, opts ...grpc.CallOption) (*CampaignResponse, error) - // Proclaim updates the leader's posted value with a new value. - Proclaim(ctx context.Context, in *ProclaimRequest, opts ...grpc.CallOption) (*ProclaimResponse, error) - // Leader returns the current election proclamation, if any. - Leader(ctx context.Context, in *LeaderRequest, opts ...grpc.CallOption) (*LeaderResponse, error) - // Observe streams election proclamations in-order as made by the election's - // elected leaders. - Observe(ctx context.Context, in *LeaderRequest, opts ...grpc.CallOption) (Election_ObserveClient, error) - // Resign releases election leadership so other campaigners may acquire - // leadership on the election. - Resign(ctx context.Context, in *ResignRequest, opts ...grpc.CallOption) (*ResignResponse, error) -} - -type electionClient struct { - cc *grpc.ClientConn -} - -func NewElectionClient(cc *grpc.ClientConn) ElectionClient { - return &electionClient{cc} -} - -func (c *electionClient) Campaign(ctx context.Context, in *CampaignRequest, opts ...grpc.CallOption) (*CampaignResponse, error) { - out := new(CampaignResponse) - err := c.cc.Invoke(ctx, "/v3electionpb.Election/Campaign", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *electionClient) Proclaim(ctx context.Context, in *ProclaimRequest, opts ...grpc.CallOption) (*ProclaimResponse, error) { - out := new(ProclaimResponse) - err := c.cc.Invoke(ctx, "/v3electionpb.Election/Proclaim", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *electionClient) Leader(ctx context.Context, in *LeaderRequest, opts ...grpc.CallOption) (*LeaderResponse, error) { - out := new(LeaderResponse) - err := c.cc.Invoke(ctx, "/v3electionpb.Election/Leader", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *electionClient) Observe(ctx context.Context, in *LeaderRequest, opts ...grpc.CallOption) (Election_ObserveClient, error) { - stream, err := c.cc.NewStream(ctx, &_Election_serviceDesc.Streams[0], "/v3electionpb.Election/Observe", opts...) - if err != nil { - return nil, err - } - x := &electionObserveClient{stream} - if err := x.ClientStream.SendMsg(in); err != nil { - return nil, err - } - if err := x.ClientStream.CloseSend(); err != nil { - return nil, err - } - return x, nil -} - -type Election_ObserveClient interface { - Recv() (*LeaderResponse, error) - grpc.ClientStream -} - -type electionObserveClient struct { - grpc.ClientStream -} - -func (x *electionObserveClient) Recv() (*LeaderResponse, error) { - m := new(LeaderResponse) - if err := x.ClientStream.RecvMsg(m); err != nil { - return nil, err - } - return m, nil -} - -func (c *electionClient) Resign(ctx context.Context, in *ResignRequest, opts ...grpc.CallOption) (*ResignResponse, error) { - out := new(ResignResponse) - err := c.cc.Invoke(ctx, "/v3electionpb.Election/Resign", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -// ElectionServer is the server API for Election service. -type ElectionServer interface { - // Campaign waits to acquire leadership in an election, returning a LeaderKey - // representing the leadership if successful. The LeaderKey can then be used - // to issue new values on the election, transactionally guard API requests on - // leadership still being held, and resign from the election. - Campaign(context.Context, *CampaignRequest) (*CampaignResponse, error) - // Proclaim updates the leader's posted value with a new value. - Proclaim(context.Context, *ProclaimRequest) (*ProclaimResponse, error) - // Leader returns the current election proclamation, if any. - Leader(context.Context, *LeaderRequest) (*LeaderResponse, error) - // Observe streams election proclamations in-order as made by the election's - // elected leaders. - Observe(*LeaderRequest, Election_ObserveServer) error - // Resign releases election leadership so other campaigners may acquire - // leadership on the election. - Resign(context.Context, *ResignRequest) (*ResignResponse, error) -} - -// UnimplementedElectionServer can be embedded to have forward compatible implementations. -type UnimplementedElectionServer struct { -} - -func (*UnimplementedElectionServer) Campaign(ctx context.Context, req *CampaignRequest) (*CampaignResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method Campaign not implemented") -} -func (*UnimplementedElectionServer) Proclaim(ctx context.Context, req *ProclaimRequest) (*ProclaimResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method Proclaim not implemented") -} -func (*UnimplementedElectionServer) Leader(ctx context.Context, req *LeaderRequest) (*LeaderResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method Leader not implemented") -} -func (*UnimplementedElectionServer) Observe(req *LeaderRequest, srv Election_ObserveServer) error { - return status.Errorf(codes.Unimplemented, "method Observe not implemented") -} -func (*UnimplementedElectionServer) Resign(ctx context.Context, req *ResignRequest) (*ResignResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method Resign not implemented") -} - -func RegisterElectionServer(s *grpc.Server, srv ElectionServer) { - s.RegisterService(&_Election_serviceDesc, srv) -} - -func _Election_Campaign_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(CampaignRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(ElectionServer).Campaign(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/v3electionpb.Election/Campaign", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(ElectionServer).Campaign(ctx, req.(*CampaignRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Election_Proclaim_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(ProclaimRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(ElectionServer).Proclaim(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/v3electionpb.Election/Proclaim", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(ElectionServer).Proclaim(ctx, req.(*ProclaimRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Election_Leader_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(LeaderRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(ElectionServer).Leader(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/v3electionpb.Election/Leader", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(ElectionServer).Leader(ctx, req.(*LeaderRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Election_Observe_Handler(srv interface{}, stream grpc.ServerStream) error { - m := new(LeaderRequest) - if err := stream.RecvMsg(m); err != nil { - return err - } - return srv.(ElectionServer).Observe(m, &electionObserveServer{stream}) -} - -type Election_ObserveServer interface { - Send(*LeaderResponse) error - grpc.ServerStream -} - -type electionObserveServer struct { - grpc.ServerStream -} - -func (x *electionObserveServer) Send(m *LeaderResponse) error { - return x.ServerStream.SendMsg(m) -} - -func _Election_Resign_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(ResignRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(ElectionServer).Resign(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/v3electionpb.Election/Resign", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(ElectionServer).Resign(ctx, req.(*ResignRequest)) - } - return interceptor(ctx, in, info, handler) -} - -var _Election_serviceDesc = grpc.ServiceDesc{ - ServiceName: "v3electionpb.Election", - HandlerType: (*ElectionServer)(nil), - Methods: []grpc.MethodDesc{ - { - MethodName: "Campaign", - Handler: _Election_Campaign_Handler, - }, - { - MethodName: "Proclaim", - Handler: _Election_Proclaim_Handler, - }, - { - MethodName: "Leader", - Handler: _Election_Leader_Handler, - }, - { - MethodName: "Resign", - Handler: _Election_Resign_Handler, - }, - }, - Streams: []grpc.StreamDesc{ - { - StreamName: "Observe", - Handler: _Election_Observe_Handler, - ServerStreams: true, - }, - }, - Metadata: "v3election.proto", -} - -func (m *CampaignRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *CampaignRequest) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *CampaignRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.XXX_unrecognized != nil { - i -= len(m.XXX_unrecognized) - copy(dAtA[i:], m.XXX_unrecognized) - } - if len(m.Value) > 0 { - i -= len(m.Value) - copy(dAtA[i:], m.Value) - i = encodeVarintV3Election(dAtA, i, uint64(len(m.Value))) - i-- - dAtA[i] = 0x1a - } - if m.Lease != 0 { - i = encodeVarintV3Election(dAtA, i, uint64(m.Lease)) - i-- - dAtA[i] = 0x10 - } - if len(m.Name) > 0 { - i -= len(m.Name) - copy(dAtA[i:], m.Name) - i = encodeVarintV3Election(dAtA, i, uint64(len(m.Name))) - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - -func (m *CampaignResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *CampaignResponse) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *CampaignResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.XXX_unrecognized != nil { - i -= len(m.XXX_unrecognized) - copy(dAtA[i:], m.XXX_unrecognized) - } - if m.Leader != nil { - { - size, err := m.Leader.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintV3Election(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x12 - } - if m.Header != nil { - { - size, err := m.Header.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintV3Election(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - -func (m *LeaderKey) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *LeaderKey) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *LeaderKey) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.XXX_unrecognized != nil { - i -= len(m.XXX_unrecognized) - copy(dAtA[i:], m.XXX_unrecognized) - } - if m.Lease != 0 { - i = encodeVarintV3Election(dAtA, i, uint64(m.Lease)) - i-- - dAtA[i] = 0x20 - } - if m.Rev != 0 { - i = encodeVarintV3Election(dAtA, i, uint64(m.Rev)) - i-- - dAtA[i] = 0x18 - } - if len(m.Key) > 0 { - i -= len(m.Key) - copy(dAtA[i:], m.Key) - i = encodeVarintV3Election(dAtA, i, uint64(len(m.Key))) - i-- - dAtA[i] = 0x12 - } - if len(m.Name) > 0 { - i -= len(m.Name) - copy(dAtA[i:], m.Name) - i = encodeVarintV3Election(dAtA, i, uint64(len(m.Name))) - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - -func (m *LeaderRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *LeaderRequest) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *LeaderRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.XXX_unrecognized != nil { - i -= len(m.XXX_unrecognized) - copy(dAtA[i:], m.XXX_unrecognized) - } - if len(m.Name) > 0 { - i -= len(m.Name) - copy(dAtA[i:], m.Name) - i = encodeVarintV3Election(dAtA, i, uint64(len(m.Name))) - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - -func (m *LeaderResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *LeaderResponse) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *LeaderResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.XXX_unrecognized != nil { - i -= len(m.XXX_unrecognized) - copy(dAtA[i:], m.XXX_unrecognized) - } - if m.Kv != nil { - { - size, err := m.Kv.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintV3Election(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x12 - } - if m.Header != nil { - { - size, err := m.Header.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintV3Election(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - -func (m *ResignRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *ResignRequest) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *ResignRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.XXX_unrecognized != nil { - i -= len(m.XXX_unrecognized) - copy(dAtA[i:], m.XXX_unrecognized) - } - if m.Leader != nil { - { - size, err := m.Leader.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintV3Election(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - -func (m *ResignResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *ResignResponse) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *ResignResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.XXX_unrecognized != nil { - i -= len(m.XXX_unrecognized) - copy(dAtA[i:], m.XXX_unrecognized) - } - if m.Header != nil { - { - size, err := m.Header.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintV3Election(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - -func (m *ProclaimRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *ProclaimRequest) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *ProclaimRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.XXX_unrecognized != nil { - i -= len(m.XXX_unrecognized) - copy(dAtA[i:], m.XXX_unrecognized) - } - if len(m.Value) > 0 { - i -= len(m.Value) - copy(dAtA[i:], m.Value) - i = encodeVarintV3Election(dAtA, i, uint64(len(m.Value))) - i-- - dAtA[i] = 0x12 - } - if m.Leader != nil { - { - size, err := m.Leader.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintV3Election(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - -func (m *ProclaimResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *ProclaimResponse) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *ProclaimResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.XXX_unrecognized != nil { - i -= len(m.XXX_unrecognized) - copy(dAtA[i:], m.XXX_unrecognized) - } - if m.Header != nil { - { - size, err := m.Header.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintV3Election(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - -func encodeVarintV3Election(dAtA []byte, offset int, v uint64) int { - offset -= sovV3Election(v) - base := offset - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return base -} -func (m *CampaignRequest) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = len(m.Name) - if l > 0 { - n += 1 + l + sovV3Election(uint64(l)) - } - if m.Lease != 0 { - n += 1 + sovV3Election(uint64(m.Lease)) - } - l = len(m.Value) - if l > 0 { - n += 1 + l + sovV3Election(uint64(l)) - } - if m.XXX_unrecognized != nil { - n += len(m.XXX_unrecognized) - } - return n -} - -func (m *CampaignResponse) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.Header != nil { - l = m.Header.Size() - n += 1 + l + sovV3Election(uint64(l)) - } - if m.Leader != nil { - l = m.Leader.Size() - n += 1 + l + sovV3Election(uint64(l)) - } - if m.XXX_unrecognized != nil { - n += len(m.XXX_unrecognized) - } - return n -} - -func (m *LeaderKey) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = len(m.Name) - if l > 0 { - n += 1 + l + sovV3Election(uint64(l)) - } - l = len(m.Key) - if l > 0 { - n += 1 + l + sovV3Election(uint64(l)) - } - if m.Rev != 0 { - n += 1 + sovV3Election(uint64(m.Rev)) - } - if m.Lease != 0 { - n += 1 + sovV3Election(uint64(m.Lease)) - } - if m.XXX_unrecognized != nil { - n += len(m.XXX_unrecognized) - } - return n -} - -func (m *LeaderRequest) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = len(m.Name) - if l > 0 { - n += 1 + l + sovV3Election(uint64(l)) - } - if m.XXX_unrecognized != nil { - n += len(m.XXX_unrecognized) - } - return n -} - -func (m *LeaderResponse) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.Header != nil { - l = m.Header.Size() - n += 1 + l + sovV3Election(uint64(l)) - } - if m.Kv != nil { - l = m.Kv.Size() - n += 1 + l + sovV3Election(uint64(l)) - } - if m.XXX_unrecognized != nil { - n += len(m.XXX_unrecognized) - } - return n -} - -func (m *ResignRequest) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.Leader != nil { - l = m.Leader.Size() - n += 1 + l + sovV3Election(uint64(l)) - } - if m.XXX_unrecognized != nil { - n += len(m.XXX_unrecognized) - } - return n -} - -func (m *ResignResponse) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.Header != nil { - l = m.Header.Size() - n += 1 + l + sovV3Election(uint64(l)) - } - if m.XXX_unrecognized != nil { - n += len(m.XXX_unrecognized) - } - return n -} - -func (m *ProclaimRequest) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.Leader != nil { - l = m.Leader.Size() - n += 1 + l + sovV3Election(uint64(l)) - } - l = len(m.Value) - if l > 0 { - n += 1 + l + sovV3Election(uint64(l)) - } - if m.XXX_unrecognized != nil { - n += len(m.XXX_unrecognized) - } - return n -} - -func (m *ProclaimResponse) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.Header != nil { - l = m.Header.Size() - n += 1 + l + sovV3Election(uint64(l)) - } - if m.XXX_unrecognized != nil { - n += len(m.XXX_unrecognized) - } - return n -} - -func sovV3Election(x uint64) (n int) { - return (math_bits.Len64(x|1) + 6) / 7 -} -func sozV3Election(x uint64) (n int) { - return sovV3Election(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} -func (m *CampaignRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowV3Election - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: CampaignRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: CampaignRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Name", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowV3Election - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthV3Election - } - postIndex := iNdEx + byteLen - if postIndex < 0 { - return ErrInvalidLengthV3Election - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Name = append(m.Name[:0], dAtA[iNdEx:postIndex]...) - if m.Name == nil { - m.Name = []byte{} - } - iNdEx = postIndex - case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Lease", wireType) - } - m.Lease = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowV3Election - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Lease |= int64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Value", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowV3Election - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthV3Election - } - postIndex := iNdEx + byteLen - if postIndex < 0 { - return ErrInvalidLengthV3Election - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Value = append(m.Value[:0], dAtA[iNdEx:postIndex]...) - if m.Value == nil { - m.Value = []byte{} - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipV3Election(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthV3Election - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *CampaignResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowV3Election - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: CampaignResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: CampaignResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Header", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowV3Election - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthV3Election - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthV3Election - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Header == nil { - m.Header = &etcdserverpb.ResponseHeader{} - } - if err := m.Header.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Leader", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowV3Election - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthV3Election - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthV3Election - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Leader == nil { - m.Leader = &LeaderKey{} - } - if err := m.Leader.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipV3Election(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthV3Election - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *LeaderKey) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowV3Election - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: LeaderKey: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: LeaderKey: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Name", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowV3Election - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthV3Election - } - postIndex := iNdEx + byteLen - if postIndex < 0 { - return ErrInvalidLengthV3Election - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Name = append(m.Name[:0], dAtA[iNdEx:postIndex]...) - if m.Name == nil { - m.Name = []byte{} - } - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Key", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowV3Election - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthV3Election - } - postIndex := iNdEx + byteLen - if postIndex < 0 { - return ErrInvalidLengthV3Election - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Key = append(m.Key[:0], dAtA[iNdEx:postIndex]...) - if m.Key == nil { - m.Key = []byte{} - } - iNdEx = postIndex - case 3: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Rev", wireType) - } - m.Rev = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowV3Election - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Rev |= int64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 4: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Lease", wireType) - } - m.Lease = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowV3Election - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Lease |= int64(b&0x7F) << shift - if b < 0x80 { - break - } - } - default: - iNdEx = preIndex - skippy, err := skipV3Election(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthV3Election - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *LeaderRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowV3Election - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: LeaderRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: LeaderRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Name", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowV3Election - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthV3Election - } - postIndex := iNdEx + byteLen - if postIndex < 0 { - return ErrInvalidLengthV3Election - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Name = append(m.Name[:0], dAtA[iNdEx:postIndex]...) - if m.Name == nil { - m.Name = []byte{} - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipV3Election(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthV3Election - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *LeaderResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowV3Election - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: LeaderResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: LeaderResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Header", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowV3Election - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthV3Election - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthV3Election - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Header == nil { - m.Header = &etcdserverpb.ResponseHeader{} - } - if err := m.Header.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Kv", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowV3Election - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthV3Election - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthV3Election - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Kv == nil { - m.Kv = &mvccpb.KeyValue{} - } - if err := m.Kv.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipV3Election(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthV3Election - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *ResignRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowV3Election - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: ResignRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: ResignRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Leader", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowV3Election - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthV3Election - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthV3Election - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Leader == nil { - m.Leader = &LeaderKey{} - } - if err := m.Leader.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipV3Election(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthV3Election - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *ResignResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowV3Election - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: ResignResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: ResignResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Header", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowV3Election - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthV3Election - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthV3Election - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Header == nil { - m.Header = &etcdserverpb.ResponseHeader{} - } - if err := m.Header.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipV3Election(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthV3Election - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *ProclaimRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowV3Election - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: ProclaimRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: ProclaimRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Leader", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowV3Election - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthV3Election - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthV3Election - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Leader == nil { - m.Leader = &LeaderKey{} - } - if err := m.Leader.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Value", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowV3Election - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthV3Election - } - postIndex := iNdEx + byteLen - if postIndex < 0 { - return ErrInvalidLengthV3Election - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Value = append(m.Value[:0], dAtA[iNdEx:postIndex]...) - if m.Value == nil { - m.Value = []byte{} - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipV3Election(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthV3Election - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *ProclaimResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowV3Election - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: ProclaimResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: ProclaimResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Header", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowV3Election - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthV3Election - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthV3Election - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Header == nil { - m.Header = &etcdserverpb.ResponseHeader{} - } - if err := m.Header.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipV3Election(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthV3Election - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func skipV3Election(dAtA []byte) (n int, err error) { - l := len(dAtA) - iNdEx := 0 - depth := 0 - for iNdEx < l { - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowV3Election - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - wireType := int(wire & 0x7) - switch wireType { - case 0: - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowV3Election - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - iNdEx++ - if dAtA[iNdEx-1] < 0x80 { - break - } - } - case 1: - iNdEx += 8 - case 2: - var length int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowV3Election - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - length |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if length < 0 { - return 0, ErrInvalidLengthV3Election - } - iNdEx += length - case 3: - depth++ - case 4: - if depth == 0 { - return 0, ErrUnexpectedEndOfGroupV3Election - } - depth-- - case 5: - iNdEx += 4 - default: - return 0, fmt.Errorf("proto: illegal wireType %d", wireType) - } - if iNdEx < 0 { - return 0, ErrInvalidLengthV3Election - } - if depth == 0 { - return iNdEx, nil - } - } - return 0, io.ErrUnexpectedEOF -} - -var ( - ErrInvalidLengthV3Election = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowV3Election = fmt.Errorf("proto: integer overflow") - ErrUnexpectedEndOfGroupV3Election = fmt.Errorf("proto: unexpected end of group") -) diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3election/v3electionpb/v3election.proto b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3election/v3electionpb/v3election.proto deleted file mode 100644 index 24ccaf138d..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3election/v3electionpb/v3election.proto +++ /dev/null @@ -1,119 +0,0 @@ -syntax = "proto3"; -package v3electionpb; - -import "gogoproto/gogo.proto"; -import "etcd/api/etcdserverpb/rpc.proto"; -import "etcd/api/mvccpb/kv.proto"; - -// for grpc-gateway -import "google/api/annotations.proto"; - -option (gogoproto.marshaler_all) = true; -option (gogoproto.unmarshaler_all) = true; - -// The election service exposes client-side election facilities as a gRPC interface. -service Election { - // Campaign waits to acquire leadership in an election, returning a LeaderKey - // representing the leadership if successful. The LeaderKey can then be used - // to issue new values on the election, transactionally guard API requests on - // leadership still being held, and resign from the election. - rpc Campaign(CampaignRequest) returns (CampaignResponse) { - option (google.api.http) = { - post: "/v3/election/campaign" - body: "*" - }; - } - // Proclaim updates the leader's posted value with a new value. - rpc Proclaim(ProclaimRequest) returns (ProclaimResponse) { - option (google.api.http) = { - post: "/v3/election/proclaim" - body: "*" - }; - } - // Leader returns the current election proclamation, if any. - rpc Leader(LeaderRequest) returns (LeaderResponse) { - option (google.api.http) = { - post: "/v3/election/leader" - body: "*" - }; - } - // Observe streams election proclamations in-order as made by the election's - // elected leaders. - rpc Observe(LeaderRequest) returns (stream LeaderResponse) { - option (google.api.http) = { - post: "/v3/election/observe" - body: "*" - }; - } - // Resign releases election leadership so other campaigners may acquire - // leadership on the election. - rpc Resign(ResignRequest) returns (ResignResponse) { - option (google.api.http) = { - post: "/v3/election/resign" - body: "*" - }; - } -} - -message CampaignRequest { - // name is the election's identifier for the campaign. - bytes name = 1; - // lease is the ID of the lease attached to leadership of the election. If the - // lease expires or is revoked before resigning leadership, then the - // leadership is transferred to the next campaigner, if any. - int64 lease = 2; - // value is the initial proclaimed value set when the campaigner wins the - // election. - bytes value = 3; -} - -message CampaignResponse { - etcdserverpb.ResponseHeader header = 1; - // leader describes the resources used for holding leadereship of the election. - LeaderKey leader = 2; -} - -message LeaderKey { - // name is the election identifier that correponds to the leadership key. - bytes name = 1; - // key is an opaque key representing the ownership of the election. If the key - // is deleted, then leadership is lost. - bytes key = 2; - // rev is the creation revision of the key. It can be used to test for ownership - // of an election during transactions by testing the key's creation revision - // matches rev. - int64 rev = 3; - // lease is the lease ID of the election leader. - int64 lease = 4; -} - -message LeaderRequest { - // name is the election identifier for the leadership information. - bytes name = 1; -} - -message LeaderResponse { - etcdserverpb.ResponseHeader header = 1; - // kv is the key-value pair representing the latest leader update. - mvccpb.KeyValue kv = 2; -} - -message ResignRequest { - // leader is the leadership to relinquish by resignation. - LeaderKey leader = 1; -} - -message ResignResponse { - etcdserverpb.ResponseHeader header = 1; -} - -message ProclaimRequest { - // leader is the leadership hold on the election. - LeaderKey leader = 1; - // value is an update meant to overwrite the leader's current value. - bytes value = 2; -} - -message ProclaimResponse { - etcdserverpb.ResponseHeader header = 1; -} diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3lock/doc.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3lock/doc.go deleted file mode 100644 index e0a1008abc..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3lock/doc.go +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package v3lock provides a v3 locking service from an etcdserver. -package v3lock diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3lock/lock.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3lock/lock.go deleted file mode 100644 index 8f9623361c..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3lock/lock.go +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package v3lock - -import ( - "context" - - "go.etcd.io/etcd/client/v3" - "go.etcd.io/etcd/client/v3/concurrency" - "go.etcd.io/etcd/server/v3/etcdserver/api/v3lock/v3lockpb" -) - -type lockServer struct { - c *clientv3.Client -} - -func NewLockServer(c *clientv3.Client) v3lockpb.LockServer { - return &lockServer{c} -} - -func (ls *lockServer) Lock(ctx context.Context, req *v3lockpb.LockRequest) (*v3lockpb.LockResponse, error) { - s, err := concurrency.NewSession( - ls.c, - concurrency.WithLease(clientv3.LeaseID(req.Lease)), - concurrency.WithContext(ctx), - ) - if err != nil { - return nil, err - } - s.Orphan() - m := concurrency.NewMutex(s, string(req.Name)) - if err = m.Lock(ctx); err != nil { - return nil, err - } - return &v3lockpb.LockResponse{Header: m.Header(), Key: []byte(m.Key())}, nil -} - -func (ls *lockServer) Unlock(ctx context.Context, req *v3lockpb.UnlockRequest) (*v3lockpb.UnlockResponse, error) { - resp, err := ls.c.Delete(ctx, string(req.Key)) - if err != nil { - return nil, err - } - return &v3lockpb.UnlockResponse{Header: resp.Header}, nil -} diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3lock/v3lockpb/gw/v3lock.pb.gw.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3lock/v3lockpb/gw/v3lock.pb.gw.go deleted file mode 100644 index dc573d79cf..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3lock/v3lockpb/gw/v3lock.pb.gw.go +++ /dev/null @@ -1,242 +0,0 @@ -// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. -// source: server/etcdserver/api/v3lock/v3lockpb/v3lock.proto - -/* -Package v3lockpb is a reverse proxy. - -It translates gRPC into RESTful JSON APIs. -*/ -package gw - -import ( - "context" - "go.etcd.io/etcd/server/v3/etcdserver/api/v3lock/v3lockpb" - "io" - "net/http" - - "github.com/golang/protobuf/descriptor" - "github.com/golang/protobuf/proto" - "github.com/grpc-ecosystem/grpc-gateway/runtime" - "github.com/grpc-ecosystem/grpc-gateway/utilities" - "google.golang.org/grpc" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/grpclog" - "google.golang.org/grpc/status" -) - -// Suppress "imported and not used" errors -var _ codes.Code -var _ io.Reader -var _ status.Status -var _ = runtime.String -var _ = utilities.NewDoubleArray -var _ = descriptor.ForMessage - -func request_Lock_Lock_0(ctx context.Context, marshaler runtime.Marshaler, client v3lockpb.LockClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq v3lockpb.LockRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.Lock(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func local_request_Lock_Lock_0(ctx context.Context, marshaler runtime.Marshaler, server v3lockpb.LockServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq v3lockpb.LockRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := server.Lock(ctx, &protoReq) - return msg, metadata, err - -} - -func request_Lock_Unlock_0(ctx context.Context, marshaler runtime.Marshaler, client v3lockpb.LockClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq v3lockpb.UnlockRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.Unlock(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func local_request_Lock_Unlock_0(ctx context.Context, marshaler runtime.Marshaler, server v3lockpb.LockServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq v3lockpb.UnlockRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := server.Unlock(ctx, &protoReq) - return msg, metadata, err - -} - -// v3lockpb.RegisterLockHandlerServer registers the http handlers for service Lock to "mux". -// UnaryRPC :call v3lockpb.LockServer directly. -// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. -func RegisterLockHandlerServer(ctx context.Context, mux *runtime.ServeMux, server v3lockpb.LockServer) error { - - mux.Handle("POST", pattern_Lock_Lock_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := local_request_Lock_Lock_0(rctx, inboundMarshaler, server, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Lock_Lock_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Lock_Unlock_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := local_request_Lock_Unlock_0(rctx, inboundMarshaler, server, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Lock_Unlock_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - return nil -} - -// RegisterLockHandlerFromEndpoint is same as RegisterLockHandler but -// automatically dials to "endpoint" and closes the connection when "ctx" gets done. -func RegisterLockHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { - conn, err := grpc.Dial(endpoint, opts...) - if err != nil { - return err - } - defer func() { - if err != nil { - if cerr := conn.Close(); cerr != nil { - grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) - } - return - } - go func() { - <-ctx.Done() - if cerr := conn.Close(); cerr != nil { - grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) - } - }() - }() - - return RegisterLockHandler(ctx, mux, conn) -} - -// RegisterLockHandler registers the http handlers for service Lock to "mux". -// The handlers forward requests to the grpc endpoint over "conn". -func RegisterLockHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { - return RegisterLockHandlerClient(ctx, mux, v3lockpb.NewLockClient(conn)) -} - -// v3lockpb.RegisterLockHandlerClient registers the http handlers for service Lock -// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "LockClient". -// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "LockClient" -// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in -// "LockClient" to call the correct interceptors. -func RegisterLockHandlerClient(ctx context.Context, mux *runtime.ServeMux, client v3lockpb.LockClient) error { - - mux.Handle("POST", pattern_Lock_Lock_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Lock_Lock_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Lock_Lock_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_Lock_Unlock_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Lock_Unlock_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Lock_Unlock_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - return nil -} - -var ( - pattern_Lock_Lock_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 1}, []string{"v3", "lock"}, "", runtime.AssumeColonVerbOpt(true))) - - pattern_Lock_Unlock_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v3", "lock", "unlock"}, "", runtime.AssumeColonVerbOpt(true))) -) - -var ( - forward_Lock_Lock_0 = runtime.ForwardResponseMessage - - forward_Lock_Unlock_0 = runtime.ForwardResponseMessage -) diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3lock/v3lockpb/v3lock.pb.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3lock/v3lockpb/v3lock.pb.go deleted file mode 100644 index 4282ddc85e..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3lock/v3lockpb/v3lock.pb.go +++ /dev/null @@ -1,1141 +0,0 @@ -// Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: v3lock.proto - -package v3lockpb - -import ( - context "context" - fmt "fmt" - io "io" - math "math" - math_bits "math/bits" - - _ "github.com/gogo/protobuf/gogoproto" - proto "github.com/golang/protobuf/proto" - etcdserverpb "go.etcd.io/etcd/api/v3/etcdserverpb" - _ "google.golang.org/genproto/googleapis/api/annotations" - grpc "google.golang.org/grpc" - codes "google.golang.org/grpc/codes" - status "google.golang.org/grpc/status" -) - -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package - -type LockRequest struct { - // name is the identifier for the distributed shared lock to be acquired. - Name []byte `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` - // lease is the ID of the lease that will be attached to ownership of the - // lock. If the lease expires or is revoked and currently holds the lock, - // the lock is automatically released. Calls to Lock with the same lease will - // be treated as a single acquisition; locking twice with the same lease is a - // no-op. - Lease int64 `protobuf:"varint,2,opt,name=lease,proto3" json:"lease,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *LockRequest) Reset() { *m = LockRequest{} } -func (m *LockRequest) String() string { return proto.CompactTextString(m) } -func (*LockRequest) ProtoMessage() {} -func (*LockRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_52389b3e2f253201, []int{0} -} -func (m *LockRequest) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *LockRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_LockRequest.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *LockRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_LockRequest.Merge(m, src) -} -func (m *LockRequest) XXX_Size() int { - return m.Size() -} -func (m *LockRequest) XXX_DiscardUnknown() { - xxx_messageInfo_LockRequest.DiscardUnknown(m) -} - -var xxx_messageInfo_LockRequest proto.InternalMessageInfo - -func (m *LockRequest) GetName() []byte { - if m != nil { - return m.Name - } - return nil -} - -func (m *LockRequest) GetLease() int64 { - if m != nil { - return m.Lease - } - return 0 -} - -type LockResponse struct { - Header *etcdserverpb.ResponseHeader `protobuf:"bytes,1,opt,name=header,proto3" json:"header,omitempty"` - // key is a key that will exist on etcd for the duration that the Lock caller - // owns the lock. Users should not modify this key or the lock may exhibit - // undefined behavior. - Key []byte `protobuf:"bytes,2,opt,name=key,proto3" json:"key,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *LockResponse) Reset() { *m = LockResponse{} } -func (m *LockResponse) String() string { return proto.CompactTextString(m) } -func (*LockResponse) ProtoMessage() {} -func (*LockResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_52389b3e2f253201, []int{1} -} -func (m *LockResponse) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *LockResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_LockResponse.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *LockResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_LockResponse.Merge(m, src) -} -func (m *LockResponse) XXX_Size() int { - return m.Size() -} -func (m *LockResponse) XXX_DiscardUnknown() { - xxx_messageInfo_LockResponse.DiscardUnknown(m) -} - -var xxx_messageInfo_LockResponse proto.InternalMessageInfo - -func (m *LockResponse) GetHeader() *etcdserverpb.ResponseHeader { - if m != nil { - return m.Header - } - return nil -} - -func (m *LockResponse) GetKey() []byte { - if m != nil { - return m.Key - } - return nil -} - -type UnlockRequest struct { - // key is the lock ownership key granted by Lock. - Key []byte `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *UnlockRequest) Reset() { *m = UnlockRequest{} } -func (m *UnlockRequest) String() string { return proto.CompactTextString(m) } -func (*UnlockRequest) ProtoMessage() {} -func (*UnlockRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_52389b3e2f253201, []int{2} -} -func (m *UnlockRequest) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *UnlockRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_UnlockRequest.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *UnlockRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_UnlockRequest.Merge(m, src) -} -func (m *UnlockRequest) XXX_Size() int { - return m.Size() -} -func (m *UnlockRequest) XXX_DiscardUnknown() { - xxx_messageInfo_UnlockRequest.DiscardUnknown(m) -} - -var xxx_messageInfo_UnlockRequest proto.InternalMessageInfo - -func (m *UnlockRequest) GetKey() []byte { - if m != nil { - return m.Key - } - return nil -} - -type UnlockResponse struct { - Header *etcdserverpb.ResponseHeader `protobuf:"bytes,1,opt,name=header,proto3" json:"header,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *UnlockResponse) Reset() { *m = UnlockResponse{} } -func (m *UnlockResponse) String() string { return proto.CompactTextString(m) } -func (*UnlockResponse) ProtoMessage() {} -func (*UnlockResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_52389b3e2f253201, []int{3} -} -func (m *UnlockResponse) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *UnlockResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_UnlockResponse.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *UnlockResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_UnlockResponse.Merge(m, src) -} -func (m *UnlockResponse) XXX_Size() int { - return m.Size() -} -func (m *UnlockResponse) XXX_DiscardUnknown() { - xxx_messageInfo_UnlockResponse.DiscardUnknown(m) -} - -var xxx_messageInfo_UnlockResponse proto.InternalMessageInfo - -func (m *UnlockResponse) GetHeader() *etcdserverpb.ResponseHeader { - if m != nil { - return m.Header - } - return nil -} - -func init() { - proto.RegisterType((*LockRequest)(nil), "v3lockpb.LockRequest") - proto.RegisterType((*LockResponse)(nil), "v3lockpb.LockResponse") - proto.RegisterType((*UnlockRequest)(nil), "v3lockpb.UnlockRequest") - proto.RegisterType((*UnlockResponse)(nil), "v3lockpb.UnlockResponse") -} - -func init() { proto.RegisterFile("v3lock.proto", fileDescriptor_52389b3e2f253201) } - -var fileDescriptor_52389b3e2f253201 = []byte{ - // 330 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x29, 0x33, 0xce, 0xc9, - 0x4f, 0xce, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0xe2, 0x80, 0xf0, 0x0a, 0x92, 0xa4, 0x44, - 0xd2, 0xf3, 0xd3, 0xf3, 0xc1, 0x82, 0xfa, 0x20, 0x16, 0x44, 0x5e, 0x4a, 0x3e, 0xb5, 0x24, 0x39, - 0x45, 0x3f, 0xb1, 0x20, 0x53, 0x1f, 0xc4, 0x28, 0x4e, 0x2d, 0x2a, 0x4b, 0x2d, 0x2a, 0x48, 0xd2, - 0x2f, 0x2a, 0x48, 0x86, 0x2a, 0x90, 0x49, 0xcf, 0xcf, 0x4f, 0xcf, 0x49, 0x05, 0x2b, 0x49, 0xcc, - 0xcb, 0xcb, 0x2f, 0x49, 0x2c, 0xc9, 0xcc, 0xcf, 0x2b, 0x86, 0xc8, 0x2a, 0x99, 0x73, 0x71, 0xfb, - 0xe4, 0x27, 0x67, 0x07, 0xa5, 0x16, 0x96, 0xa6, 0x16, 0x97, 0x08, 0x09, 0x71, 0xb1, 0xe4, 0x25, - 0xe6, 0xa6, 0x4a, 0x30, 0x2a, 0x30, 0x6a, 0xf0, 0x04, 0x81, 0xd9, 0x42, 0x22, 0x5c, 0xac, 0x39, - 0xa9, 0x89, 0xc5, 0xa9, 0x12, 0x4c, 0x0a, 0x8c, 0x1a, 0xcc, 0x41, 0x10, 0x8e, 0x52, 0x18, 0x17, - 0x0f, 0x44, 0x63, 0x71, 0x41, 0x7e, 0x5e, 0x71, 0xaa, 0x90, 0x09, 0x17, 0x5b, 0x46, 0x6a, 0x62, - 0x4a, 0x6a, 0x11, 0x58, 0x2f, 0xb7, 0x91, 0x8c, 0x1e, 0xb2, 0x7b, 0xf4, 0x60, 0xea, 0x3c, 0xc0, - 0x6a, 0x82, 0xa0, 0x6a, 0x85, 0x04, 0xb8, 0x98, 0xb3, 0x53, 0x2b, 0xc1, 0x26, 0xf3, 0x04, 0x81, - 0x98, 0x4a, 0x8a, 0x5c, 0xbc, 0xa1, 0x79, 0x39, 0x48, 0x4e, 0x82, 0x2a, 0x61, 0x44, 0x28, 0x71, - 0xe3, 0xe2, 0x83, 0x29, 0xa1, 0xc4, 0x72, 0xa3, 0x0d, 0x8c, 0x5c, 0x2c, 0x20, 0x3f, 0x08, 0xf9, - 0x43, 0x69, 0x51, 0x3d, 0x58, 0x60, 0xeb, 0x21, 0x05, 0x8a, 0x94, 0x18, 0xba, 0x30, 0xc4, 0x34, - 0x25, 0x89, 0xa6, 0xcb, 0x4f, 0x26, 0x33, 0x09, 0x29, 0xf1, 0xea, 0x97, 0x19, 0xeb, 0x83, 0x14, - 0x80, 0x09, 0x2b, 0x46, 0x2d, 0xa1, 0x70, 0x2e, 0x36, 0x88, 0x0b, 0x85, 0xc4, 0x11, 0x7a, 0x51, - 0xbc, 0x25, 0x25, 0x81, 0x29, 0x01, 0x35, 0x56, 0x0a, 0x6c, 0xac, 0x88, 0x12, 0x3f, 0xdc, 0xd8, - 0xd2, 0x3c, 0xa8, 0xc1, 0x4e, 0x02, 0x27, 0x1e, 0xc9, 0x31, 0x5e, 0x78, 0x24, 0xc7, 0xf8, 0xe0, - 0x91, 0x1c, 0xe3, 0x8c, 0xc7, 0x72, 0x0c, 0x49, 0x6c, 0xe0, 0x78, 0x34, 0x06, 0x04, 0x00, 0x00, - 0xff, 0xff, 0x4a, 0x4d, 0xca, 0xbb, 0x36, 0x02, 0x00, 0x00, -} - -// Reference imports to suppress errors if they are not otherwise used. -var _ context.Context -var _ grpc.ClientConn - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the grpc package it is being compiled against. -const _ = grpc.SupportPackageIsVersion4 - -// LockClient is the client API for Lock service. -// -// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. -type LockClient interface { - // Lock acquires a distributed shared lock on a given named lock. - // On success, it will return a unique key that exists so long as the - // lock is held by the caller. This key can be used in conjunction with - // transactions to safely ensure updates to etcd only occur while holding - // lock ownership. The lock is held until Unlock is called on the key or the - // lease associate with the owner expires. - Lock(ctx context.Context, in *LockRequest, opts ...grpc.CallOption) (*LockResponse, error) - // Unlock takes a key returned by Lock and releases the hold on lock. The - // next Lock caller waiting for the lock will then be woken up and given - // ownership of the lock. - Unlock(ctx context.Context, in *UnlockRequest, opts ...grpc.CallOption) (*UnlockResponse, error) -} - -type lockClient struct { - cc *grpc.ClientConn -} - -func NewLockClient(cc *grpc.ClientConn) LockClient { - return &lockClient{cc} -} - -func (c *lockClient) Lock(ctx context.Context, in *LockRequest, opts ...grpc.CallOption) (*LockResponse, error) { - out := new(LockResponse) - err := c.cc.Invoke(ctx, "/v3lockpb.Lock/Lock", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *lockClient) Unlock(ctx context.Context, in *UnlockRequest, opts ...grpc.CallOption) (*UnlockResponse, error) { - out := new(UnlockResponse) - err := c.cc.Invoke(ctx, "/v3lockpb.Lock/Unlock", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -// LockServer is the server API for Lock service. -type LockServer interface { - // Lock acquires a distributed shared lock on a given named lock. - // On success, it will return a unique key that exists so long as the - // lock is held by the caller. This key can be used in conjunction with - // transactions to safely ensure updates to etcd only occur while holding - // lock ownership. The lock is held until Unlock is called on the key or the - // lease associate with the owner expires. - Lock(context.Context, *LockRequest) (*LockResponse, error) - // Unlock takes a key returned by Lock and releases the hold on lock. The - // next Lock caller waiting for the lock will then be woken up and given - // ownership of the lock. - Unlock(context.Context, *UnlockRequest) (*UnlockResponse, error) -} - -// UnimplementedLockServer can be embedded to have forward compatible implementations. -type UnimplementedLockServer struct { -} - -func (*UnimplementedLockServer) Lock(ctx context.Context, req *LockRequest) (*LockResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method Lock not implemented") -} -func (*UnimplementedLockServer) Unlock(ctx context.Context, req *UnlockRequest) (*UnlockResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method Unlock not implemented") -} - -func RegisterLockServer(s *grpc.Server, srv LockServer) { - s.RegisterService(&_Lock_serviceDesc, srv) -} - -func _Lock_Lock_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(LockRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(LockServer).Lock(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/v3lockpb.Lock/Lock", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(LockServer).Lock(ctx, req.(*LockRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Lock_Unlock_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(UnlockRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(LockServer).Unlock(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/v3lockpb.Lock/Unlock", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(LockServer).Unlock(ctx, req.(*UnlockRequest)) - } - return interceptor(ctx, in, info, handler) -} - -var _Lock_serviceDesc = grpc.ServiceDesc{ - ServiceName: "v3lockpb.Lock", - HandlerType: (*LockServer)(nil), - Methods: []grpc.MethodDesc{ - { - MethodName: "Lock", - Handler: _Lock_Lock_Handler, - }, - { - MethodName: "Unlock", - Handler: _Lock_Unlock_Handler, - }, - }, - Streams: []grpc.StreamDesc{}, - Metadata: "v3lock.proto", -} - -func (m *LockRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *LockRequest) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *LockRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.XXX_unrecognized != nil { - i -= len(m.XXX_unrecognized) - copy(dAtA[i:], m.XXX_unrecognized) - } - if m.Lease != 0 { - i = encodeVarintV3Lock(dAtA, i, uint64(m.Lease)) - i-- - dAtA[i] = 0x10 - } - if len(m.Name) > 0 { - i -= len(m.Name) - copy(dAtA[i:], m.Name) - i = encodeVarintV3Lock(dAtA, i, uint64(len(m.Name))) - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - -func (m *LockResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *LockResponse) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *LockResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.XXX_unrecognized != nil { - i -= len(m.XXX_unrecognized) - copy(dAtA[i:], m.XXX_unrecognized) - } - if len(m.Key) > 0 { - i -= len(m.Key) - copy(dAtA[i:], m.Key) - i = encodeVarintV3Lock(dAtA, i, uint64(len(m.Key))) - i-- - dAtA[i] = 0x12 - } - if m.Header != nil { - { - size, err := m.Header.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintV3Lock(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - -func (m *UnlockRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *UnlockRequest) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *UnlockRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.XXX_unrecognized != nil { - i -= len(m.XXX_unrecognized) - copy(dAtA[i:], m.XXX_unrecognized) - } - if len(m.Key) > 0 { - i -= len(m.Key) - copy(dAtA[i:], m.Key) - i = encodeVarintV3Lock(dAtA, i, uint64(len(m.Key))) - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - -func (m *UnlockResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *UnlockResponse) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *UnlockResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.XXX_unrecognized != nil { - i -= len(m.XXX_unrecognized) - copy(dAtA[i:], m.XXX_unrecognized) - } - if m.Header != nil { - { - size, err := m.Header.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintV3Lock(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - -func encodeVarintV3Lock(dAtA []byte, offset int, v uint64) int { - offset -= sovV3Lock(v) - base := offset - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return base -} -func (m *LockRequest) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = len(m.Name) - if l > 0 { - n += 1 + l + sovV3Lock(uint64(l)) - } - if m.Lease != 0 { - n += 1 + sovV3Lock(uint64(m.Lease)) - } - if m.XXX_unrecognized != nil { - n += len(m.XXX_unrecognized) - } - return n -} - -func (m *LockResponse) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.Header != nil { - l = m.Header.Size() - n += 1 + l + sovV3Lock(uint64(l)) - } - l = len(m.Key) - if l > 0 { - n += 1 + l + sovV3Lock(uint64(l)) - } - if m.XXX_unrecognized != nil { - n += len(m.XXX_unrecognized) - } - return n -} - -func (m *UnlockRequest) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = len(m.Key) - if l > 0 { - n += 1 + l + sovV3Lock(uint64(l)) - } - if m.XXX_unrecognized != nil { - n += len(m.XXX_unrecognized) - } - return n -} - -func (m *UnlockResponse) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.Header != nil { - l = m.Header.Size() - n += 1 + l + sovV3Lock(uint64(l)) - } - if m.XXX_unrecognized != nil { - n += len(m.XXX_unrecognized) - } - return n -} - -func sovV3Lock(x uint64) (n int) { - return (math_bits.Len64(x|1) + 6) / 7 -} -func sozV3Lock(x uint64) (n int) { - return sovV3Lock(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} -func (m *LockRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowV3Lock - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: LockRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: LockRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Name", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowV3Lock - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthV3Lock - } - postIndex := iNdEx + byteLen - if postIndex < 0 { - return ErrInvalidLengthV3Lock - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Name = append(m.Name[:0], dAtA[iNdEx:postIndex]...) - if m.Name == nil { - m.Name = []byte{} - } - iNdEx = postIndex - case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Lease", wireType) - } - m.Lease = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowV3Lock - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Lease |= int64(b&0x7F) << shift - if b < 0x80 { - break - } - } - default: - iNdEx = preIndex - skippy, err := skipV3Lock(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthV3Lock - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *LockResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowV3Lock - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: LockResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: LockResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Header", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowV3Lock - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthV3Lock - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthV3Lock - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Header == nil { - m.Header = &etcdserverpb.ResponseHeader{} - } - if err := m.Header.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Key", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowV3Lock - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthV3Lock - } - postIndex := iNdEx + byteLen - if postIndex < 0 { - return ErrInvalidLengthV3Lock - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Key = append(m.Key[:0], dAtA[iNdEx:postIndex]...) - if m.Key == nil { - m.Key = []byte{} - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipV3Lock(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthV3Lock - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *UnlockRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowV3Lock - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: UnlockRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: UnlockRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Key", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowV3Lock - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthV3Lock - } - postIndex := iNdEx + byteLen - if postIndex < 0 { - return ErrInvalidLengthV3Lock - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Key = append(m.Key[:0], dAtA[iNdEx:postIndex]...) - if m.Key == nil { - m.Key = []byte{} - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipV3Lock(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthV3Lock - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *UnlockResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowV3Lock - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: UnlockResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: UnlockResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Header", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowV3Lock - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthV3Lock - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthV3Lock - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Header == nil { - m.Header = &etcdserverpb.ResponseHeader{} - } - if err := m.Header.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipV3Lock(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthV3Lock - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func skipV3Lock(dAtA []byte) (n int, err error) { - l := len(dAtA) - iNdEx := 0 - depth := 0 - for iNdEx < l { - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowV3Lock - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - wireType := int(wire & 0x7) - switch wireType { - case 0: - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowV3Lock - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - iNdEx++ - if dAtA[iNdEx-1] < 0x80 { - break - } - } - case 1: - iNdEx += 8 - case 2: - var length int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowV3Lock - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - length |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if length < 0 { - return 0, ErrInvalidLengthV3Lock - } - iNdEx += length - case 3: - depth++ - case 4: - if depth == 0 { - return 0, ErrUnexpectedEndOfGroupV3Lock - } - depth-- - case 5: - iNdEx += 4 - default: - return 0, fmt.Errorf("proto: illegal wireType %d", wireType) - } - if iNdEx < 0 { - return 0, ErrInvalidLengthV3Lock - } - if depth == 0 { - return iNdEx, nil - } - } - return 0, io.ErrUnexpectedEOF -} - -var ( - ErrInvalidLengthV3Lock = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowV3Lock = fmt.Errorf("proto: integer overflow") - ErrUnexpectedEndOfGroupV3Lock = fmt.Errorf("proto: unexpected end of group") -) diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3lock/v3lockpb/v3lock.proto b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3lock/v3lockpb/v3lock.proto deleted file mode 100644 index 1b5c456ae2..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3lock/v3lockpb/v3lock.proto +++ /dev/null @@ -1,65 +0,0 @@ -syntax = "proto3"; -package v3lockpb; - -import "gogoproto/gogo.proto"; -import "etcd/api/etcdserverpb/rpc.proto"; - -// for grpc-gateway -import "google/api/annotations.proto"; - -option (gogoproto.marshaler_all) = true; -option (gogoproto.unmarshaler_all) = true; - -// The lock service exposes client-side locking facilities as a gRPC interface. -service Lock { - // Lock acquires a distributed shared lock on a given named lock. - // On success, it will return a unique key that exists so long as the - // lock is held by the caller. This key can be used in conjunction with - // transactions to safely ensure updates to etcd only occur while holding - // lock ownership. The lock is held until Unlock is called on the key or the - // lease associate with the owner expires. - rpc Lock(LockRequest) returns (LockResponse) { - option (google.api.http) = { - post: "/v3/lock/lock" - body: "*" - }; - } - - // Unlock takes a key returned by Lock and releases the hold on lock. The - // next Lock caller waiting for the lock will then be woken up and given - // ownership of the lock. - rpc Unlock(UnlockRequest) returns (UnlockResponse) { - option (google.api.http) = { - post: "/v3/lock/unlock" - body: "*" - }; - } -} - -message LockRequest { - // name is the identifier for the distributed shared lock to be acquired. - bytes name = 1; - // lease is the ID of the lease that will be attached to ownership of the - // lock. If the lease expires or is revoked and currently holds the lock, - // the lock is automatically released. Calls to Lock with the same lease will - // be treated as a single acquisition; locking twice with the same lease is a - // no-op. - int64 lease = 2; -} - -message LockResponse { - etcdserverpb.ResponseHeader header = 1; - // key is a key that will exist on etcd for the duration that the Lock caller - // owns the lock. Users should not modify this key or the lock may exhibit - // undefined behavior. - bytes key = 2; -} - -message UnlockRequest { - // key is the lock ownership key granted by Lock. - bytes key = 1; -} - -message UnlockResponse { - etcdserverpb.ResponseHeader header = 1; -} diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3rpc/auth.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3rpc/auth.go deleted file mode 100644 index d986037a1b..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3rpc/auth.go +++ /dev/null @@ -1,166 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package v3rpc - -import ( - "context" - - pb "go.etcd.io/etcd/api/v3/etcdserverpb" - "go.etcd.io/etcd/server/v3/etcdserver" -) - -type AuthServer struct { - authenticator etcdserver.Authenticator -} - -func NewAuthServer(s *etcdserver.EtcdServer) *AuthServer { - return &AuthServer{authenticator: s} -} - -func (as *AuthServer) AuthEnable(ctx context.Context, r *pb.AuthEnableRequest) (*pb.AuthEnableResponse, error) { - resp, err := as.authenticator.AuthEnable(ctx, r) - if err != nil { - return nil, togRPCError(err) - } - return resp, nil -} - -func (as *AuthServer) AuthDisable(ctx context.Context, r *pb.AuthDisableRequest) (*pb.AuthDisableResponse, error) { - resp, err := as.authenticator.AuthDisable(ctx, r) - if err != nil { - return nil, togRPCError(err) - } - return resp, nil -} - -func (as *AuthServer) AuthStatus(ctx context.Context, r *pb.AuthStatusRequest) (*pb.AuthStatusResponse, error) { - resp, err := as.authenticator.AuthStatus(ctx, r) - if err != nil { - return nil, togRPCError(err) - } - return resp, nil -} - -func (as *AuthServer) Authenticate(ctx context.Context, r *pb.AuthenticateRequest) (*pb.AuthenticateResponse, error) { - resp, err := as.authenticator.Authenticate(ctx, r) - if err != nil { - return nil, togRPCError(err) - } - return resp, nil -} - -func (as *AuthServer) RoleAdd(ctx context.Context, r *pb.AuthRoleAddRequest) (*pb.AuthRoleAddResponse, error) { - resp, err := as.authenticator.RoleAdd(ctx, r) - if err != nil { - return nil, togRPCError(err) - } - return resp, nil -} - -func (as *AuthServer) RoleDelete(ctx context.Context, r *pb.AuthRoleDeleteRequest) (*pb.AuthRoleDeleteResponse, error) { - resp, err := as.authenticator.RoleDelete(ctx, r) - if err != nil { - return nil, togRPCError(err) - } - return resp, nil -} - -func (as *AuthServer) RoleGet(ctx context.Context, r *pb.AuthRoleGetRequest) (*pb.AuthRoleGetResponse, error) { - resp, err := as.authenticator.RoleGet(ctx, r) - if err != nil { - return nil, togRPCError(err) - } - return resp, nil -} - -func (as *AuthServer) RoleList(ctx context.Context, r *pb.AuthRoleListRequest) (*pb.AuthRoleListResponse, error) { - resp, err := as.authenticator.RoleList(ctx, r) - if err != nil { - return nil, togRPCError(err) - } - return resp, nil -} - -func (as *AuthServer) RoleRevokePermission(ctx context.Context, r *pb.AuthRoleRevokePermissionRequest) (*pb.AuthRoleRevokePermissionResponse, error) { - resp, err := as.authenticator.RoleRevokePermission(ctx, r) - if err != nil { - return nil, togRPCError(err) - } - return resp, nil -} - -func (as *AuthServer) RoleGrantPermission(ctx context.Context, r *pb.AuthRoleGrantPermissionRequest) (*pb.AuthRoleGrantPermissionResponse, error) { - resp, err := as.authenticator.RoleGrantPermission(ctx, r) - if err != nil { - return nil, togRPCError(err) - } - return resp, nil -} - -func (as *AuthServer) UserAdd(ctx context.Context, r *pb.AuthUserAddRequest) (*pb.AuthUserAddResponse, error) { - resp, err := as.authenticator.UserAdd(ctx, r) - if err != nil { - return nil, togRPCError(err) - } - return resp, nil -} - -func (as *AuthServer) UserDelete(ctx context.Context, r *pb.AuthUserDeleteRequest) (*pb.AuthUserDeleteResponse, error) { - resp, err := as.authenticator.UserDelete(ctx, r) - if err != nil { - return nil, togRPCError(err) - } - return resp, nil -} - -func (as *AuthServer) UserGet(ctx context.Context, r *pb.AuthUserGetRequest) (*pb.AuthUserGetResponse, error) { - resp, err := as.authenticator.UserGet(ctx, r) - if err != nil { - return nil, togRPCError(err) - } - return resp, nil -} - -func (as *AuthServer) UserList(ctx context.Context, r *pb.AuthUserListRequest) (*pb.AuthUserListResponse, error) { - resp, err := as.authenticator.UserList(ctx, r) - if err != nil { - return nil, togRPCError(err) - } - return resp, nil -} - -func (as *AuthServer) UserGrantRole(ctx context.Context, r *pb.AuthUserGrantRoleRequest) (*pb.AuthUserGrantRoleResponse, error) { - resp, err := as.authenticator.UserGrantRole(ctx, r) - if err != nil { - return nil, togRPCError(err) - } - return resp, nil -} - -func (as *AuthServer) UserRevokeRole(ctx context.Context, r *pb.AuthUserRevokeRoleRequest) (*pb.AuthUserRevokeRoleResponse, error) { - resp, err := as.authenticator.UserRevokeRole(ctx, r) - if err != nil { - return nil, togRPCError(err) - } - return resp, nil -} - -func (as *AuthServer) UserChangePassword(ctx context.Context, r *pb.AuthUserChangePasswordRequest) (*pb.AuthUserChangePasswordResponse, error) { - resp, err := as.authenticator.UserChangePassword(ctx, r) - if err != nil { - return nil, togRPCError(err) - } - return resp, nil -} diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3rpc/codec.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3rpc/codec.go deleted file mode 100644 index d599ff63cc..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3rpc/codec.go +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package v3rpc - -import "github.com/golang/protobuf/proto" - -type codec struct{} - -func (c *codec) Marshal(v interface{}) ([]byte, error) { - b, err := proto.Marshal(v.(proto.Message)) - sentBytes.Add(float64(len(b))) - return b, err -} - -func (c *codec) Unmarshal(data []byte, v interface{}) error { - receivedBytes.Add(float64(len(data))) - return proto.Unmarshal(data, v.(proto.Message)) -} - -func (c *codec) String() string { - return "proto" -} diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3rpc/grpc.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3rpc/grpc.go deleted file mode 100644 index 26c52b385b..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3rpc/grpc.go +++ /dev/null @@ -1,91 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package v3rpc - -import ( - "crypto/tls" - "math" - - pb "go.etcd.io/etcd/api/v3/etcdserverpb" - "go.etcd.io/etcd/client/v3/credentials" - "go.etcd.io/etcd/server/v3/etcdserver" - - grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware" - grpc_prometheus "github.com/grpc-ecosystem/go-grpc-prometheus" - "go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc" - "google.golang.org/grpc" - "google.golang.org/grpc/health" - healthpb "google.golang.org/grpc/health/grpc_health_v1" -) - -const ( - grpcOverheadBytes = 512 * 1024 - maxStreams = math.MaxUint32 - maxSendBytes = math.MaxInt32 -) - -func Server(s *etcdserver.EtcdServer, tls *tls.Config, gopts ...grpc.ServerOption) *grpc.Server { - var opts []grpc.ServerOption - opts = append(opts, grpc.CustomCodec(&codec{})) - if tls != nil { - bundle := credentials.NewBundle(credentials.Config{TLSConfig: tls}) - opts = append(opts, grpc.Creds(bundle.TransportCredentials())) - } - - chainUnaryInterceptors := []grpc.UnaryServerInterceptor{ - newLogUnaryInterceptor(s), - newUnaryInterceptor(s), - grpc_prometheus.UnaryServerInterceptor, - } - - chainStreamInterceptors := []grpc.StreamServerInterceptor{ - newStreamInterceptor(s), - grpc_prometheus.StreamServerInterceptor, - } - - if s.Cfg.ExperimentalEnableDistributedTracing { - chainUnaryInterceptors = append(chainUnaryInterceptors, otelgrpc.UnaryServerInterceptor(s.Cfg.ExperimentalTracerOptions...)) - chainStreamInterceptors = append(chainStreamInterceptors, otelgrpc.StreamServerInterceptor(s.Cfg.ExperimentalTracerOptions...)) - - } - - opts = append(opts, grpc.UnaryInterceptor(grpc_middleware.ChainUnaryServer(chainUnaryInterceptors...))) - opts = append(opts, grpc.StreamInterceptor(grpc_middleware.ChainStreamServer(chainStreamInterceptors...))) - - opts = append(opts, grpc.MaxRecvMsgSize(int(s.Cfg.MaxRequestBytes+grpcOverheadBytes))) - opts = append(opts, grpc.MaxSendMsgSize(maxSendBytes)) - opts = append(opts, grpc.MaxConcurrentStreams(maxStreams)) - - grpcServer := grpc.NewServer(append(opts, gopts...)...) - - pb.RegisterKVServer(grpcServer, NewQuotaKVServer(s)) - pb.RegisterWatchServer(grpcServer, NewWatchServer(s)) - pb.RegisterLeaseServer(grpcServer, NewQuotaLeaseServer(s)) - pb.RegisterClusterServer(grpcServer, NewClusterServer(s)) - pb.RegisterAuthServer(grpcServer, NewAuthServer(s)) - pb.RegisterMaintenanceServer(grpcServer, NewMaintenanceServer(s)) - - // server should register all the services manually - // use empty service name for all etcd services' health status, - // see https://github.com/grpc/grpc/blob/master/doc/health-checking.md for more - hsrv := health.NewServer() - hsrv.SetServingStatus("", healthpb.HealthCheckResponse_SERVING) - healthpb.RegisterHealthServer(grpcServer, hsrv) - - // set zero values for metrics registered for this grpc server - grpc_prometheus.Register(grpcServer) - - return grpcServer -} diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3rpc/header.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3rpc/header.go deleted file mode 100644 index 112cc922ea..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3rpc/header.go +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package v3rpc - -import ( - pb "go.etcd.io/etcd/api/v3/etcdserverpb" - "go.etcd.io/etcd/server/v3/etcdserver" -) - -type header struct { - clusterID int64 - memberID int64 - sg etcdserver.RaftStatusGetter - rev func() int64 -} - -func newHeader(s *etcdserver.EtcdServer) header { - return header{ - clusterID: int64(s.Cluster().ID()), - memberID: int64(s.ID()), - sg: s, - rev: func() int64 { return s.KV().Rev() }, - } -} - -// fill populates pb.ResponseHeader using etcdserver information -func (h *header) fill(rh *pb.ResponseHeader) { - if rh == nil { - panic("unexpected nil resp.Header") - } - rh.ClusterId = uint64(h.clusterID) - rh.MemberId = uint64(h.memberID) - rh.RaftTerm = h.sg.Term() - if rh.Revision == 0 { - rh.Revision = h.rev() - } -} diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3rpc/interceptor.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3rpc/interceptor.go deleted file mode 100644 index 5c80fcf041..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3rpc/interceptor.go +++ /dev/null @@ -1,345 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package v3rpc - -import ( - "context" - "sync" - "time" - - "go.etcd.io/etcd/api/v3/v3rpc/rpctypes" - "go.etcd.io/etcd/client/pkg/v3/types" - "go.etcd.io/etcd/raft/v3" - "go.etcd.io/etcd/server/v3/etcdserver" - "go.etcd.io/etcd/server/v3/etcdserver/api" - - pb "go.etcd.io/etcd/api/v3/etcdserverpb" - "go.uber.org/zap" - "google.golang.org/grpc" - "google.golang.org/grpc/metadata" - "google.golang.org/grpc/peer" -) - -const ( - maxNoLeaderCnt = 3 - warnUnaryRequestLatency = 300 * time.Millisecond - snapshotMethod = "/etcdserverpb.Maintenance/Snapshot" -) - -type streamsMap struct { - mu sync.Mutex - streams map[grpc.ServerStream]struct{} -} - -func newUnaryInterceptor(s *etcdserver.EtcdServer) grpc.UnaryServerInterceptor { - return func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) { - if !api.IsCapabilityEnabled(api.V3rpcCapability) { - return nil, rpctypes.ErrGRPCNotCapable - } - - if s.IsMemberExist(s.ID()) && s.IsLearner() && !isRPCSupportedForLearner(req) { - return nil, rpctypes.ErrGPRCNotSupportedForLearner - } - - md, ok := metadata.FromIncomingContext(ctx) - if ok { - ver, vs := "unknown", md.Get(rpctypes.MetadataClientAPIVersionKey) - if len(vs) > 0 { - ver = vs[0] - } - clientRequests.WithLabelValues("unary", ver).Inc() - - if ks := md[rpctypes.MetadataRequireLeaderKey]; len(ks) > 0 && ks[0] == rpctypes.MetadataHasLeader { - if s.Leader() == types.ID(raft.None) { - return nil, rpctypes.ErrGRPCNoLeader - } - } - } - - return handler(ctx, req) - } -} - -func newLogUnaryInterceptor(s *etcdserver.EtcdServer) grpc.UnaryServerInterceptor { - return func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) { - startTime := time.Now() - resp, err := handler(ctx, req) - lg := s.Logger() - if lg != nil { // acquire stats if debug level is enabled or request is expensive - defer logUnaryRequestStats(ctx, lg, info, startTime, req, resp) - } - return resp, err - } -} - -func logUnaryRequestStats(ctx context.Context, lg *zap.Logger, info *grpc.UnaryServerInfo, startTime time.Time, req interface{}, resp interface{}) { - duration := time.Since(startTime) - var enabledDebugLevel, expensiveRequest bool - if lg.Core().Enabled(zap.DebugLevel) { - enabledDebugLevel = true - } - if duration > warnUnaryRequestLatency { - expensiveRequest = true - } - if !enabledDebugLevel && !expensiveRequest { - return - } - remote := "No remote client info." - peerInfo, ok := peer.FromContext(ctx) - if ok { - remote = peerInfo.Addr.String() - } - responseType := info.FullMethod - var reqCount, respCount int64 - var reqSize, respSize int - var reqContent string - switch _resp := resp.(type) { - case *pb.RangeResponse: - _req, ok := req.(*pb.RangeRequest) - if ok { - reqCount = 0 - reqSize = _req.Size() - reqContent = _req.String() - } - if _resp != nil { - respCount = _resp.GetCount() - respSize = _resp.Size() - } - case *pb.PutResponse: - _req, ok := req.(*pb.PutRequest) - if ok { - reqCount = 1 - reqSize = _req.Size() - reqContent = pb.NewLoggablePutRequest(_req).String() - // redact value field from request content, see PR #9821 - } - if _resp != nil { - respCount = 0 - respSize = _resp.Size() - } - case *pb.DeleteRangeResponse: - _req, ok := req.(*pb.DeleteRangeRequest) - if ok { - reqCount = 0 - reqSize = _req.Size() - reqContent = _req.String() - } - if _resp != nil { - respCount = _resp.GetDeleted() - respSize = _resp.Size() - } - case *pb.TxnResponse: - _req, ok := req.(*pb.TxnRequest) - if ok && _resp != nil { - if _resp.GetSucceeded() { // determine the 'actual' count and size of request based on success or failure - reqCount = int64(len(_req.GetSuccess())) - reqSize = 0 - for _, r := range _req.GetSuccess() { - reqSize += r.Size() - } - } else { - reqCount = int64(len(_req.GetFailure())) - reqSize = 0 - for _, r := range _req.GetFailure() { - reqSize += r.Size() - } - } - reqContent = pb.NewLoggableTxnRequest(_req).String() - // redact value field from request content, see PR #9821 - } - if _resp != nil { - respCount = 0 - respSize = _resp.Size() - } - default: - reqCount = -1 - reqSize = -1 - respCount = -1 - respSize = -1 - } - - if enabledDebugLevel { - logGenericRequestStats(lg, startTime, duration, remote, responseType, reqCount, reqSize, respCount, respSize, reqContent) - } else if expensiveRequest { - logExpensiveRequestStats(lg, startTime, duration, remote, responseType, reqCount, reqSize, respCount, respSize, reqContent) - } -} - -func logGenericRequestStats(lg *zap.Logger, startTime time.Time, duration time.Duration, remote string, responseType string, - reqCount int64, reqSize int, respCount int64, respSize int, reqContent string) { - lg.Debug("request stats", - zap.Time("start time", startTime), - zap.Duration("time spent", duration), - zap.String("remote", remote), - zap.String("response type", responseType), - zap.Int64("request count", reqCount), - zap.Int("request size", reqSize), - zap.Int64("response count", respCount), - zap.Int("response size", respSize), - zap.String("request content", reqContent), - ) -} - -func logExpensiveRequestStats(lg *zap.Logger, startTime time.Time, duration time.Duration, remote string, responseType string, - reqCount int64, reqSize int, respCount int64, respSize int, reqContent string) { - lg.Warn("request stats", - zap.Time("start time", startTime), - zap.Duration("time spent", duration), - zap.String("remote", remote), - zap.String("response type", responseType), - zap.Int64("request count", reqCount), - zap.Int("request size", reqSize), - zap.Int64("response count", respCount), - zap.Int("response size", respSize), - zap.String("request content", reqContent), - ) -} - -func newStreamInterceptor(s *etcdserver.EtcdServer) grpc.StreamServerInterceptor { - smap := monitorLeader(s) - - return func(srv interface{}, ss grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) error { - if !api.IsCapabilityEnabled(api.V3rpcCapability) { - return rpctypes.ErrGRPCNotCapable - } - - if s.IsMemberExist(s.ID()) && s.IsLearner() && info.FullMethod != snapshotMethod { // learner does not support stream RPC except Snapshot - return rpctypes.ErrGPRCNotSupportedForLearner - } - - md, ok := metadata.FromIncomingContext(ss.Context()) - if ok { - ver, vs := "unknown", md.Get(rpctypes.MetadataClientAPIVersionKey) - if len(vs) > 0 { - ver = vs[0] - } - clientRequests.WithLabelValues("stream", ver).Inc() - - if ks := md[rpctypes.MetadataRequireLeaderKey]; len(ks) > 0 && ks[0] == rpctypes.MetadataHasLeader { - if s.Leader() == types.ID(raft.None) { - return rpctypes.ErrGRPCNoLeader - } - - ctx := newCancellableContext(ss.Context()) - ss = serverStreamWithCtx{ctx: ctx, ServerStream: ss} - - smap.mu.Lock() - smap.streams[ss] = struct{}{} - smap.mu.Unlock() - - defer func() { - smap.mu.Lock() - delete(smap.streams, ss) - smap.mu.Unlock() - // TODO: investigate whether the reason for cancellation here is useful to know - ctx.Cancel(nil) - }() - } - } - - return handler(srv, ss) - } -} - -// cancellableContext wraps a context with new cancellable context that allows a -// specific cancellation error to be preserved and later retrieved using the -// Context.Err() function. This is so downstream context users can disambiguate -// the reason for the cancellation which could be from the client (for example) -// or from this interceptor code. -type cancellableContext struct { - context.Context - - lock sync.RWMutex - cancel context.CancelFunc - cancelReason error -} - -func newCancellableContext(parent context.Context) *cancellableContext { - ctx, cancel := context.WithCancel(parent) - return &cancellableContext{ - Context: ctx, - cancel: cancel, - } -} - -// Cancel stores the cancellation reason and then delegates to context.WithCancel -// against the parent context. -func (c *cancellableContext) Cancel(reason error) { - c.lock.Lock() - c.cancelReason = reason - c.lock.Unlock() - c.cancel() -} - -// Err will return the preserved cancel reason error if present, and will -// otherwise return the underlying error from the parent context. -func (c *cancellableContext) Err() error { - c.lock.RLock() - defer c.lock.RUnlock() - if c.cancelReason != nil { - return c.cancelReason - } - return c.Context.Err() -} - -type serverStreamWithCtx struct { - grpc.ServerStream - - // ctx is used so that we can preserve a reason for cancellation. - ctx *cancellableContext -} - -func (ssc serverStreamWithCtx) Context() context.Context { return ssc.ctx } - -func monitorLeader(s *etcdserver.EtcdServer) *streamsMap { - smap := &streamsMap{ - streams: make(map[grpc.ServerStream]struct{}), - } - - s.GoAttach(func() { - election := time.Duration(s.Cfg.TickMs) * time.Duration(s.Cfg.ElectionTicks) * time.Millisecond - noLeaderCnt := 0 - - for { - select { - case <-s.StoppingNotify(): - return - case <-time.After(election): - if s.Leader() == types.ID(raft.None) { - noLeaderCnt++ - } else { - noLeaderCnt = 0 - } - - // We are more conservative on canceling existing streams. Reconnecting streams - // cost much more than just rejecting new requests. So we wait until the member - // cannot find a leader for maxNoLeaderCnt election timeouts to cancel existing streams. - if noLeaderCnt >= maxNoLeaderCnt { - smap.mu.Lock() - for ss := range smap.streams { - if ssWithCtx, ok := ss.(serverStreamWithCtx); ok { - ssWithCtx.ctx.Cancel(rpctypes.ErrGRPCNoLeader) - <-ss.Context().Done() - } - } - smap.streams = make(map[grpc.ServerStream]struct{}) - smap.mu.Unlock() - } - } - } - }) - - return smap -} diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3rpc/key.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3rpc/key.go deleted file mode 100644 index d1a7ee6334..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3rpc/key.go +++ /dev/null @@ -1,271 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package v3rpc implements etcd v3 RPC system based on gRPC. -package v3rpc - -import ( - "context" - - pb "go.etcd.io/etcd/api/v3/etcdserverpb" - "go.etcd.io/etcd/api/v3/v3rpc/rpctypes" - "go.etcd.io/etcd/pkg/v3/adt" - "go.etcd.io/etcd/server/v3/etcdserver" -) - -type kvServer struct { - hdr header - kv etcdserver.RaftKV - // maxTxnOps is the max operations per txn. - // e.g suppose maxTxnOps = 128. - // Txn.Success can have at most 128 operations, - // and Txn.Failure can have at most 128 operations. - maxTxnOps uint -} - -func NewKVServer(s *etcdserver.EtcdServer) pb.KVServer { - return &kvServer{hdr: newHeader(s), kv: s, maxTxnOps: s.Cfg.MaxTxnOps} -} - -func (s *kvServer) Range(ctx context.Context, r *pb.RangeRequest) (*pb.RangeResponse, error) { - if err := checkRangeRequest(r); err != nil { - return nil, err - } - - resp, err := s.kv.Range(ctx, r) - if err != nil { - return nil, togRPCError(err) - } - - s.hdr.fill(resp.Header) - return resp, nil -} - -func (s *kvServer) Put(ctx context.Context, r *pb.PutRequest) (*pb.PutResponse, error) { - if err := checkPutRequest(r); err != nil { - return nil, err - } - - resp, err := s.kv.Put(ctx, r) - if err != nil { - return nil, togRPCError(err) - } - - s.hdr.fill(resp.Header) - return resp, nil -} - -func (s *kvServer) DeleteRange(ctx context.Context, r *pb.DeleteRangeRequest) (*pb.DeleteRangeResponse, error) { - if err := checkDeleteRequest(r); err != nil { - return nil, err - } - - resp, err := s.kv.DeleteRange(ctx, r) - if err != nil { - return nil, togRPCError(err) - } - - s.hdr.fill(resp.Header) - return resp, nil -} - -func (s *kvServer) Txn(ctx context.Context, r *pb.TxnRequest) (*pb.TxnResponse, error) { - if err := checkTxnRequest(r, int(s.maxTxnOps)); err != nil { - return nil, err - } - // check for forbidden put/del overlaps after checking request to avoid quadratic blowup - if _, _, err := checkIntervals(r.Success); err != nil { - return nil, err - } - if _, _, err := checkIntervals(r.Failure); err != nil { - return nil, err - } - - resp, err := s.kv.Txn(ctx, r) - if err != nil { - return nil, togRPCError(err) - } - - s.hdr.fill(resp.Header) - return resp, nil -} - -func (s *kvServer) Compact(ctx context.Context, r *pb.CompactionRequest) (*pb.CompactionResponse, error) { - resp, err := s.kv.Compact(ctx, r) - if err != nil { - return nil, togRPCError(err) - } - - s.hdr.fill(resp.Header) - return resp, nil -} - -func checkRangeRequest(r *pb.RangeRequest) error { - if len(r.Key) == 0 { - return rpctypes.ErrGRPCEmptyKey - } - return nil -} - -func checkPutRequest(r *pb.PutRequest) error { - if len(r.Key) == 0 { - return rpctypes.ErrGRPCEmptyKey - } - if r.IgnoreValue && len(r.Value) != 0 { - return rpctypes.ErrGRPCValueProvided - } - if r.IgnoreLease && r.Lease != 0 { - return rpctypes.ErrGRPCLeaseProvided - } - return nil -} - -func checkDeleteRequest(r *pb.DeleteRangeRequest) error { - if len(r.Key) == 0 { - return rpctypes.ErrGRPCEmptyKey - } - return nil -} - -func checkTxnRequest(r *pb.TxnRequest, maxTxnOps int) error { - opc := len(r.Compare) - if opc < len(r.Success) { - opc = len(r.Success) - } - if opc < len(r.Failure) { - opc = len(r.Failure) - } - if opc > maxTxnOps { - return rpctypes.ErrGRPCTooManyOps - } - - for _, c := range r.Compare { - if len(c.Key) == 0 { - return rpctypes.ErrGRPCEmptyKey - } - } - for _, u := range r.Success { - if err := checkRequestOp(u, maxTxnOps-opc); err != nil { - return err - } - } - for _, u := range r.Failure { - if err := checkRequestOp(u, maxTxnOps-opc); err != nil { - return err - } - } - - return nil -} - -// checkIntervals tests whether puts and deletes overlap for a list of ops. If -// there is an overlap, returns an error. If no overlap, return put and delete -// sets for recursive evaluation. -func checkIntervals(reqs []*pb.RequestOp) (map[string]struct{}, adt.IntervalTree, error) { - dels := adt.NewIntervalTree() - - // collect deletes from this level; build first to check lower level overlapped puts - for _, req := range reqs { - tv, ok := req.Request.(*pb.RequestOp_RequestDeleteRange) - if !ok { - continue - } - dreq := tv.RequestDeleteRange - if dreq == nil { - continue - } - var iv adt.Interval - if len(dreq.RangeEnd) != 0 { - iv = adt.NewStringAffineInterval(string(dreq.Key), string(dreq.RangeEnd)) - } else { - iv = adt.NewStringAffinePoint(string(dreq.Key)) - } - dels.Insert(iv, struct{}{}) - } - - // collect children puts/deletes - puts := make(map[string]struct{}) - for _, req := range reqs { - tv, ok := req.Request.(*pb.RequestOp_RequestTxn) - if !ok { - continue - } - putsThen, delsThen, err := checkIntervals(tv.RequestTxn.Success) - if err != nil { - return nil, dels, err - } - putsElse, delsElse, err := checkIntervals(tv.RequestTxn.Failure) - if err != nil { - return nil, dels, err - } - for k := range putsThen { - if _, ok := puts[k]; ok { - return nil, dels, rpctypes.ErrGRPCDuplicateKey - } - if dels.Intersects(adt.NewStringAffinePoint(k)) { - return nil, dels, rpctypes.ErrGRPCDuplicateKey - } - puts[k] = struct{}{} - } - for k := range putsElse { - if _, ok := puts[k]; ok { - // if key is from putsThen, overlap is OK since - // either then/else are mutually exclusive - if _, isSafe := putsThen[k]; !isSafe { - return nil, dels, rpctypes.ErrGRPCDuplicateKey - } - } - if dels.Intersects(adt.NewStringAffinePoint(k)) { - return nil, dels, rpctypes.ErrGRPCDuplicateKey - } - puts[k] = struct{}{} - } - dels.Union(delsThen, adt.NewStringAffineInterval("\x00", "")) - dels.Union(delsElse, adt.NewStringAffineInterval("\x00", "")) - } - - // collect and check this level's puts - for _, req := range reqs { - tv, ok := req.Request.(*pb.RequestOp_RequestPut) - if !ok || tv.RequestPut == nil { - continue - } - k := string(tv.RequestPut.Key) - if _, ok := puts[k]; ok { - return nil, dels, rpctypes.ErrGRPCDuplicateKey - } - if dels.Intersects(adt.NewStringAffinePoint(k)) { - return nil, dels, rpctypes.ErrGRPCDuplicateKey - } - puts[k] = struct{}{} - } - return puts, dels, nil -} - -func checkRequestOp(u *pb.RequestOp, maxTxnOps int) error { - // TODO: ensure only one of the field is set. - switch uv := u.Request.(type) { - case *pb.RequestOp_RequestRange: - return checkRangeRequest(uv.RequestRange) - case *pb.RequestOp_RequestPut: - return checkPutRequest(uv.RequestPut) - case *pb.RequestOp_RequestDeleteRange: - return checkDeleteRequest(uv.RequestDeleteRange) - case *pb.RequestOp_RequestTxn: - return checkTxnRequest(uv.RequestTxn, maxTxnOps) - default: - // empty op / nil entry - return rpctypes.ErrGRPCKeyNotFound - } -} diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3rpc/lease.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3rpc/lease.go deleted file mode 100644 index e123dd2a37..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3rpc/lease.go +++ /dev/null @@ -1,157 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package v3rpc - -import ( - "context" - "io" - - pb "go.etcd.io/etcd/api/v3/etcdserverpb" - "go.etcd.io/etcd/api/v3/v3rpc/rpctypes" - "go.etcd.io/etcd/server/v3/etcdserver" - "go.etcd.io/etcd/server/v3/lease" - - "go.uber.org/zap" -) - -type LeaseServer struct { - lg *zap.Logger - hdr header - le etcdserver.Lessor -} - -func NewLeaseServer(s *etcdserver.EtcdServer) pb.LeaseServer { - srv := &LeaseServer{lg: s.Cfg.Logger, le: s, hdr: newHeader(s)} - if srv.lg == nil { - srv.lg = zap.NewNop() - } - return srv -} - -func (ls *LeaseServer) LeaseGrant(ctx context.Context, cr *pb.LeaseGrantRequest) (*pb.LeaseGrantResponse, error) { - resp, err := ls.le.LeaseGrant(ctx, cr) - - if err != nil { - return nil, togRPCError(err) - } - ls.hdr.fill(resp.Header) - return resp, nil -} - -func (ls *LeaseServer) LeaseRevoke(ctx context.Context, rr *pb.LeaseRevokeRequest) (*pb.LeaseRevokeResponse, error) { - resp, err := ls.le.LeaseRevoke(ctx, rr) - if err != nil { - return nil, togRPCError(err) - } - ls.hdr.fill(resp.Header) - return resp, nil -} - -func (ls *LeaseServer) LeaseTimeToLive(ctx context.Context, rr *pb.LeaseTimeToLiveRequest) (*pb.LeaseTimeToLiveResponse, error) { - resp, err := ls.le.LeaseTimeToLive(ctx, rr) - if err != nil && err != lease.ErrLeaseNotFound { - return nil, togRPCError(err) - } - if err == lease.ErrLeaseNotFound { - resp = &pb.LeaseTimeToLiveResponse{ - Header: &pb.ResponseHeader{}, - ID: rr.ID, - TTL: -1, - } - } - ls.hdr.fill(resp.Header) - return resp, nil -} - -func (ls *LeaseServer) LeaseLeases(ctx context.Context, rr *pb.LeaseLeasesRequest) (*pb.LeaseLeasesResponse, error) { - resp, err := ls.le.LeaseLeases(ctx, rr) - if err != nil && err != lease.ErrLeaseNotFound { - return nil, togRPCError(err) - } - if err == lease.ErrLeaseNotFound { - resp = &pb.LeaseLeasesResponse{ - Header: &pb.ResponseHeader{}, - Leases: []*pb.LeaseStatus{}, - } - } - ls.hdr.fill(resp.Header) - return resp, nil -} - -func (ls *LeaseServer) LeaseKeepAlive(stream pb.Lease_LeaseKeepAliveServer) (err error) { - errc := make(chan error, 1) - go func() { - errc <- ls.leaseKeepAlive(stream) - }() - select { - case err = <-errc: - case <-stream.Context().Done(): - // the only server-side cancellation is noleader for now. - err = stream.Context().Err() - if err == context.Canceled { - err = rpctypes.ErrGRPCNoLeader - } - } - return err -} - -func (ls *LeaseServer) leaseKeepAlive(stream pb.Lease_LeaseKeepAliveServer) error { - for { - req, err := stream.Recv() - if err == io.EOF { - return nil - } - if err != nil { - if isClientCtxErr(stream.Context().Err(), err) { - ls.lg.Debug("failed to receive lease keepalive request from gRPC stream", zap.Error(err)) - } else { - ls.lg.Warn("failed to receive lease keepalive request from gRPC stream", zap.Error(err)) - streamFailures.WithLabelValues("receive", "lease-keepalive").Inc() - } - return err - } - - // Create header before we sent out the renew request. - // This can make sure that the revision is strictly smaller or equal to - // when the keepalive happened at the local server (when the local server is the leader) - // or remote leader. - // Without this, a lease might be revoked at rev 3 but client can see the keepalive succeeded - // at rev 4. - resp := &pb.LeaseKeepAliveResponse{ID: req.ID, Header: &pb.ResponseHeader{}} - ls.hdr.fill(resp.Header) - - ttl, err := ls.le.LeaseRenew(stream.Context(), lease.LeaseID(req.ID)) - if err == lease.ErrLeaseNotFound { - err = nil - ttl = 0 - } - - if err != nil { - return togRPCError(err) - } - - resp.TTL = ttl - err = stream.Send(resp) - if err != nil { - if isClientCtxErr(stream.Context().Err(), err) { - ls.lg.Debug("failed to send lease keepalive response to gRPC stream", zap.Error(err)) - } else { - ls.lg.Warn("failed to send lease keepalive response to gRPC stream", zap.Error(err)) - streamFailures.WithLabelValues("send", "lease-keepalive").Inc() - } - return err - } - } -} diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3rpc/maintenance.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3rpc/maintenance.go deleted file mode 100644 index 38cc913716..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3rpc/maintenance.go +++ /dev/null @@ -1,314 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package v3rpc - -import ( - "context" - "crypto/sha256" - "io" - "time" - - "github.com/dustin/go-humanize" - pb "go.etcd.io/etcd/api/v3/etcdserverpb" - "go.etcd.io/etcd/api/v3/v3rpc/rpctypes" - "go.etcd.io/etcd/api/v3/version" - "go.etcd.io/etcd/raft/v3" - "go.etcd.io/etcd/server/v3/auth" - "go.etcd.io/etcd/server/v3/etcdserver" - "go.etcd.io/etcd/server/v3/mvcc" - "go.etcd.io/etcd/server/v3/mvcc/backend" - - "go.uber.org/zap" -) - -type KVGetter interface { - KV() mvcc.WatchableKV -} - -type BackendGetter interface { - Backend() backend.Backend -} - -type Alarmer interface { - // Alarms is implemented in Server interface located in etcdserver/server.go - // It returns a list of alarms present in the AlarmStore - Alarms() []*pb.AlarmMember - Alarm(ctx context.Context, ar *pb.AlarmRequest) (*pb.AlarmResponse, error) -} - -type Downgrader interface { - Downgrade(ctx context.Context, dr *pb.DowngradeRequest) (*pb.DowngradeResponse, error) -} - -type LeaderTransferrer interface { - MoveLeader(ctx context.Context, lead, target uint64) error -} - -type AuthGetter interface { - AuthInfoFromCtx(ctx context.Context) (*auth.AuthInfo, error) - AuthStore() auth.AuthStore -} - -type ClusterStatusGetter interface { - IsLearner() bool -} - -type maintenanceServer struct { - lg *zap.Logger - rg etcdserver.RaftStatusGetter - kg KVGetter - bg BackendGetter - a Alarmer - lt LeaderTransferrer - hdr header - cs ClusterStatusGetter - d Downgrader -} - -func NewMaintenanceServer(s *etcdserver.EtcdServer) pb.MaintenanceServer { - srv := &maintenanceServer{lg: s.Cfg.Logger, rg: s, kg: s, bg: s, a: s, lt: s, hdr: newHeader(s), cs: s, d: s} - if srv.lg == nil { - srv.lg = zap.NewNop() - } - return &authMaintenanceServer{srv, s} -} - -func (ms *maintenanceServer) Defragment(ctx context.Context, sr *pb.DefragmentRequest) (*pb.DefragmentResponse, error) { - ms.lg.Info("starting defragment") - err := ms.bg.Backend().Defrag() - if err != nil { - ms.lg.Warn("failed to defragment", zap.Error(err)) - return nil, err - } - ms.lg.Info("finished defragment") - return &pb.DefragmentResponse{}, nil -} - -// big enough size to hold >1 OS pages in the buffer -const snapshotSendBufferSize = 32 * 1024 - -func (ms *maintenanceServer) Snapshot(sr *pb.SnapshotRequest, srv pb.Maintenance_SnapshotServer) error { - snap := ms.bg.Backend().Snapshot() - pr, pw := io.Pipe() - - defer pr.Close() - - go func() { - snap.WriteTo(pw) - if err := snap.Close(); err != nil { - ms.lg.Warn("failed to close snapshot", zap.Error(err)) - } - pw.Close() - }() - - // record SHA digest of snapshot data - // used for integrity checks during snapshot restore operation - h := sha256.New() - - sent := int64(0) - total := snap.Size() - size := humanize.Bytes(uint64(total)) - - start := time.Now() - ms.lg.Info("sending database snapshot to client", - zap.Int64("total-bytes", total), - zap.String("size", size), - ) - for total-sent > 0 { - // buffer just holds read bytes from stream - // response size is multiple of OS page size, fetched in boltdb - // e.g. 4*1024 - // NOTE: srv.Send does not wait until the message is received by the client. - // Therefore the buffer can not be safely reused between Send operations - buf := make([]byte, snapshotSendBufferSize) - - n, err := io.ReadFull(pr, buf) - if err != nil && err != io.EOF && err != io.ErrUnexpectedEOF { - return togRPCError(err) - } - sent += int64(n) - - // if total is x * snapshotSendBufferSize. it is possible that - // resp.RemainingBytes == 0 - // resp.Blob == zero byte but not nil - // does this make server response sent to client nil in proto - // and client stops receiving from snapshot stream before - // server sends snapshot SHA? - // No, the client will still receive non-nil response - // until server closes the stream with EOF - resp := &pb.SnapshotResponse{ - RemainingBytes: uint64(total - sent), - Blob: buf[:n], - } - if err = srv.Send(resp); err != nil { - return togRPCError(err) - } - h.Write(buf[:n]) - } - - // send SHA digest for integrity checks - // during snapshot restore operation - sha := h.Sum(nil) - - ms.lg.Info("sending database sha256 checksum to client", - zap.Int64("total-bytes", total), - zap.Int("checksum-size", len(sha)), - ) - hresp := &pb.SnapshotResponse{RemainingBytes: 0, Blob: sha} - if err := srv.Send(hresp); err != nil { - return togRPCError(err) - } - - ms.lg.Info("successfully sent database snapshot to client", - zap.Int64("total-bytes", total), - zap.String("size", size), - zap.String("took", humanize.Time(start)), - ) - return nil -} - -func (ms *maintenanceServer) Hash(ctx context.Context, r *pb.HashRequest) (*pb.HashResponse, error) { - h, rev, err := ms.kg.KV().Hash() - if err != nil { - return nil, togRPCError(err) - } - resp := &pb.HashResponse{Header: &pb.ResponseHeader{Revision: rev}, Hash: h} - ms.hdr.fill(resp.Header) - return resp, nil -} - -func (ms *maintenanceServer) HashKV(ctx context.Context, r *pb.HashKVRequest) (*pb.HashKVResponse, error) { - h, rev, compactRev, err := ms.kg.KV().HashByRev(r.Revision) - if err != nil { - return nil, togRPCError(err) - } - - resp := &pb.HashKVResponse{Header: &pb.ResponseHeader{Revision: rev}, Hash: h, CompactRevision: compactRev} - ms.hdr.fill(resp.Header) - return resp, nil -} - -func (ms *maintenanceServer) Alarm(ctx context.Context, ar *pb.AlarmRequest) (*pb.AlarmResponse, error) { - resp, err := ms.a.Alarm(ctx, ar) - if err != nil { - return nil, togRPCError(err) - } - if resp.Header == nil { - resp.Header = &pb.ResponseHeader{} - } - ms.hdr.fill(resp.Header) - return resp, nil -} - -func (ms *maintenanceServer) Status(ctx context.Context, ar *pb.StatusRequest) (*pb.StatusResponse, error) { - hdr := &pb.ResponseHeader{} - ms.hdr.fill(hdr) - resp := &pb.StatusResponse{ - Header: hdr, - Version: version.Version, - Leader: uint64(ms.rg.Leader()), - RaftIndex: ms.rg.CommittedIndex(), - RaftAppliedIndex: ms.rg.AppliedIndex(), - RaftTerm: ms.rg.Term(), - DbSize: ms.bg.Backend().Size(), - DbSizeInUse: ms.bg.Backend().SizeInUse(), - IsLearner: ms.cs.IsLearner(), - } - if resp.Leader == raft.None { - resp.Errors = append(resp.Errors, etcdserver.ErrNoLeader.Error()) - } - for _, a := range ms.a.Alarms() { - resp.Errors = append(resp.Errors, a.String()) - } - return resp, nil -} - -func (ms *maintenanceServer) MoveLeader(ctx context.Context, tr *pb.MoveLeaderRequest) (*pb.MoveLeaderResponse, error) { - if ms.rg.ID() != ms.rg.Leader() { - return nil, rpctypes.ErrGRPCNotLeader - } - - if err := ms.lt.MoveLeader(ctx, uint64(ms.rg.Leader()), tr.TargetID); err != nil { - return nil, togRPCError(err) - } - return &pb.MoveLeaderResponse{}, nil -} - -func (ms *maintenanceServer) Downgrade(ctx context.Context, r *pb.DowngradeRequest) (*pb.DowngradeResponse, error) { - resp, err := ms.d.Downgrade(ctx, r) - if err != nil { - return nil, togRPCError(err) - } - resp.Header = &pb.ResponseHeader{} - ms.hdr.fill(resp.Header) - return resp, nil -} - -type authMaintenanceServer struct { - *maintenanceServer - ag AuthGetter -} - -func (ams *authMaintenanceServer) isAuthenticated(ctx context.Context) error { - authInfo, err := ams.ag.AuthInfoFromCtx(ctx) - if err != nil { - return err - } - - return ams.ag.AuthStore().IsAdminPermitted(authInfo) -} - -func (ams *authMaintenanceServer) Defragment(ctx context.Context, sr *pb.DefragmentRequest) (*pb.DefragmentResponse, error) { - if err := ams.isAuthenticated(ctx); err != nil { - return nil, err - } - - return ams.maintenanceServer.Defragment(ctx, sr) -} - -func (ams *authMaintenanceServer) Snapshot(sr *pb.SnapshotRequest, srv pb.Maintenance_SnapshotServer) error { - if err := ams.isAuthenticated(srv.Context()); err != nil { - return err - } - - return ams.maintenanceServer.Snapshot(sr, srv) -} - -func (ams *authMaintenanceServer) Hash(ctx context.Context, r *pb.HashRequest) (*pb.HashResponse, error) { - if err := ams.isAuthenticated(ctx); err != nil { - return nil, err - } - - return ams.maintenanceServer.Hash(ctx, r) -} - -func (ams *authMaintenanceServer) HashKV(ctx context.Context, r *pb.HashKVRequest) (*pb.HashKVResponse, error) { - if err := ams.isAuthenticated(ctx); err != nil { - return nil, err - } - return ams.maintenanceServer.HashKV(ctx, r) -} - -func (ams *authMaintenanceServer) Status(ctx context.Context, ar *pb.StatusRequest) (*pb.StatusResponse, error) { - return ams.maintenanceServer.Status(ctx, ar) -} - -func (ams *authMaintenanceServer) MoveLeader(ctx context.Context, tr *pb.MoveLeaderRequest) (*pb.MoveLeaderResponse, error) { - return ams.maintenanceServer.MoveLeader(ctx, tr) -} - -func (ams *authMaintenanceServer) Downgrade(ctx context.Context, r *pb.DowngradeRequest) (*pb.DowngradeResponse, error) { - return ams.maintenanceServer.Downgrade(ctx, r) -} diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3rpc/member.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3rpc/member.go deleted file mode 100644 index 54fcc24843..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3rpc/member.go +++ /dev/null @@ -1,124 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package v3rpc - -import ( - "context" - "time" - - pb "go.etcd.io/etcd/api/v3/etcdserverpb" - "go.etcd.io/etcd/api/v3/v3rpc/rpctypes" - "go.etcd.io/etcd/client/pkg/v3/types" - "go.etcd.io/etcd/server/v3/etcdserver" - "go.etcd.io/etcd/server/v3/etcdserver/api" - "go.etcd.io/etcd/server/v3/etcdserver/api/membership" -) - -type ClusterServer struct { - cluster api.Cluster - server *etcdserver.EtcdServer -} - -func NewClusterServer(s *etcdserver.EtcdServer) *ClusterServer { - return &ClusterServer{ - cluster: s.Cluster(), - server: s, - } -} - -func (cs *ClusterServer) MemberAdd(ctx context.Context, r *pb.MemberAddRequest) (*pb.MemberAddResponse, error) { - urls, err := types.NewURLs(r.PeerURLs) - if err != nil { - return nil, rpctypes.ErrGRPCMemberBadURLs - } - - now := time.Now() - var m *membership.Member - if r.IsLearner { - m = membership.NewMemberAsLearner("", urls, "", &now) - } else { - m = membership.NewMember("", urls, "", &now) - } - membs, merr := cs.server.AddMember(ctx, *m) - if merr != nil { - return nil, togRPCError(merr) - } - - return &pb.MemberAddResponse{ - Header: cs.header(), - Member: &pb.Member{ - ID: uint64(m.ID), - PeerURLs: m.PeerURLs, - IsLearner: m.IsLearner, - }, - Members: membersToProtoMembers(membs), - }, nil -} - -func (cs *ClusterServer) MemberRemove(ctx context.Context, r *pb.MemberRemoveRequest) (*pb.MemberRemoveResponse, error) { - membs, err := cs.server.RemoveMember(ctx, r.ID) - if err != nil { - return nil, togRPCError(err) - } - return &pb.MemberRemoveResponse{Header: cs.header(), Members: membersToProtoMembers(membs)}, nil -} - -func (cs *ClusterServer) MemberUpdate(ctx context.Context, r *pb.MemberUpdateRequest) (*pb.MemberUpdateResponse, error) { - m := membership.Member{ - ID: types.ID(r.ID), - RaftAttributes: membership.RaftAttributes{PeerURLs: r.PeerURLs}, - } - membs, err := cs.server.UpdateMember(ctx, m) - if err != nil { - return nil, togRPCError(err) - } - return &pb.MemberUpdateResponse{Header: cs.header(), Members: membersToProtoMembers(membs)}, nil -} - -func (cs *ClusterServer) MemberList(ctx context.Context, r *pb.MemberListRequest) (*pb.MemberListResponse, error) { - if r.Linearizable { - if err := cs.server.LinearizableReadNotify(ctx); err != nil { - return nil, togRPCError(err) - } - } - membs := membersToProtoMembers(cs.cluster.Members()) - return &pb.MemberListResponse{Header: cs.header(), Members: membs}, nil -} - -func (cs *ClusterServer) MemberPromote(ctx context.Context, r *pb.MemberPromoteRequest) (*pb.MemberPromoteResponse, error) { - membs, err := cs.server.PromoteMember(ctx, r.ID) - if err != nil { - return nil, togRPCError(err) - } - return &pb.MemberPromoteResponse{Header: cs.header(), Members: membersToProtoMembers(membs)}, nil -} - -func (cs *ClusterServer) header() *pb.ResponseHeader { - return &pb.ResponseHeader{ClusterId: uint64(cs.cluster.ID()), MemberId: uint64(cs.server.ID()), RaftTerm: cs.server.Term()} -} - -func membersToProtoMembers(membs []*membership.Member) []*pb.Member { - protoMembs := make([]*pb.Member, len(membs)) - for i := range membs { - protoMembs[i] = &pb.Member{ - Name: membs[i].Name, - ID: uint64(membs[i].ID), - PeerURLs: membs[i].PeerURLs, - ClientURLs: membs[i].ClientURLs, - IsLearner: membs[i].IsLearner, - } - } - return protoMembs -} diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3rpc/metrics.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3rpc/metrics.go deleted file mode 100644 index a4ee723c52..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3rpc/metrics.go +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package v3rpc - -import "github.com/prometheus/client_golang/prometheus" - -var ( - sentBytes = prometheus.NewCounter(prometheus.CounterOpts{ - Namespace: "etcd", - Subsystem: "network", - Name: "client_grpc_sent_bytes_total", - Help: "The total number of bytes sent to grpc clients.", - }) - - receivedBytes = prometheus.NewCounter(prometheus.CounterOpts{ - Namespace: "etcd", - Subsystem: "network", - Name: "client_grpc_received_bytes_total", - Help: "The total number of bytes received from grpc clients.", - }) - - streamFailures = prometheus.NewCounterVec(prometheus.CounterOpts{ - Namespace: "etcd", - Subsystem: "network", - Name: "server_stream_failures_total", - Help: "The total number of stream failures from the local server.", - }, - []string{"Type", "API"}, - ) - - clientRequests = prometheus.NewCounterVec(prometheus.CounterOpts{ - Namespace: "etcd", - Subsystem: "server", - Name: "client_requests_total", - Help: "The total number of client requests per client version.", - }, - []string{"type", "client_api_version"}, - ) -) - -func init() { - prometheus.MustRegister(sentBytes) - prometheus.MustRegister(receivedBytes) - prometheus.MustRegister(streamFailures) - prometheus.MustRegister(clientRequests) -} diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3rpc/quota.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3rpc/quota.go deleted file mode 100644 index 7f53bd966b..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3rpc/quota.go +++ /dev/null @@ -1,90 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package v3rpc - -import ( - "context" - - pb "go.etcd.io/etcd/api/v3/etcdserverpb" - "go.etcd.io/etcd/api/v3/v3rpc/rpctypes" - "go.etcd.io/etcd/client/pkg/v3/types" - "go.etcd.io/etcd/server/v3/etcdserver" -) - -type quotaKVServer struct { - pb.KVServer - qa quotaAlarmer -} - -type quotaAlarmer struct { - q etcdserver.Quota - a Alarmer - id types.ID -} - -// check whether request satisfies the quota. If there is not enough space, -// ignore request and raise the free space alarm. -func (qa *quotaAlarmer) check(ctx context.Context, r interface{}) error { - if qa.q.Available(r) { - return nil - } - req := &pb.AlarmRequest{ - MemberID: uint64(qa.id), - Action: pb.AlarmRequest_ACTIVATE, - Alarm: pb.AlarmType_NOSPACE, - } - qa.a.Alarm(ctx, req) - return rpctypes.ErrGRPCNoSpace -} - -func NewQuotaKVServer(s *etcdserver.EtcdServer) pb.KVServer { - return "aKVServer{ - NewKVServer(s), - quotaAlarmer{etcdserver.NewBackendQuota(s, "kv"), s, s.ID()}, - } -} - -func (s *quotaKVServer) Put(ctx context.Context, r *pb.PutRequest) (*pb.PutResponse, error) { - if err := s.qa.check(ctx, r); err != nil { - return nil, err - } - return s.KVServer.Put(ctx, r) -} - -func (s *quotaKVServer) Txn(ctx context.Context, r *pb.TxnRequest) (*pb.TxnResponse, error) { - if err := s.qa.check(ctx, r); err != nil { - return nil, err - } - return s.KVServer.Txn(ctx, r) -} - -type quotaLeaseServer struct { - pb.LeaseServer - qa quotaAlarmer -} - -func (s *quotaLeaseServer) LeaseGrant(ctx context.Context, cr *pb.LeaseGrantRequest) (*pb.LeaseGrantResponse, error) { - if err := s.qa.check(ctx, cr); err != nil { - return nil, err - } - return s.LeaseServer.LeaseGrant(ctx, cr) -} - -func NewQuotaLeaseServer(s *etcdserver.EtcdServer) pb.LeaseServer { - return "aLeaseServer{ - NewLeaseServer(s), - quotaAlarmer{etcdserver.NewBackendQuota(s, "lease"), s, s.ID()}, - } -} diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3rpc/util.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3rpc/util.go deleted file mode 100644 index f61fae03b9..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3rpc/util.go +++ /dev/null @@ -1,147 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package v3rpc - -import ( - "context" - "strings" - - pb "go.etcd.io/etcd/api/v3/etcdserverpb" - "go.etcd.io/etcd/api/v3/v3rpc/rpctypes" - "go.etcd.io/etcd/server/v3/auth" - "go.etcd.io/etcd/server/v3/etcdserver" - "go.etcd.io/etcd/server/v3/etcdserver/api/membership" - "go.etcd.io/etcd/server/v3/lease" - "go.etcd.io/etcd/server/v3/mvcc" - - "google.golang.org/grpc/codes" - "google.golang.org/grpc/status" -) - -var toGRPCErrorMap = map[error]error{ - membership.ErrIDRemoved: rpctypes.ErrGRPCMemberNotFound, - membership.ErrIDNotFound: rpctypes.ErrGRPCMemberNotFound, - membership.ErrIDExists: rpctypes.ErrGRPCMemberExist, - membership.ErrPeerURLexists: rpctypes.ErrGRPCPeerURLExist, - membership.ErrMemberNotLearner: rpctypes.ErrGRPCMemberNotLearner, - membership.ErrTooManyLearners: rpctypes.ErrGRPCTooManyLearners, - etcdserver.ErrNotEnoughStartedMembers: rpctypes.ErrMemberNotEnoughStarted, - etcdserver.ErrLearnerNotReady: rpctypes.ErrGRPCLearnerNotReady, - - mvcc.ErrCompacted: rpctypes.ErrGRPCCompacted, - mvcc.ErrFutureRev: rpctypes.ErrGRPCFutureRev, - etcdserver.ErrRequestTooLarge: rpctypes.ErrGRPCRequestTooLarge, - etcdserver.ErrNoSpace: rpctypes.ErrGRPCNoSpace, - etcdserver.ErrTooManyRequests: rpctypes.ErrTooManyRequests, - - etcdserver.ErrNoLeader: rpctypes.ErrGRPCNoLeader, - etcdserver.ErrNotLeader: rpctypes.ErrGRPCNotLeader, - etcdserver.ErrLeaderChanged: rpctypes.ErrGRPCLeaderChanged, - etcdserver.ErrStopped: rpctypes.ErrGRPCStopped, - etcdserver.ErrTimeout: rpctypes.ErrGRPCTimeout, - etcdserver.ErrTimeoutDueToLeaderFail: rpctypes.ErrGRPCTimeoutDueToLeaderFail, - etcdserver.ErrTimeoutDueToConnectionLost: rpctypes.ErrGRPCTimeoutDueToConnectionLost, - etcdserver.ErrUnhealthy: rpctypes.ErrGRPCUnhealthy, - etcdserver.ErrKeyNotFound: rpctypes.ErrGRPCKeyNotFound, - etcdserver.ErrCorrupt: rpctypes.ErrGRPCCorrupt, - etcdserver.ErrBadLeaderTransferee: rpctypes.ErrGRPCBadLeaderTransferee, - - etcdserver.ErrClusterVersionUnavailable: rpctypes.ErrGRPCClusterVersionUnavailable, - etcdserver.ErrWrongDowngradeVersionFormat: rpctypes.ErrGRPCWrongDowngradeVersionFormat, - etcdserver.ErrInvalidDowngradeTargetVersion: rpctypes.ErrGRPCInvalidDowngradeTargetVersion, - etcdserver.ErrDowngradeInProcess: rpctypes.ErrGRPCDowngradeInProcess, - etcdserver.ErrNoInflightDowngrade: rpctypes.ErrGRPCNoInflightDowngrade, - - lease.ErrLeaseNotFound: rpctypes.ErrGRPCLeaseNotFound, - lease.ErrLeaseExists: rpctypes.ErrGRPCLeaseExist, - lease.ErrLeaseTTLTooLarge: rpctypes.ErrGRPCLeaseTTLTooLarge, - - auth.ErrRootUserNotExist: rpctypes.ErrGRPCRootUserNotExist, - auth.ErrRootRoleNotExist: rpctypes.ErrGRPCRootRoleNotExist, - auth.ErrUserAlreadyExist: rpctypes.ErrGRPCUserAlreadyExist, - auth.ErrUserEmpty: rpctypes.ErrGRPCUserEmpty, - auth.ErrUserNotFound: rpctypes.ErrGRPCUserNotFound, - auth.ErrRoleAlreadyExist: rpctypes.ErrGRPCRoleAlreadyExist, - auth.ErrRoleNotFound: rpctypes.ErrGRPCRoleNotFound, - auth.ErrRoleEmpty: rpctypes.ErrGRPCRoleEmpty, - auth.ErrAuthFailed: rpctypes.ErrGRPCAuthFailed, - auth.ErrPermissionNotGiven: rpctypes.ErrGRPCPermissionNotGiven, - auth.ErrPermissionDenied: rpctypes.ErrGRPCPermissionDenied, - auth.ErrRoleNotGranted: rpctypes.ErrGRPCRoleNotGranted, - auth.ErrPermissionNotGranted: rpctypes.ErrGRPCPermissionNotGranted, - auth.ErrAuthNotEnabled: rpctypes.ErrGRPCAuthNotEnabled, - auth.ErrInvalidAuthToken: rpctypes.ErrGRPCInvalidAuthToken, - auth.ErrInvalidAuthMgmt: rpctypes.ErrGRPCInvalidAuthMgmt, - - // In sync with status.FromContextError - context.Canceled: rpctypes.ErrGRPCCanceled, - context.DeadlineExceeded: rpctypes.ErrGRPCDeadlineExceeded, -} - -func togRPCError(err error) error { - // let gRPC server convert to codes.Canceled, codes.DeadlineExceeded - if err == context.Canceled || err == context.DeadlineExceeded { - return err - } - grpcErr, ok := toGRPCErrorMap[err] - if !ok { - return status.Error(codes.Unknown, err.Error()) - } - return grpcErr -} - -func isClientCtxErr(ctxErr error, err error) bool { - if ctxErr != nil { - return true - } - - ev, ok := status.FromError(err) - if !ok { - return false - } - - switch ev.Code() { - case codes.Canceled, codes.DeadlineExceeded: - // client-side context cancel or deadline exceeded - // "rpc error: code = Canceled desc = context canceled" - // "rpc error: code = DeadlineExceeded desc = context deadline exceeded" - return true - case codes.Unavailable: - msg := ev.Message() - // client-side context cancel or deadline exceeded with TLS ("http2.errClientDisconnected") - // "rpc error: code = Unavailable desc = client disconnected" - if msg == "client disconnected" { - return true - } - // "grpc/transport.ClientTransport.CloseStream" on canceled streams - // "rpc error: code = Unavailable desc = stream error: stream ID 21; CANCEL") - if strings.HasPrefix(msg, "stream error: ") && strings.HasSuffix(msg, "; CANCEL") { - return true - } - } - return false -} - -// in v3.4, learner is allowed to serve serializable read and endpoint status -func isRPCSupportedForLearner(req interface{}) bool { - switch r := req.(type) { - case *pb.StatusRequest: - return true - case *pb.RangeRequest: - return r.Serializable - default: - return false - } -} diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3rpc/watch.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3rpc/watch.go deleted file mode 100644 index c56ec4b26e..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/api/v3rpc/watch.go +++ /dev/null @@ -1,583 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package v3rpc - -import ( - "context" - "io" - "math/rand" - "sync" - "time" - - pb "go.etcd.io/etcd/api/v3/etcdserverpb" - "go.etcd.io/etcd/api/v3/mvccpb" - "go.etcd.io/etcd/api/v3/v3rpc/rpctypes" - "go.etcd.io/etcd/server/v3/auth" - "go.etcd.io/etcd/server/v3/etcdserver" - "go.etcd.io/etcd/server/v3/mvcc" - - "go.uber.org/zap" -) - -const minWatchProgressInterval = 100 * time.Millisecond - -type watchServer struct { - lg *zap.Logger - - clusterID int64 - memberID int64 - - maxRequestBytes int - - sg etcdserver.RaftStatusGetter - watchable mvcc.WatchableKV - ag AuthGetter -} - -// NewWatchServer returns a new watch server. -func NewWatchServer(s *etcdserver.EtcdServer) pb.WatchServer { - srv := &watchServer{ - lg: s.Cfg.Logger, - - clusterID: int64(s.Cluster().ID()), - memberID: int64(s.ID()), - - maxRequestBytes: int(s.Cfg.MaxRequestBytes + grpcOverheadBytes), - - sg: s, - watchable: s.Watchable(), - ag: s, - } - if srv.lg == nil { - srv.lg = zap.NewNop() - } - if s.Cfg.WatchProgressNotifyInterval > 0 { - if s.Cfg.WatchProgressNotifyInterval < minWatchProgressInterval { - srv.lg.Warn( - "adjusting watch progress notify interval to minimum period", - zap.Duration("min-watch-progress-notify-interval", minWatchProgressInterval), - ) - s.Cfg.WatchProgressNotifyInterval = minWatchProgressInterval - } - SetProgressReportInterval(s.Cfg.WatchProgressNotifyInterval) - } - return srv -} - -var ( - // External test can read this with GetProgressReportInterval() - // and change this to a small value to finish fast with - // SetProgressReportInterval(). - progressReportInterval = 10 * time.Minute - progressReportIntervalMu sync.RWMutex -) - -// GetProgressReportInterval returns the current progress report interval (for testing). -func GetProgressReportInterval() time.Duration { - progressReportIntervalMu.RLock() - interval := progressReportInterval - progressReportIntervalMu.RUnlock() - - // add rand(1/10*progressReportInterval) as jitter so that etcdserver will not - // send progress notifications to watchers around the same time even when watchers - // are created around the same time (which is common when a client restarts itself). - jitter := time.Duration(rand.Int63n(int64(interval) / 10)) - - return interval + jitter -} - -// SetProgressReportInterval updates the current progress report interval (for testing). -func SetProgressReportInterval(newTimeout time.Duration) { - progressReportIntervalMu.Lock() - progressReportInterval = newTimeout - progressReportIntervalMu.Unlock() -} - -// We send ctrl response inside the read loop. We do not want -// send to block read, but we still want ctrl response we sent to -// be serialized. Thus we use a buffered chan to solve the problem. -// A small buffer should be OK for most cases, since we expect the -// ctrl requests are infrequent. -const ctrlStreamBufLen = 16 - -// serverWatchStream is an etcd server side stream. It receives requests -// from client side gRPC stream. It receives watch events from mvcc.WatchStream, -// and creates responses that forwarded to gRPC stream. -// It also forwards control message like watch created and canceled. -type serverWatchStream struct { - lg *zap.Logger - - clusterID int64 - memberID int64 - - maxRequestBytes int - - sg etcdserver.RaftStatusGetter - watchable mvcc.WatchableKV - ag AuthGetter - - gRPCStream pb.Watch_WatchServer - watchStream mvcc.WatchStream - ctrlStream chan *pb.WatchResponse - - // mu protects progress, prevKV, fragment - mu sync.RWMutex - // tracks the watchID that stream might need to send progress to - // TODO: combine progress and prevKV into a single struct? - progress map[mvcc.WatchID]bool - // record watch IDs that need return previous key-value pair - prevKV map[mvcc.WatchID]bool - // records fragmented watch IDs - fragment map[mvcc.WatchID]bool - - // closec indicates the stream is closed. - closec chan struct{} - - // wg waits for the send loop to complete - wg sync.WaitGroup -} - -func (ws *watchServer) Watch(stream pb.Watch_WatchServer) (err error) { - sws := serverWatchStream{ - lg: ws.lg, - - clusterID: ws.clusterID, - memberID: ws.memberID, - - maxRequestBytes: ws.maxRequestBytes, - - sg: ws.sg, - watchable: ws.watchable, - ag: ws.ag, - - gRPCStream: stream, - watchStream: ws.watchable.NewWatchStream(), - // chan for sending control response like watcher created and canceled. - ctrlStream: make(chan *pb.WatchResponse, ctrlStreamBufLen), - - progress: make(map[mvcc.WatchID]bool), - prevKV: make(map[mvcc.WatchID]bool), - fragment: make(map[mvcc.WatchID]bool), - - closec: make(chan struct{}), - } - - sws.wg.Add(1) - go func() { - sws.sendLoop() - sws.wg.Done() - }() - - errc := make(chan error, 1) - // Ideally recvLoop would also use sws.wg to signal its completion - // but when stream.Context().Done() is closed, the stream's recv - // may continue to block since it uses a different context, leading to - // deadlock when calling sws.close(). - go func() { - if rerr := sws.recvLoop(); rerr != nil { - if isClientCtxErr(stream.Context().Err(), rerr) { - sws.lg.Debug("failed to receive watch request from gRPC stream", zap.Error(rerr)) - } else { - sws.lg.Warn("failed to receive watch request from gRPC stream", zap.Error(rerr)) - streamFailures.WithLabelValues("receive", "watch").Inc() - } - errc <- rerr - } - }() - - // TODO: There's a race here. When a stream is closed (e.g. due to a cancellation), - // the underlying error (e.g. a gRPC stream error) may be returned and handled - // through errc if the recv goroutine finishes before the send goroutine. - // When the recv goroutine wins, the stream error is retained. When recv loses - // the race, the underlying error is lost (unless the root error is propagated - // through Context.Err() which is not always the case (as callers have to decide - // to implement a custom context to do so). The stdlib context package builtins - // may be insufficient to carry semantically useful errors around and should be - // revisited. - select { - case err = <-errc: - if err == context.Canceled { - err = rpctypes.ErrGRPCWatchCanceled - } - close(sws.ctrlStream) - case <-stream.Context().Done(): - err = stream.Context().Err() - if err == context.Canceled { - err = rpctypes.ErrGRPCWatchCanceled - } - } - - sws.close() - return err -} - -func (sws *serverWatchStream) isWatchPermitted(wcr *pb.WatchCreateRequest) bool { - authInfo, err := sws.ag.AuthInfoFromCtx(sws.gRPCStream.Context()) - if err != nil { - return false - } - if authInfo == nil { - // if auth is enabled, IsRangePermitted() can cause an error - authInfo = &auth.AuthInfo{} - } - return sws.ag.AuthStore().IsRangePermitted(authInfo, wcr.Key, wcr.RangeEnd) == nil -} - -func (sws *serverWatchStream) recvLoop() error { - for { - req, err := sws.gRPCStream.Recv() - if err == io.EOF { - return nil - } - if err != nil { - return err - } - - switch uv := req.RequestUnion.(type) { - case *pb.WatchRequest_CreateRequest: - if uv.CreateRequest == nil { - break - } - - creq := uv.CreateRequest - if len(creq.Key) == 0 { - // \x00 is the smallest key - creq.Key = []byte{0} - } - if len(creq.RangeEnd) == 0 { - // force nil since watchstream.Watch distinguishes - // between nil and []byte{} for single key / >= - creq.RangeEnd = nil - } - if len(creq.RangeEnd) == 1 && creq.RangeEnd[0] == 0 { - // support >= key queries - creq.RangeEnd = []byte{} - } - - if !sws.isWatchPermitted(creq) { - wr := &pb.WatchResponse{ - Header: sws.newResponseHeader(sws.watchStream.Rev()), - WatchId: creq.WatchId, - Canceled: true, - Created: true, - CancelReason: rpctypes.ErrGRPCPermissionDenied.Error(), - } - - select { - case sws.ctrlStream <- wr: - continue - case <-sws.closec: - return nil - } - } - - filters := FiltersFromRequest(creq) - - wsrev := sws.watchStream.Rev() - rev := creq.StartRevision - if rev == 0 { - rev = wsrev + 1 - } - id, err := sws.watchStream.Watch(mvcc.WatchID(creq.WatchId), creq.Key, creq.RangeEnd, rev, filters...) - if err == nil { - sws.mu.Lock() - if creq.ProgressNotify { - sws.progress[id] = true - } - if creq.PrevKv { - sws.prevKV[id] = true - } - if creq.Fragment { - sws.fragment[id] = true - } - sws.mu.Unlock() - } - wr := &pb.WatchResponse{ - Header: sws.newResponseHeader(wsrev), - WatchId: int64(id), - Created: true, - Canceled: err != nil, - } - if err != nil { - wr.CancelReason = err.Error() - } - select { - case sws.ctrlStream <- wr: - case <-sws.closec: - return nil - } - - case *pb.WatchRequest_CancelRequest: - if uv.CancelRequest != nil { - id := uv.CancelRequest.WatchId - err := sws.watchStream.Cancel(mvcc.WatchID(id)) - if err == nil { - sws.ctrlStream <- &pb.WatchResponse{ - Header: sws.newResponseHeader(sws.watchStream.Rev()), - WatchId: id, - Canceled: true, - } - sws.mu.Lock() - delete(sws.progress, mvcc.WatchID(id)) - delete(sws.prevKV, mvcc.WatchID(id)) - delete(sws.fragment, mvcc.WatchID(id)) - sws.mu.Unlock() - } - } - case *pb.WatchRequest_ProgressRequest: - if uv.ProgressRequest != nil { - sws.ctrlStream <- &pb.WatchResponse{ - Header: sws.newResponseHeader(sws.watchStream.Rev()), - WatchId: -1, // response is not associated with any WatchId and will be broadcast to all watch channels - } - } - default: - // we probably should not shutdown the entire stream when - // receive an valid command. - // so just do nothing instead. - continue - } - } -} - -func (sws *serverWatchStream) sendLoop() { - // watch ids that are currently active - ids := make(map[mvcc.WatchID]struct{}) - // watch responses pending on a watch id creation message - pending := make(map[mvcc.WatchID][]*pb.WatchResponse) - - interval := GetProgressReportInterval() - progressTicker := time.NewTicker(interval) - - defer func() { - progressTicker.Stop() - // drain the chan to clean up pending events - for ws := range sws.watchStream.Chan() { - mvcc.ReportEventReceived(len(ws.Events)) - } - for _, wrs := range pending { - for _, ws := range wrs { - mvcc.ReportEventReceived(len(ws.Events)) - } - } - }() - - for { - select { - case wresp, ok := <-sws.watchStream.Chan(): - if !ok { - return - } - - // TODO: evs is []mvccpb.Event type - // either return []*mvccpb.Event from the mvcc package - // or define protocol buffer with []mvccpb.Event. - evs := wresp.Events - events := make([]*mvccpb.Event, len(evs)) - sws.mu.RLock() - needPrevKV := sws.prevKV[wresp.WatchID] - sws.mu.RUnlock() - for i := range evs { - events[i] = &evs[i] - if needPrevKV && !IsCreateEvent(evs[i]) { - opt := mvcc.RangeOptions{Rev: evs[i].Kv.ModRevision - 1} - r, err := sws.watchable.Range(context.TODO(), evs[i].Kv.Key, nil, opt) - if err == nil && len(r.KVs) != 0 { - events[i].PrevKv = &(r.KVs[0]) - } - } - } - - canceled := wresp.CompactRevision != 0 - wr := &pb.WatchResponse{ - Header: sws.newResponseHeader(wresp.Revision), - WatchId: int64(wresp.WatchID), - Events: events, - CompactRevision: wresp.CompactRevision, - Canceled: canceled, - } - - if _, okID := ids[wresp.WatchID]; !okID { - // buffer if id not yet announced - wrs := append(pending[wresp.WatchID], wr) - pending[wresp.WatchID] = wrs - continue - } - - mvcc.ReportEventReceived(len(evs)) - - sws.mu.RLock() - fragmented, ok := sws.fragment[wresp.WatchID] - sws.mu.RUnlock() - - var serr error - if !fragmented && !ok { - serr = sws.gRPCStream.Send(wr) - } else { - serr = sendFragments(wr, sws.maxRequestBytes, sws.gRPCStream.Send) - } - - if serr != nil { - if isClientCtxErr(sws.gRPCStream.Context().Err(), serr) { - sws.lg.Debug("failed to send watch response to gRPC stream", zap.Error(serr)) - } else { - sws.lg.Warn("failed to send watch response to gRPC stream", zap.Error(serr)) - streamFailures.WithLabelValues("send", "watch").Inc() - } - return - } - - sws.mu.Lock() - if len(evs) > 0 && sws.progress[wresp.WatchID] { - // elide next progress update if sent a key update - sws.progress[wresp.WatchID] = false - } - sws.mu.Unlock() - - case c, ok := <-sws.ctrlStream: - if !ok { - return - } - - if err := sws.gRPCStream.Send(c); err != nil { - if isClientCtxErr(sws.gRPCStream.Context().Err(), err) { - sws.lg.Debug("failed to send watch control response to gRPC stream", zap.Error(err)) - } else { - sws.lg.Warn("failed to send watch control response to gRPC stream", zap.Error(err)) - streamFailures.WithLabelValues("send", "watch").Inc() - } - return - } - - // track id creation - wid := mvcc.WatchID(c.WatchId) - if c.Canceled { - delete(ids, wid) - continue - } - if c.Created { - // flush buffered events - ids[wid] = struct{}{} - for _, v := range pending[wid] { - mvcc.ReportEventReceived(len(v.Events)) - if err := sws.gRPCStream.Send(v); err != nil { - if isClientCtxErr(sws.gRPCStream.Context().Err(), err) { - sws.lg.Debug("failed to send pending watch response to gRPC stream", zap.Error(err)) - } else { - sws.lg.Warn("failed to send pending watch response to gRPC stream", zap.Error(err)) - streamFailures.WithLabelValues("send", "watch").Inc() - } - return - } - } - delete(pending, wid) - } - - case <-progressTicker.C: - sws.mu.Lock() - for id, ok := range sws.progress { - if ok { - sws.watchStream.RequestProgress(id) - } - sws.progress[id] = true - } - sws.mu.Unlock() - - case <-sws.closec: - return - } - } -} - -func IsCreateEvent(e mvccpb.Event) bool { - return e.Type == mvccpb.PUT && e.Kv.CreateRevision == e.Kv.ModRevision -} - -func sendFragments( - wr *pb.WatchResponse, - maxRequestBytes int, - sendFunc func(*pb.WatchResponse) error) error { - // no need to fragment if total request size is smaller - // than max request limit or response contains only one event - if wr.Size() < maxRequestBytes || len(wr.Events) < 2 { - return sendFunc(wr) - } - - ow := *wr - ow.Events = make([]*mvccpb.Event, 0) - ow.Fragment = true - - var idx int - for { - cur := ow - for _, ev := range wr.Events[idx:] { - cur.Events = append(cur.Events, ev) - if len(cur.Events) > 1 && cur.Size() >= maxRequestBytes { - cur.Events = cur.Events[:len(cur.Events)-1] - break - } - idx++ - } - if idx == len(wr.Events) { - // last response has no more fragment - cur.Fragment = false - } - if err := sendFunc(&cur); err != nil { - return err - } - if !cur.Fragment { - break - } - } - return nil -} - -func (sws *serverWatchStream) close() { - sws.watchStream.Close() - close(sws.closec) - sws.wg.Wait() -} - -func (sws *serverWatchStream) newResponseHeader(rev int64) *pb.ResponseHeader { - return &pb.ResponseHeader{ - ClusterId: uint64(sws.clusterID), - MemberId: uint64(sws.memberID), - Revision: rev, - RaftTerm: sws.sg.Term(), - } -} - -func filterNoDelete(e mvccpb.Event) bool { - return e.Type == mvccpb.DELETE -} - -func filterNoPut(e mvccpb.Event) bool { - return e.Type == mvccpb.PUT -} - -// FiltersFromRequest returns "mvcc.FilterFunc" from a given watch create request. -func FiltersFromRequest(creq *pb.WatchCreateRequest) []mvcc.FilterFunc { - filters := make([]mvcc.FilterFunc, 0, len(creq.Filters)) - for _, ft := range creq.Filters { - switch ft { - case pb.WatchCreateRequest_NOPUT: - filters = append(filters, filterNoPut) - case pb.WatchCreateRequest_NODELETE: - filters = append(filters, filterNoDelete) - default: - } - } - return filters -} diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/apply.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/apply.go deleted file mode 100644 index 5a77ef3773..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/apply.go +++ /dev/null @@ -1,1151 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package etcdserver - -import ( - "bytes" - "context" - "fmt" - "sort" - "strconv" - "time" - - "github.com/coreos/go-semver/semver" - pb "go.etcd.io/etcd/api/v3/etcdserverpb" - "go.etcd.io/etcd/api/v3/membershippb" - "go.etcd.io/etcd/api/v3/mvccpb" - "go.etcd.io/etcd/client/pkg/v3/types" - "go.etcd.io/etcd/pkg/v3/traceutil" - "go.etcd.io/etcd/server/v3/auth" - "go.etcd.io/etcd/server/v3/etcdserver/api" - "go.etcd.io/etcd/server/v3/etcdserver/api/membership" - "go.etcd.io/etcd/server/v3/lease" - "go.etcd.io/etcd/server/v3/mvcc" - - "github.com/gogo/protobuf/proto" - "go.uber.org/zap" -) - -const ( - v3Version = "v3" -) - -type applyResult struct { - resp proto.Message - err error - // physc signals the physical effect of the request has completed in addition - // to being logically reflected by the node. Currently only used for - // Compaction requests. - physc <-chan struct{} - trace *traceutil.Trace -} - -// applierV3Internal is the interface for processing internal V3 raft request -type applierV3Internal interface { - ClusterVersionSet(r *membershippb.ClusterVersionSetRequest, shouldApplyV3 membership.ShouldApplyV3) - ClusterMemberAttrSet(r *membershippb.ClusterMemberAttrSetRequest, shouldApplyV3 membership.ShouldApplyV3) - DowngradeInfoSet(r *membershippb.DowngradeInfoSetRequest, shouldApplyV3 membership.ShouldApplyV3) -} - -// applierV3 is the interface for processing V3 raft messages -type applierV3 interface { - Apply(r *pb.InternalRaftRequest, shouldApplyV3 membership.ShouldApplyV3) *applyResult - - Put(ctx context.Context, txn mvcc.TxnWrite, p *pb.PutRequest) (*pb.PutResponse, *traceutil.Trace, error) - Range(ctx context.Context, txn mvcc.TxnRead, r *pb.RangeRequest) (*pb.RangeResponse, error) - DeleteRange(txn mvcc.TxnWrite, dr *pb.DeleteRangeRequest) (*pb.DeleteRangeResponse, error) - Txn(ctx context.Context, rt *pb.TxnRequest) (*pb.TxnResponse, *traceutil.Trace, error) - Compaction(compaction *pb.CompactionRequest) (*pb.CompactionResponse, <-chan struct{}, *traceutil.Trace, error) - - LeaseGrant(lc *pb.LeaseGrantRequest) (*pb.LeaseGrantResponse, error) - LeaseRevoke(lc *pb.LeaseRevokeRequest) (*pb.LeaseRevokeResponse, error) - - LeaseCheckpoint(lc *pb.LeaseCheckpointRequest) (*pb.LeaseCheckpointResponse, error) - - Alarm(*pb.AlarmRequest) (*pb.AlarmResponse, error) - - Authenticate(r *pb.InternalAuthenticateRequest) (*pb.AuthenticateResponse, error) - - AuthEnable() (*pb.AuthEnableResponse, error) - AuthDisable() (*pb.AuthDisableResponse, error) - AuthStatus() (*pb.AuthStatusResponse, error) - - UserAdd(ua *pb.AuthUserAddRequest) (*pb.AuthUserAddResponse, error) - UserDelete(ua *pb.AuthUserDeleteRequest) (*pb.AuthUserDeleteResponse, error) - UserChangePassword(ua *pb.AuthUserChangePasswordRequest) (*pb.AuthUserChangePasswordResponse, error) - UserGrantRole(ua *pb.AuthUserGrantRoleRequest) (*pb.AuthUserGrantRoleResponse, error) - UserGet(ua *pb.AuthUserGetRequest) (*pb.AuthUserGetResponse, error) - UserRevokeRole(ua *pb.AuthUserRevokeRoleRequest) (*pb.AuthUserRevokeRoleResponse, error) - RoleAdd(ua *pb.AuthRoleAddRequest) (*pb.AuthRoleAddResponse, error) - RoleGrantPermission(ua *pb.AuthRoleGrantPermissionRequest) (*pb.AuthRoleGrantPermissionResponse, error) - RoleGet(ua *pb.AuthRoleGetRequest) (*pb.AuthRoleGetResponse, error) - RoleRevokePermission(ua *pb.AuthRoleRevokePermissionRequest) (*pb.AuthRoleRevokePermissionResponse, error) - RoleDelete(ua *pb.AuthRoleDeleteRequest) (*pb.AuthRoleDeleteResponse, error) - UserList(ua *pb.AuthUserListRequest) (*pb.AuthUserListResponse, error) - RoleList(ua *pb.AuthRoleListRequest) (*pb.AuthRoleListResponse, error) -} - -type checkReqFunc func(mvcc.ReadView, *pb.RequestOp) error - -type applierV3backend struct { - s *EtcdServer - - checkPut checkReqFunc - checkRange checkReqFunc -} - -func (s *EtcdServer) newApplierV3Backend() applierV3 { - base := &applierV3backend{s: s} - base.checkPut = func(rv mvcc.ReadView, req *pb.RequestOp) error { - return base.checkRequestPut(rv, req) - } - base.checkRange = func(rv mvcc.ReadView, req *pb.RequestOp) error { - return base.checkRequestRange(rv, req) - } - return base -} - -func (s *EtcdServer) newApplierV3Internal() applierV3Internal { - base := &applierV3backend{s: s} - return base -} - -func (s *EtcdServer) newApplierV3() applierV3 { - return newAuthApplierV3( - s.AuthStore(), - newQuotaApplierV3(s, s.newApplierV3Backend()), - s.lessor, - ) -} - -func (a *applierV3backend) Apply(r *pb.InternalRaftRequest, shouldApplyV3 membership.ShouldApplyV3) *applyResult { - op := "unknown" - ar := &applyResult{} - defer func(start time.Time) { - success := ar.err == nil || ar.err == mvcc.ErrCompacted - applySec.WithLabelValues(v3Version, op, strconv.FormatBool(success)).Observe(time.Since(start).Seconds()) - warnOfExpensiveRequest(a.s.Logger(), a.s.Cfg.WarningApplyDuration, start, &pb.InternalRaftStringer{Request: r}, ar.resp, ar.err) - if !success { - warnOfFailedRequest(a.s.Logger(), start, &pb.InternalRaftStringer{Request: r}, ar.resp, ar.err) - } - }(time.Now()) - - switch { - case r.ClusterVersionSet != nil: // Implemented in 3.5.x - op = "ClusterVersionSet" - a.s.applyV3Internal.ClusterVersionSet(r.ClusterVersionSet, shouldApplyV3) - return nil - case r.ClusterMemberAttrSet != nil: - op = "ClusterMemberAttrSet" // Implemented in 3.5.x - a.s.applyV3Internal.ClusterMemberAttrSet(r.ClusterMemberAttrSet, shouldApplyV3) - return nil - case r.DowngradeInfoSet != nil: - op = "DowngradeInfoSet" // Implemented in 3.5.x - a.s.applyV3Internal.DowngradeInfoSet(r.DowngradeInfoSet, shouldApplyV3) - return nil - } - - if !shouldApplyV3 { - return nil - } - - // call into a.s.applyV3.F instead of a.F so upper appliers can check individual calls - switch { - case r.Range != nil: - op = "Range" - ar.resp, ar.err = a.s.applyV3.Range(context.TODO(), nil, r.Range) - case r.Put != nil: - op = "Put" - ar.resp, ar.trace, ar.err = a.s.applyV3.Put(context.TODO(), nil, r.Put) - case r.DeleteRange != nil: - op = "DeleteRange" - ar.resp, ar.err = a.s.applyV3.DeleteRange(nil, r.DeleteRange) - case r.Txn != nil: - op = "Txn" - ar.resp, ar.trace, ar.err = a.s.applyV3.Txn(context.TODO(), r.Txn) - case r.Compaction != nil: - op = "Compaction" - ar.resp, ar.physc, ar.trace, ar.err = a.s.applyV3.Compaction(r.Compaction) - case r.LeaseGrant != nil: - op = "LeaseGrant" - ar.resp, ar.err = a.s.applyV3.LeaseGrant(r.LeaseGrant) - case r.LeaseRevoke != nil: - op = "LeaseRevoke" - ar.resp, ar.err = a.s.applyV3.LeaseRevoke(r.LeaseRevoke) - case r.LeaseCheckpoint != nil: - op = "LeaseCheckpoint" - ar.resp, ar.err = a.s.applyV3.LeaseCheckpoint(r.LeaseCheckpoint) - case r.Alarm != nil: - op = "Alarm" - ar.resp, ar.err = a.s.applyV3.Alarm(r.Alarm) - case r.Authenticate != nil: - op = "Authenticate" - ar.resp, ar.err = a.s.applyV3.Authenticate(r.Authenticate) - case r.AuthEnable != nil: - op = "AuthEnable" - ar.resp, ar.err = a.s.applyV3.AuthEnable() - case r.AuthDisable != nil: - op = "AuthDisable" - ar.resp, ar.err = a.s.applyV3.AuthDisable() - case r.AuthStatus != nil: - ar.resp, ar.err = a.s.applyV3.AuthStatus() - case r.AuthUserAdd != nil: - op = "AuthUserAdd" - ar.resp, ar.err = a.s.applyV3.UserAdd(r.AuthUserAdd) - case r.AuthUserDelete != nil: - op = "AuthUserDelete" - ar.resp, ar.err = a.s.applyV3.UserDelete(r.AuthUserDelete) - case r.AuthUserChangePassword != nil: - op = "AuthUserChangePassword" - ar.resp, ar.err = a.s.applyV3.UserChangePassword(r.AuthUserChangePassword) - case r.AuthUserGrantRole != nil: - op = "AuthUserGrantRole" - ar.resp, ar.err = a.s.applyV3.UserGrantRole(r.AuthUserGrantRole) - case r.AuthUserGet != nil: - op = "AuthUserGet" - ar.resp, ar.err = a.s.applyV3.UserGet(r.AuthUserGet) - case r.AuthUserRevokeRole != nil: - op = "AuthUserRevokeRole" - ar.resp, ar.err = a.s.applyV3.UserRevokeRole(r.AuthUserRevokeRole) - case r.AuthRoleAdd != nil: - op = "AuthRoleAdd" - ar.resp, ar.err = a.s.applyV3.RoleAdd(r.AuthRoleAdd) - case r.AuthRoleGrantPermission != nil: - op = "AuthRoleGrantPermission" - ar.resp, ar.err = a.s.applyV3.RoleGrantPermission(r.AuthRoleGrantPermission) - case r.AuthRoleGet != nil: - op = "AuthRoleGet" - ar.resp, ar.err = a.s.applyV3.RoleGet(r.AuthRoleGet) - case r.AuthRoleRevokePermission != nil: - op = "AuthRoleRevokePermission" - ar.resp, ar.err = a.s.applyV3.RoleRevokePermission(r.AuthRoleRevokePermission) - case r.AuthRoleDelete != nil: - op = "AuthRoleDelete" - ar.resp, ar.err = a.s.applyV3.RoleDelete(r.AuthRoleDelete) - case r.AuthUserList != nil: - op = "AuthUserList" - ar.resp, ar.err = a.s.applyV3.UserList(r.AuthUserList) - case r.AuthRoleList != nil: - op = "AuthRoleList" - ar.resp, ar.err = a.s.applyV3.RoleList(r.AuthRoleList) - default: - a.s.lg.Panic("not implemented apply", zap.Stringer("raft-request", r)) - } - return ar -} - -func (a *applierV3backend) Put(ctx context.Context, txn mvcc.TxnWrite, p *pb.PutRequest) (resp *pb.PutResponse, trace *traceutil.Trace, err error) { - resp = &pb.PutResponse{} - resp.Header = &pb.ResponseHeader{} - trace = traceutil.Get(ctx) - // create put tracing if the trace in context is empty - if trace.IsEmpty() { - trace = traceutil.New("put", - a.s.Logger(), - traceutil.Field{Key: "key", Value: string(p.Key)}, - traceutil.Field{Key: "req_size", Value: p.Size()}, - ) - } - val, leaseID := p.Value, lease.LeaseID(p.Lease) - if txn == nil { - if leaseID != lease.NoLease { - if l := a.s.lessor.Lookup(leaseID); l == nil { - return nil, nil, lease.ErrLeaseNotFound - } - } - txn = a.s.KV().Write(trace) - defer txn.End() - } - - var rr *mvcc.RangeResult - if p.IgnoreValue || p.IgnoreLease || p.PrevKv { - trace.StepWithFunction(func() { - rr, err = txn.Range(context.TODO(), p.Key, nil, mvcc.RangeOptions{}) - }, "get previous kv pair") - - if err != nil { - return nil, nil, err - } - } - if p.IgnoreValue || p.IgnoreLease { - if rr == nil || len(rr.KVs) == 0 { - // ignore_{lease,value} flag expects previous key-value pair - return nil, nil, ErrKeyNotFound - } - } - if p.IgnoreValue { - val = rr.KVs[0].Value - } - if p.IgnoreLease { - leaseID = lease.LeaseID(rr.KVs[0].Lease) - } - if p.PrevKv { - if rr != nil && len(rr.KVs) != 0 { - resp.PrevKv = &rr.KVs[0] - } - } - - resp.Header.Revision = txn.Put(p.Key, val, leaseID) - trace.AddField(traceutil.Field{Key: "response_revision", Value: resp.Header.Revision}) - return resp, trace, nil -} - -func (a *applierV3backend) DeleteRange(txn mvcc.TxnWrite, dr *pb.DeleteRangeRequest) (*pb.DeleteRangeResponse, error) { - resp := &pb.DeleteRangeResponse{} - resp.Header = &pb.ResponseHeader{} - end := mkGteRange(dr.RangeEnd) - - if txn == nil { - txn = a.s.kv.Write(traceutil.TODO()) - defer txn.End() - } - - if dr.PrevKv { - rr, err := txn.Range(context.TODO(), dr.Key, end, mvcc.RangeOptions{}) - if err != nil { - return nil, err - } - if rr != nil { - resp.PrevKvs = make([]*mvccpb.KeyValue, len(rr.KVs)) - for i := range rr.KVs { - resp.PrevKvs[i] = &rr.KVs[i] - } - } - } - - resp.Deleted, resp.Header.Revision = txn.DeleteRange(dr.Key, end) - return resp, nil -} - -func (a *applierV3backend) Range(ctx context.Context, txn mvcc.TxnRead, r *pb.RangeRequest) (*pb.RangeResponse, error) { - trace := traceutil.Get(ctx) - - resp := &pb.RangeResponse{} - resp.Header = &pb.ResponseHeader{} - - if txn == nil { - txn = a.s.kv.Read(mvcc.ConcurrentReadTxMode, trace) - defer txn.End() - } - - limit := r.Limit - if r.SortOrder != pb.RangeRequest_NONE || - r.MinModRevision != 0 || r.MaxModRevision != 0 || - r.MinCreateRevision != 0 || r.MaxCreateRevision != 0 { - // fetch everything; sort and truncate afterwards - limit = 0 - } - if limit > 0 { - // fetch one extra for 'more' flag - limit = limit + 1 - } - - ro := mvcc.RangeOptions{ - Limit: limit, - Rev: r.Revision, - Count: r.CountOnly, - } - - rr, err := txn.Range(ctx, r.Key, mkGteRange(r.RangeEnd), ro) - if err != nil { - return nil, err - } - - if r.MaxModRevision != 0 { - f := func(kv *mvccpb.KeyValue) bool { return kv.ModRevision > r.MaxModRevision } - pruneKVs(rr, f) - } - if r.MinModRevision != 0 { - f := func(kv *mvccpb.KeyValue) bool { return kv.ModRevision < r.MinModRevision } - pruneKVs(rr, f) - } - if r.MaxCreateRevision != 0 { - f := func(kv *mvccpb.KeyValue) bool { return kv.CreateRevision > r.MaxCreateRevision } - pruneKVs(rr, f) - } - if r.MinCreateRevision != 0 { - f := func(kv *mvccpb.KeyValue) bool { return kv.CreateRevision < r.MinCreateRevision } - pruneKVs(rr, f) - } - - sortOrder := r.SortOrder - if r.SortTarget != pb.RangeRequest_KEY && sortOrder == pb.RangeRequest_NONE { - // Since current mvcc.Range implementation returns results - // sorted by keys in lexiographically ascending order, - // sort ASCEND by default only when target is not 'KEY' - sortOrder = pb.RangeRequest_ASCEND - } - if sortOrder != pb.RangeRequest_NONE { - var sorter sort.Interface - switch { - case r.SortTarget == pb.RangeRequest_KEY: - sorter = &kvSortByKey{&kvSort{rr.KVs}} - case r.SortTarget == pb.RangeRequest_VERSION: - sorter = &kvSortByVersion{&kvSort{rr.KVs}} - case r.SortTarget == pb.RangeRequest_CREATE: - sorter = &kvSortByCreate{&kvSort{rr.KVs}} - case r.SortTarget == pb.RangeRequest_MOD: - sorter = &kvSortByMod{&kvSort{rr.KVs}} - case r.SortTarget == pb.RangeRequest_VALUE: - sorter = &kvSortByValue{&kvSort{rr.KVs}} - } - switch { - case sortOrder == pb.RangeRequest_ASCEND: - sort.Sort(sorter) - case sortOrder == pb.RangeRequest_DESCEND: - sort.Sort(sort.Reverse(sorter)) - } - } - - if r.Limit > 0 && len(rr.KVs) > int(r.Limit) { - rr.KVs = rr.KVs[:r.Limit] - resp.More = true - } - trace.Step("filter and sort the key-value pairs") - resp.Header.Revision = rr.Rev - resp.Count = int64(rr.Count) - resp.Kvs = make([]*mvccpb.KeyValue, len(rr.KVs)) - for i := range rr.KVs { - if r.KeysOnly { - rr.KVs[i].Value = nil - } - resp.Kvs[i] = &rr.KVs[i] - } - trace.Step("assemble the response") - return resp, nil -} - -func (a *applierV3backend) Txn(ctx context.Context, rt *pb.TxnRequest) (*pb.TxnResponse, *traceutil.Trace, error) { - trace := traceutil.Get(ctx) - if trace.IsEmpty() { - trace = traceutil.New("transaction", a.s.Logger()) - ctx = context.WithValue(ctx, traceutil.TraceKey, trace) - } - isWrite := !isTxnReadonly(rt) - - // When the transaction contains write operations, we use ReadTx instead of - // ConcurrentReadTx to avoid extra overhead of copying buffer. - var txn mvcc.TxnWrite - if isWrite && a.s.Cfg.ExperimentalTxnModeWriteWithSharedBuffer { - txn = mvcc.NewReadOnlyTxnWrite(a.s.KV().Read(mvcc.SharedBufReadTxMode, trace)) - } else { - txn = mvcc.NewReadOnlyTxnWrite(a.s.KV().Read(mvcc.ConcurrentReadTxMode, trace)) - } - - var txnPath []bool - trace.StepWithFunction( - func() { - txnPath = compareToPath(txn, rt) - }, - "compare", - ) - - if isWrite { - trace.AddField(traceutil.Field{Key: "read_only", Value: false}) - if _, err := checkRequests(txn, rt, txnPath, a.checkPut); err != nil { - txn.End() - return nil, nil, err - } - } - if _, err := checkRequests(txn, rt, txnPath, a.checkRange); err != nil { - txn.End() - return nil, nil, err - } - trace.Step("check requests") - txnResp, _ := newTxnResp(rt, txnPath) - - // When executing mutable txn ops, etcd must hold the txn lock so - // readers do not see any intermediate results. Since writes are - // serialized on the raft loop, the revision in the read view will - // be the revision of the write txn. - if isWrite { - txn.End() - txn = a.s.KV().Write(trace) - } - a.applyTxn(ctx, txn, rt, txnPath, txnResp) - rev := txn.Rev() - if len(txn.Changes()) != 0 { - rev++ - } - txn.End() - - txnResp.Header.Revision = rev - trace.AddField( - traceutil.Field{Key: "number_of_response", Value: len(txnResp.Responses)}, - traceutil.Field{Key: "response_revision", Value: txnResp.Header.Revision}, - ) - return txnResp, trace, nil -} - -// newTxnResp allocates a txn response for a txn request given a path. -func newTxnResp(rt *pb.TxnRequest, txnPath []bool) (txnResp *pb.TxnResponse, txnCount int) { - reqs := rt.Success - if !txnPath[0] { - reqs = rt.Failure - } - resps := make([]*pb.ResponseOp, len(reqs)) - txnResp = &pb.TxnResponse{ - Responses: resps, - Succeeded: txnPath[0], - Header: &pb.ResponseHeader{}, - } - for i, req := range reqs { - switch tv := req.Request.(type) { - case *pb.RequestOp_RequestRange: - resps[i] = &pb.ResponseOp{Response: &pb.ResponseOp_ResponseRange{}} - case *pb.RequestOp_RequestPut: - resps[i] = &pb.ResponseOp{Response: &pb.ResponseOp_ResponsePut{}} - case *pb.RequestOp_RequestDeleteRange: - resps[i] = &pb.ResponseOp{Response: &pb.ResponseOp_ResponseDeleteRange{}} - case *pb.RequestOp_RequestTxn: - resp, txns := newTxnResp(tv.RequestTxn, txnPath[1:]) - resps[i] = &pb.ResponseOp{Response: &pb.ResponseOp_ResponseTxn{ResponseTxn: resp}} - txnPath = txnPath[1+txns:] - txnCount += txns + 1 - default: - } - } - return txnResp, txnCount -} - -func compareToPath(rv mvcc.ReadView, rt *pb.TxnRequest) []bool { - txnPath := make([]bool, 1) - ops := rt.Success - if txnPath[0] = applyCompares(rv, rt.Compare); !txnPath[0] { - ops = rt.Failure - } - for _, op := range ops { - tv, ok := op.Request.(*pb.RequestOp_RequestTxn) - if !ok || tv.RequestTxn == nil { - continue - } - txnPath = append(txnPath, compareToPath(rv, tv.RequestTxn)...) - } - return txnPath -} - -func applyCompares(rv mvcc.ReadView, cmps []*pb.Compare) bool { - for _, c := range cmps { - if !applyCompare(rv, c) { - return false - } - } - return true -} - -// applyCompare applies the compare request. -// If the comparison succeeds, it returns true. Otherwise, returns false. -func applyCompare(rv mvcc.ReadView, c *pb.Compare) bool { - // TODO: possible optimizations - // * chunk reads for large ranges to conserve memory - // * rewrite rules for common patterns: - // ex. "[a, b) createrev > 0" => "limit 1 /\ kvs > 0" - // * caching - rr, err := rv.Range(context.TODO(), c.Key, mkGteRange(c.RangeEnd), mvcc.RangeOptions{}) - if err != nil { - return false - } - if len(rr.KVs) == 0 { - if c.Target == pb.Compare_VALUE { - // Always fail if comparing a value on a key/keys that doesn't exist; - // nil == empty string in grpc; no way to represent missing value - return false - } - return compareKV(c, mvccpb.KeyValue{}) - } - for _, kv := range rr.KVs { - if !compareKV(c, kv) { - return false - } - } - return true -} - -func compareKV(c *pb.Compare, ckv mvccpb.KeyValue) bool { - var result int - rev := int64(0) - switch c.Target { - case pb.Compare_VALUE: - v := []byte{} - if tv, _ := c.TargetUnion.(*pb.Compare_Value); tv != nil { - v = tv.Value - } - result = bytes.Compare(ckv.Value, v) - case pb.Compare_CREATE: - if tv, _ := c.TargetUnion.(*pb.Compare_CreateRevision); tv != nil { - rev = tv.CreateRevision - } - result = compareInt64(ckv.CreateRevision, rev) - case pb.Compare_MOD: - if tv, _ := c.TargetUnion.(*pb.Compare_ModRevision); tv != nil { - rev = tv.ModRevision - } - result = compareInt64(ckv.ModRevision, rev) - case pb.Compare_VERSION: - if tv, _ := c.TargetUnion.(*pb.Compare_Version); tv != nil { - rev = tv.Version - } - result = compareInt64(ckv.Version, rev) - case pb.Compare_LEASE: - if tv, _ := c.TargetUnion.(*pb.Compare_Lease); tv != nil { - rev = tv.Lease - } - result = compareInt64(ckv.Lease, rev) - } - switch c.Result { - case pb.Compare_EQUAL: - return result == 0 - case pb.Compare_NOT_EQUAL: - return result != 0 - case pb.Compare_GREATER: - return result > 0 - case pb.Compare_LESS: - return result < 0 - } - return true -} - -func (a *applierV3backend) applyTxn(ctx context.Context, txn mvcc.TxnWrite, rt *pb.TxnRequest, txnPath []bool, tresp *pb.TxnResponse) (txns int) { - trace := traceutil.Get(ctx) - reqs := rt.Success - if !txnPath[0] { - reqs = rt.Failure - } - - lg := a.s.Logger() - for i, req := range reqs { - respi := tresp.Responses[i].Response - switch tv := req.Request.(type) { - case *pb.RequestOp_RequestRange: - trace.StartSubTrace( - traceutil.Field{Key: "req_type", Value: "range"}, - traceutil.Field{Key: "range_begin", Value: string(tv.RequestRange.Key)}, - traceutil.Field{Key: "range_end", Value: string(tv.RequestRange.RangeEnd)}) - resp, err := a.Range(ctx, txn, tv.RequestRange) - if err != nil { - lg.Panic("unexpected error during txn", zap.Error(err)) - } - respi.(*pb.ResponseOp_ResponseRange).ResponseRange = resp - trace.StopSubTrace() - case *pb.RequestOp_RequestPut: - trace.StartSubTrace( - traceutil.Field{Key: "req_type", Value: "put"}, - traceutil.Field{Key: "key", Value: string(tv.RequestPut.Key)}, - traceutil.Field{Key: "req_size", Value: tv.RequestPut.Size()}) - resp, _, err := a.Put(ctx, txn, tv.RequestPut) - if err != nil { - lg.Panic("unexpected error during txn", zap.Error(err)) - } - respi.(*pb.ResponseOp_ResponsePut).ResponsePut = resp - trace.StopSubTrace() - case *pb.RequestOp_RequestDeleteRange: - resp, err := a.DeleteRange(txn, tv.RequestDeleteRange) - if err != nil { - lg.Panic("unexpected error during txn", zap.Error(err)) - } - respi.(*pb.ResponseOp_ResponseDeleteRange).ResponseDeleteRange = resp - case *pb.RequestOp_RequestTxn: - resp := respi.(*pb.ResponseOp_ResponseTxn).ResponseTxn - applyTxns := a.applyTxn(ctx, txn, tv.RequestTxn, txnPath[1:], resp) - txns += applyTxns + 1 - txnPath = txnPath[applyTxns+1:] - default: - // empty union - } - } - return txns -} - -func (a *applierV3backend) Compaction(compaction *pb.CompactionRequest) (*pb.CompactionResponse, <-chan struct{}, *traceutil.Trace, error) { - resp := &pb.CompactionResponse{} - resp.Header = &pb.ResponseHeader{} - trace := traceutil.New("compact", - a.s.Logger(), - traceutil.Field{Key: "revision", Value: compaction.Revision}, - ) - - ch, err := a.s.KV().Compact(trace, compaction.Revision) - if err != nil { - return nil, ch, nil, err - } - // get the current revision. which key to get is not important. - rr, _ := a.s.KV().Range(context.TODO(), []byte("compaction"), nil, mvcc.RangeOptions{}) - resp.Header.Revision = rr.Rev - return resp, ch, trace, err -} - -func (a *applierV3backend) LeaseGrant(lc *pb.LeaseGrantRequest) (*pb.LeaseGrantResponse, error) { - l, err := a.s.lessor.Grant(lease.LeaseID(lc.ID), lc.TTL) - resp := &pb.LeaseGrantResponse{} - if err == nil { - resp.ID = int64(l.ID) - resp.TTL = l.TTL() - resp.Header = newHeader(a.s) - } - return resp, err -} - -func (a *applierV3backend) LeaseRevoke(lc *pb.LeaseRevokeRequest) (*pb.LeaseRevokeResponse, error) { - err := a.s.lessor.Revoke(lease.LeaseID(lc.ID)) - return &pb.LeaseRevokeResponse{Header: newHeader(a.s)}, err -} - -func (a *applierV3backend) LeaseCheckpoint(lc *pb.LeaseCheckpointRequest) (*pb.LeaseCheckpointResponse, error) { - for _, c := range lc.Checkpoints { - err := a.s.lessor.Checkpoint(lease.LeaseID(c.ID), c.Remaining_TTL) - if err != nil { - return &pb.LeaseCheckpointResponse{Header: newHeader(a.s)}, err - } - } - return &pb.LeaseCheckpointResponse{Header: newHeader(a.s)}, nil -} - -func (a *applierV3backend) Alarm(ar *pb.AlarmRequest) (*pb.AlarmResponse, error) { - resp := &pb.AlarmResponse{} - oldCount := len(a.s.alarmStore.Get(ar.Alarm)) - - lg := a.s.Logger() - switch ar.Action { - case pb.AlarmRequest_GET: - resp.Alarms = a.s.alarmStore.Get(ar.Alarm) - case pb.AlarmRequest_ACTIVATE: - if ar.Alarm == pb.AlarmType_NONE { - break - } - m := a.s.alarmStore.Activate(types.ID(ar.MemberID), ar.Alarm) - if m == nil { - break - } - resp.Alarms = append(resp.Alarms, m) - activated := oldCount == 0 && len(a.s.alarmStore.Get(m.Alarm)) == 1 - if !activated { - break - } - - lg.Warn("alarm raised", zap.String("alarm", m.Alarm.String()), zap.String("from", types.ID(m.MemberID).String())) - switch m.Alarm { - case pb.AlarmType_CORRUPT: - a.s.applyV3 = newApplierV3Corrupt(a) - case pb.AlarmType_NOSPACE: - a.s.applyV3 = newApplierV3Capped(a) - default: - lg.Panic("unimplemented alarm activation", zap.String("alarm", fmt.Sprintf("%+v", m))) - } - case pb.AlarmRequest_DEACTIVATE: - m := a.s.alarmStore.Deactivate(types.ID(ar.MemberID), ar.Alarm) - if m == nil { - break - } - resp.Alarms = append(resp.Alarms, m) - deactivated := oldCount > 0 && len(a.s.alarmStore.Get(ar.Alarm)) == 0 - if !deactivated { - break - } - - switch m.Alarm { - case pb.AlarmType_NOSPACE, pb.AlarmType_CORRUPT: - // TODO: check kv hash before deactivating CORRUPT? - lg.Warn("alarm disarmed", zap.String("alarm", m.Alarm.String()), zap.String("from", types.ID(m.MemberID).String())) - a.s.applyV3 = a.s.newApplierV3() - default: - lg.Warn("unimplemented alarm deactivation", zap.String("alarm", fmt.Sprintf("%+v", m))) - } - default: - return nil, nil - } - return resp, nil -} - -type applierV3Capped struct { - applierV3 - q backendQuota -} - -// newApplierV3Capped creates an applyV3 that will reject Puts and transactions -// with Puts so that the number of keys in the store is capped. -func newApplierV3Capped(base applierV3) applierV3 { return &applierV3Capped{applierV3: base} } - -func (a *applierV3Capped) Put(ctx context.Context, txn mvcc.TxnWrite, p *pb.PutRequest) (*pb.PutResponse, *traceutil.Trace, error) { - return nil, nil, ErrNoSpace -} - -func (a *applierV3Capped) Txn(ctx context.Context, r *pb.TxnRequest) (*pb.TxnResponse, *traceutil.Trace, error) { - if a.q.Cost(r) > 0 { - return nil, nil, ErrNoSpace - } - return a.applierV3.Txn(ctx, r) -} - -func (a *applierV3Capped) LeaseGrant(lc *pb.LeaseGrantRequest) (*pb.LeaseGrantResponse, error) { - return nil, ErrNoSpace -} - -func (a *applierV3backend) AuthEnable() (*pb.AuthEnableResponse, error) { - err := a.s.AuthStore().AuthEnable() - if err != nil { - return nil, err - } - return &pb.AuthEnableResponse{Header: newHeader(a.s)}, nil -} - -func (a *applierV3backend) AuthDisable() (*pb.AuthDisableResponse, error) { - a.s.AuthStore().AuthDisable() - return &pb.AuthDisableResponse{Header: newHeader(a.s)}, nil -} - -func (a *applierV3backend) AuthStatus() (*pb.AuthStatusResponse, error) { - enabled := a.s.AuthStore().IsAuthEnabled() - authRevision := a.s.AuthStore().Revision() - return &pb.AuthStatusResponse{Header: newHeader(a.s), Enabled: enabled, AuthRevision: authRevision}, nil -} - -func (a *applierV3backend) Authenticate(r *pb.InternalAuthenticateRequest) (*pb.AuthenticateResponse, error) { - ctx := context.WithValue(context.WithValue(a.s.ctx, auth.AuthenticateParamIndex{}, a.s.consistIndex.ConsistentIndex()), auth.AuthenticateParamSimpleTokenPrefix{}, r.SimpleToken) - resp, err := a.s.AuthStore().Authenticate(ctx, r.Name, r.Password) - if resp != nil { - resp.Header = newHeader(a.s) - } - return resp, err -} - -func (a *applierV3backend) UserAdd(r *pb.AuthUserAddRequest) (*pb.AuthUserAddResponse, error) { - resp, err := a.s.AuthStore().UserAdd(r) - if resp != nil { - resp.Header = newHeader(a.s) - } - return resp, err -} - -func (a *applierV3backend) UserDelete(r *pb.AuthUserDeleteRequest) (*pb.AuthUserDeleteResponse, error) { - resp, err := a.s.AuthStore().UserDelete(r) - if resp != nil { - resp.Header = newHeader(a.s) - } - return resp, err -} - -func (a *applierV3backend) UserChangePassword(r *pb.AuthUserChangePasswordRequest) (*pb.AuthUserChangePasswordResponse, error) { - resp, err := a.s.AuthStore().UserChangePassword(r) - if resp != nil { - resp.Header = newHeader(a.s) - } - return resp, err -} - -func (a *applierV3backend) UserGrantRole(r *pb.AuthUserGrantRoleRequest) (*pb.AuthUserGrantRoleResponse, error) { - resp, err := a.s.AuthStore().UserGrantRole(r) - if resp != nil { - resp.Header = newHeader(a.s) - } - return resp, err -} - -func (a *applierV3backend) UserGet(r *pb.AuthUserGetRequest) (*pb.AuthUserGetResponse, error) { - resp, err := a.s.AuthStore().UserGet(r) - if resp != nil { - resp.Header = newHeader(a.s) - } - return resp, err -} - -func (a *applierV3backend) UserRevokeRole(r *pb.AuthUserRevokeRoleRequest) (*pb.AuthUserRevokeRoleResponse, error) { - resp, err := a.s.AuthStore().UserRevokeRole(r) - if resp != nil { - resp.Header = newHeader(a.s) - } - return resp, err -} - -func (a *applierV3backend) RoleAdd(r *pb.AuthRoleAddRequest) (*pb.AuthRoleAddResponse, error) { - resp, err := a.s.AuthStore().RoleAdd(r) - if resp != nil { - resp.Header = newHeader(a.s) - } - return resp, err -} - -func (a *applierV3backend) RoleGrantPermission(r *pb.AuthRoleGrantPermissionRequest) (*pb.AuthRoleGrantPermissionResponse, error) { - resp, err := a.s.AuthStore().RoleGrantPermission(r) - if resp != nil { - resp.Header = newHeader(a.s) - } - return resp, err -} - -func (a *applierV3backend) RoleGet(r *pb.AuthRoleGetRequest) (*pb.AuthRoleGetResponse, error) { - resp, err := a.s.AuthStore().RoleGet(r) - if resp != nil { - resp.Header = newHeader(a.s) - } - return resp, err -} - -func (a *applierV3backend) RoleRevokePermission(r *pb.AuthRoleRevokePermissionRequest) (*pb.AuthRoleRevokePermissionResponse, error) { - resp, err := a.s.AuthStore().RoleRevokePermission(r) - if resp != nil { - resp.Header = newHeader(a.s) - } - return resp, err -} - -func (a *applierV3backend) RoleDelete(r *pb.AuthRoleDeleteRequest) (*pb.AuthRoleDeleteResponse, error) { - resp, err := a.s.AuthStore().RoleDelete(r) - if resp != nil { - resp.Header = newHeader(a.s) - } - return resp, err -} - -func (a *applierV3backend) UserList(r *pb.AuthUserListRequest) (*pb.AuthUserListResponse, error) { - resp, err := a.s.AuthStore().UserList(r) - if resp != nil { - resp.Header = newHeader(a.s) - } - return resp, err -} - -func (a *applierV3backend) RoleList(r *pb.AuthRoleListRequest) (*pb.AuthRoleListResponse, error) { - resp, err := a.s.AuthStore().RoleList(r) - if resp != nil { - resp.Header = newHeader(a.s) - } - return resp, err -} - -func (a *applierV3backend) ClusterVersionSet(r *membershippb.ClusterVersionSetRequest, shouldApplyV3 membership.ShouldApplyV3) { - a.s.cluster.SetVersion(semver.Must(semver.NewVersion(r.Ver)), api.UpdateCapability, shouldApplyV3) -} - -func (a *applierV3backend) ClusterMemberAttrSet(r *membershippb.ClusterMemberAttrSetRequest, shouldApplyV3 membership.ShouldApplyV3) { - a.s.cluster.UpdateAttributes( - types.ID(r.Member_ID), - membership.Attributes{ - Name: r.MemberAttributes.Name, - ClientURLs: r.MemberAttributes.ClientUrls, - }, - shouldApplyV3, - ) -} - -func (a *applierV3backend) DowngradeInfoSet(r *membershippb.DowngradeInfoSetRequest, shouldApplyV3 membership.ShouldApplyV3) { - d := membership.DowngradeInfo{Enabled: false} - if r.Enabled { - d = membership.DowngradeInfo{Enabled: true, TargetVersion: r.Ver} - } - a.s.cluster.SetDowngradeInfo(&d, shouldApplyV3) -} - -type quotaApplierV3 struct { - applierV3 - q Quota -} - -func newQuotaApplierV3(s *EtcdServer, app applierV3) applierV3 { - return "aApplierV3{app, NewBackendQuota(s, "v3-applier")} -} - -func (a *quotaApplierV3) Put(ctx context.Context, txn mvcc.TxnWrite, p *pb.PutRequest) (*pb.PutResponse, *traceutil.Trace, error) { - ok := a.q.Available(p) - resp, trace, err := a.applierV3.Put(ctx, txn, p) - if err == nil && !ok { - err = ErrNoSpace - } - return resp, trace, err -} - -func (a *quotaApplierV3) Txn(ctx context.Context, rt *pb.TxnRequest) (*pb.TxnResponse, *traceutil.Trace, error) { - ok := a.q.Available(rt) - resp, trace, err := a.applierV3.Txn(ctx, rt) - if err == nil && !ok { - err = ErrNoSpace - } - return resp, trace, err -} - -func (a *quotaApplierV3) LeaseGrant(lc *pb.LeaseGrantRequest) (*pb.LeaseGrantResponse, error) { - ok := a.q.Available(lc) - resp, err := a.applierV3.LeaseGrant(lc) - if err == nil && !ok { - err = ErrNoSpace - } - return resp, err -} - -type kvSort struct{ kvs []mvccpb.KeyValue } - -func (s *kvSort) Swap(i, j int) { - t := s.kvs[i] - s.kvs[i] = s.kvs[j] - s.kvs[j] = t -} -func (s *kvSort) Len() int { return len(s.kvs) } - -type kvSortByKey struct{ *kvSort } - -func (s *kvSortByKey) Less(i, j int) bool { - return bytes.Compare(s.kvs[i].Key, s.kvs[j].Key) < 0 -} - -type kvSortByVersion struct{ *kvSort } - -func (s *kvSortByVersion) Less(i, j int) bool { - return (s.kvs[i].Version - s.kvs[j].Version) < 0 -} - -type kvSortByCreate struct{ *kvSort } - -func (s *kvSortByCreate) Less(i, j int) bool { - return (s.kvs[i].CreateRevision - s.kvs[j].CreateRevision) < 0 -} - -type kvSortByMod struct{ *kvSort } - -func (s *kvSortByMod) Less(i, j int) bool { - return (s.kvs[i].ModRevision - s.kvs[j].ModRevision) < 0 -} - -type kvSortByValue struct{ *kvSort } - -func (s *kvSortByValue) Less(i, j int) bool { - return bytes.Compare(s.kvs[i].Value, s.kvs[j].Value) < 0 -} - -func checkRequests(rv mvcc.ReadView, rt *pb.TxnRequest, txnPath []bool, f checkReqFunc) (int, error) { - txnCount := 0 - reqs := rt.Success - if !txnPath[0] { - reqs = rt.Failure - } - for _, req := range reqs { - if tv, ok := req.Request.(*pb.RequestOp_RequestTxn); ok && tv.RequestTxn != nil { - txns, err := checkRequests(rv, tv.RequestTxn, txnPath[1:], f) - if err != nil { - return 0, err - } - txnCount += txns + 1 - txnPath = txnPath[txns+1:] - continue - } - if err := f(rv, req); err != nil { - return 0, err - } - } - return txnCount, nil -} - -func (a *applierV3backend) checkRequestPut(rv mvcc.ReadView, reqOp *pb.RequestOp) error { - tv, ok := reqOp.Request.(*pb.RequestOp_RequestPut) - if !ok || tv.RequestPut == nil { - return nil - } - req := tv.RequestPut - if req.IgnoreValue || req.IgnoreLease { - // expects previous key-value, error if not exist - rr, err := rv.Range(context.TODO(), req.Key, nil, mvcc.RangeOptions{}) - if err != nil { - return err - } - if rr == nil || len(rr.KVs) == 0 { - return ErrKeyNotFound - } - } - if lease.LeaseID(req.Lease) != lease.NoLease { - if l := a.s.lessor.Lookup(lease.LeaseID(req.Lease)); l == nil { - return lease.ErrLeaseNotFound - } - } - return nil -} - -func (a *applierV3backend) checkRequestRange(rv mvcc.ReadView, reqOp *pb.RequestOp) error { - tv, ok := reqOp.Request.(*pb.RequestOp_RequestRange) - if !ok || tv.RequestRange == nil { - return nil - } - req := tv.RequestRange - switch { - case req.Revision == 0: - return nil - case req.Revision > rv.Rev(): - return mvcc.ErrFutureRev - case req.Revision < rv.FirstRev(): - return mvcc.ErrCompacted - } - return nil -} - -func compareInt64(a, b int64) int { - switch { - case a < b: - return -1 - case a > b: - return 1 - default: - return 0 - } -} - -// mkGteRange determines if the range end is a >= range. This works around grpc -// sending empty byte strings as nil; >= is encoded in the range end as '\0'. -// If it is a GTE range, then []byte{} is returned to indicate the empty byte -// string (vs nil being no byte string). -func mkGteRange(rangeEnd []byte) []byte { - if len(rangeEnd) == 1 && rangeEnd[0] == 0 { - return []byte{} - } - return rangeEnd -} - -func noSideEffect(r *pb.InternalRaftRequest) bool { - return r.Range != nil || r.AuthUserGet != nil || r.AuthRoleGet != nil || r.AuthStatus != nil -} - -func removeNeedlessRangeReqs(txn *pb.TxnRequest) { - f := func(ops []*pb.RequestOp) []*pb.RequestOp { - j := 0 - for i := 0; i < len(ops); i++ { - if _, ok := ops[i].Request.(*pb.RequestOp_RequestRange); ok { - continue - } - ops[j] = ops[i] - j++ - } - - return ops[:j] - } - - txn.Success = f(txn.Success) - txn.Failure = f(txn.Failure) -} - -func pruneKVs(rr *mvcc.RangeResult, isPrunable func(*mvccpb.KeyValue) bool) { - j := 0 - for i := range rr.KVs { - rr.KVs[j] = rr.KVs[i] - if !isPrunable(&rr.KVs[i]) { - j++ - } - } - rr.KVs = rr.KVs[:j] -} - -func newHeader(s *EtcdServer) *pb.ResponseHeader { - return &pb.ResponseHeader{ - ClusterId: uint64(s.Cluster().ID()), - MemberId: uint64(s.ID()), - Revision: s.KV().Rev(), - RaftTerm: s.Term(), - } -} diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/apply_auth.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/apply_auth.go deleted file mode 100644 index 74fd2b4fc3..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/apply_auth.go +++ /dev/null @@ -1,247 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package etcdserver - -import ( - "context" - "sync" - - pb "go.etcd.io/etcd/api/v3/etcdserverpb" - "go.etcd.io/etcd/pkg/v3/traceutil" - "go.etcd.io/etcd/server/v3/auth" - "go.etcd.io/etcd/server/v3/etcdserver/api/membership" - "go.etcd.io/etcd/server/v3/lease" - "go.etcd.io/etcd/server/v3/mvcc" -) - -type authApplierV3 struct { - applierV3 - as auth.AuthStore - lessor lease.Lessor - - // mu serializes Apply so that user isn't corrupted and so that - // serialized requests don't leak data from TOCTOU errors - mu sync.Mutex - - authInfo auth.AuthInfo -} - -func newAuthApplierV3(as auth.AuthStore, base applierV3, lessor lease.Lessor) *authApplierV3 { - return &authApplierV3{applierV3: base, as: as, lessor: lessor} -} - -func (aa *authApplierV3) Apply(r *pb.InternalRaftRequest, shouldApplyV3 membership.ShouldApplyV3) *applyResult { - aa.mu.Lock() - defer aa.mu.Unlock() - if r.Header != nil { - // backward-compatible with pre-3.0 releases when internalRaftRequest - // does not have header field - aa.authInfo.Username = r.Header.Username - aa.authInfo.Revision = r.Header.AuthRevision - } - if needAdminPermission(r) { - if err := aa.as.IsAdminPermitted(&aa.authInfo); err != nil { - aa.authInfo.Username = "" - aa.authInfo.Revision = 0 - return &applyResult{err: err} - } - } - ret := aa.applierV3.Apply(r, shouldApplyV3) - aa.authInfo.Username = "" - aa.authInfo.Revision = 0 - return ret -} - -func (aa *authApplierV3) Put(ctx context.Context, txn mvcc.TxnWrite, r *pb.PutRequest) (*pb.PutResponse, *traceutil.Trace, error) { - if err := aa.as.IsPutPermitted(&aa.authInfo, r.Key); err != nil { - return nil, nil, err - } - - if err := aa.checkLeasePuts(lease.LeaseID(r.Lease)); err != nil { - // The specified lease is already attached with a key that cannot - // be written by this user. It means the user cannot revoke the - // lease so attaching the lease to the newly written key should - // be forbidden. - return nil, nil, err - } - - if r.PrevKv { - err := aa.as.IsRangePermitted(&aa.authInfo, r.Key, nil) - if err != nil { - return nil, nil, err - } - } - return aa.applierV3.Put(ctx, txn, r) -} - -func (aa *authApplierV3) Range(ctx context.Context, txn mvcc.TxnRead, r *pb.RangeRequest) (*pb.RangeResponse, error) { - if err := aa.as.IsRangePermitted(&aa.authInfo, r.Key, r.RangeEnd); err != nil { - return nil, err - } - return aa.applierV3.Range(ctx, txn, r) -} - -func (aa *authApplierV3) DeleteRange(txn mvcc.TxnWrite, r *pb.DeleteRangeRequest) (*pb.DeleteRangeResponse, error) { - if err := aa.as.IsDeleteRangePermitted(&aa.authInfo, r.Key, r.RangeEnd); err != nil { - return nil, err - } - if r.PrevKv { - err := aa.as.IsRangePermitted(&aa.authInfo, r.Key, r.RangeEnd) - if err != nil { - return nil, err - } - } - - return aa.applierV3.DeleteRange(txn, r) -} - -func checkTxnReqsPermission(as auth.AuthStore, ai *auth.AuthInfo, reqs []*pb.RequestOp) error { - for _, requ := range reqs { - switch tv := requ.Request.(type) { - case *pb.RequestOp_RequestRange: - if tv.RequestRange == nil { - continue - } - - if err := as.IsRangePermitted(ai, tv.RequestRange.Key, tv.RequestRange.RangeEnd); err != nil { - return err - } - - case *pb.RequestOp_RequestPut: - if tv.RequestPut == nil { - continue - } - - if err := as.IsPutPermitted(ai, tv.RequestPut.Key); err != nil { - return err - } - - case *pb.RequestOp_RequestDeleteRange: - if tv.RequestDeleteRange == nil { - continue - } - - if tv.RequestDeleteRange.PrevKv { - err := as.IsRangePermitted(ai, tv.RequestDeleteRange.Key, tv.RequestDeleteRange.RangeEnd) - if err != nil { - return err - } - } - - err := as.IsDeleteRangePermitted(ai, tv.RequestDeleteRange.Key, tv.RequestDeleteRange.RangeEnd) - if err != nil { - return err - } - } - } - - return nil -} - -func checkTxnAuth(as auth.AuthStore, ai *auth.AuthInfo, rt *pb.TxnRequest) error { - for _, c := range rt.Compare { - if err := as.IsRangePermitted(ai, c.Key, c.RangeEnd); err != nil { - return err - } - } - if err := checkTxnReqsPermission(as, ai, rt.Success); err != nil { - return err - } - return checkTxnReqsPermission(as, ai, rt.Failure) -} - -func (aa *authApplierV3) Txn(ctx context.Context, rt *pb.TxnRequest) (*pb.TxnResponse, *traceutil.Trace, error) { - if err := checkTxnAuth(aa.as, &aa.authInfo, rt); err != nil { - return nil, nil, err - } - return aa.applierV3.Txn(ctx, rt) -} - -func (aa *authApplierV3) LeaseRevoke(lc *pb.LeaseRevokeRequest) (*pb.LeaseRevokeResponse, error) { - if err := aa.checkLeasePuts(lease.LeaseID(lc.ID)); err != nil { - return nil, err - } - return aa.applierV3.LeaseRevoke(lc) -} - -func (aa *authApplierV3) checkLeasePuts(leaseID lease.LeaseID) error { - lease := aa.lessor.Lookup(leaseID) - if lease != nil { - for _, key := range lease.Keys() { - if err := aa.as.IsPutPermitted(&aa.authInfo, []byte(key)); err != nil { - return err - } - } - } - - return nil -} - -func (aa *authApplierV3) UserGet(r *pb.AuthUserGetRequest) (*pb.AuthUserGetResponse, error) { - err := aa.as.IsAdminPermitted(&aa.authInfo) - if err != nil && r.Name != aa.authInfo.Username { - aa.authInfo.Username = "" - aa.authInfo.Revision = 0 - return &pb.AuthUserGetResponse{}, err - } - - return aa.applierV3.UserGet(r) -} - -func (aa *authApplierV3) RoleGet(r *pb.AuthRoleGetRequest) (*pb.AuthRoleGetResponse, error) { - err := aa.as.IsAdminPermitted(&aa.authInfo) - if err != nil && !aa.as.HasRole(aa.authInfo.Username, r.Role) { - aa.authInfo.Username = "" - aa.authInfo.Revision = 0 - return &pb.AuthRoleGetResponse{}, err - } - - return aa.applierV3.RoleGet(r) -} - -func needAdminPermission(r *pb.InternalRaftRequest) bool { - switch { - case r.AuthEnable != nil: - return true - case r.AuthDisable != nil: - return true - case r.AuthStatus != nil: - return true - case r.AuthUserAdd != nil: - return true - case r.AuthUserDelete != nil: - return true - case r.AuthUserChangePassword != nil: - return true - case r.AuthUserGrantRole != nil: - return true - case r.AuthUserRevokeRole != nil: - return true - case r.AuthRoleAdd != nil: - return true - case r.AuthRoleGrantPermission != nil: - return true - case r.AuthRoleRevokePermission != nil: - return true - case r.AuthRoleDelete != nil: - return true - case r.AuthUserList != nil: - return true - case r.AuthRoleList != nil: - return true - default: - return false - } -} diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/apply_v2.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/apply_v2.go deleted file mode 100644 index 2f5913f18c..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/apply_v2.go +++ /dev/null @@ -1,159 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package etcdserver - -import ( - "encoding/json" - "fmt" - "path" - "strconv" - "time" - - "github.com/coreos/go-semver/semver" - "go.etcd.io/etcd/pkg/v3/pbutil" - "go.etcd.io/etcd/server/v3/etcdserver/api" - "go.etcd.io/etcd/server/v3/etcdserver/api/membership" - "go.etcd.io/etcd/server/v3/etcdserver/api/v2store" - - "go.uber.org/zap" -) - -const v2Version = "v2" - -// ApplierV2 is the interface for processing V2 raft messages -type ApplierV2 interface { - Delete(r *RequestV2) Response - Post(r *RequestV2) Response - Put(r *RequestV2, shouldApplyV3 membership.ShouldApplyV3) Response - QGet(r *RequestV2) Response - Sync(r *RequestV2) Response -} - -func NewApplierV2(lg *zap.Logger, s v2store.Store, c *membership.RaftCluster) ApplierV2 { - if lg == nil { - lg = zap.NewNop() - } - return &applierV2store{lg: lg, store: s, cluster: c} -} - -type applierV2store struct { - lg *zap.Logger - store v2store.Store - cluster *membership.RaftCluster -} - -func (a *applierV2store) Delete(r *RequestV2) Response { - switch { - case r.PrevIndex > 0 || r.PrevValue != "": - return toResponse(a.store.CompareAndDelete(r.Path, r.PrevValue, r.PrevIndex)) - default: - return toResponse(a.store.Delete(r.Path, r.Dir, r.Recursive)) - } -} - -func (a *applierV2store) Post(r *RequestV2) Response { - return toResponse(a.store.Create(r.Path, r.Dir, r.Val, true, r.TTLOptions())) -} - -func (a *applierV2store) Put(r *RequestV2, shouldApplyV3 membership.ShouldApplyV3) Response { - ttlOptions := r.TTLOptions() - exists, existsSet := pbutil.GetBool(r.PrevExist) - switch { - case existsSet: - if exists { - if r.PrevIndex == 0 && r.PrevValue == "" { - return toResponse(a.store.Update(r.Path, r.Val, ttlOptions)) - } - return toResponse(a.store.CompareAndSwap(r.Path, r.PrevValue, r.PrevIndex, r.Val, ttlOptions)) - } - return toResponse(a.store.Create(r.Path, r.Dir, r.Val, false, ttlOptions)) - case r.PrevIndex > 0 || r.PrevValue != "": - return toResponse(a.store.CompareAndSwap(r.Path, r.PrevValue, r.PrevIndex, r.Val, ttlOptions)) - default: - if storeMemberAttributeRegexp.MatchString(r.Path) { - id := membership.MustParseMemberIDFromKey(a.lg, path.Dir(r.Path)) - var attr membership.Attributes - if err := json.Unmarshal([]byte(r.Val), &attr); err != nil { - a.lg.Panic("failed to unmarshal", zap.String("value", r.Val), zap.Error(err)) - } - if a.cluster != nil { - a.cluster.UpdateAttributes(id, attr, shouldApplyV3) - } - // return an empty response since there is no consumer. - return Response{} - } - // TODO remove v2 version set to avoid the conflict between v2 and v3 in etcd 3.6 - if r.Path == membership.StoreClusterVersionKey() { - if a.cluster != nil { - // persist to backend given v2store can be very stale - a.cluster.SetVersion(semver.Must(semver.NewVersion(r.Val)), api.UpdateCapability, shouldApplyV3) - } - return Response{} - } - return toResponse(a.store.Set(r.Path, r.Dir, r.Val, ttlOptions)) - } -} - -func (a *applierV2store) QGet(r *RequestV2) Response { - return toResponse(a.store.Get(r.Path, r.Recursive, r.Sorted)) -} - -func (a *applierV2store) Sync(r *RequestV2) Response { - a.store.DeleteExpiredKeys(time.Unix(0, r.Time)) - return Response{} -} - -// applyV2Request interprets r as a call to v2store.X -// and returns a Response interpreted from v2store.Event -func (s *EtcdServer) applyV2Request(r *RequestV2, shouldApplyV3 membership.ShouldApplyV3) (resp Response) { - stringer := panicAlternativeStringer{ - stringer: r, - alternative: func() string { return fmt.Sprintf("id:%d,method:%s,path:%s", r.ID, r.Method, r.Path) }, - } - defer func(start time.Time) { - success := resp.Err == nil - applySec.WithLabelValues(v2Version, r.Method, strconv.FormatBool(success)).Observe(time.Since(start).Seconds()) - warnOfExpensiveRequest(s.Logger(), s.Cfg.WarningApplyDuration, start, stringer, nil, nil) - }(time.Now()) - - switch r.Method { - case "POST": - return s.applyV2.Post(r) - case "PUT": - return s.applyV2.Put(r, shouldApplyV3) - case "DELETE": - return s.applyV2.Delete(r) - case "QGET": - return s.applyV2.QGet(r) - case "SYNC": - return s.applyV2.Sync(r) - default: - // This should never be reached, but just in case: - return Response{Err: ErrUnknownMethod} - } -} - -func (r *RequestV2) TTLOptions() v2store.TTLOptionSet { - refresh, _ := pbutil.GetBool(r.Refresh) - ttlOptions := v2store.TTLOptionSet{Refresh: refresh} - if r.Expiration != 0 { - ttlOptions.ExpireTime = time.Unix(0, r.Expiration) - } - return ttlOptions -} - -func toResponse(ev *v2store.Event, err error) Response { - return Response{Event: ev, Err: err} -} diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/backend.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/backend.go deleted file mode 100644 index 081be2b525..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/backend.go +++ /dev/null @@ -1,109 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package etcdserver - -import ( - "fmt" - "os" - "time" - - "go.etcd.io/etcd/raft/v3/raftpb" - "go.etcd.io/etcd/server/v3/config" - "go.etcd.io/etcd/server/v3/etcdserver/api/snap" - "go.etcd.io/etcd/server/v3/etcdserver/cindex" - "go.etcd.io/etcd/server/v3/mvcc/backend" - - "go.uber.org/zap" -) - -func newBackend(cfg config.ServerConfig, hooks backend.Hooks) backend.Backend { - bcfg := backend.DefaultBackendConfig() - bcfg.Path = cfg.BackendPath() - bcfg.UnsafeNoFsync = cfg.UnsafeNoFsync - if cfg.BackendBatchLimit != 0 { - bcfg.BatchLimit = cfg.BackendBatchLimit - if cfg.Logger != nil { - cfg.Logger.Info("setting backend batch limit", zap.Int("batch limit", cfg.BackendBatchLimit)) - } - } - if cfg.BackendBatchInterval != 0 { - bcfg.BatchInterval = cfg.BackendBatchInterval - if cfg.Logger != nil { - cfg.Logger.Info("setting backend batch interval", zap.Duration("batch interval", cfg.BackendBatchInterval)) - } - } - bcfg.BackendFreelistType = cfg.BackendFreelistType - bcfg.Logger = cfg.Logger - if cfg.QuotaBackendBytes > 0 && cfg.QuotaBackendBytes != DefaultQuotaBytes { - // permit 10% excess over quota for disarm - bcfg.MmapSize = uint64(cfg.QuotaBackendBytes + cfg.QuotaBackendBytes/10) - } - bcfg.Mlock = cfg.ExperimentalMemoryMlock - bcfg.Hooks = hooks - return backend.New(bcfg) -} - -// openSnapshotBackend renames a snapshot db to the current etcd db and opens it. -func openSnapshotBackend(cfg config.ServerConfig, ss *snap.Snapshotter, snapshot raftpb.Snapshot, hooks backend.Hooks) (backend.Backend, error) { - snapPath, err := ss.DBFilePath(snapshot.Metadata.Index) - if err != nil { - return nil, fmt.Errorf("failed to find database snapshot file (%v)", err) - } - if err := os.Rename(snapPath, cfg.BackendPath()); err != nil { - return nil, fmt.Errorf("failed to rename database snapshot file (%v)", err) - } - return openBackend(cfg, hooks), nil -} - -// openBackend returns a backend using the current etcd db. -func openBackend(cfg config.ServerConfig, hooks backend.Hooks) backend.Backend { - fn := cfg.BackendPath() - - now, beOpened := time.Now(), make(chan backend.Backend) - go func() { - beOpened <- newBackend(cfg, hooks) - }() - - select { - case be := <-beOpened: - cfg.Logger.Info("opened backend db", zap.String("path", fn), zap.Duration("took", time.Since(now))) - return be - - case <-time.After(10 * time.Second): - cfg.Logger.Info( - "db file is flocked by another process, or taking too long", - zap.String("path", fn), - zap.Duration("took", time.Since(now)), - ) - } - - return <-beOpened -} - -// recoverBackendSnapshot recovers the DB from a snapshot in case etcd crashes -// before updating the backend db after persisting raft snapshot to disk, -// violating the invariant snapshot.Metadata.Index < db.consistentIndex. In this -// case, replace the db with the snapshot db sent by the leader. -func recoverSnapshotBackend(cfg config.ServerConfig, oldbe backend.Backend, snapshot raftpb.Snapshot, beExist bool, hooks backend.Hooks) (backend.Backend, error) { - consistentIndex := uint64(0) - if beExist { - consistentIndex, _ = cindex.ReadConsistentIndex(oldbe.BatchTx()) - } - if snapshot.Metadata.Index <= consistentIndex { - return oldbe, nil - } - oldbe.Close() - return openSnapshotBackend(cfg, snap.New(cfg.Logger, cfg.SnapDir()), snapshot, hooks) -} diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/cindex/cindex.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/cindex/cindex.go deleted file mode 100644 index 64b98b6fff..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/cindex/cindex.go +++ /dev/null @@ -1,189 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package cindex - -import ( - "encoding/binary" - "sync" - "sync/atomic" - - "go.etcd.io/etcd/server/v3/mvcc/backend" - "go.etcd.io/etcd/server/v3/mvcc/buckets" -) - -type Backend interface { - BatchTx() backend.BatchTx -} - -// ConsistentIndexer is an interface that wraps the Get/Set/Save method for consistentIndex. -type ConsistentIndexer interface { - - // ConsistentIndex returns the consistent index of current executing entry. - ConsistentIndex() uint64 - - // SetConsistentIndex set the consistent index of current executing entry. - SetConsistentIndex(v uint64, term uint64) - - // UnsafeSave must be called holding the lock on the tx. - // It saves consistentIndex to the underlying stable storage. - UnsafeSave(tx backend.BatchTx) - - // SetBackend set the available backend.BatchTx for ConsistentIndexer. - SetBackend(be Backend) -} - -// consistentIndex implements the ConsistentIndexer interface. -type consistentIndex struct { - // consistentIndex represents the offset of an entry in a consistent replica log. - // It caches the "consistent_index" key's value. - // Accessed through atomics so must be 64-bit aligned. - consistentIndex uint64 - // term represents the RAFT term of committed entry in a consistent replica log. - // Accessed through atomics so must be 64-bit aligned. - // The value is being persisted in the backend since v3.5. - term uint64 - - // be is used for initial read consistentIndex - be Backend - // mutex is protecting be. - mutex sync.Mutex -} - -// NewConsistentIndex creates a new consistent index. -// If `be` is nil, it must be set (SetBackend) before first access using `ConsistentIndex()`. -func NewConsistentIndex(be Backend) ConsistentIndexer { - return &consistentIndex{be: be} -} - -func (ci *consistentIndex) ConsistentIndex() uint64 { - if index := atomic.LoadUint64(&ci.consistentIndex); index > 0 { - return index - } - ci.mutex.Lock() - defer ci.mutex.Unlock() - - v, term := ReadConsistentIndex(ci.be.BatchTx()) - ci.SetConsistentIndex(v, term) - return v -} - -func (ci *consistentIndex) SetConsistentIndex(v uint64, term uint64) { - atomic.StoreUint64(&ci.consistentIndex, v) - atomic.StoreUint64(&ci.term, term) -} - -func (ci *consistentIndex) UnsafeSave(tx backend.BatchTx) { - index := atomic.LoadUint64(&ci.consistentIndex) - term := atomic.LoadUint64(&ci.term) - UnsafeUpdateConsistentIndex(tx, index, term, true) -} - -func (ci *consistentIndex) SetBackend(be Backend) { - ci.mutex.Lock() - defer ci.mutex.Unlock() - ci.be = be - // After the backend is changed, the first access should re-read it. - ci.SetConsistentIndex(0, 0) -} - -func NewFakeConsistentIndex(index uint64) ConsistentIndexer { - return &fakeConsistentIndex{index: index} -} - -type fakeConsistentIndex struct { - index uint64 - term uint64 -} - -func (f *fakeConsistentIndex) ConsistentIndex() uint64 { return f.index } - -func (f *fakeConsistentIndex) SetConsistentIndex(index uint64, term uint64) { - atomic.StoreUint64(&f.index, index) - atomic.StoreUint64(&f.term, term) -} - -func (f *fakeConsistentIndex) UnsafeSave(_ backend.BatchTx) {} -func (f *fakeConsistentIndex) SetBackend(_ Backend) {} - -// UnsafeCreateMetaBucket creates the `meta` bucket (if it does not exists yet). -func UnsafeCreateMetaBucket(tx backend.BatchTx) { - tx.UnsafeCreateBucket(buckets.Meta) -} - -// CreateMetaBucket creates the `meta` bucket (if it does not exists yet). -func CreateMetaBucket(tx backend.BatchTx) { - tx.Lock() - defer tx.Unlock() - tx.UnsafeCreateBucket(buckets.Meta) -} - -// unsafeGetConsistentIndex loads consistent index & term from given transaction. -// returns 0,0 if the data are not found. -// Term is persisted since v3.5. -func unsafeReadConsistentIndex(tx backend.ReadTx) (uint64, uint64) { - _, vs := tx.UnsafeRange(buckets.Meta, buckets.MetaConsistentIndexKeyName, nil, 0) - if len(vs) == 0 { - return 0, 0 - } - v := binary.BigEndian.Uint64(vs[0]) - _, ts := tx.UnsafeRange(buckets.Meta, buckets.MetaTermKeyName, nil, 0) - if len(ts) == 0 { - return v, 0 - } - t := binary.BigEndian.Uint64(ts[0]) - return v, t -} - -// ReadConsistentIndex loads consistent index and term from given transaction. -// returns 0 if the data are not found. -func ReadConsistentIndex(tx backend.ReadTx) (uint64, uint64) { - tx.Lock() - defer tx.Unlock() - return unsafeReadConsistentIndex(tx) -} - -func UnsafeUpdateConsistentIndex(tx backend.BatchTx, index uint64, term uint64, onlyGrow bool) { - if index == 0 { - // Never save 0 as it means that we didn't loaded the real index yet. - return - } - - if onlyGrow { - oldi, oldTerm := unsafeReadConsistentIndex(tx) - if term < oldTerm { - return - } - if term == oldTerm && index <= oldi { - return - } - } - - bs1 := make([]byte, 8) - binary.BigEndian.PutUint64(bs1, index) - // put the index into the underlying backend - // tx has been locked in TxnBegin, so there is no need to lock it again - tx.UnsafePut(buckets.Meta, buckets.MetaConsistentIndexKeyName, bs1) - if term > 0 { - bs2 := make([]byte, 8) - binary.BigEndian.PutUint64(bs2, term) - tx.UnsafePut(buckets.Meta, buckets.MetaTermKeyName, bs2) - } -} - -func UpdateConsistentIndex(tx backend.BatchTx, index uint64, term uint64, onlyGrow bool) { - tx.Lock() - defer tx.Unlock() - UnsafeUpdateConsistentIndex(tx, index, term, onlyGrow) -} diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/cindex/doc.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/cindex/doc.go deleted file mode 100644 index 7d3e4b774e..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/cindex/doc.go +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package cindex provides an interface and implementation for getting/saving consistentIndex. -package cindex diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/cluster_util.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/cluster_util.go deleted file mode 100644 index 595586e201..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/cluster_util.go +++ /dev/null @@ -1,482 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package etcdserver - -import ( - "context" - "encoding/json" - "fmt" - "io/ioutil" - "net/http" - "sort" - "strconv" - "strings" - "time" - - "go.etcd.io/etcd/api/v3/version" - "go.etcd.io/etcd/client/pkg/v3/types" - "go.etcd.io/etcd/server/v3/etcdserver/api/membership" - - "github.com/coreos/go-semver/semver" - "go.uber.org/zap" -) - -// isMemberBootstrapped tries to check if the given member has been bootstrapped -// in the given cluster. -func isMemberBootstrapped(lg *zap.Logger, cl *membership.RaftCluster, member string, rt http.RoundTripper, timeout time.Duration) bool { - rcl, err := getClusterFromRemotePeers(lg, getRemotePeerURLs(cl, member), timeout, false, rt) - if err != nil { - return false - } - id := cl.MemberByName(member).ID - m := rcl.Member(id) - if m == nil { - return false - } - if len(m.ClientURLs) > 0 { - return true - } - return false -} - -// GetClusterFromRemotePeers takes a set of URLs representing etcd peers, and -// attempts to construct a Cluster by accessing the members endpoint on one of -// these URLs. The first URL to provide a response is used. If no URLs provide -// a response, or a Cluster cannot be successfully created from a received -// response, an error is returned. -// Each request has a 10-second timeout. Because the upper limit of TTL is 5s, -// 10 second is enough for building connection and finishing request. -func GetClusterFromRemotePeers(lg *zap.Logger, urls []string, rt http.RoundTripper) (*membership.RaftCluster, error) { - return getClusterFromRemotePeers(lg, urls, 10*time.Second, true, rt) -} - -// If logerr is true, it prints out more error messages. -func getClusterFromRemotePeers(lg *zap.Logger, urls []string, timeout time.Duration, logerr bool, rt http.RoundTripper) (*membership.RaftCluster, error) { - if lg == nil { - lg = zap.NewNop() - } - cc := &http.Client{ - Transport: rt, - Timeout: timeout, - } - for _, u := range urls { - addr := u + "/members" - resp, err := cc.Get(addr) - if err != nil { - if logerr { - lg.Warn("failed to get cluster response", zap.String("address", addr), zap.Error(err)) - } - continue - } - b, err := ioutil.ReadAll(resp.Body) - resp.Body.Close() - if err != nil { - if logerr { - lg.Warn("failed to read body of cluster response", zap.String("address", addr), zap.Error(err)) - } - continue - } - var membs []*membership.Member - if err = json.Unmarshal(b, &membs); err != nil { - if logerr { - lg.Warn("failed to unmarshal cluster response", zap.String("address", addr), zap.Error(err)) - } - continue - } - id, err := types.IDFromString(resp.Header.Get("X-Etcd-Cluster-ID")) - if err != nil { - if logerr { - lg.Warn( - "failed to parse cluster ID", - zap.String("address", addr), - zap.String("header", resp.Header.Get("X-Etcd-Cluster-ID")), - zap.Error(err), - ) - } - continue - } - - // check the length of membership members - // if the membership members are present then prepare and return raft cluster - // if membership members are not present then the raft cluster formed will be - // an invalid empty cluster hence return failed to get raft cluster member(s) from the given urls error - if len(membs) > 0 { - return membership.NewClusterFromMembers(lg, id, membs), nil - } - return nil, fmt.Errorf("failed to get raft cluster member(s) from the given URLs") - } - return nil, fmt.Errorf("could not retrieve cluster information from the given URLs") -} - -// getRemotePeerURLs returns peer urls of remote members in the cluster. The -// returned list is sorted in ascending lexicographical order. -func getRemotePeerURLs(cl *membership.RaftCluster, local string) []string { - us := make([]string, 0) - for _, m := range cl.Members() { - if m.Name == local { - continue - } - us = append(us, m.PeerURLs...) - } - sort.Strings(us) - return us -} - -// getVersions returns the versions of the members in the given cluster. -// The key of the returned map is the member's ID. The value of the returned map -// is the semver versions string, including server and cluster. -// If it fails to get the version of a member, the key will be nil. -func getVersions(lg *zap.Logger, cl *membership.RaftCluster, local types.ID, rt http.RoundTripper) map[string]*version.Versions { - members := cl.Members() - vers := make(map[string]*version.Versions) - for _, m := range members { - if m.ID == local { - cv := "not_decided" - if cl.Version() != nil { - cv = cl.Version().String() - } - vers[m.ID.String()] = &version.Versions{Server: version.Version, Cluster: cv} - continue - } - ver, err := getVersion(lg, m, rt) - if err != nil { - lg.Warn("failed to get version", zap.String("remote-member-id", m.ID.String()), zap.Error(err)) - vers[m.ID.String()] = nil - } else { - vers[m.ID.String()] = ver - } - } - return vers -} - -// decideClusterVersion decides the cluster version based on the versions map. -// The returned version is the min server version in the map, or nil if the min -// version in unknown. -func decideClusterVersion(lg *zap.Logger, vers map[string]*version.Versions) *semver.Version { - var cv *semver.Version - lv := semver.Must(semver.NewVersion(version.Version)) - - for mid, ver := range vers { - if ver == nil { - return nil - } - v, err := semver.NewVersion(ver.Server) - if err != nil { - lg.Warn( - "failed to parse server version of remote member", - zap.String("remote-member-id", mid), - zap.String("remote-member-version", ver.Server), - zap.Error(err), - ) - return nil - } - if lv.LessThan(*v) { - lg.Warn( - "leader found higher-versioned member", - zap.String("local-member-version", lv.String()), - zap.String("remote-member-id", mid), - zap.String("remote-member-version", ver.Server), - ) - } - if cv == nil { - cv = v - } else if v.LessThan(*cv) { - cv = v - } - } - return cv -} - -// allowedVersionRange decides the available version range of the cluster that local server can join in; -// if the downgrade enabled status is true, the version window is [oneMinorHigher, oneMinorHigher] -// if the downgrade is not enabled, the version window is [MinClusterVersion, localVersion] -func allowedVersionRange(downgradeEnabled bool) (minV *semver.Version, maxV *semver.Version) { - minV = semver.Must(semver.NewVersion(version.MinClusterVersion)) - maxV = semver.Must(semver.NewVersion(version.Version)) - maxV = &semver.Version{Major: maxV.Major, Minor: maxV.Minor} - - if downgradeEnabled { - // Todo: handle the case that downgrading from higher major version(e.g. downgrade from v4.0 to v3.x) - maxV.Minor = maxV.Minor + 1 - minV = &semver.Version{Major: maxV.Major, Minor: maxV.Minor} - } - return minV, maxV -} - -// isCompatibleWithCluster return true if the local member has a compatible version with -// the current running cluster. -// The version is considered as compatible when at least one of the other members in the cluster has a -// cluster version in the range of [MinV, MaxV] and no known members has a cluster version -// out of the range. -// We set this rule since when the local member joins, another member might be offline. -func isCompatibleWithCluster(lg *zap.Logger, cl *membership.RaftCluster, local types.ID, rt http.RoundTripper) bool { - vers := getVersions(lg, cl, local, rt) - minV, maxV := allowedVersionRange(getDowngradeEnabledFromRemotePeers(lg, cl, local, rt)) - return isCompatibleWithVers(lg, vers, local, minV, maxV) -} - -func isCompatibleWithVers(lg *zap.Logger, vers map[string]*version.Versions, local types.ID, minV, maxV *semver.Version) bool { - var ok bool - for id, v := range vers { - // ignore comparison with local version - if id == local.String() { - continue - } - if v == nil { - continue - } - clusterv, err := semver.NewVersion(v.Cluster) - if err != nil { - lg.Warn( - "failed to parse cluster version of remote member", - zap.String("remote-member-id", id), - zap.String("remote-member-cluster-version", v.Cluster), - zap.Error(err), - ) - continue - } - if clusterv.LessThan(*minV) { - lg.Warn( - "cluster version of remote member is not compatible; too low", - zap.String("remote-member-id", id), - zap.String("remote-member-cluster-version", clusterv.String()), - zap.String("minimum-cluster-version-supported", minV.String()), - ) - return false - } - if maxV.LessThan(*clusterv) { - lg.Warn( - "cluster version of remote member is not compatible; too high", - zap.String("remote-member-id", id), - zap.String("remote-member-cluster-version", clusterv.String()), - zap.String("minimum-cluster-version-supported", minV.String()), - ) - return false - } - ok = true - } - return ok -} - -// getVersion returns the Versions of the given member via its -// peerURLs. Returns the last error if it fails to get the version. -func getVersion(lg *zap.Logger, m *membership.Member, rt http.RoundTripper) (*version.Versions, error) { - cc := &http.Client{ - Transport: rt, - } - var ( - err error - resp *http.Response - ) - - for _, u := range m.PeerURLs { - addr := u + "/version" - resp, err = cc.Get(addr) - if err != nil { - lg.Warn( - "failed to reach the peer URL", - zap.String("address", addr), - zap.String("remote-member-id", m.ID.String()), - zap.Error(err), - ) - continue - } - var b []byte - b, err = ioutil.ReadAll(resp.Body) - resp.Body.Close() - if err != nil { - lg.Warn( - "failed to read body of response", - zap.String("address", addr), - zap.String("remote-member-id", m.ID.String()), - zap.Error(err), - ) - continue - } - var vers version.Versions - if err = json.Unmarshal(b, &vers); err != nil { - lg.Warn( - "failed to unmarshal response", - zap.String("address", addr), - zap.String("remote-member-id", m.ID.String()), - zap.Error(err), - ) - continue - } - return &vers, nil - } - return nil, err -} - -func promoteMemberHTTP(ctx context.Context, url string, id uint64, peerRt http.RoundTripper) ([]*membership.Member, error) { - cc := &http.Client{Transport: peerRt} - // TODO: refactor member http handler code - // cannot import etcdhttp, so manually construct url - requestUrl := url + "/members/promote/" + fmt.Sprintf("%d", id) - req, err := http.NewRequest("POST", requestUrl, nil) - if err != nil { - return nil, err - } - req = req.WithContext(ctx) - resp, err := cc.Do(req) - if err != nil { - return nil, err - } - defer resp.Body.Close() - b, err := ioutil.ReadAll(resp.Body) - if err != nil { - return nil, err - } - - if resp.StatusCode == http.StatusRequestTimeout { - return nil, ErrTimeout - } - if resp.StatusCode == http.StatusPreconditionFailed { - // both ErrMemberNotLearner and ErrLearnerNotReady have same http status code - if strings.Contains(string(b), ErrLearnerNotReady.Error()) { - return nil, ErrLearnerNotReady - } - if strings.Contains(string(b), membership.ErrMemberNotLearner.Error()) { - return nil, membership.ErrMemberNotLearner - } - return nil, fmt.Errorf("member promote: unknown error(%s)", string(b)) - } - if resp.StatusCode == http.StatusNotFound { - return nil, membership.ErrIDNotFound - } - - if resp.StatusCode != http.StatusOK { // all other types of errors - return nil, fmt.Errorf("member promote: unknown error(%s)", string(b)) - } - - var membs []*membership.Member - if err := json.Unmarshal(b, &membs); err != nil { - return nil, err - } - return membs, nil -} - -// getDowngradeEnabledFromRemotePeers will get the downgrade enabled status of the cluster. -func getDowngradeEnabledFromRemotePeers(lg *zap.Logger, cl *membership.RaftCluster, local types.ID, rt http.RoundTripper) bool { - members := cl.Members() - - for _, m := range members { - if m.ID == local { - continue - } - enable, err := getDowngradeEnabled(lg, m, rt) - if err != nil { - lg.Warn("failed to get downgrade enabled status", zap.String("remote-member-id", m.ID.String()), zap.Error(err)) - } else { - // Since the "/downgrade/enabled" serves linearized data, - // this function can return once it gets a non-error response from the endpoint. - return enable - } - } - return false -} - -// getDowngradeEnabled returns the downgrade enabled status of the given member -// via its peerURLs. Returns the last error if it fails to get it. -func getDowngradeEnabled(lg *zap.Logger, m *membership.Member, rt http.RoundTripper) (bool, error) { - cc := &http.Client{ - Transport: rt, - } - var ( - err error - resp *http.Response - ) - - for _, u := range m.PeerURLs { - addr := u + DowngradeEnabledPath - resp, err = cc.Get(addr) - if err != nil { - lg.Warn( - "failed to reach the peer URL", - zap.String("address", addr), - zap.String("remote-member-id", m.ID.String()), - zap.Error(err), - ) - continue - } - var b []byte - b, err = ioutil.ReadAll(resp.Body) - resp.Body.Close() - if err != nil { - lg.Warn( - "failed to read body of response", - zap.String("address", addr), - zap.String("remote-member-id", m.ID.String()), - zap.Error(err), - ) - continue - } - var enable bool - if enable, err = strconv.ParseBool(string(b)); err != nil { - lg.Warn( - "failed to convert response", - zap.String("address", addr), - zap.String("remote-member-id", m.ID.String()), - zap.Error(err), - ) - continue - } - return enable, nil - } - return false, err -} - -// isMatchedVersions returns true if all server versions are equal to target version, otherwise return false. -// It can be used to decide the whether the cluster finishes downgrading to target version. -func isMatchedVersions(lg *zap.Logger, targetVersion *semver.Version, vers map[string]*version.Versions) bool { - for mid, ver := range vers { - if ver == nil { - return false - } - v, err := semver.NewVersion(ver.Cluster) - if err != nil { - lg.Warn( - "failed to parse server version of remote member", - zap.String("remote-member-id", mid), - zap.String("remote-member-version", ver.Server), - zap.Error(err), - ) - return false - } - if !targetVersion.Equal(*v) { - lg.Warn("remotes server has mismatching etcd version", - zap.String("remote-member-id", mid), - zap.String("current-server-version", v.String()), - zap.String("target-version", targetVersion.String()), - ) - return false - } - } - return true -} - -func convertToClusterVersion(v string) (*semver.Version, error) { - ver, err := semver.NewVersion(v) - if err != nil { - // allow input version format Major.Minor - ver, err = semver.NewVersion(v + ".0") - if err != nil { - return nil, ErrWrongDowngradeVersionFormat - } - } - // cluster version only keeps major.minor, remove patch version - ver = &semver.Version{Major: ver.Major, Minor: ver.Minor} - return ver, nil -} diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/corrupt.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/corrupt.go deleted file mode 100644 index 3a4bab6d5c..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/corrupt.go +++ /dev/null @@ -1,442 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package etcdserver - -import ( - "bytes" - "context" - "encoding/json" - "fmt" - "io/ioutil" - "net/http" - "strings" - "time" - - pb "go.etcd.io/etcd/api/v3/etcdserverpb" - "go.etcd.io/etcd/api/v3/v3rpc/rpctypes" - "go.etcd.io/etcd/client/pkg/v3/types" - "go.etcd.io/etcd/pkg/v3/traceutil" - "go.etcd.io/etcd/server/v3/mvcc" - - "go.uber.org/zap" -) - -// CheckInitialHashKV compares initial hash values with its peers -// before serving any peer/client traffic. Only mismatch when hashes -// are different at requested revision, with same compact revision. -func (s *EtcdServer) CheckInitialHashKV() error { - if !s.Cfg.InitialCorruptCheck { - return nil - } - - lg := s.Logger() - - lg.Info( - "starting initial corruption check", - zap.String("local-member-id", s.ID().String()), - zap.Duration("timeout", s.Cfg.ReqTimeout()), - ) - - h, rev, crev, err := s.kv.HashByRev(0) - if err != nil { - return fmt.Errorf("%s failed to fetch hash (%v)", s.ID(), err) - } - peers := s.getPeerHashKVs(rev) - mismatch := 0 - for _, p := range peers { - if p.resp != nil { - peerID := types.ID(p.resp.Header.MemberId) - fields := []zap.Field{ - zap.String("local-member-id", s.ID().String()), - zap.Int64("local-member-revision", rev), - zap.Int64("local-member-compact-revision", crev), - zap.Uint32("local-member-hash", h), - zap.String("remote-peer-id", peerID.String()), - zap.Strings("remote-peer-endpoints", p.eps), - zap.Int64("remote-peer-revision", p.resp.Header.Revision), - zap.Int64("remote-peer-compact-revision", p.resp.CompactRevision), - zap.Uint32("remote-peer-hash", p.resp.Hash), - } - - if h != p.resp.Hash { - if crev == p.resp.CompactRevision { - lg.Warn("found different hash values from remote peer", fields...) - mismatch++ - } else { - lg.Warn("found different compact revision values from remote peer", fields...) - } - } - - continue - } - - if p.err != nil { - switch p.err { - case rpctypes.ErrFutureRev: - lg.Warn( - "cannot fetch hash from slow remote peer", - zap.String("local-member-id", s.ID().String()), - zap.Int64("local-member-revision", rev), - zap.Int64("local-member-compact-revision", crev), - zap.Uint32("local-member-hash", h), - zap.String("remote-peer-id", p.id.String()), - zap.Strings("remote-peer-endpoints", p.eps), - zap.Error(err), - ) - case rpctypes.ErrCompacted: - lg.Warn( - "cannot fetch hash from remote peer; local member is behind", - zap.String("local-member-id", s.ID().String()), - zap.Int64("local-member-revision", rev), - zap.Int64("local-member-compact-revision", crev), - zap.Uint32("local-member-hash", h), - zap.String("remote-peer-id", p.id.String()), - zap.Strings("remote-peer-endpoints", p.eps), - zap.Error(err), - ) - } - } - } - if mismatch > 0 { - return fmt.Errorf("%s found data inconsistency with peers", s.ID()) - } - - lg.Info( - "initial corruption checking passed; no corruption", - zap.String("local-member-id", s.ID().String()), - ) - return nil -} - -func (s *EtcdServer) monitorKVHash() { - t := s.Cfg.CorruptCheckTime - if t == 0 { - return - } - - lg := s.Logger() - lg.Info( - "enabled corruption checking", - zap.String("local-member-id", s.ID().String()), - zap.Duration("interval", t), - ) - - for { - select { - case <-s.stopping: - return - case <-time.After(t): - } - if !s.isLeader() { - continue - } - if err := s.checkHashKV(); err != nil { - lg.Warn("failed to check hash KV", zap.Error(err)) - } - } -} - -func (s *EtcdServer) checkHashKV() error { - lg := s.Logger() - - h, rev, crev, err := s.kv.HashByRev(0) - if err != nil { - return err - } - peers := s.getPeerHashKVs(rev) - - ctx, cancel := context.WithTimeout(context.Background(), s.Cfg.ReqTimeout()) - err = s.linearizableReadNotify(ctx) - cancel() - if err != nil { - return err - } - - h2, rev2, crev2, err := s.kv.HashByRev(0) - if err != nil { - return err - } - - alarmed := false - mismatch := func(id uint64) { - if alarmed { - return - } - alarmed = true - a := &pb.AlarmRequest{ - MemberID: id, - Action: pb.AlarmRequest_ACTIVATE, - Alarm: pb.AlarmType_CORRUPT, - } - s.GoAttach(func() { - s.raftRequest(s.ctx, pb.InternalRaftRequest{Alarm: a}) - }) - } - - if h2 != h && rev2 == rev && crev == crev2 { - lg.Warn( - "found hash mismatch", - zap.Int64("revision-1", rev), - zap.Int64("compact-revision-1", crev), - zap.Uint32("hash-1", h), - zap.Int64("revision-2", rev2), - zap.Int64("compact-revision-2", crev2), - zap.Uint32("hash-2", h2), - ) - mismatch(uint64(s.ID())) - } - - checkedCount := 0 - for _, p := range peers { - if p.resp == nil { - continue - } - checkedCount++ - id := p.resp.Header.MemberId - - // leader expects follower's latest revision less than or equal to leader's - if p.resp.Header.Revision > rev2 { - lg.Warn( - "revision from follower must be less than or equal to leader's", - zap.Int64("leader-revision", rev2), - zap.Int64("follower-revision", p.resp.Header.Revision), - zap.String("follower-peer-id", types.ID(id).String()), - ) - mismatch(id) - } - - // leader expects follower's latest compact revision less than or equal to leader's - if p.resp.CompactRevision > crev2 { - lg.Warn( - "compact revision from follower must be less than or equal to leader's", - zap.Int64("leader-compact-revision", crev2), - zap.Int64("follower-compact-revision", p.resp.CompactRevision), - zap.String("follower-peer-id", types.ID(id).String()), - ) - mismatch(id) - } - - // follower's compact revision is leader's old one, then hashes must match - if p.resp.CompactRevision == crev && p.resp.Hash != h { - lg.Warn( - "same compact revision then hashes must match", - zap.Int64("leader-compact-revision", crev2), - zap.Uint32("leader-hash", h), - zap.Int64("follower-compact-revision", p.resp.CompactRevision), - zap.Uint32("follower-hash", p.resp.Hash), - zap.String("follower-peer-id", types.ID(id).String()), - ) - mismatch(id) - } - } - lg.Info("finished peer corruption check", zap.Int("number-of-peers-checked", checkedCount)) - return nil -} - -type peerInfo struct { - id types.ID - eps []string -} - -type peerHashKVResp struct { - peerInfo - resp *pb.HashKVResponse - err error -} - -func (s *EtcdServer) getPeerHashKVs(rev int64) []*peerHashKVResp { - // TODO: handle the case when "s.cluster.Members" have not - // been populated (e.g. no snapshot to load from disk) - members := s.cluster.Members() - peers := make([]peerInfo, 0, len(members)) - for _, m := range members { - if m.ID == s.ID() { - continue - } - peers = append(peers, peerInfo{id: m.ID, eps: m.PeerURLs}) - } - - lg := s.Logger() - - var resps []*peerHashKVResp - for _, p := range peers { - if len(p.eps) == 0 { - continue - } - - respsLen := len(resps) - var lastErr error - for _, ep := range p.eps { - ctx, cancel := context.WithTimeout(context.Background(), s.Cfg.ReqTimeout()) - resp, lastErr := s.getPeerHashKVHTTP(ctx, ep, rev) - cancel() - if lastErr == nil { - resps = append(resps, &peerHashKVResp{peerInfo: p, resp: resp, err: nil}) - break - } - lg.Warn( - "failed hash kv request", - zap.String("local-member-id", s.ID().String()), - zap.Int64("requested-revision", rev), - zap.String("remote-peer-endpoint", ep), - zap.Error(lastErr), - ) - } - - // failed to get hashKV from all endpoints of this peer - if respsLen == len(resps) { - resps = append(resps, &peerHashKVResp{peerInfo: p, resp: nil, err: lastErr}) - } - } - return resps -} - -type applierV3Corrupt struct { - applierV3 -} - -func newApplierV3Corrupt(a applierV3) *applierV3Corrupt { return &applierV3Corrupt{a} } - -func (a *applierV3Corrupt) Put(ctx context.Context, txn mvcc.TxnWrite, p *pb.PutRequest) (*pb.PutResponse, *traceutil.Trace, error) { - return nil, nil, ErrCorrupt -} - -func (a *applierV3Corrupt) Range(ctx context.Context, txn mvcc.TxnRead, p *pb.RangeRequest) (*pb.RangeResponse, error) { - return nil, ErrCorrupt -} - -func (a *applierV3Corrupt) DeleteRange(txn mvcc.TxnWrite, p *pb.DeleteRangeRequest) (*pb.DeleteRangeResponse, error) { - return nil, ErrCorrupt -} - -func (a *applierV3Corrupt) Txn(ctx context.Context, rt *pb.TxnRequest) (*pb.TxnResponse, *traceutil.Trace, error) { - return nil, nil, ErrCorrupt -} - -func (a *applierV3Corrupt) Compaction(compaction *pb.CompactionRequest) (*pb.CompactionResponse, <-chan struct{}, *traceutil.Trace, error) { - return nil, nil, nil, ErrCorrupt -} - -func (a *applierV3Corrupt) LeaseGrant(lc *pb.LeaseGrantRequest) (*pb.LeaseGrantResponse, error) { - return nil, ErrCorrupt -} - -func (a *applierV3Corrupt) LeaseRevoke(lc *pb.LeaseRevokeRequest) (*pb.LeaseRevokeResponse, error) { - return nil, ErrCorrupt -} - -const PeerHashKVPath = "/members/hashkv" - -type hashKVHandler struct { - lg *zap.Logger - server *EtcdServer -} - -func (s *EtcdServer) HashKVHandler() http.Handler { - return &hashKVHandler{lg: s.Logger(), server: s} -} - -func (h *hashKVHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { - if r.Method != http.MethodGet { - w.Header().Set("Allow", http.MethodGet) - http.Error(w, "Method Not Allowed", http.StatusMethodNotAllowed) - return - } - if r.URL.Path != PeerHashKVPath { - http.Error(w, "bad path", http.StatusBadRequest) - return - } - - defer r.Body.Close() - b, err := ioutil.ReadAll(r.Body) - if err != nil { - http.Error(w, "error reading body", http.StatusBadRequest) - return - } - - req := &pb.HashKVRequest{} - if err := json.Unmarshal(b, req); err != nil { - h.lg.Warn("failed to unmarshal request", zap.Error(err)) - http.Error(w, "error unmarshalling request", http.StatusBadRequest) - return - } - hash, rev, compactRev, err := h.server.KV().HashByRev(req.Revision) - if err != nil { - h.lg.Warn( - "failed to get hashKV", - zap.Int64("requested-revision", req.Revision), - zap.Error(err), - ) - http.Error(w, err.Error(), http.StatusBadRequest) - return - } - resp := &pb.HashKVResponse{Header: &pb.ResponseHeader{Revision: rev}, Hash: hash, CompactRevision: compactRev} - respBytes, err := json.Marshal(resp) - if err != nil { - h.lg.Warn("failed to marshal hashKV response", zap.Error(err)) - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - - w.Header().Set("X-Etcd-Cluster-ID", h.server.Cluster().ID().String()) - w.Header().Set("Content-Type", "application/json") - w.Write(respBytes) -} - -// getPeerHashKVHTTP fetch hash of kv store at the given rev via http call to the given url -func (s *EtcdServer) getPeerHashKVHTTP(ctx context.Context, url string, rev int64) (*pb.HashKVResponse, error) { - cc := &http.Client{Transport: s.peerRt} - hashReq := &pb.HashKVRequest{Revision: rev} - hashReqBytes, err := json.Marshal(hashReq) - if err != nil { - return nil, err - } - requestUrl := url + PeerHashKVPath - req, err := http.NewRequest(http.MethodGet, requestUrl, bytes.NewReader(hashReqBytes)) - if err != nil { - return nil, err - } - req = req.WithContext(ctx) - req.Header.Set("Content-Type", "application/json") - req.Cancel = ctx.Done() - - resp, err := cc.Do(req) - if err != nil { - return nil, err - } - defer resp.Body.Close() - b, err := ioutil.ReadAll(resp.Body) - if err != nil { - return nil, err - } - - if resp.StatusCode == http.StatusBadRequest { - if strings.Contains(string(b), mvcc.ErrCompacted.Error()) { - return nil, rpctypes.ErrCompacted - } - if strings.Contains(string(b), mvcc.ErrFutureRev.Error()) { - return nil, rpctypes.ErrFutureRev - } - } - if resp.StatusCode != http.StatusOK { - return nil, fmt.Errorf("unknown error: %s", string(b)) - } - - hashResp := &pb.HashKVResponse{} - if err := json.Unmarshal(b, hashResp); err != nil { - return nil, err - } - return hashResp, nil -} diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/doc.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/doc.go deleted file mode 100644 index b195d2d167..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/doc.go +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package etcdserver defines how etcd servers interact and store their states. -package etcdserver diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/errors.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/errors.go deleted file mode 100644 index dc2a85fdd4..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/errors.go +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package etcdserver - -import ( - "errors" - "fmt" -) - -var ( - ErrUnknownMethod = errors.New("etcdserver: unknown method") - ErrStopped = errors.New("etcdserver: server stopped") - ErrCanceled = errors.New("etcdserver: request cancelled") - ErrTimeout = errors.New("etcdserver: request timed out") - ErrTimeoutDueToLeaderFail = errors.New("etcdserver: request timed out, possibly due to previous leader failure") - ErrTimeoutDueToConnectionLost = errors.New("etcdserver: request timed out, possibly due to connection lost") - ErrTimeoutLeaderTransfer = errors.New("etcdserver: request timed out, leader transfer took too long") - ErrLeaderChanged = errors.New("etcdserver: leader changed") - ErrNotEnoughStartedMembers = errors.New("etcdserver: re-configuration failed due to not enough started members") - ErrLearnerNotReady = errors.New("etcdserver: can only promote a learner member which is in sync with leader") - ErrNoLeader = errors.New("etcdserver: no leader") - ErrNotLeader = errors.New("etcdserver: not leader") - ErrRequestTooLarge = errors.New("etcdserver: request is too large") - ErrNoSpace = errors.New("etcdserver: no space") - ErrTooManyRequests = errors.New("etcdserver: too many requests") - ErrUnhealthy = errors.New("etcdserver: unhealthy cluster") - ErrKeyNotFound = errors.New("etcdserver: key not found") - ErrCorrupt = errors.New("etcdserver: corrupt cluster") - ErrBadLeaderTransferee = errors.New("etcdserver: bad leader transferee") - ErrClusterVersionUnavailable = errors.New("etcdserver: cluster version not found during downgrade") - ErrWrongDowngradeVersionFormat = errors.New("etcdserver: wrong downgrade target version format") - ErrInvalidDowngradeTargetVersion = errors.New("etcdserver: invalid downgrade target version") - ErrDowngradeInProcess = errors.New("etcdserver: cluster has a downgrade job in progress") - ErrNoInflightDowngrade = errors.New("etcdserver: no inflight downgrade job") -) - -type DiscoveryError struct { - Op string - Err error -} - -func (e DiscoveryError) Error() string { - return fmt.Sprintf("failed to %s discovery cluster (%v)", e.Op, e.Err) -} diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/metrics.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/metrics.go deleted file mode 100644 index 06263a9cd2..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/metrics.go +++ /dev/null @@ -1,243 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package etcdserver - -import ( - goruntime "runtime" - "time" - - "go.etcd.io/etcd/api/v3/version" - "go.etcd.io/etcd/pkg/v3/runtime" - - "github.com/prometheus/client_golang/prometheus" - "go.uber.org/zap" -) - -var ( - hasLeader = prometheus.NewGauge(prometheus.GaugeOpts{ - Namespace: "etcd", - Subsystem: "server", - Name: "has_leader", - Help: "Whether or not a leader exists. 1 is existence, 0 is not.", - }) - isLeader = prometheus.NewGauge(prometheus.GaugeOpts{ - Namespace: "etcd", - Subsystem: "server", - Name: "is_leader", - Help: "Whether or not this member is a leader. 1 if is, 0 otherwise.", - }) - leaderChanges = prometheus.NewCounter(prometheus.CounterOpts{ - Namespace: "etcd", - Subsystem: "server", - Name: "leader_changes_seen_total", - Help: "The number of leader changes seen.", - }) - isLearner = prometheus.NewGauge(prometheus.GaugeOpts{ - Namespace: "etcd", - Subsystem: "server", - Name: "is_learner", - Help: "Whether or not this member is a learner. 1 if is, 0 otherwise.", - }) - learnerPromoteFailed = prometheus.NewCounterVec(prometheus.CounterOpts{ - Namespace: "etcd", - Subsystem: "server", - Name: "learner_promote_failures", - Help: "The total number of failed learner promotions (likely learner not ready) while this member is leader.", - }, - []string{"Reason"}, - ) - learnerPromoteSucceed = prometheus.NewCounter(prometheus.CounterOpts{ - Namespace: "etcd", - Subsystem: "server", - Name: "learner_promote_successes", - Help: "The total number of successful learner promotions while this member is leader.", - }) - heartbeatSendFailures = prometheus.NewCounter(prometheus.CounterOpts{ - Namespace: "etcd", - Subsystem: "server", - Name: "heartbeat_send_failures_total", - Help: "The total number of leader heartbeat send failures (likely overloaded from slow disk).", - }) - slowApplies = prometheus.NewCounter(prometheus.CounterOpts{ - Namespace: "etcd", - Subsystem: "server", - Name: "slow_apply_total", - Help: "The total number of slow apply requests (likely overloaded from slow disk).", - }) - applySnapshotInProgress = prometheus.NewGauge(prometheus.GaugeOpts{ - Namespace: "etcd", - Subsystem: "server", - Name: "snapshot_apply_in_progress_total", - Help: "1 if the server is applying the incoming snapshot. 0 if none.", - }) - proposalsCommitted = prometheus.NewGauge(prometheus.GaugeOpts{ - Namespace: "etcd", - Subsystem: "server", - Name: "proposals_committed_total", - Help: "The total number of consensus proposals committed.", - }) - proposalsApplied = prometheus.NewGauge(prometheus.GaugeOpts{ - Namespace: "etcd", - Subsystem: "server", - Name: "proposals_applied_total", - Help: "The total number of consensus proposals applied.", - }) - proposalsPending = prometheus.NewGauge(prometheus.GaugeOpts{ - Namespace: "etcd", - Subsystem: "server", - Name: "proposals_pending", - Help: "The current number of pending proposals to commit.", - }) - proposalsFailed = prometheus.NewCounter(prometheus.CounterOpts{ - Namespace: "etcd", - Subsystem: "server", - Name: "proposals_failed_total", - Help: "The total number of failed proposals seen.", - }) - slowReadIndex = prometheus.NewCounter(prometheus.CounterOpts{ - Namespace: "etcd", - Subsystem: "server", - Name: "slow_read_indexes_total", - Help: "The total number of pending read indexes not in sync with leader's or timed out read index requests.", - }) - readIndexFailed = prometheus.NewCounter(prometheus.CounterOpts{ - Namespace: "etcd", - Subsystem: "server", - Name: "read_indexes_failed_total", - Help: "The total number of failed read indexes seen.", - }) - leaseExpired = prometheus.NewCounter(prometheus.CounterOpts{ - Namespace: "etcd_debugging", - Subsystem: "server", - Name: "lease_expired_total", - Help: "The total number of expired leases.", - }) - quotaBackendBytes = prometheus.NewGauge(prometheus.GaugeOpts{ - Namespace: "etcd", - Subsystem: "server", - Name: "quota_backend_bytes", - Help: "Current backend storage quota size in bytes.", - }) - currentVersion = prometheus.NewGaugeVec(prometheus.GaugeOpts{ - Namespace: "etcd", - Subsystem: "server", - Name: "version", - Help: "Which version is running. 1 for 'server_version' label with current version.", - }, - []string{"server_version"}) - currentGoVersion = prometheus.NewGaugeVec(prometheus.GaugeOpts{ - Namespace: "etcd", - Subsystem: "server", - Name: "go_version", - Help: "Which Go version server is running with. 1 for 'server_go_version' label with current version.", - }, - []string{"server_go_version"}) - serverID = prometheus.NewGaugeVec(prometheus.GaugeOpts{ - Namespace: "etcd", - Subsystem: "server", - Name: "id", - Help: "Server or member ID in hexadecimal format. 1 for 'server_id' label with current ID.", - }, - []string{"server_id"}) - - fdUsed = prometheus.NewGauge(prometheus.GaugeOpts{ - Namespace: "os", - Subsystem: "fd", - Name: "used", - Help: "The number of used file descriptors.", - }) - fdLimit = prometheus.NewGauge(prometheus.GaugeOpts{ - Namespace: "os", - Subsystem: "fd", - Name: "limit", - Help: "The file descriptor limit.", - }) - applySec = prometheus.NewHistogramVec(prometheus.HistogramOpts{ - Namespace: "etcd", - Subsystem: "server", - Name: "apply_duration_seconds", - Help: "The latency distributions of v2 apply called by backend.", - - // lowest bucket start of upper bound 0.0001 sec (0.1 ms) with factor 2 - // highest bucket start of 0.0001 sec * 2^19 == 52.4288 sec - Buckets: prometheus.ExponentialBuckets(0.0001, 2, 20), - }, - []string{"version", "op", "success"}) -) - -func init() { - prometheus.MustRegister(hasLeader) - prometheus.MustRegister(isLeader) - prometheus.MustRegister(leaderChanges) - prometheus.MustRegister(heartbeatSendFailures) - prometheus.MustRegister(slowApplies) - prometheus.MustRegister(applySnapshotInProgress) - prometheus.MustRegister(proposalsCommitted) - prometheus.MustRegister(proposalsApplied) - prometheus.MustRegister(proposalsPending) - prometheus.MustRegister(proposalsFailed) - prometheus.MustRegister(slowReadIndex) - prometheus.MustRegister(readIndexFailed) - prometheus.MustRegister(leaseExpired) - prometheus.MustRegister(quotaBackendBytes) - prometheus.MustRegister(currentVersion) - prometheus.MustRegister(currentGoVersion) - prometheus.MustRegister(serverID) - prometheus.MustRegister(isLearner) - prometheus.MustRegister(learnerPromoteSucceed) - prometheus.MustRegister(learnerPromoteFailed) - prometheus.MustRegister(fdUsed) - prometheus.MustRegister(fdLimit) - prometheus.MustRegister(applySec) - - currentVersion.With(prometheus.Labels{ - "server_version": version.Version, - }).Set(1) - currentGoVersion.With(prometheus.Labels{ - "server_go_version": goruntime.Version(), - }).Set(1) -} - -func monitorFileDescriptor(lg *zap.Logger, done <-chan struct{}) { - // This ticker will check File Descriptor Requirements ,and count all fds in used. - // And recorded some logs when in used >= limit/5*4. Just recorded message. - // If fds was more than 10K,It's low performance due to FDUsage() works. - // So need to increase it. - // See https://github.com/etcd-io/etcd/issues/11969 for more detail. - ticker := time.NewTicker(10 * time.Minute) - defer ticker.Stop() - for { - used, err := runtime.FDUsage() - if err != nil { - lg.Warn("failed to get file descriptor usage", zap.Error(err)) - return - } - fdUsed.Set(float64(used)) - limit, err := runtime.FDLimit() - if err != nil { - lg.Warn("failed to get file descriptor limit", zap.Error(err)) - return - } - fdLimit.Set(float64(limit)) - if used >= limit/5*4 { - lg.Warn("80% of file descriptors are used", zap.Uint64("used", used), zap.Uint64("limit", limit)) - } - select { - case <-ticker.C: - case <-done: - return - } - } -} diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/quota.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/quota.go deleted file mode 100644 index 33c06e6190..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/quota.go +++ /dev/null @@ -1,172 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package etcdserver - -import ( - "sync" - - pb "go.etcd.io/etcd/api/v3/etcdserverpb" - - humanize "github.com/dustin/go-humanize" - "go.uber.org/zap" -) - -const ( - // DefaultQuotaBytes is the number of bytes the backend Size may - // consume before exceeding the space quota. - DefaultQuotaBytes = int64(2 * 1024 * 1024 * 1024) // 2GB - // MaxQuotaBytes is the maximum number of bytes suggested for a backend - // quota. A larger quota may lead to degraded performance. - MaxQuotaBytes = int64(8 * 1024 * 1024 * 1024) // 8GB -) - -// Quota represents an arbitrary quota against arbitrary requests. Each request -// costs some charge; if there is not enough remaining charge, then there are -// too few resources available within the quota to apply the request. -type Quota interface { - // Available judges whether the given request fits within the quota. - Available(req interface{}) bool - // Cost computes the charge against the quota for a given request. - Cost(req interface{}) int - // Remaining is the amount of charge left for the quota. - Remaining() int64 -} - -type passthroughQuota struct{} - -func (*passthroughQuota) Available(interface{}) bool { return true } -func (*passthroughQuota) Cost(interface{}) int { return 0 } -func (*passthroughQuota) Remaining() int64 { return 1 } - -type backendQuota struct { - s *EtcdServer - maxBackendBytes int64 -} - -const ( - // leaseOverhead is an estimate for the cost of storing a lease - leaseOverhead = 64 - // kvOverhead is an estimate for the cost of storing a key's metadata - kvOverhead = 256 -) - -var ( - // only log once - quotaLogOnce sync.Once - - DefaultQuotaSize = humanize.Bytes(uint64(DefaultQuotaBytes)) - maxQuotaSize = humanize.Bytes(uint64(MaxQuotaBytes)) -) - -// NewBackendQuota creates a quota layer with the given storage limit. -func NewBackendQuota(s *EtcdServer, name string) Quota { - lg := s.Logger() - quotaBackendBytes.Set(float64(s.Cfg.QuotaBackendBytes)) - - if s.Cfg.QuotaBackendBytes < 0 { - // disable quotas if negative - quotaLogOnce.Do(func() { - lg.Info( - "disabled backend quota", - zap.String("quota-name", name), - zap.Int64("quota-size-bytes", s.Cfg.QuotaBackendBytes), - ) - }) - return &passthroughQuota{} - } - - if s.Cfg.QuotaBackendBytes == 0 { - // use default size if no quota size given - quotaLogOnce.Do(func() { - if lg != nil { - lg.Info( - "enabled backend quota with default value", - zap.String("quota-name", name), - zap.Int64("quota-size-bytes", DefaultQuotaBytes), - zap.String("quota-size", DefaultQuotaSize), - ) - } - }) - quotaBackendBytes.Set(float64(DefaultQuotaBytes)) - return &backendQuota{s, DefaultQuotaBytes} - } - - quotaLogOnce.Do(func() { - if s.Cfg.QuotaBackendBytes > MaxQuotaBytes { - lg.Warn( - "quota exceeds the maximum value", - zap.String("quota-name", name), - zap.Int64("quota-size-bytes", s.Cfg.QuotaBackendBytes), - zap.String("quota-size", humanize.Bytes(uint64(s.Cfg.QuotaBackendBytes))), - zap.Int64("quota-maximum-size-bytes", MaxQuotaBytes), - zap.String("quota-maximum-size", maxQuotaSize), - ) - } - lg.Info( - "enabled backend quota", - zap.String("quota-name", name), - zap.Int64("quota-size-bytes", s.Cfg.QuotaBackendBytes), - zap.String("quota-size", humanize.Bytes(uint64(s.Cfg.QuotaBackendBytes))), - ) - }) - return &backendQuota{s, s.Cfg.QuotaBackendBytes} -} - -func (b *backendQuota) Available(v interface{}) bool { - // TODO: maybe optimize backend.Size() - return b.s.Backend().Size()+int64(b.Cost(v)) < b.maxBackendBytes -} - -func (b *backendQuota) Cost(v interface{}) int { - switch r := v.(type) { - case *pb.PutRequest: - return costPut(r) - case *pb.TxnRequest: - return costTxn(r) - case *pb.LeaseGrantRequest: - return leaseOverhead - default: - panic("unexpected cost") - } -} - -func costPut(r *pb.PutRequest) int { return kvOverhead + len(r.Key) + len(r.Value) } - -func costTxnReq(u *pb.RequestOp) int { - r := u.GetRequestPut() - if r == nil { - return 0 - } - return costPut(r) -} - -func costTxn(r *pb.TxnRequest) int { - sizeSuccess := 0 - for _, u := range r.Success { - sizeSuccess += costTxnReq(u) - } - sizeFailure := 0 - for _, u := range r.Failure { - sizeFailure += costTxnReq(u) - } - if sizeFailure > sizeSuccess { - return sizeFailure - } - return sizeSuccess -} - -func (b *backendQuota) Remaining() int64 { - return b.maxBackendBytes - b.s.Backend().Size() -} diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/raft.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/raft.go deleted file mode 100644 index 8b9600d39c..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/raft.go +++ /dev/null @@ -1,689 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package etcdserver - -import ( - "encoding/json" - "expvar" - "fmt" - "log" - "sort" - "sync" - "time" - - pb "go.etcd.io/etcd/api/v3/etcdserverpb" - "go.etcd.io/etcd/client/pkg/v3/logutil" - "go.etcd.io/etcd/client/pkg/v3/types" - "go.etcd.io/etcd/pkg/v3/contention" - "go.etcd.io/etcd/pkg/v3/pbutil" - "go.etcd.io/etcd/raft/v3" - "go.etcd.io/etcd/raft/v3/raftpb" - "go.etcd.io/etcd/server/v3/config" - "go.etcd.io/etcd/server/v3/etcdserver/api/membership" - "go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp" - "go.etcd.io/etcd/server/v3/wal" - "go.etcd.io/etcd/server/v3/wal/walpb" - "go.uber.org/zap" -) - -const ( - // The max throughput of etcd will not exceed 100MB/s (100K * 1KB value). - // Assuming the RTT is around 10ms, 1MB max size is large enough. - maxSizePerMsg = 1 * 1024 * 1024 - // Never overflow the rafthttp buffer, which is 4096. - // TODO: a better const? - maxInflightMsgs = 4096 / 8 -) - -var ( - // protects raftStatus - raftStatusMu sync.Mutex - // indirection for expvar func interface - // expvar panics when publishing duplicate name - // expvar does not support remove a registered name - // so only register a func that calls raftStatus - // and change raftStatus as we need. - raftStatus func() raft.Status -) - -func init() { - expvar.Publish("raft.status", expvar.Func(func() interface{} { - raftStatusMu.Lock() - defer raftStatusMu.Unlock() - if raftStatus == nil { - return nil - } - return raftStatus() - })) -} - -// apply contains entries, snapshot to be applied. Once -// an apply is consumed, the entries will be persisted to -// to raft storage concurrently; the application must read -// raftDone before assuming the raft messages are stable. -type apply struct { - entries []raftpb.Entry - snapshot raftpb.Snapshot - // notifyc synchronizes etcd server applies with the raft node - notifyc chan struct{} -} - -type raftNode struct { - lg *zap.Logger - - tickMu *sync.Mutex - raftNodeConfig - - // a chan to send/receive snapshot - msgSnapC chan raftpb.Message - - // a chan to send out apply - applyc chan apply - - // a chan to send out readState - readStateC chan raft.ReadState - - // utility - ticker *time.Ticker - // contention detectors for raft heartbeat message - td *contention.TimeoutDetector - - stopped chan struct{} - done chan struct{} -} - -type raftNodeConfig struct { - lg *zap.Logger - - // to check if msg receiver is removed from cluster - isIDRemoved func(id uint64) bool - raft.Node - raftStorage *raft.MemoryStorage - storage Storage - heartbeat time.Duration // for logging - // transport specifies the transport to send and receive msgs to members. - // Sending messages MUST NOT block. It is okay to drop messages, since - // clients should timeout and reissue their messages. - // If transport is nil, server will panic. - transport rafthttp.Transporter -} - -func newRaftNode(cfg raftNodeConfig) *raftNode { - var lg raft.Logger - if cfg.lg != nil { - lg = NewRaftLoggerZap(cfg.lg) - } else { - lcfg := logutil.DefaultZapLoggerConfig - var err error - lg, err = NewRaftLogger(&lcfg) - if err != nil { - log.Fatalf("cannot create raft logger %v", err) - } - } - raft.SetLogger(lg) - r := &raftNode{ - lg: cfg.lg, - tickMu: new(sync.Mutex), - raftNodeConfig: cfg, - // set up contention detectors for raft heartbeat message. - // expect to send a heartbeat within 2 heartbeat intervals. - td: contention.NewTimeoutDetector(2 * cfg.heartbeat), - readStateC: make(chan raft.ReadState, 1), - msgSnapC: make(chan raftpb.Message, maxInFlightMsgSnap), - applyc: make(chan apply), - stopped: make(chan struct{}), - done: make(chan struct{}), - } - if r.heartbeat == 0 { - r.ticker = &time.Ticker{} - } else { - r.ticker = time.NewTicker(r.heartbeat) - } - return r -} - -// raft.Node does not have locks in Raft package -func (r *raftNode) tick() { - r.tickMu.Lock() - r.Tick() - r.tickMu.Unlock() -} - -// start prepares and starts raftNode in a new goroutine. It is no longer safe -// to modify the fields after it has been started. -func (r *raftNode) start(rh *raftReadyHandler) { - internalTimeout := time.Second - - go func() { - defer r.onStop() - islead := false - - for { - select { - case <-r.ticker.C: - r.tick() - case rd := <-r.Ready(): - if rd.SoftState != nil { - newLeader := rd.SoftState.Lead != raft.None && rh.getLead() != rd.SoftState.Lead - if newLeader { - leaderChanges.Inc() - } - - if rd.SoftState.Lead == raft.None { - hasLeader.Set(0) - } else { - hasLeader.Set(1) - } - - rh.updateLead(rd.SoftState.Lead) - islead = rd.RaftState == raft.StateLeader - if islead { - isLeader.Set(1) - } else { - isLeader.Set(0) - } - rh.updateLeadership(newLeader) - r.td.Reset() - } - - if len(rd.ReadStates) != 0 { - select { - case r.readStateC <- rd.ReadStates[len(rd.ReadStates)-1]: - case <-time.After(internalTimeout): - r.lg.Warn("timed out sending read state", zap.Duration("timeout", internalTimeout)) - case <-r.stopped: - return - } - } - - notifyc := make(chan struct{}, 1) - ap := apply{ - entries: rd.CommittedEntries, - snapshot: rd.Snapshot, - notifyc: notifyc, - } - - updateCommittedIndex(&ap, rh) - - select { - case r.applyc <- ap: - case <-r.stopped: - return - } - - // the leader can write to its disk in parallel with replicating to the followers and them - // writing to their disks. - // For more details, check raft thesis 10.2.1 - if islead { - // gofail: var raftBeforeLeaderSend struct{} - r.transport.Send(r.processMessages(rd.Messages)) - } - - // Must save the snapshot file and WAL snapshot entry before saving any other entries or hardstate to - // ensure that recovery after a snapshot restore is possible. - if !raft.IsEmptySnap(rd.Snapshot) { - // gofail: var raftBeforeSaveSnap struct{} - if err := r.storage.SaveSnap(rd.Snapshot); err != nil { - r.lg.Fatal("failed to save Raft snapshot", zap.Error(err)) - } - // gofail: var raftAfterSaveSnap struct{} - } - - // gofail: var raftBeforeSave struct{} - if err := r.storage.Save(rd.HardState, rd.Entries); err != nil { - r.lg.Fatal("failed to save Raft hard state and entries", zap.Error(err)) - } - if !raft.IsEmptyHardState(rd.HardState) { - proposalsCommitted.Set(float64(rd.HardState.Commit)) - } - // gofail: var raftAfterSave struct{} - - if !raft.IsEmptySnap(rd.Snapshot) { - // Force WAL to fsync its hard state before Release() releases - // old data from the WAL. Otherwise could get an error like: - // panic: tocommit(107) is out of range [lastIndex(84)]. Was the raft log corrupted, truncated, or lost? - // See https://github.com/etcd-io/etcd/issues/10219 for more details. - if err := r.storage.Sync(); err != nil { - r.lg.Fatal("failed to sync Raft snapshot", zap.Error(err)) - } - - // etcdserver now claim the snapshot has been persisted onto the disk - notifyc <- struct{}{} - - // gofail: var raftBeforeApplySnap struct{} - r.raftStorage.ApplySnapshot(rd.Snapshot) - r.lg.Info("applied incoming Raft snapshot", zap.Uint64("snapshot-index", rd.Snapshot.Metadata.Index)) - // gofail: var raftAfterApplySnap struct{} - - if err := r.storage.Release(rd.Snapshot); err != nil { - r.lg.Fatal("failed to release Raft wal", zap.Error(err)) - } - // gofail: var raftAfterWALRelease struct{} - } - - r.raftStorage.Append(rd.Entries) - - if !islead { - // finish processing incoming messages before we signal raftdone chan - msgs := r.processMessages(rd.Messages) - - // now unblocks 'applyAll' that waits on Raft log disk writes before triggering snapshots - notifyc <- struct{}{} - - // Candidate or follower needs to wait for all pending configuration - // changes to be applied before sending messages. - // Otherwise we might incorrectly count votes (e.g. votes from removed members). - // Also slow machine's follower raft-layer could proceed to become the leader - // on its own single-node cluster, before apply-layer applies the config change. - // We simply wait for ALL pending entries to be applied for now. - // We might improve this later on if it causes unnecessary long blocking issues. - waitApply := false - for _, ent := range rd.CommittedEntries { - if ent.Type == raftpb.EntryConfChange { - waitApply = true - break - } - } - if waitApply { - // blocks until 'applyAll' calls 'applyWait.Trigger' - // to be in sync with scheduled config-change job - // (assume notifyc has cap of 1) - select { - case notifyc <- struct{}{}: - case <-r.stopped: - return - } - } - - // gofail: var raftBeforeFollowerSend struct{} - r.transport.Send(msgs) - } else { - // leader already processed 'MsgSnap' and signaled - notifyc <- struct{}{} - } - - r.Advance() - case <-r.stopped: - return - } - } - }() -} - -func updateCommittedIndex(ap *apply, rh *raftReadyHandler) { - var ci uint64 - if len(ap.entries) != 0 { - ci = ap.entries[len(ap.entries)-1].Index - } - if ap.snapshot.Metadata.Index > ci { - ci = ap.snapshot.Metadata.Index - } - if ci != 0 { - rh.updateCommittedIndex(ci) - } -} - -func (r *raftNode) processMessages(ms []raftpb.Message) []raftpb.Message { - sentAppResp := false - for i := len(ms) - 1; i >= 0; i-- { - if r.isIDRemoved(ms[i].To) { - ms[i].To = 0 - } - - if ms[i].Type == raftpb.MsgAppResp { - if sentAppResp { - ms[i].To = 0 - } else { - sentAppResp = true - } - } - - if ms[i].Type == raftpb.MsgSnap { - // There are two separate data store: the store for v2, and the KV for v3. - // The msgSnap only contains the most recent snapshot of store without KV. - // So we need to redirect the msgSnap to etcd server main loop for merging in the - // current store snapshot and KV snapshot. - select { - case r.msgSnapC <- ms[i]: - default: - // drop msgSnap if the inflight chan if full. - } - ms[i].To = 0 - } - if ms[i].Type == raftpb.MsgHeartbeat { - ok, exceed := r.td.Observe(ms[i].To) - if !ok { - // TODO: limit request rate. - r.lg.Warn( - "leader failed to send out heartbeat on time; took too long, leader is overloaded likely from slow disk", - zap.String("to", fmt.Sprintf("%x", ms[i].To)), - zap.Duration("heartbeat-interval", r.heartbeat), - zap.Duration("expected-duration", 2*r.heartbeat), - zap.Duration("exceeded-duration", exceed), - ) - heartbeatSendFailures.Inc() - } - } - } - return ms -} - -func (r *raftNode) apply() chan apply { - return r.applyc -} - -func (r *raftNode) stop() { - r.stopped <- struct{}{} - <-r.done -} - -func (r *raftNode) onStop() { - r.Stop() - r.ticker.Stop() - r.transport.Stop() - if err := r.storage.Close(); err != nil { - r.lg.Panic("failed to close Raft storage", zap.Error(err)) - } - close(r.done) -} - -// for testing -func (r *raftNode) pauseSending() { - p := r.transport.(rafthttp.Pausable) - p.Pause() -} - -func (r *raftNode) resumeSending() { - p := r.transport.(rafthttp.Pausable) - p.Resume() -} - -// advanceTicks advances ticks of Raft node. -// This can be used for fast-forwarding election -// ticks in multi data-center deployments, thus -// speeding up election process. -func (r *raftNode) advanceTicks(ticks int) { - for i := 0; i < ticks; i++ { - r.tick() - } -} - -func startNode(cfg config.ServerConfig, cl *membership.RaftCluster, ids []types.ID) (id types.ID, n raft.Node, s *raft.MemoryStorage, w *wal.WAL) { - var err error - member := cl.MemberByName(cfg.Name) - metadata := pbutil.MustMarshal( - &pb.Metadata{ - NodeID: uint64(member.ID), - ClusterID: uint64(cl.ID()), - }, - ) - if w, err = wal.Create(cfg.Logger, cfg.WALDir(), metadata); err != nil { - cfg.Logger.Panic("failed to create WAL", zap.Error(err)) - } - if cfg.UnsafeNoFsync { - w.SetUnsafeNoFsync() - } - peers := make([]raft.Peer, len(ids)) - for i, id := range ids { - var ctx []byte - ctx, err = json.Marshal((*cl).Member(id)) - if err != nil { - cfg.Logger.Panic("failed to marshal member", zap.Error(err)) - } - peers[i] = raft.Peer{ID: uint64(id), Context: ctx} - } - id = member.ID - cfg.Logger.Info( - "starting local member", - zap.String("local-member-id", id.String()), - zap.String("cluster-id", cl.ID().String()), - ) - s = raft.NewMemoryStorage() - c := &raft.Config{ - ID: uint64(id), - ElectionTick: cfg.ElectionTicks, - HeartbeatTick: 1, - Storage: s, - MaxSizePerMsg: maxSizePerMsg, - MaxInflightMsgs: maxInflightMsgs, - CheckQuorum: true, - PreVote: cfg.PreVote, - Logger: NewRaftLoggerZap(cfg.Logger.Named("raft")), - } - if len(peers) == 0 { - n = raft.RestartNode(c) - } else { - n = raft.StartNode(c, peers) - } - raftStatusMu.Lock() - raftStatus = n.Status - raftStatusMu.Unlock() - return id, n, s, w -} - -func restartNode(cfg config.ServerConfig, snapshot *raftpb.Snapshot) (types.ID, *membership.RaftCluster, raft.Node, *raft.MemoryStorage, *wal.WAL) { - var walsnap walpb.Snapshot - if snapshot != nil { - walsnap.Index, walsnap.Term = snapshot.Metadata.Index, snapshot.Metadata.Term - } - w, id, cid, st, ents := readWAL(cfg.Logger, cfg.WALDir(), walsnap, cfg.UnsafeNoFsync) - - cfg.Logger.Info( - "restarting local member", - zap.String("cluster-id", cid.String()), - zap.String("local-member-id", id.String()), - zap.Uint64("commit-index", st.Commit), - ) - cl := membership.NewCluster(cfg.Logger) - cl.SetID(id, cid) - s := raft.NewMemoryStorage() - if snapshot != nil { - s.ApplySnapshot(*snapshot) - } - s.SetHardState(st) - s.Append(ents) - c := &raft.Config{ - ID: uint64(id), - ElectionTick: cfg.ElectionTicks, - HeartbeatTick: 1, - Storage: s, - MaxSizePerMsg: maxSizePerMsg, - MaxInflightMsgs: maxInflightMsgs, - CheckQuorum: true, - PreVote: cfg.PreVote, - Logger: NewRaftLoggerZap(cfg.Logger.Named("raft")), - } - - n := raft.RestartNode(c) - raftStatusMu.Lock() - raftStatus = n.Status - raftStatusMu.Unlock() - return id, cl, n, s, w -} - -func restartAsStandaloneNode(cfg config.ServerConfig, snapshot *raftpb.Snapshot) (types.ID, *membership.RaftCluster, raft.Node, *raft.MemoryStorage, *wal.WAL) { - var walsnap walpb.Snapshot - if snapshot != nil { - walsnap.Index, walsnap.Term = snapshot.Metadata.Index, snapshot.Metadata.Term - } - w, id, cid, st, ents := readWAL(cfg.Logger, cfg.WALDir(), walsnap, cfg.UnsafeNoFsync) - - // discard the previously uncommitted entries - for i, ent := range ents { - if ent.Index > st.Commit { - cfg.Logger.Info( - "discarding uncommitted WAL entries", - zap.Uint64("entry-index", ent.Index), - zap.Uint64("commit-index-from-wal", st.Commit), - zap.Int("number-of-discarded-entries", len(ents)-i), - ) - ents = ents[:i] - break - } - } - - // force append the configuration change entries - toAppEnts := createConfigChangeEnts( - cfg.Logger, - getIDs(cfg.Logger, snapshot, ents), - uint64(id), - st.Term, - st.Commit, - ) - ents = append(ents, toAppEnts...) - - // force commit newly appended entries - err := w.Save(raftpb.HardState{}, toAppEnts) - if err != nil { - cfg.Logger.Fatal("failed to save hard state and entries", zap.Error(err)) - } - if len(ents) != 0 { - st.Commit = ents[len(ents)-1].Index - } - - cfg.Logger.Info( - "forcing restart member", - zap.String("cluster-id", cid.String()), - zap.String("local-member-id", id.String()), - zap.Uint64("commit-index", st.Commit), - ) - - cl := membership.NewCluster(cfg.Logger) - cl.SetID(id, cid) - s := raft.NewMemoryStorage() - if snapshot != nil { - s.ApplySnapshot(*snapshot) - } - s.SetHardState(st) - s.Append(ents) - c := &raft.Config{ - ID: uint64(id), - ElectionTick: cfg.ElectionTicks, - HeartbeatTick: 1, - Storage: s, - MaxSizePerMsg: maxSizePerMsg, - MaxInflightMsgs: maxInflightMsgs, - CheckQuorum: true, - PreVote: cfg.PreVote, - Logger: NewRaftLoggerZap(cfg.Logger.Named("raft")), - } - - n := raft.RestartNode(c) - raftStatus = n.Status - return id, cl, n, s, w -} - -// getIDs returns an ordered set of IDs included in the given snapshot and -// the entries. The given snapshot/entries can contain three kinds of -// ID-related entry: -// - ConfChangeAddNode, in which case the contained ID will be added into the set. -// - ConfChangeRemoveNode, in which case the contained ID will be removed from the set. -// - ConfChangeAddLearnerNode, in which the contained ID will be added into the set. -func getIDs(lg *zap.Logger, snap *raftpb.Snapshot, ents []raftpb.Entry) []uint64 { - ids := make(map[uint64]bool) - if snap != nil { - for _, id := range snap.Metadata.ConfState.Voters { - ids[id] = true - } - } - for _, e := range ents { - if e.Type != raftpb.EntryConfChange { - continue - } - var cc raftpb.ConfChange - pbutil.MustUnmarshal(&cc, e.Data) - switch cc.Type { - case raftpb.ConfChangeAddLearnerNode: - ids[cc.NodeID] = true - case raftpb.ConfChangeAddNode: - ids[cc.NodeID] = true - case raftpb.ConfChangeRemoveNode: - delete(ids, cc.NodeID) - case raftpb.ConfChangeUpdateNode: - // do nothing - default: - lg.Panic("unknown ConfChange Type", zap.String("type", cc.Type.String())) - } - } - sids := make(types.Uint64Slice, 0, len(ids)) - for id := range ids { - sids = append(sids, id) - } - sort.Sort(sids) - return []uint64(sids) -} - -// createConfigChangeEnts creates a series of Raft entries (i.e. -// EntryConfChange) to remove the set of given IDs from the cluster. The ID -// `self` is _not_ removed, even if present in the set. -// If `self` is not inside the given ids, it creates a Raft entry to add a -// default member with the given `self`. -func createConfigChangeEnts(lg *zap.Logger, ids []uint64, self uint64, term, index uint64) []raftpb.Entry { - found := false - for _, id := range ids { - if id == self { - found = true - } - } - - var ents []raftpb.Entry - next := index + 1 - - // NB: always add self first, then remove other nodes. Raft will panic if the - // set of voters ever becomes empty. - if !found { - m := membership.Member{ - ID: types.ID(self), - RaftAttributes: membership.RaftAttributes{PeerURLs: []string{"http://localhost:2380"}}, - } - ctx, err := json.Marshal(m) - if err != nil { - lg.Panic("failed to marshal member", zap.Error(err)) - } - cc := &raftpb.ConfChange{ - Type: raftpb.ConfChangeAddNode, - NodeID: self, - Context: ctx, - } - e := raftpb.Entry{ - Type: raftpb.EntryConfChange, - Data: pbutil.MustMarshal(cc), - Term: term, - Index: next, - } - ents = append(ents, e) - next++ - } - - for _, id := range ids { - if id == self { - continue - } - cc := &raftpb.ConfChange{ - Type: raftpb.ConfChangeRemoveNode, - NodeID: id, - } - e := raftpb.Entry{ - Type: raftpb.EntryConfChange, - Data: pbutil.MustMarshal(cc), - Term: term, - Index: next, - } - ents = append(ents, e) - next++ - } - - return ents -} diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/server.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/server.go deleted file mode 100644 index 56e288cc5f..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/server.go +++ /dev/null @@ -1,2699 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package etcdserver - -import ( - "context" - "encoding/json" - "expvar" - "fmt" - "math" - "math/rand" - "net/http" - "os" - "path" - "regexp" - "strconv" - "strings" - "sync" - "sync/atomic" - "time" - - "github.com/coreos/go-semver/semver" - humanize "github.com/dustin/go-humanize" - "github.com/prometheus/client_golang/prometheus" - "go.etcd.io/etcd/server/v3/config" - "go.uber.org/zap" - - pb "go.etcd.io/etcd/api/v3/etcdserverpb" - "go.etcd.io/etcd/api/v3/membershippb" - "go.etcd.io/etcd/api/v3/version" - "go.etcd.io/etcd/client/pkg/v3/fileutil" - "go.etcd.io/etcd/client/pkg/v3/types" - "go.etcd.io/etcd/pkg/v3/idutil" - "go.etcd.io/etcd/pkg/v3/pbutil" - "go.etcd.io/etcd/pkg/v3/runtime" - "go.etcd.io/etcd/pkg/v3/schedule" - "go.etcd.io/etcd/pkg/v3/traceutil" - "go.etcd.io/etcd/pkg/v3/wait" - "go.etcd.io/etcd/raft/v3" - "go.etcd.io/etcd/raft/v3/raftpb" - "go.etcd.io/etcd/server/v3/auth" - "go.etcd.io/etcd/server/v3/etcdserver/api" - "go.etcd.io/etcd/server/v3/etcdserver/api/membership" - "go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp" - "go.etcd.io/etcd/server/v3/etcdserver/api/snap" - "go.etcd.io/etcd/server/v3/etcdserver/api/v2discovery" - "go.etcd.io/etcd/server/v3/etcdserver/api/v2http/httptypes" - stats "go.etcd.io/etcd/server/v3/etcdserver/api/v2stats" - "go.etcd.io/etcd/server/v3/etcdserver/api/v2store" - "go.etcd.io/etcd/server/v3/etcdserver/api/v3alarm" - "go.etcd.io/etcd/server/v3/etcdserver/api/v3compactor" - "go.etcd.io/etcd/server/v3/etcdserver/cindex" - "go.etcd.io/etcd/server/v3/lease" - "go.etcd.io/etcd/server/v3/lease/leasehttp" - "go.etcd.io/etcd/server/v3/mvcc" - "go.etcd.io/etcd/server/v3/mvcc/backend" - "go.etcd.io/etcd/server/v3/wal" -) - -const ( - DefaultSnapshotCount = 100000 - - // DefaultSnapshotCatchUpEntries is the number of entries for a slow follower - // to catch-up after compacting the raft storage entries. - // We expect the follower has a millisecond level latency with the leader. - // The max throughput is around 10K. Keep a 5K entries is enough for helping - // follower to catch up. - DefaultSnapshotCatchUpEntries uint64 = 5000 - - StoreClusterPrefix = "/0" - StoreKeysPrefix = "/1" - - // HealthInterval is the minimum time the cluster should be healthy - // before accepting add member requests. - HealthInterval = 5 * time.Second - - purgeFileInterval = 30 * time.Second - - // max number of in-flight snapshot messages etcdserver allows to have - // This number is more than enough for most clusters with 5 machines. - maxInFlightMsgSnap = 16 - - releaseDelayAfterSnapshot = 30 * time.Second - - // maxPendingRevokes is the maximum number of outstanding expired lease revocations. - maxPendingRevokes = 16 - - recommendedMaxRequestBytes = 10 * 1024 * 1024 - - readyPercent = 0.9 - - DowngradeEnabledPath = "/downgrade/enabled" -) - -var ( - // monitorVersionInterval should be smaller than the timeout - // on the connection. Or we will not be able to reuse the connection - // (since it will timeout). - monitorVersionInterval = rafthttp.ConnWriteTimeout - time.Second - - recommendedMaxRequestBytesString = humanize.Bytes(uint64(recommendedMaxRequestBytes)) - storeMemberAttributeRegexp = regexp.MustCompile(path.Join(membership.StoreMembersPrefix, "[[:xdigit:]]{1,16}", "attributes")) -) - -func init() { - rand.Seed(time.Now().UnixNano()) - - expvar.Publish( - "file_descriptor_limit", - expvar.Func( - func() interface{} { - n, _ := runtime.FDLimit() - return n - }, - ), - ) -} - -type Response struct { - Term uint64 - Index uint64 - Event *v2store.Event - Watcher v2store.Watcher - Err error -} - -type ServerV2 interface { - Server - Leader() types.ID - - // Do takes a V2 request and attempts to fulfill it, returning a Response. - Do(ctx context.Context, r pb.Request) (Response, error) - stats.Stats - ClientCertAuthEnabled() bool -} - -type ServerV3 interface { - Server - RaftStatusGetter -} - -func (s *EtcdServer) ClientCertAuthEnabled() bool { return s.Cfg.ClientCertAuthEnabled } - -type Server interface { - // AddMember attempts to add a member into the cluster. It will return - // ErrIDRemoved if member ID is removed from the cluster, or return - // ErrIDExists if member ID exists in the cluster. - AddMember(ctx context.Context, memb membership.Member) ([]*membership.Member, error) - // RemoveMember attempts to remove a member from the cluster. It will - // return ErrIDRemoved if member ID is removed from the cluster, or return - // ErrIDNotFound if member ID is not in the cluster. - RemoveMember(ctx context.Context, id uint64) ([]*membership.Member, error) - // UpdateMember attempts to update an existing member in the cluster. It will - // return ErrIDNotFound if the member ID does not exist. - UpdateMember(ctx context.Context, updateMemb membership.Member) ([]*membership.Member, error) - // PromoteMember attempts to promote a non-voting node to a voting node. It will - // return ErrIDNotFound if the member ID does not exist. - // return ErrLearnerNotReady if the member are not ready. - // return ErrMemberNotLearner if the member is not a learner. - PromoteMember(ctx context.Context, id uint64) ([]*membership.Member, error) - - // ClusterVersion is the cluster-wide minimum major.minor version. - // Cluster version is set to the min version that an etcd member is - // compatible with when first bootstrap. - // - // ClusterVersion is nil until the cluster is bootstrapped (has a quorum). - // - // During a rolling upgrades, the ClusterVersion will be updated - // automatically after a sync. (5 second by default) - // - // The API/raft component can utilize ClusterVersion to determine if - // it can accept a client request or a raft RPC. - // NOTE: ClusterVersion might be nil when etcd 2.1 works with etcd 2.0 and - // the leader is etcd 2.0. etcd 2.0 leader will not update clusterVersion since - // this feature is introduced post 2.0. - ClusterVersion() *semver.Version - Cluster() api.Cluster - Alarms() []*pb.AlarmMember - - // LeaderChangedNotify returns a channel for application level code to be notified - // when etcd leader changes, this function is intend to be used only in application - // which embed etcd. - // Caution: - // 1. the returned channel is being closed when the leadership changes. - // 2. so the new channel needs to be obtained for each raft term. - // 3. user can loose some consecutive channel changes using this API. - LeaderChangedNotify() <-chan struct{} -} - -// EtcdServer is the production implementation of the Server interface -type EtcdServer struct { - // inflightSnapshots holds count the number of snapshots currently inflight. - inflightSnapshots int64 // must use atomic operations to access; keep 64-bit aligned. - appliedIndex uint64 // must use atomic operations to access; keep 64-bit aligned. - committedIndex uint64 // must use atomic operations to access; keep 64-bit aligned. - term uint64 // must use atomic operations to access; keep 64-bit aligned. - lead uint64 // must use atomic operations to access; keep 64-bit aligned. - - consistIndex cindex.ConsistentIndexer // consistIndex is used to get/set/save consistentIndex - r raftNode // uses 64-bit atomics; keep 64-bit aligned. - - readych chan struct{} - Cfg config.ServerConfig - - lgMu *sync.RWMutex - lg *zap.Logger - - w wait.Wait - - readMu sync.RWMutex - // read routine notifies etcd server that it waits for reading by sending an empty struct to - // readwaitC - readwaitc chan struct{} - // readNotifier is used to notify the read routine that it can process the request - // when there is no error - readNotifier *notifier - - // stop signals the run goroutine should shutdown. - stop chan struct{} - // stopping is closed by run goroutine on shutdown. - stopping chan struct{} - // done is closed when all goroutines from start() complete. - done chan struct{} - // leaderChanged is used to notify the linearizable read loop to drop the old read requests. - leaderChanged chan struct{} - leaderChangedMu sync.RWMutex - - errorc chan error - id types.ID - attributes membership.Attributes - - cluster *membership.RaftCluster - - v2store v2store.Store - snapshotter *snap.Snapshotter - - applyV2 ApplierV2 - - // applyV3 is the applier with auth and quotas - applyV3 applierV3 - // applyV3Base is the core applier without auth or quotas - applyV3Base applierV3 - // applyV3Internal is the applier for internal request - applyV3Internal applierV3Internal - applyWait wait.WaitTime - - kv mvcc.WatchableKV - lessor lease.Lessor - bemu sync.Mutex - be backend.Backend - beHooks *backendHooks - authStore auth.AuthStore - alarmStore *v3alarm.AlarmStore - - stats *stats.ServerStats - lstats *stats.LeaderStats - - SyncTicker *time.Ticker - // compactor is used to auto-compact the KV. - compactor v3compactor.Compactor - - // peerRt used to send requests (version, lease) to peers. - peerRt http.RoundTripper - reqIDGen *idutil.Generator - - // wgMu blocks concurrent waitgroup mutation while server stopping - wgMu sync.RWMutex - // wg is used to wait for the goroutines that depends on the server state - // to exit when stopping the server. - wg sync.WaitGroup - - // ctx is used for etcd-initiated requests that may need to be canceled - // on etcd server shutdown. - ctx context.Context - cancel context.CancelFunc - - leadTimeMu sync.RWMutex - leadElectedTime time.Time - - firstCommitInTermMu sync.RWMutex - firstCommitInTermC chan struct{} - - *AccessController -} - -type backendHooks struct { - indexer cindex.ConsistentIndexer - lg *zap.Logger - - // confState to be written in the next submitted backend transaction (if dirty) - confState raftpb.ConfState - // first write changes it to 'dirty'. false by default, so - // not initialized `confState` is meaningless. - confStateDirty bool - confStateLock sync.Mutex -} - -func (bh *backendHooks) OnPreCommitUnsafe(tx backend.BatchTx) { - bh.indexer.UnsafeSave(tx) - bh.confStateLock.Lock() - defer bh.confStateLock.Unlock() - if bh.confStateDirty { - membership.MustUnsafeSaveConfStateToBackend(bh.lg, tx, &bh.confState) - // save bh.confState - bh.confStateDirty = false - } -} - -func (bh *backendHooks) SetConfState(confState *raftpb.ConfState) { - bh.confStateLock.Lock() - defer bh.confStateLock.Unlock() - bh.confState = *confState - bh.confStateDirty = true -} - -// NewServer creates a new EtcdServer from the supplied configuration. The -// configuration is considered static for the lifetime of the EtcdServer. -func NewServer(cfg config.ServerConfig) (srv *EtcdServer, err error) { - st := v2store.New(StoreClusterPrefix, StoreKeysPrefix) - - var ( - w *wal.WAL - n raft.Node - s *raft.MemoryStorage - id types.ID - cl *membership.RaftCluster - ) - - if cfg.MaxRequestBytes > recommendedMaxRequestBytes { - cfg.Logger.Warn( - "exceeded recommended request limit", - zap.Uint("max-request-bytes", cfg.MaxRequestBytes), - zap.String("max-request-size", humanize.Bytes(uint64(cfg.MaxRequestBytes))), - zap.Int("recommended-request-bytes", recommendedMaxRequestBytes), - zap.String("recommended-request-size", recommendedMaxRequestBytesString), - ) - } - - if terr := fileutil.TouchDirAll(cfg.DataDir); terr != nil { - return nil, fmt.Errorf("cannot access data directory: %v", terr) - } - - haveWAL := wal.Exist(cfg.WALDir()) - - if err = fileutil.TouchDirAll(cfg.SnapDir()); err != nil { - cfg.Logger.Fatal( - "failed to create snapshot directory", - zap.String("path", cfg.SnapDir()), - zap.Error(err), - ) - } - - if err = fileutil.RemoveMatchFile(cfg.Logger, cfg.SnapDir(), func(fileName string) bool { - return strings.HasPrefix(fileName, "tmp") - }); err != nil { - cfg.Logger.Error( - "failed to remove temp file(s) in snapshot directory", - zap.String("path", cfg.SnapDir()), - zap.Error(err), - ) - } - - ss := snap.New(cfg.Logger, cfg.SnapDir()) - - bepath := cfg.BackendPath() - beExist := fileutil.Exist(bepath) - - ci := cindex.NewConsistentIndex(nil) - beHooks := &backendHooks{lg: cfg.Logger, indexer: ci} - be := openBackend(cfg, beHooks) - ci.SetBackend(be) - cindex.CreateMetaBucket(be.BatchTx()) - - if cfg.ExperimentalBootstrapDefragThresholdMegabytes != 0 { - err := maybeDefragBackend(cfg, be) - if err != nil { - return nil, err - } - } - - defer func() { - if err != nil { - be.Close() - } - }() - - prt, err := rafthttp.NewRoundTripper(cfg.PeerTLSInfo, cfg.PeerDialTimeout()) - if err != nil { - return nil, err - } - var ( - remotes []*membership.Member - snapshot *raftpb.Snapshot - ) - - switch { - case !haveWAL && !cfg.NewCluster: - if err = cfg.VerifyJoinExisting(); err != nil { - return nil, err - } - cl, err = membership.NewClusterFromURLsMap(cfg.Logger, cfg.InitialClusterToken, cfg.InitialPeerURLsMap) - if err != nil { - return nil, err - } - existingCluster, gerr := GetClusterFromRemotePeers(cfg.Logger, getRemotePeerURLs(cl, cfg.Name), prt) - if gerr != nil { - return nil, fmt.Errorf("cannot fetch cluster info from peer urls: %v", gerr) - } - if err = membership.ValidateClusterAndAssignIDs(cfg.Logger, cl, existingCluster); err != nil { - return nil, fmt.Errorf("error validating peerURLs %s: %v", existingCluster, err) - } - if !isCompatibleWithCluster(cfg.Logger, cl, cl.MemberByName(cfg.Name).ID, prt) { - return nil, fmt.Errorf("incompatible with current running cluster") - } - - remotes = existingCluster.Members() - cl.SetID(types.ID(0), existingCluster.ID()) - cl.SetStore(st) - cl.SetBackend(be) - id, n, s, w = startNode(cfg, cl, nil) - cl.SetID(id, existingCluster.ID()) - - case !haveWAL && cfg.NewCluster: - if err = cfg.VerifyBootstrap(); err != nil { - return nil, err - } - cl, err = membership.NewClusterFromURLsMap(cfg.Logger, cfg.InitialClusterToken, cfg.InitialPeerURLsMap) - if err != nil { - return nil, err - } - m := cl.MemberByName(cfg.Name) - if isMemberBootstrapped(cfg.Logger, cl, cfg.Name, prt, cfg.BootstrapTimeoutEffective()) { - return nil, fmt.Errorf("member %s has already been bootstrapped", m.ID) - } - if cfg.ShouldDiscover() { - var str string - str, err = v2discovery.JoinCluster(cfg.Logger, cfg.DiscoveryURL, cfg.DiscoveryProxy, m.ID, cfg.InitialPeerURLsMap.String()) - if err != nil { - return nil, &DiscoveryError{Op: "join", Err: err} - } - var urlsmap types.URLsMap - urlsmap, err = types.NewURLsMap(str) - if err != nil { - return nil, err - } - if config.CheckDuplicateURL(urlsmap) { - return nil, fmt.Errorf("discovery cluster %s has duplicate url", urlsmap) - } - if cl, err = membership.NewClusterFromURLsMap(cfg.Logger, cfg.InitialClusterToken, urlsmap); err != nil { - return nil, err - } - } - cl.SetStore(st) - cl.SetBackend(be) - id, n, s, w = startNode(cfg, cl, cl.MemberIDs()) - cl.SetID(id, cl.ID()) - - case haveWAL: - if err = fileutil.IsDirWriteable(cfg.MemberDir()); err != nil { - return nil, fmt.Errorf("cannot write to member directory: %v", err) - } - - if err = fileutil.IsDirWriteable(cfg.WALDir()); err != nil { - return nil, fmt.Errorf("cannot write to WAL directory: %v", err) - } - - if cfg.ShouldDiscover() { - cfg.Logger.Warn( - "discovery token is ignored since cluster already initialized; valid logs are found", - zap.String("wal-dir", cfg.WALDir()), - ) - } - - // Find a snapshot to start/restart a raft node - walSnaps, err := wal.ValidSnapshotEntries(cfg.Logger, cfg.WALDir()) - if err != nil { - return nil, err - } - // snapshot files can be orphaned if etcd crashes after writing them but before writing the corresponding - // wal log entries - snapshot, err := ss.LoadNewestAvailable(walSnaps) - if err != nil && err != snap.ErrNoSnapshot { - return nil, err - } - - if snapshot != nil { - if err = st.Recovery(snapshot.Data); err != nil { - cfg.Logger.Panic("failed to recover from snapshot", zap.Error(err)) - } - - if err = assertNoV2StoreContent(cfg.Logger, st, cfg.V2Deprecation); err != nil { - cfg.Logger.Error("illegal v2store content", zap.Error(err)) - return nil, err - } - - cfg.Logger.Info( - "recovered v2 store from snapshot", - zap.Uint64("snapshot-index", snapshot.Metadata.Index), - zap.String("snapshot-size", humanize.Bytes(uint64(snapshot.Size()))), - ) - - if be, err = recoverSnapshotBackend(cfg, be, *snapshot, beExist, beHooks); err != nil { - cfg.Logger.Panic("failed to recover v3 backend from snapshot", zap.Error(err)) - } - s1, s2 := be.Size(), be.SizeInUse() - cfg.Logger.Info( - "recovered v3 backend from snapshot", - zap.Int64("backend-size-bytes", s1), - zap.String("backend-size", humanize.Bytes(uint64(s1))), - zap.Int64("backend-size-in-use-bytes", s2), - zap.String("backend-size-in-use", humanize.Bytes(uint64(s2))), - ) - } else { - cfg.Logger.Info("No snapshot found. Recovering WAL from scratch!") - } - - if !cfg.ForceNewCluster { - id, cl, n, s, w = restartNode(cfg, snapshot) - } else { - id, cl, n, s, w = restartAsStandaloneNode(cfg, snapshot) - } - - cl.SetStore(st) - cl.SetBackend(be) - cl.Recover(api.UpdateCapability) - if cl.Version() != nil && !cl.Version().LessThan(semver.Version{Major: 3}) && !beExist { - os.RemoveAll(bepath) - return nil, fmt.Errorf("database file (%v) of the backend is missing", bepath) - } - - default: - return nil, fmt.Errorf("unsupported bootstrap config") - } - - if terr := fileutil.TouchDirAll(cfg.MemberDir()); terr != nil { - return nil, fmt.Errorf("cannot access member directory: %v", terr) - } - - sstats := stats.NewServerStats(cfg.Name, id.String()) - lstats := stats.NewLeaderStats(cfg.Logger, id.String()) - - heartbeat := time.Duration(cfg.TickMs) * time.Millisecond - srv = &EtcdServer{ - readych: make(chan struct{}), - Cfg: cfg, - lgMu: new(sync.RWMutex), - lg: cfg.Logger, - errorc: make(chan error, 1), - v2store: st, - snapshotter: ss, - r: *newRaftNode( - raftNodeConfig{ - lg: cfg.Logger, - isIDRemoved: func(id uint64) bool { return cl.IsIDRemoved(types.ID(id)) }, - Node: n, - heartbeat: heartbeat, - raftStorage: s, - storage: NewStorage(w, ss), - }, - ), - id: id, - attributes: membership.Attributes{Name: cfg.Name, ClientURLs: cfg.ClientURLs.StringSlice()}, - cluster: cl, - stats: sstats, - lstats: lstats, - SyncTicker: time.NewTicker(500 * time.Millisecond), - peerRt: prt, - reqIDGen: idutil.NewGenerator(uint16(id), time.Now()), - AccessController: &AccessController{CORS: cfg.CORS, HostWhitelist: cfg.HostWhitelist}, - consistIndex: ci, - firstCommitInTermC: make(chan struct{}), - } - serverID.With(prometheus.Labels{"server_id": id.String()}).Set(1) - - srv.applyV2 = NewApplierV2(cfg.Logger, srv.v2store, srv.cluster) - - srv.be = be - srv.beHooks = beHooks - minTTL := time.Duration((3*cfg.ElectionTicks)/2) * heartbeat - - // always recover lessor before kv. When we recover the mvcc.KV it will reattach keys to its leases. - // If we recover mvcc.KV first, it will attach the keys to the wrong lessor before it recovers. - srv.lessor = lease.NewLessor(srv.Logger(), srv.be, lease.LessorConfig{ - MinLeaseTTL: int64(math.Ceil(minTTL.Seconds())), - CheckpointInterval: cfg.LeaseCheckpointInterval, - ExpiredLeasesRetryInterval: srv.Cfg.ReqTimeout(), - }) - - tp, err := auth.NewTokenProvider(cfg.Logger, cfg.AuthToken, - func(index uint64) <-chan struct{} { - return srv.applyWait.Wait(index) - }, - time.Duration(cfg.TokenTTL)*time.Second, - ) - if err != nil { - cfg.Logger.Warn("failed to create token provider", zap.Error(err)) - return nil, err - } - srv.kv = mvcc.New(srv.Logger(), srv.be, srv.lessor, mvcc.StoreConfig{CompactionBatchLimit: cfg.CompactionBatchLimit}) - - kvindex := ci.ConsistentIndex() - srv.lg.Debug("restore consistentIndex", zap.Uint64("index", kvindex)) - if beExist { - // TODO: remove kvindex != 0 checking when we do not expect users to upgrade - // etcd from pre-3.0 release. - if snapshot != nil && kvindex < snapshot.Metadata.Index { - if kvindex != 0 { - return nil, fmt.Errorf("database file (%v index %d) does not match with snapshot (index %d)", bepath, kvindex, snapshot.Metadata.Index) - } - cfg.Logger.Warn( - "consistent index was never saved", - zap.Uint64("snapshot-index", snapshot.Metadata.Index), - ) - } - } - - srv.authStore = auth.NewAuthStore(srv.Logger(), srv.be, tp, int(cfg.BcryptCost)) - - newSrv := srv // since srv == nil in defer if srv is returned as nil - defer func() { - // closing backend without first closing kv can cause - // resumed compactions to fail with closed tx errors - if err != nil { - newSrv.kv.Close() - } - }() - if num := cfg.AutoCompactionRetention; num != 0 { - srv.compactor, err = v3compactor.New(cfg.Logger, cfg.AutoCompactionMode, num, srv.kv, srv) - if err != nil { - return nil, err - } - srv.compactor.Run() - } - - srv.applyV3Base = srv.newApplierV3Backend() - srv.applyV3Internal = srv.newApplierV3Internal() - if err = srv.restoreAlarms(); err != nil { - return nil, err - } - - if srv.Cfg.EnableLeaseCheckpoint { - // setting checkpointer enables lease checkpoint feature. - srv.lessor.SetCheckpointer(func(ctx context.Context, cp *pb.LeaseCheckpointRequest) { - srv.raftRequestOnce(ctx, pb.InternalRaftRequest{LeaseCheckpoint: cp}) - }) - } - - // TODO: move transport initialization near the definition of remote - tr := &rafthttp.Transport{ - Logger: cfg.Logger, - TLSInfo: cfg.PeerTLSInfo, - DialTimeout: cfg.PeerDialTimeout(), - ID: id, - URLs: cfg.PeerURLs, - ClusterID: cl.ID(), - Raft: srv, - Snapshotter: ss, - ServerStats: sstats, - LeaderStats: lstats, - ErrorC: srv.errorc, - } - if err = tr.Start(); err != nil { - return nil, err - } - // add all remotes into transport - for _, m := range remotes { - if m.ID != id { - tr.AddRemote(m.ID, m.PeerURLs) - } - } - for _, m := range cl.Members() { - if m.ID != id { - tr.AddPeer(m.ID, m.PeerURLs) - } - } - srv.r.transport = tr - - return srv, nil -} - -// assertNoV2StoreContent -> depending on the deprecation stage, warns or report an error -// if the v2store contains custom content. -func assertNoV2StoreContent(lg *zap.Logger, st v2store.Store, deprecationStage config.V2DeprecationEnum) error { - metaOnly, err := membership.IsMetaStoreOnly(st) - if err != nil { - return err - } - if metaOnly { - return nil - } - if deprecationStage.IsAtLeast(config.V2_DEPR_1_WRITE_ONLY) { - return fmt.Errorf("detected disallowed custom content in v2store for stage --v2-deprecation=%s", deprecationStage) - } - lg.Warn("detected custom v2store content. Etcd v3.5 is the last version allowing to access it using API v2. Please remove the content.") - return nil -} - -func (s *EtcdServer) Logger() *zap.Logger { - s.lgMu.RLock() - l := s.lg - s.lgMu.RUnlock() - return l -} - -func tickToDur(ticks int, tickMs uint) string { - return fmt.Sprintf("%v", time.Duration(ticks)*time.Duration(tickMs)*time.Millisecond) -} - -func (s *EtcdServer) adjustTicks() { - lg := s.Logger() - clusterN := len(s.cluster.Members()) - - // single-node fresh start, or single-node recovers from snapshot - if clusterN == 1 { - ticks := s.Cfg.ElectionTicks - 1 - lg.Info( - "started as single-node; fast-forwarding election ticks", - zap.String("local-member-id", s.ID().String()), - zap.Int("forward-ticks", ticks), - zap.String("forward-duration", tickToDur(ticks, s.Cfg.TickMs)), - zap.Int("election-ticks", s.Cfg.ElectionTicks), - zap.String("election-timeout", tickToDur(s.Cfg.ElectionTicks, s.Cfg.TickMs)), - ) - s.r.advanceTicks(ticks) - return - } - - if !s.Cfg.InitialElectionTickAdvance { - lg.Info("skipping initial election tick advance", zap.Int("election-ticks", s.Cfg.ElectionTicks)) - return - } - lg.Info("starting initial election tick advance", zap.Int("election-ticks", s.Cfg.ElectionTicks)) - - // retry up to "rafthttp.ConnReadTimeout", which is 5-sec - // until peer connection reports; otherwise: - // 1. all connections failed, or - // 2. no active peers, or - // 3. restarted single-node with no snapshot - // then, do nothing, because advancing ticks would have no effect - waitTime := rafthttp.ConnReadTimeout - itv := 50 * time.Millisecond - for i := int64(0); i < int64(waitTime/itv); i++ { - select { - case <-time.After(itv): - case <-s.stopping: - return - } - - peerN := s.r.transport.ActivePeers() - if peerN > 1 { - // multi-node received peer connection reports - // adjust ticks, in case slow leader message receive - ticks := s.Cfg.ElectionTicks - 2 - - lg.Info( - "initialized peer connections; fast-forwarding election ticks", - zap.String("local-member-id", s.ID().String()), - zap.Int("forward-ticks", ticks), - zap.String("forward-duration", tickToDur(ticks, s.Cfg.TickMs)), - zap.Int("election-ticks", s.Cfg.ElectionTicks), - zap.String("election-timeout", tickToDur(s.Cfg.ElectionTicks, s.Cfg.TickMs)), - zap.Int("active-remote-members", peerN), - ) - - s.r.advanceTicks(ticks) - return - } - } -} - -// Start performs any initialization of the Server necessary for it to -// begin serving requests. It must be called before Do or Process. -// Start must be non-blocking; any long-running server functionality -// should be implemented in goroutines. -func (s *EtcdServer) Start() { - s.start() - s.GoAttach(func() { s.adjustTicks() }) - // TODO: Switch to publishV3 in 3.6. - // Support for cluster_member_set_attr was added in 3.5. - s.GoAttach(func() { s.publish(s.Cfg.ReqTimeout()) }) - s.GoAttach(s.purgeFile) - s.GoAttach(func() { monitorFileDescriptor(s.Logger(), s.stopping) }) - s.GoAttach(s.monitorVersions) - s.GoAttach(s.linearizableReadLoop) - s.GoAttach(s.monitorKVHash) - s.GoAttach(s.monitorDowngrade) -} - -// start prepares and starts server in a new goroutine. It is no longer safe to -// modify a server's fields after it has been sent to Start. -// This function is just used for testing. -func (s *EtcdServer) start() { - lg := s.Logger() - - if s.Cfg.SnapshotCount == 0 { - lg.Info( - "updating snapshot-count to default", - zap.Uint64("given-snapshot-count", s.Cfg.SnapshotCount), - zap.Uint64("updated-snapshot-count", DefaultSnapshotCount), - ) - s.Cfg.SnapshotCount = DefaultSnapshotCount - } - if s.Cfg.SnapshotCatchUpEntries == 0 { - lg.Info( - "updating snapshot catch-up entries to default", - zap.Uint64("given-snapshot-catchup-entries", s.Cfg.SnapshotCatchUpEntries), - zap.Uint64("updated-snapshot-catchup-entries", DefaultSnapshotCatchUpEntries), - ) - s.Cfg.SnapshotCatchUpEntries = DefaultSnapshotCatchUpEntries - } - - s.w = wait.New() - s.applyWait = wait.NewTimeList() - s.done = make(chan struct{}) - s.stop = make(chan struct{}) - s.stopping = make(chan struct{}, 1) - s.ctx, s.cancel = context.WithCancel(context.Background()) - s.readwaitc = make(chan struct{}, 1) - s.readNotifier = newNotifier() - s.leaderChanged = make(chan struct{}) - if s.ClusterVersion() != nil { - lg.Info( - "starting etcd server", - zap.String("local-member-id", s.ID().String()), - zap.String("local-server-version", version.Version), - zap.String("cluster-id", s.Cluster().ID().String()), - zap.String("cluster-version", version.Cluster(s.ClusterVersion().String())), - ) - membership.ClusterVersionMetrics.With(prometheus.Labels{"cluster_version": version.Cluster(s.ClusterVersion().String())}).Set(1) - } else { - lg.Info( - "starting etcd server", - zap.String("local-member-id", s.ID().String()), - zap.String("local-server-version", version.Version), - zap.String("cluster-version", "to_be_decided"), - ) - } - - // TODO: if this is an empty log, writes all peer infos - // into the first entry - go s.run() -} - -func (s *EtcdServer) purgeFile() { - lg := s.Logger() - var dberrc, serrc, werrc <-chan error - var dbdonec, sdonec, wdonec <-chan struct{} - if s.Cfg.MaxSnapFiles > 0 { - dbdonec, dberrc = fileutil.PurgeFileWithDoneNotify(lg, s.Cfg.SnapDir(), "snap.db", s.Cfg.MaxSnapFiles, purgeFileInterval, s.stopping) - sdonec, serrc = fileutil.PurgeFileWithDoneNotify(lg, s.Cfg.SnapDir(), "snap", s.Cfg.MaxSnapFiles, purgeFileInterval, s.stopping) - } - if s.Cfg.MaxWALFiles > 0 { - wdonec, werrc = fileutil.PurgeFileWithDoneNotify(lg, s.Cfg.WALDir(), "wal", s.Cfg.MaxWALFiles, purgeFileInterval, s.stopping) - } - - select { - case e := <-dberrc: - lg.Fatal("failed to purge snap db file", zap.Error(e)) - case e := <-serrc: - lg.Fatal("failed to purge snap file", zap.Error(e)) - case e := <-werrc: - lg.Fatal("failed to purge wal file", zap.Error(e)) - case <-s.stopping: - if dbdonec != nil { - <-dbdonec - } - if sdonec != nil { - <-sdonec - } - if wdonec != nil { - <-wdonec - } - return - } -} - -func (s *EtcdServer) Cluster() api.Cluster { return s.cluster } - -func (s *EtcdServer) ApplyWait() <-chan struct{} { return s.applyWait.Wait(s.getCommittedIndex()) } - -type ServerPeer interface { - ServerV2 - RaftHandler() http.Handler - LeaseHandler() http.Handler -} - -func (s *EtcdServer) LeaseHandler() http.Handler { - if s.lessor == nil { - return nil - } - return leasehttp.NewHandler(s.lessor, s.ApplyWait) -} - -func (s *EtcdServer) RaftHandler() http.Handler { return s.r.transport.Handler() } - -type ServerPeerV2 interface { - ServerPeer - HashKVHandler() http.Handler - DowngradeEnabledHandler() http.Handler -} - -func (s *EtcdServer) DowngradeInfo() *membership.DowngradeInfo { return s.cluster.DowngradeInfo() } - -type downgradeEnabledHandler struct { - lg *zap.Logger - cluster api.Cluster - server *EtcdServer -} - -func (s *EtcdServer) DowngradeEnabledHandler() http.Handler { - return &downgradeEnabledHandler{ - lg: s.Logger(), - cluster: s.cluster, - server: s, - } -} - -func (h *downgradeEnabledHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { - if r.Method != http.MethodGet { - w.Header().Set("Allow", http.MethodGet) - http.Error(w, "Method Not Allowed", http.StatusMethodNotAllowed) - return - } - - w.Header().Set("X-Etcd-Cluster-ID", h.cluster.ID().String()) - - if r.URL.Path != DowngradeEnabledPath { - http.Error(w, "bad path", http.StatusBadRequest) - return - } - - ctx, cancel := context.WithTimeout(context.Background(), h.server.Cfg.ReqTimeout()) - defer cancel() - - // serve with linearized downgrade info - if err := h.server.linearizableReadNotify(ctx); err != nil { - http.Error(w, fmt.Sprintf("failed linearized read: %v", err), - http.StatusInternalServerError) - return - } - enabled := h.server.DowngradeInfo().Enabled - w.Header().Set("Content-Type", "text/plain") - w.Write([]byte(strconv.FormatBool(enabled))) -} - -// Process takes a raft message and applies it to the server's raft state -// machine, respecting any timeout of the given context. -func (s *EtcdServer) Process(ctx context.Context, m raftpb.Message) error { - lg := s.Logger() - if s.cluster.IsIDRemoved(types.ID(m.From)) { - lg.Warn( - "rejected Raft message from removed member", - zap.String("local-member-id", s.ID().String()), - zap.String("removed-member-id", types.ID(m.From).String()), - ) - return httptypes.NewHTTPError(http.StatusForbidden, "cannot process message from removed member") - } - if m.Type == raftpb.MsgApp { - s.stats.RecvAppendReq(types.ID(m.From).String(), m.Size()) - } - return s.r.Step(ctx, m) -} - -func (s *EtcdServer) IsIDRemoved(id uint64) bool { return s.cluster.IsIDRemoved(types.ID(id)) } - -func (s *EtcdServer) ReportUnreachable(id uint64) { s.r.ReportUnreachable(id) } - -// ReportSnapshot reports snapshot sent status to the raft state machine, -// and clears the used snapshot from the snapshot store. -func (s *EtcdServer) ReportSnapshot(id uint64, status raft.SnapshotStatus) { - s.r.ReportSnapshot(id, status) -} - -type etcdProgress struct { - confState raftpb.ConfState - snapi uint64 - appliedt uint64 - appliedi uint64 -} - -// raftReadyHandler contains a set of EtcdServer operations to be called by raftNode, -// and helps decouple state machine logic from Raft algorithms. -// TODO: add a state machine interface to apply the commit entries and do snapshot/recover -type raftReadyHandler struct { - getLead func() (lead uint64) - updateLead func(lead uint64) - updateLeadership func(newLeader bool) - updateCommittedIndex func(uint64) -} - -func (s *EtcdServer) run() { - lg := s.Logger() - - sn, err := s.r.raftStorage.Snapshot() - if err != nil { - lg.Panic("failed to get snapshot from Raft storage", zap.Error(err)) - } - - // asynchronously accept apply packets, dispatch progress in-order - sched := schedule.NewFIFOScheduler() - - var ( - smu sync.RWMutex - syncC <-chan time.Time - ) - setSyncC := func(ch <-chan time.Time) { - smu.Lock() - syncC = ch - smu.Unlock() - } - getSyncC := func() (ch <-chan time.Time) { - smu.RLock() - ch = syncC - smu.RUnlock() - return - } - rh := &raftReadyHandler{ - getLead: func() (lead uint64) { return s.getLead() }, - updateLead: func(lead uint64) { s.setLead(lead) }, - updateLeadership: func(newLeader bool) { - if !s.isLeader() { - if s.lessor != nil { - s.lessor.Demote() - } - if s.compactor != nil { - s.compactor.Pause() - } - setSyncC(nil) - } else { - if newLeader { - t := time.Now() - s.leadTimeMu.Lock() - s.leadElectedTime = t - s.leadTimeMu.Unlock() - } - setSyncC(s.SyncTicker.C) - if s.compactor != nil { - s.compactor.Resume() - } - } - if newLeader { - s.leaderChangedMu.Lock() - lc := s.leaderChanged - s.leaderChanged = make(chan struct{}) - close(lc) - s.leaderChangedMu.Unlock() - } - // TODO: remove the nil checking - // current test utility does not provide the stats - if s.stats != nil { - s.stats.BecomeLeader() - } - }, - updateCommittedIndex: func(ci uint64) { - cci := s.getCommittedIndex() - if ci > cci { - s.setCommittedIndex(ci) - } - }, - } - s.r.start(rh) - - ep := etcdProgress{ - confState: sn.Metadata.ConfState, - snapi: sn.Metadata.Index, - appliedt: sn.Metadata.Term, - appliedi: sn.Metadata.Index, - } - - defer func() { - s.wgMu.Lock() // block concurrent waitgroup adds in GoAttach while stopping - close(s.stopping) - s.wgMu.Unlock() - s.cancel() - sched.Stop() - - // wait for gouroutines before closing raft so wal stays open - s.wg.Wait() - - s.SyncTicker.Stop() - - // must stop raft after scheduler-- etcdserver can leak rafthttp pipelines - // by adding a peer after raft stops the transport - s.r.stop() - - s.Cleanup() - - close(s.done) - }() - - var expiredLeaseC <-chan []*lease.Lease - if s.lessor != nil { - expiredLeaseC = s.lessor.ExpiredLeasesC() - } - - for { - select { - case ap := <-s.r.apply(): - f := func(context.Context) { s.applyAll(&ep, &ap) } - sched.Schedule(f) - case leases := <-expiredLeaseC: - s.GoAttach(func() { - // Increases throughput of expired leases deletion process through parallelization - c := make(chan struct{}, maxPendingRevokes) - for _, lease := range leases { - select { - case c <- struct{}{}: - case <-s.stopping: - return - } - lid := lease.ID - s.GoAttach(func() { - ctx := s.authStore.WithRoot(s.ctx) - _, lerr := s.LeaseRevoke(ctx, &pb.LeaseRevokeRequest{ID: int64(lid)}) - if lerr == nil { - leaseExpired.Inc() - } else { - lg.Warn( - "failed to revoke lease", - zap.String("lease-id", fmt.Sprintf("%016x", lid)), - zap.Error(lerr), - ) - } - - <-c - }) - } - }) - case err := <-s.errorc: - lg.Warn("server error", zap.Error(err)) - lg.Warn("data-dir used by this member must be removed") - return - case <-getSyncC(): - if s.v2store.HasTTLKeys() { - s.sync(s.Cfg.ReqTimeout()) - } - case <-s.stop: - return - } - } -} - -// Cleanup removes allocated objects by EtcdServer.NewServer in -// situation that EtcdServer::Start was not called (that takes care of cleanup). -func (s *EtcdServer) Cleanup() { - // kv, lessor and backend can be nil if running without v3 enabled - // or running unit tests. - if s.lessor != nil { - s.lessor.Stop() - } - if s.kv != nil { - s.kv.Close() - } - if s.authStore != nil { - s.authStore.Close() - } - if s.be != nil { - s.be.Close() - } - if s.compactor != nil { - s.compactor.Stop() - } -} - -func (s *EtcdServer) applyAll(ep *etcdProgress, apply *apply) { - s.applySnapshot(ep, apply) - s.applyEntries(ep, apply) - - proposalsApplied.Set(float64(ep.appliedi)) - s.applyWait.Trigger(ep.appliedi) - - // wait for the raft routine to finish the disk writes before triggering a - // snapshot. or applied index might be greater than the last index in raft - // storage, since the raft routine might be slower than apply routine. - <-apply.notifyc - - s.triggerSnapshot(ep) - select { - // snapshot requested via send() - case m := <-s.r.msgSnapC: - merged := s.createMergedSnapshotMessage(m, ep.appliedt, ep.appliedi, ep.confState) - s.sendMergedSnap(merged) - default: - } -} - -func (s *EtcdServer) applySnapshot(ep *etcdProgress, apply *apply) { - if raft.IsEmptySnap(apply.snapshot) { - return - } - applySnapshotInProgress.Inc() - - lg := s.Logger() - lg.Info( - "applying snapshot", - zap.Uint64("current-snapshot-index", ep.snapi), - zap.Uint64("current-applied-index", ep.appliedi), - zap.Uint64("incoming-leader-snapshot-index", apply.snapshot.Metadata.Index), - zap.Uint64("incoming-leader-snapshot-term", apply.snapshot.Metadata.Term), - ) - defer func() { - lg.Info( - "applied snapshot", - zap.Uint64("current-snapshot-index", ep.snapi), - zap.Uint64("current-applied-index", ep.appliedi), - zap.Uint64("incoming-leader-snapshot-index", apply.snapshot.Metadata.Index), - zap.Uint64("incoming-leader-snapshot-term", apply.snapshot.Metadata.Term), - ) - applySnapshotInProgress.Dec() - }() - - if apply.snapshot.Metadata.Index <= ep.appliedi { - lg.Panic( - "unexpected leader snapshot from outdated index", - zap.Uint64("current-snapshot-index", ep.snapi), - zap.Uint64("current-applied-index", ep.appliedi), - zap.Uint64("incoming-leader-snapshot-index", apply.snapshot.Metadata.Index), - zap.Uint64("incoming-leader-snapshot-term", apply.snapshot.Metadata.Term), - ) - } - - // wait for raftNode to persist snapshot onto the disk - <-apply.notifyc - - newbe, err := openSnapshotBackend(s.Cfg, s.snapshotter, apply.snapshot, s.beHooks) - if err != nil { - lg.Panic("failed to open snapshot backend", zap.Error(err)) - } - - // always recover lessor before kv. When we recover the mvcc.KV it will reattach keys to its leases. - // If we recover mvcc.KV first, it will attach the keys to the wrong lessor before it recovers. - if s.lessor != nil { - lg.Info("restoring lease store") - - s.lessor.Recover(newbe, func() lease.TxnDelete { return s.kv.Write(traceutil.TODO()) }) - - lg.Info("restored lease store") - } - - lg.Info("restoring mvcc store") - - if err := s.kv.Restore(newbe); err != nil { - lg.Panic("failed to restore mvcc store", zap.Error(err)) - } - - s.consistIndex.SetBackend(newbe) - lg.Info("restored mvcc store", zap.Uint64("consistent-index", s.consistIndex.ConsistentIndex())) - - // Closing old backend might block until all the txns - // on the backend are finished. - // We do not want to wait on closing the old backend. - s.bemu.Lock() - oldbe := s.be - go func() { - lg.Info("closing old backend file") - defer func() { - lg.Info("closed old backend file") - }() - if err := oldbe.Close(); err != nil { - lg.Panic("failed to close old backend", zap.Error(err)) - } - }() - - s.be = newbe - s.bemu.Unlock() - - lg.Info("restoring alarm store") - - if err := s.restoreAlarms(); err != nil { - lg.Panic("failed to restore alarm store", zap.Error(err)) - } - - lg.Info("restored alarm store") - - if s.authStore != nil { - lg.Info("restoring auth store") - - s.authStore.Recover(newbe) - - lg.Info("restored auth store") - } - - lg.Info("restoring v2 store") - if err := s.v2store.Recovery(apply.snapshot.Data); err != nil { - lg.Panic("failed to restore v2 store", zap.Error(err)) - } - - if err := assertNoV2StoreContent(lg, s.v2store, s.Cfg.V2Deprecation); err != nil { - lg.Panic("illegal v2store content", zap.Error(err)) - } - - lg.Info("restored v2 store") - - s.cluster.SetBackend(newbe) - - lg.Info("restoring cluster configuration") - - s.cluster.Recover(api.UpdateCapability) - - lg.Info("restored cluster configuration") - lg.Info("removing old peers from network") - - // recover raft transport - s.r.transport.RemoveAllPeers() - - lg.Info("removed old peers from network") - lg.Info("adding peers from new cluster configuration") - - for _, m := range s.cluster.Members() { - if m.ID == s.ID() { - continue - } - s.r.transport.AddPeer(m.ID, m.PeerURLs) - } - - lg.Info("added peers from new cluster configuration") - - ep.appliedt = apply.snapshot.Metadata.Term - ep.appliedi = apply.snapshot.Metadata.Index - ep.snapi = ep.appliedi - ep.confState = apply.snapshot.Metadata.ConfState -} - -func (s *EtcdServer) applyEntries(ep *etcdProgress, apply *apply) { - if len(apply.entries) == 0 { - return - } - firsti := apply.entries[0].Index - if firsti > ep.appliedi+1 { - lg := s.Logger() - lg.Panic( - "unexpected committed entry index", - zap.Uint64("current-applied-index", ep.appliedi), - zap.Uint64("first-committed-entry-index", firsti), - ) - } - var ents []raftpb.Entry - if ep.appliedi+1-firsti < uint64(len(apply.entries)) { - ents = apply.entries[ep.appliedi+1-firsti:] - } - if len(ents) == 0 { - return - } - var shouldstop bool - if ep.appliedt, ep.appliedi, shouldstop = s.apply(ents, &ep.confState); shouldstop { - go s.stopWithDelay(10*100*time.Millisecond, fmt.Errorf("the member has been permanently removed from the cluster")) - } -} - -func (s *EtcdServer) triggerSnapshot(ep *etcdProgress) { - if ep.appliedi-ep.snapi <= s.Cfg.SnapshotCount { - return - } - - lg := s.Logger() - lg.Info( - "triggering snapshot", - zap.String("local-member-id", s.ID().String()), - zap.Uint64("local-member-applied-index", ep.appliedi), - zap.Uint64("local-member-snapshot-index", ep.snapi), - zap.Uint64("local-member-snapshot-count", s.Cfg.SnapshotCount), - ) - - s.snapshot(ep.appliedi, ep.confState) - ep.snapi = ep.appliedi -} - -func (s *EtcdServer) hasMultipleVotingMembers() bool { - return s.cluster != nil && len(s.cluster.VotingMemberIDs()) > 1 -} - -func (s *EtcdServer) isLeader() bool { - return uint64(s.ID()) == s.Lead() -} - -// MoveLeader transfers the leader to the given transferee. -func (s *EtcdServer) MoveLeader(ctx context.Context, lead, transferee uint64) error { - if !s.cluster.IsMemberExist(types.ID(transferee)) || s.cluster.Member(types.ID(transferee)).IsLearner { - return ErrBadLeaderTransferee - } - - now := time.Now() - interval := time.Duration(s.Cfg.TickMs) * time.Millisecond - - lg := s.Logger() - lg.Info( - "leadership transfer starting", - zap.String("local-member-id", s.ID().String()), - zap.String("current-leader-member-id", types.ID(lead).String()), - zap.String("transferee-member-id", types.ID(transferee).String()), - ) - - s.r.TransferLeadership(ctx, lead, transferee) - for s.Lead() != transferee { - select { - case <-ctx.Done(): // time out - return ErrTimeoutLeaderTransfer - case <-time.After(interval): - } - } - - // TODO: drain all requests, or drop all messages to the old leader - lg.Info( - "leadership transfer finished", - zap.String("local-member-id", s.ID().String()), - zap.String("old-leader-member-id", types.ID(lead).String()), - zap.String("new-leader-member-id", types.ID(transferee).String()), - zap.Duration("took", time.Since(now)), - ) - return nil -} - -// TransferLeadership transfers the leader to the chosen transferee. -func (s *EtcdServer) TransferLeadership() error { - lg := s.Logger() - if !s.isLeader() { - lg.Info( - "skipped leadership transfer; local server is not leader", - zap.String("local-member-id", s.ID().String()), - zap.String("current-leader-member-id", types.ID(s.Lead()).String()), - ) - return nil - } - - if !s.hasMultipleVotingMembers() { - lg.Info( - "skipped leadership transfer for single voting member cluster", - zap.String("local-member-id", s.ID().String()), - zap.String("current-leader-member-id", types.ID(s.Lead()).String()), - ) - return nil - } - - transferee, ok := longestConnected(s.r.transport, s.cluster.VotingMemberIDs()) - if !ok { - return ErrUnhealthy - } - - tm := s.Cfg.ReqTimeout() - ctx, cancel := context.WithTimeout(s.ctx, tm) - err := s.MoveLeader(ctx, s.Lead(), uint64(transferee)) - cancel() - return err -} - -// HardStop stops the server without coordination with other members in the cluster. -func (s *EtcdServer) HardStop() { - select { - case s.stop <- struct{}{}: - case <-s.done: - return - } - <-s.done -} - -// Stop stops the server gracefully, and shuts down the running goroutine. -// Stop should be called after a Start(s), otherwise it will block forever. -// When stopping leader, Stop transfers its leadership to one of its peers -// before stopping the server. -// Stop terminates the Server and performs any necessary finalization. -// Do and Process cannot be called after Stop has been invoked. -func (s *EtcdServer) Stop() { - lg := s.Logger() - if err := s.TransferLeadership(); err != nil { - lg.Warn("leadership transfer failed", zap.String("local-member-id", s.ID().String()), zap.Error(err)) - } - s.HardStop() -} - -// ReadyNotify returns a channel that will be closed when the server -// is ready to serve client requests -func (s *EtcdServer) ReadyNotify() <-chan struct{} { return s.readych } - -func (s *EtcdServer) stopWithDelay(d time.Duration, err error) { - select { - case <-time.After(d): - case <-s.done: - } - select { - case s.errorc <- err: - default: - } -} - -// StopNotify returns a channel that receives a empty struct -// when the server is stopped. -func (s *EtcdServer) StopNotify() <-chan struct{} { return s.done } - -// StoppingNotify returns a channel that receives a empty struct -// when the server is being stopped. -func (s *EtcdServer) StoppingNotify() <-chan struct{} { return s.stopping } - -func (s *EtcdServer) SelfStats() []byte { return s.stats.JSON() } - -func (s *EtcdServer) LeaderStats() []byte { - lead := s.getLead() - if lead != uint64(s.id) { - return nil - } - return s.lstats.JSON() -} - -func (s *EtcdServer) StoreStats() []byte { return s.v2store.JsonStats() } - -func (s *EtcdServer) checkMembershipOperationPermission(ctx context.Context) error { - if s.authStore == nil { - // In the context of ordinary etcd process, s.authStore will never be nil. - // This branch is for handling cases in server_test.go - return nil - } - - // Note that this permission check is done in the API layer, - // so TOCTOU problem can be caused potentially in a schedule like this: - // update membership with user A -> revoke root role of A -> apply membership change - // in the state machine layer - // However, both of membership change and role management requires the root privilege. - // So careful operation by admins can prevent the problem. - authInfo, err := s.AuthInfoFromCtx(ctx) - if err != nil { - return err - } - - return s.AuthStore().IsAdminPermitted(authInfo) -} - -func (s *EtcdServer) AddMember(ctx context.Context, memb membership.Member) ([]*membership.Member, error) { - if err := s.checkMembershipOperationPermission(ctx); err != nil { - return nil, err - } - - // TODO: move Member to protobuf type - b, err := json.Marshal(memb) - if err != nil { - return nil, err - } - - // by default StrictReconfigCheck is enabled; reject new members if unhealthy. - if err := s.mayAddMember(memb); err != nil { - return nil, err - } - - cc := raftpb.ConfChange{ - Type: raftpb.ConfChangeAddNode, - NodeID: uint64(memb.ID), - Context: b, - } - - if memb.IsLearner { - cc.Type = raftpb.ConfChangeAddLearnerNode - } - - return s.configure(ctx, cc) -} - -func (s *EtcdServer) mayAddMember(memb membership.Member) error { - lg := s.Logger() - if !s.Cfg.StrictReconfigCheck { - return nil - } - - // protect quorum when adding voting member - if !memb.IsLearner && !s.cluster.IsReadyToAddVotingMember() { - lg.Warn( - "rejecting member add request; not enough healthy members", - zap.String("local-member-id", s.ID().String()), - zap.String("requested-member-add", fmt.Sprintf("%+v", memb)), - zap.Error(ErrNotEnoughStartedMembers), - ) - return ErrNotEnoughStartedMembers - } - - if !isConnectedFullySince(s.r.transport, time.Now().Add(-HealthInterval), s.ID(), s.cluster.VotingMembers()) { - lg.Warn( - "rejecting member add request; local member has not been connected to all peers, reconfigure breaks active quorum", - zap.String("local-member-id", s.ID().String()), - zap.String("requested-member-add", fmt.Sprintf("%+v", memb)), - zap.Error(ErrUnhealthy), - ) - return ErrUnhealthy - } - - return nil -} - -func (s *EtcdServer) RemoveMember(ctx context.Context, id uint64) ([]*membership.Member, error) { - if err := s.checkMembershipOperationPermission(ctx); err != nil { - return nil, err - } - - // by default StrictReconfigCheck is enabled; reject removal if leads to quorum loss - if err := s.mayRemoveMember(types.ID(id)); err != nil { - return nil, err - } - - cc := raftpb.ConfChange{ - Type: raftpb.ConfChangeRemoveNode, - NodeID: id, - } - return s.configure(ctx, cc) -} - -// PromoteMember promotes a learner node to a voting node. -func (s *EtcdServer) PromoteMember(ctx context.Context, id uint64) ([]*membership.Member, error) { - // only raft leader has information on whether the to-be-promoted learner node is ready. If promoteMember call - // fails with ErrNotLeader, forward the request to leader node via HTTP. If promoteMember call fails with error - // other than ErrNotLeader, return the error. - resp, err := s.promoteMember(ctx, id) - if err == nil { - learnerPromoteSucceed.Inc() - return resp, nil - } - if err != ErrNotLeader { - learnerPromoteFailed.WithLabelValues(err.Error()).Inc() - return resp, err - } - - cctx, cancel := context.WithTimeout(ctx, s.Cfg.ReqTimeout()) - defer cancel() - // forward to leader - for cctx.Err() == nil { - leader, err := s.waitLeader(cctx) - if err != nil { - return nil, err - } - for _, url := range leader.PeerURLs { - resp, err := promoteMemberHTTP(cctx, url, id, s.peerRt) - if err == nil { - return resp, nil - } - // If member promotion failed, return early. Otherwise keep retry. - if err == ErrLearnerNotReady || err == membership.ErrIDNotFound || err == membership.ErrMemberNotLearner { - return nil, err - } - } - } - - if cctx.Err() == context.DeadlineExceeded { - return nil, ErrTimeout - } - return nil, ErrCanceled -} - -// promoteMember checks whether the to-be-promoted learner node is ready before sending the promote -// request to raft. -// The function returns ErrNotLeader if the local node is not raft leader (therefore does not have -// enough information to determine if the learner node is ready), returns ErrLearnerNotReady if the -// local node is leader (therefore has enough information) but decided the learner node is not ready -// to be promoted. -func (s *EtcdServer) promoteMember(ctx context.Context, id uint64) ([]*membership.Member, error) { - if err := s.checkMembershipOperationPermission(ctx); err != nil { - return nil, err - } - - // check if we can promote this learner. - if err := s.mayPromoteMember(types.ID(id)); err != nil { - return nil, err - } - - // build the context for the promote confChange. mark IsLearner to false and IsPromote to true. - promoteChangeContext := membership.ConfigChangeContext{ - Member: membership.Member{ - ID: types.ID(id), - }, - IsPromote: true, - } - - b, err := json.Marshal(promoteChangeContext) - if err != nil { - return nil, err - } - - cc := raftpb.ConfChange{ - Type: raftpb.ConfChangeAddNode, - NodeID: id, - Context: b, - } - - return s.configure(ctx, cc) -} - -func (s *EtcdServer) mayPromoteMember(id types.ID) error { - lg := s.Logger() - err := s.isLearnerReady(uint64(id)) - if err != nil { - return err - } - - if !s.Cfg.StrictReconfigCheck { - return nil - } - if !s.cluster.IsReadyToPromoteMember(uint64(id)) { - lg.Warn( - "rejecting member promote request; not enough healthy members", - zap.String("local-member-id", s.ID().String()), - zap.String("requested-member-remove-id", id.String()), - zap.Error(ErrNotEnoughStartedMembers), - ) - return ErrNotEnoughStartedMembers - } - - return nil -} - -// check whether the learner catches up with leader or not. -// Note: it will return nil if member is not found in cluster or if member is not learner. -// These two conditions will be checked before apply phase later. -func (s *EtcdServer) isLearnerReady(id uint64) error { - rs := s.raftStatus() - - // leader's raftStatus.Progress is not nil - if rs.Progress == nil { - return ErrNotLeader - } - - var learnerMatch uint64 - isFound := false - leaderID := rs.ID - for memberID, progress := range rs.Progress { - if id == memberID { - // check its status - learnerMatch = progress.Match - isFound = true - break - } - } - - if isFound { - leaderMatch := rs.Progress[leaderID].Match - // the learner's Match not caught up with leader yet - if float64(learnerMatch) < float64(leaderMatch)*readyPercent { - return ErrLearnerNotReady - } - } - - return nil -} - -func (s *EtcdServer) mayRemoveMember(id types.ID) error { - if !s.Cfg.StrictReconfigCheck { - return nil - } - - lg := s.Logger() - isLearner := s.cluster.IsMemberExist(id) && s.cluster.Member(id).IsLearner - // no need to check quorum when removing non-voting member - if isLearner { - return nil - } - - if !s.cluster.IsReadyToRemoveVotingMember(uint64(id)) { - lg.Warn( - "rejecting member remove request; not enough healthy members", - zap.String("local-member-id", s.ID().String()), - zap.String("requested-member-remove-id", id.String()), - zap.Error(ErrNotEnoughStartedMembers), - ) - return ErrNotEnoughStartedMembers - } - - // downed member is safe to remove since it's not part of the active quorum - if t := s.r.transport.ActiveSince(id); id != s.ID() && t.IsZero() { - return nil - } - - // protect quorum if some members are down - m := s.cluster.VotingMembers() - active := numConnectedSince(s.r.transport, time.Now().Add(-HealthInterval), s.ID(), m) - if (active - 1) < 1+((len(m)-1)/2) { - lg.Warn( - "rejecting member remove request; local member has not been connected to all peers, reconfigure breaks active quorum", - zap.String("local-member-id", s.ID().String()), - zap.String("requested-member-remove", id.String()), - zap.Int("active-peers", active), - zap.Error(ErrUnhealthy), - ) - return ErrUnhealthy - } - - return nil -} - -func (s *EtcdServer) UpdateMember(ctx context.Context, memb membership.Member) ([]*membership.Member, error) { - b, merr := json.Marshal(memb) - if merr != nil { - return nil, merr - } - - if err := s.checkMembershipOperationPermission(ctx); err != nil { - return nil, err - } - cc := raftpb.ConfChange{ - Type: raftpb.ConfChangeUpdateNode, - NodeID: uint64(memb.ID), - Context: b, - } - return s.configure(ctx, cc) -} - -func (s *EtcdServer) setCommittedIndex(v uint64) { - atomic.StoreUint64(&s.committedIndex, v) -} - -func (s *EtcdServer) getCommittedIndex() uint64 { - return atomic.LoadUint64(&s.committedIndex) -} - -func (s *EtcdServer) setAppliedIndex(v uint64) { - atomic.StoreUint64(&s.appliedIndex, v) -} - -func (s *EtcdServer) getAppliedIndex() uint64 { - return atomic.LoadUint64(&s.appliedIndex) -} - -func (s *EtcdServer) setTerm(v uint64) { - atomic.StoreUint64(&s.term, v) -} - -func (s *EtcdServer) getTerm() uint64 { - return atomic.LoadUint64(&s.term) -} - -func (s *EtcdServer) setLead(v uint64) { - atomic.StoreUint64(&s.lead, v) -} - -func (s *EtcdServer) getLead() uint64 { - return atomic.LoadUint64(&s.lead) -} - -func (s *EtcdServer) LeaderChangedNotify() <-chan struct{} { - s.leaderChangedMu.RLock() - defer s.leaderChangedMu.RUnlock() - return s.leaderChanged -} - -// FirstCommitInTermNotify returns channel that will be unlocked on first -// entry committed in new term, which is necessary for new leader to answer -// read-only requests (leader is not able to respond any read-only requests -// as long as linearizable semantic is required) -func (s *EtcdServer) FirstCommitInTermNotify() <-chan struct{} { - s.firstCommitInTermMu.RLock() - defer s.firstCommitInTermMu.RUnlock() - return s.firstCommitInTermC -} - -// RaftStatusGetter represents etcd server and Raft progress. -type RaftStatusGetter interface { - ID() types.ID - Leader() types.ID - CommittedIndex() uint64 - AppliedIndex() uint64 - Term() uint64 -} - -func (s *EtcdServer) ID() types.ID { return s.id } - -func (s *EtcdServer) Leader() types.ID { return types.ID(s.getLead()) } - -func (s *EtcdServer) Lead() uint64 { return s.getLead() } - -func (s *EtcdServer) CommittedIndex() uint64 { return s.getCommittedIndex() } - -func (s *EtcdServer) AppliedIndex() uint64 { return s.getAppliedIndex() } - -func (s *EtcdServer) Term() uint64 { return s.getTerm() } - -type confChangeResponse struct { - membs []*membership.Member - err error -} - -// configure sends a configuration change through consensus and -// then waits for it to be applied to the server. It -// will block until the change is performed or there is an error. -func (s *EtcdServer) configure(ctx context.Context, cc raftpb.ConfChange) ([]*membership.Member, error) { - lg := s.Logger() - cc.ID = s.reqIDGen.Next() - ch := s.w.Register(cc.ID) - - start := time.Now() - if err := s.r.ProposeConfChange(ctx, cc); err != nil { - s.w.Trigger(cc.ID, nil) - return nil, err - } - - select { - case x := <-ch: - if x == nil { - lg.Panic("failed to configure") - } - resp := x.(*confChangeResponse) - lg.Info( - "applied a configuration change through raft", - zap.String("local-member-id", s.ID().String()), - zap.String("raft-conf-change", cc.Type.String()), - zap.String("raft-conf-change-node-id", types.ID(cc.NodeID).String()), - ) - return resp.membs, resp.err - - case <-ctx.Done(): - s.w.Trigger(cc.ID, nil) // GC wait - return nil, s.parseProposeCtxErr(ctx.Err(), start) - - case <-s.stopping: - return nil, ErrStopped - } -} - -// sync proposes a SYNC request and is non-blocking. -// This makes no guarantee that the request will be proposed or performed. -// The request will be canceled after the given timeout. -func (s *EtcdServer) sync(timeout time.Duration) { - req := pb.Request{ - Method: "SYNC", - ID: s.reqIDGen.Next(), - Time: time.Now().UnixNano(), - } - data := pbutil.MustMarshal(&req) - // There is no promise that node has leader when do SYNC request, - // so it uses goroutine to propose. - ctx, cancel := context.WithTimeout(s.ctx, timeout) - s.GoAttach(func() { - s.r.Propose(ctx, data) - cancel() - }) -} - -// publishV3 registers server information into the cluster using v3 request. The -// information is the JSON representation of this server's member struct, updated -// with the static clientURLs of the server. -// The function keeps attempting to register until it succeeds, -// or its server is stopped. -func (s *EtcdServer) publishV3(timeout time.Duration) { - req := &membershippb.ClusterMemberAttrSetRequest{ - Member_ID: uint64(s.id), - MemberAttributes: &membershippb.Attributes{ - Name: s.attributes.Name, - ClientUrls: s.attributes.ClientURLs, - }, - } - lg := s.Logger() - for { - select { - case <-s.stopping: - lg.Warn( - "stopped publish because server is stopping", - zap.String("local-member-id", s.ID().String()), - zap.String("local-member-attributes", fmt.Sprintf("%+v", s.attributes)), - zap.Duration("publish-timeout", timeout), - ) - return - - default: - } - - ctx, cancel := context.WithTimeout(s.ctx, timeout) - _, err := s.raftRequest(ctx, pb.InternalRaftRequest{ClusterMemberAttrSet: req}) - cancel() - switch err { - case nil: - close(s.readych) - lg.Info( - "published local member to cluster through raft", - zap.String("local-member-id", s.ID().String()), - zap.String("local-member-attributes", fmt.Sprintf("%+v", s.attributes)), - zap.String("cluster-id", s.cluster.ID().String()), - zap.Duration("publish-timeout", timeout), - ) - return - - default: - lg.Warn( - "failed to publish local member to cluster through raft", - zap.String("local-member-id", s.ID().String()), - zap.String("local-member-attributes", fmt.Sprintf("%+v", s.attributes)), - zap.Duration("publish-timeout", timeout), - zap.Error(err), - ) - } - } -} - -// publish registers server information into the cluster. The information -// is the JSON representation of this server's member struct, updated with the -// static clientURLs of the server. -// The function keeps attempting to register until it succeeds, -// or its server is stopped. -// -// Use v2 store to encode member attributes, and apply through Raft -// but does not go through v2 API endpoint, which means even with v2 -// client handler disabled (e.g. --enable-v2=false), cluster can still -// process publish requests through rafthttp -// TODO: Remove in 3.6 (start using publishV3) -func (s *EtcdServer) publish(timeout time.Duration) { - lg := s.Logger() - b, err := json.Marshal(s.attributes) - if err != nil { - lg.Panic("failed to marshal JSON", zap.Error(err)) - return - } - req := pb.Request{ - Method: "PUT", - Path: membership.MemberAttributesStorePath(s.id), - Val: string(b), - } - - for { - ctx, cancel := context.WithTimeout(s.ctx, timeout) - _, err := s.Do(ctx, req) - cancel() - switch err { - case nil: - close(s.readych) - lg.Info( - "published local member to cluster through raft", - zap.String("local-member-id", s.ID().String()), - zap.String("local-member-attributes", fmt.Sprintf("%+v", s.attributes)), - zap.String("request-path", req.Path), - zap.String("cluster-id", s.cluster.ID().String()), - zap.Duration("publish-timeout", timeout), - ) - return - - case ErrStopped: - lg.Warn( - "stopped publish because server is stopped", - zap.String("local-member-id", s.ID().String()), - zap.String("local-member-attributes", fmt.Sprintf("%+v", s.attributes)), - zap.Duration("publish-timeout", timeout), - zap.Error(err), - ) - return - - default: - lg.Warn( - "failed to publish local member to cluster through raft", - zap.String("local-member-id", s.ID().String()), - zap.String("local-member-attributes", fmt.Sprintf("%+v", s.attributes)), - zap.String("request-path", req.Path), - zap.Duration("publish-timeout", timeout), - zap.Error(err), - ) - } - } -} - -func (s *EtcdServer) sendMergedSnap(merged snap.Message) { - atomic.AddInt64(&s.inflightSnapshots, 1) - - lg := s.Logger() - fields := []zap.Field{ - zap.String("from", s.ID().String()), - zap.String("to", types.ID(merged.To).String()), - zap.Int64("bytes", merged.TotalSize), - zap.String("size", humanize.Bytes(uint64(merged.TotalSize))), - } - - now := time.Now() - s.r.transport.SendSnapshot(merged) - lg.Info("sending merged snapshot", fields...) - - s.GoAttach(func() { - select { - case ok := <-merged.CloseNotify(): - // delay releasing inflight snapshot for another 30 seconds to - // block log compaction. - // If the follower still fails to catch up, it is probably just too slow - // to catch up. We cannot avoid the snapshot cycle anyway. - if ok { - select { - case <-time.After(releaseDelayAfterSnapshot): - case <-s.stopping: - } - } - - atomic.AddInt64(&s.inflightSnapshots, -1) - - lg.Info("sent merged snapshot", append(fields, zap.Duration("took", time.Since(now)))...) - - case <-s.stopping: - lg.Warn("canceled sending merged snapshot; server stopping", fields...) - return - } - }) -} - -// apply takes entries received from Raft (after it has been committed) and -// applies them to the current state of the EtcdServer. -// The given entries should not be empty. -func (s *EtcdServer) apply( - es []raftpb.Entry, - confState *raftpb.ConfState, -) (appliedt uint64, appliedi uint64, shouldStop bool) { - s.lg.Debug("Applying entries", zap.Int("num-entries", len(es))) - for i := range es { - e := es[i] - s.lg.Debug("Applying entry", - zap.Uint64("index", e.Index), - zap.Uint64("term", e.Term), - zap.Stringer("type", e.Type)) - switch e.Type { - case raftpb.EntryNormal: - s.applyEntryNormal(&e) - s.setAppliedIndex(e.Index) - s.setTerm(e.Term) - - case raftpb.EntryConfChange: - // We need to apply all WAL entries on top of v2store - // and only 'unapplied' (e.Index>backend.ConsistentIndex) on the backend. - shouldApplyV3 := membership.ApplyV2storeOnly - - // set the consistent index of current executing entry - if e.Index > s.consistIndex.ConsistentIndex() { - s.consistIndex.SetConsistentIndex(e.Index, e.Term) - shouldApplyV3 = membership.ApplyBoth - } - - var cc raftpb.ConfChange - pbutil.MustUnmarshal(&cc, e.Data) - removedSelf, err := s.applyConfChange(cc, confState, shouldApplyV3) - s.setAppliedIndex(e.Index) - s.setTerm(e.Term) - shouldStop = shouldStop || removedSelf - s.w.Trigger(cc.ID, &confChangeResponse{s.cluster.Members(), err}) - - default: - lg := s.Logger() - lg.Panic( - "unknown entry type; must be either EntryNormal or EntryConfChange", - zap.String("type", e.Type.String()), - ) - } - appliedi, appliedt = e.Index, e.Term - } - return appliedt, appliedi, shouldStop -} - -// applyEntryNormal apples an EntryNormal type raftpb request to the EtcdServer -func (s *EtcdServer) applyEntryNormal(e *raftpb.Entry) { - shouldApplyV3 := membership.ApplyV2storeOnly - index := s.consistIndex.ConsistentIndex() - if e.Index > index { - // set the consistent index of current executing entry - s.consistIndex.SetConsistentIndex(e.Index, e.Term) - shouldApplyV3 = membership.ApplyBoth - } - s.lg.Debug("apply entry normal", - zap.Uint64("consistent-index", index), - zap.Uint64("entry-index", e.Index), - zap.Bool("should-applyV3", bool(shouldApplyV3))) - - // raft state machine may generate noop entry when leader confirmation. - // skip it in advance to avoid some potential bug in the future - if len(e.Data) == 0 { - s.notifyAboutFirstCommitInTerm() - - // promote lessor when the local member is leader and finished - // applying all entries from the last term. - if s.isLeader() { - s.lessor.Promote(s.Cfg.ElectionTimeout()) - } - return - } - - var raftReq pb.InternalRaftRequest - if !pbutil.MaybeUnmarshal(&raftReq, e.Data) { // backward compatible - var r pb.Request - rp := &r - pbutil.MustUnmarshal(rp, e.Data) - s.lg.Debug("applyEntryNormal", zap.Stringer("V2request", rp)) - s.w.Trigger(r.ID, s.applyV2Request((*RequestV2)(rp), shouldApplyV3)) - return - } - s.lg.Debug("applyEntryNormal", zap.Stringer("raftReq", &raftReq)) - - if raftReq.V2 != nil { - req := (*RequestV2)(raftReq.V2) - s.w.Trigger(req.ID, s.applyV2Request(req, shouldApplyV3)) - return - } - - id := raftReq.ID - if id == 0 { - id = raftReq.Header.ID - } - - var ar *applyResult - needResult := s.w.IsRegistered(id) - if needResult || !noSideEffect(&raftReq) { - if !needResult && raftReq.Txn != nil { - removeNeedlessRangeReqs(raftReq.Txn) - } - ar = s.applyV3.Apply(&raftReq, shouldApplyV3) - } - - // do not re-apply applied entries. - if !shouldApplyV3 { - return - } - - if ar == nil { - return - } - - if ar.err != ErrNoSpace || len(s.alarmStore.Get(pb.AlarmType_NOSPACE)) > 0 { - s.w.Trigger(id, ar) - return - } - - lg := s.Logger() - lg.Warn( - "message exceeded backend quota; raising alarm", - zap.Int64("quota-size-bytes", s.Cfg.QuotaBackendBytes), - zap.String("quota-size", humanize.Bytes(uint64(s.Cfg.QuotaBackendBytes))), - zap.Error(ar.err), - ) - - s.GoAttach(func() { - a := &pb.AlarmRequest{ - MemberID: uint64(s.ID()), - Action: pb.AlarmRequest_ACTIVATE, - Alarm: pb.AlarmType_NOSPACE, - } - s.raftRequest(s.ctx, pb.InternalRaftRequest{Alarm: a}) - s.w.Trigger(id, ar) - }) -} - -func (s *EtcdServer) notifyAboutFirstCommitInTerm() { - newNotifier := make(chan struct{}) - s.firstCommitInTermMu.Lock() - notifierToClose := s.firstCommitInTermC - s.firstCommitInTermC = newNotifier - s.firstCommitInTermMu.Unlock() - close(notifierToClose) -} - -// applyConfChange applies a ConfChange to the server. It is only -// invoked with a ConfChange that has already passed through Raft -func (s *EtcdServer) applyConfChange(cc raftpb.ConfChange, confState *raftpb.ConfState, shouldApplyV3 membership.ShouldApplyV3) (bool, error) { - if err := s.cluster.ValidateConfigurationChange(cc); err != nil { - cc.NodeID = raft.None - s.r.ApplyConfChange(cc) - return false, err - } - - lg := s.Logger() - *confState = *s.r.ApplyConfChange(cc) - s.beHooks.SetConfState(confState) - switch cc.Type { - case raftpb.ConfChangeAddNode, raftpb.ConfChangeAddLearnerNode: - confChangeContext := new(membership.ConfigChangeContext) - if err := json.Unmarshal(cc.Context, confChangeContext); err != nil { - lg.Panic("failed to unmarshal member", zap.Error(err)) - } - if cc.NodeID != uint64(confChangeContext.Member.ID) { - lg.Panic( - "got different member ID", - zap.String("member-id-from-config-change-entry", types.ID(cc.NodeID).String()), - zap.String("member-id-from-message", confChangeContext.Member.ID.String()), - ) - } - if confChangeContext.IsPromote { - s.cluster.PromoteMember(confChangeContext.Member.ID, shouldApplyV3) - } else { - s.cluster.AddMember(&confChangeContext.Member, shouldApplyV3) - - if confChangeContext.Member.ID != s.id { - s.r.transport.AddPeer(confChangeContext.Member.ID, confChangeContext.PeerURLs) - } - } - - // update the isLearner metric when this server id is equal to the id in raft member confChange - if confChangeContext.Member.ID == s.id { - if cc.Type == raftpb.ConfChangeAddLearnerNode { - isLearner.Set(1) - } else { - isLearner.Set(0) - } - } - - case raftpb.ConfChangeRemoveNode: - id := types.ID(cc.NodeID) - s.cluster.RemoveMember(id, shouldApplyV3) - if id == s.id { - return true, nil - } - s.r.transport.RemovePeer(id) - - case raftpb.ConfChangeUpdateNode: - m := new(membership.Member) - if err := json.Unmarshal(cc.Context, m); err != nil { - lg.Panic("failed to unmarshal member", zap.Error(err)) - } - if cc.NodeID != uint64(m.ID) { - lg.Panic( - "got different member ID", - zap.String("member-id-from-config-change-entry", types.ID(cc.NodeID).String()), - zap.String("member-id-from-message", m.ID.String()), - ) - } - s.cluster.UpdateRaftAttributes(m.ID, m.RaftAttributes, shouldApplyV3) - if m.ID != s.id { - s.r.transport.UpdatePeer(m.ID, m.PeerURLs) - } - } - return false, nil -} - -// TODO: non-blocking snapshot -func (s *EtcdServer) snapshot(snapi uint64, confState raftpb.ConfState) { - clone := s.v2store.Clone() - // commit kv to write metadata (for example: consistent index) to disk. - // - // This guarantees that Backend's consistent_index is >= index of last snapshot. - // - // KV().commit() updates the consistent index in backend. - // All operations that update consistent index must be called sequentially - // from applyAll function. - // So KV().Commit() cannot run in parallel with apply. It has to be called outside - // the go routine created below. - s.KV().Commit() - - s.GoAttach(func() { - lg := s.Logger() - - d, err := clone.SaveNoCopy() - // TODO: current store will never fail to do a snapshot - // what should we do if the store might fail? - if err != nil { - lg.Panic("failed to save v2 store", zap.Error(err)) - } - snap, err := s.r.raftStorage.CreateSnapshot(snapi, &confState, d) - if err != nil { - // the snapshot was done asynchronously with the progress of raft. - // raft might have already got a newer snapshot. - if err == raft.ErrSnapOutOfDate { - return - } - lg.Panic("failed to create snapshot", zap.Error(err)) - } - // SaveSnap saves the snapshot to file and appends the corresponding WAL entry. - if err = s.r.storage.SaveSnap(snap); err != nil { - lg.Panic("failed to save snapshot", zap.Error(err)) - } - if err = s.r.storage.Release(snap); err != nil { - lg.Panic("failed to release wal", zap.Error(err)) - } - - lg.Info( - "saved snapshot", - zap.Uint64("snapshot-index", snap.Metadata.Index), - ) - - // When sending a snapshot, etcd will pause compaction. - // After receives a snapshot, the slow follower needs to get all the entries right after - // the snapshot sent to catch up. If we do not pause compaction, the log entries right after - // the snapshot sent might already be compacted. It happens when the snapshot takes long time - // to send and save. Pausing compaction avoids triggering a snapshot sending cycle. - if atomic.LoadInt64(&s.inflightSnapshots) != 0 { - lg.Info("skip compaction since there is an inflight snapshot") - return - } - - // keep some in memory log entries for slow followers. - compacti := uint64(1) - if snapi > s.Cfg.SnapshotCatchUpEntries { - compacti = snapi - s.Cfg.SnapshotCatchUpEntries - } - - err = s.r.raftStorage.Compact(compacti) - if err != nil { - // the compaction was done asynchronously with the progress of raft. - // raft log might already been compact. - if err == raft.ErrCompacted { - return - } - lg.Panic("failed to compact", zap.Error(err)) - } - lg.Info( - "compacted Raft logs", - zap.Uint64("compact-index", compacti), - ) - }) -} - -// CutPeer drops messages to the specified peer. -func (s *EtcdServer) CutPeer(id types.ID) { - tr, ok := s.r.transport.(*rafthttp.Transport) - if ok { - tr.CutPeer(id) - } -} - -// MendPeer recovers the message dropping behavior of the given peer. -func (s *EtcdServer) MendPeer(id types.ID) { - tr, ok := s.r.transport.(*rafthttp.Transport) - if ok { - tr.MendPeer(id) - } -} - -func (s *EtcdServer) PauseSending() { s.r.pauseSending() } - -func (s *EtcdServer) ResumeSending() { s.r.resumeSending() } - -func (s *EtcdServer) ClusterVersion() *semver.Version { - if s.cluster == nil { - return nil - } - return s.cluster.Version() -} - -// monitorVersions checks the member's version every monitorVersionInterval. -// It updates the cluster version if all members agrees on a higher one. -// It prints out log if there is a member with a higher version than the -// local version. -// TODO switch to updateClusterVersionV3 in 3.6 -func (s *EtcdServer) monitorVersions() { - for { - select { - case <-s.FirstCommitInTermNotify(): - case <-time.After(monitorVersionInterval): - case <-s.stopping: - return - } - - if s.Leader() != s.ID() { - continue - } - - v := decideClusterVersion(s.Logger(), getVersions(s.Logger(), s.cluster, s.id, s.peerRt)) - if v != nil { - // only keep major.minor version for comparison - v = &semver.Version{ - Major: v.Major, - Minor: v.Minor, - } - } - - // if the current version is nil: - // 1. use the decided version if possible - // 2. or use the min cluster version - if s.cluster.Version() == nil { - verStr := version.MinClusterVersion - if v != nil { - verStr = v.String() - } - s.GoAttach(func() { s.updateClusterVersionV2(verStr) }) - continue - } - - if v != nil && membership.IsValidVersionChange(s.cluster.Version(), v) { - s.GoAttach(func() { s.updateClusterVersionV2(v.String()) }) - } - } -} - -func (s *EtcdServer) updateClusterVersionV2(ver string) { - lg := s.Logger() - - if s.cluster.Version() == nil { - lg.Info( - "setting up initial cluster version using v2 API", - zap.String("cluster-version", version.Cluster(ver)), - ) - } else { - lg.Info( - "updating cluster version using v2 API", - zap.String("from", version.Cluster(s.cluster.Version().String())), - zap.String("to", version.Cluster(ver)), - ) - } - - req := pb.Request{ - Method: "PUT", - Path: membership.StoreClusterVersionKey(), - Val: ver, - } - - ctx, cancel := context.WithTimeout(s.ctx, s.Cfg.ReqTimeout()) - _, err := s.Do(ctx, req) - cancel() - - switch err { - case nil: - lg.Info("cluster version is updated", zap.String("cluster-version", version.Cluster(ver))) - return - - case ErrStopped: - lg.Warn("aborting cluster version update; server is stopped", zap.Error(err)) - return - - default: - lg.Warn("failed to update cluster version", zap.Error(err)) - } -} - -func (s *EtcdServer) updateClusterVersionV3(ver string) { - lg := s.Logger() - - if s.cluster.Version() == nil { - lg.Info( - "setting up initial cluster version using v3 API", - zap.String("cluster-version", version.Cluster(ver)), - ) - } else { - lg.Info( - "updating cluster version using v3 API", - zap.String("from", version.Cluster(s.cluster.Version().String())), - zap.String("to", version.Cluster(ver)), - ) - } - - req := membershippb.ClusterVersionSetRequest{Ver: ver} - - ctx, cancel := context.WithTimeout(s.ctx, s.Cfg.ReqTimeout()) - _, err := s.raftRequest(ctx, pb.InternalRaftRequest{ClusterVersionSet: &req}) - cancel() - - switch err { - case nil: - lg.Info("cluster version is updated", zap.String("cluster-version", version.Cluster(ver))) - return - - case ErrStopped: - lg.Warn("aborting cluster version update; server is stopped", zap.Error(err)) - return - - default: - lg.Warn("failed to update cluster version", zap.Error(err)) - } -} - -func (s *EtcdServer) monitorDowngrade() { - t := s.Cfg.DowngradeCheckTime - if t == 0 { - return - } - lg := s.Logger() - for { - select { - case <-time.After(t): - case <-s.stopping: - return - } - - if !s.isLeader() { - continue - } - - d := s.cluster.DowngradeInfo() - if !d.Enabled { - continue - } - - targetVersion := d.TargetVersion - v := semver.Must(semver.NewVersion(targetVersion)) - if isMatchedVersions(s.Logger(), v, getVersions(s.Logger(), s.cluster, s.id, s.peerRt)) { - lg.Info("the cluster has been downgraded", zap.String("cluster-version", targetVersion)) - ctx, cancel := context.WithTimeout(context.Background(), s.Cfg.ReqTimeout()) - if _, err := s.downgradeCancel(ctx); err != nil { - lg.Warn("failed to cancel downgrade", zap.Error(err)) - } - cancel() - } - } -} - -func (s *EtcdServer) parseProposeCtxErr(err error, start time.Time) error { - switch err { - case context.Canceled: - return ErrCanceled - - case context.DeadlineExceeded: - s.leadTimeMu.RLock() - curLeadElected := s.leadElectedTime - s.leadTimeMu.RUnlock() - prevLeadLost := curLeadElected.Add(-2 * time.Duration(s.Cfg.ElectionTicks) * time.Duration(s.Cfg.TickMs) * time.Millisecond) - if start.After(prevLeadLost) && start.Before(curLeadElected) { - return ErrTimeoutDueToLeaderFail - } - lead := types.ID(s.getLead()) - switch lead { - case types.ID(raft.None): - // TODO: return error to specify it happens because the cluster does not have leader now - case s.ID(): - if !isConnectedToQuorumSince(s.r.transport, start, s.ID(), s.cluster.Members()) { - return ErrTimeoutDueToConnectionLost - } - default: - if !isConnectedSince(s.r.transport, start, lead) { - return ErrTimeoutDueToConnectionLost - } - } - return ErrTimeout - - default: - return err - } -} - -func (s *EtcdServer) KV() mvcc.WatchableKV { return s.kv } -func (s *EtcdServer) Backend() backend.Backend { - s.bemu.Lock() - defer s.bemu.Unlock() - return s.be -} - -func (s *EtcdServer) AuthStore() auth.AuthStore { return s.authStore } - -func (s *EtcdServer) restoreAlarms() error { - s.applyV3 = s.newApplierV3() - as, err := v3alarm.NewAlarmStore(s.lg, s) - if err != nil { - return err - } - s.alarmStore = as - if len(as.Get(pb.AlarmType_NOSPACE)) > 0 { - s.applyV3 = newApplierV3Capped(s.applyV3) - } - if len(as.Get(pb.AlarmType_CORRUPT)) > 0 { - s.applyV3 = newApplierV3Corrupt(s.applyV3) - } - return nil -} - -// GoAttach creates a goroutine on a given function and tracks it using -// the etcdserver waitgroup. -// The passed function should interrupt on s.StoppingNotify(). -func (s *EtcdServer) GoAttach(f func()) { - s.wgMu.RLock() // this blocks with ongoing close(s.stopping) - defer s.wgMu.RUnlock() - select { - case <-s.stopping: - lg := s.Logger() - lg.Warn("server has stopped; skipping GoAttach") - return - default: - } - - // now safe to add since waitgroup wait has not started yet - s.wg.Add(1) - go func() { - defer s.wg.Done() - f() - }() -} - -func (s *EtcdServer) Alarms() []*pb.AlarmMember { - return s.alarmStore.Get(pb.AlarmType_NONE) -} - -// IsLearner returns if the local member is raft learner -func (s *EtcdServer) IsLearner() bool { - return s.cluster.IsLocalMemberLearner() -} - -// IsMemberExist returns if the member with the given id exists in cluster. -func (s *EtcdServer) IsMemberExist(id types.ID) bool { - return s.cluster.IsMemberExist(id) -} - -// raftStatus returns the raft status of this etcd node. -func (s *EtcdServer) raftStatus() raft.Status { - return s.r.Node.Status() -} - -func maybeDefragBackend(cfg config.ServerConfig, be backend.Backend) error { - size := be.Size() - sizeInUse := be.SizeInUse() - freeableMemory := uint(size - sizeInUse) - thresholdBytes := cfg.ExperimentalBootstrapDefragThresholdMegabytes * 1024 * 1024 - if freeableMemory < thresholdBytes { - cfg.Logger.Info("Skipping defragmentation", - zap.Int64("current-db-size-bytes", size), - zap.String("current-db-size", humanize.Bytes(uint64(size))), - zap.Int64("current-db-size-in-use-bytes", sizeInUse), - zap.String("current-db-size-in-use", humanize.Bytes(uint64(sizeInUse))), - zap.Uint("experimental-bootstrap-defrag-threshold-bytes", thresholdBytes), - zap.String("experimental-bootstrap-defrag-threshold", humanize.Bytes(uint64(thresholdBytes))), - ) - return nil - } - return be.Defrag() -} diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/server_access_control.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/server_access_control.go deleted file mode 100644 index 09e2255ccc..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/server_access_control.go +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright 2018 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package etcdserver - -import "sync" - -// AccessController controls etcd server HTTP request access. -type AccessController struct { - corsMu sync.RWMutex - CORS map[string]struct{} - hostWhitelistMu sync.RWMutex - HostWhitelist map[string]struct{} -} - -// NewAccessController returns a new "AccessController" with default "*" values. -func NewAccessController() *AccessController { - return &AccessController{ - CORS: map[string]struct{}{"*": {}}, - HostWhitelist: map[string]struct{}{"*": {}}, - } -} - -// OriginAllowed determines whether the server will allow a given CORS origin. -// If CORS is empty, allow all. -func (ac *AccessController) OriginAllowed(origin string) bool { - ac.corsMu.RLock() - defer ac.corsMu.RUnlock() - if len(ac.CORS) == 0 { // allow all - return true - } - _, ok := ac.CORS["*"] - if ok { - return true - } - _, ok = ac.CORS[origin] - return ok -} - -// IsHostWhitelisted returns true if the host is whitelisted. -// If whitelist is empty, allow all. -func (ac *AccessController) IsHostWhitelisted(host string) bool { - ac.hostWhitelistMu.RLock() - defer ac.hostWhitelistMu.RUnlock() - if len(ac.HostWhitelist) == 0 { // allow all - return true - } - _, ok := ac.HostWhitelist["*"] - if ok { - return true - } - _, ok = ac.HostWhitelist[host] - return ok -} diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/snapshot_merge.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/snapshot_merge.go deleted file mode 100644 index 72d10c1796..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/snapshot_merge.go +++ /dev/null @@ -1,85 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package etcdserver - -import ( - "io" - - "go.etcd.io/etcd/raft/v3/raftpb" - "go.etcd.io/etcd/server/v3/etcdserver/api/snap" - "go.etcd.io/etcd/server/v3/mvcc/backend" - - humanize "github.com/dustin/go-humanize" - "go.uber.org/zap" -) - -// createMergedSnapshotMessage creates a snapshot message that contains: raft status (term, conf), -// a snapshot of v2 store inside raft.Snapshot as []byte, a snapshot of v3 KV in the top level message -// as ReadCloser. -func (s *EtcdServer) createMergedSnapshotMessage(m raftpb.Message, snapt, snapi uint64, confState raftpb.ConfState) snap.Message { - lg := s.Logger() - // get a snapshot of v2 store as []byte - clone := s.v2store.Clone() - d, err := clone.SaveNoCopy() - if err != nil { - lg.Panic("failed to save v2 store data", zap.Error(err)) - } - - // commit kv to write metadata(for example: consistent index). - s.KV().Commit() - dbsnap := s.be.Snapshot() - // get a snapshot of v3 KV as readCloser - rc := newSnapshotReaderCloser(lg, dbsnap) - - // put the []byte snapshot of store into raft snapshot and return the merged snapshot with - // KV readCloser snapshot. - snapshot := raftpb.Snapshot{ - Metadata: raftpb.SnapshotMetadata{ - Index: snapi, - Term: snapt, - ConfState: confState, - }, - Data: d, - } - m.Snapshot = snapshot - - return *snap.NewMessage(m, rc, dbsnap.Size()) -} - -func newSnapshotReaderCloser(lg *zap.Logger, snapshot backend.Snapshot) io.ReadCloser { - pr, pw := io.Pipe() - go func() { - n, err := snapshot.WriteTo(pw) - if err == nil { - lg.Info( - "sent database snapshot to writer", - zap.Int64("bytes", n), - zap.String("size", humanize.Bytes(uint64(n))), - ) - } else { - lg.Warn( - "failed to send database snapshot to writer", - zap.String("size", humanize.Bytes(uint64(n))), - zap.Error(err), - ) - } - pw.CloseWithError(err) - err = snapshot.Close() - if err != nil { - lg.Panic("failed to close database snapshot", zap.Error(err)) - } - }() - return pr -} diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/storage.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/storage.go deleted file mode 100644 index e662537d36..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/storage.go +++ /dev/null @@ -1,121 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package etcdserver - -import ( - "io" - - pb "go.etcd.io/etcd/api/v3/etcdserverpb" - "go.etcd.io/etcd/client/pkg/v3/types" - "go.etcd.io/etcd/pkg/v3/pbutil" - "go.etcd.io/etcd/raft/v3/raftpb" - "go.etcd.io/etcd/server/v3/etcdserver/api/snap" - "go.etcd.io/etcd/server/v3/wal" - "go.etcd.io/etcd/server/v3/wal/walpb" - - "go.uber.org/zap" -) - -type Storage interface { - // Save function saves ents and state to the underlying stable storage. - // Save MUST block until st and ents are on stable storage. - Save(st raftpb.HardState, ents []raftpb.Entry) error - // SaveSnap function saves snapshot to the underlying stable storage. - SaveSnap(snap raftpb.Snapshot) error - // Close closes the Storage and performs finalization. - Close() error - // Release releases the locked wal files older than the provided snapshot. - Release(snap raftpb.Snapshot) error - // Sync WAL - Sync() error -} - -type storage struct { - *wal.WAL - *snap.Snapshotter -} - -func NewStorage(w *wal.WAL, s *snap.Snapshotter) Storage { - return &storage{w, s} -} - -// SaveSnap saves the snapshot file to disk and writes the WAL snapshot entry. -func (st *storage) SaveSnap(snap raftpb.Snapshot) error { - walsnap := walpb.Snapshot{ - Index: snap.Metadata.Index, - Term: snap.Metadata.Term, - ConfState: &snap.Metadata.ConfState, - } - // save the snapshot file before writing the snapshot to the wal. - // This makes it possible for the snapshot file to become orphaned, but prevents - // a WAL snapshot entry from having no corresponding snapshot file. - err := st.Snapshotter.SaveSnap(snap) - if err != nil { - return err - } - // gofail: var raftBeforeWALSaveSnaphot struct{} - - return st.WAL.SaveSnapshot(walsnap) -} - -// Release releases resources older than the given snap and are no longer needed: -// - releases the locks to the wal files that are older than the provided wal for the given snap. -// - deletes any .snap.db files that are older than the given snap. -func (st *storage) Release(snap raftpb.Snapshot) error { - if err := st.WAL.ReleaseLockTo(snap.Metadata.Index); err != nil { - return err - } - return st.Snapshotter.ReleaseSnapDBs(snap) -} - -// readWAL reads the WAL at the given snap and returns the wal, its latest HardState and cluster ID, and all entries that appear -// after the position of the given snap in the WAL. -// The snap must have been previously saved to the WAL, or this call will panic. -func readWAL(lg *zap.Logger, waldir string, snap walpb.Snapshot, unsafeNoFsync bool) (w *wal.WAL, id, cid types.ID, st raftpb.HardState, ents []raftpb.Entry) { - var ( - err error - wmetadata []byte - ) - - repaired := false - for { - if w, err = wal.Open(lg, waldir, snap); err != nil { - lg.Fatal("failed to open WAL", zap.Error(err)) - } - if unsafeNoFsync { - w.SetUnsafeNoFsync() - } - if wmetadata, st, ents, err = w.ReadAll(); err != nil { - w.Close() - // we can only repair ErrUnexpectedEOF and we never repair twice. - if repaired || err != io.ErrUnexpectedEOF { - lg.Fatal("failed to read WAL, cannot be repaired", zap.Error(err)) - } - if !wal.Repair(lg, waldir) { - lg.Fatal("failed to repair WAL", zap.Error(err)) - } else { - lg.Info("repaired WAL", zap.Error(err)) - repaired = true - } - continue - } - break - } - var metadata pb.Metadata - pbutil.MustUnmarshal(&metadata, wmetadata) - id = types.ID(metadata.NodeID) - cid = types.ID(metadata.ClusterID) - return w, id, cid, st, ents -} diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/util.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/util.go deleted file mode 100644 index 6ad5f0f4c6..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/util.go +++ /dev/null @@ -1,198 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package etcdserver - -import ( - "fmt" - "reflect" - "strings" - "time" - - "github.com/golang/protobuf/proto" - pb "go.etcd.io/etcd/api/v3/etcdserverpb" - "go.etcd.io/etcd/client/pkg/v3/types" - "go.etcd.io/etcd/server/v3/etcdserver/api/membership" - "go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp" - - "go.uber.org/zap" -) - -// isConnectedToQuorumSince checks whether the local member is connected to the -// quorum of the cluster since the given time. -func isConnectedToQuorumSince(transport rafthttp.Transporter, since time.Time, self types.ID, members []*membership.Member) bool { - return numConnectedSince(transport, since, self, members) >= (len(members)/2)+1 -} - -// isConnectedSince checks whether the local member is connected to the -// remote member since the given time. -func isConnectedSince(transport rafthttp.Transporter, since time.Time, remote types.ID) bool { - t := transport.ActiveSince(remote) - return !t.IsZero() && t.Before(since) -} - -// isConnectedFullySince checks whether the local member is connected to all -// members in the cluster since the given time. -func isConnectedFullySince(transport rafthttp.Transporter, since time.Time, self types.ID, members []*membership.Member) bool { - return numConnectedSince(transport, since, self, members) == len(members) -} - -// numConnectedSince counts how many members are connected to the local member -// since the given time. -func numConnectedSince(transport rafthttp.Transporter, since time.Time, self types.ID, members []*membership.Member) int { - connectedNum := 0 - for _, m := range members { - if m.ID == self || isConnectedSince(transport, since, m.ID) { - connectedNum++ - } - } - return connectedNum -} - -// longestConnected chooses the member with longest active-since-time. -// It returns false, if nothing is active. -func longestConnected(tp rafthttp.Transporter, membs []types.ID) (types.ID, bool) { - var longest types.ID - var oldest time.Time - for _, id := range membs { - tm := tp.ActiveSince(id) - if tm.IsZero() { // inactive - continue - } - - if oldest.IsZero() { // first longest candidate - oldest = tm - longest = id - } - - if tm.Before(oldest) { - oldest = tm - longest = id - } - } - if uint64(longest) == 0 { - return longest, false - } - return longest, true -} - -type notifier struct { - c chan struct{} - err error -} - -func newNotifier() *notifier { - return ¬ifier{ - c: make(chan struct{}), - } -} - -func (nc *notifier) notify(err error) { - nc.err = err - close(nc.c) -} - -func warnOfExpensiveRequest(lg *zap.Logger, warningApplyDuration time.Duration, now time.Time, reqStringer fmt.Stringer, respMsg proto.Message, err error) { - if time.Since(now) <= warningApplyDuration { - return - } - var resp string - if !isNil(respMsg) { - resp = fmt.Sprintf("size:%d", proto.Size(respMsg)) - } - warnOfExpensiveGenericRequest(lg, warningApplyDuration, now, reqStringer, "", resp, err) -} - -func warnOfFailedRequest(lg *zap.Logger, now time.Time, reqStringer fmt.Stringer, respMsg proto.Message, err error) { - var resp string - if !isNil(respMsg) { - resp = fmt.Sprintf("size:%d", proto.Size(respMsg)) - } - d := time.Since(now) - lg.Warn( - "failed to apply request", - zap.Duration("took", d), - zap.String("request", reqStringer.String()), - zap.String("response", resp), - zap.Error(err), - ) -} - -func warnOfExpensiveReadOnlyTxnRequest(lg *zap.Logger, warningApplyDuration time.Duration, now time.Time, r *pb.TxnRequest, txnResponse *pb.TxnResponse, err error) { - if time.Since(now) <= warningApplyDuration { - return - } - reqStringer := pb.NewLoggableTxnRequest(r) - var resp string - if !isNil(txnResponse) { - var resps []string - for _, r := range txnResponse.Responses { - switch op := r.Response.(type) { - case *pb.ResponseOp_ResponseRange: - resps = append(resps, fmt.Sprintf("range_response_count:%d", len(op.ResponseRange.Kvs))) - default: - // only range responses should be in a read only txn request - } - } - resp = fmt.Sprintf("responses:<%s> size:%d", strings.Join(resps, " "), txnResponse.Size()) - } - warnOfExpensiveGenericRequest(lg, warningApplyDuration, now, reqStringer, "read-only txn ", resp, err) -} - -func warnOfExpensiveReadOnlyRangeRequest(lg *zap.Logger, warningApplyDuration time.Duration, now time.Time, reqStringer fmt.Stringer, rangeResponse *pb.RangeResponse, err error) { - if time.Since(now) <= warningApplyDuration { - return - } - var resp string - if !isNil(rangeResponse) { - resp = fmt.Sprintf("range_response_count:%d size:%d", len(rangeResponse.Kvs), rangeResponse.Size()) - } - warnOfExpensiveGenericRequest(lg, warningApplyDuration, now, reqStringer, "read-only range ", resp, err) -} - -// callers need make sure time has passed warningApplyDuration -func warnOfExpensiveGenericRequest(lg *zap.Logger, warningApplyDuration time.Duration, now time.Time, reqStringer fmt.Stringer, prefix string, resp string, err error) { - lg.Warn( - "apply request took too long", - zap.Duration("took", time.Since(now)), - zap.Duration("expected-duration", warningApplyDuration), - zap.String("prefix", prefix), - zap.String("request", reqStringer.String()), - zap.String("response", resp), - zap.Error(err), - ) - slowApplies.Inc() -} - -func isNil(msg proto.Message) bool { - return msg == nil || reflect.ValueOf(msg).IsNil() -} - -// panicAlternativeStringer wraps a fmt.Stringer, and if calling String() panics, calls the alternative instead. -// This is needed to ensure logging slow v2 requests does not panic, which occurs when running integration tests -// with the embedded server with github.com/golang/protobuf v1.4.0+. See https://github.com/etcd-io/etcd/issues/12197. -type panicAlternativeStringer struct { - stringer fmt.Stringer - alternative func() string -} - -func (n panicAlternativeStringer) String() (s string) { - defer func() { - if err := recover(); err != nil { - s = n.alternative() - } - }() - s = n.stringer.String() - return s -} diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/v2_server.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/v2_server.go deleted file mode 100644 index 24c97c924a..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/v2_server.go +++ /dev/null @@ -1,166 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package etcdserver - -import ( - "context" - "time" - - pb "go.etcd.io/etcd/api/v3/etcdserverpb" - "go.etcd.io/etcd/server/v3/etcdserver/api/membership" - "go.etcd.io/etcd/server/v3/etcdserver/api/v2store" -) - -type RequestV2 pb.Request - -type RequestV2Handler interface { - Post(ctx context.Context, r *RequestV2) (Response, error) - Put(ctx context.Context, r *RequestV2) (Response, error) - Delete(ctx context.Context, r *RequestV2) (Response, error) - QGet(ctx context.Context, r *RequestV2) (Response, error) - Get(ctx context.Context, r *RequestV2) (Response, error) - Head(ctx context.Context, r *RequestV2) (Response, error) -} - -type reqV2HandlerEtcdServer struct { - reqV2HandlerStore - s *EtcdServer -} - -type reqV2HandlerStore struct { - store v2store.Store - applier ApplierV2 -} - -func NewStoreRequestV2Handler(s v2store.Store, applier ApplierV2) RequestV2Handler { - return &reqV2HandlerStore{s, applier} -} - -func (a *reqV2HandlerStore) Post(ctx context.Context, r *RequestV2) (Response, error) { - return a.applier.Post(r), nil -} - -func (a *reqV2HandlerStore) Put(ctx context.Context, r *RequestV2) (Response, error) { - return a.applier.Put(r, membership.ApplyBoth), nil -} - -func (a *reqV2HandlerStore) Delete(ctx context.Context, r *RequestV2) (Response, error) { - return a.applier.Delete(r), nil -} - -func (a *reqV2HandlerStore) QGet(ctx context.Context, r *RequestV2) (Response, error) { - return a.applier.QGet(r), nil -} - -func (a *reqV2HandlerStore) Get(ctx context.Context, r *RequestV2) (Response, error) { - if r.Wait { - wc, err := a.store.Watch(r.Path, r.Recursive, r.Stream, r.Since) - return Response{Watcher: wc}, err - } - ev, err := a.store.Get(r.Path, r.Recursive, r.Sorted) - return Response{Event: ev}, err -} - -func (a *reqV2HandlerStore) Head(ctx context.Context, r *RequestV2) (Response, error) { - ev, err := a.store.Get(r.Path, r.Recursive, r.Sorted) - return Response{Event: ev}, err -} - -func (a *reqV2HandlerEtcdServer) Post(ctx context.Context, r *RequestV2) (Response, error) { - return a.processRaftRequest(ctx, r) -} - -func (a *reqV2HandlerEtcdServer) Put(ctx context.Context, r *RequestV2) (Response, error) { - return a.processRaftRequest(ctx, r) -} - -func (a *reqV2HandlerEtcdServer) Delete(ctx context.Context, r *RequestV2) (Response, error) { - return a.processRaftRequest(ctx, r) -} - -func (a *reqV2HandlerEtcdServer) QGet(ctx context.Context, r *RequestV2) (Response, error) { - return a.processRaftRequest(ctx, r) -} - -func (a *reqV2HandlerEtcdServer) processRaftRequest(ctx context.Context, r *RequestV2) (Response, error) { - data, err := ((*pb.Request)(r)).Marshal() - if err != nil { - return Response{}, err - } - ch := a.s.w.Register(r.ID) - - start := time.Now() - a.s.r.Propose(ctx, data) - proposalsPending.Inc() - defer proposalsPending.Dec() - - select { - case x := <-ch: - resp := x.(Response) - return resp, resp.Err - case <-ctx.Done(): - proposalsFailed.Inc() - a.s.w.Trigger(r.ID, nil) // GC wait - return Response{}, a.s.parseProposeCtxErr(ctx.Err(), start) - case <-a.s.stopping: - } - return Response{}, ErrStopped -} - -func (s *EtcdServer) Do(ctx context.Context, r pb.Request) (Response, error) { - r.ID = s.reqIDGen.Next() - h := &reqV2HandlerEtcdServer{ - reqV2HandlerStore: reqV2HandlerStore{ - store: s.v2store, - applier: s.applyV2, - }, - s: s, - } - rp := &r - resp, err := ((*RequestV2)(rp)).Handle(ctx, h) - resp.Term, resp.Index = s.Term(), s.CommittedIndex() - return resp, err -} - -// Handle interprets r and performs an operation on s.store according to r.Method -// and other fields. If r.Method is "POST", "PUT", "DELETE", or a "GET" with -// Quorum == true, r will be sent through consensus before performing its -// respective operation. Do will block until an action is performed or there is -// an error. -func (r *RequestV2) Handle(ctx context.Context, v2api RequestV2Handler) (Response, error) { - if r.Method == "GET" && r.Quorum { - r.Method = "QGET" - } - switch r.Method { - case "POST": - return v2api.Post(ctx, r) - case "PUT": - return v2api.Put(ctx, r) - case "DELETE": - return v2api.Delete(ctx, r) - case "QGET": - return v2api.QGet(ctx, r) - case "GET": - return v2api.Get(ctx, r) - case "HEAD": - return v2api.Head(ctx, r) - } - return Response{}, ErrUnknownMethod -} - -func (r *RequestV2) String() string { - rpb := pb.Request(*r) - return rpb.String() -} diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/v3_server.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/v3_server.go deleted file mode 100644 index 442288a6ee..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/v3_server.go +++ /dev/null @@ -1,991 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package etcdserver - -import ( - "bytes" - "context" - "encoding/base64" - "encoding/binary" - "strconv" - "time" - - pb "go.etcd.io/etcd/api/v3/etcdserverpb" - "go.etcd.io/etcd/api/v3/membershippb" - "go.etcd.io/etcd/pkg/v3/traceutil" - "go.etcd.io/etcd/raft/v3" - "go.etcd.io/etcd/server/v3/auth" - "go.etcd.io/etcd/server/v3/etcdserver/api/membership" - "go.etcd.io/etcd/server/v3/lease" - "go.etcd.io/etcd/server/v3/lease/leasehttp" - "go.etcd.io/etcd/server/v3/mvcc" - - "github.com/gogo/protobuf/proto" - "go.uber.org/zap" - "golang.org/x/crypto/bcrypt" -) - -const ( - // In the health case, there might be a small gap (10s of entries) between - // the applied index and committed index. - // However, if the committed entries are very heavy to apply, the gap might grow. - // We should stop accepting new proposals if the gap growing to a certain point. - maxGapBetweenApplyAndCommitIndex = 5000 - traceThreshold = 100 * time.Millisecond - readIndexRetryTime = 500 * time.Millisecond -) - -type RaftKV interface { - Range(ctx context.Context, r *pb.RangeRequest) (*pb.RangeResponse, error) - Put(ctx context.Context, r *pb.PutRequest) (*pb.PutResponse, error) - DeleteRange(ctx context.Context, r *pb.DeleteRangeRequest) (*pb.DeleteRangeResponse, error) - Txn(ctx context.Context, r *pb.TxnRequest) (*pb.TxnResponse, error) - Compact(ctx context.Context, r *pb.CompactionRequest) (*pb.CompactionResponse, error) -} - -type Lessor interface { - // LeaseGrant sends LeaseGrant request to raft and apply it after committed. - LeaseGrant(ctx context.Context, r *pb.LeaseGrantRequest) (*pb.LeaseGrantResponse, error) - // LeaseRevoke sends LeaseRevoke request to raft and apply it after committed. - LeaseRevoke(ctx context.Context, r *pb.LeaseRevokeRequest) (*pb.LeaseRevokeResponse, error) - - // LeaseRenew renews the lease with given ID. The renewed TTL is returned. Or an error - // is returned. - LeaseRenew(ctx context.Context, id lease.LeaseID) (int64, error) - - // LeaseTimeToLive retrieves lease information. - LeaseTimeToLive(ctx context.Context, r *pb.LeaseTimeToLiveRequest) (*pb.LeaseTimeToLiveResponse, error) - - // LeaseLeases lists all leases. - LeaseLeases(ctx context.Context, r *pb.LeaseLeasesRequest) (*pb.LeaseLeasesResponse, error) -} - -type Authenticator interface { - AuthEnable(ctx context.Context, r *pb.AuthEnableRequest) (*pb.AuthEnableResponse, error) - AuthDisable(ctx context.Context, r *pb.AuthDisableRequest) (*pb.AuthDisableResponse, error) - AuthStatus(ctx context.Context, r *pb.AuthStatusRequest) (*pb.AuthStatusResponse, error) - Authenticate(ctx context.Context, r *pb.AuthenticateRequest) (*pb.AuthenticateResponse, error) - UserAdd(ctx context.Context, r *pb.AuthUserAddRequest) (*pb.AuthUserAddResponse, error) - UserDelete(ctx context.Context, r *pb.AuthUserDeleteRequest) (*pb.AuthUserDeleteResponse, error) - UserChangePassword(ctx context.Context, r *pb.AuthUserChangePasswordRequest) (*pb.AuthUserChangePasswordResponse, error) - UserGrantRole(ctx context.Context, r *pb.AuthUserGrantRoleRequest) (*pb.AuthUserGrantRoleResponse, error) - UserGet(ctx context.Context, r *pb.AuthUserGetRequest) (*pb.AuthUserGetResponse, error) - UserRevokeRole(ctx context.Context, r *pb.AuthUserRevokeRoleRequest) (*pb.AuthUserRevokeRoleResponse, error) - RoleAdd(ctx context.Context, r *pb.AuthRoleAddRequest) (*pb.AuthRoleAddResponse, error) - RoleGrantPermission(ctx context.Context, r *pb.AuthRoleGrantPermissionRequest) (*pb.AuthRoleGrantPermissionResponse, error) - RoleGet(ctx context.Context, r *pb.AuthRoleGetRequest) (*pb.AuthRoleGetResponse, error) - RoleRevokePermission(ctx context.Context, r *pb.AuthRoleRevokePermissionRequest) (*pb.AuthRoleRevokePermissionResponse, error) - RoleDelete(ctx context.Context, r *pb.AuthRoleDeleteRequest) (*pb.AuthRoleDeleteResponse, error) - UserList(ctx context.Context, r *pb.AuthUserListRequest) (*pb.AuthUserListResponse, error) - RoleList(ctx context.Context, r *pb.AuthRoleListRequest) (*pb.AuthRoleListResponse, error) -} - -func (s *EtcdServer) Range(ctx context.Context, r *pb.RangeRequest) (*pb.RangeResponse, error) { - trace := traceutil.New("range", - s.Logger(), - traceutil.Field{Key: "range_begin", Value: string(r.Key)}, - traceutil.Field{Key: "range_end", Value: string(r.RangeEnd)}, - ) - ctx = context.WithValue(ctx, traceutil.TraceKey, trace) - - var resp *pb.RangeResponse - var err error - defer func(start time.Time) { - warnOfExpensiveReadOnlyRangeRequest(s.Logger(), s.Cfg.WarningApplyDuration, start, r, resp, err) - if resp != nil { - trace.AddField( - traceutil.Field{Key: "response_count", Value: len(resp.Kvs)}, - traceutil.Field{Key: "response_revision", Value: resp.Header.Revision}, - ) - } - trace.LogIfLong(traceThreshold) - }(time.Now()) - - if !r.Serializable { - err = s.linearizableReadNotify(ctx) - trace.Step("agreement among raft nodes before linearized reading") - if err != nil { - return nil, err - } - } - chk := func(ai *auth.AuthInfo) error { - return s.authStore.IsRangePermitted(ai, r.Key, r.RangeEnd) - } - - get := func() { resp, err = s.applyV3Base.Range(ctx, nil, r) } - if serr := s.doSerialize(ctx, chk, get); serr != nil { - err = serr - return nil, err - } - return resp, err -} - -func (s *EtcdServer) Put(ctx context.Context, r *pb.PutRequest) (*pb.PutResponse, error) { - ctx = context.WithValue(ctx, traceutil.StartTimeKey, time.Now()) - resp, err := s.raftRequest(ctx, pb.InternalRaftRequest{Put: r}) - if err != nil { - return nil, err - } - return resp.(*pb.PutResponse), nil -} - -func (s *EtcdServer) DeleteRange(ctx context.Context, r *pb.DeleteRangeRequest) (*pb.DeleteRangeResponse, error) { - resp, err := s.raftRequest(ctx, pb.InternalRaftRequest{DeleteRange: r}) - if err != nil { - return nil, err - } - return resp.(*pb.DeleteRangeResponse), nil -} - -func (s *EtcdServer) Txn(ctx context.Context, r *pb.TxnRequest) (*pb.TxnResponse, error) { - if isTxnReadonly(r) { - trace := traceutil.New("transaction", - s.Logger(), - traceutil.Field{Key: "read_only", Value: true}, - ) - ctx = context.WithValue(ctx, traceutil.TraceKey, trace) - if !isTxnSerializable(r) { - err := s.linearizableReadNotify(ctx) - trace.Step("agreement among raft nodes before linearized reading") - if err != nil { - return nil, err - } - } - var resp *pb.TxnResponse - var err error - chk := func(ai *auth.AuthInfo) error { - return checkTxnAuth(s.authStore, ai, r) - } - - defer func(start time.Time) { - warnOfExpensiveReadOnlyTxnRequest(s.Logger(), s.Cfg.WarningApplyDuration, start, r, resp, err) - trace.LogIfLong(traceThreshold) - }(time.Now()) - - get := func() { resp, _, err = s.applyV3Base.Txn(ctx, r) } - if serr := s.doSerialize(ctx, chk, get); serr != nil { - return nil, serr - } - return resp, err - } - - ctx = context.WithValue(ctx, traceutil.StartTimeKey, time.Now()) - resp, err := s.raftRequest(ctx, pb.InternalRaftRequest{Txn: r}) - if err != nil { - return nil, err - } - return resp.(*pb.TxnResponse), nil -} - -func isTxnSerializable(r *pb.TxnRequest) bool { - for _, u := range r.Success { - if r := u.GetRequestRange(); r == nil || !r.Serializable { - return false - } - } - for _, u := range r.Failure { - if r := u.GetRequestRange(); r == nil || !r.Serializable { - return false - } - } - return true -} - -func isTxnReadonly(r *pb.TxnRequest) bool { - for _, u := range r.Success { - if r := u.GetRequestRange(); r == nil { - return false - } - } - for _, u := range r.Failure { - if r := u.GetRequestRange(); r == nil { - return false - } - } - return true -} - -func (s *EtcdServer) Compact(ctx context.Context, r *pb.CompactionRequest) (*pb.CompactionResponse, error) { - startTime := time.Now() - result, err := s.processInternalRaftRequestOnce(ctx, pb.InternalRaftRequest{Compaction: r}) - trace := traceutil.TODO() - if result != nil && result.trace != nil { - trace = result.trace - defer func() { - trace.LogIfLong(traceThreshold) - }() - applyStart := result.trace.GetStartTime() - result.trace.SetStartTime(startTime) - trace.InsertStep(0, applyStart, "process raft request") - } - if r.Physical && result != nil && result.physc != nil { - <-result.physc - // The compaction is done deleting keys; the hash is now settled - // but the data is not necessarily committed. If there's a crash, - // the hash may revert to a hash prior to compaction completing - // if the compaction resumes. Force the finished compaction to - // commit so it won't resume following a crash. - s.be.ForceCommit() - trace.Step("physically apply compaction") - } - if err != nil { - return nil, err - } - if result.err != nil { - return nil, result.err - } - resp := result.resp.(*pb.CompactionResponse) - if resp == nil { - resp = &pb.CompactionResponse{} - } - if resp.Header == nil { - resp.Header = &pb.ResponseHeader{} - } - resp.Header.Revision = s.kv.Rev() - trace.AddField(traceutil.Field{Key: "response_revision", Value: resp.Header.Revision}) - return resp, nil -} - -func (s *EtcdServer) LeaseGrant(ctx context.Context, r *pb.LeaseGrantRequest) (*pb.LeaseGrantResponse, error) { - // no id given? choose one - for r.ID == int64(lease.NoLease) { - // only use positive int64 id's - r.ID = int64(s.reqIDGen.Next() & ((1 << 63) - 1)) - } - resp, err := s.raftRequestOnce(ctx, pb.InternalRaftRequest{LeaseGrant: r}) - if err != nil { - return nil, err - } - return resp.(*pb.LeaseGrantResponse), nil -} - -func (s *EtcdServer) LeaseRevoke(ctx context.Context, r *pb.LeaseRevokeRequest) (*pb.LeaseRevokeResponse, error) { - resp, err := s.raftRequestOnce(ctx, pb.InternalRaftRequest{LeaseRevoke: r}) - if err != nil { - return nil, err - } - return resp.(*pb.LeaseRevokeResponse), nil -} - -func (s *EtcdServer) LeaseRenew(ctx context.Context, id lease.LeaseID) (int64, error) { - ttl, err := s.lessor.Renew(id) - if err == nil { // already requested to primary lessor(leader) - return ttl, nil - } - if err != lease.ErrNotPrimary { - return -1, err - } - - cctx, cancel := context.WithTimeout(ctx, s.Cfg.ReqTimeout()) - defer cancel() - - // renewals don't go through raft; forward to leader manually - for cctx.Err() == nil && err != nil { - leader, lerr := s.waitLeader(cctx) - if lerr != nil { - return -1, lerr - } - for _, url := range leader.PeerURLs { - lurl := url + leasehttp.LeasePrefix - ttl, err = leasehttp.RenewHTTP(cctx, id, lurl, s.peerRt) - if err == nil || err == lease.ErrLeaseNotFound { - return ttl, err - } - } - // Throttle in case of e.g. connection problems. - time.Sleep(50 * time.Millisecond) - } - - if cctx.Err() == context.DeadlineExceeded { - return -1, ErrTimeout - } - return -1, ErrCanceled -} - -func (s *EtcdServer) LeaseTimeToLive(ctx context.Context, r *pb.LeaseTimeToLiveRequest) (*pb.LeaseTimeToLiveResponse, error) { - if s.Leader() == s.ID() { - // primary; timetolive directly from leader - le := s.lessor.Lookup(lease.LeaseID(r.ID)) - if le == nil { - return nil, lease.ErrLeaseNotFound - } - // TODO: fill out ResponseHeader - resp := &pb.LeaseTimeToLiveResponse{Header: &pb.ResponseHeader{}, ID: r.ID, TTL: int64(le.Remaining().Seconds()), GrantedTTL: le.TTL()} - if r.Keys { - ks := le.Keys() - kbs := make([][]byte, len(ks)) - for i := range ks { - kbs[i] = []byte(ks[i]) - } - resp.Keys = kbs - } - return resp, nil - } - - cctx, cancel := context.WithTimeout(ctx, s.Cfg.ReqTimeout()) - defer cancel() - - // forward to leader - for cctx.Err() == nil { - leader, err := s.waitLeader(cctx) - if err != nil { - return nil, err - } - for _, url := range leader.PeerURLs { - lurl := url + leasehttp.LeaseInternalPrefix - resp, err := leasehttp.TimeToLiveHTTP(cctx, lease.LeaseID(r.ID), r.Keys, lurl, s.peerRt) - if err == nil { - return resp.LeaseTimeToLiveResponse, nil - } - if err == lease.ErrLeaseNotFound { - return nil, err - } - } - } - - if cctx.Err() == context.DeadlineExceeded { - return nil, ErrTimeout - } - return nil, ErrCanceled -} - -func (s *EtcdServer) LeaseLeases(ctx context.Context, r *pb.LeaseLeasesRequest) (*pb.LeaseLeasesResponse, error) { - ls := s.lessor.Leases() - lss := make([]*pb.LeaseStatus, len(ls)) - for i := range ls { - lss[i] = &pb.LeaseStatus{ID: int64(ls[i].ID)} - } - return &pb.LeaseLeasesResponse{Header: newHeader(s), Leases: lss}, nil -} - -func (s *EtcdServer) waitLeader(ctx context.Context) (*membership.Member, error) { - leader := s.cluster.Member(s.Leader()) - for leader == nil { - // wait an election - dur := time.Duration(s.Cfg.ElectionTicks) * time.Duration(s.Cfg.TickMs) * time.Millisecond - select { - case <-time.After(dur): - leader = s.cluster.Member(s.Leader()) - case <-s.stopping: - return nil, ErrStopped - case <-ctx.Done(): - return nil, ErrNoLeader - } - } - if leader == nil || len(leader.PeerURLs) == 0 { - return nil, ErrNoLeader - } - return leader, nil -} - -func (s *EtcdServer) Alarm(ctx context.Context, r *pb.AlarmRequest) (*pb.AlarmResponse, error) { - resp, err := s.raftRequestOnce(ctx, pb.InternalRaftRequest{Alarm: r}) - if err != nil { - return nil, err - } - return resp.(*pb.AlarmResponse), nil -} - -func (s *EtcdServer) AuthEnable(ctx context.Context, r *pb.AuthEnableRequest) (*pb.AuthEnableResponse, error) { - resp, err := s.raftRequestOnce(ctx, pb.InternalRaftRequest{AuthEnable: r}) - if err != nil { - return nil, err - } - return resp.(*pb.AuthEnableResponse), nil -} - -func (s *EtcdServer) AuthDisable(ctx context.Context, r *pb.AuthDisableRequest) (*pb.AuthDisableResponse, error) { - resp, err := s.raftRequest(ctx, pb.InternalRaftRequest{AuthDisable: r}) - if err != nil { - return nil, err - } - return resp.(*pb.AuthDisableResponse), nil -} - -func (s *EtcdServer) AuthStatus(ctx context.Context, r *pb.AuthStatusRequest) (*pb.AuthStatusResponse, error) { - resp, err := s.raftRequest(ctx, pb.InternalRaftRequest{AuthStatus: r}) - if err != nil { - return nil, err - } - return resp.(*pb.AuthStatusResponse), nil -} - -func (s *EtcdServer) Authenticate(ctx context.Context, r *pb.AuthenticateRequest) (*pb.AuthenticateResponse, error) { - if err := s.linearizableReadNotify(ctx); err != nil { - return nil, err - } - - lg := s.Logger() - - var resp proto.Message - for { - checkedRevision, err := s.AuthStore().CheckPassword(r.Name, r.Password) - if err != nil { - if err != auth.ErrAuthNotEnabled { - lg.Warn( - "invalid authentication was requested", - zap.String("user", r.Name), - zap.Error(err), - ) - } - return nil, err - } - - st, err := s.AuthStore().GenTokenPrefix() - if err != nil { - return nil, err - } - - // internalReq doesn't need to have Password because the above s.AuthStore().CheckPassword() already did it. - // In addition, it will let a WAL entry not record password as a plain text. - internalReq := &pb.InternalAuthenticateRequest{ - Name: r.Name, - SimpleToken: st, - } - - resp, err = s.raftRequestOnce(ctx, pb.InternalRaftRequest{Authenticate: internalReq}) - if err != nil { - return nil, err - } - if checkedRevision == s.AuthStore().Revision() { - break - } - - lg.Info("revision when password checked became stale; retrying") - } - - return resp.(*pb.AuthenticateResponse), nil -} - -func (s *EtcdServer) UserAdd(ctx context.Context, r *pb.AuthUserAddRequest) (*pb.AuthUserAddResponse, error) { - if r.Options == nil || !r.Options.NoPassword { - hashedPassword, err := bcrypt.GenerateFromPassword([]byte(r.Password), s.authStore.BcryptCost()) - if err != nil { - return nil, err - } - r.HashedPassword = base64.StdEncoding.EncodeToString(hashedPassword) - r.Password = "" - } - - resp, err := s.raftRequest(ctx, pb.InternalRaftRequest{AuthUserAdd: r}) - if err != nil { - return nil, err - } - return resp.(*pb.AuthUserAddResponse), nil -} - -func (s *EtcdServer) UserDelete(ctx context.Context, r *pb.AuthUserDeleteRequest) (*pb.AuthUserDeleteResponse, error) { - resp, err := s.raftRequest(ctx, pb.InternalRaftRequest{AuthUserDelete: r}) - if err != nil { - return nil, err - } - return resp.(*pb.AuthUserDeleteResponse), nil -} - -func (s *EtcdServer) UserChangePassword(ctx context.Context, r *pb.AuthUserChangePasswordRequest) (*pb.AuthUserChangePasswordResponse, error) { - if r.Password != "" { - hashedPassword, err := bcrypt.GenerateFromPassword([]byte(r.Password), s.authStore.BcryptCost()) - if err != nil { - return nil, err - } - r.HashedPassword = base64.StdEncoding.EncodeToString(hashedPassword) - r.Password = "" - } - - resp, err := s.raftRequest(ctx, pb.InternalRaftRequest{AuthUserChangePassword: r}) - if err != nil { - return nil, err - } - return resp.(*pb.AuthUserChangePasswordResponse), nil -} - -func (s *EtcdServer) UserGrantRole(ctx context.Context, r *pb.AuthUserGrantRoleRequest) (*pb.AuthUserGrantRoleResponse, error) { - resp, err := s.raftRequest(ctx, pb.InternalRaftRequest{AuthUserGrantRole: r}) - if err != nil { - return nil, err - } - return resp.(*pb.AuthUserGrantRoleResponse), nil -} - -func (s *EtcdServer) UserGet(ctx context.Context, r *pb.AuthUserGetRequest) (*pb.AuthUserGetResponse, error) { - resp, err := s.raftRequest(ctx, pb.InternalRaftRequest{AuthUserGet: r}) - if err != nil { - return nil, err - } - return resp.(*pb.AuthUserGetResponse), nil -} - -func (s *EtcdServer) UserList(ctx context.Context, r *pb.AuthUserListRequest) (*pb.AuthUserListResponse, error) { - resp, err := s.raftRequest(ctx, pb.InternalRaftRequest{AuthUserList: r}) - if err != nil { - return nil, err - } - return resp.(*pb.AuthUserListResponse), nil -} - -func (s *EtcdServer) UserRevokeRole(ctx context.Context, r *pb.AuthUserRevokeRoleRequest) (*pb.AuthUserRevokeRoleResponse, error) { - resp, err := s.raftRequest(ctx, pb.InternalRaftRequest{AuthUserRevokeRole: r}) - if err != nil { - return nil, err - } - return resp.(*pb.AuthUserRevokeRoleResponse), nil -} - -func (s *EtcdServer) RoleAdd(ctx context.Context, r *pb.AuthRoleAddRequest) (*pb.AuthRoleAddResponse, error) { - resp, err := s.raftRequest(ctx, pb.InternalRaftRequest{AuthRoleAdd: r}) - if err != nil { - return nil, err - } - return resp.(*pb.AuthRoleAddResponse), nil -} - -func (s *EtcdServer) RoleGrantPermission(ctx context.Context, r *pb.AuthRoleGrantPermissionRequest) (*pb.AuthRoleGrantPermissionResponse, error) { - resp, err := s.raftRequest(ctx, pb.InternalRaftRequest{AuthRoleGrantPermission: r}) - if err != nil { - return nil, err - } - return resp.(*pb.AuthRoleGrantPermissionResponse), nil -} - -func (s *EtcdServer) RoleGet(ctx context.Context, r *pb.AuthRoleGetRequest) (*pb.AuthRoleGetResponse, error) { - resp, err := s.raftRequest(ctx, pb.InternalRaftRequest{AuthRoleGet: r}) - if err != nil { - return nil, err - } - return resp.(*pb.AuthRoleGetResponse), nil -} - -func (s *EtcdServer) RoleList(ctx context.Context, r *pb.AuthRoleListRequest) (*pb.AuthRoleListResponse, error) { - resp, err := s.raftRequest(ctx, pb.InternalRaftRequest{AuthRoleList: r}) - if err != nil { - return nil, err - } - return resp.(*pb.AuthRoleListResponse), nil -} - -func (s *EtcdServer) RoleRevokePermission(ctx context.Context, r *pb.AuthRoleRevokePermissionRequest) (*pb.AuthRoleRevokePermissionResponse, error) { - resp, err := s.raftRequest(ctx, pb.InternalRaftRequest{AuthRoleRevokePermission: r}) - if err != nil { - return nil, err - } - return resp.(*pb.AuthRoleRevokePermissionResponse), nil -} - -func (s *EtcdServer) RoleDelete(ctx context.Context, r *pb.AuthRoleDeleteRequest) (*pb.AuthRoleDeleteResponse, error) { - resp, err := s.raftRequest(ctx, pb.InternalRaftRequest{AuthRoleDelete: r}) - if err != nil { - return nil, err - } - return resp.(*pb.AuthRoleDeleteResponse), nil -} - -func (s *EtcdServer) raftRequestOnce(ctx context.Context, r pb.InternalRaftRequest) (proto.Message, error) { - result, err := s.processInternalRaftRequestOnce(ctx, r) - if err != nil { - return nil, err - } - if result.err != nil { - return nil, result.err - } - if startTime, ok := ctx.Value(traceutil.StartTimeKey).(time.Time); ok && result.trace != nil { - applyStart := result.trace.GetStartTime() - // The trace object is created in apply. Here reset the start time to trace - // the raft request time by the difference between the request start time - // and apply start time - result.trace.SetStartTime(startTime) - result.trace.InsertStep(0, applyStart, "process raft request") - result.trace.LogIfLong(traceThreshold) - } - return result.resp, nil -} - -func (s *EtcdServer) raftRequest(ctx context.Context, r pb.InternalRaftRequest) (proto.Message, error) { - return s.raftRequestOnce(ctx, r) -} - -// doSerialize handles the auth logic, with permissions checked by "chk", for a serialized request "get". Returns a non-nil error on authentication failure. -func (s *EtcdServer) doSerialize(ctx context.Context, chk func(*auth.AuthInfo) error, get func()) error { - trace := traceutil.Get(ctx) - ai, err := s.AuthInfoFromCtx(ctx) - if err != nil { - return err - } - if ai == nil { - // chk expects non-nil AuthInfo; use empty credentials - ai = &auth.AuthInfo{} - } - if err = chk(ai); err != nil { - return err - } - trace.Step("get authentication metadata") - // fetch response for serialized request - get() - // check for stale token revision in case the auth store was updated while - // the request has been handled. - if ai.Revision != 0 && ai.Revision != s.authStore.Revision() { - return auth.ErrAuthOldRevision - } - return nil -} - -func (s *EtcdServer) processInternalRaftRequestOnce(ctx context.Context, r pb.InternalRaftRequest) (*applyResult, error) { - ai := s.getAppliedIndex() - ci := s.getCommittedIndex() - if ci > ai+maxGapBetweenApplyAndCommitIndex { - return nil, ErrTooManyRequests - } - - r.Header = &pb.RequestHeader{ - ID: s.reqIDGen.Next(), - } - - // check authinfo if it is not InternalAuthenticateRequest - if r.Authenticate == nil { - authInfo, err := s.AuthInfoFromCtx(ctx) - if err != nil { - return nil, err - } - if authInfo != nil { - r.Header.Username = authInfo.Username - r.Header.AuthRevision = authInfo.Revision - } - } - - data, err := r.Marshal() - if err != nil { - return nil, err - } - - if len(data) > int(s.Cfg.MaxRequestBytes) { - return nil, ErrRequestTooLarge - } - - id := r.ID - if id == 0 { - id = r.Header.ID - } - ch := s.w.Register(id) - - cctx, cancel := context.WithTimeout(ctx, s.Cfg.ReqTimeout()) - defer cancel() - - start := time.Now() - err = s.r.Propose(cctx, data) - if err != nil { - proposalsFailed.Inc() - s.w.Trigger(id, nil) // GC wait - return nil, err - } - proposalsPending.Inc() - defer proposalsPending.Dec() - - select { - case x := <-ch: - return x.(*applyResult), nil - case <-cctx.Done(): - proposalsFailed.Inc() - s.w.Trigger(id, nil) // GC wait - return nil, s.parseProposeCtxErr(cctx.Err(), start) - case <-s.done: - return nil, ErrStopped - } -} - -// Watchable returns a watchable interface attached to the etcdserver. -func (s *EtcdServer) Watchable() mvcc.WatchableKV { return s.KV() } - -func (s *EtcdServer) linearizableReadLoop() { - for { - requestId := s.reqIDGen.Next() - leaderChangedNotifier := s.LeaderChangedNotify() - select { - case <-leaderChangedNotifier: - continue - case <-s.readwaitc: - case <-s.stopping: - return - } - - // as a single loop is can unlock multiple reads, it is not very useful - // to propagate the trace from Txn or Range. - trace := traceutil.New("linearizableReadLoop", s.Logger()) - - nextnr := newNotifier() - s.readMu.Lock() - nr := s.readNotifier - s.readNotifier = nextnr - s.readMu.Unlock() - - confirmedIndex, err := s.requestCurrentIndex(leaderChangedNotifier, requestId) - if isStopped(err) { - return - } - if err != nil { - nr.notify(err) - continue - } - - trace.Step("read index received") - - trace.AddField(traceutil.Field{Key: "readStateIndex", Value: confirmedIndex}) - - appliedIndex := s.getAppliedIndex() - trace.AddField(traceutil.Field{Key: "appliedIndex", Value: strconv.FormatUint(appliedIndex, 10)}) - - if appliedIndex < confirmedIndex { - select { - case <-s.applyWait.Wait(confirmedIndex): - case <-s.stopping: - return - } - } - // unblock all l-reads requested at indices before confirmedIndex - nr.notify(nil) - trace.Step("applied index is now lower than readState.Index") - - trace.LogAllStepsIfLong(traceThreshold) - } -} - -func isStopped(err error) bool { - return err == raft.ErrStopped || err == ErrStopped -} - -func (s *EtcdServer) requestCurrentIndex(leaderChangedNotifier <-chan struct{}, requestId uint64) (uint64, error) { - err := s.sendReadIndex(requestId) - if err != nil { - return 0, err - } - - lg := s.Logger() - errorTimer := time.NewTimer(s.Cfg.ReqTimeout()) - defer errorTimer.Stop() - retryTimer := time.NewTimer(readIndexRetryTime) - defer retryTimer.Stop() - - firstCommitInTermNotifier := s.FirstCommitInTermNotify() - - for { - select { - case rs := <-s.r.readStateC: - requestIdBytes := uint64ToBigEndianBytes(requestId) - gotOwnResponse := bytes.Equal(rs.RequestCtx, requestIdBytes) - if !gotOwnResponse { - // a previous request might time out. now we should ignore the response of it and - // continue waiting for the response of the current requests. - responseId := uint64(0) - if len(rs.RequestCtx) == 8 { - responseId = binary.BigEndian.Uint64(rs.RequestCtx) - } - lg.Warn( - "ignored out-of-date read index response; local node read indexes queueing up and waiting to be in sync with leader", - zap.Uint64("sent-request-id", requestId), - zap.Uint64("received-request-id", responseId), - ) - slowReadIndex.Inc() - continue - } - return rs.Index, nil - case <-leaderChangedNotifier: - readIndexFailed.Inc() - // return a retryable error. - return 0, ErrLeaderChanged - case <-firstCommitInTermNotifier: - firstCommitInTermNotifier = s.FirstCommitInTermNotify() - lg.Info("first commit in current term: resending ReadIndex request") - err := s.sendReadIndex(requestId) - if err != nil { - return 0, err - } - retryTimer.Reset(readIndexRetryTime) - continue - case <-retryTimer.C: - lg.Warn( - "waiting for ReadIndex response took too long, retrying", - zap.Uint64("sent-request-id", requestId), - zap.Duration("retry-timeout", readIndexRetryTime), - ) - err := s.sendReadIndex(requestId) - if err != nil { - return 0, err - } - retryTimer.Reset(readIndexRetryTime) - continue - case <-errorTimer.C: - lg.Warn( - "timed out waiting for read index response (local node might have slow network)", - zap.Duration("timeout", s.Cfg.ReqTimeout()), - ) - slowReadIndex.Inc() - return 0, ErrTimeout - case <-s.stopping: - return 0, ErrStopped - } - } -} - -func uint64ToBigEndianBytes(number uint64) []byte { - byteResult := make([]byte, 8) - binary.BigEndian.PutUint64(byteResult, number) - return byteResult -} - -func (s *EtcdServer) sendReadIndex(requestIndex uint64) error { - ctxToSend := uint64ToBigEndianBytes(requestIndex) - - cctx, cancel := context.WithTimeout(context.Background(), s.Cfg.ReqTimeout()) - err := s.r.ReadIndex(cctx, ctxToSend) - cancel() - if err == raft.ErrStopped { - return err - } - if err != nil { - lg := s.Logger() - lg.Warn("failed to get read index from Raft", zap.Error(err)) - readIndexFailed.Inc() - return err - } - return nil -} - -func (s *EtcdServer) LinearizableReadNotify(ctx context.Context) error { - return s.linearizableReadNotify(ctx) -} - -func (s *EtcdServer) linearizableReadNotify(ctx context.Context) error { - s.readMu.RLock() - nc := s.readNotifier - s.readMu.RUnlock() - - // signal linearizable loop for current notify if it hasn't been already - select { - case s.readwaitc <- struct{}{}: - default: - } - - // wait for read state notification - select { - case <-nc.c: - return nc.err - case <-ctx.Done(): - return ctx.Err() - case <-s.done: - return ErrStopped - } -} - -func (s *EtcdServer) AuthInfoFromCtx(ctx context.Context) (*auth.AuthInfo, error) { - authInfo, err := s.AuthStore().AuthInfoFromCtx(ctx) - if authInfo != nil || err != nil { - return authInfo, err - } - if !s.Cfg.ClientCertAuthEnabled { - return nil, nil - } - authInfo = s.AuthStore().AuthInfoFromTLS(ctx) - return authInfo, nil -} - -func (s *EtcdServer) Downgrade(ctx context.Context, r *pb.DowngradeRequest) (*pb.DowngradeResponse, error) { - switch r.Action { - case pb.DowngradeRequest_VALIDATE: - return s.downgradeValidate(ctx, r.Version) - case pb.DowngradeRequest_ENABLE: - return s.downgradeEnable(ctx, r) - case pb.DowngradeRequest_CANCEL: - return s.downgradeCancel(ctx) - default: - return nil, ErrUnknownMethod - } -} - -func (s *EtcdServer) downgradeValidate(ctx context.Context, v string) (*pb.DowngradeResponse, error) { - resp := &pb.DowngradeResponse{} - - targetVersion, err := convertToClusterVersion(v) - if err != nil { - return nil, err - } - - // gets leaders commit index and wait for local store to finish applying that index - // to avoid using stale downgrade information - err = s.linearizableReadNotify(ctx) - if err != nil { - return nil, err - } - - cv := s.ClusterVersion() - if cv == nil { - return nil, ErrClusterVersionUnavailable - } - resp.Version = cv.String() - - allowedTargetVersion := membership.AllowedDowngradeVersion(cv) - if !targetVersion.Equal(*allowedTargetVersion) { - return nil, ErrInvalidDowngradeTargetVersion - } - - downgradeInfo := s.cluster.DowngradeInfo() - if downgradeInfo.Enabled { - // Todo: return the downgrade status along with the error msg - return nil, ErrDowngradeInProcess - } - return resp, nil -} - -func (s *EtcdServer) downgradeEnable(ctx context.Context, r *pb.DowngradeRequest) (*pb.DowngradeResponse, error) { - // validate downgrade capability before starting downgrade - v := r.Version - lg := s.Logger() - if resp, err := s.downgradeValidate(ctx, v); err != nil { - lg.Warn("reject downgrade request", zap.Error(err)) - return resp, err - } - targetVersion, err := convertToClusterVersion(v) - if err != nil { - lg.Warn("reject downgrade request", zap.Error(err)) - return nil, err - } - - raftRequest := membershippb.DowngradeInfoSetRequest{Enabled: true, Ver: targetVersion.String()} - _, err = s.raftRequest(ctx, pb.InternalRaftRequest{DowngradeInfoSet: &raftRequest}) - if err != nil { - lg.Warn("reject downgrade request", zap.Error(err)) - return nil, err - } - resp := pb.DowngradeResponse{Version: s.ClusterVersion().String()} - return &resp, nil -} - -func (s *EtcdServer) downgradeCancel(ctx context.Context) (*pb.DowngradeResponse, error) { - // gets leaders commit index and wait for local store to finish applying that index - // to avoid using stale downgrade information - if err := s.linearizableReadNotify(ctx); err != nil { - return nil, err - } - - downgradeInfo := s.cluster.DowngradeInfo() - if !downgradeInfo.Enabled { - return nil, ErrNoInflightDowngrade - } - - raftRequest := membershippb.DowngradeInfoSetRequest{Enabled: false} - _, err := s.raftRequest(ctx, pb.InternalRaftRequest{DowngradeInfoSet: &raftRequest}) - if err != nil { - return nil, err - } - resp := pb.DowngradeResponse{Version: s.ClusterVersion().String()} - return &resp, nil -} diff --git a/vendor/go.etcd.io/etcd/server/v3/etcdserver/zap_raft.go b/vendor/go.etcd.io/etcd/server/v3/etcdserver/zap_raft.go deleted file mode 100644 index e8174f396f..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/etcdserver/zap_raft.go +++ /dev/null @@ -1,102 +0,0 @@ -// Copyright 2018 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package etcdserver - -import ( - "errors" - - "go.etcd.io/etcd/raft/v3" - - "go.uber.org/zap" - "go.uber.org/zap/zapcore" -) - -// NewRaftLogger builds "raft.Logger" from "*zap.Config". -func NewRaftLogger(lcfg *zap.Config) (raft.Logger, error) { - if lcfg == nil { - return nil, errors.New("nil zap.Config") - } - lg, err := lcfg.Build(zap.AddCallerSkip(1)) // to annotate caller outside of "logutil" - if err != nil { - return nil, err - } - return &zapRaftLogger{lg: lg, sugar: lg.Sugar()}, nil -} - -// NewRaftLoggerZap converts "*zap.Logger" to "raft.Logger". -func NewRaftLoggerZap(lg *zap.Logger) raft.Logger { - return &zapRaftLogger{lg: lg, sugar: lg.Sugar()} -} - -// NewRaftLoggerFromZapCore creates "raft.Logger" from "zap.Core" -// and "zapcore.WriteSyncer". -func NewRaftLoggerFromZapCore(cr zapcore.Core, syncer zapcore.WriteSyncer) raft.Logger { - // "AddCallerSkip" to annotate caller outside of "logutil" - lg := zap.New(cr, zap.AddCaller(), zap.AddCallerSkip(1), zap.ErrorOutput(syncer)) - return &zapRaftLogger{lg: lg, sugar: lg.Sugar()} -} - -type zapRaftLogger struct { - lg *zap.Logger - sugar *zap.SugaredLogger -} - -func (zl *zapRaftLogger) Debug(args ...interface{}) { - zl.sugar.Debug(args...) -} - -func (zl *zapRaftLogger) Debugf(format string, args ...interface{}) { - zl.sugar.Debugf(format, args...) -} - -func (zl *zapRaftLogger) Error(args ...interface{}) { - zl.sugar.Error(args...) -} - -func (zl *zapRaftLogger) Errorf(format string, args ...interface{}) { - zl.sugar.Errorf(format, args...) -} - -func (zl *zapRaftLogger) Info(args ...interface{}) { - zl.sugar.Info(args...) -} - -func (zl *zapRaftLogger) Infof(format string, args ...interface{}) { - zl.sugar.Infof(format, args...) -} - -func (zl *zapRaftLogger) Warning(args ...interface{}) { - zl.sugar.Warn(args...) -} - -func (zl *zapRaftLogger) Warningf(format string, args ...interface{}) { - zl.sugar.Warnf(format, args...) -} - -func (zl *zapRaftLogger) Fatal(args ...interface{}) { - zl.sugar.Fatal(args...) -} - -func (zl *zapRaftLogger) Fatalf(format string, args ...interface{}) { - zl.sugar.Fatalf(format, args...) -} - -func (zl *zapRaftLogger) Panic(args ...interface{}) { - zl.sugar.Panic(args...) -} - -func (zl *zapRaftLogger) Panicf(format string, args ...interface{}) { - zl.sugar.Panicf(format, args...) -} diff --git a/vendor/go.etcd.io/etcd/server/v3/lease/doc.go b/vendor/go.etcd.io/etcd/server/v3/lease/doc.go deleted file mode 100644 index a74eaf76fc..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/lease/doc.go +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package lease provides an interface and implementation for time-limited leases over arbitrary resources. -package lease diff --git a/vendor/go.etcd.io/etcd/server/v3/lease/lease_queue.go b/vendor/go.etcd.io/etcd/server/v3/lease/lease_queue.go deleted file mode 100644 index ffb7285ec0..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/lease/lease_queue.go +++ /dev/null @@ -1,108 +0,0 @@ -// Copyright 2018 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package lease - -import ( - "container/heap" - "time" -) - -// LeaseWithTime contains lease object with a time. -// For the lessor's lease heap, time identifies the lease expiration time. -// For the lessor's lease checkpoint heap, the time identifies the next lease checkpoint time. -type LeaseWithTime struct { - id LeaseID - time time.Time - index int -} - -type LeaseQueue []*LeaseWithTime - -func (pq LeaseQueue) Len() int { return len(pq) } - -func (pq LeaseQueue) Less(i, j int) bool { - return pq[i].time.Before(pq[j].time) -} - -func (pq LeaseQueue) Swap(i, j int) { - pq[i], pq[j] = pq[j], pq[i] - pq[i].index = i - pq[j].index = j -} - -func (pq *LeaseQueue) Push(x interface{}) { - n := len(*pq) - item := x.(*LeaseWithTime) - item.index = n - *pq = append(*pq, item) -} - -func (pq *LeaseQueue) Pop() interface{} { - old := *pq - n := len(old) - item := old[n-1] - item.index = -1 // for safety - *pq = old[0 : n-1] - return item -} - -// LeaseExpiredNotifier is a queue used to notify lessor to revoke expired lease. -// Only save one item for a lease, `Register` will update time of the corresponding lease. -type LeaseExpiredNotifier struct { - m map[LeaseID]*LeaseWithTime - queue LeaseQueue -} - -func newLeaseExpiredNotifier() *LeaseExpiredNotifier { - return &LeaseExpiredNotifier{ - m: make(map[LeaseID]*LeaseWithTime), - queue: make(LeaseQueue, 0), - } -} - -func (mq *LeaseExpiredNotifier) Init() { - heap.Init(&mq.queue) - mq.m = make(map[LeaseID]*LeaseWithTime) - for _, item := range mq.queue { - mq.m[item.id] = item - } -} - -func (mq *LeaseExpiredNotifier) RegisterOrUpdate(item *LeaseWithTime) { - if old, ok := mq.m[item.id]; ok { - old.time = item.time - heap.Fix(&mq.queue, old.index) - } else { - heap.Push(&mq.queue, item) - mq.m[item.id] = item - } -} - -func (mq *LeaseExpiredNotifier) Unregister() *LeaseWithTime { - item := heap.Pop(&mq.queue).(*LeaseWithTime) - delete(mq.m, item.id) - return item -} - -func (mq *LeaseExpiredNotifier) Poll() *LeaseWithTime { - if mq.Len() == 0 { - return nil - } - return mq.queue[0] -} - -func (mq *LeaseExpiredNotifier) Len() int { - return len(mq.m) -} diff --git a/vendor/go.etcd.io/etcd/server/v3/lease/leasehttp/doc.go b/vendor/go.etcd.io/etcd/server/v3/lease/leasehttp/doc.go deleted file mode 100644 index 8177a37b66..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/lease/leasehttp/doc.go +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package leasehttp serves lease renewals made through HTTP requests. -package leasehttp diff --git a/vendor/go.etcd.io/etcd/server/v3/lease/leasehttp/http.go b/vendor/go.etcd.io/etcd/server/v3/lease/leasehttp/http.go deleted file mode 100644 index 4b0a60a9be..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/lease/leasehttp/http.go +++ /dev/null @@ -1,248 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package leasehttp - -import ( - "bytes" - "context" - "errors" - "fmt" - "io/ioutil" - "net/http" - "time" - - pb "go.etcd.io/etcd/api/v3/etcdserverpb" - "go.etcd.io/etcd/pkg/v3/httputil" - "go.etcd.io/etcd/server/v3/lease" - "go.etcd.io/etcd/server/v3/lease/leasepb" -) - -var ( - LeasePrefix = "/leases" - LeaseInternalPrefix = "/leases/internal" - applyTimeout = time.Second - ErrLeaseHTTPTimeout = errors.New("waiting for node to catch up its applied index has timed out") -) - -// NewHandler returns an http Handler for lease renewals -func NewHandler(l lease.Lessor, waitch func() <-chan struct{}) http.Handler { - return &leaseHandler{l, waitch} -} - -type leaseHandler struct { - l lease.Lessor - waitch func() <-chan struct{} -} - -func (h *leaseHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { - if r.Method != "POST" { - http.Error(w, "Method Not Allowed", http.StatusMethodNotAllowed) - return - } - - defer r.Body.Close() - b, err := ioutil.ReadAll(r.Body) - if err != nil { - http.Error(w, "error reading body", http.StatusBadRequest) - return - } - - var v []byte - switch r.URL.Path { - case LeasePrefix: - lreq := pb.LeaseKeepAliveRequest{} - if uerr := lreq.Unmarshal(b); uerr != nil { - http.Error(w, "error unmarshalling request", http.StatusBadRequest) - return - } - select { - case <-h.waitch(): - case <-time.After(applyTimeout): - http.Error(w, ErrLeaseHTTPTimeout.Error(), http.StatusRequestTimeout) - return - } - ttl, rerr := h.l.Renew(lease.LeaseID(lreq.ID)) - if rerr != nil { - if rerr == lease.ErrLeaseNotFound { - http.Error(w, rerr.Error(), http.StatusNotFound) - return - } - - http.Error(w, rerr.Error(), http.StatusBadRequest) - return - } - // TODO: fill out ResponseHeader - resp := &pb.LeaseKeepAliveResponse{ID: lreq.ID, TTL: ttl} - v, err = resp.Marshal() - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - - case LeaseInternalPrefix: - lreq := leasepb.LeaseInternalRequest{} - if lerr := lreq.Unmarshal(b); lerr != nil { - http.Error(w, "error unmarshalling request", http.StatusBadRequest) - return - } - select { - case <-h.waitch(): - case <-time.After(applyTimeout): - http.Error(w, ErrLeaseHTTPTimeout.Error(), http.StatusRequestTimeout) - return - } - l := h.l.Lookup(lease.LeaseID(lreq.LeaseTimeToLiveRequest.ID)) - if l == nil { - http.Error(w, lease.ErrLeaseNotFound.Error(), http.StatusNotFound) - return - } - // TODO: fill out ResponseHeader - resp := &leasepb.LeaseInternalResponse{ - LeaseTimeToLiveResponse: &pb.LeaseTimeToLiveResponse{ - Header: &pb.ResponseHeader{}, - ID: lreq.LeaseTimeToLiveRequest.ID, - TTL: int64(l.Remaining().Seconds()), - GrantedTTL: l.TTL(), - }, - } - if lreq.LeaseTimeToLiveRequest.Keys { - ks := l.Keys() - kbs := make([][]byte, len(ks)) - for i := range ks { - kbs[i] = []byte(ks[i]) - } - resp.LeaseTimeToLiveResponse.Keys = kbs - } - - v, err = resp.Marshal() - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - - default: - http.Error(w, fmt.Sprintf("unknown request path %q", r.URL.Path), http.StatusBadRequest) - return - } - - w.Header().Set("Content-Type", "application/protobuf") - w.Write(v) -} - -// RenewHTTP renews a lease at a given primary server. -// TODO: Batch request in future? -func RenewHTTP(ctx context.Context, id lease.LeaseID, url string, rt http.RoundTripper) (int64, error) { - // will post lreq protobuf to leader - lreq, err := (&pb.LeaseKeepAliveRequest{ID: int64(id)}).Marshal() - if err != nil { - return -1, err - } - - cc := &http.Client{Transport: rt} - req, err := http.NewRequest("POST", url, bytes.NewReader(lreq)) - if err != nil { - return -1, err - } - req.Header.Set("Content-Type", "application/protobuf") - req.Cancel = ctx.Done() - - resp, err := cc.Do(req) - if err != nil { - return -1, err - } - b, err := readResponse(resp) - if err != nil { - return -1, err - } - - if resp.StatusCode == http.StatusRequestTimeout { - return -1, ErrLeaseHTTPTimeout - } - - if resp.StatusCode == http.StatusNotFound { - return -1, lease.ErrLeaseNotFound - } - - if resp.StatusCode != http.StatusOK { - return -1, fmt.Errorf("lease: unknown error(%s)", string(b)) - } - - lresp := &pb.LeaseKeepAliveResponse{} - if err := lresp.Unmarshal(b); err != nil { - return -1, fmt.Errorf(`lease: %v. data = "%s"`, err, string(b)) - } - if lresp.ID != int64(id) { - return -1, fmt.Errorf("lease: renew id mismatch") - } - return lresp.TTL, nil -} - -// TimeToLiveHTTP retrieves lease information of the given lease ID. -func TimeToLiveHTTP(ctx context.Context, id lease.LeaseID, keys bool, url string, rt http.RoundTripper) (*leasepb.LeaseInternalResponse, error) { - // will post lreq protobuf to leader - lreq, err := (&leasepb.LeaseInternalRequest{ - LeaseTimeToLiveRequest: &pb.LeaseTimeToLiveRequest{ - ID: int64(id), - Keys: keys, - }, - }).Marshal() - if err != nil { - return nil, err - } - - req, err := http.NewRequest("POST", url, bytes.NewReader(lreq)) - if err != nil { - return nil, err - } - req.Header.Set("Content-Type", "application/protobuf") - - req = req.WithContext(ctx) - - cc := &http.Client{Transport: rt} - var b []byte - // buffer errc channel so that errc don't block inside the go routinue - resp, err := cc.Do(req) - if err != nil { - return nil, err - } - b, err = readResponse(resp) - if err != nil { - return nil, err - } - if resp.StatusCode == http.StatusRequestTimeout { - return nil, ErrLeaseHTTPTimeout - } - if resp.StatusCode == http.StatusNotFound { - return nil, lease.ErrLeaseNotFound - } - if resp.StatusCode != http.StatusOK { - return nil, fmt.Errorf("lease: unknown error(%s)", string(b)) - } - - lresp := &leasepb.LeaseInternalResponse{} - if err := lresp.Unmarshal(b); err != nil { - return nil, fmt.Errorf(`lease: %v. data = "%s"`, err, string(b)) - } - if lresp.LeaseTimeToLiveResponse.ID != int64(id) { - return nil, fmt.Errorf("lease: renew id mismatch") - } - return lresp, nil -} - -func readResponse(resp *http.Response) (b []byte, err error) { - b, err = ioutil.ReadAll(resp.Body) - httputil.GracefulClose(resp) - return -} diff --git a/vendor/go.etcd.io/etcd/server/v3/lease/leasepb/lease.pb.go b/vendor/go.etcd.io/etcd/server/v3/lease/leasepb/lease.pb.go deleted file mode 100644 index 8a1c54922f..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/lease/leasepb/lease.pb.go +++ /dev/null @@ -1,733 +0,0 @@ -// Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: lease.proto - -package leasepb - -import ( - fmt "fmt" - io "io" - math "math" - math_bits "math/bits" - - _ "github.com/gogo/protobuf/gogoproto" - proto "github.com/golang/protobuf/proto" - etcdserverpb "go.etcd.io/etcd/api/v3/etcdserverpb" -) - -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package - -type Lease struct { - ID int64 `protobuf:"varint,1,opt,name=ID,proto3" json:"ID,omitempty"` - TTL int64 `protobuf:"varint,2,opt,name=TTL,proto3" json:"TTL,omitempty"` - RemainingTTL int64 `protobuf:"varint,3,opt,name=RemainingTTL,proto3" json:"RemainingTTL,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *Lease) Reset() { *m = Lease{} } -func (m *Lease) String() string { return proto.CompactTextString(m) } -func (*Lease) ProtoMessage() {} -func (*Lease) Descriptor() ([]byte, []int) { - return fileDescriptor_3dd57e402472b33a, []int{0} -} -func (m *Lease) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *Lease) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_Lease.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *Lease) XXX_Merge(src proto.Message) { - xxx_messageInfo_Lease.Merge(m, src) -} -func (m *Lease) XXX_Size() int { - return m.Size() -} -func (m *Lease) XXX_DiscardUnknown() { - xxx_messageInfo_Lease.DiscardUnknown(m) -} - -var xxx_messageInfo_Lease proto.InternalMessageInfo - -type LeaseInternalRequest struct { - LeaseTimeToLiveRequest *etcdserverpb.LeaseTimeToLiveRequest `protobuf:"bytes,1,opt,name=LeaseTimeToLiveRequest,proto3" json:"LeaseTimeToLiveRequest,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *LeaseInternalRequest) Reset() { *m = LeaseInternalRequest{} } -func (m *LeaseInternalRequest) String() string { return proto.CompactTextString(m) } -func (*LeaseInternalRequest) ProtoMessage() {} -func (*LeaseInternalRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_3dd57e402472b33a, []int{1} -} -func (m *LeaseInternalRequest) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *LeaseInternalRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_LeaseInternalRequest.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *LeaseInternalRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_LeaseInternalRequest.Merge(m, src) -} -func (m *LeaseInternalRequest) XXX_Size() int { - return m.Size() -} -func (m *LeaseInternalRequest) XXX_DiscardUnknown() { - xxx_messageInfo_LeaseInternalRequest.DiscardUnknown(m) -} - -var xxx_messageInfo_LeaseInternalRequest proto.InternalMessageInfo - -type LeaseInternalResponse struct { - LeaseTimeToLiveResponse *etcdserverpb.LeaseTimeToLiveResponse `protobuf:"bytes,1,opt,name=LeaseTimeToLiveResponse,proto3" json:"LeaseTimeToLiveResponse,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *LeaseInternalResponse) Reset() { *m = LeaseInternalResponse{} } -func (m *LeaseInternalResponse) String() string { return proto.CompactTextString(m) } -func (*LeaseInternalResponse) ProtoMessage() {} -func (*LeaseInternalResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_3dd57e402472b33a, []int{2} -} -func (m *LeaseInternalResponse) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *LeaseInternalResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_LeaseInternalResponse.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *LeaseInternalResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_LeaseInternalResponse.Merge(m, src) -} -func (m *LeaseInternalResponse) XXX_Size() int { - return m.Size() -} -func (m *LeaseInternalResponse) XXX_DiscardUnknown() { - xxx_messageInfo_LeaseInternalResponse.DiscardUnknown(m) -} - -var xxx_messageInfo_LeaseInternalResponse proto.InternalMessageInfo - -func init() { - proto.RegisterType((*Lease)(nil), "leasepb.Lease") - proto.RegisterType((*LeaseInternalRequest)(nil), "leasepb.LeaseInternalRequest") - proto.RegisterType((*LeaseInternalResponse)(nil), "leasepb.LeaseInternalResponse") -} - -func init() { proto.RegisterFile("lease.proto", fileDescriptor_3dd57e402472b33a) } - -var fileDescriptor_3dd57e402472b33a = []byte{ - // 256 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0xce, 0x49, 0x4d, 0x2c, - 0x4e, 0xd5, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0x07, 0x73, 0x0a, 0x92, 0xa4, 0x44, 0xd2, - 0xf3, 0xd3, 0xf3, 0xc1, 0x62, 0xfa, 0x20, 0x16, 0x44, 0x5a, 0x4a, 0x3e, 0xb5, 0x24, 0x39, 0x45, - 0x3f, 0xb1, 0x20, 0x53, 0x1f, 0xc4, 0x28, 0x4e, 0x2d, 0x2a, 0x4b, 0x2d, 0x2a, 0x48, 0xd2, 0x2f, - 0x2a, 0x48, 0x86, 0x28, 0x50, 0xf2, 0xe5, 0x62, 0xf5, 0x01, 0x99, 0x20, 0xc4, 0xc7, 0xc5, 0xe4, - 0xe9, 0x22, 0xc1, 0xa8, 0xc0, 0xa8, 0xc1, 0x1c, 0xc4, 0xe4, 0xe9, 0x22, 0x24, 0xc0, 0xc5, 0x1c, - 0x12, 0xe2, 0x23, 0xc1, 0x04, 0x16, 0x00, 0x31, 0x85, 0x94, 0xb8, 0x78, 0x82, 0x52, 0x73, 0x13, - 0x33, 0xf3, 0x32, 0xf3, 0xd2, 0x41, 0x52, 0xcc, 0x60, 0x29, 0x14, 0x31, 0xa5, 0x12, 0x2e, 0x11, - 0xb0, 0x71, 0x9e, 0x79, 0x25, 0xa9, 0x45, 0x79, 0x89, 0x39, 0x41, 0xa9, 0x85, 0xa5, 0xa9, 0xc5, - 0x25, 0x42, 0x31, 0x5c, 0x62, 0x60, 0xf1, 0x90, 0xcc, 0xdc, 0xd4, 0x90, 0x7c, 0x9f, 0xcc, 0xb2, - 0x54, 0xa8, 0x0c, 0xd8, 0x46, 0x6e, 0x23, 0x15, 0x3d, 0x64, 0xf7, 0xe9, 0x61, 0x57, 0x1b, 0x84, - 0xc3, 0x0c, 0xa5, 0x0a, 0x2e, 0x51, 0x34, 0x5b, 0x8b, 0x0b, 0xf2, 0xf3, 0x8a, 0x53, 0x85, 0xe2, - 0xb9, 0xc4, 0x31, 0xb4, 0x40, 0xa4, 0xa0, 0xf6, 0xaa, 0x12, 0xb0, 0x17, 0xa2, 0x38, 0x08, 0x97, - 0x29, 0x4e, 0x12, 0x27, 0x1e, 0xca, 0x31, 0x5c, 0x78, 0x28, 0xc7, 0x70, 0xe2, 0x91, 0x1c, 0xe3, - 0x85, 0x47, 0x72, 0x8c, 0x0f, 0x1e, 0xc9, 0x31, 0xce, 0x78, 0x2c, 0xc7, 0x90, 0xc4, 0x06, 0x0e, - 0x5f, 0x63, 0x40, 0x00, 0x00, 0x00, 0xff, 0xff, 0x7b, 0x8a, 0x94, 0xb9, 0xae, 0x01, 0x00, 0x00, -} - -func (m *Lease) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *Lease) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *Lease) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.XXX_unrecognized != nil { - i -= len(m.XXX_unrecognized) - copy(dAtA[i:], m.XXX_unrecognized) - } - if m.RemainingTTL != 0 { - i = encodeVarintLease(dAtA, i, uint64(m.RemainingTTL)) - i-- - dAtA[i] = 0x18 - } - if m.TTL != 0 { - i = encodeVarintLease(dAtA, i, uint64(m.TTL)) - i-- - dAtA[i] = 0x10 - } - if m.ID != 0 { - i = encodeVarintLease(dAtA, i, uint64(m.ID)) - i-- - dAtA[i] = 0x8 - } - return len(dAtA) - i, nil -} - -func (m *LeaseInternalRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *LeaseInternalRequest) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *LeaseInternalRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.XXX_unrecognized != nil { - i -= len(m.XXX_unrecognized) - copy(dAtA[i:], m.XXX_unrecognized) - } - if m.LeaseTimeToLiveRequest != nil { - { - size, err := m.LeaseTimeToLiveRequest.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintLease(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - -func (m *LeaseInternalResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *LeaseInternalResponse) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *LeaseInternalResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.XXX_unrecognized != nil { - i -= len(m.XXX_unrecognized) - copy(dAtA[i:], m.XXX_unrecognized) - } - if m.LeaseTimeToLiveResponse != nil { - { - size, err := m.LeaseTimeToLiveResponse.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintLease(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - -func encodeVarintLease(dAtA []byte, offset int, v uint64) int { - offset -= sovLease(v) - base := offset - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return base -} -func (m *Lease) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.ID != 0 { - n += 1 + sovLease(uint64(m.ID)) - } - if m.TTL != 0 { - n += 1 + sovLease(uint64(m.TTL)) - } - if m.RemainingTTL != 0 { - n += 1 + sovLease(uint64(m.RemainingTTL)) - } - if m.XXX_unrecognized != nil { - n += len(m.XXX_unrecognized) - } - return n -} - -func (m *LeaseInternalRequest) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.LeaseTimeToLiveRequest != nil { - l = m.LeaseTimeToLiveRequest.Size() - n += 1 + l + sovLease(uint64(l)) - } - if m.XXX_unrecognized != nil { - n += len(m.XXX_unrecognized) - } - return n -} - -func (m *LeaseInternalResponse) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.LeaseTimeToLiveResponse != nil { - l = m.LeaseTimeToLiveResponse.Size() - n += 1 + l + sovLease(uint64(l)) - } - if m.XXX_unrecognized != nil { - n += len(m.XXX_unrecognized) - } - return n -} - -func sovLease(x uint64) (n int) { - return (math_bits.Len64(x|1) + 6) / 7 -} -func sozLease(x uint64) (n int) { - return sovLease(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} -func (m *Lease) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowLease - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: Lease: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: Lease: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field ID", wireType) - } - m.ID = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowLease - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.ID |= int64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field TTL", wireType) - } - m.TTL = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowLease - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.TTL |= int64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 3: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field RemainingTTL", wireType) - } - m.RemainingTTL = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowLease - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.RemainingTTL |= int64(b&0x7F) << shift - if b < 0x80 { - break - } - } - default: - iNdEx = preIndex - skippy, err := skipLease(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthLease - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *LeaseInternalRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowLease - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: LeaseInternalRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: LeaseInternalRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field LeaseTimeToLiveRequest", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowLease - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthLease - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthLease - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.LeaseTimeToLiveRequest == nil { - m.LeaseTimeToLiveRequest = &etcdserverpb.LeaseTimeToLiveRequest{} - } - if err := m.LeaseTimeToLiveRequest.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipLease(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthLease - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *LeaseInternalResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowLease - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: LeaseInternalResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: LeaseInternalResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field LeaseTimeToLiveResponse", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowLease - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthLease - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthLease - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.LeaseTimeToLiveResponse == nil { - m.LeaseTimeToLiveResponse = &etcdserverpb.LeaseTimeToLiveResponse{} - } - if err := m.LeaseTimeToLiveResponse.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipLease(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthLease - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func skipLease(dAtA []byte) (n int, err error) { - l := len(dAtA) - iNdEx := 0 - depth := 0 - for iNdEx < l { - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowLease - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - wireType := int(wire & 0x7) - switch wireType { - case 0: - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowLease - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - iNdEx++ - if dAtA[iNdEx-1] < 0x80 { - break - } - } - case 1: - iNdEx += 8 - case 2: - var length int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowLease - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - length |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if length < 0 { - return 0, ErrInvalidLengthLease - } - iNdEx += length - case 3: - depth++ - case 4: - if depth == 0 { - return 0, ErrUnexpectedEndOfGroupLease - } - depth-- - case 5: - iNdEx += 4 - default: - return 0, fmt.Errorf("proto: illegal wireType %d", wireType) - } - if iNdEx < 0 { - return 0, ErrInvalidLengthLease - } - if depth == 0 { - return iNdEx, nil - } - } - return 0, io.ErrUnexpectedEOF -} - -var ( - ErrInvalidLengthLease = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowLease = fmt.Errorf("proto: integer overflow") - ErrUnexpectedEndOfGroupLease = fmt.Errorf("proto: unexpected end of group") -) diff --git a/vendor/go.etcd.io/etcd/server/v3/lease/leasepb/lease.proto b/vendor/go.etcd.io/etcd/server/v3/lease/leasepb/lease.proto deleted file mode 100644 index 5b40e3b17b..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/lease/leasepb/lease.proto +++ /dev/null @@ -1,25 +0,0 @@ -syntax = "proto3"; -package leasepb; - -import "gogoproto/gogo.proto"; -import "etcd/api/etcdserverpb/rpc.proto"; - -option (gogoproto.marshaler_all) = true; -option (gogoproto.sizer_all) = true; -option (gogoproto.unmarshaler_all) = true; -option (gogoproto.goproto_getters_all) = false; -option (gogoproto.goproto_enum_prefix_all) = false; - -message Lease { - int64 ID = 1; - int64 TTL = 2; - int64 RemainingTTL = 3; -} - -message LeaseInternalRequest { - etcdserverpb.LeaseTimeToLiveRequest LeaseTimeToLiveRequest = 1; -} - -message LeaseInternalResponse { - etcdserverpb.LeaseTimeToLiveResponse LeaseTimeToLiveResponse = 1; -} diff --git a/vendor/go.etcd.io/etcd/server/v3/lease/lessor.go b/vendor/go.etcd.io/etcd/server/v3/lease/lessor.go deleted file mode 100644 index 7236515f2b..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/lease/lessor.go +++ /dev/null @@ -1,937 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package lease - -import ( - "container/heap" - "context" - "encoding/binary" - "errors" - "math" - "sort" - "sync" - "time" - - pb "go.etcd.io/etcd/api/v3/etcdserverpb" - "go.etcd.io/etcd/server/v3/lease/leasepb" - "go.etcd.io/etcd/server/v3/mvcc/backend" - "go.etcd.io/etcd/server/v3/mvcc/buckets" - "go.uber.org/zap" -) - -// NoLease is a special LeaseID representing the absence of a lease. -const NoLease = LeaseID(0) - -// MaxLeaseTTL is the maximum lease TTL value -const MaxLeaseTTL = 9000000000 - -var ( - forever = time.Time{} - - // maximum number of leases to revoke per second; configurable for tests - leaseRevokeRate = 1000 - - // maximum number of lease checkpoints recorded to the consensus log per second; configurable for tests - leaseCheckpointRate = 1000 - - // the default interval of lease checkpoint - defaultLeaseCheckpointInterval = 5 * time.Minute - - // maximum number of lease checkpoints to batch into a single consensus log entry - maxLeaseCheckpointBatchSize = 1000 - - // the default interval to check if the expired lease is revoked - defaultExpiredleaseRetryInterval = 3 * time.Second - - ErrNotPrimary = errors.New("not a primary lessor") - ErrLeaseNotFound = errors.New("lease not found") - ErrLeaseExists = errors.New("lease already exists") - ErrLeaseTTLTooLarge = errors.New("too large lease TTL") -) - -// TxnDelete is a TxnWrite that only permits deletes. Defined here -// to avoid circular dependency with mvcc. -type TxnDelete interface { - DeleteRange(key, end []byte) (n, rev int64) - End() -} - -// RangeDeleter is a TxnDelete constructor. -type RangeDeleter func() TxnDelete - -// Checkpointer permits checkpointing of lease remaining TTLs to the consensus log. Defined here to -// avoid circular dependency with mvcc. -type Checkpointer func(ctx context.Context, lc *pb.LeaseCheckpointRequest) - -type LeaseID int64 - -// Lessor owns leases. It can grant, revoke, renew and modify leases for lessee. -type Lessor interface { - // SetRangeDeleter lets the lessor create TxnDeletes to the store. - // Lessor deletes the items in the revoked or expired lease by creating - // new TxnDeletes. - SetRangeDeleter(rd RangeDeleter) - - SetCheckpointer(cp Checkpointer) - - // Grant grants a lease that expires at least after TTL seconds. - Grant(id LeaseID, ttl int64) (*Lease, error) - // Revoke revokes a lease with given ID. The item attached to the - // given lease will be removed. If the ID does not exist, an error - // will be returned. - Revoke(id LeaseID) error - - // Checkpoint applies the remainingTTL of a lease. The remainingTTL is used in Promote to set - // the expiry of leases to less than the full TTL when possible. - Checkpoint(id LeaseID, remainingTTL int64) error - - // Attach attaches given leaseItem to the lease with given LeaseID. - // If the lease does not exist, an error will be returned. - Attach(id LeaseID, items []LeaseItem) error - - // GetLease returns LeaseID for given item. - // If no lease found, NoLease value will be returned. - GetLease(item LeaseItem) LeaseID - - // Detach detaches given leaseItem from the lease with given LeaseID. - // If the lease does not exist, an error will be returned. - Detach(id LeaseID, items []LeaseItem) error - - // Promote promotes the lessor to be the primary lessor. Primary lessor manages - // the expiration and renew of leases. - // Newly promoted lessor renew the TTL of all lease to extend + previous TTL. - Promote(extend time.Duration) - - // Demote demotes the lessor from being the primary lessor. - Demote() - - // Renew renews a lease with given ID. It returns the renewed TTL. If the ID does not exist, - // an error will be returned. - Renew(id LeaseID) (int64, error) - - // Lookup gives the lease at a given lease id, if any - Lookup(id LeaseID) *Lease - - // Leases lists all leases. - Leases() []*Lease - - // ExpiredLeasesC returns a chan that is used to receive expired leases. - ExpiredLeasesC() <-chan []*Lease - - // Recover recovers the lessor state from the given backend and RangeDeleter. - Recover(b backend.Backend, rd RangeDeleter) - - // Stop stops the lessor for managing leases. The behavior of calling Stop multiple - // times is undefined. - Stop() -} - -// lessor implements Lessor interface. -// TODO: use clockwork for testability. -type lessor struct { - mu sync.RWMutex - - // demotec is set when the lessor is the primary. - // demotec will be closed if the lessor is demoted. - demotec chan struct{} - - leaseMap map[LeaseID]*Lease - leaseExpiredNotifier *LeaseExpiredNotifier - leaseCheckpointHeap LeaseQueue - itemMap map[LeaseItem]LeaseID - - // When a lease expires, the lessor will delete the - // leased range (or key) by the RangeDeleter. - rd RangeDeleter - - // When a lease's deadline should be persisted to preserve the remaining TTL across leader - // elections and restarts, the lessor will checkpoint the lease by the Checkpointer. - cp Checkpointer - - // backend to persist leases. We only persist lease ID and expiry for now. - // The leased items can be recovered by iterating all the keys in kv. - b backend.Backend - - // minLeaseTTL is the minimum lease TTL that can be granted for a lease. Any - // requests for shorter TTLs are extended to the minimum TTL. - minLeaseTTL int64 - - expiredC chan []*Lease - // stopC is a channel whose closure indicates that the lessor should be stopped. - stopC chan struct{} - // doneC is a channel whose closure indicates that the lessor is stopped. - doneC chan struct{} - - lg *zap.Logger - - // Wait duration between lease checkpoints. - checkpointInterval time.Duration - // the interval to check if the expired lease is revoked - expiredLeaseRetryInterval time.Duration -} - -type LessorConfig struct { - MinLeaseTTL int64 - CheckpointInterval time.Duration - ExpiredLeasesRetryInterval time.Duration -} - -func NewLessor(lg *zap.Logger, b backend.Backend, cfg LessorConfig) Lessor { - return newLessor(lg, b, cfg) -} - -func newLessor(lg *zap.Logger, b backend.Backend, cfg LessorConfig) *lessor { - checkpointInterval := cfg.CheckpointInterval - expiredLeaseRetryInterval := cfg.ExpiredLeasesRetryInterval - if checkpointInterval == 0 { - checkpointInterval = defaultLeaseCheckpointInterval - } - if expiredLeaseRetryInterval == 0 { - expiredLeaseRetryInterval = defaultExpiredleaseRetryInterval - } - l := &lessor{ - leaseMap: make(map[LeaseID]*Lease), - itemMap: make(map[LeaseItem]LeaseID), - leaseExpiredNotifier: newLeaseExpiredNotifier(), - leaseCheckpointHeap: make(LeaseQueue, 0), - b: b, - minLeaseTTL: cfg.MinLeaseTTL, - checkpointInterval: checkpointInterval, - expiredLeaseRetryInterval: expiredLeaseRetryInterval, - // expiredC is a small buffered chan to avoid unnecessary blocking. - expiredC: make(chan []*Lease, 16), - stopC: make(chan struct{}), - doneC: make(chan struct{}), - lg: lg, - } - l.initAndRecover() - - go l.runLoop() - - return l -} - -// isPrimary indicates if this lessor is the primary lessor. The primary -// lessor manages lease expiration and renew. -// -// in etcd, raft leader is the primary. Thus there might be two primary -// leaders at the same time (raft allows concurrent leader but with different term) -// for at most a leader election timeout. -// The old primary leader cannot affect the correctness since its proposal has a -// smaller term and will not be committed. -// -// TODO: raft follower do not forward lease management proposals. There might be a -// very small window (within second normally which depends on go scheduling) that -// a raft follow is the primary between the raft leader demotion and lessor demotion. -// Usually this should not be a problem. Lease should not be that sensitive to timing. -func (le *lessor) isPrimary() bool { - return le.demotec != nil -} - -func (le *lessor) SetRangeDeleter(rd RangeDeleter) { - le.mu.Lock() - defer le.mu.Unlock() - - le.rd = rd -} - -func (le *lessor) SetCheckpointer(cp Checkpointer) { - le.mu.Lock() - defer le.mu.Unlock() - - le.cp = cp -} - -func (le *lessor) Grant(id LeaseID, ttl int64) (*Lease, error) { - if id == NoLease { - return nil, ErrLeaseNotFound - } - - if ttl > MaxLeaseTTL { - return nil, ErrLeaseTTLTooLarge - } - - // TODO: when lessor is under high load, it should give out lease - // with longer TTL to reduce renew load. - l := &Lease{ - ID: id, - ttl: ttl, - itemSet: make(map[LeaseItem]struct{}), - revokec: make(chan struct{}), - } - - le.mu.Lock() - defer le.mu.Unlock() - - if _, ok := le.leaseMap[id]; ok { - return nil, ErrLeaseExists - } - - if l.ttl < le.minLeaseTTL { - l.ttl = le.minLeaseTTL - } - - if le.isPrimary() { - l.refresh(0) - } else { - l.forever() - } - - le.leaseMap[id] = l - l.persistTo(le.b) - - leaseTotalTTLs.Observe(float64(l.ttl)) - leaseGranted.Inc() - - if le.isPrimary() { - item := &LeaseWithTime{id: l.ID, time: l.expiry} - le.leaseExpiredNotifier.RegisterOrUpdate(item) - le.scheduleCheckpointIfNeeded(l) - } - - return l, nil -} - -func (le *lessor) Revoke(id LeaseID) error { - le.mu.Lock() - - l := le.leaseMap[id] - if l == nil { - le.mu.Unlock() - return ErrLeaseNotFound - } - defer close(l.revokec) - // unlock before doing external work - le.mu.Unlock() - - if le.rd == nil { - return nil - } - - txn := le.rd() - - // sort keys so deletes are in same order among all members, - // otherwise the backend hashes will be different - keys := l.Keys() - sort.StringSlice(keys).Sort() - for _, key := range keys { - txn.DeleteRange([]byte(key), nil) - } - - le.mu.Lock() - defer le.mu.Unlock() - delete(le.leaseMap, l.ID) - // lease deletion needs to be in the same backend transaction with the - // kv deletion. Or we might end up with not executing the revoke or not - // deleting the keys if etcdserver fails in between. - le.b.BatchTx().UnsafeDelete(buckets.Lease, int64ToBytes(int64(l.ID))) - - txn.End() - - leaseRevoked.Inc() - return nil -} - -func (le *lessor) Checkpoint(id LeaseID, remainingTTL int64) error { - le.mu.Lock() - defer le.mu.Unlock() - - if l, ok := le.leaseMap[id]; ok { - // when checkpointing, we only update the remainingTTL, Promote is responsible for applying this to lease expiry - l.remainingTTL = remainingTTL - if le.isPrimary() { - // schedule the next checkpoint as needed - le.scheduleCheckpointIfNeeded(l) - } - } - return nil -} - -// Renew renews an existing lease. If the given lease does not exist or -// has expired, an error will be returned. -func (le *lessor) Renew(id LeaseID) (int64, error) { - le.mu.RLock() - if !le.isPrimary() { - // forward renew request to primary instead of returning error. - le.mu.RUnlock() - return -1, ErrNotPrimary - } - - demotec := le.demotec - - l := le.leaseMap[id] - if l == nil { - le.mu.RUnlock() - return -1, ErrLeaseNotFound - } - // Clear remaining TTL when we renew if it is set - clearRemainingTTL := le.cp != nil && l.remainingTTL > 0 - - le.mu.RUnlock() - if l.expired() { - select { - // A expired lease might be pending for revoking or going through - // quorum to be revoked. To be accurate, renew request must wait for the - // deletion to complete. - case <-l.revokec: - return -1, ErrLeaseNotFound - // The expired lease might fail to be revoked if the primary changes. - // The caller will retry on ErrNotPrimary. - case <-demotec: - return -1, ErrNotPrimary - case <-le.stopC: - return -1, ErrNotPrimary - } - } - - // Clear remaining TTL when we renew if it is set - // By applying a RAFT entry only when the remainingTTL is already set, we limit the number - // of RAFT entries written per lease to a max of 2 per checkpoint interval. - if clearRemainingTTL { - le.cp(context.Background(), &pb.LeaseCheckpointRequest{Checkpoints: []*pb.LeaseCheckpoint{{ID: int64(l.ID), Remaining_TTL: 0}}}) - } - - le.mu.Lock() - l.refresh(0) - item := &LeaseWithTime{id: l.ID, time: l.expiry} - le.leaseExpiredNotifier.RegisterOrUpdate(item) - le.mu.Unlock() - - leaseRenewed.Inc() - return l.ttl, nil -} - -func (le *lessor) Lookup(id LeaseID) *Lease { - le.mu.RLock() - defer le.mu.RUnlock() - return le.leaseMap[id] -} - -func (le *lessor) unsafeLeases() []*Lease { - leases := make([]*Lease, 0, len(le.leaseMap)) - for _, l := range le.leaseMap { - leases = append(leases, l) - } - return leases -} - -func (le *lessor) Leases() []*Lease { - le.mu.RLock() - ls := le.unsafeLeases() - le.mu.RUnlock() - sort.Sort(leasesByExpiry(ls)) - return ls -} - -func (le *lessor) Promote(extend time.Duration) { - le.mu.Lock() - defer le.mu.Unlock() - - le.demotec = make(chan struct{}) - - // refresh the expiries of all leases. - for _, l := range le.leaseMap { - l.refresh(extend) - item := &LeaseWithTime{id: l.ID, time: l.expiry} - le.leaseExpiredNotifier.RegisterOrUpdate(item) - } - - if len(le.leaseMap) < leaseRevokeRate { - // no possibility of lease pile-up - return - } - - // adjust expiries in case of overlap - leases := le.unsafeLeases() - sort.Sort(leasesByExpiry(leases)) - - baseWindow := leases[0].Remaining() - nextWindow := baseWindow + time.Second - expires := 0 - // have fewer expires than the total revoke rate so piled up leases - // don't consume the entire revoke limit - targetExpiresPerSecond := (3 * leaseRevokeRate) / 4 - for _, l := range leases { - remaining := l.Remaining() - if remaining > nextWindow { - baseWindow = remaining - nextWindow = baseWindow + time.Second - expires = 1 - continue - } - expires++ - if expires <= targetExpiresPerSecond { - continue - } - rateDelay := float64(time.Second) * (float64(expires) / float64(targetExpiresPerSecond)) - // If leases are extended by n seconds, leases n seconds ahead of the - // base window should be extended by only one second. - rateDelay -= float64(remaining - baseWindow) - delay := time.Duration(rateDelay) - nextWindow = baseWindow + delay - l.refresh(delay + extend) - item := &LeaseWithTime{id: l.ID, time: l.expiry} - le.leaseExpiredNotifier.RegisterOrUpdate(item) - le.scheduleCheckpointIfNeeded(l) - } -} - -type leasesByExpiry []*Lease - -func (le leasesByExpiry) Len() int { return len(le) } -func (le leasesByExpiry) Less(i, j int) bool { return le[i].Remaining() < le[j].Remaining() } -func (le leasesByExpiry) Swap(i, j int) { le[i], le[j] = le[j], le[i] } - -func (le *lessor) Demote() { - le.mu.Lock() - defer le.mu.Unlock() - - // set the expiries of all leases to forever - for _, l := range le.leaseMap { - l.forever() - } - - le.clearScheduledLeasesCheckpoints() - le.clearLeaseExpiredNotifier() - - if le.demotec != nil { - close(le.demotec) - le.demotec = nil - } -} - -// Attach attaches items to the lease with given ID. When the lease -// expires, the attached items will be automatically removed. -// If the given lease does not exist, an error will be returned. -func (le *lessor) Attach(id LeaseID, items []LeaseItem) error { - le.mu.Lock() - defer le.mu.Unlock() - - l := le.leaseMap[id] - if l == nil { - return ErrLeaseNotFound - } - - l.mu.Lock() - for _, it := range items { - l.itemSet[it] = struct{}{} - le.itemMap[it] = id - } - l.mu.Unlock() - return nil -} - -func (le *lessor) GetLease(item LeaseItem) LeaseID { - le.mu.RLock() - id := le.itemMap[item] - le.mu.RUnlock() - return id -} - -// Detach detaches items from the lease with given ID. -// If the given lease does not exist, an error will be returned. -func (le *lessor) Detach(id LeaseID, items []LeaseItem) error { - le.mu.Lock() - defer le.mu.Unlock() - - l := le.leaseMap[id] - if l == nil { - return ErrLeaseNotFound - } - - l.mu.Lock() - for _, it := range items { - delete(l.itemSet, it) - delete(le.itemMap, it) - } - l.mu.Unlock() - return nil -} - -func (le *lessor) Recover(b backend.Backend, rd RangeDeleter) { - le.mu.Lock() - defer le.mu.Unlock() - - le.b = b - le.rd = rd - le.leaseMap = make(map[LeaseID]*Lease) - le.itemMap = make(map[LeaseItem]LeaseID) - le.initAndRecover() -} - -func (le *lessor) ExpiredLeasesC() <-chan []*Lease { - return le.expiredC -} - -func (le *lessor) Stop() { - close(le.stopC) - <-le.doneC -} - -func (le *lessor) runLoop() { - defer close(le.doneC) - - for { - le.revokeExpiredLeases() - le.checkpointScheduledLeases() - - select { - case <-time.After(500 * time.Millisecond): - case <-le.stopC: - return - } - } -} - -// revokeExpiredLeases finds all leases past their expiry and sends them to expired channel for -// to be revoked. -func (le *lessor) revokeExpiredLeases() { - var ls []*Lease - - // rate limit - revokeLimit := leaseRevokeRate / 2 - - le.mu.RLock() - if le.isPrimary() { - ls = le.findExpiredLeases(revokeLimit) - } - le.mu.RUnlock() - - if len(ls) != 0 { - select { - case <-le.stopC: - return - case le.expiredC <- ls: - default: - // the receiver of expiredC is probably busy handling - // other stuff - // let's try this next time after 500ms - } - } -} - -// checkpointScheduledLeases finds all scheduled lease checkpoints that are due and -// submits them to the checkpointer to persist them to the consensus log. -func (le *lessor) checkpointScheduledLeases() { - var cps []*pb.LeaseCheckpoint - - // rate limit - for i := 0; i < leaseCheckpointRate/2; i++ { - le.mu.Lock() - if le.isPrimary() { - cps = le.findDueScheduledCheckpoints(maxLeaseCheckpointBatchSize) - } - le.mu.Unlock() - - if len(cps) != 0 { - le.cp(context.Background(), &pb.LeaseCheckpointRequest{Checkpoints: cps}) - } - if len(cps) < maxLeaseCheckpointBatchSize { - return - } - } -} - -func (le *lessor) clearScheduledLeasesCheckpoints() { - le.leaseCheckpointHeap = make(LeaseQueue, 0) -} - -func (le *lessor) clearLeaseExpiredNotifier() { - le.leaseExpiredNotifier = newLeaseExpiredNotifier() -} - -// expireExists returns true if expiry items exist. -// It pops only when expiry item exists. -// "next" is true, to indicate that it may exist in next attempt. -func (le *lessor) expireExists() (l *Lease, ok bool, next bool) { - if le.leaseExpiredNotifier.Len() == 0 { - return nil, false, false - } - - item := le.leaseExpiredNotifier.Poll() - l = le.leaseMap[item.id] - if l == nil { - // lease has expired or been revoked - // no need to revoke (nothing is expiry) - le.leaseExpiredNotifier.Unregister() // O(log N) - return nil, false, true - } - now := time.Now() - if now.Before(item.time) /* item.time: expiration time */ { - // Candidate expirations are caught up, reinsert this item - // and no need to revoke (nothing is expiry) - return l, false, false - } - - // recheck if revoke is complete after retry interval - item.time = now.Add(le.expiredLeaseRetryInterval) - le.leaseExpiredNotifier.RegisterOrUpdate(item) - return l, true, false -} - -// findExpiredLeases loops leases in the leaseMap until reaching expired limit -// and returns the expired leases that needed to be revoked. -func (le *lessor) findExpiredLeases(limit int) []*Lease { - leases := make([]*Lease, 0, 16) - - for { - l, ok, next := le.expireExists() - if !ok && !next { - break - } - if !ok { - continue - } - if next { - continue - } - - if l.expired() { - leases = append(leases, l) - - // reach expired limit - if len(leases) == limit { - break - } - } - } - - return leases -} - -func (le *lessor) scheduleCheckpointIfNeeded(lease *Lease) { - if le.cp == nil { - return - } - - if lease.RemainingTTL() > int64(le.checkpointInterval.Seconds()) { - if le.lg != nil { - le.lg.Debug("Scheduling lease checkpoint", - zap.Int64("leaseID", int64(lease.ID)), - zap.Duration("intervalSeconds", le.checkpointInterval), - ) - } - heap.Push(&le.leaseCheckpointHeap, &LeaseWithTime{ - id: lease.ID, - time: time.Now().Add(le.checkpointInterval), - }) - } -} - -func (le *lessor) findDueScheduledCheckpoints(checkpointLimit int) []*pb.LeaseCheckpoint { - if le.cp == nil { - return nil - } - - now := time.Now() - cps := []*pb.LeaseCheckpoint{} - for le.leaseCheckpointHeap.Len() > 0 && len(cps) < checkpointLimit { - lt := le.leaseCheckpointHeap[0] - if lt.time.After(now) /* lt.time: next checkpoint time */ { - return cps - } - heap.Pop(&le.leaseCheckpointHeap) - var l *Lease - var ok bool - if l, ok = le.leaseMap[lt.id]; !ok { - continue - } - if !now.Before(l.expiry) { - continue - } - remainingTTL := int64(math.Ceil(l.expiry.Sub(now).Seconds())) - if remainingTTL >= l.ttl { - continue - } - if le.lg != nil { - le.lg.Debug("Checkpointing lease", - zap.Int64("leaseID", int64(lt.id)), - zap.Int64("remainingTTL", remainingTTL), - ) - } - cps = append(cps, &pb.LeaseCheckpoint{ID: int64(lt.id), Remaining_TTL: remainingTTL}) - } - return cps -} - -func (le *lessor) initAndRecover() { - tx := le.b.BatchTx() - tx.Lock() - - tx.UnsafeCreateBucket(buckets.Lease) - _, vs := tx.UnsafeRange(buckets.Lease, int64ToBytes(0), int64ToBytes(math.MaxInt64), 0) - // TODO: copy vs and do decoding outside tx lock if lock contention becomes an issue. - for i := range vs { - var lpb leasepb.Lease - err := lpb.Unmarshal(vs[i]) - if err != nil { - tx.Unlock() - panic("failed to unmarshal lease proto item") - } - ID := LeaseID(lpb.ID) - if lpb.TTL < le.minLeaseTTL { - lpb.TTL = le.minLeaseTTL - } - le.leaseMap[ID] = &Lease{ - ID: ID, - ttl: lpb.TTL, - // itemSet will be filled in when recover key-value pairs - // set expiry to forever, refresh when promoted - itemSet: make(map[LeaseItem]struct{}), - expiry: forever, - revokec: make(chan struct{}), - } - } - le.leaseExpiredNotifier.Init() - heap.Init(&le.leaseCheckpointHeap) - tx.Unlock() - - le.b.ForceCommit() -} - -type Lease struct { - ID LeaseID - ttl int64 // time to live of the lease in seconds - remainingTTL int64 // remaining time to live in seconds, if zero valued it is considered unset and the full ttl should be used - // expiryMu protects concurrent accesses to expiry - expiryMu sync.RWMutex - // expiry is time when lease should expire. no expiration when expiry.IsZero() is true - expiry time.Time - - // mu protects concurrent accesses to itemSet - mu sync.RWMutex - itemSet map[LeaseItem]struct{} - revokec chan struct{} -} - -func (l *Lease) expired() bool { - return l.Remaining() <= 0 -} - -func (l *Lease) persistTo(b backend.Backend) { - key := int64ToBytes(int64(l.ID)) - - lpb := leasepb.Lease{ID: int64(l.ID), TTL: l.ttl, RemainingTTL: l.remainingTTL} - val, err := lpb.Marshal() - if err != nil { - panic("failed to marshal lease proto item") - } - - b.BatchTx().Lock() - b.BatchTx().UnsafePut(buckets.Lease, key, val) - b.BatchTx().Unlock() -} - -// TTL returns the TTL of the Lease. -func (l *Lease) TTL() int64 { - return l.ttl -} - -// RemainingTTL returns the last checkpointed remaining TTL of the lease. -// TODO(jpbetz): do not expose this utility method -func (l *Lease) RemainingTTL() int64 { - if l.remainingTTL > 0 { - return l.remainingTTL - } - return l.ttl -} - -// refresh refreshes the expiry of the lease. -func (l *Lease) refresh(extend time.Duration) { - newExpiry := time.Now().Add(extend + time.Duration(l.RemainingTTL())*time.Second) - l.expiryMu.Lock() - defer l.expiryMu.Unlock() - l.expiry = newExpiry -} - -// forever sets the expiry of lease to be forever. -func (l *Lease) forever() { - l.expiryMu.Lock() - defer l.expiryMu.Unlock() - l.expiry = forever -} - -// Keys returns all the keys attached to the lease. -func (l *Lease) Keys() []string { - l.mu.RLock() - keys := make([]string, 0, len(l.itemSet)) - for k := range l.itemSet { - keys = append(keys, k.Key) - } - l.mu.RUnlock() - return keys -} - -// Remaining returns the remaining time of the lease. -func (l *Lease) Remaining() time.Duration { - l.expiryMu.RLock() - defer l.expiryMu.RUnlock() - if l.expiry.IsZero() { - return time.Duration(math.MaxInt64) - } - return time.Until(l.expiry) -} - -type LeaseItem struct { - Key string -} - -func int64ToBytes(n int64) []byte { - bytes := make([]byte, 8) - binary.BigEndian.PutUint64(bytes, uint64(n)) - return bytes -} - -// FakeLessor is a fake implementation of Lessor interface. -// Used for testing only. -type FakeLessor struct{} - -func (fl *FakeLessor) SetRangeDeleter(dr RangeDeleter) {} - -func (fl *FakeLessor) SetCheckpointer(cp Checkpointer) {} - -func (fl *FakeLessor) Grant(id LeaseID, ttl int64) (*Lease, error) { return nil, nil } - -func (fl *FakeLessor) Revoke(id LeaseID) error { return nil } - -func (fl *FakeLessor) Checkpoint(id LeaseID, remainingTTL int64) error { return nil } - -func (fl *FakeLessor) Attach(id LeaseID, items []LeaseItem) error { return nil } - -func (fl *FakeLessor) GetLease(item LeaseItem) LeaseID { return 0 } -func (fl *FakeLessor) Detach(id LeaseID, items []LeaseItem) error { return nil } - -func (fl *FakeLessor) Promote(extend time.Duration) {} - -func (fl *FakeLessor) Demote() {} - -func (fl *FakeLessor) Renew(id LeaseID) (int64, error) { return 10, nil } - -func (fl *FakeLessor) Lookup(id LeaseID) *Lease { return nil } - -func (fl *FakeLessor) Leases() []*Lease { return nil } - -func (fl *FakeLessor) ExpiredLeasesC() <-chan []*Lease { return nil } - -func (fl *FakeLessor) Recover(b backend.Backend, rd RangeDeleter) {} - -func (fl *FakeLessor) Stop() {} - -type FakeTxnDelete struct { - backend.BatchTx -} - -func (ftd *FakeTxnDelete) DeleteRange(key, end []byte) (n, rev int64) { return 0, 0 } -func (ftd *FakeTxnDelete) End() { ftd.Unlock() } diff --git a/vendor/go.etcd.io/etcd/server/v3/lease/metrics.go b/vendor/go.etcd.io/etcd/server/v3/lease/metrics.go deleted file mode 100644 index 06f8b58015..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/lease/metrics.go +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright 2018 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package lease - -import ( - "github.com/prometheus/client_golang/prometheus" -) - -var ( - leaseGranted = prometheus.NewCounter(prometheus.CounterOpts{ - Namespace: "etcd_debugging", - Subsystem: "lease", - Name: "granted_total", - Help: "The total number of granted leases.", - }) - - leaseRevoked = prometheus.NewCounter(prometheus.CounterOpts{ - Namespace: "etcd_debugging", - Subsystem: "lease", - Name: "revoked_total", - Help: "The total number of revoked leases.", - }) - - leaseRenewed = prometheus.NewCounter(prometheus.CounterOpts{ - Namespace: "etcd_debugging", - Subsystem: "lease", - Name: "renewed_total", - Help: "The number of renewed leases seen by the leader.", - }) - - leaseTotalTTLs = prometheus.NewHistogram( - prometheus.HistogramOpts{ - Namespace: "etcd_debugging", - Subsystem: "lease", - Name: "ttl_total", - Help: "Bucketed histogram of lease TTLs.", - // 1 second -> 3 months - Buckets: prometheus.ExponentialBuckets(1, 2, 24), - }) -) - -func init() { - prometheus.MustRegister(leaseGranted) - prometheus.MustRegister(leaseRevoked) - prometheus.MustRegister(leaseRenewed) - prometheus.MustRegister(leaseTotalTTLs) -} diff --git a/vendor/go.etcd.io/etcd/server/v3/mvcc/backend/backend.go b/vendor/go.etcd.io/etcd/server/v3/mvcc/backend/backend.go deleted file mode 100644 index b7207c1717..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/mvcc/backend/backend.go +++ /dev/null @@ -1,648 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package backend - -import ( - "fmt" - "hash/crc32" - "io" - "io/ioutil" - "os" - "path/filepath" - "sync" - "sync/atomic" - "time" - - humanize "github.com/dustin/go-humanize" - bolt "go.etcd.io/bbolt" - "go.uber.org/zap" -) - -var ( - defaultBatchLimit = 10000 - defaultBatchInterval = 100 * time.Millisecond - - defragLimit = 10000 - - // initialMmapSize is the initial size of the mmapped region. Setting this larger than - // the potential max db size can prevent writer from blocking reader. - // This only works for linux. - initialMmapSize = uint64(10 * 1024 * 1024 * 1024) - - // minSnapshotWarningTimeout is the minimum threshold to trigger a long running snapshot warning. - minSnapshotWarningTimeout = 30 * time.Second -) - -type Backend interface { - // ReadTx returns a read transaction. It is replaced by ConcurrentReadTx in the main data path, see #10523. - ReadTx() ReadTx - BatchTx() BatchTx - // ConcurrentReadTx returns a non-blocking read transaction. - ConcurrentReadTx() ReadTx - - Snapshot() Snapshot - Hash(ignores func(bucketName, keyName []byte) bool) (uint32, error) - // Size returns the current size of the backend physically allocated. - // The backend can hold DB space that is not utilized at the moment, - // since it can conduct pre-allocation or spare unused space for recycling. - // Use SizeInUse() instead for the actual DB size. - Size() int64 - // SizeInUse returns the current size of the backend logically in use. - // Since the backend can manage free space in a non-byte unit such as - // number of pages, the returned value can be not exactly accurate in bytes. - SizeInUse() int64 - // OpenReadTxN returns the number of currently open read transactions in the backend. - OpenReadTxN() int64 - Defrag() error - ForceCommit() - Close() error -} - -type Snapshot interface { - // Size gets the size of the snapshot. - Size() int64 - // WriteTo writes the snapshot into the given writer. - WriteTo(w io.Writer) (n int64, err error) - // Close closes the snapshot. - Close() error -} - -type txReadBufferCache struct { - mu sync.Mutex - buf *txReadBuffer - bufVersion uint64 -} - -type backend struct { - // size and commits are used with atomic operations so they must be - // 64-bit aligned, otherwise 32-bit tests will crash - - // size is the number of bytes allocated in the backend - size int64 - // sizeInUse is the number of bytes actually used in the backend - sizeInUse int64 - // commits counts number of commits since start - commits int64 - // openReadTxN is the number of currently open read transactions in the backend - openReadTxN int64 - // mlock prevents backend database file to be swapped - mlock bool - - mu sync.RWMutex - db *bolt.DB - - batchInterval time.Duration - batchLimit int - batchTx *batchTxBuffered - - readTx *readTx - // txReadBufferCache mirrors "txReadBuffer" within "readTx" -- readTx.baseReadTx.buf. - // When creating "concurrentReadTx": - // - if the cache is up-to-date, "readTx.baseReadTx.buf" copy can be skipped - // - if the cache is empty or outdated, "readTx.baseReadTx.buf" copy is required - txReadBufferCache txReadBufferCache - - stopc chan struct{} - donec chan struct{} - - hooks Hooks - - lg *zap.Logger -} - -type BackendConfig struct { - // Path is the file path to the backend file. - Path string - // BatchInterval is the maximum time before flushing the BatchTx. - BatchInterval time.Duration - // BatchLimit is the maximum puts before flushing the BatchTx. - BatchLimit int - // BackendFreelistType is the backend boltdb's freelist type. - BackendFreelistType bolt.FreelistType - // MmapSize is the number of bytes to mmap for the backend. - MmapSize uint64 - // Logger logs backend-side operations. - Logger *zap.Logger - // UnsafeNoFsync disables all uses of fsync. - UnsafeNoFsync bool `json:"unsafe-no-fsync"` - // Mlock prevents backend database file to be swapped - Mlock bool - - // Hooks are getting executed during lifecycle of Backend's transactions. - Hooks Hooks -} - -func DefaultBackendConfig() BackendConfig { - return BackendConfig{ - BatchInterval: defaultBatchInterval, - BatchLimit: defaultBatchLimit, - MmapSize: initialMmapSize, - } -} - -func New(bcfg BackendConfig) Backend { - return newBackend(bcfg) -} - -func NewDefaultBackend(path string) Backend { - bcfg := DefaultBackendConfig() - bcfg.Path = path - return newBackend(bcfg) -} - -func newBackend(bcfg BackendConfig) *backend { - if bcfg.Logger == nil { - bcfg.Logger = zap.NewNop() - } - - bopts := &bolt.Options{} - if boltOpenOptions != nil { - *bopts = *boltOpenOptions - } - bopts.InitialMmapSize = bcfg.mmapSize() - bopts.FreelistType = bcfg.BackendFreelistType - bopts.NoSync = bcfg.UnsafeNoFsync - bopts.NoGrowSync = bcfg.UnsafeNoFsync - bopts.Mlock = bcfg.Mlock - - db, err := bolt.Open(bcfg.Path, 0600, bopts) - if err != nil { - bcfg.Logger.Panic("failed to open database", zap.String("path", bcfg.Path), zap.Error(err)) - } - - // In future, may want to make buffering optional for low-concurrency systems - // or dynamically swap between buffered/non-buffered depending on workload. - b := &backend{ - db: db, - - batchInterval: bcfg.BatchInterval, - batchLimit: bcfg.BatchLimit, - mlock: bcfg.Mlock, - - readTx: &readTx{ - baseReadTx: baseReadTx{ - buf: txReadBuffer{ - txBuffer: txBuffer{make(map[BucketID]*bucketBuffer)}, - bufVersion: 0, - }, - buckets: make(map[BucketID]*bolt.Bucket), - txWg: new(sync.WaitGroup), - txMu: new(sync.RWMutex), - }, - }, - txReadBufferCache: txReadBufferCache{ - mu: sync.Mutex{}, - bufVersion: 0, - buf: nil, - }, - - stopc: make(chan struct{}), - donec: make(chan struct{}), - - lg: bcfg.Logger, - } - - b.batchTx = newBatchTxBuffered(b) - // We set it after newBatchTxBuffered to skip the 'empty' commit. - b.hooks = bcfg.Hooks - - go b.run() - return b -} - -// BatchTx returns the current batch tx in coalescer. The tx can be used for read and -// write operations. The write result can be retrieved within the same tx immediately. -// The write result is isolated with other txs until the current one get committed. -func (b *backend) BatchTx() BatchTx { - return b.batchTx -} - -func (b *backend) ReadTx() ReadTx { return b.readTx } - -// ConcurrentReadTx creates and returns a new ReadTx, which: -// A) creates and keeps a copy of backend.readTx.txReadBuffer, -// B) references the boltdb read Tx (and its bucket cache) of current batch interval. -func (b *backend) ConcurrentReadTx() ReadTx { - b.readTx.RLock() - defer b.readTx.RUnlock() - // prevent boltdb read Tx from been rolled back until store read Tx is done. Needs to be called when holding readTx.RLock(). - b.readTx.txWg.Add(1) - - // TODO: might want to copy the read buffer lazily - create copy when A) end of a write transaction B) end of a batch interval. - - // inspect/update cache recency iff there's no ongoing update to the cache - // this falls through if there's no cache update - - // by this line, "ConcurrentReadTx" code path is already protected against concurrent "writeback" operations - // which requires write lock to update "readTx.baseReadTx.buf". - // Which means setting "buf *txReadBuffer" with "readTx.buf.unsafeCopy()" is guaranteed to be up-to-date, - // whereas "txReadBufferCache.buf" may be stale from concurrent "writeback" operations. - // We only update "txReadBufferCache.buf" if we know "buf *txReadBuffer" is up-to-date. - // The update to "txReadBufferCache.buf" will benefit the following "ConcurrentReadTx" creation - // by avoiding copying "readTx.baseReadTx.buf". - b.txReadBufferCache.mu.Lock() - - curCache := b.txReadBufferCache.buf - curCacheVer := b.txReadBufferCache.bufVersion - curBufVer := b.readTx.buf.bufVersion - - isEmptyCache := curCache == nil - isStaleCache := curCacheVer != curBufVer - - var buf *txReadBuffer - switch { - case isEmptyCache: - // perform safe copy of buffer while holding "b.txReadBufferCache.mu.Lock" - // this is only supposed to run once so there won't be much overhead - curBuf := b.readTx.buf.unsafeCopy() - buf = &curBuf - case isStaleCache: - // to maximize the concurrency, try unsafe copy of buffer - // release the lock while copying buffer -- cache may become stale again and - // get overwritten by someone else. - // therefore, we need to check the readTx buffer version again - b.txReadBufferCache.mu.Unlock() - curBuf := b.readTx.buf.unsafeCopy() - b.txReadBufferCache.mu.Lock() - buf = &curBuf - default: - // neither empty nor stale cache, just use the current buffer - buf = curCache - } - // txReadBufferCache.bufVersion can be modified when we doing an unsafeCopy() - // as a result, curCacheVer could be no longer the same as - // txReadBufferCache.bufVersion - // if !isEmptyCache && curCacheVer != b.txReadBufferCache.bufVersion - // then the cache became stale while copying "readTx.baseReadTx.buf". - // It is safe to not update "txReadBufferCache.buf", because the next following - // "ConcurrentReadTx" creation will trigger a new "readTx.baseReadTx.buf" copy - // and "buf" is still used for the current "concurrentReadTx.baseReadTx.buf". - if isEmptyCache || curCacheVer == b.txReadBufferCache.bufVersion { - // continue if the cache is never set or no one has modified the cache - b.txReadBufferCache.buf = buf - b.txReadBufferCache.bufVersion = curBufVer - } - - b.txReadBufferCache.mu.Unlock() - - // concurrentReadTx is not supposed to write to its txReadBuffer - return &concurrentReadTx{ - baseReadTx: baseReadTx{ - buf: *buf, - txMu: b.readTx.txMu, - tx: b.readTx.tx, - buckets: b.readTx.buckets, - txWg: b.readTx.txWg, - }, - } -} - -// ForceCommit forces the current batching tx to commit. -func (b *backend) ForceCommit() { - b.batchTx.Commit() -} - -func (b *backend) Snapshot() Snapshot { - b.batchTx.Commit() - - b.mu.RLock() - defer b.mu.RUnlock() - tx, err := b.db.Begin(false) - if err != nil { - b.lg.Fatal("failed to begin tx", zap.Error(err)) - } - - stopc, donec := make(chan struct{}), make(chan struct{}) - dbBytes := tx.Size() - go func() { - defer close(donec) - // sendRateBytes is based on transferring snapshot data over a 1 gigabit/s connection - // assuming a min tcp throughput of 100MB/s. - var sendRateBytes int64 = 100 * 1024 * 1024 - warningTimeout := time.Duration(int64((float64(dbBytes) / float64(sendRateBytes)) * float64(time.Second))) - if warningTimeout < minSnapshotWarningTimeout { - warningTimeout = minSnapshotWarningTimeout - } - start := time.Now() - ticker := time.NewTicker(warningTimeout) - defer ticker.Stop() - for { - select { - case <-ticker.C: - b.lg.Warn( - "snapshotting taking too long to transfer", - zap.Duration("taking", time.Since(start)), - zap.Int64("bytes", dbBytes), - zap.String("size", humanize.Bytes(uint64(dbBytes))), - ) - - case <-stopc: - snapshotTransferSec.Observe(time.Since(start).Seconds()) - return - } - } - }() - - return &snapshot{tx, stopc, donec} -} - -func (b *backend) Hash(ignores func(bucketName, keyName []byte) bool) (uint32, error) { - h := crc32.New(crc32.MakeTable(crc32.Castagnoli)) - - b.mu.RLock() - defer b.mu.RUnlock() - err := b.db.View(func(tx *bolt.Tx) error { - c := tx.Cursor() - for next, _ := c.First(); next != nil; next, _ = c.Next() { - b := tx.Bucket(next) - if b == nil { - return fmt.Errorf("cannot get hash of bucket %s", string(next)) - } - h.Write(next) - b.ForEach(func(k, v []byte) error { - if ignores != nil && !ignores(next, k) { - h.Write(k) - h.Write(v) - } - return nil - }) - } - return nil - }) - - if err != nil { - return 0, err - } - - return h.Sum32(), nil -} - -func (b *backend) Size() int64 { - return atomic.LoadInt64(&b.size) -} - -func (b *backend) SizeInUse() int64 { - return atomic.LoadInt64(&b.sizeInUse) -} - -func (b *backend) run() { - defer close(b.donec) - t := time.NewTimer(b.batchInterval) - defer t.Stop() - for { - select { - case <-t.C: - case <-b.stopc: - b.batchTx.CommitAndStop() - return - } - if b.batchTx.safePending() != 0 { - b.batchTx.Commit() - } - t.Reset(b.batchInterval) - } -} - -func (b *backend) Close() error { - close(b.stopc) - <-b.donec - return b.db.Close() -} - -// Commits returns total number of commits since start -func (b *backend) Commits() int64 { - return atomic.LoadInt64(&b.commits) -} - -func (b *backend) Defrag() error { - return b.defrag() -} - -func (b *backend) defrag() error { - now := time.Now() - - // TODO: make this non-blocking? - // lock batchTx to ensure nobody is using previous tx, and then - // close previous ongoing tx. - b.batchTx.Lock() - defer b.batchTx.Unlock() - - // lock database after lock tx to avoid deadlock. - b.mu.Lock() - defer b.mu.Unlock() - - // block concurrent read requests while resetting tx - b.readTx.Lock() - defer b.readTx.Unlock() - - b.batchTx.unsafeCommit(true) - - b.batchTx.tx = nil - - // Create a temporary file to ensure we start with a clean slate. - // Snapshotter.cleanupSnapdir cleans up any of these that are found during startup. - dir := filepath.Dir(b.db.Path()) - temp, err := ioutil.TempFile(dir, "db.tmp.*") - if err != nil { - return err - } - options := bolt.Options{} - if boltOpenOptions != nil { - options = *boltOpenOptions - } - options.OpenFile = func(_ string, _ int, _ os.FileMode) (file *os.File, err error) { - return temp, nil - } - // Don't load tmp db into memory regardless of opening options - options.Mlock = false - tdbp := temp.Name() - tmpdb, err := bolt.Open(tdbp, 0600, &options) - if err != nil { - return err - } - - dbp := b.db.Path() - size1, sizeInUse1 := b.Size(), b.SizeInUse() - if b.lg != nil { - b.lg.Info( - "defragmenting", - zap.String("path", dbp), - zap.Int64("current-db-size-bytes", size1), - zap.String("current-db-size", humanize.Bytes(uint64(size1))), - zap.Int64("current-db-size-in-use-bytes", sizeInUse1), - zap.String("current-db-size-in-use", humanize.Bytes(uint64(sizeInUse1))), - ) - } - // gofail: var defragBeforeCopy struct{} - err = defragdb(b.db, tmpdb, defragLimit) - if err != nil { - tmpdb.Close() - if rmErr := os.RemoveAll(tmpdb.Path()); rmErr != nil { - b.lg.Error("failed to remove db.tmp after defragmentation completed", zap.Error(rmErr)) - } - return err - } - - err = b.db.Close() - if err != nil { - b.lg.Fatal("failed to close database", zap.Error(err)) - } - err = tmpdb.Close() - if err != nil { - b.lg.Fatal("failed to close tmp database", zap.Error(err)) - } - // gofail: var defragBeforeRename struct{} - err = os.Rename(tdbp, dbp) - if err != nil { - b.lg.Fatal("failed to rename tmp database", zap.Error(err)) - } - - defragmentedBoltOptions := bolt.Options{} - if boltOpenOptions != nil { - defragmentedBoltOptions = *boltOpenOptions - } - defragmentedBoltOptions.Mlock = b.mlock - - b.db, err = bolt.Open(dbp, 0600, &defragmentedBoltOptions) - if err != nil { - b.lg.Fatal("failed to open database", zap.String("path", dbp), zap.Error(err)) - } - b.batchTx.tx = b.unsafeBegin(true) - - b.readTx.reset() - b.readTx.tx = b.unsafeBegin(false) - - size := b.readTx.tx.Size() - db := b.readTx.tx.DB() - atomic.StoreInt64(&b.size, size) - atomic.StoreInt64(&b.sizeInUse, size-(int64(db.Stats().FreePageN)*int64(db.Info().PageSize))) - - took := time.Since(now) - defragSec.Observe(took.Seconds()) - - size2, sizeInUse2 := b.Size(), b.SizeInUse() - if b.lg != nil { - b.lg.Info( - "finished defragmenting directory", - zap.String("path", dbp), - zap.Int64("current-db-size-bytes-diff", size2-size1), - zap.Int64("current-db-size-bytes", size2), - zap.String("current-db-size", humanize.Bytes(uint64(size2))), - zap.Int64("current-db-size-in-use-bytes-diff", sizeInUse2-sizeInUse1), - zap.Int64("current-db-size-in-use-bytes", sizeInUse2), - zap.String("current-db-size-in-use", humanize.Bytes(uint64(sizeInUse2))), - zap.Duration("took", took), - ) - } - return nil -} - -func defragdb(odb, tmpdb *bolt.DB, limit int) error { - // open a tx on tmpdb for writes - tmptx, err := tmpdb.Begin(true) - if err != nil { - return err - } - defer func() { - if err != nil { - tmptx.Rollback() - } - }() - - // open a tx on old db for read - tx, err := odb.Begin(false) - if err != nil { - return err - } - defer tx.Rollback() - - c := tx.Cursor() - - count := 0 - for next, _ := c.First(); next != nil; next, _ = c.Next() { - b := tx.Bucket(next) - if b == nil { - return fmt.Errorf("backend: cannot defrag bucket %s", string(next)) - } - - tmpb, berr := tmptx.CreateBucketIfNotExists(next) - if berr != nil { - return berr - } - tmpb.FillPercent = 0.9 // for bucket2seq write in for each - - if err = b.ForEach(func(k, v []byte) error { - count++ - if count > limit { - err = tmptx.Commit() - if err != nil { - return err - } - tmptx, err = tmpdb.Begin(true) - if err != nil { - return err - } - tmpb = tmptx.Bucket(next) - tmpb.FillPercent = 0.9 // for bucket2seq write in for each - - count = 0 - } - return tmpb.Put(k, v) - }); err != nil { - return err - } - } - - return tmptx.Commit() -} - -func (b *backend) begin(write bool) *bolt.Tx { - b.mu.RLock() - tx := b.unsafeBegin(write) - b.mu.RUnlock() - - size := tx.Size() - db := tx.DB() - stats := db.Stats() - atomic.StoreInt64(&b.size, size) - atomic.StoreInt64(&b.sizeInUse, size-(int64(stats.FreePageN)*int64(db.Info().PageSize))) - atomic.StoreInt64(&b.openReadTxN, int64(stats.OpenTxN)) - - return tx -} - -func (b *backend) unsafeBegin(write bool) *bolt.Tx { - tx, err := b.db.Begin(write) - if err != nil { - b.lg.Fatal("failed to begin tx", zap.Error(err)) - } - return tx -} - -func (b *backend) OpenReadTxN() int64 { - return atomic.LoadInt64(&b.openReadTxN) -} - -type snapshot struct { - *bolt.Tx - stopc chan struct{} - donec chan struct{} -} - -func (s *snapshot) Close() error { - close(s.stopc) - <-s.donec - return s.Tx.Rollback() -} diff --git a/vendor/go.etcd.io/etcd/server/v3/mvcc/backend/batch_tx.go b/vendor/go.etcd.io/etcd/server/v3/mvcc/backend/batch_tx.go deleted file mode 100644 index b2b0ad7cbf..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/mvcc/backend/batch_tx.go +++ /dev/null @@ -1,344 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package backend - -import ( - "bytes" - "math" - "sync" - "sync/atomic" - "time" - - bolt "go.etcd.io/bbolt" - "go.uber.org/zap" -) - -type BucketID int - -type Bucket interface { - // ID returns a unique identifier of a bucket. - // The id must NOT be persisted and can be used as lightweight identificator - // in the in-memory maps. - ID() BucketID - Name() []byte - // String implements Stringer (human readable name). - String() string - - // IsSafeRangeBucket is a hack to avoid inadvertently reading duplicate keys; - // overwrites on a bucket should only fetch with limit=1, but safeRangeBucket - // is known to never overwrite any key so range is safe. - IsSafeRangeBucket() bool -} - -type BatchTx interface { - ReadTx - UnsafeCreateBucket(bucket Bucket) - UnsafeDeleteBucket(bucket Bucket) - UnsafePut(bucket Bucket, key []byte, value []byte) - UnsafeSeqPut(bucket Bucket, key []byte, value []byte) - UnsafeDelete(bucket Bucket, key []byte) - // Commit commits a previous tx and begins a new writable one. - Commit() - // CommitAndStop commits the previous tx and does not create a new one. - CommitAndStop() -} - -type batchTx struct { - sync.Mutex - tx *bolt.Tx - backend *backend - - pending int -} - -func (t *batchTx) Lock() { - t.Mutex.Lock() -} - -func (t *batchTx) Unlock() { - if t.pending >= t.backend.batchLimit { - t.commit(false) - } - t.Mutex.Unlock() -} - -// BatchTx interface embeds ReadTx interface. But RLock() and RUnlock() do not -// have appropriate semantics in BatchTx interface. Therefore should not be called. -// TODO: might want to decouple ReadTx and BatchTx - -func (t *batchTx) RLock() { - panic("unexpected RLock") -} - -func (t *batchTx) RUnlock() { - panic("unexpected RUnlock") -} - -func (t *batchTx) UnsafeCreateBucket(bucket Bucket) { - _, err := t.tx.CreateBucket(bucket.Name()) - if err != nil && err != bolt.ErrBucketExists { - t.backend.lg.Fatal( - "failed to create a bucket", - zap.Stringer("bucket-name", bucket), - zap.Error(err), - ) - } - t.pending++ -} - -func (t *batchTx) UnsafeDeleteBucket(bucket Bucket) { - err := t.tx.DeleteBucket(bucket.Name()) - if err != nil && err != bolt.ErrBucketNotFound { - t.backend.lg.Fatal( - "failed to delete a bucket", - zap.Stringer("bucket-name", bucket), - zap.Error(err), - ) - } - t.pending++ -} - -// UnsafePut must be called holding the lock on the tx. -func (t *batchTx) UnsafePut(bucket Bucket, key []byte, value []byte) { - t.unsafePut(bucket, key, value, false) -} - -// UnsafeSeqPut must be called holding the lock on the tx. -func (t *batchTx) UnsafeSeqPut(bucket Bucket, key []byte, value []byte) { - t.unsafePut(bucket, key, value, true) -} - -func (t *batchTx) unsafePut(bucketType Bucket, key []byte, value []byte, seq bool) { - bucket := t.tx.Bucket(bucketType.Name()) - if bucket == nil { - t.backend.lg.Fatal( - "failed to find a bucket", - zap.Stringer("bucket-name", bucketType), - zap.Stack("stack"), - ) - } - if seq { - // it is useful to increase fill percent when the workloads are mostly append-only. - // this can delay the page split and reduce space usage. - bucket.FillPercent = 0.9 - } - if err := bucket.Put(key, value); err != nil { - t.backend.lg.Fatal( - "failed to write to a bucket", - zap.Stringer("bucket-name", bucketType), - zap.Error(err), - ) - } - t.pending++ -} - -// UnsafeRange must be called holding the lock on the tx. -func (t *batchTx) UnsafeRange(bucketType Bucket, key, endKey []byte, limit int64) ([][]byte, [][]byte) { - bucket := t.tx.Bucket(bucketType.Name()) - if bucket == nil { - t.backend.lg.Fatal( - "failed to find a bucket", - zap.Stringer("bucket-name", bucketType), - zap.Stack("stack"), - ) - } - return unsafeRange(bucket.Cursor(), key, endKey, limit) -} - -func unsafeRange(c *bolt.Cursor, key, endKey []byte, limit int64) (keys [][]byte, vs [][]byte) { - if limit <= 0 { - limit = math.MaxInt64 - } - var isMatch func(b []byte) bool - if len(endKey) > 0 { - isMatch = func(b []byte) bool { return bytes.Compare(b, endKey) < 0 } - } else { - isMatch = func(b []byte) bool { return bytes.Equal(b, key) } - limit = 1 - } - - for ck, cv := c.Seek(key); ck != nil && isMatch(ck); ck, cv = c.Next() { - vs = append(vs, cv) - keys = append(keys, ck) - if limit == int64(len(keys)) { - break - } - } - return keys, vs -} - -// UnsafeDelete must be called holding the lock on the tx. -func (t *batchTx) UnsafeDelete(bucketType Bucket, key []byte) { - bucket := t.tx.Bucket(bucketType.Name()) - if bucket == nil { - t.backend.lg.Fatal( - "failed to find a bucket", - zap.Stringer("bucket-name", bucketType), - zap.Stack("stack"), - ) - } - err := bucket.Delete(key) - if err != nil { - t.backend.lg.Fatal( - "failed to delete a key", - zap.Stringer("bucket-name", bucketType), - zap.Error(err), - ) - } - t.pending++ -} - -// UnsafeForEach must be called holding the lock on the tx. -func (t *batchTx) UnsafeForEach(bucket Bucket, visitor func(k, v []byte) error) error { - return unsafeForEach(t.tx, bucket, visitor) -} - -func unsafeForEach(tx *bolt.Tx, bucket Bucket, visitor func(k, v []byte) error) error { - if b := tx.Bucket(bucket.Name()); b != nil { - return b.ForEach(visitor) - } - return nil -} - -// Commit commits a previous tx and begins a new writable one. -func (t *batchTx) Commit() { - t.Lock() - t.commit(false) - t.Unlock() -} - -// CommitAndStop commits the previous tx and does not create a new one. -func (t *batchTx) CommitAndStop() { - t.Lock() - t.commit(true) - t.Unlock() -} - -func (t *batchTx) safePending() int { - t.Mutex.Lock() - defer t.Mutex.Unlock() - return t.pending -} - -func (t *batchTx) commit(stop bool) { - // commit the last tx - if t.tx != nil { - if t.pending == 0 && !stop { - return - } - - start := time.Now() - - // gofail: var beforeCommit struct{} - err := t.tx.Commit() - // gofail: var afterCommit struct{} - - rebalanceSec.Observe(t.tx.Stats().RebalanceTime.Seconds()) - spillSec.Observe(t.tx.Stats().SpillTime.Seconds()) - writeSec.Observe(t.tx.Stats().WriteTime.Seconds()) - commitSec.Observe(time.Since(start).Seconds()) - atomic.AddInt64(&t.backend.commits, 1) - - t.pending = 0 - if err != nil { - t.backend.lg.Fatal("failed to commit tx", zap.Error(err)) - } - } - if !stop { - t.tx = t.backend.begin(true) - } -} - -type batchTxBuffered struct { - batchTx - buf txWriteBuffer -} - -func newBatchTxBuffered(backend *backend) *batchTxBuffered { - tx := &batchTxBuffered{ - batchTx: batchTx{backend: backend}, - buf: txWriteBuffer{ - txBuffer: txBuffer{make(map[BucketID]*bucketBuffer)}, - bucket2seq: make(map[BucketID]bool), - }, - } - tx.Commit() - return tx -} - -func (t *batchTxBuffered) Unlock() { - if t.pending != 0 { - t.backend.readTx.Lock() // blocks txReadBuffer for writing. - t.buf.writeback(&t.backend.readTx.buf) - t.backend.readTx.Unlock() - if t.pending >= t.backend.batchLimit { - t.commit(false) - } - } - t.batchTx.Unlock() -} - -func (t *batchTxBuffered) Commit() { - t.Lock() - t.commit(false) - t.Unlock() -} - -func (t *batchTxBuffered) CommitAndStop() { - t.Lock() - t.commit(true) - t.Unlock() -} - -func (t *batchTxBuffered) commit(stop bool) { - if t.backend.hooks != nil { - t.backend.hooks.OnPreCommitUnsafe(t) - } - - // all read txs must be closed to acquire boltdb commit rwlock - t.backend.readTx.Lock() - t.unsafeCommit(stop) - t.backend.readTx.Unlock() -} - -func (t *batchTxBuffered) unsafeCommit(stop bool) { - if t.backend.readTx.tx != nil { - // wait all store read transactions using the current boltdb tx to finish, - // then close the boltdb tx - go func(tx *bolt.Tx, wg *sync.WaitGroup) { - wg.Wait() - if err := tx.Rollback(); err != nil { - t.backend.lg.Fatal("failed to rollback tx", zap.Error(err)) - } - }(t.backend.readTx.tx, t.backend.readTx.txWg) - t.backend.readTx.reset() - } - - t.batchTx.commit(stop) - - if !stop { - t.backend.readTx.tx = t.backend.begin(false) - } -} - -func (t *batchTxBuffered) UnsafePut(bucket Bucket, key []byte, value []byte) { - t.batchTx.UnsafePut(bucket, key, value) - t.buf.put(bucket, key, value) -} - -func (t *batchTxBuffered) UnsafeSeqPut(bucket Bucket, key []byte, value []byte) { - t.batchTx.UnsafeSeqPut(bucket, key, value) - t.buf.putSeq(bucket, key, value) -} diff --git a/vendor/go.etcd.io/etcd/server/v3/mvcc/backend/config_default.go b/vendor/go.etcd.io/etcd/server/v3/mvcc/backend/config_default.go deleted file mode 100644 index 847bd10fd7..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/mvcc/backend/config_default.go +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -//go:build !linux && !windows -// +build !linux,!windows - -package backend - -import bolt "go.etcd.io/bbolt" - -var boltOpenOptions *bolt.Options - -func (bcfg *BackendConfig) mmapSize() int { return int(bcfg.MmapSize) } diff --git a/vendor/go.etcd.io/etcd/server/v3/mvcc/backend/config_linux.go b/vendor/go.etcd.io/etcd/server/v3/mvcc/backend/config_linux.go deleted file mode 100644 index f712671af4..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/mvcc/backend/config_linux.go +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package backend - -import ( - "syscall" - - bolt "go.etcd.io/bbolt" -) - -// syscall.MAP_POPULATE on linux 2.6.23+ does sequential read-ahead -// which can speed up entire-database read with boltdb. We want to -// enable MAP_POPULATE for faster key-value store recovery in storage -// package. If your kernel version is lower than 2.6.23 -// (https://github.com/torvalds/linux/releases/tag/v2.6.23), mmap might -// silently ignore this flag. Please update your kernel to prevent this. -var boltOpenOptions = &bolt.Options{ - MmapFlags: syscall.MAP_POPULATE, - NoFreelistSync: true, -} - -func (bcfg *BackendConfig) mmapSize() int { return int(bcfg.MmapSize) } diff --git a/vendor/go.etcd.io/etcd/server/v3/mvcc/backend/config_windows.go b/vendor/go.etcd.io/etcd/server/v3/mvcc/backend/config_windows.go deleted file mode 100644 index ba6e5a1284..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/mvcc/backend/config_windows.go +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -//go:build windows -// +build windows - -package backend - -import bolt "go.etcd.io/bbolt" - -var boltOpenOptions *bolt.Options = nil - -// setting mmap size != 0 on windows will allocate the entire -// mmap size for the file, instead of growing it. So, force 0. - -func (bcfg *BackendConfig) mmapSize() int { return 0 } diff --git a/vendor/go.etcd.io/etcd/server/v3/mvcc/backend/doc.go b/vendor/go.etcd.io/etcd/server/v3/mvcc/backend/doc.go deleted file mode 100644 index 9cc42fa793..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/mvcc/backend/doc.go +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package backend defines a standard interface for etcd's backend MVCC storage. -package backend diff --git a/vendor/go.etcd.io/etcd/server/v3/mvcc/backend/hooks.go b/vendor/go.etcd.io/etcd/server/v3/mvcc/backend/hooks.go deleted file mode 100644 index 9750828ef7..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/mvcc/backend/hooks.go +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright 2021 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package backend - -type HookFunc func(tx BatchTx) - -// Hooks allow to add additional logic executed during transaction lifetime. -type Hooks interface { - // OnPreCommitUnsafe is executed before Commit of transactions. - // The given transaction is already locked. - OnPreCommitUnsafe(tx BatchTx) -} - -type hooks struct { - onPreCommitUnsafe HookFunc -} - -func (h hooks) OnPreCommitUnsafe(tx BatchTx) { - h.onPreCommitUnsafe(tx) -} - -func NewHooks(onPreCommitUnsafe HookFunc) Hooks { - return hooks{onPreCommitUnsafe: onPreCommitUnsafe} -} diff --git a/vendor/go.etcd.io/etcd/server/v3/mvcc/backend/metrics.go b/vendor/go.etcd.io/etcd/server/v3/mvcc/backend/metrics.go deleted file mode 100644 index d9641af7ae..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/mvcc/backend/metrics.go +++ /dev/null @@ -1,95 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package backend - -import "github.com/prometheus/client_golang/prometheus" - -var ( - commitSec = prometheus.NewHistogram(prometheus.HistogramOpts{ - Namespace: "etcd", - Subsystem: "disk", - Name: "backend_commit_duration_seconds", - Help: "The latency distributions of commit called by backend.", - - // lowest bucket start of upper bound 0.001 sec (1 ms) with factor 2 - // highest bucket start of 0.001 sec * 2^13 == 8.192 sec - Buckets: prometheus.ExponentialBuckets(0.001, 2, 14), - }) - - rebalanceSec = prometheus.NewHistogram(prometheus.HistogramOpts{ - Namespace: "etcd_debugging", - Subsystem: "disk", - Name: "backend_commit_rebalance_duration_seconds", - Help: "The latency distributions of commit.rebalance called by bboltdb backend.", - - // lowest bucket start of upper bound 0.001 sec (1 ms) with factor 2 - // highest bucket start of 0.001 sec * 2^13 == 8.192 sec - Buckets: prometheus.ExponentialBuckets(0.001, 2, 14), - }) - - spillSec = prometheus.NewHistogram(prometheus.HistogramOpts{ - Namespace: "etcd_debugging", - Subsystem: "disk", - Name: "backend_commit_spill_duration_seconds", - Help: "The latency distributions of commit.spill called by bboltdb backend.", - - // lowest bucket start of upper bound 0.001 sec (1 ms) with factor 2 - // highest bucket start of 0.001 sec * 2^13 == 8.192 sec - Buckets: prometheus.ExponentialBuckets(0.001, 2, 14), - }) - - writeSec = prometheus.NewHistogram(prometheus.HistogramOpts{ - Namespace: "etcd_debugging", - Subsystem: "disk", - Name: "backend_commit_write_duration_seconds", - Help: "The latency distributions of commit.write called by bboltdb backend.", - - // lowest bucket start of upper bound 0.001 sec (1 ms) with factor 2 - // highest bucket start of 0.001 sec * 2^13 == 8.192 sec - Buckets: prometheus.ExponentialBuckets(0.001, 2, 14), - }) - - defragSec = prometheus.NewHistogram(prometheus.HistogramOpts{ - Namespace: "etcd", - Subsystem: "disk", - Name: "backend_defrag_duration_seconds", - Help: "The latency distribution of backend defragmentation.", - - // 100 MB usually takes 1 sec, so start with 10 MB of 100 ms - // lowest bucket start of upper bound 0.1 sec (100 ms) with factor 2 - // highest bucket start of 0.1 sec * 2^12 == 409.6 sec - Buckets: prometheus.ExponentialBuckets(.1, 2, 13), - }) - - snapshotTransferSec = prometheus.NewHistogram(prometheus.HistogramOpts{ - Namespace: "etcd", - Subsystem: "disk", - Name: "backend_snapshot_duration_seconds", - Help: "The latency distribution of backend snapshots.", - - // lowest bucket start of upper bound 0.01 sec (10 ms) with factor 2 - // highest bucket start of 0.01 sec * 2^16 == 655.36 sec - Buckets: prometheus.ExponentialBuckets(.01, 2, 17), - }) -) - -func init() { - prometheus.MustRegister(commitSec) - prometheus.MustRegister(rebalanceSec) - prometheus.MustRegister(spillSec) - prometheus.MustRegister(writeSec) - prometheus.MustRegister(defragSec) - prometheus.MustRegister(snapshotTransferSec) -} diff --git a/vendor/go.etcd.io/etcd/server/v3/mvcc/backend/read_tx.go b/vendor/go.etcd.io/etcd/server/v3/mvcc/backend/read_tx.go deleted file mode 100644 index 56327d52ae..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/mvcc/backend/read_tx.go +++ /dev/null @@ -1,150 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package backend - -import ( - "math" - "sync" - - bolt "go.etcd.io/bbolt" -) - -// IsSafeRangeBucket is a hack to avoid inadvertently reading duplicate keys; -// overwrites on a bucket should only fetch with limit=1, but IsSafeRangeBucket -// is known to never overwrite any key so range is safe. - -type ReadTx interface { - Lock() - Unlock() - RLock() - RUnlock() - - UnsafeRange(bucket Bucket, key, endKey []byte, limit int64) (keys [][]byte, vals [][]byte) - UnsafeForEach(bucket Bucket, visitor func(k, v []byte) error) error -} - -// Base type for readTx and concurrentReadTx to eliminate duplicate functions between these -type baseReadTx struct { - // mu protects accesses to the txReadBuffer - mu sync.RWMutex - buf txReadBuffer - - // TODO: group and encapsulate {txMu, tx, buckets, txWg}, as they share the same lifecycle. - // txMu protects accesses to buckets and tx on Range requests. - txMu *sync.RWMutex - tx *bolt.Tx - buckets map[BucketID]*bolt.Bucket - // txWg protects tx from being rolled back at the end of a batch interval until all reads using this tx are done. - txWg *sync.WaitGroup -} - -func (baseReadTx *baseReadTx) UnsafeForEach(bucket Bucket, visitor func(k, v []byte) error) error { - dups := make(map[string]struct{}) - getDups := func(k, v []byte) error { - dups[string(k)] = struct{}{} - return nil - } - visitNoDup := func(k, v []byte) error { - if _, ok := dups[string(k)]; ok { - return nil - } - return visitor(k, v) - } - if err := baseReadTx.buf.ForEach(bucket, getDups); err != nil { - return err - } - baseReadTx.txMu.Lock() - err := unsafeForEach(baseReadTx.tx, bucket, visitNoDup) - baseReadTx.txMu.Unlock() - if err != nil { - return err - } - return baseReadTx.buf.ForEach(bucket, visitor) -} - -func (baseReadTx *baseReadTx) UnsafeRange(bucketType Bucket, key, endKey []byte, limit int64) ([][]byte, [][]byte) { - if endKey == nil { - // forbid duplicates for single keys - limit = 1 - } - if limit <= 0 { - limit = math.MaxInt64 - } - if limit > 1 && !bucketType.IsSafeRangeBucket() { - panic("do not use unsafeRange on non-keys bucket") - } - keys, vals := baseReadTx.buf.Range(bucketType, key, endKey, limit) - if int64(len(keys)) == limit { - return keys, vals - } - - // find/cache bucket - bn := bucketType.ID() - baseReadTx.txMu.RLock() - bucket, ok := baseReadTx.buckets[bn] - baseReadTx.txMu.RUnlock() - lockHeld := false - if !ok { - baseReadTx.txMu.Lock() - lockHeld = true - bucket = baseReadTx.tx.Bucket(bucketType.Name()) - baseReadTx.buckets[bn] = bucket - } - - // ignore missing bucket since may have been created in this batch - if bucket == nil { - if lockHeld { - baseReadTx.txMu.Unlock() - } - return keys, vals - } - if !lockHeld { - baseReadTx.txMu.Lock() - } - c := bucket.Cursor() - baseReadTx.txMu.Unlock() - - k2, v2 := unsafeRange(c, key, endKey, limit-int64(len(keys))) - return append(k2, keys...), append(v2, vals...) -} - -type readTx struct { - baseReadTx -} - -func (rt *readTx) Lock() { rt.mu.Lock() } -func (rt *readTx) Unlock() { rt.mu.Unlock() } -func (rt *readTx) RLock() { rt.mu.RLock() } -func (rt *readTx) RUnlock() { rt.mu.RUnlock() } - -func (rt *readTx) reset() { - rt.buf.reset() - rt.buckets = make(map[BucketID]*bolt.Bucket) - rt.tx = nil - rt.txWg = new(sync.WaitGroup) -} - -type concurrentReadTx struct { - baseReadTx -} - -func (rt *concurrentReadTx) Lock() {} -func (rt *concurrentReadTx) Unlock() {} - -// RLock is no-op. concurrentReadTx does not need to be locked after it is created. -func (rt *concurrentReadTx) RLock() {} - -// RUnlock signals the end of concurrentReadTx. -func (rt *concurrentReadTx) RUnlock() { rt.txWg.Done() } diff --git a/vendor/go.etcd.io/etcd/server/v3/mvcc/backend/tx_buffer.go b/vendor/go.etcd.io/etcd/server/v3/mvcc/backend/tx_buffer.go deleted file mode 100644 index 6674002483..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/mvcc/backend/tx_buffer.go +++ /dev/null @@ -1,231 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package backend - -import ( - "bytes" - "sort" -) - -const bucketBufferInitialSize = 512 - -// txBuffer handles functionality shared between txWriteBuffer and txReadBuffer. -type txBuffer struct { - buckets map[BucketID]*bucketBuffer -} - -func (txb *txBuffer) reset() { - for k, v := range txb.buckets { - if v.used == 0 { - // demote - delete(txb.buckets, k) - } - v.used = 0 - } -} - -// txWriteBuffer buffers writes of pending updates that have not yet committed. -type txWriteBuffer struct { - txBuffer - // Map from bucket ID into information whether this bucket is edited - // sequentially (i.e. keys are growing monotonically). - bucket2seq map[BucketID]bool -} - -func (txw *txWriteBuffer) put(bucket Bucket, k, v []byte) { - txw.bucket2seq[bucket.ID()] = false - txw.putInternal(bucket, k, v) -} - -func (txw *txWriteBuffer) putSeq(bucket Bucket, k, v []byte) { - // TODO: Add (in tests?) verification whether k>b[len(b)] - txw.putInternal(bucket, k, v) -} - -func (txw *txWriteBuffer) putInternal(bucket Bucket, k, v []byte) { - b, ok := txw.buckets[bucket.ID()] - if !ok { - b = newBucketBuffer() - txw.buckets[bucket.ID()] = b - } - b.add(k, v) -} - -func (txw *txWriteBuffer) reset() { - txw.txBuffer.reset() - for k := range txw.bucket2seq { - v, ok := txw.buckets[k] - if !ok { - delete(txw.bucket2seq, k) - } else if v.used == 0 { - txw.bucket2seq[k] = true - } - } -} - -func (txw *txWriteBuffer) writeback(txr *txReadBuffer) { - for k, wb := range txw.buckets { - rb, ok := txr.buckets[k] - if !ok { - delete(txw.buckets, k) - txr.buckets[k] = wb - continue - } - if seq, ok := txw.bucket2seq[k]; ok && !seq && wb.used > 1 { - // assume no duplicate keys - sort.Sort(wb) - } - rb.merge(wb) - } - txw.reset() - // increase the buffer version - txr.bufVersion++ -} - -// txReadBuffer accesses buffered updates. -type txReadBuffer struct { - txBuffer - // bufVersion is used to check if the buffer is modified recently - bufVersion uint64 -} - -func (txr *txReadBuffer) Range(bucket Bucket, key, endKey []byte, limit int64) ([][]byte, [][]byte) { - if b := txr.buckets[bucket.ID()]; b != nil { - return b.Range(key, endKey, limit) - } - return nil, nil -} - -func (txr *txReadBuffer) ForEach(bucket Bucket, visitor func(k, v []byte) error) error { - if b := txr.buckets[bucket.ID()]; b != nil { - return b.ForEach(visitor) - } - return nil -} - -// unsafeCopy returns a copy of txReadBuffer, caller should acquire backend.readTx.RLock() -func (txr *txReadBuffer) unsafeCopy() txReadBuffer { - txrCopy := txReadBuffer{ - txBuffer: txBuffer{ - buckets: make(map[BucketID]*bucketBuffer, len(txr.txBuffer.buckets)), - }, - bufVersion: 0, - } - for bucketName, bucket := range txr.txBuffer.buckets { - txrCopy.txBuffer.buckets[bucketName] = bucket.Copy() - } - return txrCopy -} - -type kv struct { - key []byte - val []byte -} - -// bucketBuffer buffers key-value pairs that are pending commit. -type bucketBuffer struct { - buf []kv - // used tracks number of elements in use so buf can be reused without reallocation. - used int -} - -func newBucketBuffer() *bucketBuffer { - return &bucketBuffer{buf: make([]kv, bucketBufferInitialSize), used: 0} -} - -func (bb *bucketBuffer) Range(key, endKey []byte, limit int64) (keys [][]byte, vals [][]byte) { - f := func(i int) bool { return bytes.Compare(bb.buf[i].key, key) >= 0 } - idx := sort.Search(bb.used, f) - if idx < 0 { - return nil, nil - } - if len(endKey) == 0 { - if bytes.Equal(key, bb.buf[idx].key) { - keys = append(keys, bb.buf[idx].key) - vals = append(vals, bb.buf[idx].val) - } - return keys, vals - } - if bytes.Compare(endKey, bb.buf[idx].key) <= 0 { - return nil, nil - } - for i := idx; i < bb.used && int64(len(keys)) < limit; i++ { - if bytes.Compare(endKey, bb.buf[i].key) <= 0 { - break - } - keys = append(keys, bb.buf[i].key) - vals = append(vals, bb.buf[i].val) - } - return keys, vals -} - -func (bb *bucketBuffer) ForEach(visitor func(k, v []byte) error) error { - for i := 0; i < bb.used; i++ { - if err := visitor(bb.buf[i].key, bb.buf[i].val); err != nil { - return err - } - } - return nil -} - -func (bb *bucketBuffer) add(k, v []byte) { - bb.buf[bb.used].key, bb.buf[bb.used].val = k, v - bb.used++ - if bb.used == len(bb.buf) { - buf := make([]kv, (3*len(bb.buf))/2) - copy(buf, bb.buf) - bb.buf = buf - } -} - -// merge merges data from bbsrc into bb. -func (bb *bucketBuffer) merge(bbsrc *bucketBuffer) { - for i := 0; i < bbsrc.used; i++ { - bb.add(bbsrc.buf[i].key, bbsrc.buf[i].val) - } - if bb.used == bbsrc.used { - return - } - if bytes.Compare(bb.buf[(bb.used-bbsrc.used)-1].key, bbsrc.buf[0].key) < 0 { - return - } - - sort.Stable(bb) - - // remove duplicates, using only newest update - widx := 0 - for ridx := 1; ridx < bb.used; ridx++ { - if !bytes.Equal(bb.buf[ridx].key, bb.buf[widx].key) { - widx++ - } - bb.buf[widx] = bb.buf[ridx] - } - bb.used = widx + 1 -} - -func (bb *bucketBuffer) Len() int { return bb.used } -func (bb *bucketBuffer) Less(i, j int) bool { - return bytes.Compare(bb.buf[i].key, bb.buf[j].key) < 0 -} -func (bb *bucketBuffer) Swap(i, j int) { bb.buf[i], bb.buf[j] = bb.buf[j], bb.buf[i] } - -func (bb *bucketBuffer) Copy() *bucketBuffer { - bbCopy := bucketBuffer{ - buf: make([]kv, len(bb.buf)), - used: bb.used, - } - copy(bbCopy.buf, bb.buf) - return &bbCopy -} diff --git a/vendor/go.etcd.io/etcd/server/v3/mvcc/buckets/bucket.go b/vendor/go.etcd.io/etcd/server/v3/mvcc/buckets/bucket.go deleted file mode 100644 index 9214f72f25..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/mvcc/buckets/bucket.go +++ /dev/null @@ -1,80 +0,0 @@ -// Copyright 2021 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package buckets - -import ( - "bytes" - - "go.etcd.io/etcd/server/v3/mvcc/backend" -) - -var ( - keyBucketName = []byte("key") - metaBucketName = []byte("meta") - leaseBucketName = []byte("lease") - alarmBucketName = []byte("alarm") - - clusterBucketName = []byte("cluster") - - membersBucketName = []byte("members") - membersRemovedBucketName = []byte("members_removed") - - authBucketName = []byte("auth") - authUsersBucketName = []byte("authUsers") - authRolesBucketName = []byte("authRoles") - - testBucketName = []byte("test") -) - -var ( - Key = backend.Bucket(bucket{id: 1, name: keyBucketName, safeRangeBucket: true}) - Meta = backend.Bucket(bucket{id: 2, name: metaBucketName, safeRangeBucket: false}) - Lease = backend.Bucket(bucket{id: 3, name: leaseBucketName, safeRangeBucket: false}) - Alarm = backend.Bucket(bucket{id: 4, name: alarmBucketName, safeRangeBucket: false}) - Cluster = backend.Bucket(bucket{id: 5, name: clusterBucketName, safeRangeBucket: false}) - - Members = backend.Bucket(bucket{id: 10, name: membersBucketName, safeRangeBucket: false}) - MembersRemoved = backend.Bucket(bucket{id: 11, name: membersRemovedBucketName, safeRangeBucket: false}) - - Auth = backend.Bucket(bucket{id: 20, name: authBucketName, safeRangeBucket: false}) - AuthUsers = backend.Bucket(bucket{id: 21, name: authUsersBucketName, safeRangeBucket: false}) - AuthRoles = backend.Bucket(bucket{id: 22, name: authRolesBucketName, safeRangeBucket: false}) - - Test = backend.Bucket(bucket{id: 100, name: testBucketName, safeRangeBucket: false}) -) - -type bucket struct { - id backend.BucketID - name []byte - safeRangeBucket bool -} - -func (b bucket) ID() backend.BucketID { return b.id } -func (b bucket) Name() []byte { return b.name } -func (b bucket) String() string { return string(b.Name()) } -func (b bucket) IsSafeRangeBucket() bool { return b.safeRangeBucket } - -var ( - MetaConsistentIndexKeyName = []byte("consistent_index") - MetaTermKeyName = []byte("term") -) - -// DefaultIgnores defines buckets & keys to ignore in hash checking. -func DefaultIgnores(bucket, key []byte) bool { - // consistent index & term might be changed due to v2 internal sync, which - // is not controllable by the user. - return bytes.Compare(bucket, Meta.Name()) == 0 && - (bytes.Compare(key, MetaTermKeyName) == 0 || bytes.Compare(key, MetaConsistentIndexKeyName) == 0) -} diff --git a/vendor/go.etcd.io/etcd/server/v3/mvcc/doc.go b/vendor/go.etcd.io/etcd/server/v3/mvcc/doc.go deleted file mode 100644 index ad5be03086..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/mvcc/doc.go +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package mvcc defines etcd's stable MVCC storage. -package mvcc diff --git a/vendor/go.etcd.io/etcd/server/v3/mvcc/index.go b/vendor/go.etcd.io/etcd/server/v3/mvcc/index.go deleted file mode 100644 index 0a5cb00516..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/mvcc/index.go +++ /dev/null @@ -1,276 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package mvcc - -import ( - "sort" - "sync" - - "github.com/google/btree" - "go.uber.org/zap" -) - -type index interface { - Get(key []byte, atRev int64) (rev, created revision, ver int64, err error) - Range(key, end []byte, atRev int64) ([][]byte, []revision) - Revisions(key, end []byte, atRev int64, limit int) ([]revision, int) - CountRevisions(key, end []byte, atRev int64) int - Put(key []byte, rev revision) - Tombstone(key []byte, rev revision) error - RangeSince(key, end []byte, rev int64) []revision - Compact(rev int64) map[revision]struct{} - Keep(rev int64) map[revision]struct{} - Equal(b index) bool - - Insert(ki *keyIndex) - KeyIndex(ki *keyIndex) *keyIndex -} - -type treeIndex struct { - sync.RWMutex - tree *btree.BTree - lg *zap.Logger -} - -func newTreeIndex(lg *zap.Logger) index { - return &treeIndex{ - tree: btree.New(32), - lg: lg, - } -} - -func (ti *treeIndex) Put(key []byte, rev revision) { - keyi := &keyIndex{key: key} - - ti.Lock() - defer ti.Unlock() - item := ti.tree.Get(keyi) - if item == nil { - keyi.put(ti.lg, rev.main, rev.sub) - ti.tree.ReplaceOrInsert(keyi) - return - } - okeyi := item.(*keyIndex) - okeyi.put(ti.lg, rev.main, rev.sub) -} - -func (ti *treeIndex) Get(key []byte, atRev int64) (modified, created revision, ver int64, err error) { - keyi := &keyIndex{key: key} - ti.RLock() - defer ti.RUnlock() - if keyi = ti.keyIndex(keyi); keyi == nil { - return revision{}, revision{}, 0, ErrRevisionNotFound - } - return keyi.get(ti.lg, atRev) -} - -func (ti *treeIndex) KeyIndex(keyi *keyIndex) *keyIndex { - ti.RLock() - defer ti.RUnlock() - return ti.keyIndex(keyi) -} - -func (ti *treeIndex) keyIndex(keyi *keyIndex) *keyIndex { - if item := ti.tree.Get(keyi); item != nil { - return item.(*keyIndex) - } - return nil -} - -func (ti *treeIndex) visit(key, end []byte, f func(ki *keyIndex) bool) { - keyi, endi := &keyIndex{key: key}, &keyIndex{key: end} - - ti.RLock() - defer ti.RUnlock() - - ti.tree.AscendGreaterOrEqual(keyi, func(item btree.Item) bool { - if len(endi.key) > 0 && !item.Less(endi) { - return false - } - if !f(item.(*keyIndex)) { - return false - } - return true - }) -} - -func (ti *treeIndex) Revisions(key, end []byte, atRev int64, limit int) (revs []revision, total int) { - if end == nil { - rev, _, _, err := ti.Get(key, atRev) - if err != nil { - return nil, 0 - } - return []revision{rev}, 1 - } - ti.visit(key, end, func(ki *keyIndex) bool { - if rev, _, _, err := ki.get(ti.lg, atRev); err == nil { - if limit <= 0 || len(revs) < limit { - revs = append(revs, rev) - } - total++ - } - return true - }) - return revs, total -} - -func (ti *treeIndex) CountRevisions(key, end []byte, atRev int64) int { - if end == nil { - _, _, _, err := ti.Get(key, atRev) - if err != nil { - return 0 - } - return 1 - } - total := 0 - ti.visit(key, end, func(ki *keyIndex) bool { - if _, _, _, err := ki.get(ti.lg, atRev); err == nil { - total++ - } - return true - }) - return total -} - -func (ti *treeIndex) Range(key, end []byte, atRev int64) (keys [][]byte, revs []revision) { - if end == nil { - rev, _, _, err := ti.Get(key, atRev) - if err != nil { - return nil, nil - } - return [][]byte{key}, []revision{rev} - } - ti.visit(key, end, func(ki *keyIndex) bool { - if rev, _, _, err := ki.get(ti.lg, atRev); err == nil { - revs = append(revs, rev) - keys = append(keys, ki.key) - } - return true - }) - return keys, revs -} - -func (ti *treeIndex) Tombstone(key []byte, rev revision) error { - keyi := &keyIndex{key: key} - - ti.Lock() - defer ti.Unlock() - item := ti.tree.Get(keyi) - if item == nil { - return ErrRevisionNotFound - } - - ki := item.(*keyIndex) - return ki.tombstone(ti.lg, rev.main, rev.sub) -} - -// RangeSince returns all revisions from key(including) to end(excluding) -// at or after the given rev. The returned slice is sorted in the order -// of revision. -func (ti *treeIndex) RangeSince(key, end []byte, rev int64) []revision { - keyi := &keyIndex{key: key} - - ti.RLock() - defer ti.RUnlock() - - if end == nil { - item := ti.tree.Get(keyi) - if item == nil { - return nil - } - keyi = item.(*keyIndex) - return keyi.since(ti.lg, rev) - } - - endi := &keyIndex{key: end} - var revs []revision - ti.tree.AscendGreaterOrEqual(keyi, func(item btree.Item) bool { - if len(endi.key) > 0 && !item.Less(endi) { - return false - } - curKeyi := item.(*keyIndex) - revs = append(revs, curKeyi.since(ti.lg, rev)...) - return true - }) - sort.Sort(revisions(revs)) - - return revs -} - -func (ti *treeIndex) Compact(rev int64) map[revision]struct{} { - available := make(map[revision]struct{}) - ti.lg.Info("compact tree index", zap.Int64("revision", rev)) - ti.Lock() - clone := ti.tree.Clone() - ti.Unlock() - - clone.Ascend(func(item btree.Item) bool { - keyi := item.(*keyIndex) - //Lock is needed here to prevent modification to the keyIndex while - //compaction is going on or revision added to empty before deletion - ti.Lock() - keyi.compact(ti.lg, rev, available) - if keyi.isEmpty() { - item := ti.tree.Delete(keyi) - if item == nil { - ti.lg.Panic("failed to delete during compaction") - } - } - ti.Unlock() - return true - }) - return available -} - -// Keep finds all revisions to be kept for a Compaction at the given rev. -func (ti *treeIndex) Keep(rev int64) map[revision]struct{} { - available := make(map[revision]struct{}) - ti.RLock() - defer ti.RUnlock() - ti.tree.Ascend(func(i btree.Item) bool { - keyi := i.(*keyIndex) - keyi.keep(rev, available) - return true - }) - return available -} - -func (ti *treeIndex) Equal(bi index) bool { - b := bi.(*treeIndex) - - if ti.tree.Len() != b.tree.Len() { - return false - } - - equal := true - - ti.tree.Ascend(func(item btree.Item) bool { - aki := item.(*keyIndex) - bki := b.tree.Get(item).(*keyIndex) - if !aki.equal(bki) { - equal = false - return false - } - return true - }) - - return equal -} - -func (ti *treeIndex) Insert(ki *keyIndex) { - ti.Lock() - defer ti.Unlock() - ti.tree.ReplaceOrInsert(ki) -} diff --git a/vendor/go.etcd.io/etcd/server/v3/mvcc/key_index.go b/vendor/go.etcd.io/etcd/server/v3/mvcc/key_index.go deleted file mode 100644 index 58ad4832eb..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/mvcc/key_index.go +++ /dev/null @@ -1,378 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package mvcc - -import ( - "bytes" - "errors" - "fmt" - - "github.com/google/btree" - "go.uber.org/zap" -) - -var ( - ErrRevisionNotFound = errors.New("mvcc: revision not found") -) - -// keyIndex stores the revisions of a key in the backend. -// Each keyIndex has at least one key generation. -// Each generation might have several key versions. -// Tombstone on a key appends an tombstone version at the end -// of the current generation and creates a new empty generation. -// Each version of a key has an index pointing to the backend. -// -// For example: put(1.0);put(2.0);tombstone(3.0);put(4.0);tombstone(5.0) on key "foo" -// generate a keyIndex: -// key: "foo" -// rev: 5 -// generations: -// {empty} -// {4.0, 5.0(t)} -// {1.0, 2.0, 3.0(t)} -// -// Compact a keyIndex removes the versions with smaller or equal to -// rev except the largest one. If the generation becomes empty -// during compaction, it will be removed. if all the generations get -// removed, the keyIndex should be removed. -// -// For example: -// compact(2) on the previous example -// generations: -// {empty} -// {4.0, 5.0(t)} -// {2.0, 3.0(t)} -// -// compact(4) -// generations: -// {empty} -// {4.0, 5.0(t)} -// -// compact(5): -// generations: -// {empty} -> key SHOULD be removed. -// -// compact(6): -// generations: -// {empty} -> key SHOULD be removed. -type keyIndex struct { - key []byte - modified revision // the main rev of the last modification - generations []generation -} - -// put puts a revision to the keyIndex. -func (ki *keyIndex) put(lg *zap.Logger, main int64, sub int64) { - rev := revision{main: main, sub: sub} - - if !rev.GreaterThan(ki.modified) { - lg.Panic( - "'put' with an unexpected smaller revision", - zap.Int64("given-revision-main", rev.main), - zap.Int64("given-revision-sub", rev.sub), - zap.Int64("modified-revision-main", ki.modified.main), - zap.Int64("modified-revision-sub", ki.modified.sub), - ) - } - if len(ki.generations) == 0 { - ki.generations = append(ki.generations, generation{}) - } - g := &ki.generations[len(ki.generations)-1] - if len(g.revs) == 0 { // create a new key - keysGauge.Inc() - g.created = rev - } - g.revs = append(g.revs, rev) - g.ver++ - ki.modified = rev -} - -func (ki *keyIndex) restore(lg *zap.Logger, created, modified revision, ver int64) { - if len(ki.generations) != 0 { - lg.Panic( - "'restore' got an unexpected non-empty generations", - zap.Int("generations-size", len(ki.generations)), - ) - } - - ki.modified = modified - g := generation{created: created, ver: ver, revs: []revision{modified}} - ki.generations = append(ki.generations, g) - keysGauge.Inc() -} - -// tombstone puts a revision, pointing to a tombstone, to the keyIndex. -// It also creates a new empty generation in the keyIndex. -// It returns ErrRevisionNotFound when tombstone on an empty generation. -func (ki *keyIndex) tombstone(lg *zap.Logger, main int64, sub int64) error { - if ki.isEmpty() { - lg.Panic( - "'tombstone' got an unexpected empty keyIndex", - zap.String("key", string(ki.key)), - ) - } - if ki.generations[len(ki.generations)-1].isEmpty() { - return ErrRevisionNotFound - } - ki.put(lg, main, sub) - ki.generations = append(ki.generations, generation{}) - keysGauge.Dec() - return nil -} - -// get gets the modified, created revision and version of the key that satisfies the given atRev. -// Rev must be higher than or equal to the given atRev. -func (ki *keyIndex) get(lg *zap.Logger, atRev int64) (modified, created revision, ver int64, err error) { - if ki.isEmpty() { - lg.Panic( - "'get' got an unexpected empty keyIndex", - zap.String("key", string(ki.key)), - ) - } - g := ki.findGeneration(atRev) - if g.isEmpty() { - return revision{}, revision{}, 0, ErrRevisionNotFound - } - - n := g.walk(func(rev revision) bool { return rev.main > atRev }) - if n != -1 { - return g.revs[n], g.created, g.ver - int64(len(g.revs)-n-1), nil - } - - return revision{}, revision{}, 0, ErrRevisionNotFound -} - -// since returns revisions since the given rev. Only the revision with the -// largest sub revision will be returned if multiple revisions have the same -// main revision. -func (ki *keyIndex) since(lg *zap.Logger, rev int64) []revision { - if ki.isEmpty() { - lg.Panic( - "'since' got an unexpected empty keyIndex", - zap.String("key", string(ki.key)), - ) - } - since := revision{rev, 0} - var gi int - // find the generations to start checking - for gi = len(ki.generations) - 1; gi > 0; gi-- { - g := ki.generations[gi] - if g.isEmpty() { - continue - } - if since.GreaterThan(g.created) { - break - } - } - - var revs []revision - var last int64 - for ; gi < len(ki.generations); gi++ { - for _, r := range ki.generations[gi].revs { - if since.GreaterThan(r) { - continue - } - if r.main == last { - // replace the revision with a new one that has higher sub value, - // because the original one should not be seen by external - revs[len(revs)-1] = r - continue - } - revs = append(revs, r) - last = r.main - } - } - return revs -} - -// compact compacts a keyIndex by removing the versions with smaller or equal -// revision than the given atRev except the largest one (If the largest one is -// a tombstone, it will not be kept). -// If a generation becomes empty during compaction, it will be removed. -func (ki *keyIndex) compact(lg *zap.Logger, atRev int64, available map[revision]struct{}) { - if ki.isEmpty() { - lg.Panic( - "'compact' got an unexpected empty keyIndex", - zap.String("key", string(ki.key)), - ) - } - - genIdx, revIndex := ki.doCompact(atRev, available) - - g := &ki.generations[genIdx] - if !g.isEmpty() { - // remove the previous contents. - if revIndex != -1 { - g.revs = g.revs[revIndex:] - } - // remove any tombstone - if len(g.revs) == 1 && genIdx != len(ki.generations)-1 { - delete(available, g.revs[0]) - genIdx++ - } - } - - // remove the previous generations. - ki.generations = ki.generations[genIdx:] -} - -// keep finds the revision to be kept if compact is called at given atRev. -func (ki *keyIndex) keep(atRev int64, available map[revision]struct{}) { - if ki.isEmpty() { - return - } - - genIdx, revIndex := ki.doCompact(atRev, available) - g := &ki.generations[genIdx] - if !g.isEmpty() { - // remove any tombstone - if revIndex == len(g.revs)-1 && genIdx != len(ki.generations)-1 { - delete(available, g.revs[revIndex]) - } - } -} - -func (ki *keyIndex) doCompact(atRev int64, available map[revision]struct{}) (genIdx int, revIndex int) { - // walk until reaching the first revision smaller or equal to "atRev", - // and add the revision to the available map - f := func(rev revision) bool { - if rev.main <= atRev { - available[rev] = struct{}{} - return false - } - return true - } - - genIdx, g := 0, &ki.generations[0] - // find first generation includes atRev or created after atRev - for genIdx < len(ki.generations)-1 { - if tomb := g.revs[len(g.revs)-1].main; tomb > atRev { - break - } - genIdx++ - g = &ki.generations[genIdx] - } - - revIndex = g.walk(f) - - return genIdx, revIndex -} - -func (ki *keyIndex) isEmpty() bool { - return len(ki.generations) == 1 && ki.generations[0].isEmpty() -} - -// findGeneration finds out the generation of the keyIndex that the -// given rev belongs to. If the given rev is at the gap of two generations, -// which means that the key does not exist at the given rev, it returns nil. -func (ki *keyIndex) findGeneration(rev int64) *generation { - lastg := len(ki.generations) - 1 - cg := lastg - - for cg >= 0 { - if len(ki.generations[cg].revs) == 0 { - cg-- - continue - } - g := ki.generations[cg] - if cg != lastg { - if tomb := g.revs[len(g.revs)-1].main; tomb <= rev { - return nil - } - } - if g.revs[0].main <= rev { - return &ki.generations[cg] - } - cg-- - } - return nil -} - -func (ki *keyIndex) Less(b btree.Item) bool { - return bytes.Compare(ki.key, b.(*keyIndex).key) == -1 -} - -func (ki *keyIndex) equal(b *keyIndex) bool { - if !bytes.Equal(ki.key, b.key) { - return false - } - if ki.modified != b.modified { - return false - } - if len(ki.generations) != len(b.generations) { - return false - } - for i := range ki.generations { - ag, bg := ki.generations[i], b.generations[i] - if !ag.equal(bg) { - return false - } - } - return true -} - -func (ki *keyIndex) String() string { - var s string - for _, g := range ki.generations { - s += g.String() - } - return s -} - -// generation contains multiple revisions of a key. -type generation struct { - ver int64 - created revision // when the generation is created (put in first revision). - revs []revision -} - -func (g *generation) isEmpty() bool { return g == nil || len(g.revs) == 0 } - -// walk walks through the revisions in the generation in descending order. -// It passes the revision to the given function. -// walk returns until: 1. it finishes walking all pairs 2. the function returns false. -// walk returns the position at where it stopped. If it stopped after -// finishing walking, -1 will be returned. -func (g *generation) walk(f func(rev revision) bool) int { - l := len(g.revs) - for i := range g.revs { - ok := f(g.revs[l-i-1]) - if !ok { - return l - i - 1 - } - } - return -1 -} - -func (g *generation) String() string { - return fmt.Sprintf("g: created[%d] ver[%d], revs %#v\n", g.created, g.ver, g.revs) -} - -func (g generation) equal(b generation) bool { - if g.ver != b.ver { - return false - } - if len(g.revs) != len(b.revs) { - return false - } - - for i := range g.revs { - ar, br := g.revs[i], b.revs[i] - if ar != br { - return false - } - } - return true -} diff --git a/vendor/go.etcd.io/etcd/server/v3/mvcc/kv.go b/vendor/go.etcd.io/etcd/server/v3/mvcc/kv.go deleted file mode 100644 index 79c2e68700..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/mvcc/kv.go +++ /dev/null @@ -1,150 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package mvcc - -import ( - "context" - - "go.etcd.io/etcd/api/v3/mvccpb" - "go.etcd.io/etcd/pkg/v3/traceutil" - "go.etcd.io/etcd/server/v3/lease" - "go.etcd.io/etcd/server/v3/mvcc/backend" -) - -type RangeOptions struct { - Limit int64 - Rev int64 - Count bool -} - -type RangeResult struct { - KVs []mvccpb.KeyValue - Rev int64 - Count int -} - -type ReadView interface { - // FirstRev returns the first KV revision at the time of opening the txn. - // After a compaction, the first revision increases to the compaction - // revision. - FirstRev() int64 - - // Rev returns the revision of the KV at the time of opening the txn. - Rev() int64 - - // Range gets the keys in the range at rangeRev. - // The returned rev is the current revision of the KV when the operation is executed. - // If rangeRev <=0, range gets the keys at currentRev. - // If `end` is nil, the request returns the key. - // If `end` is not nil and not empty, it gets the keys in range [key, range_end). - // If `end` is not nil and empty, it gets the keys greater than or equal to key. - // Limit limits the number of keys returned. - // If the required rev is compacted, ErrCompacted will be returned. - Range(ctx context.Context, key, end []byte, ro RangeOptions) (r *RangeResult, err error) -} - -// TxnRead represents a read-only transaction with operations that will not -// block other read transactions. -type TxnRead interface { - ReadView - // End marks the transaction is complete and ready to commit. - End() -} - -type WriteView interface { - // DeleteRange deletes the given range from the store. - // A deleteRange increases the rev of the store if any key in the range exists. - // The number of key deleted will be returned. - // The returned rev is the current revision of the KV when the operation is executed. - // It also generates one event for each key delete in the event history. - // if the `end` is nil, deleteRange deletes the key. - // if the `end` is not nil, deleteRange deletes the keys in range [key, range_end). - DeleteRange(key, end []byte) (n, rev int64) - - // Put puts the given key, value into the store. Put also takes additional argument lease to - // attach a lease to a key-value pair as meta-data. KV implementation does not validate the lease - // id. - // A put also increases the rev of the store, and generates one event in the event history. - // The returned rev is the current revision of the KV when the operation is executed. - Put(key, value []byte, lease lease.LeaseID) (rev int64) -} - -// TxnWrite represents a transaction that can modify the store. -type TxnWrite interface { - TxnRead - WriteView - // Changes gets the changes made since opening the write txn. - Changes() []mvccpb.KeyValue -} - -// txnReadWrite coerces a read txn to a write, panicking on any write operation. -type txnReadWrite struct{ TxnRead } - -func (trw *txnReadWrite) DeleteRange(key, end []byte) (n, rev int64) { panic("unexpected DeleteRange") } -func (trw *txnReadWrite) Put(key, value []byte, lease lease.LeaseID) (rev int64) { - panic("unexpected Put") -} -func (trw *txnReadWrite) Changes() []mvccpb.KeyValue { return nil } - -func NewReadOnlyTxnWrite(txn TxnRead) TxnWrite { return &txnReadWrite{txn} } - -type ReadTxMode uint32 - -const ( - // Use ConcurrentReadTx and the txReadBuffer is copied - ConcurrentReadTxMode = ReadTxMode(1) - // Use backend ReadTx and txReadBuffer is not copied - SharedBufReadTxMode = ReadTxMode(2) -) - -type KV interface { - ReadView - WriteView - - // Read creates a read transaction. - Read(mode ReadTxMode, trace *traceutil.Trace) TxnRead - - // Write creates a write transaction. - Write(trace *traceutil.Trace) TxnWrite - - // Hash computes the hash of the KV's backend. - Hash() (hash uint32, revision int64, err error) - - // HashByRev computes the hash of all MVCC revisions up to a given revision. - HashByRev(rev int64) (hash uint32, revision int64, compactRev int64, err error) - - // Compact frees all superseded keys with revisions less than rev. - Compact(trace *traceutil.Trace, rev int64) (<-chan struct{}, error) - - // Commit commits outstanding txns into the underlying backend. - Commit() - - // Restore restores the KV store from a backend. - Restore(b backend.Backend) error - Close() error -} - -// WatchableKV is a KV that can be watched. -type WatchableKV interface { - KV - Watchable -} - -// Watchable is the interface that wraps the NewWatchStream function. -type Watchable interface { - // NewWatchStream returns a WatchStream that can be used to - // watch events happened or happening on the KV. - NewWatchStream() WatchStream -} diff --git a/vendor/go.etcd.io/etcd/server/v3/mvcc/kv_view.go b/vendor/go.etcd.io/etcd/server/v3/mvcc/kv_view.go deleted file mode 100644 index 56260e7599..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/mvcc/kv_view.go +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package mvcc - -import ( - "context" - - "go.etcd.io/etcd/pkg/v3/traceutil" - "go.etcd.io/etcd/server/v3/lease" -) - -type readView struct{ kv KV } - -func (rv *readView) FirstRev() int64 { - tr := rv.kv.Read(ConcurrentReadTxMode, traceutil.TODO()) - defer tr.End() - return tr.FirstRev() -} - -func (rv *readView) Rev() int64 { - tr := rv.kv.Read(ConcurrentReadTxMode, traceutil.TODO()) - defer tr.End() - return tr.Rev() -} - -func (rv *readView) Range(ctx context.Context, key, end []byte, ro RangeOptions) (r *RangeResult, err error) { - tr := rv.kv.Read(ConcurrentReadTxMode, traceutil.TODO()) - defer tr.End() - return tr.Range(ctx, key, end, ro) -} - -type writeView struct{ kv KV } - -func (wv *writeView) DeleteRange(key, end []byte) (n, rev int64) { - tw := wv.kv.Write(traceutil.TODO()) - defer tw.End() - return tw.DeleteRange(key, end) -} - -func (wv *writeView) Put(key, value []byte, lease lease.LeaseID) (rev int64) { - tw := wv.kv.Write(traceutil.TODO()) - defer tw.End() - return tw.Put(key, value, lease) -} diff --git a/vendor/go.etcd.io/etcd/server/v3/mvcc/kvstore.go b/vendor/go.etcd.io/etcd/server/v3/mvcc/kvstore.go deleted file mode 100644 index 54055ed055..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/mvcc/kvstore.go +++ /dev/null @@ -1,555 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package mvcc - -import ( - "context" - "errors" - "fmt" - "hash/crc32" - "math" - "sync" - "time" - - "go.etcd.io/etcd/api/v3/mvccpb" - "go.etcd.io/etcd/pkg/v3/schedule" - "go.etcd.io/etcd/pkg/v3/traceutil" - "go.etcd.io/etcd/server/v3/lease" - "go.etcd.io/etcd/server/v3/mvcc/backend" - "go.etcd.io/etcd/server/v3/mvcc/buckets" - - "go.uber.org/zap" -) - -var ( - scheduledCompactKeyName = []byte("scheduledCompactRev") - finishedCompactKeyName = []byte("finishedCompactRev") - - ErrCompacted = errors.New("mvcc: required revision has been compacted") - ErrFutureRev = errors.New("mvcc: required revision is a future revision") -) - -const ( - // markedRevBytesLen is the byte length of marked revision. - // The first `revBytesLen` bytes represents a normal revision. The last - // one byte is the mark. - markedRevBytesLen = revBytesLen + 1 - markBytePosition = markedRevBytesLen - 1 - markTombstone byte = 't' -) - -var restoreChunkKeys = 10000 // non-const for testing -var defaultCompactBatchLimit = 1000 - -type StoreConfig struct { - CompactionBatchLimit int -} - -type store struct { - ReadView - WriteView - - cfg StoreConfig - - // mu read locks for txns and write locks for non-txn store changes. - mu sync.RWMutex - - b backend.Backend - kvindex index - - le lease.Lessor - - // revMuLock protects currentRev and compactMainRev. - // Locked at end of write txn and released after write txn unlock lock. - // Locked before locking read txn and released after locking. - revMu sync.RWMutex - // currentRev is the revision of the last completed transaction. - currentRev int64 - // compactMainRev is the main revision of the last compaction. - compactMainRev int64 - - fifoSched schedule.Scheduler - - stopc chan struct{} - - lg *zap.Logger -} - -// NewStore returns a new store. It is useful to create a store inside -// mvcc pkg. It should only be used for testing externally. -func NewStore(lg *zap.Logger, b backend.Backend, le lease.Lessor, cfg StoreConfig) *store { - if lg == nil { - lg = zap.NewNop() - } - if cfg.CompactionBatchLimit == 0 { - cfg.CompactionBatchLimit = defaultCompactBatchLimit - } - s := &store{ - cfg: cfg, - b: b, - kvindex: newTreeIndex(lg), - - le: le, - - currentRev: 1, - compactMainRev: -1, - - fifoSched: schedule.NewFIFOScheduler(), - - stopc: make(chan struct{}), - - lg: lg, - } - s.ReadView = &readView{s} - s.WriteView = &writeView{s} - if s.le != nil { - s.le.SetRangeDeleter(func() lease.TxnDelete { return s.Write(traceutil.TODO()) }) - } - - tx := s.b.BatchTx() - tx.Lock() - tx.UnsafeCreateBucket(buckets.Key) - tx.UnsafeCreateBucket(buckets.Meta) - tx.Unlock() - s.b.ForceCommit() - - s.mu.Lock() - defer s.mu.Unlock() - if err := s.restore(); err != nil { - // TODO: return the error instead of panic here? - panic("failed to recover store from backend") - } - - return s -} - -func (s *store) compactBarrier(ctx context.Context, ch chan struct{}) { - if ctx == nil || ctx.Err() != nil { - select { - case <-s.stopc: - default: - // fix deadlock in mvcc,for more information, please refer to pr 11817. - // s.stopc is only updated in restore operation, which is called by apply - // snapshot call, compaction and apply snapshot requests are serialized by - // raft, and do not happen at the same time. - s.mu.Lock() - f := func(ctx context.Context) { s.compactBarrier(ctx, ch) } - s.fifoSched.Schedule(f) - s.mu.Unlock() - } - return - } - close(ch) -} - -func (s *store) Hash() (hash uint32, revision int64, err error) { - // TODO: hash and revision could be inconsistent, one possible fix is to add s.revMu.RLock() at the beginning of function, which is costly - start := time.Now() - - s.b.ForceCommit() - h, err := s.b.Hash(buckets.DefaultIgnores) - - hashSec.Observe(time.Since(start).Seconds()) - return h, s.currentRev, err -} - -func (s *store) HashByRev(rev int64) (hash uint32, currentRev int64, compactRev int64, err error) { - start := time.Now() - - s.mu.RLock() - s.revMu.RLock() - compactRev, currentRev = s.compactMainRev, s.currentRev - s.revMu.RUnlock() - - if rev > 0 && rev <= compactRev { - s.mu.RUnlock() - return 0, 0, compactRev, ErrCompacted - } else if rev > 0 && rev > currentRev { - s.mu.RUnlock() - return 0, currentRev, 0, ErrFutureRev - } - - if rev == 0 { - rev = currentRev - } - keep := s.kvindex.Keep(rev) - - tx := s.b.ReadTx() - tx.RLock() - defer tx.RUnlock() - s.mu.RUnlock() - - upper := revision{main: rev + 1} - lower := revision{main: compactRev + 1} - h := crc32.New(crc32.MakeTable(crc32.Castagnoli)) - - h.Write(buckets.Key.Name()) - err = tx.UnsafeForEach(buckets.Key, func(k, v []byte) error { - kr := bytesToRev(k) - if !upper.GreaterThan(kr) { - return nil - } - // skip revisions that are scheduled for deletion - // due to compacting; don't skip if there isn't one. - if lower.GreaterThan(kr) && len(keep) > 0 { - if _, ok := keep[kr]; !ok { - return nil - } - } - h.Write(k) - h.Write(v) - return nil - }) - hash = h.Sum32() - - hashRevSec.Observe(time.Since(start).Seconds()) - return hash, currentRev, compactRev, err -} - -func (s *store) updateCompactRev(rev int64) (<-chan struct{}, error) { - s.revMu.Lock() - if rev <= s.compactMainRev { - ch := make(chan struct{}) - f := func(ctx context.Context) { s.compactBarrier(ctx, ch) } - s.fifoSched.Schedule(f) - s.revMu.Unlock() - return ch, ErrCompacted - } - if rev > s.currentRev { - s.revMu.Unlock() - return nil, ErrFutureRev - } - - s.compactMainRev = rev - - rbytes := newRevBytes() - revToBytes(revision{main: rev}, rbytes) - - tx := s.b.BatchTx() - tx.Lock() - tx.UnsafePut(buckets.Meta, scheduledCompactKeyName, rbytes) - tx.Unlock() - // ensure that desired compaction is persisted - s.b.ForceCommit() - - s.revMu.Unlock() - - return nil, nil -} - -func (s *store) compact(trace *traceutil.Trace, rev int64) (<-chan struct{}, error) { - ch := make(chan struct{}) - var j = func(ctx context.Context) { - if ctx.Err() != nil { - s.compactBarrier(ctx, ch) - return - } - start := time.Now() - keep := s.kvindex.Compact(rev) - indexCompactionPauseMs.Observe(float64(time.Since(start) / time.Millisecond)) - if !s.scheduleCompaction(rev, keep) { - s.compactBarrier(context.TODO(), ch) - return - } - close(ch) - } - - s.fifoSched.Schedule(j) - trace.Step("schedule compaction") - return ch, nil -} - -func (s *store) compactLockfree(rev int64) (<-chan struct{}, error) { - ch, err := s.updateCompactRev(rev) - if err != nil { - return ch, err - } - - return s.compact(traceutil.TODO(), rev) -} - -func (s *store) Compact(trace *traceutil.Trace, rev int64) (<-chan struct{}, error) { - s.mu.Lock() - - ch, err := s.updateCompactRev(rev) - trace.Step("check and update compact revision") - if err != nil { - s.mu.Unlock() - return ch, err - } - s.mu.Unlock() - - return s.compact(trace, rev) -} - -func (s *store) Commit() { - s.mu.Lock() - defer s.mu.Unlock() - s.b.ForceCommit() -} - -func (s *store) Restore(b backend.Backend) error { - s.mu.Lock() - defer s.mu.Unlock() - - close(s.stopc) - s.fifoSched.Stop() - - s.b = b - s.kvindex = newTreeIndex(s.lg) - - { - // During restore the metrics might report 'special' values - s.revMu.Lock() - s.currentRev = 1 - s.compactMainRev = -1 - s.revMu.Unlock() - } - - s.fifoSched = schedule.NewFIFOScheduler() - s.stopc = make(chan struct{}) - - return s.restore() -} - -func (s *store) restore() error { - s.setupMetricsReporter() - - min, max := newRevBytes(), newRevBytes() - revToBytes(revision{main: 1}, min) - revToBytes(revision{main: math.MaxInt64, sub: math.MaxInt64}, max) - - keyToLease := make(map[string]lease.LeaseID) - - // restore index - tx := s.b.BatchTx() - tx.Lock() - - _, finishedCompactBytes := tx.UnsafeRange(buckets.Meta, finishedCompactKeyName, nil, 0) - if len(finishedCompactBytes) != 0 { - s.revMu.Lock() - s.compactMainRev = bytesToRev(finishedCompactBytes[0]).main - - s.lg.Info( - "restored last compact revision", - zap.Stringer("meta-bucket-name", buckets.Meta), - zap.String("meta-bucket-name-key", string(finishedCompactKeyName)), - zap.Int64("restored-compact-revision", s.compactMainRev), - ) - s.revMu.Unlock() - } - _, scheduledCompactBytes := tx.UnsafeRange(buckets.Meta, scheduledCompactKeyName, nil, 0) - scheduledCompact := int64(0) - if len(scheduledCompactBytes) != 0 { - scheduledCompact = bytesToRev(scheduledCompactBytes[0]).main - } - - // index keys concurrently as they're loaded in from tx - keysGauge.Set(0) - rkvc, revc := restoreIntoIndex(s.lg, s.kvindex) - for { - keys, vals := tx.UnsafeRange(buckets.Key, min, max, int64(restoreChunkKeys)) - if len(keys) == 0 { - break - } - // rkvc blocks if the total pending keys exceeds the restore - // chunk size to keep keys from consuming too much memory. - restoreChunk(s.lg, rkvc, keys, vals, keyToLease) - if len(keys) < restoreChunkKeys { - // partial set implies final set - break - } - // next set begins after where this one ended - newMin := bytesToRev(keys[len(keys)-1][:revBytesLen]) - newMin.sub++ - revToBytes(newMin, min) - } - close(rkvc) - - { - s.revMu.Lock() - s.currentRev = <-revc - - // keys in the range [compacted revision -N, compaction] might all be deleted due to compaction. - // the correct revision should be set to compaction revision in the case, not the largest revision - // we have seen. - if s.currentRev < s.compactMainRev { - s.currentRev = s.compactMainRev - } - s.revMu.Unlock() - } - - if scheduledCompact <= s.compactMainRev { - scheduledCompact = 0 - } - - for key, lid := range keyToLease { - if s.le == nil { - tx.Unlock() - panic("no lessor to attach lease") - } - err := s.le.Attach(lid, []lease.LeaseItem{{Key: key}}) - if err != nil { - s.lg.Error( - "failed to attach a lease", - zap.String("lease-id", fmt.Sprintf("%016x", lid)), - zap.Error(err), - ) - } - } - - tx.Unlock() - - s.lg.Info("kvstore restored", zap.Int64("current-rev", s.currentRev)) - - if scheduledCompact != 0 { - if _, err := s.compactLockfree(scheduledCompact); err != nil { - s.lg.Warn("compaction encountered error", zap.Error(err)) - } - - s.lg.Info( - "resume scheduled compaction", - zap.Stringer("meta-bucket-name", buckets.Meta), - zap.String("meta-bucket-name-key", string(scheduledCompactKeyName)), - zap.Int64("scheduled-compact-revision", scheduledCompact), - ) - } - - return nil -} - -type revKeyValue struct { - key []byte - kv mvccpb.KeyValue - kstr string -} - -func restoreIntoIndex(lg *zap.Logger, idx index) (chan<- revKeyValue, <-chan int64) { - rkvc, revc := make(chan revKeyValue, restoreChunkKeys), make(chan int64, 1) - go func() { - currentRev := int64(1) - defer func() { revc <- currentRev }() - // restore the tree index from streaming the unordered index. - kiCache := make(map[string]*keyIndex, restoreChunkKeys) - for rkv := range rkvc { - ki, ok := kiCache[rkv.kstr] - // purge kiCache if many keys but still missing in the cache - if !ok && len(kiCache) >= restoreChunkKeys { - i := 10 - for k := range kiCache { - delete(kiCache, k) - if i--; i == 0 { - break - } - } - } - // cache miss, fetch from tree index if there - if !ok { - ki = &keyIndex{key: rkv.kv.Key} - if idxKey := idx.KeyIndex(ki); idxKey != nil { - kiCache[rkv.kstr], ki = idxKey, idxKey - ok = true - } - } - rev := bytesToRev(rkv.key) - currentRev = rev.main - if ok { - if isTombstone(rkv.key) { - if err := ki.tombstone(lg, rev.main, rev.sub); err != nil { - lg.Warn("tombstone encountered error", zap.Error(err)) - } - continue - } - ki.put(lg, rev.main, rev.sub) - } else if !isTombstone(rkv.key) { - ki.restore(lg, revision{rkv.kv.CreateRevision, 0}, rev, rkv.kv.Version) - idx.Insert(ki) - kiCache[rkv.kstr] = ki - } - } - }() - return rkvc, revc -} - -func restoreChunk(lg *zap.Logger, kvc chan<- revKeyValue, keys, vals [][]byte, keyToLease map[string]lease.LeaseID) { - for i, key := range keys { - rkv := revKeyValue{key: key} - if err := rkv.kv.Unmarshal(vals[i]); err != nil { - lg.Fatal("failed to unmarshal mvccpb.KeyValue", zap.Error(err)) - } - rkv.kstr = string(rkv.kv.Key) - if isTombstone(key) { - delete(keyToLease, rkv.kstr) - } else if lid := lease.LeaseID(rkv.kv.Lease); lid != lease.NoLease { - keyToLease[rkv.kstr] = lid - } else { - delete(keyToLease, rkv.kstr) - } - kvc <- rkv - } -} - -func (s *store) Close() error { - close(s.stopc) - s.fifoSched.Stop() - return nil -} - -func (s *store) setupMetricsReporter() { - b := s.b - reportDbTotalSizeInBytesMu.Lock() - reportDbTotalSizeInBytes = func() float64 { return float64(b.Size()) } - reportDbTotalSizeInBytesMu.Unlock() - reportDbTotalSizeInBytesDebugMu.Lock() - reportDbTotalSizeInBytesDebug = func() float64 { return float64(b.Size()) } - reportDbTotalSizeInBytesDebugMu.Unlock() - reportDbTotalSizeInUseInBytesMu.Lock() - reportDbTotalSizeInUseInBytes = func() float64 { return float64(b.SizeInUse()) } - reportDbTotalSizeInUseInBytesMu.Unlock() - reportDbOpenReadTxNMu.Lock() - reportDbOpenReadTxN = func() float64 { return float64(b.OpenReadTxN()) } - reportDbOpenReadTxNMu.Unlock() - reportCurrentRevMu.Lock() - reportCurrentRev = func() float64 { - s.revMu.RLock() - defer s.revMu.RUnlock() - return float64(s.currentRev) - } - reportCurrentRevMu.Unlock() - reportCompactRevMu.Lock() - reportCompactRev = func() float64 { - s.revMu.RLock() - defer s.revMu.RUnlock() - return float64(s.compactMainRev) - } - reportCompactRevMu.Unlock() -} - -// appendMarkTombstone appends tombstone mark to normal revision bytes. -func appendMarkTombstone(lg *zap.Logger, b []byte) []byte { - if len(b) != revBytesLen { - lg.Panic( - "cannot append tombstone mark to non-normal revision bytes", - zap.Int("expected-revision-bytes-size", revBytesLen), - zap.Int("given-revision-bytes-size", len(b)), - ) - } - return append(b, markTombstone) -} - -// isTombstone checks whether the revision bytes is a tombstone. -func isTombstone(b []byte) bool { - return len(b) == markedRevBytesLen && b[markBytePosition] == markTombstone -} diff --git a/vendor/go.etcd.io/etcd/server/v3/mvcc/kvstore_compaction.go b/vendor/go.etcd.io/etcd/server/v3/mvcc/kvstore_compaction.go deleted file mode 100644 index 71bd4b7369..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/mvcc/kvstore_compaction.go +++ /dev/null @@ -1,78 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package mvcc - -import ( - "encoding/binary" - "time" - - "go.etcd.io/etcd/server/v3/mvcc/buckets" - "go.uber.org/zap" -) - -func (s *store) scheduleCompaction(compactMainRev int64, keep map[revision]struct{}) bool { - totalStart := time.Now() - defer func() { dbCompactionTotalMs.Observe(float64(time.Since(totalStart) / time.Millisecond)) }() - keyCompactions := 0 - defer func() { dbCompactionKeysCounter.Add(float64(keyCompactions)) }() - defer func() { dbCompactionLast.Set(float64(time.Now().Unix())) }() - - end := make([]byte, 8) - binary.BigEndian.PutUint64(end, uint64(compactMainRev+1)) - - last := make([]byte, 8+1+8) - for { - var rev revision - - start := time.Now() - - tx := s.b.BatchTx() - tx.Lock() - keys, _ := tx.UnsafeRange(buckets.Key, last, end, int64(s.cfg.CompactionBatchLimit)) - for _, key := range keys { - rev = bytesToRev(key) - if _, ok := keep[rev]; !ok { - tx.UnsafeDelete(buckets.Key, key) - keyCompactions++ - } - } - - if len(keys) < s.cfg.CompactionBatchLimit { - rbytes := make([]byte, 8+1+8) - revToBytes(revision{main: compactMainRev}, rbytes) - tx.UnsafePut(buckets.Meta, finishedCompactKeyName, rbytes) - tx.Unlock() - s.lg.Info( - "finished scheduled compaction", - zap.Int64("compact-revision", compactMainRev), - zap.Duration("took", time.Since(totalStart)), - ) - return true - } - - // update last - revToBytes(revision{main: rev.main, sub: rev.sub + 1}, last) - tx.Unlock() - // Immediately commit the compaction deletes instead of letting them accumulate in the write buffer - s.b.ForceCommit() - dbCompactionPauseMs.Observe(float64(time.Since(start) / time.Millisecond)) - - select { - case <-time.After(10 * time.Millisecond): - case <-s.stopc: - return false - } - } -} diff --git a/vendor/go.etcd.io/etcd/server/v3/mvcc/kvstore_txn.go b/vendor/go.etcd.io/etcd/server/v3/mvcc/kvstore_txn.go deleted file mode 100644 index 93d7db20e0..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/mvcc/kvstore_txn.go +++ /dev/null @@ -1,304 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package mvcc - -import ( - "context" - - "go.etcd.io/etcd/api/v3/mvccpb" - "go.etcd.io/etcd/pkg/v3/traceutil" - "go.etcd.io/etcd/server/v3/lease" - "go.etcd.io/etcd/server/v3/mvcc/backend" - "go.etcd.io/etcd/server/v3/mvcc/buckets" - "go.uber.org/zap" -) - -type storeTxnRead struct { - s *store - tx backend.ReadTx - - firstRev int64 - rev int64 - - trace *traceutil.Trace -} - -func (s *store) Read(mode ReadTxMode, trace *traceutil.Trace) TxnRead { - s.mu.RLock() - s.revMu.RLock() - // For read-only workloads, we use shared buffer by copying transaction read buffer - // for higher concurrency with ongoing blocking writes. - // For write/write-read transactions, we use the shared buffer - // rather than duplicating transaction read buffer to avoid transaction overhead. - var tx backend.ReadTx - if mode == ConcurrentReadTxMode { - tx = s.b.ConcurrentReadTx() - } else { - tx = s.b.ReadTx() - } - - tx.RLock() // RLock is no-op. concurrentReadTx does not need to be locked after it is created. - firstRev, rev := s.compactMainRev, s.currentRev - s.revMu.RUnlock() - return newMetricsTxnRead(&storeTxnRead{s, tx, firstRev, rev, trace}) -} - -func (tr *storeTxnRead) FirstRev() int64 { return tr.firstRev } -func (tr *storeTxnRead) Rev() int64 { return tr.rev } - -func (tr *storeTxnRead) Range(ctx context.Context, key, end []byte, ro RangeOptions) (r *RangeResult, err error) { - return tr.rangeKeys(ctx, key, end, tr.Rev(), ro) -} - -func (tr *storeTxnRead) End() { - tr.tx.RUnlock() // RUnlock signals the end of concurrentReadTx. - tr.s.mu.RUnlock() -} - -type storeTxnWrite struct { - storeTxnRead - tx backend.BatchTx - // beginRev is the revision where the txn begins; it will write to the next revision. - beginRev int64 - changes []mvccpb.KeyValue -} - -func (s *store) Write(trace *traceutil.Trace) TxnWrite { - s.mu.RLock() - tx := s.b.BatchTx() - tx.Lock() - tw := &storeTxnWrite{ - storeTxnRead: storeTxnRead{s, tx, 0, 0, trace}, - tx: tx, - beginRev: s.currentRev, - changes: make([]mvccpb.KeyValue, 0, 4), - } - return newMetricsTxnWrite(tw) -} - -func (tw *storeTxnWrite) Rev() int64 { return tw.beginRev } - -func (tw *storeTxnWrite) Range(ctx context.Context, key, end []byte, ro RangeOptions) (r *RangeResult, err error) { - rev := tw.beginRev - if len(tw.changes) > 0 { - rev++ - } - return tw.rangeKeys(ctx, key, end, rev, ro) -} - -func (tw *storeTxnWrite) DeleteRange(key, end []byte) (int64, int64) { - if n := tw.deleteRange(key, end); n != 0 || len(tw.changes) > 0 { - return n, tw.beginRev + 1 - } - return 0, tw.beginRev -} - -func (tw *storeTxnWrite) Put(key, value []byte, lease lease.LeaseID) int64 { - tw.put(key, value, lease) - return tw.beginRev + 1 -} - -func (tw *storeTxnWrite) End() { - // only update index if the txn modifies the mvcc state. - if len(tw.changes) != 0 { - // hold revMu lock to prevent new read txns from opening until writeback. - tw.s.revMu.Lock() - tw.s.currentRev++ - } - tw.tx.Unlock() - if len(tw.changes) != 0 { - tw.s.revMu.Unlock() - } - tw.s.mu.RUnlock() -} - -func (tr *storeTxnRead) rangeKeys(ctx context.Context, key, end []byte, curRev int64, ro RangeOptions) (*RangeResult, error) { - rev := ro.Rev - if rev > curRev { - return &RangeResult{KVs: nil, Count: -1, Rev: curRev}, ErrFutureRev - } - if rev <= 0 { - rev = curRev - } - if rev < tr.s.compactMainRev { - return &RangeResult{KVs: nil, Count: -1, Rev: 0}, ErrCompacted - } - if ro.Count { - total := tr.s.kvindex.CountRevisions(key, end, rev) - tr.trace.Step("count revisions from in-memory index tree") - return &RangeResult{KVs: nil, Count: total, Rev: curRev}, nil - } - revpairs, total := tr.s.kvindex.Revisions(key, end, rev, int(ro.Limit)) - tr.trace.Step("range keys from in-memory index tree") - if len(revpairs) == 0 { - return &RangeResult{KVs: nil, Count: total, Rev: curRev}, nil - } - - limit := int(ro.Limit) - if limit <= 0 || limit > len(revpairs) { - limit = len(revpairs) - } - - kvs := make([]mvccpb.KeyValue, limit) - revBytes := newRevBytes() - for i, revpair := range revpairs[:len(kvs)] { - select { - case <-ctx.Done(): - return nil, ctx.Err() - default: - } - revToBytes(revpair, revBytes) - _, vs := tr.tx.UnsafeRange(buckets.Key, revBytes, nil, 0) - if len(vs) != 1 { - tr.s.lg.Fatal( - "range failed to find revision pair", - zap.Int64("revision-main", revpair.main), - zap.Int64("revision-sub", revpair.sub), - ) - } - if err := kvs[i].Unmarshal(vs[0]); err != nil { - tr.s.lg.Fatal( - "failed to unmarshal mvccpb.KeyValue", - zap.Error(err), - ) - } - } - tr.trace.Step("range keys from bolt db") - return &RangeResult{KVs: kvs, Count: total, Rev: curRev}, nil -} - -func (tw *storeTxnWrite) put(key, value []byte, leaseID lease.LeaseID) { - rev := tw.beginRev + 1 - c := rev - oldLease := lease.NoLease - - // if the key exists before, use its previous created and - // get its previous leaseID - _, created, ver, err := tw.s.kvindex.Get(key, rev) - if err == nil { - c = created.main - oldLease = tw.s.le.GetLease(lease.LeaseItem{Key: string(key)}) - tw.trace.Step("get key's previous created_revision and leaseID") - } - ibytes := newRevBytes() - idxRev := revision{main: rev, sub: int64(len(tw.changes))} - revToBytes(idxRev, ibytes) - - ver = ver + 1 - kv := mvccpb.KeyValue{ - Key: key, - Value: value, - CreateRevision: c, - ModRevision: rev, - Version: ver, - Lease: int64(leaseID), - } - - d, err := kv.Marshal() - if err != nil { - tw.storeTxnRead.s.lg.Fatal( - "failed to marshal mvccpb.KeyValue", - zap.Error(err), - ) - } - - tw.trace.Step("marshal mvccpb.KeyValue") - tw.tx.UnsafeSeqPut(buckets.Key, ibytes, d) - tw.s.kvindex.Put(key, idxRev) - tw.changes = append(tw.changes, kv) - tw.trace.Step("store kv pair into bolt db") - - if oldLease != lease.NoLease { - if tw.s.le == nil { - panic("no lessor to detach lease") - } - err = tw.s.le.Detach(oldLease, []lease.LeaseItem{{Key: string(key)}}) - if err != nil { - tw.storeTxnRead.s.lg.Error( - "failed to detach old lease from a key", - zap.Error(err), - ) - } - } - if leaseID != lease.NoLease { - if tw.s.le == nil { - panic("no lessor to attach lease") - } - err = tw.s.le.Attach(leaseID, []lease.LeaseItem{{Key: string(key)}}) - if err != nil { - panic("unexpected error from lease Attach") - } - } - tw.trace.Step("attach lease to kv pair") -} - -func (tw *storeTxnWrite) deleteRange(key, end []byte) int64 { - rrev := tw.beginRev - if len(tw.changes) > 0 { - rrev++ - } - keys, _ := tw.s.kvindex.Range(key, end, rrev) - if len(keys) == 0 { - return 0 - } - for _, key := range keys { - tw.delete(key) - } - return int64(len(keys)) -} - -func (tw *storeTxnWrite) delete(key []byte) { - ibytes := newRevBytes() - idxRev := revision{main: tw.beginRev + 1, sub: int64(len(tw.changes))} - revToBytes(idxRev, ibytes) - - ibytes = appendMarkTombstone(tw.storeTxnRead.s.lg, ibytes) - - kv := mvccpb.KeyValue{Key: key} - - d, err := kv.Marshal() - if err != nil { - tw.storeTxnRead.s.lg.Fatal( - "failed to marshal mvccpb.KeyValue", - zap.Error(err), - ) - } - - tw.tx.UnsafeSeqPut(buckets.Key, ibytes, d) - err = tw.s.kvindex.Tombstone(key, idxRev) - if err != nil { - tw.storeTxnRead.s.lg.Fatal( - "failed to tombstone an existing key", - zap.String("key", string(key)), - zap.Error(err), - ) - } - tw.changes = append(tw.changes, kv) - - item := lease.LeaseItem{Key: string(key)} - leaseID := tw.s.le.GetLease(item) - - if leaseID != lease.NoLease { - err = tw.s.le.Detach(leaseID, []lease.LeaseItem{item}) - if err != nil { - tw.storeTxnRead.s.lg.Error( - "failed to detach old lease from a key", - zap.Error(err), - ) - } - } -} - -func (tw *storeTxnWrite) Changes() []mvccpb.KeyValue { return tw.changes } diff --git a/vendor/go.etcd.io/etcd/server/v3/mvcc/metrics.go b/vendor/go.etcd.io/etcd/server/v3/mvcc/metrics.go deleted file mode 100644 index f28d114e2b..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/mvcc/metrics.go +++ /dev/null @@ -1,314 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package mvcc - -import ( - "sync" - - "github.com/prometheus/client_golang/prometheus" -) - -var ( - rangeCounter = prometheus.NewCounter( - prometheus.CounterOpts{ - Namespace: "etcd", - Subsystem: "mvcc", - Name: "range_total", - Help: "Total number of ranges seen by this member.", - }) - rangeCounterDebug = prometheus.NewCounter( - prometheus.CounterOpts{ - Namespace: "etcd_debugging", - Subsystem: "mvcc", - Name: "range_total", - Help: "Total number of ranges seen by this member.", - }) - - putCounter = prometheus.NewCounter( - prometheus.CounterOpts{ - Namespace: "etcd", - Subsystem: "mvcc", - Name: "put_total", - Help: "Total number of puts seen by this member.", - }) - - deleteCounter = prometheus.NewCounter( - prometheus.CounterOpts{ - Namespace: "etcd", - Subsystem: "mvcc", - Name: "delete_total", - Help: "Total number of deletes seen by this member.", - }) - - txnCounter = prometheus.NewCounter( - prometheus.CounterOpts{ - Namespace: "etcd", - Subsystem: "mvcc", - Name: "txn_total", - Help: "Total number of txns seen by this member.", - }) - - keysGauge = prometheus.NewGauge( - prometheus.GaugeOpts{ - Namespace: "etcd_debugging", - Subsystem: "mvcc", - Name: "keys_total", - Help: "Total number of keys.", - }) - - watchStreamGauge = prometheus.NewGauge( - prometheus.GaugeOpts{ - Namespace: "etcd_debugging", - Subsystem: "mvcc", - Name: "watch_stream_total", - Help: "Total number of watch streams.", - }) - - watcherGauge = prometheus.NewGauge( - prometheus.GaugeOpts{ - Namespace: "etcd_debugging", - Subsystem: "mvcc", - Name: "watcher_total", - Help: "Total number of watchers.", - }) - - slowWatcherGauge = prometheus.NewGauge( - prometheus.GaugeOpts{ - Namespace: "etcd_debugging", - Subsystem: "mvcc", - Name: "slow_watcher_total", - Help: "Total number of unsynced slow watchers.", - }) - - totalEventsCounter = prometheus.NewCounter( - prometheus.CounterOpts{ - Namespace: "etcd_debugging", - Subsystem: "mvcc", - Name: "events_total", - Help: "Total number of events sent by this member.", - }) - - pendingEventsGauge = prometheus.NewGauge( - prometheus.GaugeOpts{ - Namespace: "etcd_debugging", - Subsystem: "mvcc", - Name: "pending_events_total", - Help: "Total number of pending events to be sent.", - }) - - indexCompactionPauseMs = prometheus.NewHistogram( - prometheus.HistogramOpts{ - Namespace: "etcd_debugging", - Subsystem: "mvcc", - Name: "index_compaction_pause_duration_milliseconds", - Help: "Bucketed histogram of index compaction pause duration.", - - // lowest bucket start of upper bound 0.5 ms with factor 2 - // highest bucket start of 0.5 ms * 2^13 == 4.096 sec - Buckets: prometheus.ExponentialBuckets(0.5, 2, 14), - }) - - dbCompactionPauseMs = prometheus.NewHistogram( - prometheus.HistogramOpts{ - Namespace: "etcd_debugging", - Subsystem: "mvcc", - Name: "db_compaction_pause_duration_milliseconds", - Help: "Bucketed histogram of db compaction pause duration.", - - // lowest bucket start of upper bound 1 ms with factor 2 - // highest bucket start of 1 ms * 2^12 == 4.096 sec - Buckets: prometheus.ExponentialBuckets(1, 2, 13), - }) - - dbCompactionTotalMs = prometheus.NewHistogram( - prometheus.HistogramOpts{ - Namespace: "etcd_debugging", - Subsystem: "mvcc", - Name: "db_compaction_total_duration_milliseconds", - Help: "Bucketed histogram of db compaction total duration.", - - // lowest bucket start of upper bound 100 ms with factor 2 - // highest bucket start of 100 ms * 2^13 == 8.192 sec - Buckets: prometheus.ExponentialBuckets(100, 2, 14), - }) - - dbCompactionLast = prometheus.NewGauge( - prometheus.GaugeOpts{ - Namespace: "etcd_debugging", - Subsystem: "mvcc", - Name: "db_compaction_last", - Help: "The unix time of the last db compaction. Resets to 0 on start.", - }) - - dbCompactionKeysCounter = prometheus.NewCounter( - prometheus.CounterOpts{ - Namespace: "etcd_debugging", - Subsystem: "mvcc", - Name: "db_compaction_keys_total", - Help: "Total number of db keys compacted.", - }) - - dbTotalSize = prometheus.NewGaugeFunc(prometheus.GaugeOpts{ - Namespace: "etcd", - Subsystem: "mvcc", - Name: "db_total_size_in_bytes", - Help: "Total size of the underlying database physically allocated in bytes.", - }, - func() float64 { - reportDbTotalSizeInBytesMu.RLock() - defer reportDbTotalSizeInBytesMu.RUnlock() - return reportDbTotalSizeInBytes() - }, - ) - // overridden by mvcc initialization - reportDbTotalSizeInBytesMu sync.RWMutex - reportDbTotalSizeInBytes = func() float64 { return 0 } - - // overridden by mvcc initialization - reportDbTotalSizeInBytesDebugMu sync.RWMutex - reportDbTotalSizeInBytesDebug = func() float64 { return 0 } - - dbTotalSizeInUse = prometheus.NewGaugeFunc(prometheus.GaugeOpts{ - Namespace: "etcd", - Subsystem: "mvcc", - Name: "db_total_size_in_use_in_bytes", - Help: "Total size of the underlying database logically in use in bytes.", - }, - func() float64 { - reportDbTotalSizeInUseInBytesMu.RLock() - defer reportDbTotalSizeInUseInBytesMu.RUnlock() - return reportDbTotalSizeInUseInBytes() - }, - ) - // overridden by mvcc initialization - reportDbTotalSizeInUseInBytesMu sync.RWMutex - reportDbTotalSizeInUseInBytes = func() float64 { return 0 } - - dbOpenReadTxN = prometheus.NewGaugeFunc(prometheus.GaugeOpts{ - Namespace: "etcd", - Subsystem: "mvcc", - Name: "db_open_read_transactions", - Help: "The number of currently open read transactions", - }, - - func() float64 { - reportDbOpenReadTxNMu.RLock() - defer reportDbOpenReadTxNMu.RUnlock() - return reportDbOpenReadTxN() - }, - ) - // overridden by mvcc initialization - reportDbOpenReadTxNMu sync.RWMutex - reportDbOpenReadTxN = func() float64 { return 0 } - - hashSec = prometheus.NewHistogram(prometheus.HistogramOpts{ - Namespace: "etcd", - Subsystem: "mvcc", - Name: "hash_duration_seconds", - Help: "The latency distribution of storage hash operation.", - - // 100 MB usually takes 100 ms, so start with 10 MB of 10 ms - // lowest bucket start of upper bound 0.01 sec (10 ms) with factor 2 - // highest bucket start of 0.01 sec * 2^14 == 163.84 sec - Buckets: prometheus.ExponentialBuckets(.01, 2, 15), - }) - - hashRevSec = prometheus.NewHistogram(prometheus.HistogramOpts{ - Namespace: "etcd", - Subsystem: "mvcc", - Name: "hash_rev_duration_seconds", - Help: "The latency distribution of storage hash by revision operation.", - - // 100 MB usually takes 100 ms, so start with 10 MB of 10 ms - // lowest bucket start of upper bound 0.01 sec (10 ms) with factor 2 - // highest bucket start of 0.01 sec * 2^14 == 163.84 sec - Buckets: prometheus.ExponentialBuckets(.01, 2, 15), - }) - - currentRev = prometheus.NewGaugeFunc(prometheus.GaugeOpts{ - Namespace: "etcd_debugging", - Subsystem: "mvcc", - Name: "current_revision", - Help: "The current revision of store.", - }, - func() float64 { - reportCurrentRevMu.RLock() - defer reportCurrentRevMu.RUnlock() - return reportCurrentRev() - }, - ) - // overridden by mvcc initialization - reportCurrentRevMu sync.RWMutex - reportCurrentRev = func() float64 { return 0 } - - compactRev = prometheus.NewGaugeFunc(prometheus.GaugeOpts{ - Namespace: "etcd_debugging", - Subsystem: "mvcc", - Name: "compact_revision", - Help: "The revision of the last compaction in store.", - }, - func() float64 { - reportCompactRevMu.RLock() - defer reportCompactRevMu.RUnlock() - return reportCompactRev() - }, - ) - // overridden by mvcc initialization - reportCompactRevMu sync.RWMutex - reportCompactRev = func() float64 { return 0 } - - totalPutSizeGauge = prometheus.NewGauge( - prometheus.GaugeOpts{ - Namespace: "etcd_debugging", - Subsystem: "mvcc", - Name: "total_put_size_in_bytes", - Help: "The total size of put kv pairs seen by this member.", - }) -) - -func init() { - prometheus.MustRegister(rangeCounter) - prometheus.MustRegister(rangeCounterDebug) - prometheus.MustRegister(putCounter) - prometheus.MustRegister(deleteCounter) - prometheus.MustRegister(txnCounter) - prometheus.MustRegister(keysGauge) - prometheus.MustRegister(watchStreamGauge) - prometheus.MustRegister(watcherGauge) - prometheus.MustRegister(slowWatcherGauge) - prometheus.MustRegister(totalEventsCounter) - prometheus.MustRegister(pendingEventsGauge) - prometheus.MustRegister(indexCompactionPauseMs) - prometheus.MustRegister(dbCompactionPauseMs) - prometheus.MustRegister(dbCompactionTotalMs) - prometheus.MustRegister(dbCompactionLast) - prometheus.MustRegister(dbCompactionKeysCounter) - prometheus.MustRegister(dbTotalSize) - prometheus.MustRegister(dbTotalSizeInUse) - prometheus.MustRegister(dbOpenReadTxN) - prometheus.MustRegister(hashSec) - prometheus.MustRegister(hashRevSec) - prometheus.MustRegister(currentRev) - prometheus.MustRegister(compactRev) - prometheus.MustRegister(totalPutSizeGauge) -} - -// ReportEventReceived reports that an event is received. -// This function should be called when the external systems received an -// event from mvcc.Watcher. -func ReportEventReceived(n int) { - pendingEventsGauge.Sub(float64(n)) - totalEventsCounter.Add(float64(n)) -} diff --git a/vendor/go.etcd.io/etcd/server/v3/mvcc/metrics_txn.go b/vendor/go.etcd.io/etcd/server/v3/mvcc/metrics_txn.go deleted file mode 100644 index af844f8468..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/mvcc/metrics_txn.go +++ /dev/null @@ -1,72 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package mvcc - -import ( - "context" - - "go.etcd.io/etcd/server/v3/lease" -) - -type metricsTxnWrite struct { - TxnWrite - ranges uint - puts uint - deletes uint - putSize int64 -} - -func newMetricsTxnRead(tr TxnRead) TxnRead { - return &metricsTxnWrite{&txnReadWrite{tr}, 0, 0, 0, 0} -} - -func newMetricsTxnWrite(tw TxnWrite) TxnWrite { - return &metricsTxnWrite{tw, 0, 0, 0, 0} -} - -func (tw *metricsTxnWrite) Range(ctx context.Context, key, end []byte, ro RangeOptions) (*RangeResult, error) { - tw.ranges++ - return tw.TxnWrite.Range(ctx, key, end, ro) -} - -func (tw *metricsTxnWrite) DeleteRange(key, end []byte) (n, rev int64) { - tw.deletes++ - return tw.TxnWrite.DeleteRange(key, end) -} - -func (tw *metricsTxnWrite) Put(key, value []byte, lease lease.LeaseID) (rev int64) { - tw.puts++ - size := int64(len(key) + len(value)) - tw.putSize += size - return tw.TxnWrite.Put(key, value, lease) -} - -func (tw *metricsTxnWrite) End() { - defer tw.TxnWrite.End() - if sum := tw.ranges + tw.puts + tw.deletes; sum > 1 { - txnCounter.Inc() - } - - ranges := float64(tw.ranges) - rangeCounter.Add(ranges) - rangeCounterDebug.Add(ranges) // TODO: remove in 3.5 release - - puts := float64(tw.puts) - putCounter.Add(puts) - totalPutSizeGauge.Add(float64(tw.putSize)) - - deletes := float64(tw.deletes) - deleteCounter.Add(deletes) -} diff --git a/vendor/go.etcd.io/etcd/server/v3/mvcc/revision.go b/vendor/go.etcd.io/etcd/server/v3/mvcc/revision.go deleted file mode 100644 index d6213866f2..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/mvcc/revision.go +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package mvcc - -import "encoding/binary" - -// revBytesLen is the byte length of a normal revision. -// First 8 bytes is the revision.main in big-endian format. The 9th byte -// is a '_'. The last 8 bytes is the revision.sub in big-endian format. -const revBytesLen = 8 + 1 + 8 - -// A revision indicates modification of the key-value space. -// The set of changes that share same main revision changes the key-value space atomically. -type revision struct { - // main is the main revision of a set of changes that happen atomically. - main int64 - - // sub is the sub revision of a change in a set of changes that happen - // atomically. Each change has different increasing sub revision in that - // set. - sub int64 -} - -func (a revision) GreaterThan(b revision) bool { - if a.main > b.main { - return true - } - if a.main < b.main { - return false - } - return a.sub > b.sub -} - -func newRevBytes() []byte { - return make([]byte, revBytesLen, markedRevBytesLen) -} - -func revToBytes(rev revision, bytes []byte) { - binary.BigEndian.PutUint64(bytes, uint64(rev.main)) - bytes[8] = '_' - binary.BigEndian.PutUint64(bytes[9:], uint64(rev.sub)) -} - -func bytesToRev(bytes []byte) revision { - return revision{ - main: int64(binary.BigEndian.Uint64(bytes[0:8])), - sub: int64(binary.BigEndian.Uint64(bytes[9:])), - } -} - -type revisions []revision - -func (a revisions) Len() int { return len(a) } -func (a revisions) Less(i, j int) bool { return a[j].GreaterThan(a[i]) } -func (a revisions) Swap(i, j int) { a[i], a[j] = a[j], a[i] } diff --git a/vendor/go.etcd.io/etcd/server/v3/mvcc/util.go b/vendor/go.etcd.io/etcd/server/v3/mvcc/util.go deleted file mode 100644 index 83cbf44bf8..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/mvcc/util.go +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package mvcc - -import ( - "fmt" - - "go.etcd.io/etcd/api/v3/mvccpb" - "go.etcd.io/etcd/server/v3/mvcc/backend" - "go.etcd.io/etcd/server/v3/mvcc/buckets" -) - -func WriteKV(be backend.Backend, kv mvccpb.KeyValue) { - ibytes := newRevBytes() - revToBytes(revision{main: kv.ModRevision}, ibytes) - - d, err := kv.Marshal() - if err != nil { - panic(fmt.Errorf("cannot marshal event: %v", err)) - } - - be.BatchTx().Lock() - be.BatchTx().UnsafePut(buckets.Key, ibytes, d) - be.BatchTx().Unlock() -} diff --git a/vendor/go.etcd.io/etcd/server/v3/mvcc/watchable_store.go b/vendor/go.etcd.io/etcd/server/v3/mvcc/watchable_store.go deleted file mode 100644 index 3c7edb3337..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/mvcc/watchable_store.go +++ /dev/null @@ -1,545 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package mvcc - -import ( - "sync" - "time" - - "go.etcd.io/etcd/api/v3/mvccpb" - "go.etcd.io/etcd/pkg/v3/traceutil" - "go.etcd.io/etcd/server/v3/lease" - "go.etcd.io/etcd/server/v3/mvcc/backend" - "go.etcd.io/etcd/server/v3/mvcc/buckets" - - "go.uber.org/zap" -) - -// non-const so modifiable by tests -var ( - // chanBufLen is the length of the buffered chan - // for sending out watched events. - // See https://github.com/etcd-io/etcd/issues/11906 for more detail. - chanBufLen = 128 - - // maxWatchersPerSync is the number of watchers to sync in a single batch - maxWatchersPerSync = 512 -) - -type watchable interface { - watch(key, end []byte, startRev int64, id WatchID, ch chan<- WatchResponse, fcs ...FilterFunc) (*watcher, cancelFunc) - progress(w *watcher) - rev() int64 -} - -type watchableStore struct { - *store - - // mu protects watcher groups and batches. It should never be locked - // before locking store.mu to avoid deadlock. - mu sync.RWMutex - - // victims are watcher batches that were blocked on the watch channel - victims []watcherBatch - victimc chan struct{} - - // contains all unsynced watchers that needs to sync with events that have happened - unsynced watcherGroup - - // contains all synced watchers that are in sync with the progress of the store. - // The key of the map is the key that the watcher watches on. - synced watcherGroup - - stopc chan struct{} - wg sync.WaitGroup -} - -// cancelFunc updates unsynced and synced maps when running -// cancel operations. -type cancelFunc func() - -func New(lg *zap.Logger, b backend.Backend, le lease.Lessor, cfg StoreConfig) WatchableKV { - return newWatchableStore(lg, b, le, cfg) -} - -func newWatchableStore(lg *zap.Logger, b backend.Backend, le lease.Lessor, cfg StoreConfig) *watchableStore { - if lg == nil { - lg = zap.NewNop() - } - s := &watchableStore{ - store: NewStore(lg, b, le, cfg), - victimc: make(chan struct{}, 1), - unsynced: newWatcherGroup(), - synced: newWatcherGroup(), - stopc: make(chan struct{}), - } - s.store.ReadView = &readView{s} - s.store.WriteView = &writeView{s} - if s.le != nil { - // use this store as the deleter so revokes trigger watch events - s.le.SetRangeDeleter(func() lease.TxnDelete { return s.Write(traceutil.TODO()) }) - } - s.wg.Add(2) - go s.syncWatchersLoop() - go s.syncVictimsLoop() - return s -} - -func (s *watchableStore) Close() error { - close(s.stopc) - s.wg.Wait() - return s.store.Close() -} - -func (s *watchableStore) NewWatchStream() WatchStream { - watchStreamGauge.Inc() - return &watchStream{ - watchable: s, - ch: make(chan WatchResponse, chanBufLen), - cancels: make(map[WatchID]cancelFunc), - watchers: make(map[WatchID]*watcher), - } -} - -func (s *watchableStore) watch(key, end []byte, startRev int64, id WatchID, ch chan<- WatchResponse, fcs ...FilterFunc) (*watcher, cancelFunc) { - wa := &watcher{ - key: key, - end: end, - minRev: startRev, - id: id, - ch: ch, - fcs: fcs, - } - - s.mu.Lock() - s.revMu.RLock() - synced := startRev > s.store.currentRev || startRev == 0 - if synced { - wa.minRev = s.store.currentRev + 1 - if startRev > wa.minRev { - wa.minRev = startRev - } - s.synced.add(wa) - } else { - slowWatcherGauge.Inc() - s.unsynced.add(wa) - } - s.revMu.RUnlock() - s.mu.Unlock() - - watcherGauge.Inc() - - return wa, func() { s.cancelWatcher(wa) } -} - -// cancelWatcher removes references of the watcher from the watchableStore -func (s *watchableStore) cancelWatcher(wa *watcher) { - for { - s.mu.Lock() - if s.unsynced.delete(wa) { - slowWatcherGauge.Dec() - watcherGauge.Dec() - break - } else if s.synced.delete(wa) { - watcherGauge.Dec() - break - } else if wa.compacted { - watcherGauge.Dec() - break - } else if wa.ch == nil { - // already canceled (e.g., cancel/close race) - break - } - - if !wa.victim { - s.mu.Unlock() - panic("watcher not victim but not in watch groups") - } - - var victimBatch watcherBatch - for _, wb := range s.victims { - if wb[wa] != nil { - victimBatch = wb - break - } - } - if victimBatch != nil { - slowWatcherGauge.Dec() - watcherGauge.Dec() - delete(victimBatch, wa) - break - } - - // victim being processed so not accessible; retry - s.mu.Unlock() - time.Sleep(time.Millisecond) - } - - wa.ch = nil - s.mu.Unlock() -} - -func (s *watchableStore) Restore(b backend.Backend) error { - s.mu.Lock() - defer s.mu.Unlock() - err := s.store.Restore(b) - if err != nil { - return err - } - - for wa := range s.synced.watchers { - wa.restore = true - s.unsynced.add(wa) - } - s.synced = newWatcherGroup() - return nil -} - -// syncWatchersLoop syncs the watcher in the unsynced map every 100ms. -func (s *watchableStore) syncWatchersLoop() { - defer s.wg.Done() - - for { - s.mu.RLock() - st := time.Now() - lastUnsyncedWatchers := s.unsynced.size() - s.mu.RUnlock() - - unsyncedWatchers := 0 - if lastUnsyncedWatchers > 0 { - unsyncedWatchers = s.syncWatchers() - } - syncDuration := time.Since(st) - - waitDuration := 100 * time.Millisecond - // more work pending? - if unsyncedWatchers != 0 && lastUnsyncedWatchers > unsyncedWatchers { - // be fair to other store operations by yielding time taken - waitDuration = syncDuration - } - - select { - case <-time.After(waitDuration): - case <-s.stopc: - return - } - } -} - -// syncVictimsLoop tries to write precomputed watcher responses to -// watchers that had a blocked watcher channel -func (s *watchableStore) syncVictimsLoop() { - defer s.wg.Done() - - for { - for s.moveVictims() != 0 { - // try to update all victim watchers - } - s.mu.RLock() - isEmpty := len(s.victims) == 0 - s.mu.RUnlock() - - var tickc <-chan time.Time - if !isEmpty { - tickc = time.After(10 * time.Millisecond) - } - - select { - case <-tickc: - case <-s.victimc: - case <-s.stopc: - return - } - } -} - -// moveVictims tries to update watches with already pending event data -func (s *watchableStore) moveVictims() (moved int) { - s.mu.Lock() - victims := s.victims - s.victims = nil - s.mu.Unlock() - - var newVictim watcherBatch - for _, wb := range victims { - // try to send responses again - for w, eb := range wb { - // watcher has observed the store up to, but not including, w.minRev - rev := w.minRev - 1 - if w.send(WatchResponse{WatchID: w.id, Events: eb.evs, Revision: rev}) { - pendingEventsGauge.Add(float64(len(eb.evs))) - } else { - if newVictim == nil { - newVictim = make(watcherBatch) - } - newVictim[w] = eb - continue - } - moved++ - } - - // assign completed victim watchers to unsync/sync - s.mu.Lock() - s.store.revMu.RLock() - curRev := s.store.currentRev - for w, eb := range wb { - if newVictim != nil && newVictim[w] != nil { - // couldn't send watch response; stays victim - continue - } - w.victim = false - if eb.moreRev != 0 { - w.minRev = eb.moreRev - } - if w.minRev <= curRev { - s.unsynced.add(w) - } else { - slowWatcherGauge.Dec() - s.synced.add(w) - } - } - s.store.revMu.RUnlock() - s.mu.Unlock() - } - - if len(newVictim) > 0 { - s.mu.Lock() - s.victims = append(s.victims, newVictim) - s.mu.Unlock() - } - - return moved -} - -// syncWatchers syncs unsynced watchers by: -// 1. choose a set of watchers from the unsynced watcher group -// 2. iterate over the set to get the minimum revision and remove compacted watchers -// 3. use minimum revision to get all key-value pairs and send those events to watchers -// 4. remove synced watchers in set from unsynced group and move to synced group -func (s *watchableStore) syncWatchers() int { - s.mu.Lock() - defer s.mu.Unlock() - - if s.unsynced.size() == 0 { - return 0 - } - - s.store.revMu.RLock() - defer s.store.revMu.RUnlock() - - // in order to find key-value pairs from unsynced watchers, we need to - // find min revision index, and these revisions can be used to - // query the backend store of key-value pairs - curRev := s.store.currentRev - compactionRev := s.store.compactMainRev - - wg, minRev := s.unsynced.choose(maxWatchersPerSync, curRev, compactionRev) - minBytes, maxBytes := newRevBytes(), newRevBytes() - revToBytes(revision{main: minRev}, minBytes) - revToBytes(revision{main: curRev + 1}, maxBytes) - - // UnsafeRange returns keys and values. And in boltdb, keys are revisions. - // values are actual key-value pairs in backend. - tx := s.store.b.ReadTx() - tx.RLock() - revs, vs := tx.UnsafeRange(buckets.Key, minBytes, maxBytes, 0) - tx.RUnlock() - evs := kvsToEvents(s.store.lg, wg, revs, vs) - - var victims watcherBatch - wb := newWatcherBatch(wg, evs) - for w := range wg.watchers { - w.minRev = curRev + 1 - - eb, ok := wb[w] - if !ok { - // bring un-notified watcher to synced - s.synced.add(w) - s.unsynced.delete(w) - continue - } - - if eb.moreRev != 0 { - w.minRev = eb.moreRev - } - - if w.send(WatchResponse{WatchID: w.id, Events: eb.evs, Revision: curRev}) { - pendingEventsGauge.Add(float64(len(eb.evs))) - } else { - if victims == nil { - victims = make(watcherBatch) - } - w.victim = true - } - - if w.victim { - victims[w] = eb - } else { - if eb.moreRev != 0 { - // stay unsynced; more to read - continue - } - s.synced.add(w) - } - s.unsynced.delete(w) - } - s.addVictim(victims) - - vsz := 0 - for _, v := range s.victims { - vsz += len(v) - } - slowWatcherGauge.Set(float64(s.unsynced.size() + vsz)) - - return s.unsynced.size() -} - -// kvsToEvents gets all events for the watchers from all key-value pairs -func kvsToEvents(lg *zap.Logger, wg *watcherGroup, revs, vals [][]byte) (evs []mvccpb.Event) { - for i, v := range vals { - var kv mvccpb.KeyValue - if err := kv.Unmarshal(v); err != nil { - lg.Panic("failed to unmarshal mvccpb.KeyValue", zap.Error(err)) - } - - if !wg.contains(string(kv.Key)) { - continue - } - - ty := mvccpb.PUT - if isTombstone(revs[i]) { - ty = mvccpb.DELETE - // patch in mod revision so watchers won't skip - kv.ModRevision = bytesToRev(revs[i]).main - } - evs = append(evs, mvccpb.Event{Kv: &kv, Type: ty}) - } - return evs -} - -// notify notifies the fact that given event at the given rev just happened to -// watchers that watch on the key of the event. -func (s *watchableStore) notify(rev int64, evs []mvccpb.Event) { - var victim watcherBatch - for w, eb := range newWatcherBatch(&s.synced, evs) { - if eb.revs != 1 { - s.store.lg.Panic( - "unexpected multiple revisions in watch notification", - zap.Int("number-of-revisions", eb.revs), - ) - } - if w.send(WatchResponse{WatchID: w.id, Events: eb.evs, Revision: rev}) { - pendingEventsGauge.Add(float64(len(eb.evs))) - } else { - // move slow watcher to victims - w.minRev = rev + 1 - if victim == nil { - victim = make(watcherBatch) - } - w.victim = true - victim[w] = eb - s.synced.delete(w) - slowWatcherGauge.Inc() - } - } - s.addVictim(victim) -} - -func (s *watchableStore) addVictim(victim watcherBatch) { - if victim == nil { - return - } - s.victims = append(s.victims, victim) - select { - case s.victimc <- struct{}{}: - default: - } -} - -func (s *watchableStore) rev() int64 { return s.store.Rev() } - -func (s *watchableStore) progress(w *watcher) { - s.mu.RLock() - defer s.mu.RUnlock() - - if _, ok := s.synced.watchers[w]; ok { - w.send(WatchResponse{WatchID: w.id, Revision: s.rev()}) - // If the ch is full, this watcher is receiving events. - // We do not need to send progress at all. - } -} - -type watcher struct { - // the watcher key - key []byte - // end indicates the end of the range to watch. - // If end is set, the watcher is on a range. - end []byte - - // victim is set when ch is blocked and undergoing victim processing - victim bool - - // compacted is set when the watcher is removed because of compaction - compacted bool - - // restore is true when the watcher is being restored from leader snapshot - // which means that this watcher has just been moved from "synced" to "unsynced" - // watcher group, possibly with a future revision when it was first added - // to the synced watcher - // "unsynced" watcher revision must always be <= current revision, - // except when the watcher were to be moved from "synced" watcher group - restore bool - - // minRev is the minimum revision update the watcher will accept - minRev int64 - id WatchID - - fcs []FilterFunc - // a chan to send out the watch response. - // The chan might be shared with other watchers. - ch chan<- WatchResponse -} - -func (w *watcher) send(wr WatchResponse) bool { - progressEvent := len(wr.Events) == 0 - - if len(w.fcs) != 0 { - ne := make([]mvccpb.Event, 0, len(wr.Events)) - for i := range wr.Events { - filtered := false - for _, filter := range w.fcs { - if filter(wr.Events[i]) { - filtered = true - break - } - } - if !filtered { - ne = append(ne, wr.Events[i]) - } - } - wr.Events = ne - } - - // if all events are filtered out, we should send nothing. - if !progressEvent && len(wr.Events) == 0 { - return true - } - select { - case w.ch <- wr: - return true - default: - return false - } -} diff --git a/vendor/go.etcd.io/etcd/server/v3/mvcc/watchable_store_txn.go b/vendor/go.etcd.io/etcd/server/v3/mvcc/watchable_store_txn.go deleted file mode 100644 index b70d8ceca4..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/mvcc/watchable_store_txn.go +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package mvcc - -import ( - "go.etcd.io/etcd/api/v3/mvccpb" - "go.etcd.io/etcd/pkg/v3/traceutil" -) - -func (tw *watchableStoreTxnWrite) End() { - changes := tw.Changes() - if len(changes) == 0 { - tw.TxnWrite.End() - return - } - - rev := tw.Rev() + 1 - evs := make([]mvccpb.Event, len(changes)) - for i, change := range changes { - evs[i].Kv = &changes[i] - if change.CreateRevision == 0 { - evs[i].Type = mvccpb.DELETE - evs[i].Kv.ModRevision = rev - } else { - evs[i].Type = mvccpb.PUT - } - } - - // end write txn under watchable store lock so the updates are visible - // when asynchronous event posting checks the current store revision - tw.s.mu.Lock() - tw.s.notify(rev, evs) - tw.TxnWrite.End() - tw.s.mu.Unlock() -} - -type watchableStoreTxnWrite struct { - TxnWrite - s *watchableStore -} - -func (s *watchableStore) Write(trace *traceutil.Trace) TxnWrite { - return &watchableStoreTxnWrite{s.store.Write(trace), s} -} diff --git a/vendor/go.etcd.io/etcd/server/v3/mvcc/watcher.go b/vendor/go.etcd.io/etcd/server/v3/mvcc/watcher.go deleted file mode 100644 index f48a9ef3b3..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/mvcc/watcher.go +++ /dev/null @@ -1,193 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package mvcc - -import ( - "bytes" - "errors" - "sync" - - "go.etcd.io/etcd/api/v3/mvccpb" -) - -// AutoWatchID is the watcher ID passed in WatchStream.Watch when no -// user-provided ID is available. If pass, an ID will automatically be assigned. -const AutoWatchID WatchID = 0 - -var ( - ErrWatcherNotExist = errors.New("mvcc: watcher does not exist") - ErrEmptyWatcherRange = errors.New("mvcc: watcher range is empty") - ErrWatcherDuplicateID = errors.New("mvcc: duplicate watch ID provided on the WatchStream") -) - -type WatchID int64 - -// FilterFunc returns true if the given event should be filtered out. -type FilterFunc func(e mvccpb.Event) bool - -type WatchStream interface { - // Watch creates a watcher. The watcher watches the events happening or - // happened on the given key or range [key, end) from the given startRev. - // - // The whole event history can be watched unless compacted. - // If "startRev" <=0, watch observes events after currentRev. - // - // The returned "id" is the ID of this watcher. It appears as WatchID - // in events that are sent to the created watcher through stream channel. - // The watch ID is used when it's not equal to AutoWatchID. Otherwise, - // an auto-generated watch ID is returned. - Watch(id WatchID, key, end []byte, startRev int64, fcs ...FilterFunc) (WatchID, error) - - // Chan returns a chan. All watch response will be sent to the returned chan. - Chan() <-chan WatchResponse - - // RequestProgress requests the progress of the watcher with given ID. The response - // will only be sent if the watcher is currently synced. - // The responses will be sent through the WatchRespone Chan attached - // with this stream to ensure correct ordering. - // The responses contains no events. The revision in the response is the progress - // of the watchers since the watcher is currently synced. - RequestProgress(id WatchID) - - // Cancel cancels a watcher by giving its ID. If watcher does not exist, an error will be - // returned. - Cancel(id WatchID) error - - // Close closes Chan and release all related resources. - Close() - - // Rev returns the current revision of the KV the stream watches on. - Rev() int64 -} - -type WatchResponse struct { - // WatchID is the WatchID of the watcher this response sent to. - WatchID WatchID - - // Events contains all the events that needs to send. - Events []mvccpb.Event - - // Revision is the revision of the KV when the watchResponse is created. - // For a normal response, the revision should be the same as the last - // modified revision inside Events. For a delayed response to a unsynced - // watcher, the revision is greater than the last modified revision - // inside Events. - Revision int64 - - // CompactRevision is set when the watcher is cancelled due to compaction. - CompactRevision int64 -} - -// watchStream contains a collection of watchers that share -// one streaming chan to send out watched events and other control events. -type watchStream struct { - watchable watchable - ch chan WatchResponse - - mu sync.Mutex // guards fields below it - // nextID is the ID pre-allocated for next new watcher in this stream - nextID WatchID - closed bool - cancels map[WatchID]cancelFunc - watchers map[WatchID]*watcher -} - -// Watch creates a new watcher in the stream and returns its WatchID. -func (ws *watchStream) Watch(id WatchID, key, end []byte, startRev int64, fcs ...FilterFunc) (WatchID, error) { - // prevent wrong range where key >= end lexicographically - // watch request with 'WithFromKey' has empty-byte range end - if len(end) != 0 && bytes.Compare(key, end) != -1 { - return -1, ErrEmptyWatcherRange - } - - ws.mu.Lock() - defer ws.mu.Unlock() - if ws.closed { - return -1, ErrEmptyWatcherRange - } - - if id == AutoWatchID { - for ws.watchers[ws.nextID] != nil { - ws.nextID++ - } - id = ws.nextID - ws.nextID++ - } else if _, ok := ws.watchers[id]; ok { - return -1, ErrWatcherDuplicateID - } - - w, c := ws.watchable.watch(key, end, startRev, id, ws.ch, fcs...) - - ws.cancels[id] = c - ws.watchers[id] = w - return id, nil -} - -func (ws *watchStream) Chan() <-chan WatchResponse { - return ws.ch -} - -func (ws *watchStream) Cancel(id WatchID) error { - ws.mu.Lock() - cancel, ok := ws.cancels[id] - w := ws.watchers[id] - ok = ok && !ws.closed - ws.mu.Unlock() - - if !ok { - return ErrWatcherNotExist - } - cancel() - - ws.mu.Lock() - // The watch isn't removed until cancel so that if Close() is called, - // it will wait for the cancel. Otherwise, Close() could close the - // watch channel while the store is still posting events. - if ww := ws.watchers[id]; ww == w { - delete(ws.cancels, id) - delete(ws.watchers, id) - } - ws.mu.Unlock() - - return nil -} - -func (ws *watchStream) Close() { - ws.mu.Lock() - defer ws.mu.Unlock() - - for _, cancel := range ws.cancels { - cancel() - } - ws.closed = true - close(ws.ch) - watchStreamGauge.Dec() -} - -func (ws *watchStream) Rev() int64 { - ws.mu.Lock() - defer ws.mu.Unlock() - return ws.watchable.rev() -} - -func (ws *watchStream) RequestProgress(id WatchID) { - ws.mu.Lock() - w, ok := ws.watchers[id] - ws.mu.Unlock() - if !ok { - return - } - ws.watchable.progress(w) -} diff --git a/vendor/go.etcd.io/etcd/server/v3/mvcc/watcher_group.go b/vendor/go.etcd.io/etcd/server/v3/mvcc/watcher_group.go deleted file mode 100644 index 356b49e641..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/mvcc/watcher_group.go +++ /dev/null @@ -1,293 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package mvcc - -import ( - "fmt" - "math" - - "go.etcd.io/etcd/api/v3/mvccpb" - "go.etcd.io/etcd/pkg/v3/adt" -) - -var ( - // watchBatchMaxRevs is the maximum distinct revisions that - // may be sent to an unsynced watcher at a time. Declared as - // var instead of const for testing purposes. - watchBatchMaxRevs = 1000 -) - -type eventBatch struct { - // evs is a batch of revision-ordered events - evs []mvccpb.Event - // revs is the minimum unique revisions observed for this batch - revs int - // moreRev is first revision with more events following this batch - moreRev int64 -} - -func (eb *eventBatch) add(ev mvccpb.Event) { - if eb.revs > watchBatchMaxRevs { - // maxed out batch size - return - } - - if len(eb.evs) == 0 { - // base case - eb.revs = 1 - eb.evs = append(eb.evs, ev) - return - } - - // revision accounting - ebRev := eb.evs[len(eb.evs)-1].Kv.ModRevision - evRev := ev.Kv.ModRevision - if evRev > ebRev { - eb.revs++ - if eb.revs > watchBatchMaxRevs { - eb.moreRev = evRev - return - } - } - - eb.evs = append(eb.evs, ev) -} - -type watcherBatch map[*watcher]*eventBatch - -func (wb watcherBatch) add(w *watcher, ev mvccpb.Event) { - eb := wb[w] - if eb == nil { - eb = &eventBatch{} - wb[w] = eb - } - eb.add(ev) -} - -// newWatcherBatch maps watchers to their matched events. It enables quick -// events look up by watcher. -func newWatcherBatch(wg *watcherGroup, evs []mvccpb.Event) watcherBatch { - if len(wg.watchers) == 0 { - return nil - } - - wb := make(watcherBatch) - for _, ev := range evs { - for w := range wg.watcherSetByKey(string(ev.Kv.Key)) { - if ev.Kv.ModRevision >= w.minRev { - // don't double notify - wb.add(w, ev) - } - } - } - return wb -} - -type watcherSet map[*watcher]struct{} - -func (w watcherSet) add(wa *watcher) { - if _, ok := w[wa]; ok { - panic("add watcher twice!") - } - w[wa] = struct{}{} -} - -func (w watcherSet) union(ws watcherSet) { - for wa := range ws { - w.add(wa) - } -} - -func (w watcherSet) delete(wa *watcher) { - if _, ok := w[wa]; !ok { - panic("removing missing watcher!") - } - delete(w, wa) -} - -type watcherSetByKey map[string]watcherSet - -func (w watcherSetByKey) add(wa *watcher) { - set := w[string(wa.key)] - if set == nil { - set = make(watcherSet) - w[string(wa.key)] = set - } - set.add(wa) -} - -func (w watcherSetByKey) delete(wa *watcher) bool { - k := string(wa.key) - if v, ok := w[k]; ok { - if _, ok := v[wa]; ok { - delete(v, wa) - if len(v) == 0 { - // remove the set; nothing left - delete(w, k) - } - return true - } - } - return false -} - -// watcherGroup is a collection of watchers organized by their ranges -type watcherGroup struct { - // keyWatchers has the watchers that watch on a single key - keyWatchers watcherSetByKey - // ranges has the watchers that watch a range; it is sorted by interval - ranges adt.IntervalTree - // watchers is the set of all watchers - watchers watcherSet -} - -func newWatcherGroup() watcherGroup { - return watcherGroup{ - keyWatchers: make(watcherSetByKey), - ranges: adt.NewIntervalTree(), - watchers: make(watcherSet), - } -} - -// add puts a watcher in the group. -func (wg *watcherGroup) add(wa *watcher) { - wg.watchers.add(wa) - if wa.end == nil { - wg.keyWatchers.add(wa) - return - } - - // interval already registered? - ivl := adt.NewStringAffineInterval(string(wa.key), string(wa.end)) - if iv := wg.ranges.Find(ivl); iv != nil { - iv.Val.(watcherSet).add(wa) - return - } - - // not registered, put in interval tree - ws := make(watcherSet) - ws.add(wa) - wg.ranges.Insert(ivl, ws) -} - -// contains is whether the given key has a watcher in the group. -func (wg *watcherGroup) contains(key string) bool { - _, ok := wg.keyWatchers[key] - return ok || wg.ranges.Intersects(adt.NewStringAffinePoint(key)) -} - -// size gives the number of unique watchers in the group. -func (wg *watcherGroup) size() int { return len(wg.watchers) } - -// delete removes a watcher from the group. -func (wg *watcherGroup) delete(wa *watcher) bool { - if _, ok := wg.watchers[wa]; !ok { - return false - } - wg.watchers.delete(wa) - if wa.end == nil { - wg.keyWatchers.delete(wa) - return true - } - - ivl := adt.NewStringAffineInterval(string(wa.key), string(wa.end)) - iv := wg.ranges.Find(ivl) - if iv == nil { - return false - } - - ws := iv.Val.(watcherSet) - delete(ws, wa) - if len(ws) == 0 { - // remove interval missing watchers - if ok := wg.ranges.Delete(ivl); !ok { - panic("could not remove watcher from interval tree") - } - } - - return true -} - -// choose selects watchers from the watcher group to update -func (wg *watcherGroup) choose(maxWatchers int, curRev, compactRev int64) (*watcherGroup, int64) { - if len(wg.watchers) < maxWatchers { - return wg, wg.chooseAll(curRev, compactRev) - } - ret := newWatcherGroup() - for w := range wg.watchers { - if maxWatchers <= 0 { - break - } - maxWatchers-- - ret.add(w) - } - return &ret, ret.chooseAll(curRev, compactRev) -} - -func (wg *watcherGroup) chooseAll(curRev, compactRev int64) int64 { - minRev := int64(math.MaxInt64) - for w := range wg.watchers { - if w.minRev > curRev { - // after network partition, possibly choosing future revision watcher from restore operation - // with watch key "proxy-namespace__lostleader" and revision "math.MaxInt64 - 2" - // do not panic when such watcher had been moved from "synced" watcher during restore operation - if !w.restore { - panic(fmt.Errorf("watcher minimum revision %d should not exceed current revision %d", w.minRev, curRev)) - } - - // mark 'restore' done, since it's chosen - w.restore = false - } - if w.minRev < compactRev { - select { - case w.ch <- WatchResponse{WatchID: w.id, CompactRevision: compactRev}: - w.compacted = true - wg.delete(w) - default: - // retry next time - } - continue - } - if minRev > w.minRev { - minRev = w.minRev - } - } - return minRev -} - -// watcherSetByKey gets the set of watchers that receive events on the given key. -func (wg *watcherGroup) watcherSetByKey(key string) watcherSet { - wkeys := wg.keyWatchers[key] - wranges := wg.ranges.Stab(adt.NewStringAffinePoint(key)) - - // zero-copy cases - switch { - case len(wranges) == 0: - // no need to merge ranges or copy; reuse single-key set - return wkeys - case len(wranges) == 0 && len(wkeys) == 0: - return nil - case len(wranges) == 1 && len(wkeys) == 0: - return wranges[0].Val.(watcherSet) - } - - // copy case - ret := make(watcherSet) - ret.union(wg.keyWatchers[key]) - for _, item := range wranges { - ret.union(item.Val.(watcherSet)) - } - return ret -} diff --git a/vendor/go.etcd.io/etcd/server/v3/proxy/grpcproxy/adapter/auth_client_adapter.go b/vendor/go.etcd.io/etcd/server/v3/proxy/grpcproxy/adapter/auth_client_adapter.go deleted file mode 100644 index 140212b962..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/proxy/grpcproxy/adapter/auth_client_adapter.go +++ /dev/null @@ -1,97 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package adapter - -import ( - "context" - - pb "go.etcd.io/etcd/api/v3/etcdserverpb" - - grpc "google.golang.org/grpc" -) - -type as2ac struct{ as pb.AuthServer } - -func AuthServerToAuthClient(as pb.AuthServer) pb.AuthClient { - return &as2ac{as} -} - -func (s *as2ac) AuthEnable(ctx context.Context, in *pb.AuthEnableRequest, opts ...grpc.CallOption) (*pb.AuthEnableResponse, error) { - return s.as.AuthEnable(ctx, in) -} - -func (s *as2ac) AuthDisable(ctx context.Context, in *pb.AuthDisableRequest, opts ...grpc.CallOption) (*pb.AuthDisableResponse, error) { - return s.as.AuthDisable(ctx, in) -} - -func (s *as2ac) AuthStatus(ctx context.Context, in *pb.AuthStatusRequest, opts ...grpc.CallOption) (*pb.AuthStatusResponse, error) { - return s.as.AuthStatus(ctx, in) -} - -func (s *as2ac) Authenticate(ctx context.Context, in *pb.AuthenticateRequest, opts ...grpc.CallOption) (*pb.AuthenticateResponse, error) { - return s.as.Authenticate(ctx, in) -} - -func (s *as2ac) RoleAdd(ctx context.Context, in *pb.AuthRoleAddRequest, opts ...grpc.CallOption) (*pb.AuthRoleAddResponse, error) { - return s.as.RoleAdd(ctx, in) -} - -func (s *as2ac) RoleDelete(ctx context.Context, in *pb.AuthRoleDeleteRequest, opts ...grpc.CallOption) (*pb.AuthRoleDeleteResponse, error) { - return s.as.RoleDelete(ctx, in) -} - -func (s *as2ac) RoleGet(ctx context.Context, in *pb.AuthRoleGetRequest, opts ...grpc.CallOption) (*pb.AuthRoleGetResponse, error) { - return s.as.RoleGet(ctx, in) -} - -func (s *as2ac) RoleList(ctx context.Context, in *pb.AuthRoleListRequest, opts ...grpc.CallOption) (*pb.AuthRoleListResponse, error) { - return s.as.RoleList(ctx, in) -} - -func (s *as2ac) RoleRevokePermission(ctx context.Context, in *pb.AuthRoleRevokePermissionRequest, opts ...grpc.CallOption) (*pb.AuthRoleRevokePermissionResponse, error) { - return s.as.RoleRevokePermission(ctx, in) -} - -func (s *as2ac) RoleGrantPermission(ctx context.Context, in *pb.AuthRoleGrantPermissionRequest, opts ...grpc.CallOption) (*pb.AuthRoleGrantPermissionResponse, error) { - return s.as.RoleGrantPermission(ctx, in) -} - -func (s *as2ac) UserDelete(ctx context.Context, in *pb.AuthUserDeleteRequest, opts ...grpc.CallOption) (*pb.AuthUserDeleteResponse, error) { - return s.as.UserDelete(ctx, in) -} - -func (s *as2ac) UserAdd(ctx context.Context, in *pb.AuthUserAddRequest, opts ...grpc.CallOption) (*pb.AuthUserAddResponse, error) { - return s.as.UserAdd(ctx, in) -} - -func (s *as2ac) UserGet(ctx context.Context, in *pb.AuthUserGetRequest, opts ...grpc.CallOption) (*pb.AuthUserGetResponse, error) { - return s.as.UserGet(ctx, in) -} - -func (s *as2ac) UserList(ctx context.Context, in *pb.AuthUserListRequest, opts ...grpc.CallOption) (*pb.AuthUserListResponse, error) { - return s.as.UserList(ctx, in) -} - -func (s *as2ac) UserGrantRole(ctx context.Context, in *pb.AuthUserGrantRoleRequest, opts ...grpc.CallOption) (*pb.AuthUserGrantRoleResponse, error) { - return s.as.UserGrantRole(ctx, in) -} - -func (s *as2ac) UserRevokeRole(ctx context.Context, in *pb.AuthUserRevokeRoleRequest, opts ...grpc.CallOption) (*pb.AuthUserRevokeRoleResponse, error) { - return s.as.UserRevokeRole(ctx, in) -} - -func (s *as2ac) UserChangePassword(ctx context.Context, in *pb.AuthUserChangePasswordRequest, opts ...grpc.CallOption) (*pb.AuthUserChangePasswordResponse, error) { - return s.as.UserChangePassword(ctx, in) -} diff --git a/vendor/go.etcd.io/etcd/server/v3/proxy/grpcproxy/adapter/chan_stream.go b/vendor/go.etcd.io/etcd/server/v3/proxy/grpcproxy/adapter/chan_stream.go deleted file mode 100644 index 1af514b1fd..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/proxy/grpcproxy/adapter/chan_stream.go +++ /dev/null @@ -1,167 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package adapter - -import ( - "context" - - "google.golang.org/grpc" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/metadata" - "google.golang.org/grpc/status" -) - -// chanServerStream implements grpc.ServerStream with a chanStream -type chanServerStream struct { - headerc chan<- metadata.MD - trailerc chan<- metadata.MD - grpc.Stream - - headers []metadata.MD -} - -func (ss *chanServerStream) SendHeader(md metadata.MD) error { - if ss.headerc == nil { - return errAlreadySentHeader - } - outmd := make(map[string][]string) - for _, h := range append(ss.headers, md) { - for k, v := range h { - outmd[k] = v - } - } - select { - case ss.headerc <- outmd: - ss.headerc = nil - ss.headers = nil - return nil - case <-ss.Context().Done(): - } - return ss.Context().Err() -} - -func (ss *chanServerStream) SetHeader(md metadata.MD) error { - if ss.headerc == nil { - return errAlreadySentHeader - } - ss.headers = append(ss.headers, md) - return nil -} - -func (ss *chanServerStream) SetTrailer(md metadata.MD) { - ss.trailerc <- md -} - -// chanClientStream implements grpc.ClientStream with a chanStream -type chanClientStream struct { - headerc <-chan metadata.MD - trailerc <-chan metadata.MD - *chanStream -} - -func (cs *chanClientStream) Header() (metadata.MD, error) { - select { - case md := <-cs.headerc: - return md, nil - case <-cs.Context().Done(): - } - return nil, cs.Context().Err() -} - -func (cs *chanClientStream) Trailer() metadata.MD { - select { - case md := <-cs.trailerc: - return md - case <-cs.Context().Done(): - return nil - } -} - -func (cs *chanClientStream) CloseSend() error { - close(cs.chanStream.sendc) - return nil -} - -// chanStream implements grpc.Stream using channels -type chanStream struct { - recvc <-chan interface{} - sendc chan<- interface{} - ctx context.Context - cancel context.CancelFunc -} - -func (s *chanStream) Context() context.Context { return s.ctx } - -func (s *chanStream) SendMsg(m interface{}) error { - select { - case s.sendc <- m: - if err, ok := m.(error); ok { - return err - } - return nil - case <-s.ctx.Done(): - } - return s.ctx.Err() -} - -func (s *chanStream) RecvMsg(m interface{}) error { - v := m.(*interface{}) - for { - select { - case msg, ok := <-s.recvc: - if !ok { - return status.Error(codes.Canceled, "the client connection is closing") - } - if err, ok := msg.(error); ok { - return err - } - *v = msg - return nil - case <-s.ctx.Done(): - } - if len(s.recvc) == 0 { - // prioritize any pending recv messages over canceled context - break - } - } - return s.ctx.Err() -} - -func newPipeStream(ctx context.Context, ssHandler func(chanServerStream) error) chanClientStream { - // ch1 is buffered so server can send error on close - ch1, ch2 := make(chan interface{}, 1), make(chan interface{}) - headerc, trailerc := make(chan metadata.MD, 1), make(chan metadata.MD, 1) - - cctx, ccancel := context.WithCancel(ctx) - cli := &chanStream{recvc: ch1, sendc: ch2, ctx: cctx, cancel: ccancel} - cs := chanClientStream{headerc, trailerc, cli} - - sctx, scancel := context.WithCancel(ctx) - srv := &chanStream{recvc: ch2, sendc: ch1, ctx: sctx, cancel: scancel} - ss := chanServerStream{headerc, trailerc, srv, nil} - - go func() { - if err := ssHandler(ss); err != nil { - select { - case srv.sendc <- err: - case <-sctx.Done(): - case <-cctx.Done(): - } - } - scancel() - ccancel() - }() - return cs -} diff --git a/vendor/go.etcd.io/etcd/server/v3/proxy/grpcproxy/adapter/cluster_client_adapter.go b/vendor/go.etcd.io/etcd/server/v3/proxy/grpcproxy/adapter/cluster_client_adapter.go deleted file mode 100644 index c1fff054de..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/proxy/grpcproxy/adapter/cluster_client_adapter.go +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package adapter - -import ( - "context" - - pb "go.etcd.io/etcd/api/v3/etcdserverpb" - - "google.golang.org/grpc" -) - -type cls2clc struct{ cls pb.ClusterServer } - -func ClusterServerToClusterClient(cls pb.ClusterServer) pb.ClusterClient { - return &cls2clc{cls} -} - -func (s *cls2clc) MemberList(ctx context.Context, r *pb.MemberListRequest, opts ...grpc.CallOption) (*pb.MemberListResponse, error) { - return s.cls.MemberList(ctx, r) -} - -func (s *cls2clc) MemberAdd(ctx context.Context, r *pb.MemberAddRequest, opts ...grpc.CallOption) (*pb.MemberAddResponse, error) { - return s.cls.MemberAdd(ctx, r) -} - -func (s *cls2clc) MemberUpdate(ctx context.Context, r *pb.MemberUpdateRequest, opts ...grpc.CallOption) (*pb.MemberUpdateResponse, error) { - return s.cls.MemberUpdate(ctx, r) -} - -func (s *cls2clc) MemberRemove(ctx context.Context, r *pb.MemberRemoveRequest, opts ...grpc.CallOption) (*pb.MemberRemoveResponse, error) { - return s.cls.MemberRemove(ctx, r) -} - -func (s *cls2clc) MemberPromote(ctx context.Context, r *pb.MemberPromoteRequest, opts ...grpc.CallOption) (*pb.MemberPromoteResponse, error) { - return s.cls.MemberPromote(ctx, r) -} diff --git a/vendor/go.etcd.io/etcd/server/v3/proxy/grpcproxy/adapter/doc.go b/vendor/go.etcd.io/etcd/server/v3/proxy/grpcproxy/adapter/doc.go deleted file mode 100644 index 7170be2330..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/proxy/grpcproxy/adapter/doc.go +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package adapter provides gRPC adapters between client and server -// gRPC interfaces without needing to go through a gRPC connection. -package adapter diff --git a/vendor/go.etcd.io/etcd/server/v3/proxy/grpcproxy/adapter/election_client_adapter.go b/vendor/go.etcd.io/etcd/server/v3/proxy/grpcproxy/adapter/election_client_adapter.go deleted file mode 100644 index 81d7434474..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/proxy/grpcproxy/adapter/election_client_adapter.go +++ /dev/null @@ -1,80 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package adapter - -import ( - "context" - - "go.etcd.io/etcd/server/v3/etcdserver/api/v3election/v3electionpb" - - "google.golang.org/grpc" -) - -type es2ec struct{ es v3electionpb.ElectionServer } - -func ElectionServerToElectionClient(es v3electionpb.ElectionServer) v3electionpb.ElectionClient { - return &es2ec{es} -} - -func (s *es2ec) Campaign(ctx context.Context, r *v3electionpb.CampaignRequest, opts ...grpc.CallOption) (*v3electionpb.CampaignResponse, error) { - return s.es.Campaign(ctx, r) -} - -func (s *es2ec) Proclaim(ctx context.Context, r *v3electionpb.ProclaimRequest, opts ...grpc.CallOption) (*v3electionpb.ProclaimResponse, error) { - return s.es.Proclaim(ctx, r) -} - -func (s *es2ec) Leader(ctx context.Context, r *v3electionpb.LeaderRequest, opts ...grpc.CallOption) (*v3electionpb.LeaderResponse, error) { - return s.es.Leader(ctx, r) -} - -func (s *es2ec) Resign(ctx context.Context, r *v3electionpb.ResignRequest, opts ...grpc.CallOption) (*v3electionpb.ResignResponse, error) { - return s.es.Resign(ctx, r) -} - -func (s *es2ec) Observe(ctx context.Context, in *v3electionpb.LeaderRequest, opts ...grpc.CallOption) (v3electionpb.Election_ObserveClient, error) { - cs := newPipeStream(ctx, func(ss chanServerStream) error { - return s.es.Observe(in, &es2ecServerStream{ss}) - }) - return &es2ecClientStream{cs}, nil -} - -// es2ecClientStream implements Election_ObserveClient -type es2ecClientStream struct{ chanClientStream } - -// es2ecServerStream implements Election_ObserveServer -type es2ecServerStream struct{ chanServerStream } - -func (s *es2ecClientStream) Send(rr *v3electionpb.LeaderRequest) error { - return s.SendMsg(rr) -} -func (s *es2ecClientStream) Recv() (*v3electionpb.LeaderResponse, error) { - var v interface{} - if err := s.RecvMsg(&v); err != nil { - return nil, err - } - return v.(*v3electionpb.LeaderResponse), nil -} - -func (s *es2ecServerStream) Send(rr *v3electionpb.LeaderResponse) error { - return s.SendMsg(rr) -} -func (s *es2ecServerStream) Recv() (*v3electionpb.LeaderRequest, error) { - var v interface{} - if err := s.RecvMsg(&v); err != nil { - return nil, err - } - return v.(*v3electionpb.LeaderRequest), nil -} diff --git a/vendor/go.etcd.io/etcd/server/v3/proxy/grpcproxy/adapter/kv_client_adapter.go b/vendor/go.etcd.io/etcd/server/v3/proxy/grpcproxy/adapter/kv_client_adapter.go deleted file mode 100644 index ddb6ada473..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/proxy/grpcproxy/adapter/kv_client_adapter.go +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package adapter - -import ( - "context" - - pb "go.etcd.io/etcd/api/v3/etcdserverpb" - - grpc "google.golang.org/grpc" -) - -type kvs2kvc struct{ kvs pb.KVServer } - -func KvServerToKvClient(kvs pb.KVServer) pb.KVClient { - return &kvs2kvc{kvs} -} - -func (s *kvs2kvc) Range(ctx context.Context, in *pb.RangeRequest, opts ...grpc.CallOption) (*pb.RangeResponse, error) { - return s.kvs.Range(ctx, in) -} - -func (s *kvs2kvc) Put(ctx context.Context, in *pb.PutRequest, opts ...grpc.CallOption) (*pb.PutResponse, error) { - return s.kvs.Put(ctx, in) -} - -func (s *kvs2kvc) DeleteRange(ctx context.Context, in *pb.DeleteRangeRequest, opts ...grpc.CallOption) (*pb.DeleteRangeResponse, error) { - return s.kvs.DeleteRange(ctx, in) -} - -func (s *kvs2kvc) Txn(ctx context.Context, in *pb.TxnRequest, opts ...grpc.CallOption) (*pb.TxnResponse, error) { - return s.kvs.Txn(ctx, in) -} - -func (s *kvs2kvc) Compact(ctx context.Context, in *pb.CompactionRequest, opts ...grpc.CallOption) (*pb.CompactionResponse, error) { - return s.kvs.Compact(ctx, in) -} diff --git a/vendor/go.etcd.io/etcd/server/v3/proxy/grpcproxy/adapter/lease_client_adapter.go b/vendor/go.etcd.io/etcd/server/v3/proxy/grpcproxy/adapter/lease_client_adapter.go deleted file mode 100644 index 6640d1d39e..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/proxy/grpcproxy/adapter/lease_client_adapter.go +++ /dev/null @@ -1,82 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package adapter - -import ( - "context" - - pb "go.etcd.io/etcd/api/v3/etcdserverpb" - - "google.golang.org/grpc" -) - -type ls2lc struct { - leaseServer pb.LeaseServer -} - -func LeaseServerToLeaseClient(ls pb.LeaseServer) pb.LeaseClient { - return &ls2lc{ls} -} - -func (c *ls2lc) LeaseGrant(ctx context.Context, in *pb.LeaseGrantRequest, opts ...grpc.CallOption) (*pb.LeaseGrantResponse, error) { - return c.leaseServer.LeaseGrant(ctx, in) -} - -func (c *ls2lc) LeaseRevoke(ctx context.Context, in *pb.LeaseRevokeRequest, opts ...grpc.CallOption) (*pb.LeaseRevokeResponse, error) { - return c.leaseServer.LeaseRevoke(ctx, in) -} - -func (c *ls2lc) LeaseKeepAlive(ctx context.Context, opts ...grpc.CallOption) (pb.Lease_LeaseKeepAliveClient, error) { - cs := newPipeStream(ctx, func(ss chanServerStream) error { - return c.leaseServer.LeaseKeepAlive(&ls2lcServerStream{ss}) - }) - return &ls2lcClientStream{cs}, nil -} - -func (c *ls2lc) LeaseTimeToLive(ctx context.Context, in *pb.LeaseTimeToLiveRequest, opts ...grpc.CallOption) (*pb.LeaseTimeToLiveResponse, error) { - return c.leaseServer.LeaseTimeToLive(ctx, in) -} - -func (c *ls2lc) LeaseLeases(ctx context.Context, in *pb.LeaseLeasesRequest, opts ...grpc.CallOption) (*pb.LeaseLeasesResponse, error) { - return c.leaseServer.LeaseLeases(ctx, in) -} - -// ls2lcClientStream implements Lease_LeaseKeepAliveClient -type ls2lcClientStream struct{ chanClientStream } - -// ls2lcServerStream implements Lease_LeaseKeepAliveServer -type ls2lcServerStream struct{ chanServerStream } - -func (s *ls2lcClientStream) Send(rr *pb.LeaseKeepAliveRequest) error { - return s.SendMsg(rr) -} -func (s *ls2lcClientStream) Recv() (*pb.LeaseKeepAliveResponse, error) { - var v interface{} - if err := s.RecvMsg(&v); err != nil { - return nil, err - } - return v.(*pb.LeaseKeepAliveResponse), nil -} - -func (s *ls2lcServerStream) Send(rr *pb.LeaseKeepAliveResponse) error { - return s.SendMsg(rr) -} -func (s *ls2lcServerStream) Recv() (*pb.LeaseKeepAliveRequest, error) { - var v interface{} - if err := s.RecvMsg(&v); err != nil { - return nil, err - } - return v.(*pb.LeaseKeepAliveRequest), nil -} diff --git a/vendor/go.etcd.io/etcd/server/v3/proxy/grpcproxy/adapter/lock_client_adapter.go b/vendor/go.etcd.io/etcd/server/v3/proxy/grpcproxy/adapter/lock_client_adapter.go deleted file mode 100644 index a3ceaf26da..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/proxy/grpcproxy/adapter/lock_client_adapter.go +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package adapter - -import ( - "context" - - "go.etcd.io/etcd/server/v3/etcdserver/api/v3lock/v3lockpb" - - "google.golang.org/grpc" -) - -type ls2lsc struct{ ls v3lockpb.LockServer } - -func LockServerToLockClient(ls v3lockpb.LockServer) v3lockpb.LockClient { - return &ls2lsc{ls} -} - -func (s *ls2lsc) Lock(ctx context.Context, r *v3lockpb.LockRequest, opts ...grpc.CallOption) (*v3lockpb.LockResponse, error) { - return s.ls.Lock(ctx, r) -} - -func (s *ls2lsc) Unlock(ctx context.Context, r *v3lockpb.UnlockRequest, opts ...grpc.CallOption) (*v3lockpb.UnlockResponse, error) { - return s.ls.Unlock(ctx, r) -} diff --git a/vendor/go.etcd.io/etcd/server/v3/proxy/grpcproxy/adapter/maintenance_client_adapter.go b/vendor/go.etcd.io/etcd/server/v3/proxy/grpcproxy/adapter/maintenance_client_adapter.go deleted file mode 100644 index 6369a16d8b..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/proxy/grpcproxy/adapter/maintenance_client_adapter.go +++ /dev/null @@ -1,92 +0,0 @@ -// Copyright 2017 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package adapter - -import ( - "context" - - pb "go.etcd.io/etcd/api/v3/etcdserverpb" - - "google.golang.org/grpc" -) - -type mts2mtc struct{ mts pb.MaintenanceServer } - -func MaintenanceServerToMaintenanceClient(mts pb.MaintenanceServer) pb.MaintenanceClient { - return &mts2mtc{mts} -} - -func (s *mts2mtc) Alarm(ctx context.Context, r *pb.AlarmRequest, opts ...grpc.CallOption) (*pb.AlarmResponse, error) { - return s.mts.Alarm(ctx, r) -} - -func (s *mts2mtc) Status(ctx context.Context, r *pb.StatusRequest, opts ...grpc.CallOption) (*pb.StatusResponse, error) { - return s.mts.Status(ctx, r) -} - -func (s *mts2mtc) Defragment(ctx context.Context, dr *pb.DefragmentRequest, opts ...grpc.CallOption) (*pb.DefragmentResponse, error) { - return s.mts.Defragment(ctx, dr) -} - -func (s *mts2mtc) Hash(ctx context.Context, r *pb.HashRequest, opts ...grpc.CallOption) (*pb.HashResponse, error) { - return s.mts.Hash(ctx, r) -} - -func (s *mts2mtc) HashKV(ctx context.Context, r *pb.HashKVRequest, opts ...grpc.CallOption) (*pb.HashKVResponse, error) { - return s.mts.HashKV(ctx, r) -} - -func (s *mts2mtc) MoveLeader(ctx context.Context, r *pb.MoveLeaderRequest, opts ...grpc.CallOption) (*pb.MoveLeaderResponse, error) { - return s.mts.MoveLeader(ctx, r) -} - -func (s *mts2mtc) Downgrade(ctx context.Context, r *pb.DowngradeRequest, opts ...grpc.CallOption) (*pb.DowngradeResponse, error) { - return s.mts.Downgrade(ctx, r) -} - -func (s *mts2mtc) Snapshot(ctx context.Context, in *pb.SnapshotRequest, opts ...grpc.CallOption) (pb.Maintenance_SnapshotClient, error) { - cs := newPipeStream(ctx, func(ss chanServerStream) error { - return s.mts.Snapshot(in, &ss2scServerStream{ss}) - }) - return &ss2scClientStream{cs}, nil -} - -// ss2scClientStream implements Maintenance_SnapshotClient -type ss2scClientStream struct{ chanClientStream } - -// ss2scServerStream implements Maintenance_SnapshotServer -type ss2scServerStream struct{ chanServerStream } - -func (s *ss2scClientStream) Send(rr *pb.SnapshotRequest) error { - return s.SendMsg(rr) -} -func (s *ss2scClientStream) Recv() (*pb.SnapshotResponse, error) { - var v interface{} - if err := s.RecvMsg(&v); err != nil { - return nil, err - } - return v.(*pb.SnapshotResponse), nil -} - -func (s *ss2scServerStream) Send(rr *pb.SnapshotResponse) error { - return s.SendMsg(rr) -} -func (s *ss2scServerStream) Recv() (*pb.SnapshotRequest, error) { - var v interface{} - if err := s.RecvMsg(&v); err != nil { - return nil, err - } - return v.(*pb.SnapshotRequest), nil -} diff --git a/vendor/go.etcd.io/etcd/server/v3/proxy/grpcproxy/adapter/watch_client_adapter.go b/vendor/go.etcd.io/etcd/server/v3/proxy/grpcproxy/adapter/watch_client_adapter.go deleted file mode 100644 index fbc09f6ff6..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/proxy/grpcproxy/adapter/watch_client_adapter.go +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package adapter - -import ( - "context" - "errors" - - pb "go.etcd.io/etcd/api/v3/etcdserverpb" - "google.golang.org/grpc" -) - -var errAlreadySentHeader = errors.New("adapter: already sent header") - -type ws2wc struct{ wserv pb.WatchServer } - -func WatchServerToWatchClient(wserv pb.WatchServer) pb.WatchClient { - return &ws2wc{wserv} -} - -func (s *ws2wc) Watch(ctx context.Context, opts ...grpc.CallOption) (pb.Watch_WatchClient, error) { - cs := newPipeStream(ctx, func(ss chanServerStream) error { - return s.wserv.Watch(&ws2wcServerStream{ss}) - }) - return &ws2wcClientStream{cs}, nil -} - -// ws2wcClientStream implements Watch_WatchClient -type ws2wcClientStream struct{ chanClientStream } - -// ws2wcServerStream implements Watch_WatchServer -type ws2wcServerStream struct{ chanServerStream } - -func (s *ws2wcClientStream) Send(wr *pb.WatchRequest) error { - return s.SendMsg(wr) -} -func (s *ws2wcClientStream) Recv() (*pb.WatchResponse, error) { - var v interface{} - if err := s.RecvMsg(&v); err != nil { - return nil, err - } - return v.(*pb.WatchResponse), nil -} - -func (s *ws2wcServerStream) Send(wr *pb.WatchResponse) error { - return s.SendMsg(wr) -} -func (s *ws2wcServerStream) Recv() (*pb.WatchRequest, error) { - var v interface{} - if err := s.RecvMsg(&v); err != nil { - return nil, err - } - return v.(*pb.WatchRequest), nil -} diff --git a/vendor/go.etcd.io/etcd/server/v3/verify/doc.go b/vendor/go.etcd.io/etcd/server/v3/verify/doc.go deleted file mode 100644 index 2c42bf6f19..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/verify/doc.go +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright 2021 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package verify - -// verify package is analyzing persistent state of etcd to find potential -// inconsistencies. -// In particular it covers cross-checking between different aspacts of etcd -// storage like WAL & Backend. diff --git a/vendor/go.etcd.io/etcd/server/v3/verify/verify.go b/vendor/go.etcd.io/etcd/server/v3/verify/verify.go deleted file mode 100644 index f727201ce8..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/verify/verify.go +++ /dev/null @@ -1,148 +0,0 @@ -// Copyright 2021 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package verify - -import ( - "fmt" - "os" - - "go.etcd.io/etcd/raft/v3/raftpb" - "go.etcd.io/etcd/server/v3/datadir" - "go.etcd.io/etcd/server/v3/etcdserver/cindex" - "go.etcd.io/etcd/server/v3/mvcc/backend" - wal2 "go.etcd.io/etcd/server/v3/wal" - "go.etcd.io/etcd/server/v3/wal/walpb" - "go.uber.org/zap" -) - -const ENV_VERIFY = "ETCD_VERIFY" -const ENV_VERIFY_ALL_VALUE = "all" - -type Config struct { - // DataDir is a root directory where the data being verified are stored. - DataDir string - - // ExactIndex requires consistent_index in backend exactly match the last committed WAL entry. - // Usually backend's consistent_index needs to be <= WAL.commit, but for backups the match - // is expected to be exact. - ExactIndex bool - - Logger *zap.Logger -} - -// Verify performs consistency checks of given etcd data-directory. -// The errors are reported as the returned error, but for some situations -// the function can also panic. -// The function is expected to work on not-in-use data model, i.e. -// no file-locks should be taken. Verify does not modified the data. -func Verify(cfg Config) error { - lg := cfg.Logger - if lg == nil { - lg = zap.NewNop() - } - - var err error - lg.Info("verification of persisted state", zap.String("data-dir", cfg.DataDir)) - defer func() { - if err != nil { - lg.Error("verification of persisted state failed", - zap.String("data-dir", cfg.DataDir), - zap.Error(err)) - } else if r := recover(); r != nil { - lg.Error("verification of persisted state failed", - zap.String("data-dir", cfg.DataDir)) - panic(r) - } else { - lg.Info("verification of persisted state successful", zap.String("data-dir", cfg.DataDir)) - } - }() - - beConfig := backend.DefaultBackendConfig() - beConfig.Path = datadir.ToBackendFileName(cfg.DataDir) - beConfig.Logger = cfg.Logger - - be := backend.New(beConfig) - defer be.Close() - - snapshot, hardstate, err := validateWal(cfg) - if err != nil { - return err - } - - // TODO: Perform validation of consistency of membership between - // backend/members & WAL confstate (and maybe storev2 if still exists). - - return validateConsistentIndex(cfg, hardstate, snapshot, be) -} - -// VerifyIfEnabled performs verification according to ETCD_VERIFY env settings. -// See Verify for more information. -func VerifyIfEnabled(cfg Config) error { - if os.Getenv(ENV_VERIFY) == ENV_VERIFY_ALL_VALUE { - return Verify(cfg) - } - return nil -} - -// MustVerifyIfEnabled performs verification according to ETCD_VERIFY env settings -// and exits in case of found problems. -// See Verify for more information. -func MustVerifyIfEnabled(cfg Config) { - if err := VerifyIfEnabled(cfg); err != nil { - cfg.Logger.Fatal("Verification failed", - zap.String("data-dir", cfg.DataDir), - zap.Error(err)) - } -} - -func validateConsistentIndex(cfg Config, hardstate *raftpb.HardState, snapshot *walpb.Snapshot, be backend.Backend) error { - tx := be.BatchTx() - index, term := cindex.ReadConsistentIndex(tx) - if cfg.ExactIndex && index != hardstate.Commit { - return fmt.Errorf("backend.ConsistentIndex (%v) expected == WAL.HardState.commit (%v)", index, hardstate.Commit) - } - if cfg.ExactIndex && term != hardstate.Term { - return fmt.Errorf("backend.Term (%v) expected == WAL.HardState.term, (%v)", term, hardstate.Term) - } - if index > hardstate.Commit { - return fmt.Errorf("backend.ConsistentIndex (%v) must be <= WAL.HardState.commit (%v)", index, hardstate.Commit) - } - if term > hardstate.Term { - return fmt.Errorf("backend.Term (%v) must be <= WAL.HardState.term, (%v)", term, hardstate.Term) - } - - if index < snapshot.Index { - return fmt.Errorf("backend.ConsistentIndex (%v) must be >= last snapshot index (%v)", index, snapshot.Index) - } - - cfg.Logger.Info("verification: consistentIndex OK", zap.Uint64("backend-consistent-index", index), zap.Uint64("hardstate-commit", hardstate.Commit)) - return nil -} - -func validateWal(cfg Config) (*walpb.Snapshot, *raftpb.HardState, error) { - walDir := datadir.ToWalDir(cfg.DataDir) - - walSnaps, err := wal2.ValidSnapshotEntries(cfg.Logger, walDir) - if err != nil { - return nil, nil, err - } - - snapshot := walSnaps[len(walSnaps)-1] - hardstate, err := wal2.Verify(cfg.Logger, walDir, snapshot) - if err != nil { - return nil, nil, err - } - return &snapshot, hardstate, nil -} diff --git a/vendor/go.etcd.io/etcd/server/v3/wal/decoder.go b/vendor/go.etcd.io/etcd/server/v3/wal/decoder.go deleted file mode 100644 index 0251a72133..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/wal/decoder.go +++ /dev/null @@ -1,196 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package wal - -import ( - "bufio" - "encoding/binary" - "hash" - "io" - "sync" - - "go.etcd.io/etcd/pkg/v3/crc" - "go.etcd.io/etcd/pkg/v3/pbutil" - "go.etcd.io/etcd/raft/v3/raftpb" - "go.etcd.io/etcd/server/v3/wal/walpb" -) - -const minSectorSize = 512 - -// frameSizeBytes is frame size in bytes, including record size and padding size. -const frameSizeBytes = 8 - -type decoder struct { - mu sync.Mutex - brs []*bufio.Reader - - // lastValidOff file offset following the last valid decoded record - lastValidOff int64 - crc hash.Hash32 -} - -func newDecoder(r ...io.Reader) *decoder { - readers := make([]*bufio.Reader, len(r)) - for i := range r { - readers[i] = bufio.NewReader(r[i]) - } - return &decoder{ - brs: readers, - crc: crc.New(0, crcTable), - } -} - -func (d *decoder) decode(rec *walpb.Record) error { - rec.Reset() - d.mu.Lock() - defer d.mu.Unlock() - return d.decodeRecord(rec) -} - -// raft max message size is set to 1 MB in etcd server -// assume projects set reasonable message size limit, -// thus entry size should never exceed 10 MB -const maxWALEntrySizeLimit = int64(10 * 1024 * 1024) - -func (d *decoder) decodeRecord(rec *walpb.Record) error { - if len(d.brs) == 0 { - return io.EOF - } - - l, err := readInt64(d.brs[0]) - if err == io.EOF || (err == nil && l == 0) { - // hit end of file or preallocated space - d.brs = d.brs[1:] - if len(d.brs) == 0 { - return io.EOF - } - d.lastValidOff = 0 - return d.decodeRecord(rec) - } - if err != nil { - return err - } - - recBytes, padBytes := decodeFrameSize(l) - if recBytes >= maxWALEntrySizeLimit-padBytes { - return ErrMaxWALEntrySizeLimitExceeded - } - - data := make([]byte, recBytes+padBytes) - if _, err = io.ReadFull(d.brs[0], data); err != nil { - // ReadFull returns io.EOF only if no bytes were read - // the decoder should treat this as an ErrUnexpectedEOF instead. - if err == io.EOF { - err = io.ErrUnexpectedEOF - } - return err - } - if err := rec.Unmarshal(data[:recBytes]); err != nil { - if d.isTornEntry(data) { - return io.ErrUnexpectedEOF - } - return err - } - - // skip crc checking if the record type is crcType - if rec.Type != crcType { - d.crc.Write(rec.Data) - if err := rec.Validate(d.crc.Sum32()); err != nil { - if d.isTornEntry(data) { - return io.ErrUnexpectedEOF - } - return err - } - } - // record decoded as valid; point last valid offset to end of record - d.lastValidOff += frameSizeBytes + recBytes + padBytes - return nil -} - -func decodeFrameSize(lenField int64) (recBytes int64, padBytes int64) { - // the record size is stored in the lower 56 bits of the 64-bit length - recBytes = int64(uint64(lenField) & ^(uint64(0xff) << 56)) - // non-zero padding is indicated by set MSb / a negative length - if lenField < 0 { - // padding is stored in lower 3 bits of length MSB - padBytes = int64((uint64(lenField) >> 56) & 0x7) - } - return recBytes, padBytes -} - -// isTornEntry determines whether the last entry of the WAL was partially written -// and corrupted because of a torn write. -func (d *decoder) isTornEntry(data []byte) bool { - if len(d.brs) != 1 { - return false - } - - fileOff := d.lastValidOff + frameSizeBytes - curOff := 0 - chunks := [][]byte{} - // split data on sector boundaries - for curOff < len(data) { - chunkLen := int(minSectorSize - (fileOff % minSectorSize)) - if chunkLen > len(data)-curOff { - chunkLen = len(data) - curOff - } - chunks = append(chunks, data[curOff:curOff+chunkLen]) - fileOff += int64(chunkLen) - curOff += chunkLen - } - - // if any data for a sector chunk is all 0, it's a torn write - for _, sect := range chunks { - isZero := true - for _, v := range sect { - if v != 0 { - isZero = false - break - } - } - if isZero { - return true - } - } - return false -} - -func (d *decoder) updateCRC(prevCrc uint32) { - d.crc = crc.New(prevCrc, crcTable) -} - -func (d *decoder) lastCRC() uint32 { - return d.crc.Sum32() -} - -func (d *decoder) lastOffset() int64 { return d.lastValidOff } - -func mustUnmarshalEntry(d []byte) raftpb.Entry { - var e raftpb.Entry - pbutil.MustUnmarshal(&e, d) - return e -} - -func mustUnmarshalState(d []byte) raftpb.HardState { - var s raftpb.HardState - pbutil.MustUnmarshal(&s, d) - return s -} - -func readInt64(r io.Reader) (int64, error) { - var n int64 - err := binary.Read(r, binary.LittleEndian, &n) - return n, err -} diff --git a/vendor/go.etcd.io/etcd/server/v3/wal/doc.go b/vendor/go.etcd.io/etcd/server/v3/wal/doc.go deleted file mode 100644 index 7ea348e4a9..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/wal/doc.go +++ /dev/null @@ -1,75 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/* -Package wal provides an implementation of a write ahead log that is used by -etcd. - -A WAL is created at a particular directory and is made up of a number of -segmented WAL files. Inside of each file the raft state and entries are appended -to it with the Save method: - - metadata := []byte{} - w, err := wal.Create(zap.NewExample(), "/var/lib/etcd", metadata) - ... - err := w.Save(s, ents) - -After saving a raft snapshot to disk, SaveSnapshot method should be called to -record it. So WAL can match with the saved snapshot when restarting. - - err := w.SaveSnapshot(walpb.Snapshot{Index: 10, Term: 2}) - -When a user has finished using a WAL it must be closed: - - w.Close() - -Each WAL file is a stream of WAL records. A WAL record is a length field and a wal record -protobuf. The record protobuf contains a CRC, a type, and a data payload. The length field is a -64-bit packed structure holding the length of the remaining logical record data in its lower -56 bits and its physical padding in the first three bits of the most significant byte. Each -record is 8-byte aligned so that the length field is never torn. The CRC contains the CRC32 -value of all record protobufs preceding the current record. - -WAL files are placed inside of the directory in the following format: -$seq-$index.wal - -The first WAL file to be created will be 0000000000000000-0000000000000000.wal -indicating an initial sequence of 0 and an initial raft index of 0. The first -entry written to WAL MUST have raft index 0. - -WAL will cut its current tail wal file if its size exceeds 64MB. This will increment an internal -sequence number and cause a new file to be created. If the last raft index saved -was 0x20 and this is the first time cut has been called on this WAL then the sequence will -increment from 0x0 to 0x1. The new file will be: 0000000000000001-0000000000000021.wal. -If a second cut issues 0x10 entries with incremental index later then the file will be called: -0000000000000002-0000000000000031.wal. - -At a later time a WAL can be opened at a particular snapshot. If there is no -snapshot, an empty snapshot should be passed in. - - w, err := wal.Open("/var/lib/etcd", walpb.Snapshot{Index: 10, Term: 2}) - ... - -The snapshot must have been written to the WAL. - -Additional items cannot be Saved to this WAL until all of the items from the given -snapshot to the end of the WAL are read first: - - metadata, state, ents, err := w.ReadAll() - -This will give you the metadata, the last raft.State and the slice of -raft.Entry items in the log. - -*/ -package wal diff --git a/vendor/go.etcd.io/etcd/server/v3/wal/encoder.go b/vendor/go.etcd.io/etcd/server/v3/wal/encoder.go deleted file mode 100644 index 61b4c20efb..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/wal/encoder.go +++ /dev/null @@ -1,124 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package wal - -import ( - "encoding/binary" - "hash" - "io" - "os" - "sync" - - "go.etcd.io/etcd/pkg/v3/crc" - "go.etcd.io/etcd/pkg/v3/ioutil" - "go.etcd.io/etcd/server/v3/wal/walpb" -) - -// walPageBytes is the alignment for flushing records to the backing Writer. -// It should be a multiple of the minimum sector size so that WAL can safely -// distinguish between torn writes and ordinary data corruption. -const walPageBytes = 8 * minSectorSize - -type encoder struct { - mu sync.Mutex - bw *ioutil.PageWriter - - crc hash.Hash32 - buf []byte - uint64buf []byte -} - -func newEncoder(w io.Writer, prevCrc uint32, pageOffset int) *encoder { - return &encoder{ - bw: ioutil.NewPageWriter(w, walPageBytes, pageOffset), - crc: crc.New(prevCrc, crcTable), - // 1MB buffer - buf: make([]byte, 1024*1024), - uint64buf: make([]byte, 8), - } -} - -// newFileEncoder creates a new encoder with current file offset for the page writer. -func newFileEncoder(f *os.File, prevCrc uint32) (*encoder, error) { - offset, err := f.Seek(0, io.SeekCurrent) - if err != nil { - return nil, err - } - return newEncoder(f, prevCrc, int(offset)), nil -} - -func (e *encoder) encode(rec *walpb.Record) error { - e.mu.Lock() - defer e.mu.Unlock() - - e.crc.Write(rec.Data) - rec.Crc = e.crc.Sum32() - var ( - data []byte - err error - n int - ) - - if rec.Size() > len(e.buf) { - data, err = rec.Marshal() - if err != nil { - return err - } - } else { - n, err = rec.MarshalTo(e.buf) - if err != nil { - return err - } - data = e.buf[:n] - } - - lenField, padBytes := encodeFrameSize(len(data)) - if err = writeUint64(e.bw, lenField, e.uint64buf); err != nil { - return err - } - - if padBytes != 0 { - data = append(data, make([]byte, padBytes)...) - } - n, err = e.bw.Write(data) - walWriteBytes.Add(float64(n)) - return err -} - -func encodeFrameSize(dataBytes int) (lenField uint64, padBytes int) { - lenField = uint64(dataBytes) - // force 8 byte alignment so length never gets a torn write - padBytes = (8 - (dataBytes % 8)) % 8 - if padBytes != 0 { - lenField |= uint64(0x80|padBytes) << 56 - } - return lenField, padBytes -} - -func (e *encoder) flush() error { - e.mu.Lock() - n, err := e.bw.FlushN() - e.mu.Unlock() - walWriteBytes.Add(float64(n)) - return err -} - -func writeUint64(w io.Writer, n uint64, buf []byte) error { - // http://golang.org/src/encoding/binary/binary.go - binary.LittleEndian.PutUint64(buf, n) - nv, err := w.Write(buf) - walWriteBytes.Add(float64(nv)) - return err -} diff --git a/vendor/go.etcd.io/etcd/server/v3/wal/file_pipeline.go b/vendor/go.etcd.io/etcd/server/v3/wal/file_pipeline.go deleted file mode 100644 index c2feba6c1d..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/wal/file_pipeline.go +++ /dev/null @@ -1,105 +0,0 @@ -// Copyright 2016 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package wal - -import ( - "fmt" - "os" - "path/filepath" - - "go.etcd.io/etcd/client/pkg/v3/fileutil" - - "go.uber.org/zap" -) - -// filePipeline pipelines allocating disk space -type filePipeline struct { - lg *zap.Logger - - // dir to put files - dir string - // size of files to make, in bytes - size int64 - // count number of files generated - count int - - filec chan *fileutil.LockedFile - errc chan error - donec chan struct{} -} - -func newFilePipeline(lg *zap.Logger, dir string, fileSize int64) *filePipeline { - if lg == nil { - lg = zap.NewNop() - } - fp := &filePipeline{ - lg: lg, - dir: dir, - size: fileSize, - filec: make(chan *fileutil.LockedFile), - errc: make(chan error, 1), - donec: make(chan struct{}), - } - go fp.run() - return fp -} - -// Open returns a fresh file for writing. Rename the file before calling -// Open again or there will be file collisions. -func (fp *filePipeline) Open() (f *fileutil.LockedFile, err error) { - select { - case f = <-fp.filec: - case err = <-fp.errc: - } - return f, err -} - -func (fp *filePipeline) Close() error { - close(fp.donec) - return <-fp.errc -} - -func (fp *filePipeline) alloc() (f *fileutil.LockedFile, err error) { - // count % 2 so this file isn't the same as the one last published - fpath := filepath.Join(fp.dir, fmt.Sprintf("%d.tmp", fp.count%2)) - if f, err = fileutil.LockFile(fpath, os.O_CREATE|os.O_WRONLY, fileutil.PrivateFileMode); err != nil { - return nil, err - } - if err = fileutil.Preallocate(f.File, fp.size, true); err != nil { - fp.lg.Error("failed to preallocate space when creating a new WAL", zap.Int64("size", fp.size), zap.Error(err)) - f.Close() - return nil, err - } - fp.count++ - return f, nil -} - -func (fp *filePipeline) run() { - defer close(fp.errc) - for { - f, err := fp.alloc() - if err != nil { - fp.errc <- err - return - } - select { - case fp.filec <- f: - case <-fp.donec: - os.Remove(f.Name()) - f.Close() - return - } - } -} diff --git a/vendor/go.etcd.io/etcd/server/v3/wal/metrics.go b/vendor/go.etcd.io/etcd/server/v3/wal/metrics.go deleted file mode 100644 index 814d654cdd..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/wal/metrics.go +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package wal - -import "github.com/prometheus/client_golang/prometheus" - -var ( - walFsyncSec = prometheus.NewHistogram(prometheus.HistogramOpts{ - Namespace: "etcd", - Subsystem: "disk", - Name: "wal_fsync_duration_seconds", - Help: "The latency distributions of fsync called by WAL.", - - // lowest bucket start of upper bound 0.001 sec (1 ms) with factor 2 - // highest bucket start of 0.001 sec * 2^13 == 8.192 sec - Buckets: prometheus.ExponentialBuckets(0.001, 2, 14), - }) - - walWriteBytes = prometheus.NewGauge(prometheus.GaugeOpts{ - Namespace: "etcd", - Subsystem: "disk", - Name: "wal_write_bytes_total", - Help: "Total number of bytes written in WAL.", - }) -) - -func init() { - prometheus.MustRegister(walFsyncSec) - prometheus.MustRegister(walWriteBytes) -} diff --git a/vendor/go.etcd.io/etcd/server/v3/wal/repair.go b/vendor/go.etcd.io/etcd/server/v3/wal/repair.go deleted file mode 100644 index 122ee49a6a..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/wal/repair.go +++ /dev/null @@ -1,114 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package wal - -import ( - "io" - "os" - "path/filepath" - "time" - - "go.etcd.io/etcd/client/pkg/v3/fileutil" - "go.etcd.io/etcd/server/v3/wal/walpb" - "go.uber.org/zap" -) - -// Repair tries to repair ErrUnexpectedEOF in the -// last wal file by truncating. -func Repair(lg *zap.Logger, dirpath string) bool { - if lg == nil { - lg = zap.NewNop() - } - f, err := openLast(lg, dirpath) - if err != nil { - return false - } - defer f.Close() - - lg.Info("repairing", zap.String("path", f.Name())) - - rec := &walpb.Record{} - decoder := newDecoder(f) - for { - lastOffset := decoder.lastOffset() - err := decoder.decode(rec) - switch err { - case nil: - // update crc of the decoder when necessary - switch rec.Type { - case crcType: - crc := decoder.crc.Sum32() - // current crc of decoder must match the crc of the record. - // do no need to match 0 crc, since the decoder is a new one at this case. - if crc != 0 && rec.Validate(crc) != nil { - return false - } - decoder.updateCRC(rec.Crc) - } - continue - - case io.EOF: - lg.Info("repaired", zap.String("path", f.Name()), zap.Error(io.EOF)) - return true - - case io.ErrUnexpectedEOF: - bf, bferr := os.Create(f.Name() + ".broken") - if bferr != nil { - lg.Warn("failed to create backup file", zap.String("path", f.Name()+".broken"), zap.Error(bferr)) - return false - } - defer bf.Close() - - if _, err = f.Seek(0, io.SeekStart); err != nil { - lg.Warn("failed to read file", zap.String("path", f.Name()), zap.Error(err)) - return false - } - - if _, err = io.Copy(bf, f); err != nil { - lg.Warn("failed to copy", zap.String("from", f.Name()+".broken"), zap.String("to", f.Name()), zap.Error(err)) - return false - } - - if err = f.Truncate(lastOffset); err != nil { - lg.Warn("failed to truncate", zap.String("path", f.Name()), zap.Error(err)) - return false - } - - start := time.Now() - if err = fileutil.Fsync(f.File); err != nil { - lg.Warn("failed to fsync", zap.String("path", f.Name()), zap.Error(err)) - return false - } - walFsyncSec.Observe(time.Since(start).Seconds()) - - lg.Info("repaired", zap.String("path", f.Name()), zap.Error(io.ErrUnexpectedEOF)) - return true - - default: - lg.Warn("failed to repair", zap.String("path", f.Name()), zap.Error(err)) - return false - } - } -} - -// openLast opens the last wal file for read and write. -func openLast(lg *zap.Logger, dirpath string) (*fileutil.LockedFile, error) { - names, err := readWALNames(lg, dirpath) - if err != nil { - return nil, err - } - last := filepath.Join(dirpath, names[len(names)-1]) - return fileutil.LockFile(last, os.O_RDWR, fileutil.PrivateFileMode) -} diff --git a/vendor/go.etcd.io/etcd/server/v3/wal/util.go b/vendor/go.etcd.io/etcd/server/v3/wal/util.go deleted file mode 100644 index 4a21ae6182..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/wal/util.go +++ /dev/null @@ -1,112 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package wal - -import ( - "errors" - "fmt" - "strings" - - "go.etcd.io/etcd/client/pkg/v3/fileutil" - - "go.uber.org/zap" -) - -var errBadWALName = errors.New("bad wal name") - -// Exist returns true if there are any files in a given directory. -func Exist(dir string) bool { - names, err := fileutil.ReadDir(dir, fileutil.WithExt(".wal")) - if err != nil { - return false - } - return len(names) != 0 -} - -// searchIndex returns the last array index of names whose raft index section is -// equal to or smaller than the given index. -// The given names MUST be sorted. -func searchIndex(lg *zap.Logger, names []string, index uint64) (int, bool) { - for i := len(names) - 1; i >= 0; i-- { - name := names[i] - _, curIndex, err := parseWALName(name) - if err != nil { - lg.Panic("failed to parse WAL file name", zap.String("path", name), zap.Error(err)) - } - if index >= curIndex { - return i, true - } - } - return -1, false -} - -// names should have been sorted based on sequence number. -// isValidSeq checks whether seq increases continuously. -func isValidSeq(lg *zap.Logger, names []string) bool { - var lastSeq uint64 - for _, name := range names { - curSeq, _, err := parseWALName(name) - if err != nil { - lg.Panic("failed to parse WAL file name", zap.String("path", name), zap.Error(err)) - } - if lastSeq != 0 && lastSeq != curSeq-1 { - return false - } - lastSeq = curSeq - } - return true -} - -func readWALNames(lg *zap.Logger, dirpath string) ([]string, error) { - names, err := fileutil.ReadDir(dirpath) - if err != nil { - return nil, err - } - wnames := checkWalNames(lg, names) - if len(wnames) == 0 { - return nil, ErrFileNotFound - } - return wnames, nil -} - -func checkWalNames(lg *zap.Logger, names []string) []string { - wnames := make([]string, 0) - for _, name := range names { - if _, _, err := parseWALName(name); err != nil { - // don't complain about left over tmp files - if !strings.HasSuffix(name, ".tmp") { - lg.Warn( - "ignored file in WAL directory", - zap.String("path", name), - ) - } - continue - } - wnames = append(wnames, name) - } - return wnames -} - -func parseWALName(str string) (seq, index uint64, err error) { - if !strings.HasSuffix(str, ".wal") { - return 0, 0, errBadWALName - } - _, err = fmt.Sscanf(str, "%016x-%016x.wal", &seq, &index) - return seq, index, err -} - -func walName(seq, index uint64) string { - return fmt.Sprintf("%016x-%016x.wal", seq, index) -} diff --git a/vendor/go.etcd.io/etcd/server/v3/wal/wal.go b/vendor/go.etcd.io/etcd/server/v3/wal/wal.go deleted file mode 100644 index 3c940e0cde..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/wal/wal.go +++ /dev/null @@ -1,1003 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package wal - -import ( - "bytes" - "errors" - "fmt" - "hash/crc32" - "io" - "os" - "path/filepath" - "strings" - "sync" - "time" - - "go.etcd.io/etcd/client/pkg/v3/fileutil" - "go.etcd.io/etcd/pkg/v3/pbutil" - "go.etcd.io/etcd/raft/v3" - "go.etcd.io/etcd/raft/v3/raftpb" - "go.etcd.io/etcd/server/v3/wal/walpb" - - "go.uber.org/zap" -) - -const ( - metadataType int64 = iota + 1 - entryType - stateType - crcType - snapshotType - - // warnSyncDuration is the amount of time allotted to an fsync before - // logging a warning - warnSyncDuration = time.Second -) - -var ( - // SegmentSizeBytes is the preallocated size of each wal segment file. - // The actual size might be larger than this. In general, the default - // value should be used, but this is defined as an exported variable - // so that tests can set a different segment size. - SegmentSizeBytes int64 = 64 * 1000 * 1000 // 64MB - - ErrMetadataConflict = errors.New("wal: conflicting metadata found") - ErrFileNotFound = errors.New("wal: file not found") - ErrCRCMismatch = errors.New("wal: crc mismatch") - ErrSnapshotMismatch = errors.New("wal: snapshot mismatch") - ErrSnapshotNotFound = errors.New("wal: snapshot not found") - ErrSliceOutOfRange = errors.New("wal: slice bounds out of range") - ErrMaxWALEntrySizeLimitExceeded = errors.New("wal: max entry size limit exceeded") - ErrDecoderNotFound = errors.New("wal: decoder not found") - crcTable = crc32.MakeTable(crc32.Castagnoli) -) - -// WAL is a logical representation of the stable storage. -// WAL is either in read mode or append mode but not both. -// A newly created WAL is in append mode, and ready for appending records. -// A just opened WAL is in read mode, and ready for reading records. -// The WAL will be ready for appending after reading out all the previous records. -type WAL struct { - lg *zap.Logger - - dir string // the living directory of the underlay files - - // dirFile is a fd for the wal directory for syncing on Rename - dirFile *os.File - - metadata []byte // metadata recorded at the head of each WAL - state raftpb.HardState // hardstate recorded at the head of WAL - - start walpb.Snapshot // snapshot to start reading - decoder *decoder // decoder to decode records - readClose func() error // closer for decode reader - - unsafeNoSync bool // if set, do not fsync - - mu sync.Mutex - enti uint64 // index of the last entry saved to the wal - encoder *encoder // encoder to encode records - - locks []*fileutil.LockedFile // the locked files the WAL holds (the name is increasing) - fp *filePipeline -} - -// Create creates a WAL ready for appending records. The given metadata is -// recorded at the head of each WAL file, and can be retrieved with ReadAll -// after the file is Open. -func Create(lg *zap.Logger, dirpath string, metadata []byte) (*WAL, error) { - if Exist(dirpath) { - return nil, os.ErrExist - } - - if lg == nil { - lg = zap.NewNop() - } - - // keep temporary wal directory so WAL initialization appears atomic - tmpdirpath := filepath.Clean(dirpath) + ".tmp" - if fileutil.Exist(tmpdirpath) { - if err := os.RemoveAll(tmpdirpath); err != nil { - return nil, err - } - } - defer os.RemoveAll(tmpdirpath) - - if err := fileutil.CreateDirAll(tmpdirpath); err != nil { - lg.Warn( - "failed to create a temporary WAL directory", - zap.String("tmp-dir-path", tmpdirpath), - zap.String("dir-path", dirpath), - zap.Error(err), - ) - return nil, err - } - - p := filepath.Join(tmpdirpath, walName(0, 0)) - f, err := fileutil.LockFile(p, os.O_WRONLY|os.O_CREATE, fileutil.PrivateFileMode) - if err != nil { - lg.Warn( - "failed to flock an initial WAL file", - zap.String("path", p), - zap.Error(err), - ) - return nil, err - } - if _, err = f.Seek(0, io.SeekEnd); err != nil { - lg.Warn( - "failed to seek an initial WAL file", - zap.String("path", p), - zap.Error(err), - ) - return nil, err - } - if err = fileutil.Preallocate(f.File, SegmentSizeBytes, true); err != nil { - lg.Warn( - "failed to preallocate an initial WAL file", - zap.String("path", p), - zap.Int64("segment-bytes", SegmentSizeBytes), - zap.Error(err), - ) - return nil, err - } - - w := &WAL{ - lg: lg, - dir: dirpath, - metadata: metadata, - } - w.encoder, err = newFileEncoder(f.File, 0) - if err != nil { - return nil, err - } - w.locks = append(w.locks, f) - if err = w.saveCrc(0); err != nil { - return nil, err - } - if err = w.encoder.encode(&walpb.Record{Type: metadataType, Data: metadata}); err != nil { - return nil, err - } - if err = w.SaveSnapshot(walpb.Snapshot{}); err != nil { - return nil, err - } - - logDirPath := w.dir - if w, err = w.renameWAL(tmpdirpath); err != nil { - lg.Warn( - "failed to rename the temporary WAL directory", - zap.String("tmp-dir-path", tmpdirpath), - zap.String("dir-path", logDirPath), - zap.Error(err), - ) - return nil, err - } - - var perr error - defer func() { - if perr != nil { - w.cleanupWAL(lg) - } - }() - - // directory was renamed; sync parent dir to persist rename - pdir, perr := fileutil.OpenDir(filepath.Dir(w.dir)) - if perr != nil { - lg.Warn( - "failed to open the parent data directory", - zap.String("parent-dir-path", filepath.Dir(w.dir)), - zap.String("dir-path", w.dir), - zap.Error(perr), - ) - return nil, perr - } - dirCloser := func() error { - if perr = pdir.Close(); perr != nil { - lg.Warn( - "failed to close the parent data directory file", - zap.String("parent-dir-path", filepath.Dir(w.dir)), - zap.String("dir-path", w.dir), - zap.Error(perr), - ) - return perr - } - return nil - } - start := time.Now() - if perr = fileutil.Fsync(pdir); perr != nil { - dirCloser() - lg.Warn( - "failed to fsync the parent data directory file", - zap.String("parent-dir-path", filepath.Dir(w.dir)), - zap.String("dir-path", w.dir), - zap.Error(perr), - ) - return nil, perr - } - walFsyncSec.Observe(time.Since(start).Seconds()) - if err = dirCloser(); err != nil { - return nil, err - } - - return w, nil -} - -func (w *WAL) SetUnsafeNoFsync() { - w.unsafeNoSync = true -} - -func (w *WAL) cleanupWAL(lg *zap.Logger) { - var err error - if err = w.Close(); err != nil { - lg.Panic("failed to close WAL during cleanup", zap.Error(err)) - } - brokenDirName := fmt.Sprintf("%s.broken.%v", w.dir, time.Now().Format("20060102.150405.999999")) - if err = os.Rename(w.dir, brokenDirName); err != nil { - lg.Panic( - "failed to rename WAL during cleanup", - zap.Error(err), - zap.String("source-path", w.dir), - zap.String("rename-path", brokenDirName), - ) - } -} - -func (w *WAL) renameWAL(tmpdirpath string) (*WAL, error) { - if err := os.RemoveAll(w.dir); err != nil { - return nil, err - } - // On non-Windows platforms, hold the lock while renaming. Releasing - // the lock and trying to reacquire it quickly can be flaky because - // it's possible the process will fork to spawn a process while this is - // happening. The fds are set up as close-on-exec by the Go runtime, - // but there is a window between the fork and the exec where another - // process holds the lock. - if err := os.Rename(tmpdirpath, w.dir); err != nil { - if _, ok := err.(*os.LinkError); ok { - return w.renameWALUnlock(tmpdirpath) - } - return nil, err - } - w.fp = newFilePipeline(w.lg, w.dir, SegmentSizeBytes) - df, err := fileutil.OpenDir(w.dir) - w.dirFile = df - return w, err -} - -func (w *WAL) renameWALUnlock(tmpdirpath string) (*WAL, error) { - // rename of directory with locked files doesn't work on windows/cifs; - // close the WAL to release the locks so the directory can be renamed. - w.lg.Info( - "closing WAL to release flock and retry directory renaming", - zap.String("from", tmpdirpath), - zap.String("to", w.dir), - ) - w.Close() - - if err := os.Rename(tmpdirpath, w.dir); err != nil { - return nil, err - } - - // reopen and relock - newWAL, oerr := Open(w.lg, w.dir, walpb.Snapshot{}) - if oerr != nil { - return nil, oerr - } - if _, _, _, err := newWAL.ReadAll(); err != nil { - newWAL.Close() - return nil, err - } - return newWAL, nil -} - -// Open opens the WAL at the given snap. -// The snap SHOULD have been previously saved to the WAL, or the following -// ReadAll will fail. -// The returned WAL is ready to read and the first record will be the one after -// the given snap. The WAL cannot be appended to before reading out all of its -// previous records. -func Open(lg *zap.Logger, dirpath string, snap walpb.Snapshot) (*WAL, error) { - w, err := openAtIndex(lg, dirpath, snap, true) - if err != nil { - return nil, err - } - if w.dirFile, err = fileutil.OpenDir(w.dir); err != nil { - return nil, err - } - return w, nil -} - -// OpenForRead only opens the wal files for read. -// Write on a read only wal panics. -func OpenForRead(lg *zap.Logger, dirpath string, snap walpb.Snapshot) (*WAL, error) { - return openAtIndex(lg, dirpath, snap, false) -} - -func openAtIndex(lg *zap.Logger, dirpath string, snap walpb.Snapshot, write bool) (*WAL, error) { - if lg == nil { - lg = zap.NewNop() - } - names, nameIndex, err := selectWALFiles(lg, dirpath, snap) - if err != nil { - return nil, err - } - - rs, ls, closer, err := openWALFiles(lg, dirpath, names, nameIndex, write) - if err != nil { - return nil, err - } - - // create a WAL ready for reading - w := &WAL{ - lg: lg, - dir: dirpath, - start: snap, - decoder: newDecoder(rs...), - readClose: closer, - locks: ls, - } - - if write { - // write reuses the file descriptors from read; don't close so - // WAL can append without dropping the file lock - w.readClose = nil - if _, _, err := parseWALName(filepath.Base(w.tail().Name())); err != nil { - closer() - return nil, err - } - w.fp = newFilePipeline(lg, w.dir, SegmentSizeBytes) - } - - return w, nil -} - -func selectWALFiles(lg *zap.Logger, dirpath string, snap walpb.Snapshot) ([]string, int, error) { - names, err := readWALNames(lg, dirpath) - if err != nil { - return nil, -1, err - } - - nameIndex, ok := searchIndex(lg, names, snap.Index) - if !ok || !isValidSeq(lg, names[nameIndex:]) { - err = ErrFileNotFound - return nil, -1, err - } - - return names, nameIndex, nil -} - -func openWALFiles(lg *zap.Logger, dirpath string, names []string, nameIndex int, write bool) ([]io.Reader, []*fileutil.LockedFile, func() error, error) { - rcs := make([]io.ReadCloser, 0) - rs := make([]io.Reader, 0) - ls := make([]*fileutil.LockedFile, 0) - for _, name := range names[nameIndex:] { - p := filepath.Join(dirpath, name) - if write { - l, err := fileutil.TryLockFile(p, os.O_RDWR, fileutil.PrivateFileMode) - if err != nil { - closeAll(lg, rcs...) - return nil, nil, nil, err - } - ls = append(ls, l) - rcs = append(rcs, l) - } else { - rf, err := os.OpenFile(p, os.O_RDONLY, fileutil.PrivateFileMode) - if err != nil { - closeAll(lg, rcs...) - return nil, nil, nil, err - } - ls = append(ls, nil) - rcs = append(rcs, rf) - } - rs = append(rs, rcs[len(rcs)-1]) - } - - closer := func() error { return closeAll(lg, rcs...) } - - return rs, ls, closer, nil -} - -// ReadAll reads out records of the current WAL. -// If opened in write mode, it must read out all records until EOF. Or an error -// will be returned. -// If opened in read mode, it will try to read all records if possible. -// If it cannot read out the expected snap, it will return ErrSnapshotNotFound. -// If loaded snap doesn't match with the expected one, it will return -// all the records and error ErrSnapshotMismatch. -// TODO: detect not-last-snap error. -// TODO: maybe loose the checking of match. -// After ReadAll, the WAL will be ready for appending new records. -// -// ReadAll suppresses WAL entries that got overridden (i.e. a newer entry with the same index -// exists in the log). Such a situation can happen in cases described in figure 7. of the -// RAFT paper (http://web.stanford.edu/~ouster/cgi-bin/papers/raft-atc14.pdf). -// -// ReadAll may return uncommitted yet entries, that are subject to be overriden. -// Do not apply entries that have index > state.commit, as they are subject to change. -func (w *WAL) ReadAll() (metadata []byte, state raftpb.HardState, ents []raftpb.Entry, err error) { - w.mu.Lock() - defer w.mu.Unlock() - - rec := &walpb.Record{} - - if w.decoder == nil { - return nil, state, nil, ErrDecoderNotFound - } - decoder := w.decoder - - var match bool - for err = decoder.decode(rec); err == nil; err = decoder.decode(rec) { - switch rec.Type { - case entryType: - e := mustUnmarshalEntry(rec.Data) - // 0 <= e.Index-w.start.Index - 1 < len(ents) - if e.Index > w.start.Index { - // prevent "panic: runtime error: slice bounds out of range [:13038096702221461992] with capacity 0" - up := e.Index - w.start.Index - 1 - if up > uint64(len(ents)) { - // return error before append call causes runtime panic - return nil, state, nil, ErrSliceOutOfRange - } - // The line below is potentially overriding some 'uncommitted' entries. - ents = append(ents[:up], e) - } - w.enti = e.Index - - case stateType: - state = mustUnmarshalState(rec.Data) - - case metadataType: - if metadata != nil && !bytes.Equal(metadata, rec.Data) { - state.Reset() - return nil, state, nil, ErrMetadataConflict - } - metadata = rec.Data - - case crcType: - crc := decoder.crc.Sum32() - // current crc of decoder must match the crc of the record. - // do no need to match 0 crc, since the decoder is a new one at this case. - if crc != 0 && rec.Validate(crc) != nil { - state.Reset() - return nil, state, nil, ErrCRCMismatch - } - decoder.updateCRC(rec.Crc) - - case snapshotType: - var snap walpb.Snapshot - pbutil.MustUnmarshal(&snap, rec.Data) - if snap.Index == w.start.Index { - if snap.Term != w.start.Term { - state.Reset() - return nil, state, nil, ErrSnapshotMismatch - } - match = true - } - - default: - state.Reset() - return nil, state, nil, fmt.Errorf("unexpected block type %d", rec.Type) - } - } - - switch w.tail() { - case nil: - // We do not have to read out all entries in read mode. - // The last record maybe a partial written one, so - // ErrunexpectedEOF might be returned. - if err != io.EOF && err != io.ErrUnexpectedEOF { - state.Reset() - return nil, state, nil, err - } - default: - // We must read all of the entries if WAL is opened in write mode. - if err != io.EOF { - state.Reset() - return nil, state, nil, err - } - // decodeRecord() will return io.EOF if it detects a zero record, - // but this zero record may be followed by non-zero records from - // a torn write. Overwriting some of these non-zero records, but - // not all, will cause CRC errors on WAL open. Since the records - // were never fully synced to disk in the first place, it's safe - // to zero them out to avoid any CRC errors from new writes. - if _, err = w.tail().Seek(w.decoder.lastOffset(), io.SeekStart); err != nil { - return nil, state, nil, err - } - if err = fileutil.ZeroToEnd(w.tail().File); err != nil { - return nil, state, nil, err - } - } - - err = nil - if !match { - err = ErrSnapshotNotFound - } - - // close decoder, disable reading - if w.readClose != nil { - w.readClose() - w.readClose = nil - } - w.start = walpb.Snapshot{} - - w.metadata = metadata - - if w.tail() != nil { - // create encoder (chain crc with the decoder), enable appending - w.encoder, err = newFileEncoder(w.tail().File, w.decoder.lastCRC()) - if err != nil { - return - } - } - w.decoder = nil - - return metadata, state, ents, err -} - -// ValidSnapshotEntries returns all the valid snapshot entries in the wal logs in the given directory. -// Snapshot entries are valid if their index is less than or equal to the most recent committed hardstate. -func ValidSnapshotEntries(lg *zap.Logger, walDir string) ([]walpb.Snapshot, error) { - var snaps []walpb.Snapshot - var state raftpb.HardState - var err error - - rec := &walpb.Record{} - names, err := readWALNames(lg, walDir) - if err != nil { - return nil, err - } - - // open wal files in read mode, so that there is no conflict - // when the same WAL is opened elsewhere in write mode - rs, _, closer, err := openWALFiles(lg, walDir, names, 0, false) - if err != nil { - return nil, err - } - defer func() { - if closer != nil { - closer() - } - }() - - // create a new decoder from the readers on the WAL files - decoder := newDecoder(rs...) - - for err = decoder.decode(rec); err == nil; err = decoder.decode(rec) { - switch rec.Type { - case snapshotType: - var loadedSnap walpb.Snapshot - pbutil.MustUnmarshal(&loadedSnap, rec.Data) - snaps = append(snaps, loadedSnap) - case stateType: - state = mustUnmarshalState(rec.Data) - case crcType: - crc := decoder.crc.Sum32() - // current crc of decoder must match the crc of the record. - // do no need to match 0 crc, since the decoder is a new one at this case. - if crc != 0 && rec.Validate(crc) != nil { - return nil, ErrCRCMismatch - } - decoder.updateCRC(rec.Crc) - } - } - // We do not have to read out all the WAL entries - // as the decoder is opened in read mode. - if err != io.EOF && err != io.ErrUnexpectedEOF { - return nil, err - } - - // filter out any snaps that are newer than the committed hardstate - n := 0 - for _, s := range snaps { - if s.Index <= state.Commit { - snaps[n] = s - n++ - } - } - snaps = snaps[:n:n] - return snaps, nil -} - -// Verify reads through the given WAL and verifies that it is not corrupted. -// It creates a new decoder to read through the records of the given WAL. -// It does not conflict with any open WAL, but it is recommended not to -// call this function after opening the WAL for writing. -// If it cannot read out the expected snap, it will return ErrSnapshotNotFound. -// If the loaded snap doesn't match with the expected one, it will -// return error ErrSnapshotMismatch. -func Verify(lg *zap.Logger, walDir string, snap walpb.Snapshot) (*raftpb.HardState, error) { - var metadata []byte - var err error - var match bool - var state raftpb.HardState - - rec := &walpb.Record{} - - if lg == nil { - lg = zap.NewNop() - } - names, nameIndex, err := selectWALFiles(lg, walDir, snap) - if err != nil { - return nil, err - } - - // open wal files in read mode, so that there is no conflict - // when the same WAL is opened elsewhere in write mode - rs, _, closer, err := openWALFiles(lg, walDir, names, nameIndex, false) - if err != nil { - return nil, err - } - defer func() { - if closer != nil { - closer() - } - }() - - // create a new decoder from the readers on the WAL files - decoder := newDecoder(rs...) - - for err = decoder.decode(rec); err == nil; err = decoder.decode(rec) { - switch rec.Type { - case metadataType: - if metadata != nil && !bytes.Equal(metadata, rec.Data) { - return nil, ErrMetadataConflict - } - metadata = rec.Data - case crcType: - crc := decoder.crc.Sum32() - // Current crc of decoder must match the crc of the record. - // We need not match 0 crc, since the decoder is a new one at this point. - if crc != 0 && rec.Validate(crc) != nil { - return nil, ErrCRCMismatch - } - decoder.updateCRC(rec.Crc) - case snapshotType: - var loadedSnap walpb.Snapshot - pbutil.MustUnmarshal(&loadedSnap, rec.Data) - if loadedSnap.Index == snap.Index { - if loadedSnap.Term != snap.Term { - return nil, ErrSnapshotMismatch - } - match = true - } - // We ignore all entry and state type records as these - // are not necessary for validating the WAL contents - case entryType: - case stateType: - pbutil.MustUnmarshal(&state, rec.Data) - default: - return nil, fmt.Errorf("unexpected block type %d", rec.Type) - } - } - - // We do not have to read out all the WAL entries - // as the decoder is opened in read mode. - if err != io.EOF && err != io.ErrUnexpectedEOF { - return nil, err - } - - if !match { - return nil, ErrSnapshotNotFound - } - - return &state, nil -} - -// cut closes current file written and creates a new one ready to append. -// cut first creates a temp wal file and writes necessary headers into it. -// Then cut atomically rename temp wal file to a wal file. -func (w *WAL) cut() error { - // close old wal file; truncate to avoid wasting space if an early cut - off, serr := w.tail().Seek(0, io.SeekCurrent) - if serr != nil { - return serr - } - - if err := w.tail().Truncate(off); err != nil { - return err - } - - if err := w.sync(); err != nil { - return err - } - - fpath := filepath.Join(w.dir, walName(w.seq()+1, w.enti+1)) - - // create a temp wal file with name sequence + 1, or truncate the existing one - newTail, err := w.fp.Open() - if err != nil { - return err - } - - // update writer and save the previous crc - w.locks = append(w.locks, newTail) - prevCrc := w.encoder.crc.Sum32() - w.encoder, err = newFileEncoder(w.tail().File, prevCrc) - if err != nil { - return err - } - - if err = w.saveCrc(prevCrc); err != nil { - return err - } - - if err = w.encoder.encode(&walpb.Record{Type: metadataType, Data: w.metadata}); err != nil { - return err - } - - if err = w.saveState(&w.state); err != nil { - return err - } - - // atomically move temp wal file to wal file - if err = w.sync(); err != nil { - return err - } - - off, err = w.tail().Seek(0, io.SeekCurrent) - if err != nil { - return err - } - - if err = os.Rename(newTail.Name(), fpath); err != nil { - return err - } - start := time.Now() - if err = fileutil.Fsync(w.dirFile); err != nil { - return err - } - walFsyncSec.Observe(time.Since(start).Seconds()) - - // reopen newTail with its new path so calls to Name() match the wal filename format - newTail.Close() - - if newTail, err = fileutil.LockFile(fpath, os.O_WRONLY, fileutil.PrivateFileMode); err != nil { - return err - } - if _, err = newTail.Seek(off, io.SeekStart); err != nil { - return err - } - - w.locks[len(w.locks)-1] = newTail - - prevCrc = w.encoder.crc.Sum32() - w.encoder, err = newFileEncoder(w.tail().File, prevCrc) - if err != nil { - return err - } - - w.lg.Info("created a new WAL segment", zap.String("path", fpath)) - return nil -} - -func (w *WAL) sync() error { - if w.encoder != nil { - if err := w.encoder.flush(); err != nil { - return err - } - } - - if w.unsafeNoSync { - return nil - } - - start := time.Now() - err := fileutil.Fdatasync(w.tail().File) - - took := time.Since(start) - if took > warnSyncDuration { - w.lg.Warn( - "slow fdatasync", - zap.Duration("took", took), - zap.Duration("expected-duration", warnSyncDuration), - ) - } - walFsyncSec.Observe(took.Seconds()) - - return err -} - -func (w *WAL) Sync() error { - return w.sync() -} - -// ReleaseLockTo releases the locks, which has smaller index than the given index -// except the largest one among them. -// For example, if WAL is holding lock 1,2,3,4,5,6, ReleaseLockTo(4) will release -// lock 1,2 but keep 3. ReleaseLockTo(5) will release 1,2,3 but keep 4. -func (w *WAL) ReleaseLockTo(index uint64) error { - w.mu.Lock() - defer w.mu.Unlock() - - if len(w.locks) == 0 { - return nil - } - - var smaller int - found := false - for i, l := range w.locks { - _, lockIndex, err := parseWALName(filepath.Base(l.Name())) - if err != nil { - return err - } - if lockIndex >= index { - smaller = i - 1 - found = true - break - } - } - - // if no lock index is greater than the release index, we can - // release lock up to the last one(excluding). - if !found { - smaller = len(w.locks) - 1 - } - - if smaller <= 0 { - return nil - } - - for i := 0; i < smaller; i++ { - if w.locks[i] == nil { - continue - } - w.locks[i].Close() - } - w.locks = w.locks[smaller:] - - return nil -} - -// Close closes the current WAL file and directory. -func (w *WAL) Close() error { - w.mu.Lock() - defer w.mu.Unlock() - - if w.fp != nil { - w.fp.Close() - w.fp = nil - } - - if w.tail() != nil { - if err := w.sync(); err != nil { - return err - } - } - for _, l := range w.locks { - if l == nil { - continue - } - if err := l.Close(); err != nil { - w.lg.Error("failed to close WAL", zap.Error(err)) - } - } - - return w.dirFile.Close() -} - -func (w *WAL) saveEntry(e *raftpb.Entry) error { - // TODO: add MustMarshalTo to reduce one allocation. - b := pbutil.MustMarshal(e) - rec := &walpb.Record{Type: entryType, Data: b} - if err := w.encoder.encode(rec); err != nil { - return err - } - w.enti = e.Index - return nil -} - -func (w *WAL) saveState(s *raftpb.HardState) error { - if raft.IsEmptyHardState(*s) { - return nil - } - w.state = *s - b := pbutil.MustMarshal(s) - rec := &walpb.Record{Type: stateType, Data: b} - return w.encoder.encode(rec) -} - -func (w *WAL) Save(st raftpb.HardState, ents []raftpb.Entry) error { - w.mu.Lock() - defer w.mu.Unlock() - - // short cut, do not call sync - if raft.IsEmptyHardState(st) && len(ents) == 0 { - return nil - } - - mustSync := raft.MustSync(st, w.state, len(ents)) - - // TODO(xiangli): no more reference operator - for i := range ents { - if err := w.saveEntry(&ents[i]); err != nil { - return err - } - } - if err := w.saveState(&st); err != nil { - return err - } - - curOff, err := w.tail().Seek(0, io.SeekCurrent) - if err != nil { - return err - } - if curOff < SegmentSizeBytes { - if mustSync { - return w.sync() - } - return nil - } - - return w.cut() -} - -func (w *WAL) SaveSnapshot(e walpb.Snapshot) error { - if err := walpb.ValidateSnapshotForWrite(&e); err != nil { - return err - } - - b := pbutil.MustMarshal(&e) - - w.mu.Lock() - defer w.mu.Unlock() - - rec := &walpb.Record{Type: snapshotType, Data: b} - if err := w.encoder.encode(rec); err != nil { - return err - } - // update enti only when snapshot is ahead of last index - if w.enti < e.Index { - w.enti = e.Index - } - return w.sync() -} - -func (w *WAL) saveCrc(prevCrc uint32) error { - return w.encoder.encode(&walpb.Record{Type: crcType, Crc: prevCrc}) -} - -func (w *WAL) tail() *fileutil.LockedFile { - if len(w.locks) > 0 { - return w.locks[len(w.locks)-1] - } - return nil -} - -func (w *WAL) seq() uint64 { - t := w.tail() - if t == nil { - return 0 - } - seq, _, err := parseWALName(filepath.Base(t.Name())) - if err != nil { - w.lg.Fatal("failed to parse WAL name", zap.String("name", t.Name()), zap.Error(err)) - } - return seq -} - -func closeAll(lg *zap.Logger, rcs ...io.ReadCloser) error { - stringArr := make([]string, 0) - for _, f := range rcs { - if err := f.Close(); err != nil { - lg.Warn("failed to close: ", zap.Error(err)) - stringArr = append(stringArr, err.Error()) - } - } - if len(stringArr) == 0 { - return nil - } - return errors.New(strings.Join(stringArr, ", ")) -} diff --git a/vendor/go.etcd.io/etcd/server/v3/wal/walpb/record.go b/vendor/go.etcd.io/etcd/server/v3/wal/walpb/record.go deleted file mode 100644 index e2070fbba3..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/wal/walpb/record.go +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright 2015 The etcd Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package walpb - -import "errors" - -var ( - ErrCRCMismatch = errors.New("walpb: crc mismatch") -) - -func (rec *Record) Validate(crc uint32) error { - if rec.Crc == crc { - return nil - } - rec.Reset() - return ErrCRCMismatch -} - -// ValidateSnapshotForWrite ensures the Snapshot the newly written snapshot is valid. -// -// There might exist log-entries written by old etcd versions that does not conform -// to the requirements. -func ValidateSnapshotForWrite(e *Snapshot) error { - // Since etcd>=3.5.0 - if e.ConfState == nil && e.Index > 0 { - return errors.New("Saved (not-initial) snapshot is missing ConfState: " + e.String()) - } - return nil -} diff --git a/vendor/go.etcd.io/etcd/server/v3/wal/walpb/record.pb.go b/vendor/go.etcd.io/etcd/server/v3/wal/walpb/record.pb.go deleted file mode 100644 index 654d82636c..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/wal/walpb/record.pb.go +++ /dev/null @@ -1,609 +0,0 @@ -// Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: record.proto - -package walpb - -import ( - fmt "fmt" - io "io" - math "math" - math_bits "math/bits" - - _ "github.com/gogo/protobuf/gogoproto" - proto "github.com/golang/protobuf/proto" - raftpb "go.etcd.io/etcd/raft/v3/raftpb" -) - -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package - -type Record struct { - Type int64 `protobuf:"varint,1,opt,name=type" json:"type"` - Crc uint32 `protobuf:"varint,2,opt,name=crc" json:"crc"` - Data []byte `protobuf:"bytes,3,opt,name=data" json:"data,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *Record) Reset() { *m = Record{} } -func (m *Record) String() string { return proto.CompactTextString(m) } -func (*Record) ProtoMessage() {} -func (*Record) Descriptor() ([]byte, []int) { - return fileDescriptor_bf94fd919e302a1d, []int{0} -} -func (m *Record) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *Record) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_Record.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *Record) XXX_Merge(src proto.Message) { - xxx_messageInfo_Record.Merge(m, src) -} -func (m *Record) XXX_Size() int { - return m.Size() -} -func (m *Record) XXX_DiscardUnknown() { - xxx_messageInfo_Record.DiscardUnknown(m) -} - -var xxx_messageInfo_Record proto.InternalMessageInfo - -// Keep in sync with raftpb.SnapshotMetadata. -type Snapshot struct { - Index uint64 `protobuf:"varint,1,opt,name=index" json:"index"` - Term uint64 `protobuf:"varint,2,opt,name=term" json:"term"` - // Field populated since >=etcd-3.5.0. - ConfState *raftpb.ConfState `protobuf:"bytes,3,opt,name=conf_state,json=confState" json:"conf_state,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *Snapshot) Reset() { *m = Snapshot{} } -func (m *Snapshot) String() string { return proto.CompactTextString(m) } -func (*Snapshot) ProtoMessage() {} -func (*Snapshot) Descriptor() ([]byte, []int) { - return fileDescriptor_bf94fd919e302a1d, []int{1} -} -func (m *Snapshot) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *Snapshot) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_Snapshot.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *Snapshot) XXX_Merge(src proto.Message) { - xxx_messageInfo_Snapshot.Merge(m, src) -} -func (m *Snapshot) XXX_Size() int { - return m.Size() -} -func (m *Snapshot) XXX_DiscardUnknown() { - xxx_messageInfo_Snapshot.DiscardUnknown(m) -} - -var xxx_messageInfo_Snapshot proto.InternalMessageInfo - -func init() { - proto.RegisterType((*Record)(nil), "walpb.Record") - proto.RegisterType((*Snapshot)(nil), "walpb.Snapshot") -} - -func init() { proto.RegisterFile("record.proto", fileDescriptor_bf94fd919e302a1d) } - -var fileDescriptor_bf94fd919e302a1d = []byte{ - // 234 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x3c, 0x8e, 0x41, 0x4e, 0xc3, 0x30, - 0x10, 0x45, 0x63, 0xe2, 0x22, 0x18, 0xca, 0x02, 0xab, 0xaa, 0xa2, 0x2c, 0x4c, 0xd4, 0x55, 0x56, - 0x29, 0xe2, 0x08, 0x65, 0xcf, 0x22, 0x3d, 0x00, 0x72, 0x1d, 0xa7, 0x20, 0xd1, 0x8c, 0x35, 0xb5, - 0x04, 0xdc, 0x84, 0x23, 0x65, 0xc9, 0x09, 0x10, 0x84, 0x8b, 0xa0, 0x8c, 0x03, 0x1b, 0xfb, 0xeb, - 0x7d, 0xf9, 0x7d, 0xc3, 0x9c, 0x9c, 0x45, 0x6a, 0x2a, 0x4f, 0x18, 0x50, 0xcd, 0x5e, 0xcc, 0xb3, - 0xdf, 0xe5, 0x8b, 0x3d, 0xee, 0x91, 0xc9, 0x7a, 0x4c, 0xb1, 0xcc, 0x97, 0x64, 0xda, 0xb0, 0x1e, - 0x0f, 0xbf, 0xe3, 0x2b, 0xf2, 0xd5, 0x3d, 0x9c, 0xd6, 0x2c, 0x51, 0x19, 0xc8, 0xf0, 0xe6, 0x5d, - 0x26, 0x0a, 0x51, 0xa6, 0x1b, 0xd9, 0x7f, 0x5e, 0x27, 0x35, 0x13, 0xb5, 0x84, 0xd4, 0x92, 0xcd, - 0x4e, 0x0a, 0x51, 0x5e, 0x4e, 0xc5, 0x08, 0x94, 0x02, 0xd9, 0x98, 0x60, 0xb2, 0xb4, 0x10, 0xe5, - 0xbc, 0xe6, 0xbc, 0x22, 0x38, 0xdb, 0x76, 0xc6, 0x1f, 0x1f, 0x31, 0xa8, 0x1c, 0x66, 0x4f, 0x5d, - 0xe3, 0x5e, 0x59, 0x29, 0xa7, 0x97, 0x11, 0xf1, 0x9a, 0xa3, 0x03, 0x4b, 0xe5, 0xff, 0x9a, 0xa3, - 0x83, 0xba, 0x01, 0xb0, 0xd8, 0xb5, 0x0f, 0xc7, 0x60, 0x82, 0x63, 0xf7, 0xc5, 0xed, 0x55, 0x15, - 0x7f, 0x5e, 0xdd, 0x61, 0xd7, 0x6e, 0xc7, 0xa2, 0x3e, 0xb7, 0x7f, 0x71, 0xb3, 0xe8, 0xbf, 0x75, - 0xd2, 0x0f, 0x5a, 0x7c, 0x0c, 0x5a, 0x7c, 0x0d, 0x5a, 0xbc, 0xff, 0xe8, 0xe4, 0x37, 0x00, 0x00, - 0xff, 0xff, 0xc3, 0x36, 0x0c, 0xad, 0x1d, 0x01, 0x00, 0x00, -} - -func (m *Record) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *Record) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *Record) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.XXX_unrecognized != nil { - i -= len(m.XXX_unrecognized) - copy(dAtA[i:], m.XXX_unrecognized) - } - if m.Data != nil { - i -= len(m.Data) - copy(dAtA[i:], m.Data) - i = encodeVarintRecord(dAtA, i, uint64(len(m.Data))) - i-- - dAtA[i] = 0x1a - } - i = encodeVarintRecord(dAtA, i, uint64(m.Crc)) - i-- - dAtA[i] = 0x10 - i = encodeVarintRecord(dAtA, i, uint64(m.Type)) - i-- - dAtA[i] = 0x8 - return len(dAtA) - i, nil -} - -func (m *Snapshot) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *Snapshot) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *Snapshot) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.XXX_unrecognized != nil { - i -= len(m.XXX_unrecognized) - copy(dAtA[i:], m.XXX_unrecognized) - } - if m.ConfState != nil { - { - size, err := m.ConfState.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintRecord(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x1a - } - i = encodeVarintRecord(dAtA, i, uint64(m.Term)) - i-- - dAtA[i] = 0x10 - i = encodeVarintRecord(dAtA, i, uint64(m.Index)) - i-- - dAtA[i] = 0x8 - return len(dAtA) - i, nil -} - -func encodeVarintRecord(dAtA []byte, offset int, v uint64) int { - offset -= sovRecord(v) - base := offset - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return base -} -func (m *Record) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - n += 1 + sovRecord(uint64(m.Type)) - n += 1 + sovRecord(uint64(m.Crc)) - if m.Data != nil { - l = len(m.Data) - n += 1 + l + sovRecord(uint64(l)) - } - if m.XXX_unrecognized != nil { - n += len(m.XXX_unrecognized) - } - return n -} - -func (m *Snapshot) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - n += 1 + sovRecord(uint64(m.Index)) - n += 1 + sovRecord(uint64(m.Term)) - if m.ConfState != nil { - l = m.ConfState.Size() - n += 1 + l + sovRecord(uint64(l)) - } - if m.XXX_unrecognized != nil { - n += len(m.XXX_unrecognized) - } - return n -} - -func sovRecord(x uint64) (n int) { - return (math_bits.Len64(x|1) + 6) / 7 -} -func sozRecord(x uint64) (n int) { - return sovRecord(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} -func (m *Record) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRecord - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: Record: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: Record: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Type", wireType) - } - m.Type = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRecord - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Type |= int64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Crc", wireType) - } - m.Crc = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRecord - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Crc |= uint32(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Data", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRecord - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthRecord - } - postIndex := iNdEx + byteLen - if postIndex < 0 { - return ErrInvalidLengthRecord - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Data = append(m.Data[:0], dAtA[iNdEx:postIndex]...) - if m.Data == nil { - m.Data = []byte{} - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRecord(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthRecord - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *Snapshot) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRecord - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: Snapshot: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: Snapshot: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Index", wireType) - } - m.Index = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRecord - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Index |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Term", wireType) - } - m.Term = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRecord - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Term |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ConfState", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRecord - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRecord - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthRecord - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.ConfState == nil { - m.ConfState = &raftpb.ConfState{} - } - if err := m.ConfState.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRecord(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthRecord - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func skipRecord(dAtA []byte) (n int, err error) { - l := len(dAtA) - iNdEx := 0 - depth := 0 - for iNdEx < l { - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowRecord - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - wireType := int(wire & 0x7) - switch wireType { - case 0: - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowRecord - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - iNdEx++ - if dAtA[iNdEx-1] < 0x80 { - break - } - } - case 1: - iNdEx += 8 - case 2: - var length int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowRecord - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - length |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if length < 0 { - return 0, ErrInvalidLengthRecord - } - iNdEx += length - case 3: - depth++ - case 4: - if depth == 0 { - return 0, ErrUnexpectedEndOfGroupRecord - } - depth-- - case 5: - iNdEx += 4 - default: - return 0, fmt.Errorf("proto: illegal wireType %d", wireType) - } - if iNdEx < 0 { - return 0, ErrInvalidLengthRecord - } - if depth == 0 { - return iNdEx, nil - } - } - return 0, io.ErrUnexpectedEOF -} - -var ( - ErrInvalidLengthRecord = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowRecord = fmt.Errorf("proto: integer overflow") - ErrUnexpectedEndOfGroupRecord = fmt.Errorf("proto: unexpected end of group") -) diff --git a/vendor/go.etcd.io/etcd/server/v3/wal/walpb/record.proto b/vendor/go.etcd.io/etcd/server/v3/wal/walpb/record.proto deleted file mode 100644 index 536fa6c19c..0000000000 --- a/vendor/go.etcd.io/etcd/server/v3/wal/walpb/record.proto +++ /dev/null @@ -1,24 +0,0 @@ -syntax = "proto2"; -package walpb; - -import "gogoproto/gogo.proto"; -import "raft/raftpb/raft.proto"; - -option (gogoproto.marshaler_all) = true; -option (gogoproto.sizer_all) = true; -option (gogoproto.unmarshaler_all) = true; -option (gogoproto.goproto_getters_all) = false; - -message Record { - optional int64 type = 1 [(gogoproto.nullable) = false]; - optional uint32 crc = 2 [(gogoproto.nullable) = false]; - optional bytes data = 3; -} - -// Keep in sync with raftpb.SnapshotMetadata. -message Snapshot { - optional uint64 index = 1 [(gogoproto.nullable) = false]; - optional uint64 term = 2 [(gogoproto.nullable) = false]; - // Field populated since >=etcd-3.5.0. - optional raftpb.ConfState conf_state = 3; -} diff --git a/vendor/go.opentelemetry.io/contrib/.gitignore b/vendor/go.opentelemetry.io/contrib/.gitignore deleted file mode 100644 index 21ab270fe0..0000000000 --- a/vendor/go.opentelemetry.io/contrib/.gitignore +++ /dev/null @@ -1,13 +0,0 @@ -.DS_Store -Thumbs.db - -.tools/ -.idea/ -.vscode/ -*.iml -*.so -coverage.* -example - -instrumentation/google.golang.org/grpc/otelgrpc/example/server/server -instrumentation/google.golang.org/grpc/otelgrpc/example/client/client \ No newline at end of file diff --git a/vendor/go.opentelemetry.io/contrib/.golangci.yml b/vendor/go.opentelemetry.io/contrib/.golangci.yml deleted file mode 100644 index cef170f7c7..0000000000 --- a/vendor/go.opentelemetry.io/contrib/.golangci.yml +++ /dev/null @@ -1,32 +0,0 @@ -# See https://github.com/golangci/golangci-lint#config-file -run: - issues-exit-code: 1 #Default - tests: true #Default - -linters: - enable: - - misspell - - goimports - - golint - - gofmt - -issues: - exclude-rules: - # helpers in tests often (rightfully) pass a *testing.T as their first argument - - path: _test\.go - text: "context.Context should be the first parameter of a function" - linters: - - golint - # Yes, they are, but it's okay in a test - - path: _test\.go - text: "exported func.*returns unexported type.*which can be annoying to use" - linters: - - golint - -linters-settings: - misspell: - locale: US - #ignore-words: - # - someword - goimports: - local-prefixes: go.opentelemetry.io diff --git a/vendor/go.opentelemetry.io/contrib/CHANGELOG.md b/vendor/go.opentelemetry.io/contrib/CHANGELOG.md deleted file mode 100644 index 1fcf34b2ab..0000000000 --- a/vendor/go.opentelemetry.io/contrib/CHANGELOG.md +++ /dev/null @@ -1,319 +0,0 @@ -# Changelog - -All notable changes to this project will be documented in this file. - -The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - -This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). - -## [Unreleased] - -## [0.20.0] - 2021-04-23 - -### Changed - -- The `go.opentelemetry.io/contrib/instrumentation/go.mongodb.org/mongo-driver/mongo/otelmongo` instrumentation now accepts a `WithCommandAttributeDisabled`, - so the caller can specify whether to opt-out of tracing the mongo command. (#712) -- Upgrade to v0.20.0 of `go.opentelemetry.io/otel`. (#758) -- The B3 and Jaeger propagators now store their debug or deferred state in the context.Context instead of the SpanContext. (#758) - -## [0.19.0] - 2021-03-19 - -### Changed - -- Upgrade to v0.19.0 of `go.opentelemetry.io/otel`. - -## [0.18.0] - 2021-03-04 - -### Fixed - -- `otelmemcache` no longer sets span status to OK instead of leaving it unset. (#477) -- Fix goroutine leak in gRPC `StreamClientInterceptor`. (#581) - -### Removed - -- Remove service name from `otelmemcache` configuration and span attributes. (#477) - -## [0.17.0] - 2021-02-15 - -### Added - -- Add `ot-tracer` propagator (#562) - -### Changed - -- Rename project default branch from `master` to `main`. - -### Fixed - -- Added failure message for AWS ECS resource detector for better debugging (#568) -- Goroutine leak in gRPC StreamClientInterceptor while streamer returns an error. (#581) - -## [0.16.0] - 2021-01-13 - -### Fixed - -- Fix module path for AWS ECS resource detector (#517) - -## [0.15.1] - 2020-12-14 - -### Added - -- Add registry link check to `Makefile` and pre-release script. (#446) -- A new AWS X-Ray ID Generator (#459) -- Migrate CircleCI jobs to GitHub Actions (#476) -- Add CodeQL GitHub Action (#506) -- Add gosec workflow to GitHub Actions (#507) - -### Fixed - -- Fixes the body replacement in otelhttp to not to mutate a nil body. (#484) - -## [0.15.0] - 2020-12-11 - -### Added - -- A new Amazon EKS resource detector. (#465) -- A new `gcp.CloudRun` detector for detecting resource from a Cloud Run instance. (#455) - -## [0.14.0] - 2020-11-20 - -### Added - -- `otelhttp.{Get,Head,Post,PostForm}` convenience wrappers for their `http` counterparts. (#390) -- The AWS detector now adds the cloud zone, host image ID, host type, and host name to the returned `Resource`. (#410) -- Add Amazon ECS Resource Detector for AWS X-Ray. (#466) -- Add propagator for AWS X-Ray (#462) - -### Changed - -- Add semantic version to `Tracer` / `Meter` created by instrumentation packages `otelsaram`, `otelrestful`, `otelmongo`, `otelhttp` and `otelhttptrace`. (#412) -- Update instrumentation guidelines about tracer / meter semantic version. (#412) -- Replace internal tracer and meter helpers by helpers from `go.opentelemetry.io/otel`. (#414) -- gRPC instrumentation sets span attribute `rpc.grpc.status_code`. (#453) - -## Fixed - -- `/detectors/aws` no longer fails if instance metadata is not available (e.g. not running in AWS) (#401) -- The AWS detector now returns a partial resource and an appropriate error if it encounters an error part way through determining a `Resource` identity. (#410) -- The `host` instrumentation unit test has been updated to not depend on the system it runs on. (#426) - -## [0.13.0] - 2020-10-09 - -## Added - -- A Jaeger propagator. (#375) - -## Changed - -- The `go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc` package instrumentation no longer accepts a `Tracer` as an argument to the interceptor function. - Instead, a new `WithTracerProvider` option is added to configure the `TracerProvider` used when creating the `Tracer` for the instrumentation. (#373) -- The `go.opentelemetry.io/contrib/instrumentation/gopkg.in/macaron.v1/otelmacaron` instrumentation now accepts a `TracerProvider` rather than a `Tracer`. (#374) -- Remove `go.opentelemetry.io/otel/sdk` dependency from instrumentation. (#381) -- Use `httpsnoop` in `go.opentelemetry.io/contrib/instrumentation/github.com/gorilla/mux/otelmux` to ensure `http.ResponseWriter` additional interfaces are preserved. (#388) - -### Fixed - -- The `go.opentelemetry.io/contrib/instrumentation/github.com/labstack/echo/otelecho.Middleware` no longer sends duplicate errors to the global `ErrorHandler`. (#377, #364) -- The import comment in `go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp` is now correctly quoted. (#379) -- The B3 propagator sets the sample bitmask when the sampling decision is `debug`. (#369) - -## [0.12.0] - 2020-09-25 - -### Changed - -- Replace `WithTracer` with `WithTracerProvider` in the `go.opentelemetry.io/contrib/instrumentation/gopkg.in/macaron.v1/otelmacaron` instrumentation. (#374) - -### Added - -- Benchmark tests for the gRPC instrumentation. (#296) -- Integration testing for the gRPC instrumentation. (#297) -- Allow custom labels to be added to net/http metrics. (#306) -- Added B3 propagator, moving it out of open.telemetry.io/otel repo. (#344) - -### Changed - -- Unify instrumentation about provider options for `go.mongodb.org/mongo-driver`, `gin-gonic/gin`, `gorilla/mux`, - `labstack/echo`, `emicklei/go-restful`, `bradfitz/gomemcache`, `Shopify/sarama`, `net/http` and `beego`. (#303) -- Update instrumentation guidelines about uniform provider options. Also, update style guide. (#303) -- Make config struct of instrumentation unexported. (#303) -- Instrumentations have been updated to adhere to the [configuration style guide's](https://github.com/open-telemetry/opentelemetry-go/blob/master/CONTRIBUTING.md#config) - updated recommendation to use `newConfig()` instead of `configure()`. (#336) -- A new instrumentation naming scheme is implemented to avoid package name conflicts for instrumented packages while still remaining discoverable. (#359) - - `google.golang.org/grpc` -> `google.golang.org/grpc/otelgrpc` - - `go.mongodb.org/mongo-driver` -> `go.mongodb.org/mongo-driver/mongo/otelmongo` - - `net/http` -> `net/http/otelhttp` - - `net/http/httptrace` -> `net/http/httptrace/otelhttptrace` - - `github.com/labstack/echo` -> `github.com/labstack/echo/otelecho` - - `github.com/bradfitz/gomemcache` -> `github.com/bradfitz/gomemcache/memcache/otelmemcache` - - `github.com/gin-gonic/gin` -> `github.com/gin-gonic/gin/otelgin` - - `github.com/gocql/gocql` -> `github.com/gocql/gocql/otelgocql` - - `github.com/emicklei/go-restful` -> `github.com/emicklei/go-restful/otelrestful` - - `github.com/Shopify/sarama` -> `github.com/Shopify/sarama/otelsarama` - - `github.com/gorilla/mux` -> `github.com/gorilla/mux/otelmux` - - `github.com/astaxie/beego` -> `github.com/astaxie/beego/otelbeego` - - `gopkg.in/macaron.v1` -> `gopkg.in/macaron.v1/otelmacaron` -- Rename `OTelBeegoHandler` to `Handler` in the `go.opentelemetry.io/contrib/instrumentation/github.com/astaxie/beego/otelbeego` package. (#359) - -## [0.11.0] - 2020-08-25 - -### Added - -- Top-level `Version()` and `SemVersion()` functions defining the current version of the contrib package. (#225) -- Instrumentation for the `github.com/astaxie/beego` package. (#200) -- Instrumentation for the `github.com/bradfitz/gomemcache` package. (#204) -- Host metrics instrumentation. (#231) -- Cortex histogram and distribution support. (#237) -- Cortex example project. (#238) -- Cortex HTTP authentication. (#246) - -### Changed - -- Remove service name as a parameter of Sarama instrumentation. (#221) -- Replace `WithTracer` with `WithTracerProvider` in Sarama instrumentation. (#221) -- Switch to use common top-level module `SemVersion()` when creating versioned tracer in `bradfitz/gomemcache`. (#226) -- Use `IntegrationShouldRun` in `gomemcache_test`. (#254) -- Use Go 1.15 for CI builds. (#236) -- Improved configuration for `runtime` instrumentation. (#224) - -### Fixed - -- Update dependabot configuration to include newly added `bradfitz/gomemcache` package. (#226) -- Correct `runtime` instrumentation name. (#241) - -## [0.10.1] - 2020-08-13 - -### Added - -- The `go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc` module has been added to replace the instrumentation that had previoiusly existed in the `go.opentelemetry.io/otel/instrumentation/grpctrace` package. (#189) -- Instrumentation for the stdlib `net/http` and `net/http/httptrace` packages. (#190) -- Initial Cortex exporter. (#202, #205, #210, #211, #215) - -### Fixed - -- Bump google.golang.org/grpc from 1.30.0 to 1.31.0. (#166) -- Bump go.mongodb.org/mongo-driver from 1.3.5 to 1.4.0 in /instrumentation/go.mongodb.org/mongo-driver. (#170) -- Bump google.golang.org/grpc in /instrumentation/github.com/gin-gonic/gin. (#173) -- Bump google.golang.org/grpc in /instrumentation/github.com/labstack/echo. (#176) -- Bump google.golang.org/grpc from 1.30.0 to 1.31.0 in /instrumentation/github.com/Shopify/sarama. (#179) -- Bump cloud.google.com/go from 0.61.0 to 0.63.0 in /detectors/gcp. (#181, #199) -- Bump github.com/aws/aws-sdk-go from 1.33.15 to 1.34.1 in /detectors/aws. (#184, #192, #193, #198, #201, #203) -- Bump github.com/golangci/golangci-lint from 1.29.0 to 1.30.0 in /tools. (#186) -- Setup CI to run tests that require external resources (Cassandra and MongoDB). (#191) -- Bump github.com/Shopify/sarama from 1.26.4 to 1.27.0 in /instrumentation/github.com/Shopify/sarama. (#206) - -## [0.10.0] - 2020-07-31 - -This release upgrades its [go.opentelemetry.io/otel](https://github.com/open-telemetry/opentelemetry-go/releases/tag/v0.10.0) dependency to v0.10.0 and includes new instrumentation for popular Kafka and Cassandra clients. - -### Added - -- A detector that generate resources from GCE instance. (#132) -- A detector that generate resources from AWS instances. (#139) -- Instrumentation for the Kafka client github.com/Shopify/sarama. (#134, #153) -- Links and status message for mock span in the internal testing library. (#134) -- Instrumentation for the Cassandra client github.com/gocql/gocql. (#137) -- A detector that generate resources from GKE clusters. (#154) - -### Fixed - -- Bump github.com/aws/aws-sdk-go from 1.33.8 to 1.33.15 in /detectors/aws. (#155, #157, #159, #162) -- Bump github.com/golangci/golangci-lint from 1.28.3 to 1.29.0 in /tools. (#146) - -## [0.9.0] - 2020-07-20 - -This release upgrades its [go.opentelemetry.io/otel](https://github.com/open-telemetry/opentelemetry-go/releases/tag/v0.9.0) dependency to v0.9.0. - -### Fixed - -- Bump github.com/emicklei/go-restful/v3 from 3.0.0 to 3.2.0 in /instrumentation/github.com/emicklei/go-restful. (#133) -- Update dependabot configuration to correctly check all included packages. (#131) -- Update `RELEASING.md` with correct `tag.sh` command. (#130) - -## [0.8.0] - 2020-07-10 - -This release upgrades its [go.opentelemetry.io/otel](https://github.com/open-telemetry/opentelemetry-go/releases/tag/v0.8.0) dependency to v0.8.0, includes minor fixes, and new instrumentation. - -### Added - -- Create this `CHANGELOG.md`. (#114) -- Add `emicklei/go-restful/v3` trace instrumentation. (#115) - -### Changed - -- Update `CONTRIBUTING.md` to ask for updates to `CHANGELOG.md` with each pull request. (#114) -- Move all `github.com` package instrumentation under a `github.com` directory. (#118) - -### Fixed - -- Update README to include information about external instrumentation. - To start, this includes native instrumentation found in the `go-redis/redis` package. (#117) -- Bump github.com/golangci/golangci-lint from 1.27.0 to 1.28.2 in /tools. (#122, #123, #125) -- Bump go.mongodb.org/mongo-driver from 1.3.4 to 1.3.5 in /instrumentation/go.mongodb.org/mongo-driver. (#124) - -## [0.7.0] - 2020-06-29 - -This release upgrades its [go.opentelemetry.io/otel](https://github.com/open-telemetry/opentelemetry-go/releases/tag/v0.7.0) dependency to v0.7.0. - -### Added - -- Create `RELEASING.md` instructions. (#101) -- Apply transitive dependabot go.mod updates as part of a new automatic Github workflow. (#94) -- New dependabot integration to automate package upgrades. (#61) -- Add automatic tag generation script for release. (#60) - -### Changed - -- Upgrade Datadog metrics exporter to include Resource tags. (#46) -- Added output validation to Datadog example. (#96) -- Move Macaron package to match layout guidelines. (#92) -- Update top-level README and instrumentation README. (#92) -- Bump google.golang.org/grpc from 1.29.1 to 1.30.0. (#99) -- Bump github.com/golangci/golangci-lint from 1.21.0 to 1.27.0 in /tools. (#77) -- Bump go.mongodb.org/mongo-driver from 1.3.2 to 1.3.4 in /instrumentation/go.mongodb.org/mongo-driver. (#76) -- Bump github.com/stretchr/testify from 1.5.1 to 1.6.1. (#74) -- Bump gopkg.in/macaron.v1 from 1.3.5 to 1.3.9 in /instrumentation/macaron. (#68) -- Bump github.com/gin-gonic/gin from 1.6.2 to 1.6.3 in /instrumentation/gin-gonic/gin. (#73) -- Bump github.com/DataDog/datadog-go from 3.5.0+incompatible to 3.7.2+incompatible in /exporters/metric/datadog. (#78) -- Replaced `internal/trace/http.go` helpers with `api/standard` helpers from otel-go repo. (#112) - -## [0.6.1] - 2020-06-08 - -First official tagged release of `contrib` repository. - -### Added - -- `labstack/echo` trace instrumentation (#42) -- `mongodb` trace instrumentation (#26) -- Go Runtime metrics (#9) -- `gorilla/mux` trace instrumentation (#19) -- `gin-gonic` trace instrumentation (#15) -- `macaron` trace instrumentation (#20) -- `dogstatsd` metrics exporter (#10) -- `datadog` metrics exporter (#22) -- Tags to all modules in repository -- Repository folder structure and automated build (#3) - -### Changes - -- Prefix support for dogstatsd (#34) -- Update Go Runtime package to use batch observer (#44) - -[Unreleased]: https://github.com/open-telemetry/opentelemetry-go-contrib/compare/v0.20.0...HEAD -[0.20.0]: https://github.com/open-telemetry/opentelemetry-go-contrib/releases/tag/v0.20.0 -[0.19.0]: https://github.com/open-telemetry/opentelemetry-go-contrib/releases/tag/v0.19.0 -[0.18.0]: https://github.com/open-telemetry/opentelemetry-go-contrib/releases/tag/v0.18.0 -[0.17.0]: https://github.com/open-telemetry/opentelemetry-go-contrib/releases/tag/v0.17.0 -[0.16.0]: https://github.com/open-telemetry/opentelemetry-go-contrib/releases/tag/v0.16.0 -[0.15.1]: https://github.com/open-telemetry/opentelemetry-go-contrib/releases/tag/v0.15.1 -[0.15.0]: https://github.com/open-telemetry/opentelemetry-go-contrib/releases/tag/v0.15.0 -[0.14.0]: https://github.com/open-telemetry/opentelemetry-go-contrib/releases/tag/v0.14.0 -[0.13.0]: https://github.com/open-telemetry/opentelemetry-go-contrib/releases/tag/v0.13.0 -[0.12.0]: https://github.com/open-telemetry/opentelemetry-go-contrib/releases/tag/v0.12.0 -[0.11.0]: https://github.com/open-telemetry/opentelemetry-go-contrib/releases/tag/v0.11.0 -[0.10.1]: https://github.com/open-telemetry/opentelemetry-go-contrib/releases/tag/v0.10.1 -[0.10.0]: https://github.com/open-telemetry/opentelemetry-go-contrib/releases/tag/v0.10.0 -[0.9.0]: https://github.com/open-telemetry/opentelemetry-go-contrib/releases/tag/v0.9.0 -[0.8.0]: https://github.com/open-telemetry/opentelemetry-go-contrib/releases/tag/v0.8.0 -[0.7.0]: https://github.com/open-telemetry/opentelemetry-go-contrib/releases/tag/v0.7.0 -[0.6.1]: https://github.com/open-telemetry/opentelemetry-go-contrib/releases/tag/v0.6.1 diff --git a/vendor/go.opentelemetry.io/contrib/CODEOWNERS b/vendor/go.opentelemetry.io/contrib/CODEOWNERS deleted file mode 100644 index 196df9cfd8..0000000000 --- a/vendor/go.opentelemetry.io/contrib/CODEOWNERS +++ /dev/null @@ -1,17 +0,0 @@ -##################################################### -# -# List of approvers for this repository -# -##################################################### -# -# Learn about membership in OpenTelemetry community: -# https://github.com/open-telemetry/community/blob/main/community-membership.md -# -# -# Learn about CODEOWNERS file format: -# https://help.github.com/en/articles/about-code-owners -# - -* @jmacd @MrAlias @Aneurysm9 @evantorrie @XSAM @dashpole @paivagustavo - -CODEOWNERS @MrAlias @Aneurysm9 diff --git a/vendor/go.opentelemetry.io/contrib/CONTRIBUTING.md b/vendor/go.opentelemetry.io/contrib/CONTRIBUTING.md deleted file mode 100644 index 0c7bb21bd0..0000000000 --- a/vendor/go.opentelemetry.io/contrib/CONTRIBUTING.md +++ /dev/null @@ -1,135 +0,0 @@ -# Contributing to opentelemetry-go-contrib - -The Go special interest group (SIG) meets regularly. See the -OpenTelemetry -[community](https://github.com/open-telemetry/community#golang-sdk) -repo for information on this and other language SIGs. - -See the [public meeting -notes](https://docs.google.com/document/d/1A63zSWX0x2CyCK_LoNhmQC4rqhLpYXJzXbEPDUQ2n6w/edit#heading=h.9tngw7jdwd6b) -for a summary description of past meetings. To request edit access, -join the meeting or get in touch on -[Slack](https://cloud-native.slack.com/archives/C01NPAXACKT). - -## Development - -There are some generated files checked into the repo. To make sure -that the generated files are up-to-date, run `make` (or `make -precommit` - the `precommit` target is the default). - -The `precommit` target also fixes the formatting of the code and -checks the status of the go module files. - -If after running `make precommit` the output of `git status` contains -`nothing to commit, working tree clean` then it means that everything -is up-to-date and properly formatted. - -## Pull Requests - -### How to Send Pull Requests - -Everyone is welcome to contribute code to `opentelemetry-go-contrib` via -GitHub pull requests (PRs). - -To create a new PR, fork the project in GitHub and clone the upstream -repo: - -```sh -$ git clone https://github.com/open-telemetry/opentelemetry-go-contrib -``` -This would put the project in the `opentelemetry-go-contrib` directory in -current working directory. - -Enter the newly created directory and add your fork as a new remote: - -```sh -$ git remote add git@github.com:/opentelemetry-go -``` - -Check out a new branch, make modifications, run linters and tests, update -`CHANGELOG.md` and push the branch to your fork: - -```sh -$ git checkout -b -# edit files -# update changelog -$ make precommit -$ git add -p -$ git commit -$ git push -``` - -Open a pull request against the main `opentelemetry-go-contrib` repo. Be sure to add the pull -request ID to the entry you added to `CHANGELOG.md`. - -### How to Receive Comments - -* If the PR is not ready for review, please put `[WIP]` in the title, - tag it as `work-in-progress`, or mark it as - [`draft`](https://github.blog/2019-02-14-introducing-draft-pull-requests/). -* Make sure CLA is signed and CI is clear. - -### How to Get PRs Merged - -A PR is considered to be **ready to merge** when: - -* It has received two approvals from Approvers/Maintainers (at - different companies). -* Feedback has been addressed. -* Any substantive changes to your PR will require that you clear any prior - Approval reviews, this includes changes resulting from other feedback. Unless - the approver explicitly stated that their approval will persist across - changes it should be assumed that the PR needs their review again. Other - project members (e.g. approvers, maintainers) can help with this if there are - any questions or if you forget to clear reviews. -* It has been open for review for at least one working day. This gives - people reasonable time to review. -* Trivial change (typo, cosmetic, doc, etc.) doesn't have to wait for - one day. -* `CHANGELOG.md` has been updated to reflect what has been - added, changed, removed, or fixed. -* Urgent fix can take exception as long as it has been actively - communicated. - -Any Maintainer can merge the PR once it is **ready to merge**. - -## Style Guide - -* Make sure to run `make precommit` - this will find and fix the code - formatting. -* Check [opentelemetry-go Style Guide](https://github.com/open-telemetry/opentelemetry-go/blob/main/CONTRIBUTING.md#style-guide) - -## Adding a new Contrib package - -To add a new contrib package follow an existing one. An empty Sample instrumentation -provides base structure with an example and a test. Each contrib package -should be its own module. A contrib package may contain more than one go package. - -### Folder Structure -- instrumentation/\ (**Common**) -- instrumentation/\/trace (**specific to trace**) -- instrumentation/\/metrics (**specific to metrics**) - -#### Example -- instrumentation/gorm/trace -- instrumentation/kafka/metrics - -## Approvers and Maintainers - -Approvers: - -- [Evan Torrie](https://github.com/evantorrie), Verizon Media -- [Josh MacDonald](https://github.com/jmacd), LightStep -- [Sam Xie](https://github.com/XSAM) -- [David Ashpole](https://github.com/dashpole), Google -- [Gustavo Silva Paiva](https://github.com/paivagustavo), LightStep - -Maintainers: - -- [Anthony Mirabella](https://github.com/Aneurysm9), Centene -- [Tyler Yahn](https://github.com/MrAlias), New Relic - -### Become an Approver or a Maintainer - -See the [community membership document in OpenTelemetry community -repo](https://github.com/open-telemetry/community/blob/main/community-membership.md). diff --git a/vendor/go.opentelemetry.io/contrib/LICENSE b/vendor/go.opentelemetry.io/contrib/LICENSE deleted file mode 100644 index 261eeb9e9f..0000000000 --- a/vendor/go.opentelemetry.io/contrib/LICENSE +++ /dev/null @@ -1,201 +0,0 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. diff --git a/vendor/go.opentelemetry.io/contrib/Makefile b/vendor/go.opentelemetry.io/contrib/Makefile deleted file mode 100644 index 4ad59562cc..0000000000 --- a/vendor/go.opentelemetry.io/contrib/Makefile +++ /dev/null @@ -1,203 +0,0 @@ -TOOLS_MOD_DIR := ./tools - -# All source code and documents. Used in spell check. -ALL_DOCS := $(shell find . -name '*.md' -type f | sort) -# All directories with go.mod files related to opentelemetry library. Used for building, testing and linting. -ALL_GO_MOD_DIRS := $(filter-out $(TOOLS_MOD_DIR), $(shell find . -type f -name 'go.mod' -exec dirname {} \; | sort)) -ALL_COVERAGE_MOD_DIRS := $(shell find . -type f -name 'go.mod' -exec dirname {} \; | egrep -v '^./example|^$(TOOLS_MOD_DIR)' | sort) - -# URLs to check if all contrib entries exist in the registry. -REGISTRY_BASE_URL = https://raw.githubusercontent.com/open-telemetry/opentelemetry.io/main/content/en/registry -CONTRIB_REPO_URL = https://github.com/open-telemetry/opentelemetry-go-contrib/tree/main - -# Mac OS Catalina 10.5.x doesn't support 386. Hence skip 386 test -SKIP_386_TEST = false -UNAME_S := $(shell uname -s) -ifeq ($(UNAME_S),Darwin) - SW_VERS := $(shell sw_vers -productVersion) - ifeq ($(shell echo $(SW_VERS) | egrep '^(10.1[5-9]|1[1-9]|[2-9])'), $(SW_VERS)) - SKIP_386_TEST = true - endif -endif - - -GOTEST_MIN = go test -v -timeout 30s -GOTEST = $(GOTEST_MIN) -race -GOTEST_WITH_COVERAGE = $(GOTEST) -coverprofile=coverage.out -covermode=atomic -coverpkg=./... - -.DEFAULT_GOAL := precommit - -.PHONY: precommit - -TOOLS_DIR := $(abspath ./.tools) - -$(TOOLS_DIR)/golangci-lint: $(TOOLS_MOD_DIR)/go.mod $(TOOLS_MOD_DIR)/go.sum $(TOOLS_MOD_DIR)/tools.go - cd $(TOOLS_MOD_DIR) && \ - go build -o $(TOOLS_DIR)/golangci-lint github.com/golangci/golangci-lint/cmd/golangci-lint - -$(TOOLS_DIR)/misspell: $(TOOLS_MOD_DIR)/go.mod $(TOOLS_MOD_DIR)/go.sum $(TOOLS_MOD_DIR)/tools.go - cd $(TOOLS_MOD_DIR) && \ - go build -o $(TOOLS_DIR)/misspell github.com/client9/misspell/cmd/misspell - -$(TOOLS_DIR)/stringer: $(TOOLS_MOD_DIR)/go.mod $(TOOLS_MOD_DIR)/go.sum $(TOOLS_MOD_DIR)/tools.go - cd $(TOOLS_MOD_DIR) && \ - go build -o $(TOOLS_DIR)/stringer golang.org/x/tools/cmd/stringer - -precommit: dependabot-check license-check generate build lint test - -.PHONY: test-with-coverage -test-with-coverage: - set -e; \ - printf "" > coverage.txt; \ - for dir in $(ALL_COVERAGE_MOD_DIRS); do \ - echo "go test ./... + coverage in $${dir}"; \ - (cd "$${dir}" && \ - $(GOTEST_WITH_COVERAGE) ./... && \ - go tool cover -html=coverage.out -o coverage.html); \ - [ -f "$${dir}/coverage.out" ] && cat "$${dir}/coverage.out" >> coverage.txt; \ - done; \ - sed -i.bak -e '2,$$ { /^mode: /d; }' coverage.txt && rm coverage.txt.bak - -.PHONY: ci -ci: precommit check-clean-work-tree test-with-coverage test-386 - -.PHONY: test-gocql -test-gocql: - @if ./tools/should_build.sh gocql; then \ - set -e; \ - docker run --name cass-integ --rm -p 9042:9042 -d cassandra:3; \ - CMD=cassandra IMG_NAME=cass-integ ./tools/wait.sh; \ - (cd instrumentation/github.com/gocql/gocql/otelgocql && \ - $(GOTEST_WITH_COVERAGE) . && \ - go tool cover -html=coverage.out -o coverage.html); \ - docker stop cass-integ; \ - fi - -.PHONY: test-mongo-driver -test-mongo-driver: - @if ./tools/should_build.sh mongo-driver; then \ - set -e; \ - docker run --name mongo-integ --rm -p 27017:27017 -d mongo; \ - CMD=mongo IMG_NAME=mongo-integ ./tools/wait.sh; \ - (cd instrumentation/go.mongodb.org/mongo-driver/mongo/otelmongo && \ - $(GOTEST_WITH_COVERAGE) . && \ - go tool cover -html=coverage.out -o coverage.html); \ - docker stop mongo-integ; \ - fi - -.PHONY: test-gomemcache -test-gomemcache: - @if ./tools/should_build.sh gomemcache; then \ - set -e; \ - docker run --name gomemcache-integ --rm -p 11211:11211 -d memcached; \ - CMD=gomemcache IMG_NAME=gomemcache-integ ./tools/wait.sh; \ - (cd instrumentation/github.com/bradfitz/gomemcache/memcache/otelmemcache && \ - $(GOTEST_WITH_COVERAGE) . && \ - go tool cover -html=coverage.out -o coverage.html); \ - docker stop gomemcache-integ ; \ - fi - -.PHONY: check-clean-work-tree -check-clean-work-tree: - @if ! git diff --quiet; then \ - echo; \ - echo 'Working tree is not clean, did you forget to run "make precommit"?'; \ - echo; \ - git status; \ - exit 1; \ - fi - -.PHONY: build -build: - # TODO: Fix this on windows. - set -e; for dir in $(ALL_GO_MOD_DIRS); do \ - echo "compiling all packages in $${dir}"; \ - (cd "$${dir}" && \ - go build ./... && \ - go test -run xxxxxMatchNothingxxxxx ./... >/dev/null); \ - done - -.PHONY: test -test: - set -e; for dir in $(ALL_GO_MOD_DIRS); do \ - echo "go test ./... + race in $${dir}"; \ - (cd "$${dir}" && \ - $(GOTEST) ./...); \ - done - -.PHONY: test-386 -test-386: - if [ $(SKIP_386_TEST) = true ] ; then \ - echo "skipping the test for GOARCH 386 as it is not supported on the current OS"; \ - else \ - set -e; for dir in $(ALL_GO_MOD_DIRS); do \ - echo "go test ./... GOARCH 386 in $${dir}"; \ - (cd "$${dir}" && \ - GOARCH=386 $(GOTEST_MIN) ./...); \ - done; \ - fi - -.PHONY: lint -lint: $(TOOLS_DIR)/golangci-lint $(TOOLS_DIR)/misspell - set -e; for dir in $(ALL_GO_MOD_DIRS); do \ - echo "golangci-lint in $${dir}"; \ - (cd "$${dir}" && \ - $(TOOLS_DIR)/golangci-lint run --fix && \ - $(TOOLS_DIR)/golangci-lint run); \ - done - $(TOOLS_DIR)/misspell -w $(ALL_DOCS) - set -e; for dir in $(ALL_GO_MOD_DIRS) $(TOOLS_MOD_DIR); do \ - echo "go mod tidy in $${dir}"; \ - (cd "$${dir}" && \ - go mod tidy); \ - done - -.PHONY: generate -generate: $(TOOLS_DIR)/stringer - PATH="$(TOOLS_DIR):$${PATH}" go generate ./... - -.PHONY: license-check -license-check: - @licRes=$$(for f in $$(find . -type f \( -iname '*.go' -o -iname '*.sh' \) ! -path './vendor/*' ! -path './exporters/otlp/internal/opentelemetry-proto/*') ; do \ - awk '/Copyright The OpenTelemetry Authors|generated|GENERATED/ && NR<=3 { found=1; next } END { if (!found) print FILENAME }' $$f; \ - done); \ - if [ -n "$${licRes}" ]; then \ - echo "license header checking failed:"; echo "$${licRes}"; \ - exit 1; \ - fi - -.PHONY: registry-links-check -registry-links-check: - @checkRes=$$( \ - for f in $$( find ./instrumentation ./exporters ./detectors ! -path './instrumentation/net/*' -type f -name 'go.mod' -exec dirname {} \; | egrep -v '/example|/utils' | sort ) \ - ./instrumentation/net/http; do \ - TYPE="instrumentation"; \ - if $$(echo "$$f" | grep -q "exporters"); then \ - TYPE="exporter"; \ - fi; \ - if $$(echo "$$f" | grep -q "detectors"); then \ - TYPE="detector"; \ - fi; \ - NAME=$$(echo "$$f" | sed -e 's/.*\///' -e 's/.*otel//'); \ - LINK=$(CONTRIB_REPO_URL)/$$(echo "$$f" | sed -e 's/..//' -e 's/\/otel.*$$//'); \ - if ! $$(curl -s $(REGISTRY_BASE_URL)/$${TYPE}-go-$${NAME}.md | grep -q "$${LINK}"); then \ - echo "$$f"; \ - fi \ - done; \ - ); \ - if [ -n "$$checkRes" ]; then \ - echo "WARNING: registry link check failed for the following packages:"; echo "$${checkRes}"; \ - fi - -.PHONY: dependabot-check -dependabot-check: - @result=$$( \ - for f in $$( find . -type f -name go.mod -exec dirname {} \; | sed 's/^.\/\?/\//' ); \ - do grep -q "$$f" .github/dependabot.yml \ - || echo "$$f"; \ - done; \ - ); \ - if [ -n "$$result" ]; then \ - echo "missing go.mod dependabot check:"; echo "$$result"; \ - exit 1; \ - fi diff --git a/vendor/go.opentelemetry.io/contrib/README.md b/vendor/go.opentelemetry.io/contrib/README.md deleted file mode 100644 index 28585affe9..0000000000 --- a/vendor/go.opentelemetry.io/contrib/README.md +++ /dev/null @@ -1,25 +0,0 @@ -# OpenTelemetry-Go Contrib - -[![build_and_test](https://github.com/open-telemetry/opentelemetry-go-contrib/workflows/build_and_test/badge.svg)](https://github.com/open-telemetry/opentelemetry-go-contrib/actions?query=workflow%3Abuild_and_test+branch%3Amain) -[![Docs](https://godoc.org/go.opentelemetry.io/contrib?status.svg)](https://pkg.go.dev/go.opentelemetry.io/contrib) -[![Go Report Card](https://goreportcard.com/badge/go.opentelemetry.io/contrib)](https://goreportcard.com/report/go.opentelemetry.io/contrib) -[![Slack](https://img.shields.io/badge/slack-@cncf/otel--go-brightgreen.svg?logo=slack)](https://cloud-native.slack.com/archives/C01NPAXACKT) - -Collection of 3rd-party instrumentation and exporters for [OpenTelemetry-Go](https://github.com/open-telemetry/opentelemetry-go). - -## Contents - -- [Instrumentation](./instrumentation/): Packages providing OpenTelemetry instrumentation for 3rd-party libraries. -- [Exporters](./exporters/): Packages providing OpenTelemetry exporters for 3rd-party telemetry systems. -- [Propagators](./propagators/): Packages providing OpenTelemetry context propagators for 3rd-party propagation formats. -- [Detectors](./detectors/): Packages providing OpenTelemetry resource detectors for 3rd-party cloud computing environments. - -## Project Status - -This project is currently in a pre-GA phase. Our progress towards a GA release -candidate is tracked in [this project -board](https://github.com/orgs/open-telemetry/projects/5). - -## Contributing - -For information on how to contribute, consult [the contributing guidelines](./CONTRIBUTING.md) diff --git a/vendor/go.opentelemetry.io/contrib/RELEASING.md b/vendor/go.opentelemetry.io/contrib/RELEASING.md deleted file mode 100644 index f7fd359c47..0000000000 --- a/vendor/go.opentelemetry.io/contrib/RELEASING.md +++ /dev/null @@ -1,96 +0,0 @@ -# Release Process - -There are two types of release for the `go.opentelemetry.io/contrib` repo -and submodules. - -1. **Case 1** A release due to changes independent of the -`go.opentelemetry.io/otel` module, e.g. perhaps a critical bug fix in -one of the contrib modules. - -2. **Case 2** A release due to a breaking API change in -`go.opentelemetry.io/otel` which all modules in this repo -depend on. - -## Pre-Release - -Update go.mod for submodules to depend on the upcoming new release of -the module in this repo, `go.opentelemetry.io/contrib`. Decide on the -next version of the semantic tag to apply to the contrib -module based on whether you fall into Case 1 or Case 2. - -### Case 1 - -If the changes are all internal to this repo, then the new tag will -most often be a patch or minor version upgrade to the existing tag on -this module. Let's call this ``. - -### Case 2 - -If a new release is required due to breaking changes in -`go.opentelemetry.io/otel`, then the new semantic tag for this repo -should be bumped to match the `go.opentelemetry.io/otel` new tag. -Let's call this ``. The script checks that -`go.opentelemetry.io/otel@v` is a valid tag, so you need -to wait until that tag has been pushed in the main repo. - -In nearly all cases, `` should be the same as -``. - -1. Run `pre_release.sh` script to create a branch `pre_release_`. - The script will also run `go mod tidy` and `make ci`. - - * **Case 1** `./pre_release.sh -t ` - * **Case 2** `./pre_release.sh -o [-t ]` - -2. If you used `-o ` to rewrite the modules to depend on - a new version of `go.opentelemetry.io/otel`, there will likely be - breaking changes that require fixes to the files in this - `contrib` repo. Make the appropriate fixes to address any API - breaks and run through the - - ``` - git commit -m "fixes due to API changes" - make precommit - ``` - - cycle until everything passes - -4. Push the changes to upstream. - - ``` - git diff main - git push - ``` - -5. Create a PR on github and merge the PR once approved. - - -### Tag -Now create a `` on the commit hash of the changes made in pre-release step, - -1. Run the tag.sh script. - - ``` - ./tag.sh - ``` -2. Push tags upstream. Make sure you push upstream for all the sub-module tags as well. - - ``` - git push upstream - git push upstream - ... - ``` - -## Release -Now create a release for the new `` on github. -The release body should include all the release notes in the Changelog for this release. -Additionally, the `tag.sh` script generates commit logs since last release which can be used to suppliment the release notes. - - - - - - - - - diff --git a/vendor/go.opentelemetry.io/contrib/contrib.go b/vendor/go.opentelemetry.io/contrib/contrib.go deleted file mode 100644 index 92c1ddfee9..0000000000 --- a/vendor/go.opentelemetry.io/contrib/contrib.go +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package contrib contains common values used across all -// instrumentation, exporter, and detector contributions. -package contrib // import "go.opentelemetry.io/contrib" - -// Version is the current release version of OpenTelemetry Contrib in use. -func Version() string { - return "0.20.0" - // This string is updated by the pre_release.sh script during release -} - -// SemVersion is the semantic version to be supplied to tracer/meter creation. -func SemVersion() string { - return "semver:" + Version() -} diff --git a/vendor/go.opentelemetry.io/contrib/doc.go b/vendor/go.opentelemetry.io/contrib/doc.go deleted file mode 100644 index 6c55ff6a2b..0000000000 --- a/vendor/go.opentelemetry.io/contrib/doc.go +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// This package provides all of its functionality through its -// submodules. The submodules in the exporters directory provide -// implementations for trace and metric exporters for third-party -// collectors, and submodules in the instrumentation directory provide the -// instrumentation for the popular go libraries. -package contrib diff --git a/vendor/go.opentelemetry.io/contrib/go.mod b/vendor/go.opentelemetry.io/contrib/go.mod deleted file mode 100644 index 3a96b217de..0000000000 --- a/vendor/go.opentelemetry.io/contrib/go.mod +++ /dev/null @@ -1,3 +0,0 @@ -module go.opentelemetry.io/contrib - -go 1.14 diff --git a/vendor/go.opentelemetry.io/contrib/go.sum b/vendor/go.opentelemetry.io/contrib/go.sum deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/vendor/go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc/LICENSE b/vendor/go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc/LICENSE deleted file mode 100644 index 261eeb9e9f..0000000000 --- a/vendor/go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc/LICENSE +++ /dev/null @@ -1,201 +0,0 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. diff --git a/vendor/go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc/go.mod b/vendor/go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc/go.mod deleted file mode 100644 index 368ca8dea0..0000000000 --- a/vendor/go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc/go.mod +++ /dev/null @@ -1,16 +0,0 @@ -module go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc - -go 1.14 - -replace go.opentelemetry.io/contrib => ../../../../ - -require ( - github.com/golang/protobuf v1.5.2 - github.com/stretchr/testify v1.7.0 - go.opentelemetry.io/contrib v0.20.0 - go.opentelemetry.io/otel v0.20.0 - go.opentelemetry.io/otel/oteltest v0.20.0 - go.opentelemetry.io/otel/trace v0.20.0 - go.uber.org/goleak v1.1.10 - google.golang.org/grpc v1.37.0 -) diff --git a/vendor/go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc/go.sum b/vendor/go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc/go.sum deleted file mode 100644 index 5bc12d8ab6..0000000000 --- a/vendor/go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc/go.sum +++ /dev/null @@ -1,122 +0,0 @@ -cloud.google.com/go v0.26.0 h1:e0WKqKTd5BnrG8aKH3J3h+QvEIQtSUcf2n5UZ5ZgLtQ= -cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= -github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= -github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= -github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= -github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= -github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= -github.com/envoyproxy/go-control-plane v0.9.9-0.20210217033140-668b12f5399d/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk= -github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= -github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= -github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= -github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= -github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= -github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= -github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= -github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= -github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= -github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= -github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= -github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw= -github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= -github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= -github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= -github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= -github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= -github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= -github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= -github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= -github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= -github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= -github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= -github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= -github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -go.opentelemetry.io/otel v0.20.0 h1:eaP0Fqu7SXHwvjiqDq83zImeehOHX8doTvU9AwXON8g= -go.opentelemetry.io/otel v0.20.0/go.mod h1:Y3ugLH2oa81t5QO+Lty+zXf8zC9L26ax4Nzoxm/dooo= -go.opentelemetry.io/otel/metric v0.20.0 h1:4kzhXFP+btKm4jwxpjIqjs41A7MakRFUS86bqLHTIw8= -go.opentelemetry.io/otel/metric v0.20.0/go.mod h1:598I5tYlH1vzBjn+BTuhzTCSb/9debfNp6R3s7Pr1eU= -go.opentelemetry.io/otel/oteltest v0.20.0 h1:HiITxCawalo5vQzdHfKeZurV8x7ljcqAgiWzF6Vaeaw= -go.opentelemetry.io/otel/oteltest v0.20.0/go.mod h1:L7bgKf9ZB7qCwT9Up7i9/pn0PWIa9FqQ2IQ8LoxiGnw= -go.opentelemetry.io/otel/trace v0.20.0 h1:1DL6EXUdcg95gukhuRRvLDO/4X5THh/5dIV52lqtnbw= -go.opentelemetry.io/otel/trace v0.20.0/go.mod h1:6GjCW8zgDjwGHGa6GkyeB8+/5vjT16gUEi0Nf1iBdgw= -go.uber.org/goleak v1.1.10 h1:z+mqJhf6ss6BSfSM671tgKyZBFPTTJM+HLxnhPC3wu0= -go.uber.org/goleak v1.1.10/go.mod h1:8a7PlsEVH3e/a/GLqe5IIrQx6GzcnRmZEufDUTk4A7A= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= -golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= -golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= -golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= -golang.org/x/lint v0.0.0-20190930215403-16217165b5de h1:5hukYrvBGR8/eNkX5mdUezrA6JiaEZDtJb9Ei+1LlBs= -golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= -golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190620200207-3b0461eec859 h1:R/3boaszxrf1GEUWTVDzSKVwLmSJpwZ1yqXm8j0v2QI= -golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be h1:vEDujvNQGv4jgYKudGeI/+DAX4Jffq6hpD55MmoEvKs= -golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= -golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a h1:1BGLXjeY4akVXGgbC9HugT3Jv3hCI0z56oJR5vAMgBU= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= -golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= -golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= -golang.org/x/tools v0.0.0-20191108193012-7d206e10da11 h1:Yq9t9jnGoR+dBuitxdo9l6Q7xh/zOyNnYUtDKaQ3x0E= -golang.org/x/tools v0.0.0-20191108193012-7d206e10da11/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= -google.golang.org/appengine v1.4.0 h1:/wp5JvzpHIxhs/dumFmF7BXTf3Z+dd4uXta4kVyO508= -google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= -google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= -google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= -google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 h1:+kGHl1aib/qcwaRi1CbqBZ1rk19r85MNUf8HaBghugY= -google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= -google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= -google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= -google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= -google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= -google.golang.org/grpc v1.37.0 h1:uSZWeQJX5j11bIQ4AJoj+McDBo29cY1MCoC1wO3ts+c= -google.golang.org/grpc v1.37.0/go.mod h1:NREThFqKR1f3iQ6oBuvc5LadQuXVGo9rkm5ZGrQdJfM= -google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= -google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= -google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= -google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= -google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= -google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= -google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= -google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= -google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= -google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= -google.golang.org/protobuf v1.26.0 h1:bxAC2xTBsZGibn2RTntX0oH50xLsqy1OxA9tTL3p/lk= -google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= -gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= -honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/vendor/go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc/grpctrace.go b/vendor/go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc/grpctrace.go deleted file mode 100644 index a80daf621f..0000000000 --- a/vendor/go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc/grpctrace.go +++ /dev/null @@ -1,132 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package otelgrpc - -import ( - "context" - - "google.golang.org/grpc/metadata" - - "go.opentelemetry.io/otel" - "go.opentelemetry.io/otel/attribute" - "go.opentelemetry.io/otel/baggage" - "go.opentelemetry.io/otel/propagation" - "go.opentelemetry.io/otel/trace" -) - -const ( - // instrumentationName is the name of this instrumentation package. - instrumentationName = "go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc" - // GRPCStatusCodeKey is convention for numeric status code of a gRPC request. - GRPCStatusCodeKey = attribute.Key("rpc.grpc.status_code") -) - -// config is a group of options for this instrumentation. -type config struct { - Propagators propagation.TextMapPropagator - TracerProvider trace.TracerProvider -} - -// Option applies an option value for a config. -type Option interface { - Apply(*config) -} - -// newConfig returns a config configured with all the passed Options. -func newConfig(opts []Option) *config { - c := &config{ - Propagators: otel.GetTextMapPropagator(), - TracerProvider: otel.GetTracerProvider(), - } - for _, o := range opts { - o.Apply(c) - } - return c -} - -type propagatorsOption struct{ p propagation.TextMapPropagator } - -func (o propagatorsOption) Apply(c *config) { - c.Propagators = o.p -} - -// WithPropagators returns an Option to use the Propagators when extracting -// and injecting trace context from requests. -func WithPropagators(p propagation.TextMapPropagator) Option { - return propagatorsOption{p: p} -} - -type tracerProviderOption struct{ tp trace.TracerProvider } - -func (o tracerProviderOption) Apply(c *config) { - c.TracerProvider = o.tp -} - -// WithTracerProvider returns an Option to use the TracerProvider when -// creating a Tracer. -func WithTracerProvider(tp trace.TracerProvider) Option { - return tracerProviderOption{tp: tp} -} - -type metadataSupplier struct { - metadata *metadata.MD -} - -// assert that metadataSupplier implements the TextMapCarrier interface -var _ propagation.TextMapCarrier = &metadataSupplier{} - -func (s *metadataSupplier) Get(key string) string { - values := s.metadata.Get(key) - if len(values) == 0 { - return "" - } - return values[0] -} - -func (s *metadataSupplier) Set(key string, value string) { - s.metadata.Set(key, value) -} - -func (s *metadataSupplier) Keys() []string { - out := make([]string, 0, len(*s.metadata)) - for key := range *s.metadata { - out = append(out, key) - } - return out -} - -// Inject injects correlation context and span context into the gRPC -// metadata object. This function is meant to be used on outgoing -// requests. -func Inject(ctx context.Context, metadata *metadata.MD, opts ...Option) { - c := newConfig(opts) - c.Propagators.Inject(ctx, &metadataSupplier{ - metadata: metadata, - }) -} - -// Extract returns the correlation context and span context that -// another service encoded in the gRPC metadata object with Inject. -// This function is meant to be used on incoming requests. -func Extract(ctx context.Context, metadata *metadata.MD, opts ...Option) ([]attribute.KeyValue, trace.SpanContext) { - c := newConfig(opts) - ctx = c.Propagators.Extract(ctx, &metadataSupplier{ - metadata: metadata, - }) - - attributeSet := baggage.Set(ctx) - - return (&attributeSet).ToSlice(), trace.SpanContextFromContext(ctx) -} diff --git a/vendor/go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc/interceptor.go b/vendor/go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc/interceptor.go deleted file mode 100644 index 4465d1d5d0..0000000000 --- a/vendor/go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc/interceptor.go +++ /dev/null @@ -1,499 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package otelgrpc - -// gRPC tracing middleware -// https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/rpc.md -import ( - "context" - "io" - "net" - "strings" - - "github.com/golang/protobuf/proto" // nolint:staticcheck - - "google.golang.org/grpc" - grpc_codes "google.golang.org/grpc/codes" - "google.golang.org/grpc/metadata" - "google.golang.org/grpc/peer" - "google.golang.org/grpc/status" - - "go.opentelemetry.io/otel/attribute" - "go.opentelemetry.io/otel/baggage" - "go.opentelemetry.io/otel/codes" - "go.opentelemetry.io/otel/semconv" - "go.opentelemetry.io/otel/trace" - - otelcontrib "go.opentelemetry.io/contrib" -) - -type messageType attribute.KeyValue - -// Event adds an event of the messageType to the span associated with the -// passed context with id and size (if message is a proto message). -func (m messageType) Event(ctx context.Context, id int, message interface{}) { - span := trace.SpanFromContext(ctx) - if p, ok := message.(proto.Message); ok { - span.AddEvent("message", trace.WithAttributes( - attribute.KeyValue(m), - semconv.RPCMessageIDKey.Int(id), - semconv.RPCMessageUncompressedSizeKey.Int(proto.Size(p)), - )) - } else { - span.AddEvent("message", trace.WithAttributes( - attribute.KeyValue(m), - semconv.RPCMessageIDKey.Int(id), - )) - } -} - -var ( - messageSent = messageType(semconv.RPCMessageTypeSent) - messageReceived = messageType(semconv.RPCMessageTypeReceived) -) - -// UnaryClientInterceptor returns a grpc.UnaryClientInterceptor suitable -// for use in a grpc.Dial call. -func UnaryClientInterceptor(opts ...Option) grpc.UnaryClientInterceptor { - return func( - ctx context.Context, - method string, - req, reply interface{}, - cc *grpc.ClientConn, - invoker grpc.UnaryInvoker, - callOpts ...grpc.CallOption, - ) error { - requestMetadata, _ := metadata.FromOutgoingContext(ctx) - metadataCopy := requestMetadata.Copy() - - tracer := newConfig(opts).TracerProvider.Tracer( - instrumentationName, - trace.WithInstrumentationVersion(otelcontrib.SemVersion()), - ) - - name, attr := spanInfo(method, cc.Target()) - var span trace.Span - ctx, span = tracer.Start( - ctx, - name, - trace.WithSpanKind(trace.SpanKindClient), - trace.WithAttributes(attr...), - ) - defer span.End() - - Inject(ctx, &metadataCopy, opts...) - ctx = metadata.NewOutgoingContext(ctx, metadataCopy) - - messageSent.Event(ctx, 1, req) - - err := invoker(ctx, method, req, reply, cc, callOpts...) - - messageReceived.Event(ctx, 1, reply) - - if err != nil { - s, _ := status.FromError(err) - span.SetStatus(codes.Error, s.Message()) - span.SetAttributes(statusCodeAttr(s.Code())) - } else { - span.SetAttributes(statusCodeAttr(grpc_codes.OK)) - } - - return err - } -} - -type streamEventType int - -type streamEvent struct { - Type streamEventType - Err error -} - -const ( - closeEvent streamEventType = iota - receiveEndEvent - errorEvent -) - -// clientStream wraps around the embedded grpc.ClientStream, and intercepts the RecvMsg and -// SendMsg method call. -type clientStream struct { - grpc.ClientStream - - desc *grpc.StreamDesc - events chan streamEvent - eventsDone chan struct{} - finished chan error - - receivedMessageID int - sentMessageID int -} - -var _ = proto.Marshal - -func (w *clientStream) RecvMsg(m interface{}) error { - err := w.ClientStream.RecvMsg(m) - - if err == nil && !w.desc.ServerStreams { - w.sendStreamEvent(receiveEndEvent, nil) - } else if err == io.EOF { - w.sendStreamEvent(receiveEndEvent, nil) - } else if err != nil { - w.sendStreamEvent(errorEvent, err) - } else { - w.receivedMessageID++ - messageReceived.Event(w.Context(), w.receivedMessageID, m) - } - - return err -} - -func (w *clientStream) SendMsg(m interface{}) error { - err := w.ClientStream.SendMsg(m) - - w.sentMessageID++ - messageSent.Event(w.Context(), w.sentMessageID, m) - - if err != nil { - w.sendStreamEvent(errorEvent, err) - } - - return err -} - -func (w *clientStream) Header() (metadata.MD, error) { - md, err := w.ClientStream.Header() - - if err != nil { - w.sendStreamEvent(errorEvent, err) - } - - return md, err -} - -func (w *clientStream) CloseSend() error { - err := w.ClientStream.CloseSend() - - if err != nil { - w.sendStreamEvent(errorEvent, err) - } else { - w.sendStreamEvent(closeEvent, nil) - } - - return err -} - -const ( - clientClosedState byte = 1 << iota - receiveEndedState -) - -func wrapClientStream(s grpc.ClientStream, desc *grpc.StreamDesc) *clientStream { - events := make(chan streamEvent) - eventsDone := make(chan struct{}) - finished := make(chan error) - - go func() { - defer close(eventsDone) - - // Both streams have to be closed - state := byte(0) - - for event := range events { - switch event.Type { - case closeEvent: - state |= clientClosedState - case receiveEndEvent: - state |= receiveEndedState - case errorEvent: - finished <- event.Err - return - } - - if state == clientClosedState|receiveEndedState { - finished <- nil - return - } - } - }() - - return &clientStream{ - ClientStream: s, - desc: desc, - events: events, - eventsDone: eventsDone, - finished: finished, - } -} - -func (w *clientStream) sendStreamEvent(eventType streamEventType, err error) { - select { - case <-w.eventsDone: - case w.events <- streamEvent{Type: eventType, Err: err}: - } -} - -// StreamClientInterceptor returns a grpc.StreamClientInterceptor suitable -// for use in a grpc.Dial call. -func StreamClientInterceptor(opts ...Option) grpc.StreamClientInterceptor { - return func( - ctx context.Context, - desc *grpc.StreamDesc, - cc *grpc.ClientConn, - method string, - streamer grpc.Streamer, - callOpts ...grpc.CallOption, - ) (grpc.ClientStream, error) { - requestMetadata, _ := metadata.FromOutgoingContext(ctx) - metadataCopy := requestMetadata.Copy() - - tracer := newConfig(opts).TracerProvider.Tracer( - instrumentationName, - trace.WithInstrumentationVersion(otelcontrib.SemVersion()), - ) - - name, attr := spanInfo(method, cc.Target()) - var span trace.Span - ctx, span = tracer.Start( - ctx, - name, - trace.WithSpanKind(trace.SpanKindClient), - trace.WithAttributes(attr...), - ) - - Inject(ctx, &metadataCopy, opts...) - ctx = metadata.NewOutgoingContext(ctx, metadataCopy) - - s, err := streamer(ctx, desc, cc, method, callOpts...) - if err != nil { - grpcStatus, _ := status.FromError(err) - span.SetStatus(codes.Error, grpcStatus.Message()) - span.SetAttributes(statusCodeAttr(grpcStatus.Code())) - span.End() - return s, err - } - stream := wrapClientStream(s, desc) - - go func() { - err := <-stream.finished - - if err != nil { - s, _ := status.FromError(err) - span.SetStatus(codes.Error, s.Message()) - span.SetAttributes(statusCodeAttr(s.Code())) - } else { - span.SetAttributes(statusCodeAttr(grpc_codes.OK)) - } - - span.End() - }() - - return stream, nil - } -} - -// UnaryServerInterceptor returns a grpc.UnaryServerInterceptor suitable -// for use in a grpc.NewServer call. -func UnaryServerInterceptor(opts ...Option) grpc.UnaryServerInterceptor { - return func( - ctx context.Context, - req interface{}, - info *grpc.UnaryServerInfo, - handler grpc.UnaryHandler, - ) (interface{}, error) { - requestMetadata, _ := metadata.FromIncomingContext(ctx) - metadataCopy := requestMetadata.Copy() - - entries, spanCtx := Extract(ctx, &metadataCopy, opts...) - ctx = baggage.ContextWithValues(ctx, entries...) - - tracer := newConfig(opts).TracerProvider.Tracer( - instrumentationName, - trace.WithInstrumentationVersion(otelcontrib.SemVersion()), - ) - - name, attr := spanInfo(info.FullMethod, peerFromCtx(ctx)) - ctx, span := tracer.Start( - trace.ContextWithRemoteSpanContext(ctx, spanCtx), - name, - trace.WithSpanKind(trace.SpanKindServer), - trace.WithAttributes(attr...), - ) - defer span.End() - - messageReceived.Event(ctx, 1, req) - - resp, err := handler(ctx, req) - if err != nil { - s, _ := status.FromError(err) - span.SetStatus(codes.Error, s.Message()) - span.SetAttributes(statusCodeAttr(s.Code())) - messageSent.Event(ctx, 1, s.Proto()) - } else { - span.SetAttributes(statusCodeAttr(grpc_codes.OK)) - messageSent.Event(ctx, 1, resp) - } - - return resp, err - } -} - -// serverStream wraps around the embedded grpc.ServerStream, and intercepts the RecvMsg and -// SendMsg method call. -type serverStream struct { - grpc.ServerStream - ctx context.Context - - receivedMessageID int - sentMessageID int -} - -func (w *serverStream) Context() context.Context { - return w.ctx -} - -func (w *serverStream) RecvMsg(m interface{}) error { - err := w.ServerStream.RecvMsg(m) - - if err == nil { - w.receivedMessageID++ - messageReceived.Event(w.Context(), w.receivedMessageID, m) - } - - return err -} - -func (w *serverStream) SendMsg(m interface{}) error { - err := w.ServerStream.SendMsg(m) - - w.sentMessageID++ - messageSent.Event(w.Context(), w.sentMessageID, m) - - return err -} - -func wrapServerStream(ctx context.Context, ss grpc.ServerStream) *serverStream { - return &serverStream{ - ServerStream: ss, - ctx: ctx, - } -} - -// StreamServerInterceptor returns a grpc.StreamServerInterceptor suitable -// for use in a grpc.NewServer call. -func StreamServerInterceptor(opts ...Option) grpc.StreamServerInterceptor { - return func( - srv interface{}, - ss grpc.ServerStream, - info *grpc.StreamServerInfo, - handler grpc.StreamHandler, - ) error { - ctx := ss.Context() - - requestMetadata, _ := metadata.FromIncomingContext(ctx) - metadataCopy := requestMetadata.Copy() - - entries, spanCtx := Extract(ctx, &metadataCopy, opts...) - ctx = baggage.ContextWithValues(ctx, entries...) - - tracer := newConfig(opts).TracerProvider.Tracer( - instrumentationName, - trace.WithInstrumentationVersion(otelcontrib.SemVersion()), - ) - - name, attr := spanInfo(info.FullMethod, peerFromCtx(ctx)) - ctx, span := tracer.Start( - trace.ContextWithRemoteSpanContext(ctx, spanCtx), - name, - trace.WithSpanKind(trace.SpanKindServer), - trace.WithAttributes(attr...), - ) - defer span.End() - - err := handler(srv, wrapServerStream(ctx, ss)) - - if err != nil { - s, _ := status.FromError(err) - span.SetStatus(codes.Error, s.Message()) - span.SetAttributes(statusCodeAttr(s.Code())) - } else { - span.SetAttributes(statusCodeAttr(grpc_codes.OK)) - } - - return err - } -} - -// spanInfo returns a span name and all appropriate attributes from the gRPC -// method and peer address. -func spanInfo(fullMethod, peerAddress string) (string, []attribute.KeyValue) { - attrs := []attribute.KeyValue{semconv.RPCSystemGRPC} - name, mAttrs := parseFullMethod(fullMethod) - attrs = append(attrs, mAttrs...) - attrs = append(attrs, peerAttr(peerAddress)...) - return name, attrs -} - -// peerAttr returns attributes about the peer address. -func peerAttr(addr string) []attribute.KeyValue { - host, port, err := net.SplitHostPort(addr) - if err != nil { - return []attribute.KeyValue(nil) - } - - if host == "" { - host = "127.0.0.1" - } - - return []attribute.KeyValue{ - semconv.NetPeerIPKey.String(host), - semconv.NetPeerPortKey.String(port), - } -} - -// peerFromCtx returns a peer address from a context, if one exists. -func peerFromCtx(ctx context.Context) string { - p, ok := peer.FromContext(ctx) - if !ok { - return "" - } - return p.Addr.String() -} - -// parseFullMethod returns a span name following the OpenTelemetry semantic -// conventions as well as all applicable span attribute.KeyValue attributes based -// on a gRPC's FullMethod. -func parseFullMethod(fullMethod string) (string, []attribute.KeyValue) { - name := strings.TrimLeft(fullMethod, "/") - parts := strings.SplitN(name, "/", 2) - if len(parts) != 2 { - // Invalid format, does not follow `/package.service/method`. - return name, []attribute.KeyValue(nil) - } - - var attrs []attribute.KeyValue - if service := parts[0]; service != "" { - attrs = append(attrs, semconv.RPCServiceKey.String(service)) - } - if method := parts[1]; method != "" { - attrs = append(attrs, semconv.RPCMethodKey.String(method)) - } - return name, attrs -} - -// statusCodeAttr returns status code attribute based on given gRPC code -func statusCodeAttr(c grpc_codes.Code) attribute.KeyValue { - return GRPCStatusCodeKey.Int64(int64(c)) -} diff --git a/vendor/go.opentelemetry.io/contrib/pre_release.sh b/vendor/go.opentelemetry.io/contrib/pre_release.sh deleted file mode 100644 index 971e86b4db..0000000000 --- a/vendor/go.opentelemetry.io/contrib/pre_release.sh +++ /dev/null @@ -1,158 +0,0 @@ -#!/usr/bin/env bash - -# Copyright The OpenTelemetry Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# -# This script is used for -# a) creating a new tagged release of go.opentelemetry.io/contrib -# b) bumping the referenced version of go.opentelemetry.io/otel -# -# The options can be used together or individually. -# -set -e - -declare CONTRIB_TAG -declare OTEL_TAG - -help() { - printf "\n" - printf "Usage: %s [-o otel_tag] [-t tag]\n" "$0" - printf "\t-o Otel release tag. Update all go.mod to reference go.opentelemetry.io/otel .\n" - printf "\t-t New Contrib unreleased tag. Update all go.mod files with this tag.\n" - exit 1 # Exit script after printing help -} - -while getopts "t:o:" opt -do - case "$opt" in - t ) CONTRIB_TAG="$OPTARG" ;; - o ) OTEL_TAG="$OPTARG" ;; - ? ) help ;; # Print help - esac -done - -declare -r SEMVER_REGEX="^v(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)(\\-[0-9A-Za-z-]+(\\.[0-9A-Za-z-]+)*)?(\\+[0-9A-Za-z-]+(\\.[0-9A-Za-z-]+)*)?$" - -validate_tag() { - local tag_=$1 - if [[ "${tag_}" =~ ${SEMVER_REGEX} ]]; then - printf "%s is valid semver tag.\n" "${tag_}" - else - printf "%s is not a valid semver tag.\n" "${tag_}" - return 1 - fi -} - -# Print help in case parameters are empty -if [[ -z "$CONTRIB_TAG" && -z "$OTEL_TAG" ]] -then - printf "At least one of '-o' or '-t' must be specified.\n" - help -fi - - -## Validate tags first -if [ -n "${OTEL_TAG}" ]; then - validate_tag "${OTEL_TAG}" || exit $? - - # check that OTEL_TAG is a currently released tag for go.opentelemetry.io/otel - TMPDIR=$(mktemp -d "/tmp/otel-contrib.XXXXXX") || exit 1 - trap "rm -fr ${TMPDIR}" EXIT - (cd "${TMPDIR}" && go mod init tagtest) - # requires go 1.14 for support of '-modfile' - if ! go get -modfile="${TMPDIR}/go.mod" -d -v "go.opentelemetry.io/otel@${OTEL_TAG}"; then - printf "go.opentelemetry.io/otel %s does not exist. Please supply a valid tag\n" "${OTEL_TAG}" - exit 1 - fi -fi -if [ -n "${CONTRIB_TAG}" ]; then - validate_tag "${CONTRIB_TAG}" || exit $? - TAG_FOUND=$(git tag --list "${CONTRIB_TAG}") - if [[ ${TAG_FOUND} = "${CONTRIB_TAG}" ]] ; then - printf "Tag %s already exists in this repo\n" "${CONTRIB_TAG}" - exit 1 - fi -else - CONTRIB_TAG=${OTEL_TAG} # if contrib_tag not specified, but OTEL_TAG is, then set it to OTEL_TAG -fi - -# Get version for contrib.go -OTEL_CONTRIB_VERSION=$(echo "${CONTRIB_TAG}" | egrep -o "${SEMVER_REGEX}") -# Strip leading v -OTEL_CONTRIB_VERSION="${OTEL_CONTRIB_VERSION#v}" - -cd "$(dirname "$0")" - -if ! git diff --quiet; then \ - printf "Working tree is not clean, can't proceed\n" - git status - git diff - exit 1 -fi - -# Update contrib.go version definition -cp contrib.go contrib.go.bak -sed "s/\(return \"\)[0-9]*\.[0-9]*\.[0-9]*\"/\1${OTEL_CONTRIB_VERSION}\"/" ./contrib.go.bak > ./contrib.go -rm -f ./contrib.go.bak - -declare -r BRANCH_NAME=pre_release_${CONTRIB_TAG} - -patch_gomods() { - local pkg_=$1 - local tag_=$2 - # now do the same for all the directories underneath - PACKAGE_DIRS=$(find . -mindepth 2 -type f -name 'go.mod' -exec dirname {} \; | egrep -v 'tools' | sed 's|^\.\/||' | sort) - # quote any '.' characters in the pkg name - local quoted_pkg_=${pkg_//./\\.} - for dir in $PACKAGE_DIRS; do - cp "${dir}/go.mod" "${dir}/go.mod.bak" - sed "s|${quoted_pkg_}\([^ ]*\) v[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*[^0-9]*.*$|${pkg_}\1 ${tag_}|" "${dir}/go.mod.bak" >"${dir}/go.mod" - rm -f "${dir}/go.mod.bak" - done -} - -# branch off from existing main -git checkout -b "${BRANCH_NAME}" main - -# Update go.mods -if [ -n "${OTEL_TAG}" ]; then - # first update the top most module - go get "go.opentelemetry.io/otel@${OTEL_TAG}" - patch_gomods go.opentelemetry.io/otel "${OTEL_TAG}" -fi - -if [ -n "${CONTRIB_TAG}" ]; then - patch_gomods go.opentelemetry.io/contrib "${CONTRIB_TAG}" -fi - -git diff -# Run lint to update go.sum -make lint - -# Add changes and commit. -git add . -make ci -# Check whether registry links are up to date -make registry-links-check - -declare COMMIT_MSG="" -if [ -n "${OTEL_TAG}" ]; then - COMMIT_MSG+="Bumping otel version to ${OTEL_TAG}" -fi -COMMIT_MSG+=". Prepare for releasing ${CONTRIB_TAG}" -git commit -m "${COMMIT_MSG}" - -printf "Now run following to verify the changes.\ngit diff main\n" -printf "\nThen push the changes to upstream\n" diff --git a/vendor/go.opentelemetry.io/contrib/tag.sh b/vendor/go.opentelemetry.io/contrib/tag.sh deleted file mode 100644 index 2a0ef1d26c..0000000000 --- a/vendor/go.opentelemetry.io/contrib/tag.sh +++ /dev/null @@ -1,178 +0,0 @@ -#!/usr/bin/env bash - -# Copyright The OpenTelemetry Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -readonly PROGNAME=$(basename "$0") -readonly PROGDIR=$(readlink -m "$(dirname "$0")") - -readonly EXCLUDE_PACKAGES="tools" -readonly SEMVER_REGEX="v(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)(\\-[0-9A-Za-z-]+(\\.[0-9A-Za-z-]+)*)?(\\+[0-9A-Za-z-]+(\\.[0-9A-Za-z-]+)*)?" - -usage() { - cat <<- EOF -Usage: $PROGNAME [OPTIONS] SEMVER_TAG COMMIT_HASH - -Creates git tag for all Go packages in project. - -OPTIONS: - -h --help Show this help. - -ARGUMENTS: - SEMVER_TAG Semantic version to tag with. - COMMIT_HASH Git commit hash to tag. -EOF -} - -cmdline() { - local arg commit - - for arg - do - local delim="" - case "$arg" in - # Translate long form options to short form. - --help) args="${args}-h ";; - # Pass through for everything else. - *) [[ "${arg:0:1}" == "-" ]] || delim="\"" - args="${args}${delim}${arg}${delim} ";; - esac - done - - # Reset and process short form options. - eval set -- "$args" - - while getopts "h" OPTION - do - case $OPTION in - h) - usage - exit 0 - ;; - *) - echo "unknown option: $OPTION" - usage - exit 1 - ;; - esac - done - - # Positional arguments. - shift $((OPTIND-1)) - readonly TAG="$1" - if [ -z "$TAG" ] - then - echo "missing SEMVER_TAG" - usage - exit 1 - fi - if [[ ! "$TAG" =~ $SEMVER_REGEX ]] - then - printf "invalid semantic version: %s\n" "$TAG" - exit 2 - fi - if [[ "$( git tag --list "$TAG" )" ]] - then - printf "tag already exists: %s\n" "$TAG" - exit 2 - fi - - shift - commit="$1" - if [ -z "$commit" ] - then - echo "missing COMMIT_HASH" - usage - exit 1 - fi - # Verify rev is for a commit and unify hashes into a complete SHA1. - readonly SHA="$( git rev-parse --quiet --verify "${commit}^{commit}" )" - if [ -z "$SHA" ] - then - printf "invalid commit hash: %s\n" "$commit" - exit 2 - fi - if [ "$( git merge-base "$SHA" HEAD )" != "$SHA" ] - then - printf "commit '%s' not found on this branch\n" "$commit" - exit 2 - fi -} - -package_dirs() { - # Return a list of package directories in the form: - # - # package/directory/a - # package/directory/b - # deeper/package/directory/a - # ... - # - # Making sure to exclude any packages in the EXCLUDE_PACKAGES regexp. - find . -mindepth 2 -type f -name 'go.mod' -exec dirname {} \; \ - | grep -E -v "$EXCLUDE_PACKAGES" \ - | sed 's/^\.\///' \ - | sort -} - -git_tag() { - local tag="$1" - local commit="$2" - - git tag -a "$tag" -s -m "Version $tag" "$commit" -} - -previous_version() { - local current="$1" - - # Requires git > 2.0 - git tag -l --sort=v:refname \ - | grep -E "^${SEMVER_REGEX}$" \ - | grep -v "$current" \ - | tail -1 -} - -print_changes() { - local tag="$1" - local previous - - previous="$( previous_version "$tag" )" - if [ -n "$previous" ] - then - printf "\nRaw changes made between %s and %s\n" "$previous" "$tag" - printf "======================================\n" - git --no-pager log --pretty=oneline "${previous}..$tag" - fi -} - -main() { - local dir - - cmdline "$@" - - cd "$PROGDIR" || exit 3 - - # Create tag for root package. - git_tag "$TAG" "$SHA" - printf "created tag: %s\n" "$TAG" - - # Create tag for all sub-packages. - for dir in $( package_dirs ) - do - git_tag "${dir}/$TAG" "$SHA" - printf "created tag: %s\n" "${dir}/$TAG" - done - - print_changes "$TAG" -} -main "$@" diff --git a/vendor/go.opentelemetry.io/otel/.gitignore b/vendor/go.opentelemetry.io/otel/.gitignore deleted file mode 100644 index 69f09e575f..0000000000 --- a/vendor/go.opentelemetry.io/otel/.gitignore +++ /dev/null @@ -1,19 +0,0 @@ -.DS_Store -Thumbs.db - -.tools/ -.idea/ -.vscode/ -*.iml -*.so -coverage.* - -gen/ - -/example/jaeger/jaeger -/example/namedtracer/namedtracer -/example/opencensus/opencensus -/example/prometheus/prometheus -/example/prom-collector/prom-collector -/example/zipkin/zipkin -/example/otel-collector/otel-collector diff --git a/vendor/go.opentelemetry.io/otel/.gitmodules b/vendor/go.opentelemetry.io/otel/.gitmodules deleted file mode 100644 index 38a1f56982..0000000000 --- a/vendor/go.opentelemetry.io/otel/.gitmodules +++ /dev/null @@ -1,3 +0,0 @@ -[submodule "opentelemetry-proto"] - path = exporters/otlp/internal/opentelemetry-proto - url = https://github.com/open-telemetry/opentelemetry-proto diff --git a/vendor/go.opentelemetry.io/otel/.golangci.yml b/vendor/go.opentelemetry.io/otel/.golangci.yml deleted file mode 100644 index 2ef168198c..0000000000 --- a/vendor/go.opentelemetry.io/otel/.golangci.yml +++ /dev/null @@ -1,32 +0,0 @@ -# See https://github.com/golangci/golangci-lint#config-file -run: - issues-exit-code: 1 #Default - tests: true #Default - -linters: - enable: - - misspell - - goimports - - golint - - gofmt - -issues: - exclude-rules: - # helpers in tests often (rightfully) pass a *testing.T as their first argument - - path: _test\.go - text: "context.Context should be the first parameter of a function" - linters: - - golint - # Yes, they are, but it's okay in a test - - path: _test\.go - text: "exported func.*returns unexported type.*which can be annoying to use" - linters: - - golint - -linters-settings: - misspell: - locale: US - ignore-words: - - cancelled - goimports: - local-prefixes: go.opentelemetry.io diff --git a/vendor/go.opentelemetry.io/otel/CHANGELOG.md b/vendor/go.opentelemetry.io/otel/CHANGELOG.md deleted file mode 100644 index 2702ccda25..0000000000 --- a/vendor/go.opentelemetry.io/otel/CHANGELOG.md +++ /dev/null @@ -1,1319 +0,0 @@ -# Changelog - -All notable changes to this project will be documented in this file. - -The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - -This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). - -## [Unreleased] - -### Added - -### Changed - -### Deprecated - -### Removed - -### Fixed - -### Security - -## [0.20.0] - 2021-04-23 - -### Added - -- The OTLP exporter now has two new convenience functions, `NewExportPipeline` and `InstallNewPipeline`, setup and install the exporter in tracing and metrics pipelines. (#1373) -- Adds semantic conventions for exceptions. (#1492) -- Added Jaeger Environment variables: `OTEL_EXPORTER_JAEGER_AGENT_HOST`, `OTEL_EXPORTER_JAEGER_AGENT_PORT` - These environment variables can be used to override Jaeger agent hostname and port (#1752) -- Option `ExportTimeout` was added to batch span processor. (#1755) -- `trace.TraceFlags` is now a defined type over `byte` and `WithSampled(bool) TraceFlags` and `IsSampled() bool` methods have been added to it. (#1770) -- The `Event` and `Link` struct types from the `go.opentelemetry.io/otel` package now include a `DroppedAttributeCount` field to record the number of attributes that were not recorded due to configured limits being reached. (#1771) -- The Jaeger exporter now reports dropped attributes for a Span event in the exported log. (#1771) -- Adds test to check BatchSpanProcessor ignores `OnEnd` and `ForceFlush` post `Shutdown`. (#1772) -- Extract resource attributes from the `OTEL_RESOURCE_ATTRIBUTES` environment variable and merge them with the `resource.Default` resource as well as resources provided to the `TracerProvider` and metric `Controller`. (#1785) -- Added `WithOSType` resource configuration option to set OS (Operating System) type resource attribute (`os.type`). (#1788) -- Added `WithProcess*` resource configuration options to set Process resource attributes. (#1788) - - `process.pid` - - `process.executable.name` - - `process.executable.path` - - `process.command_args` - - `process.owner` - - `process.runtime.name` - - `process.runtime.version` - - `process.runtime.description` -- Adds `k8s.node.name` and `k8s.node.uid` attribute keys to the `semconv` package. (#1789) -- Added support for configuring OTLP/HTTP and OTLP/gRPC Endpoints, TLS Certificates, Headers, Compression and Timeout via Environment Variables. (#1758, #1769 and #1811) - - `OTEL_EXPORTER_OTLP_ENDPOINT` - - `OTEL_EXPORTER_OTLP_TRACES_ENDPOINT` - - `OTEL_EXPORTER_OTLP_METRICS_ENDPOINT` - - `OTEL_EXPORTER_OTLP_HEADERS` - - `OTEL_EXPORTER_OTLP_TRACES_HEADERS` - - `OTEL_EXPORTER_OTLP_METRICS_HEADERS` - - `OTEL_EXPORTER_OTLP_COMPRESSION` - - `OTEL_EXPORTER_OTLP_TRACES_COMPRESSION` - - `OTEL_EXPORTER_OTLP_METRICS_COMPRESSION` - - `OTEL_EXPORTER_OTLP_TIMEOUT` - - `OTEL_EXPORTER_OTLP_TRACES_TIMEOUT` - - `OTEL_EXPORTER_OTLP_METRICS_TIMEOUT` - - `OTEL_EXPORTER_OTLP_CERTIFICATE` - - `OTEL_EXPORTER_OTLP_TRACES_CERTIFICATE` - - `OTEL_EXPORTER_OTLP_METRICS_CERTIFICATE` -- Adds `otlpgrpc.WithTimeout` option for configuring timeout to the otlp/gRPC exporter. (#1821) - -### Fixed - -- The `Span.IsRecording` implementation from `go.opentelemetry.io/otel/sdk/trace` always returns false when not being sampled. (#1750) -- The Jaeger exporter now correctly sets tags for the Span status code and message. - This means it uses the correct tag keys (`"otel.status_code"`, `"otel.status_description"`) and does not set the status message as a tag unless it is set on the span. (#1761) -- The Jaeger exporter now correctly records Span event's names using the `"event"` key for a tag. - Additionally, this tag is overridden, as specified in the OTel specification, if the event contains an attribute with that key. (#1768) -- Zipkin Exporter: Ensure mapping between OTel and Zipkin span data complies with the specification. (#1688) -- Fixed typo for default service name in Jaeger Exporter. (#1797) -- Fix flaky OTLP for the reconnnection of the client connection. (#1527, #1814) - -### Changed - -- Span `RecordError` now records an `exception` event to comply with the semantic convention specification. (#1492) -- Jaeger exporter was updated to use thrift v0.14.1. (#1712) -- Migrate from using internally built and maintained version of the OTLP to the one hosted at `go.opentelemetry.io/proto/otlp`. (#1713) -- Migrate from using `github.com/gogo/protobuf` to `google.golang.org/protobuf` to match `go.opentelemetry.io/proto/otlp`. (#1713) -- The storage of a local or remote Span in a `context.Context` using its SpanContext is unified to store just the current Span. - The Span's SpanContext can now self-identify as being remote or not. - This means that `"go.opentelemetry.io/otel/trace".ContextWithRemoteSpanContext` will now overwrite any existing current Span, not just existing remote Spans, and make it the current Span in a `context.Context`. (#1731) -- Improve OTLP/gRPC exporter connection errors. (#1737) -- Information about a parent span context in a `"go.opentelemetry.io/otel/export/trace".SpanSnapshot` is unified in a new `Parent` field. - The existing `ParentSpanID` and `HasRemoteParent` fields are removed in favor of this. (#1748) -- The `ParentContext` field of the `"go.opentelemetry.io/otel/sdk/trace".SamplingParameters` is updated to hold a `context.Context` containing the parent span. - This changes it to make `SamplingParameters` conform with the OpenTelemetry specification. (#1749) -- Updated Jaeger Environment Variables: `JAEGER_ENDPOINT`, `JAEGER_USER`, `JAEGER_PASSWORD` - to `OTEL_EXPORTER_JAEGER_ENDPOINT`, `OTEL_EXPORTER_JAEGER_USER`, `OTEL_EXPORTER_JAEGER_PASSWORD` - in compliance with OTel spec (#1752) -- Modify `BatchSpanProcessor.ForceFlush` to abort after timeout/cancellation. (#1757) -- The `DroppedAttributeCount` field of the `Span` in the `go.opentelemetry.io/otel` package now only represents the number of attributes dropped for the span itself. - It no longer is a conglomerate of itself, events, and link attributes that have been dropped. (#1771) -- Make `ExportSpans` in Jaeger Exporter honor context deadline. (#1773) -- Modify Zipkin Exporter default service name, use default resouce's serviceName instead of empty. (#1777) -- The `go.opentelemetry.io/otel/sdk/export/trace` package is merged into the `go.opentelemetry.io/otel/sdk/trace` package. (#1778) -- The prometheus.InstallNewPipeline example is moved from comment to example test (#1796) -- The convenience functions for the stdout exporter have been updated to return the `TracerProvider` implementation and enable the shutdown of the exporter. (#1800) -- Replace the flush function returned from the Jaeger exporter's convenience creation functions (`InstallNewPipeline` and `NewExportPipeline`) with the `TracerProvider` implementation they create. - This enables the caller to shutdown and flush using the related `TracerProvider` methods. (#1822) -- Updated the Jaeger exporter to have a default enpoint, `http://localhost:14250`, for the collector. (#1824) -- Changed the function `WithCollectorEndpoint` in the Jaeger exporter to no longer accept an endpoint as an argument. - The endpoint can be passed with the `CollectorEndpointOption` using the `WithEndpoint` function or by setting the `OTEL_EXPORTER_JAEGER_ENDPOINT` environment variable value appropriately. (#1824) -- The Jaeger exporter no longer batches exported spans itself, instead it relies on the SDK's `BatchSpanProcessor` for this functionality. (#1830) -- The Jaeger exporter creation functions (`NewRawExporter`, `NewExportPipeline`, and `InstallNewPipeline`) no longer accept the removed `Option` type as a variadic argument. (#1830) - -### Removed - -- Removed Jaeger Environment variables: `JAEGER_SERVICE_NAME`, `JAEGER_DISABLED`, `JAEGER_TAGS` - These environment variables will no longer be used to override values of the Jaeger exporter (#1752) -- No longer set the links for a `Span` in `go.opentelemetry.io/otel/sdk/trace` that is configured to be a new root. - This is unspecified behavior that the OpenTelemetry community plans to standardize in the future. - To prevent backwards incompatible changes when it is specified, these links are removed. (#1726) -- Setting error status while recording error with Span from oteltest package. (#1729) -- The concept of a remote and local Span stored in a context is unified to just the current Span. - Because of this `"go.opentelemetry.io/otel/trace".RemoteSpanContextFromContext` is removed as it is no longer needed. - Instead, `"go.opentelemetry.io/otel/trace".SpanContextFromContex` can be used to return the current Span. - If needed, that Span's `SpanContext.IsRemote()` can then be used to determine if it is remote or not. (#1731) -- The `HasRemoteParent` field of the `"go.opentelemetry.io/otel/sdk/trace".SamplingParameters` is removed. - This field is redundant to the information returned from the `Remote` method of the `SpanContext` held in the `ParentContext` field. (#1749) -- The `trace.FlagsDebug` and `trace.FlagsDeferred` constants have been removed and will be localized to the B3 propagator. (#1770) -- Remove `Process` configuration, `WithProcessFromEnv` and `ProcessFromEnv`, and type from the Jaeger exporter package. - The information that could be configured in the `Process` struct should be configured in a `Resource` instead. (#1776, #1804) -- Remove the `WithDisabled` option from the Jaeger exporter. - To disable the exporter unregister it from the `TracerProvider` or use a no-operation `TracerProvider`. (#1806) -- Removed the functions `CollectorEndpointFromEnv` and `WithCollectorEndpointOptionFromEnv` from the Jaeger exporter. - These functions for retrieving specific environment variable values are redundant of other internal functions and - are not intended for end user use. (#1824) -- Removed the Jaeger exporter `WithSDKOptions` `Option`. - This option was used to set SDK options for the exporter creation convenience functions. - These functions are provided as a way to easily setup or install the exporter with what are deemed reasonable SDK settings for common use cases. - If the SDK needs to be configured differently, the `NewRawExporter` function and direct setup of the SDK with the desired settings should be used. (#1825) -- The `WithBufferMaxCount` and `WithBatchMaxCount` `Option`s from the Jaeger exporter are removed. - The exporter no longer batches exports, instead relying on the SDK's `BatchSpanProcessor` for this functionality. (#1830) -- The Jaeger exporter `Option` type is removed. - The type is no longer used by the exporter to configure anything. - All of the previous configuration these options provided were duplicates of SDK configuration. - They have all been removed in favor of using the SDK configuration and focuses the exporter configuration to be only about the endpoints it will send telemetry to. (#1830) - -## [0.19.0] - 2021-03-18 - -### Added - -- Added `Marshaler` config option to `otlphttp` to enable otlp over json or protobufs. (#1586) -- A `ForceFlush` method to the `"go.opentelemetry.io/otel/sdk/trace".TracerProvider` to flush all registered `SpanProcessor`s. (#1608) -- Added `WithSampler` and `WithSpanLimits` to tracer provider. (#1633, #1702) -- `"go.opentelemetry.io/otel/trace".SpanContext` now has a `remote` property, and `IsRemote()` predicate, that is true when the `SpanContext` has been extracted from remote context data. (#1701) -- A `Valid` method to the `"go.opentelemetry.io/otel/attribute".KeyValue` type. (#1703) - -### Changed - -- `trace.SpanContext` is now immutable and has no exported fields. (#1573) - - `trace.NewSpanContext()` can be used in conjunction with the `trace.SpanContextConfig` struct to initialize a new `SpanContext` where all values are known. -- Update the `ForceFlush` method signature to the `"go.opentelemetry.io/otel/sdk/trace".SpanProcessor` to accept a `context.Context` and return an error. (#1608) -- Update the `Shutdown` method to the `"go.opentelemetry.io/otel/sdk/trace".TracerProvider` return an error on shutdown failure. (#1608) -- The SimpleSpanProcessor will now shut down the enclosed `SpanExporter` and gracefully ignore subsequent calls to `OnEnd` after `Shutdown` is called. (#1612) -- `"go.opentelemetry.io/sdk/metric/controller.basic".WithPusher` is replaced with `WithExporter` to provide consistent naming across project. (#1656) -- Added non-empty string check for trace `Attribute` keys. (#1659) -- Add `description` to SpanStatus only when `StatusCode` is set to error. (#1662) -- Jaeger exporter falls back to `resource.Default`'s `service.name` if the exported Span does not have one. (#1673) -- Jaeger exporter populates Jaeger's Span Process from Resource. (#1673) -- Renamed the `LabelSet` method of `"go.opentelemetry.io/otel/sdk/resource".Resource` to `Set`. (#1692) -- Changed `WithSDK` to `WithSDKOptions` to accept variadic arguments of `TracerProviderOption` type in `go.opentelemetry.io/otel/exporters/trace/jaeger` package. (#1693) -- Changed `WithSDK` to `WithSDKOptions` to accept variadic arguments of `TracerProviderOption` type in `go.opentelemetry.io/otel/exporters/trace/zipkin` package. (#1693) - -### Removed - -- Removed `serviceName` parameter from Zipkin exporter and uses resource instead. (#1549) -- Removed `WithConfig` from tracer provider to avoid overriding configuration. (#1633) -- Removed the exported `SimpleSpanProcessor` and `BatchSpanProcessor` structs. - These are now returned as a SpanProcessor interface from their respective constructors. (#1638) -- Removed `WithRecord()` from `trace.SpanOption` when creating a span. (#1660) -- Removed setting status to `Error` while recording an error as a span event in `RecordError`. (#1663) -- Removed `jaeger.WithProcess` configuration option. (#1673) -- Removed `ApplyConfig` method from `"go.opentelemetry.io/otel/sdk/trace".TracerProvider` and the now unneeded `Config` struct. (#1693) - -### Fixed - -- Jaeger Exporter: Ensure mapping between OTEL and Jaeger span data complies with the specification. (#1626) -- `SamplingResult.TraceState` is correctly propagated to a newly created span's `SpanContext`. (#1655) -- The `otel-collector` example now correctly flushes metric events prior to shutting down the exporter. (#1678) -- Do not set span status message in `SpanStatusFromHTTPStatusCode` if it can be inferred from `http.status_code`. (#1681) -- Synchronization issues in global trace delegate implementation. (#1686) -- Reduced excess memory usage by global `TracerProvider`. (#1687) - -## [0.18.0] - 2021-03-03 - -### Added - -- Added `resource.Default()` for use with meter and tracer providers. (#1507) -- `AttributePerEventCountLimit` and `AttributePerLinkCountLimit` for `SpanLimits`. (#1535) -- Added `Keys()` method to `propagation.TextMapCarrier` and `propagation.HeaderCarrier` to adapt `http.Header` to this interface. (#1544) -- Added `code` attributes to `go.opentelemetry.io/otel/semconv` package. (#1558) -- Compatibility testing suite in the CI system for the following systems. (#1567) - | OS | Go Version | Architecture | - | ------- | ---------- | ------------ | - | Ubuntu | 1.15 | amd64 | - | Ubuntu | 1.14 | amd64 | - | Ubuntu | 1.15 | 386 | - | Ubuntu | 1.14 | 386 | - | MacOS | 1.15 | amd64 | - | MacOS | 1.14 | amd64 | - | Windows | 1.15 | amd64 | - | Windows | 1.14 | amd64 | - | Windows | 1.15 | 386 | - | Windows | 1.14 | 386 | - -### Changed - -- Replaced interface `oteltest.SpanRecorder` with its existing implementation - `StandardSpanRecorder`. (#1542) -- Default span limit values to 128. (#1535) -- Rename `MaxEventsPerSpan`, `MaxAttributesPerSpan` and `MaxLinksPerSpan` to `EventCountLimit`, `AttributeCountLimit` and `LinkCountLimit`, and move these fields into `SpanLimits`. (#1535) -- Renamed the `otel/label` package to `otel/attribute`. (#1541) -- Vendor the Jaeger exporter's dependency on Apache Thrift. (#1551) -- Parallelize the CI linting and testing. (#1567) -- Stagger timestamps in exact aggregator tests. (#1569) -- Changed all examples to use `WithBatchTimeout(5 * time.Second)` rather than `WithBatchTimeout(5)`. (#1621) -- Prevent end-users from implementing some interfaces (#1575) -``` - "otel/exporters/otlp/otlphttp".Option - "otel/exporters/stdout".Option - "otel/oteltest".Option - "otel/trace".TracerOption - "otel/trace".SpanOption - "otel/trace".EventOption - "otel/trace".LifeCycleOption - "otel/trace".InstrumentationOption - "otel/sdk/resource".Option - "otel/sdk/trace".ParentBasedSamplerOption - "otel/sdk/trace".ReadOnlySpan - "otel/sdk/trace".ReadWriteSpan -``` -### Removed - -- Removed attempt to resample spans upon changing the span name with `span.SetName()`. (#1545) -- The `test-benchmark` is no longer a dependency of the `precommit` make target. (#1567) -- Removed the `test-386` make target. - This was replaced with a full compatibility testing suite (i.e. multi OS/arch) in the CI system. (#1567) - -### Fixed - -- The sequential timing check of timestamps in the stdout exporter are now setup explicitly to be sequential (#1571). (#1572) -- Windows build of Jaeger tests now compiles with OS specific functions (#1576). (#1577) -- The sequential timing check of timestamps of go.opentelemetry.io/otel/sdk/metric/aggregator/lastvalue are now setup explicitly to be sequential (#1578). (#1579) -- Validate tracestate header keys with vendors according to the W3C TraceContext specification (#1475). (#1581) -- The OTLP exporter includes related labels for translations of a GaugeArray (#1563). (#1570) - -## [0.17.0] - 2021-02-12 - -### Changed - -- Rename project default branch from `master` to `main`. (#1505) -- Reverse order in which `Resource` attributes are merged, per change in spec. (#1501) -- Add tooling to maintain "replace" directives in go.mod files automatically. (#1528) -- Create new modules: otel/metric, otel/trace, otel/oteltest, otel/sdk/export/metric, otel/sdk/metric (#1528) -- Move metric-related public global APIs from otel to otel/metric/global. (#1528) - -## Fixed - -- Fixed otlpgrpc reconnection issue. -- The example code in the README.md of `go.opentelemetry.io/otel/exporters/otlp` is moved to a compiled example test and used the new `WithAddress` instead of `WithEndpoint`. (#1513) -- The otel-collector example now uses the default OTLP receiver port of the collector. - -## [0.16.0] - 2021-01-13 - -### Added - -- Add the `ReadOnlySpan` and `ReadWriteSpan` interfaces to provide better control for accessing span data. (#1360) -- `NewGRPCDriver` function returns a `ProtocolDriver` that maintains a single gRPC connection to the collector. (#1369) -- Added documentation about the project's versioning policy. (#1388) -- Added `NewSplitDriver` for OTLP exporter that allows sending traces and metrics to different endpoints. (#1418) -- Added codeql worfklow to GitHub Actions (#1428) -- Added Gosec workflow to GitHub Actions (#1429) -- Add new HTTP driver for OTLP exporter in `exporters/otlp/otlphttp`. Currently it only supports the binary protobuf payloads. (#1420) -- Add an OpenCensus exporter bridge. (#1444) - -### Changed - -- Rename `internal/testing` to `internal/internaltest`. (#1449) -- Rename `export.SpanData` to `export.SpanSnapshot` and use it only for exporting spans. (#1360) -- Store the parent's full `SpanContext` rather than just its span ID in the `span` struct. (#1360) -- Improve span duration accuracy. (#1360) -- Migrated CI/CD from CircleCI to GitHub Actions (#1382) -- Remove duplicate checkout from GitHub Actions workflow (#1407) -- Metric `array` aggregator renamed `exact` to match its `aggregation.Kind` (#1412) -- Metric `exact` aggregator includes per-point timestamps (#1412) -- Metric stdout exporter uses MinMaxSumCount aggregator for ValueRecorder instruments (#1412) -- `NewExporter` from `exporters/otlp` now takes a `ProtocolDriver` as a parameter. (#1369) -- Many OTLP Exporter options became gRPC ProtocolDriver options. (#1369) -- Unify endpoint API that related to OTel exporter. (#1401) -- Optimize metric histogram aggregator to re-use its slice of buckets. (#1435) -- Metric aggregator Count() and histogram Bucket.Counts are consistently `uint64`. (1430) -- Histogram aggregator accepts functional options, uses default boundaries if none given. (#1434) -- `SamplingResult` now passed a `Tracestate` from the parent `SpanContext` (#1432) -- Moved gRPC driver for OTLP exporter to `exporters/otlp/otlpgrpc`. (#1420) -- The `TraceContext` propagator now correctly propagates `TraceState` through the `SpanContext`. (#1447) -- Metric Push and Pull Controller components are combined into a single "basic" Controller: - - `WithExporter()` and `Start()` to configure Push behavior - - `Start()` is optional; use `Collect()` and `ForEach()` for Pull behavior - - `Start()` and `Stop()` accept Context. (#1378) -- The `Event` type is moved from the `otel/sdk/export/trace` package to the `otel/trace` API package. (#1452) - -### Removed - -- Remove `errUninitializedSpan` as its only usage is now obsolete. (#1360) -- Remove Metric export functionality related to quantiles and summary data points: this is not specified (#1412) -- Remove DDSketch metric aggregator; our intention is to re-introduce this as an option of the histogram aggregator after [new OTLP histogram data types](https://github.com/open-telemetry/opentelemetry-proto/pull/226) are released (#1412) - -### Fixed - -- `BatchSpanProcessor.Shutdown()` will now shutdown underlying `export.SpanExporter`. (#1443) - -## [0.15.0] - 2020-12-10 - -### Added - -- The `WithIDGenerator` `TracerProviderOption` is added to the `go.opentelemetry.io/otel/trace` package to configure an `IDGenerator` for the `TracerProvider`. (#1363) - -### Changed - -- The Zipkin exporter now uses the Span status code to determine. (#1328) -- `NewExporter` and `Start` functions in `go.opentelemetry.io/otel/exporters/otlp` now receive `context.Context` as a first parameter. (#1357) -- Move the OpenCensus example into `example` directory. (#1359) -- Moved the SDK's `internal.IDGenerator` interface in to the `sdk/trace` package to enable support for externally-defined ID generators. (#1363) -- Bump `github.com/google/go-cmp` from 0.5.3 to 0.5.4 (#1374) -- Bump `github.com/golangci/golangci-lint` in `/internal/tools` (#1375) - -### Fixed - -- Metric SDK `SumObserver` and `UpDownSumObserver` instruments correctness fixes. (#1381) - -## [0.14.0] - 2020-11-19 - -### Added - -- An `EventOption` and the related `NewEventConfig` function are added to the `go.opentelemetry.io/otel` package to configure Span events. (#1254) -- A `TextMapPropagator` and associated `TextMapCarrier` are added to the `go.opentelemetry.io/otel/oteltest` package to test `TextMap` type propagators and their use. (#1259) -- `SpanContextFromContext` returns `SpanContext` from context. (#1255) -- `TraceState` has been added to `SpanContext`. (#1340) -- `DeploymentEnvironmentKey` added to `go.opentelemetry.io/otel/semconv` package. (#1323) -- Add an OpenCensus to OpenTelemetry tracing bridge. (#1305) -- Add a parent context argument to `SpanProcessor.OnStart` to follow the specification. (#1333) -- Add missing tests for `sdk/trace/attributes_map.go`. (#1337) - -### Changed - -- Move the `go.opentelemetry.io/otel/api/trace` package into `go.opentelemetry.io/otel/trace` with the following changes. (#1229) (#1307) - - `ID` has been renamed to `TraceID`. - - `IDFromHex` has been renamed to `TraceIDFromHex`. - - `EmptySpanContext` is removed. -- Move the `go.opentelemetry.io/otel/api/trace/tracetest` package into `go.opentelemetry.io/otel/oteltest`. (#1229) -- OTLP Exporter updates: - - supports OTLP v0.6.0 (#1230, #1354) - - supports configurable aggregation temporality (default: Cumulative, optional: Stateless). (#1296) -- The Sampler is now called on local child spans. (#1233) -- The `Kind` type from the `go.opentelemetry.io/otel/api/metric` package was renamed to `InstrumentKind` to more specifically describe what it is and avoid semantic ambiguity. (#1240) -- The `MetricKind` method of the `Descriptor` type in the `go.opentelemetry.io/otel/api/metric` package was renamed to `Descriptor.InstrumentKind`. - This matches the returned type and fixes misuse of the term metric. (#1240) -- Move test harness from the `go.opentelemetry.io/otel/api/apitest` package into `go.opentelemetry.io/otel/oteltest`. (#1241) -- Move the `go.opentelemetry.io/otel/api/metric/metrictest` package into `go.opentelemetry.io/oteltest` as part of #964. (#1252) -- Move the `go.opentelemetry.io/otel/api/metric` package into `go.opentelemetry.io/otel/metric` as part of #1303. (#1321) -- Move the `go.opentelemetry.io/otel/api/metric/registry` package into `go.opentelemetry.io/otel/metric/registry` as a part of #1303. (#1316) -- Move the `Number` type (together with related functions) from `go.opentelemetry.io/otel/api/metric` package into `go.opentelemetry.io/otel/metric/number` as a part of #1303. (#1316) -- The function signature of the Span `AddEvent` method in `go.opentelemetry.io/otel` is updated to no longer take an unused context and instead take a required name and a variable number of `EventOption`s. (#1254) -- The function signature of the Span `RecordError` method in `go.opentelemetry.io/otel` is updated to no longer take an unused context and instead take a required error value and a variable number of `EventOption`s. (#1254) -- Move the `go.opentelemetry.io/otel/api/global` package to `go.opentelemetry.io/otel`. (#1262) (#1330) -- Move the `Version` function from `go.opentelemetry.io/otel/sdk` to `go.opentelemetry.io/otel`. (#1330) -- Rename correlation context header from `"otcorrelations"` to `"baggage"` to match the OpenTelemetry specification. (#1267) -- Fix `Code.UnmarshalJSON` to work with valid JSON only. (#1276) -- The `resource.New()` method changes signature to support builtin attributes and functional options, including `telemetry.sdk.*` and - `host.name` semantic conventions; the former method is renamed `resource.NewWithAttributes`. (#1235) -- The Prometheus exporter now exports non-monotonic counters (i.e. `UpDownCounter`s) as gauges. (#1210) -- Correct the `Span.End` method documentation in the `otel` API to state updates are not allowed on a span after it has ended. (#1310) -- Updated span collection limits for attribute, event and link counts to 1000 (#1318) -- Renamed `semconv.HTTPUrlKey` to `semconv.HTTPURLKey`. (#1338) - -### Removed - -- The `ErrInvalidHexID`, `ErrInvalidTraceIDLength`, `ErrInvalidSpanIDLength`, `ErrInvalidSpanIDLength`, or `ErrNilSpanID` from the `go.opentelemetry.io/otel` package are unexported now. (#1243) -- The `AddEventWithTimestamp` method on the `Span` interface in `go.opentelemetry.io/otel` is removed due to its redundancy. - It is replaced by using the `AddEvent` method with a `WithTimestamp` option. (#1254) -- The `MockSpan` and `MockTracer` types are removed from `go.opentelemetry.io/otel/oteltest`. - `Tracer` and `Span` from the same module should be used in their place instead. (#1306) -- `WorkerCount` option is removed from `go.opentelemetry.io/otel/exporters/otlp`. (#1350) -- Remove the following labels types: INT32, UINT32, UINT64 and FLOAT32. (#1314) - -### Fixed - -- Rename `MergeItererator` to `MergeIterator` in the `go.opentelemetry.io/otel/label` package. (#1244) -- The `go.opentelemetry.io/otel/api/global` packages global TextMapPropagator now delegates functionality to a globally set delegate for all previously returned propagators. (#1258) -- Fix condition in `label.Any`. (#1299) -- Fix global `TracerProvider` to pass options to its configured provider. (#1329) -- Fix missing handler for `ExactKind` aggregator in OTLP metrics transformer (#1309) - -## [0.13.0] - 2020-10-08 - -### Added - -- OTLP Metric exporter supports Histogram aggregation. (#1209) -- The `Code` struct from the `go.opentelemetry.io/otel/codes` package now supports JSON marshaling and unmarshaling as well as implements the `Stringer` interface. (#1214) -- A Baggage API to implement the OpenTelemetry specification. (#1217) -- Add Shutdown method to sdk/trace/provider, shutdown processors in the order they were registered. (#1227) - -### Changed - -- Set default propagator to no-op propagator. (#1184) -- The `HTTPSupplier`, `HTTPExtractor`, `HTTPInjector`, and `HTTPPropagator` from the `go.opentelemetry.io/otel/api/propagation` package were replaced with unified `TextMapCarrier` and `TextMapPropagator` in the `go.opentelemetry.io/otel/propagation` package. (#1212) (#1325) -- The `New` function from the `go.opentelemetry.io/otel/api/propagation` package was replaced with `NewCompositeTextMapPropagator` in the `go.opentelemetry.io/otel` package. (#1212) -- The status codes of the `go.opentelemetry.io/otel/codes` package have been updated to match the latest OpenTelemetry specification. - They now are `Unset`, `Error`, and `Ok`. - They no longer track the gRPC codes. (#1214) -- The `StatusCode` field of the `SpanData` struct in the `go.opentelemetry.io/otel/sdk/export/trace` package now uses the codes package from this package instead of the gRPC project. (#1214) -- Move the `go.opentelemetry.io/otel/api/baggage` package into `go.opentelemetry.io/otel/baggage`. (#1217) (#1325) -- A `Shutdown` method of `SpanProcessor` and all its implementations receives a context and returns an error. (#1264) - -### Fixed - -- Copies of data from arrays and slices passed to `go.opentelemetry.io/otel/label.ArrayValue()` are now used in the returned `Value` instead of using the mutable data itself. (#1226) - -### Removed - -- The `ExtractHTTP` and `InjectHTTP` functions from the `go.opentelemetry.io/otel/api/propagation` package were removed. (#1212) -- The `Propagators` interface from the `go.opentelemetry.io/otel/api/propagation` package was removed to conform to the OpenTelemetry specification. - The explicit `TextMapPropagator` type can be used in its place as this is the `Propagator` type the specification defines. (#1212) -- The `SetAttribute` method of the `Span` from the `go.opentelemetry.io/otel/api/trace` package was removed given its redundancy with the `SetAttributes` method. (#1216) -- The internal implementation of Baggage storage is removed in favor of using the new Baggage API functionality. (#1217) -- Remove duplicate hostname key `HostHostNameKey` in Resource semantic conventions. (#1219) -- Nested array/slice support has been removed. (#1226) - -## [0.12.0] - 2020-09-24 - -### Added - -- A `SpanConfigure` function in `go.opentelemetry.io/otel/api/trace` to create a new `SpanConfig` from `SpanOption`s. (#1108) -- In the `go.opentelemetry.io/otel/api/trace` package, `NewTracerConfig` was added to construct new `TracerConfig`s. - This addition was made to conform with our project option conventions. (#1155) -- Instrumentation library information was added to the Zipkin exporter. (#1119) -- The `SpanProcessor` interface now has a `ForceFlush()` method. (#1166) -- More semantic conventions for k8s as resource attributes. (#1167) - -### Changed - -- Add reconnecting udp connection type to Jaeger exporter. - This change adds a new optional implementation of the udp conn interface used to detect changes to an agent's host dns record. - It then adopts the new destination address to ensure the exporter doesn't get stuck. This change was ported from jaegertracing/jaeger-client-go#520. (#1063) -- Replace `StartOption` and `EndOption` in `go.opentelemetry.io/otel/api/trace` with `SpanOption`. - This change is matched by replacing the `StartConfig` and `EndConfig` with a unified `SpanConfig`. (#1108) -- Replace the `LinkedTo` span option in `go.opentelemetry.io/otel/api/trace` with `WithLinks`. - This is be more consistent with our other option patterns, i.e. passing the item to be configured directly instead of its component parts, and provides a cleaner function signature. (#1108) -- The `go.opentelemetry.io/otel/api/trace` `TracerOption` was changed to an interface to conform to project option conventions. (#1109) -- Move the `B3` and `TraceContext` from within the `go.opentelemetry.io/otel/api/trace` package to their own `go.opentelemetry.io/otel/propagators` package. - This removal of the propagators is reflective of the OpenTelemetry specification for these propagators as well as cleans up the `go.opentelemetry.io/otel/api/trace` API. (#1118) -- Rename Jaeger tags used for instrumentation library information to reflect changes in OpenTelemetry specification. (#1119) -- Rename `ProbabilitySampler` to `TraceIDRatioBased` and change semantics to ignore parent span sampling status. (#1115) -- Move `tools` package under `internal`. (#1141) -- Move `go.opentelemetry.io/otel/api/correlation` package to `go.opentelemetry.io/otel/api/baggage`. (#1142) - The `correlation.CorrelationContext` propagator has been renamed `baggage.Baggage`. Other exported functions and types are unchanged. -- Rename `ParentOrElse` sampler to `ParentBased` and allow setting samplers depending on parent span. (#1153) -- In the `go.opentelemetry.io/otel/api/trace` package, `SpanConfigure` was renamed to `NewSpanConfig`. (#1155) -- Change `dependabot.yml` to add a `Skip Changelog` label to dependabot-sourced PRs. (#1161) -- The [configuration style guide](https://github.com/open-telemetry/opentelemetry-go/blob/master/CONTRIBUTING.md#config) has been updated to - recommend the use of `newConfig()` instead of `configure()`. (#1163) -- The `otlp.Config` type has been unexported and changed to `otlp.config`, along with its initializer. (#1163) -- Ensure exported interface types include parameter names and update the - Style Guide to reflect this styling rule. (#1172) -- Don't consider unset environment variable for resource detection to be an error. (#1170) -- Rename `go.opentelemetry.io/otel/api/metric.ConfigureInstrument` to `NewInstrumentConfig` and - `go.opentelemetry.io/otel/api/metric.ConfigureMeter` to `NewMeterConfig`. -- ValueObserver instruments use LastValue aggregator by default. (#1165) -- OTLP Metric exporter supports LastValue aggregation. (#1165) -- Move the `go.opentelemetry.io/otel/api/unit` package to `go.opentelemetry.io/otel/unit`. (#1185) -- Rename `Provider` to `MeterProvider` in the `go.opentelemetry.io/otel/api/metric` package. (#1190) -- Rename `NoopProvider` to `NoopMeterProvider` in the `go.opentelemetry.io/otel/api/metric` package. (#1190) -- Rename `NewProvider` to `NewMeterProvider` in the `go.opentelemetry.io/otel/api/metric/metrictest` package. (#1190) -- Rename `Provider` to `MeterProvider` in the `go.opentelemetry.io/otel/api/metric/registry` package. (#1190) -- Rename `NewProvider` to `NewMeterProvider` in the `go.opentelemetry.io/otel/api/metri/registryc` package. (#1190) -- Rename `Provider` to `TracerProvider` in the `go.opentelemetry.io/otel/api/trace` package. (#1190) -- Rename `NoopProvider` to `NoopTracerProvider` in the `go.opentelemetry.io/otel/api/trace` package. (#1190) -- Rename `Provider` to `TracerProvider` in the `go.opentelemetry.io/otel/api/trace/tracetest` package. (#1190) -- Rename `NewProvider` to `NewTracerProvider` in the `go.opentelemetry.io/otel/api/trace/tracetest` package. (#1190) -- Rename `WrapperProvider` to `WrapperTracerProvider` in the `go.opentelemetry.io/otel/bridge/opentracing` package. (#1190) -- Rename `NewWrapperProvider` to `NewWrapperTracerProvider` in the `go.opentelemetry.io/otel/bridge/opentracing` package. (#1190) -- Rename `Provider` method of the pull controller to `MeterProvider` in the `go.opentelemetry.io/otel/sdk/metric/controller/pull` package. (#1190) -- Rename `Provider` method of the push controller to `MeterProvider` in the `go.opentelemetry.io/otel/sdk/metric/controller/push` package. (#1190) -- Rename `ProviderOptions` to `TracerProviderConfig` in the `go.opentelemetry.io/otel/sdk/trace` package. (#1190) -- Rename `ProviderOption` to `TracerProviderOption` in the `go.opentelemetry.io/otel/sdk/trace` package. (#1190) -- Rename `Provider` to `TracerProvider` in the `go.opentelemetry.io/otel/sdk/trace` package. (#1190) -- Rename `NewProvider` to `NewTracerProvider` in the `go.opentelemetry.io/otel/sdk/trace` package. (#1190) -- Renamed `SamplingDecision` values to comply with OpenTelemetry specification change. (#1192) -- Renamed Zipkin attribute names from `ot.status_code & ot.status_description` to `otel.status_code & otel.status_description`. (#1201) -- The default SDK now invokes registered `SpanProcessor`s in the order they were registered with the `TracerProvider`. (#1195) -- Add test of spans being processed by the `SpanProcessor`s in the order they were registered. (#1203) - -### Removed - -- Remove the B3 propagator from `go.opentelemetry.io/otel/propagators`. It is now located in the - `go.opentelemetry.io/contrib/propagators/` module. (#1191) -- Remove the semantic convention for HTTP status text, `HTTPStatusTextKey` from package `go.opentelemetry.io/otel/semconv`. (#1194) - -### Fixed - -- Zipkin example no longer mentions `ParentSampler`, corrected to `ParentBased`. (#1171) -- Fix missing shutdown processor in otel-collector example. (#1186) -- Fix missing shutdown processor in basic and namedtracer examples. (#1197) - -## [0.11.0] - 2020-08-24 - -### Added - -- Support for exporting array-valued attributes via OTLP. (#992) -- `Noop` and `InMemory` `SpanBatcher` implementations to help with testing integrations. (#994) -- Support for filtering metric label sets. (#1047) -- A dimensionality-reducing metric Processor. (#1057) -- Integration tests for more OTel Collector Attribute types. (#1062) -- A new `WithSpanProcessor` `ProviderOption` is added to the `go.opentelemetry.io/otel/sdk/trace` package to create a `Provider` and automatically register the `SpanProcessor`. (#1078) - -### Changed - -- Rename `sdk/metric/processor/test` to `sdk/metric/processor/processortest`. (#1049) -- Rename `sdk/metric/controller/test` to `sdk/metric/controller/controllertest`. (#1049) -- Rename `api/testharness` to `api/apitest`. (#1049) -- Rename `api/trace/testtrace` to `api/trace/tracetest`. (#1049) -- Change Metric Processor to merge multiple observations. (#1024) -- The `go.opentelemetry.io/otel/bridge/opentracing` bridge package has been made into its own module. - This removes the package dependencies of this bridge from the rest of the OpenTelemetry based project. (#1038) -- Renamed `go.opentelemetry.io/otel/api/standard` package to `go.opentelemetry.io/otel/semconv` to avoid the ambiguous and generic name `standard` and better describe the package as containing OpenTelemetry semantic conventions. (#1016) -- The environment variable used for resource detection has been changed from `OTEL_RESOURCE_LABELS` to `OTEL_RESOURCE_ATTRIBUTES` (#1042) -- Replace `WithSyncer` with `WithBatcher` in examples. (#1044) -- Replace the `google.golang.org/grpc/codes` dependency in the API with an equivalent `go.opentelemetry.io/otel/codes` package. (#1046) -- Merge the `go.opentelemetry.io/otel/api/label` and `go.opentelemetry.io/otel/api/kv` into the new `go.opentelemetry.io/otel/label` package. (#1060) -- Unify Callback Function Naming. - Rename `*Callback` with `*Func`. (#1061) -- CI builds validate against last two versions of Go, dropping 1.13 and adding 1.15. (#1064) -- The `go.opentelemetry.io/otel/sdk/export/trace` interfaces `SpanSyncer` and `SpanBatcher` have been replaced with a specification compliant `Exporter` interface. - This interface still supports the export of `SpanData`, but only as a slice. - Implementation are also required now to return any error from `ExportSpans` if one occurs as well as implement a `Shutdown` method for exporter clean-up. (#1078) -- The `go.opentelemetry.io/otel/sdk/trace` `NewBatchSpanProcessor` function no longer returns an error. - If a `nil` exporter is passed as an argument to this function, instead of it returning an error, it now returns a `BatchSpanProcessor` that handles the export of `SpanData` by not taking any action. (#1078) -- The `go.opentelemetry.io/otel/sdk/trace` `NewProvider` function to create a `Provider` no longer returns an error, instead only a `*Provider`. - This change is related to `NewBatchSpanProcessor` not returning an error which was the only error this function would return. (#1078) - -### Removed - -- Duplicate, unused API sampler interface. (#999) - Use the [`Sampler` interface](https://github.com/open-telemetry/opentelemetry-go/blob/v0.11.0/sdk/trace/sampling.go) provided by the SDK instead. -- The `grpctrace` instrumentation was moved to the `go.opentelemetry.io/contrib` repository and out of this repository. - This move includes moving the `grpc` example to the `go.opentelemetry.io/contrib` as well. (#1027) -- The `WithSpan` method of the `Tracer` interface. - The functionality this method provided was limited compared to what a user can provide themselves. - It was removed with the understanding that if there is sufficient user need it can be added back based on actual user usage. (#1043) -- The `RegisterSpanProcessor` and `UnregisterSpanProcessor` functions. - These were holdovers from an approach prior to the TracerProvider design. They were not used anymore. (#1077) -- The `oterror` package. (#1026) -- The `othttp` and `httptrace` instrumentations were moved to `go.opentelemetry.io/contrib`. (#1032) - -### Fixed - -- The `semconv.HTTPServerMetricAttributesFromHTTPRequest()` function no longer generates the high-cardinality `http.request.content.length` label. (#1031) -- Correct instrumentation version tag in Jaeger exporter. (#1037) -- The SDK span will now set an error event if the `End` method is called during a panic (i.e. it was deferred). (#1043) -- Move internally generated protobuf code from the `go.opentelemetry.io/otel` to the OTLP exporter to reduce dependency overhead. (#1050) -- The `otel-collector` example referenced outdated collector processors. (#1006) - -## [0.10.0] - 2020-07-29 - -This release migrates the default OpenTelemetry SDK into its own Go module, decoupling the SDK from the API and reducing dependencies for instrumentation packages. - -### Added - -- The Zipkin exporter now has `NewExportPipeline` and `InstallNewPipeline` constructor functions to match the common pattern. - These function build a new exporter with default SDK options and register the exporter with the `global` package respectively. (#944) -- Add propagator option for gRPC instrumentation. (#986) -- The `testtrace` package now tracks the `trace.SpanKind` for each span. (#987) - -### Changed - -- Replace the `RegisterGlobal` `Option` in the Jaeger exporter with an `InstallNewPipeline` constructor function. - This matches the other exporter constructor patterns and will register a new exporter after building it with default configuration. (#944) -- The trace (`go.opentelemetry.io/otel/exporters/trace/stdout`) and metric (`go.opentelemetry.io/otel/exporters/metric/stdout`) `stdout` exporters are now merged into a single exporter at `go.opentelemetry.io/otel/exporters/stdout`. - This new exporter was made into its own Go module to follow the pattern of all exporters and decouple it from the `go.opentelemetry.io/otel` module. (#956, #963) -- Move the `go.opentelemetry.io/otel/exporters/test` test package to `go.opentelemetry.io/otel/sdk/export/metric/metrictest`. (#962) -- The `go.opentelemetry.io/otel/api/kv/value` package was merged into the parent `go.opentelemetry.io/otel/api/kv` package. (#968) - - `value.Bool` was replaced with `kv.BoolValue`. - - `value.Int64` was replaced with `kv.Int64Value`. - - `value.Uint64` was replaced with `kv.Uint64Value`. - - `value.Float64` was replaced with `kv.Float64Value`. - - `value.Int32` was replaced with `kv.Int32Value`. - - `value.Uint32` was replaced with `kv.Uint32Value`. - - `value.Float32` was replaced with `kv.Float32Value`. - - `value.String` was replaced with `kv.StringValue`. - - `value.Int` was replaced with `kv.IntValue`. - - `value.Uint` was replaced with `kv.UintValue`. - - `value.Array` was replaced with `kv.ArrayValue`. -- Rename `Infer` to `Any` in the `go.opentelemetry.io/otel/api/kv` package. (#972) -- Change `othttp` to use the `httpsnoop` package to wrap the `ResponseWriter` so that optional interfaces (`http.Hijacker`, `http.Flusher`, etc.) that are implemented by the original `ResponseWriter`are also implemented by the wrapped `ResponseWriter`. (#979) -- Rename `go.opentelemetry.io/otel/sdk/metric/aggregator/test` package to `go.opentelemetry.io/otel/sdk/metric/aggregator/aggregatortest`. (#980) -- Make the SDK into its own Go module called `go.opentelemetry.io/otel/sdk`. (#985) -- Changed the default trace `Sampler` from `AlwaysOn` to `ParentOrElse(AlwaysOn)`. (#989) - -### Removed - -- The `IndexedAttribute` function from the `go.opentelemetry.io/otel/api/label` package was removed in favor of `IndexedLabel` which it was synonymous with. (#970) - -### Fixed - -- Bump github.com/golangci/golangci-lint from 1.28.3 to 1.29.0 in /tools. (#953) -- Bump github.com/google/go-cmp from 0.5.0 to 0.5.1. (#957) -- Use `global.Handle` for span export errors in the OTLP exporter. (#946) -- Correct Go language formatting in the README documentation. (#961) -- Remove default SDK dependencies from the `go.opentelemetry.io/otel/api` package. (#977) -- Remove default SDK dependencies from the `go.opentelemetry.io/otel/instrumentation` package. (#983) -- Move documented examples for `go.opentelemetry.io/otel/instrumentation/grpctrace` interceptors into Go example tests. (#984) - -## [0.9.0] - 2020-07-20 - -### Added - -- A new Resource Detector interface is included to allow resources to be automatically detected and included. (#939) -- A Detector to automatically detect resources from an environment variable. (#939) -- Github action to generate protobuf Go bindings locally in `internal/opentelemetry-proto-gen`. (#938) -- OTLP .proto files from `open-telemetry/opentelemetry-proto` imported as a git submodule under `internal/opentelemetry-proto`. - References to `github.com/open-telemetry/opentelemetry-proto` changed to `go.opentelemetry.io/otel/internal/opentelemetry-proto-gen`. (#942) - -### Changed - -- Non-nil value `struct`s for key-value pairs will be marshalled using JSON rather than `Sprintf`. (#948) - -### Removed - -- Removed dependency on `github.com/open-telemetry/opentelemetry-collector`. (#943) - -## [0.8.0] - 2020-07-09 - -### Added - -- The `B3Encoding` type to represent the B3 encoding(s) the B3 propagator can inject. - A value for HTTP supported encodings (Multiple Header: `MultipleHeader`, Single Header: `SingleHeader`) are included. (#882) -- The `FlagsDeferred` trace flag to indicate if the trace sampling decision has been deferred. (#882) -- The `FlagsDebug` trace flag to indicate if the trace is a debug trace. (#882) -- Add `peer.service` semantic attribute. (#898) -- Add database-specific semantic attributes. (#899) -- Add semantic convention for `faas.coldstart` and `container.id`. (#909) -- Add http content size semantic conventions. (#905) -- Include `http.request_content_length` in HTTP request basic attributes. (#905) -- Add semantic conventions for operating system process resource attribute keys. (#919) -- The Jaeger exporter now has a `WithBatchMaxCount` option to specify the maximum number of spans sent in a batch. (#931) - -### Changed - -- Update `CONTRIBUTING.md` to ask for updates to `CHANGELOG.md` with each pull request. (#879) -- Use lowercase header names for B3 Multiple Headers. (#881) -- The B3 propagator `SingleHeader` field has been replaced with `InjectEncoding`. - This new field can be set to combinations of the `B3Encoding` bitmasks and will inject trace information in these encodings. - If no encoding is set, the propagator will default to `MultipleHeader` encoding. (#882) -- The B3 propagator now extracts from either HTTP encoding of B3 (Single Header or Multiple Header) based on what is contained in the header. - Preference is given to Single Header encoding with Multiple Header being the fallback if Single Header is not found or is invalid. - This behavior change is made to dynamically support all correctly encoded traces received instead of having to guess the expected encoding prior to receiving. (#882) -- Extend semantic conventions for RPC. (#900) -- To match constant naming conventions in the `api/standard` package, the `FaaS*` key names are appended with a suffix of `Key`. (#920) - - `"api/standard".FaaSName` -> `FaaSNameKey` - - `"api/standard".FaaSID` -> `FaaSIDKey` - - `"api/standard".FaaSVersion` -> `FaaSVersionKey` - - `"api/standard".FaaSInstance` -> `FaaSInstanceKey` - -### Removed - -- The `FlagsUnused` trace flag is removed. - The purpose of this flag was to act as the inverse of `FlagsSampled`, the inverse of `FlagsSampled` is used instead. (#882) -- The B3 header constants (`B3SingleHeader`, `B3DebugFlagHeader`, `B3TraceIDHeader`, `B3SpanIDHeader`, `B3SampledHeader`, `B3ParentSpanIDHeader`) are removed. - If B3 header keys are needed [the authoritative OpenZipkin package constants](https://pkg.go.dev/github.com/openzipkin/zipkin-go@v0.2.2/propagation/b3?tab=doc#pkg-constants) should be used instead. (#882) - -### Fixed - -- The B3 Single Header name is now correctly `b3` instead of the previous `X-B3`. (#881) -- The B3 propagator now correctly supports sampling only values (`b3: 0`, `b3: 1`, or `b3: d`) for a Single B3 Header. (#882) -- The B3 propagator now propagates the debug flag. - This removes the behavior of changing the debug flag into a set sampling bit. - Instead, this now follow the B3 specification and omits the `X-B3-Sampling` header. (#882) -- The B3 propagator now tracks "unset" sampling state (meaning "defer the decision") and does not set the `X-B3-Sampling` header when injecting. (#882) -- Bump github.com/itchyny/gojq from 0.10.3 to 0.10.4 in /tools. (#883) -- Bump github.com/opentracing/opentracing-go from v1.1.1-0.20190913142402-a7454ce5950e to v1.2.0. (#885) -- The tracing time conversion for OTLP spans is now correctly set to `UnixNano`. (#896) -- Ensure span status is not set to `Unknown` when no HTTP status code is provided as it is assumed to be `200 OK`. (#908) -- Ensure `httptrace.clientTracer` closes `http.headers` span. (#912) -- Prometheus exporter will not apply stale updates or forget inactive metrics. (#903) -- Add test for api.standard `HTTPClientAttributesFromHTTPRequest`. (#905) -- Bump github.com/golangci/golangci-lint from 1.27.0 to 1.28.1 in /tools. (#901, #913) -- Update otel-colector example to use the v0.5.0 collector. (#915) -- The `grpctrace` instrumentation uses a span name conforming to the OpenTelemetry semantic conventions (does not contain a leading slash (`/`)). (#922) -- The `grpctrace` instrumentation includes an `rpc.method` attribute now set to the gRPC method name. (#900, #922) -- The `grpctrace` instrumentation `rpc.service` attribute now contains the package name if one exists. - This is in accordance with OpenTelemetry semantic conventions. (#922) -- Correlation Context extractor will no longer insert an empty map into the returned context when no valid values are extracted. (#923) -- Bump google.golang.org/api from 0.28.0 to 0.29.0 in /exporters/trace/jaeger. (#925) -- Bump github.com/itchyny/gojq from 0.10.4 to 0.11.0 in /tools. (#926) -- Bump github.com/golangci/golangci-lint from 1.28.1 to 1.28.2 in /tools. (#930) - -## [0.7.0] - 2020-06-26 - -This release implements the v0.5.0 version of the OpenTelemetry specification. - -### Added - -- The othttp instrumentation now includes default metrics. (#861) -- This CHANGELOG file to track all changes in the project going forward. -- Support for array type attributes. (#798) -- Apply transitive dependabot go.mod dependency updates as part of a new automatic Github workflow. (#844) -- Timestamps are now passed to exporters for each export. (#835) -- Add new `Accumulation` type to metric SDK to transport telemetry from `Accumulator`s to `Processor`s. - This replaces the prior `Record` `struct` use for this purpose. (#835) -- New dependabot integration to automate package upgrades. (#814) -- `Meter` and `Tracer` implementations accept instrumentation version version as an optional argument. - This instrumentation version is passed on to exporters. (#811) (#805) (#802) -- The OTLP exporter includes the instrumentation version in telemetry it exports. (#811) -- Environment variables for Jaeger exporter are supported. (#796) -- New `aggregation.Kind` in the export metric API. (#808) -- New example that uses OTLP and the collector. (#790) -- Handle errors in the span `SetName` during span initialization. (#791) -- Default service config to enable retries for retry-able failed requests in the OTLP exporter and an option to override this default. (#777) -- New `go.opentelemetry.io/otel/api/oterror` package to uniformly support error handling and definitions for the project. (#778) -- New `global` default implementation of the `go.opentelemetry.io/otel/api/oterror.Handler` interface to be used to handle errors prior to an user defined `Handler`. - There is also functionality for the user to register their `Handler` as well as a convenience function `Handle` to handle an error with this global `Handler`(#778) -- Options to specify propagators for httptrace and grpctrace instrumentation. (#784) -- The required `application/json` header for the Zipkin exporter is included in all exports. (#774) -- Integrate HTTP semantics helpers from the contrib repository into the `api/standard` package. #769 - -### Changed - -- Rename `Integrator` to `Processor` in the metric SDK. (#863) -- Rename `AggregationSelector` to `AggregatorSelector`. (#859) -- Rename `SynchronizedCopy` to `SynchronizedMove`. (#858) -- Rename `simple` integrator to `basic` integrator. (#857) -- Merge otlp collector examples. (#841) -- Change the metric SDK to support cumulative, delta, and pass-through exporters directly. - With these changes, cumulative and delta specific exporters are able to request the correct kind of aggregation from the SDK. (#840) -- The `Aggregator.Checkpoint` API is renamed to `SynchronizedCopy` and adds an argument, a different `Aggregator` into which the copy is stored. (#812) -- The `export.Aggregator` contract is that `Update()` and `SynchronizedCopy()` are synchronized with each other. - All the aggregation interfaces (`Sum`, `LastValue`, ...) are not meant to be synchronized, as the caller is expected to synchronize aggregators at a higher level after the `Accumulator`. - Some of the `Aggregators` used unnecessary locking and that has been cleaned up. (#812) -- Use of `metric.Number` was replaced by `int64` now that we use `sync.Mutex` in the `MinMaxSumCount` and `Histogram` `Aggregators`. (#812) -- Replace `AlwaysParentSample` with `ParentSample(fallback)` to match the OpenTelemetry v0.5.0 specification. (#810) -- Rename `sdk/export/metric/aggregator` to `sdk/export/metric/aggregation`. #808 -- Send configured headers with every request in the OTLP exporter, instead of just on connection creation. (#806) -- Update error handling for any one off error handlers, replacing, instead, with the `global.Handle` function. (#791) -- Rename `plugin` directory to `instrumentation` to match the OpenTelemetry specification. (#779) -- Makes the argument order to Histogram and DDSketch `New()` consistent. (#781) - -### Removed - -- `Uint64NumberKind` and related functions from the API. (#864) -- Context arguments from `Aggregator.Checkpoint` and `Integrator.Process` as they were unused. (#803) -- `SpanID` is no longer included in parameters for sampling decision to match the OpenTelemetry specification. (#775) - -### Fixed - -- Upgrade OTLP exporter to opentelemetry-proto matching the opentelemetry-collector v0.4.0 release. (#866) -- Allow changes to `go.sum` and `go.mod` when running dependabot tidy-up. (#871) -- Bump github.com/stretchr/testify from 1.4.0 to 1.6.1. (#824) -- Bump github.com/prometheus/client_golang from 1.7.0 to 1.7.1 in /exporters/metric/prometheus. (#867) -- Bump google.golang.org/grpc from 1.29.1 to 1.30.0 in /exporters/trace/jaeger. (#853) -- Bump google.golang.org/grpc from 1.29.1 to 1.30.0 in /exporters/trace/zipkin. (#854) -- Bumps github.com/golang/protobuf from 1.3.2 to 1.4.2 (#848) -- Bump github.com/stretchr/testify from 1.4.0 to 1.6.1 in /exporters/otlp (#817) -- Bump github.com/golangci/golangci-lint from 1.25.1 to 1.27.0 in /tools (#828) -- Bump github.com/prometheus/client_golang from 1.5.0 to 1.7.0 in /exporters/metric/prometheus (#838) -- Bump github.com/stretchr/testify from 1.4.0 to 1.6.1 in /exporters/trace/jaeger (#829) -- Bump github.com/benbjohnson/clock from 1.0.0 to 1.0.3 (#815) -- Bump github.com/stretchr/testify from 1.4.0 to 1.6.1 in /exporters/trace/zipkin (#823) -- Bump github.com/itchyny/gojq from 0.10.1 to 0.10.3 in /tools (#830) -- Bump github.com/stretchr/testify from 1.4.0 to 1.6.1 in /exporters/metric/prometheus (#822) -- Bump google.golang.org/grpc from 1.27.1 to 1.29.1 in /exporters/trace/zipkin (#820) -- Bump google.golang.org/grpc from 1.27.1 to 1.29.1 in /exporters/trace/jaeger (#831) -- Bump github.com/google/go-cmp from 0.4.0 to 0.5.0 (#836) -- Bump github.com/google/go-cmp from 0.4.0 to 0.5.0 in /exporters/trace/jaeger (#837) -- Bump github.com/google/go-cmp from 0.4.0 to 0.5.0 in /exporters/otlp (#839) -- Bump google.golang.org/api from 0.20.0 to 0.28.0 in /exporters/trace/jaeger (#843) -- Set span status from HTTP status code in the othttp instrumentation. (#832) -- Fixed typo in push controller comment. (#834) -- The `Aggregator` testing has been updated and cleaned. (#812) -- `metric.Number(0)` expressions are replaced by `0` where possible. (#812) -- Fixed `global` `handler_test.go` test failure. #804 -- Fixed `BatchSpanProcessor.Shutdown` to wait until all spans are processed. (#766) -- Fixed OTLP example's accidental early close of exporter. (#807) -- Ensure zipkin exporter reads and closes response body. (#788) -- Update instrumentation to use `api/standard` keys instead of custom keys. (#782) -- Clean up tools and RELEASING documentation. (#762) - -## [0.6.0] - 2020-05-21 - -### Added - -- Support for `Resource`s in the prometheus exporter. (#757) -- New pull controller. (#751) -- New `UpDownSumObserver` instrument. (#750) -- OpenTelemetry collector demo. (#711) -- New `SumObserver` instrument. (#747) -- New `UpDownCounter` instrument. (#745) -- New timeout `Option` and configuration function `WithTimeout` to the push controller. (#742) -- New `api/standards` package to implement semantic conventions and standard key-value generation. (#731) - -### Changed - -- Rename `Register*` functions in the metric API to `New*` for all `Observer` instruments. (#761) -- Use `[]float64` for histogram boundaries, not `[]metric.Number`. (#758) -- Change OTLP example to use exporter as a trace `Syncer` instead of as an unneeded `Batcher`. (#756) -- Replace `WithResourceAttributes()` with `WithResource()` in the trace SDK. (#754) -- The prometheus exporter now uses the new pull controller. (#751) -- Rename `ScheduleDelayMillis` to `BatchTimeout` in the trace `BatchSpanProcessor`.(#752) -- Support use of synchronous instruments in asynchronous callbacks (#725) -- Move `Resource` from the `Export` method parameter into the metric export `Record`. (#739) -- Rename `Observer` instrument to `ValueObserver`. (#734) -- The push controller now has a method (`Provider()`) to return a `metric.Provider` instead of the old `Meter` method that acted as a `metric.Provider`. (#738) -- Replace `Measure` instrument by `ValueRecorder` instrument. (#732) -- Rename correlation context header from `"Correlation-Context"` to `"otcorrelations"` to match the OpenTelemetry specification. 727) - -### Fixed - -- Ensure gRPC `ClientStream` override methods do not panic in grpctrace package. (#755) -- Disable parts of `BatchSpanProcessor` test until a fix is found. (#743) -- Fix `string` case in `kv` `Infer` function. (#746) -- Fix panic in grpctrace client interceptors. (#740) -- Refactor the `api/metrics` push controller and add `CheckpointSet` synchronization. (#737) -- Rewrite span batch process queue batching logic. (#719) -- Remove the push controller named Meter map. (#738) -- Fix Histogram aggregator initial state (fix #735). (#736) -- Ensure golang alpine image is running `golang-1.14` for examples. (#733) -- Added test for grpctrace `UnaryInterceptorClient`. (#695) -- Rearrange `api/metric` code layout. (#724) - -## [0.5.0] - 2020-05-13 - -### Added - -- Batch `Observer` callback support. (#717) -- Alias `api` types to root package of project. (#696) -- Create basic `othttp.Transport` for simple client instrumentation. (#678) -- `SetAttribute(string, interface{})` to the trace API. (#674) -- Jaeger exporter option that allows user to specify custom http client. (#671) -- `Stringer` and `Infer` methods to `key`s. (#662) - -### Changed - -- Rename `NewKey` in the `kv` package to just `Key`. (#721) -- Move `core` and `key` to `kv` package. (#720) -- Make the metric API `Meter` a `struct` so the abstract `MeterImpl` can be passed and simplify implementation. (#709) -- Rename SDK `Batcher` to `Integrator` to match draft OpenTelemetry SDK specification. (#710) -- Rename SDK `Ungrouped` integrator to `simple.Integrator` to match draft OpenTelemetry SDK specification. (#710) -- Rename SDK `SDK` `struct` to `Accumulator` to match draft OpenTelemetry SDK specification. (#710) -- Move `Number` from `core` to `api/metric` package. (#706) -- Move `SpanContext` from `core` to `trace` package. (#692) -- Change traceparent header from `Traceparent` to `traceparent` to implement the W3C specification. (#681) - -### Fixed - -- Update tooling to run generators in all submodules. (#705) -- gRPC interceptor regexp to match methods without a service name. (#683) -- Use a `const` for padding 64-bit B3 trace IDs. (#701) -- Update `mockZipkin` listen address from `:0` to `127.0.0.1:0`. (#700) -- Left-pad 64-bit B3 trace IDs with zero. (#698) -- Propagate at least the first W3C tracestate header. (#694) -- Remove internal `StateLocker` implementation. (#688) -- Increase instance size CI system uses. (#690) -- Add a `key` benchmark and use reflection in `key.Infer()`. (#679) -- Fix internal `global` test by using `global.Meter` with `RecordBatch()`. (#680) -- Reimplement histogram using mutex instead of `StateLocker`. (#669) -- Switch `MinMaxSumCount` to a mutex lock implementation instead of `StateLocker`. (#667) -- Update documentation to not include any references to `WithKeys`. (#672) -- Correct misspelling. (#668) -- Fix clobbering of the span context if extraction fails. (#656) -- Bump `golangci-lint` and work around the corrupting bug. (#666) (#670) - -## [0.4.3] - 2020-04-24 - -### Added - -- `Dockerfile` and `docker-compose.yml` to run example code. (#635) -- New `grpctrace` package that provides gRPC client and server interceptors for both unary and stream connections. (#621) -- New `api/label` package, providing common label set implementation. (#651) -- Support for JSON marshaling of `Resources`. (#654) -- `TraceID` and `SpanID` implementations for `Stringer` interface. (#642) -- `RemoteAddrKey` in the othttp plugin to include the HTTP client address in top-level spans. (#627) -- `WithSpanFormatter` option to the othttp plugin. (#617) -- Updated README to include section for compatible libraries and include reference to the contrib repository. (#612) -- The prometheus exporter now supports exporting histograms. (#601) -- A `String` method to the `Resource` to return a hashable identifier for a now unique resource. (#613) -- An `Iter` method to the `Resource` to return an array `AttributeIterator`. (#613) -- An `Equal` method to the `Resource` test the equivalence of resources. (#613) -- An iterable structure (`AttributeIterator`) for `Resource` attributes. - -### Changed - -- zipkin export's `NewExporter` now requires a `serviceName` argument to ensure this needed values is provided. (#644) -- Pass `Resources` through the metrics export pipeline. (#659) - -### Removed - -- `WithKeys` option from the metric API. (#639) - -### Fixed - -- Use the `label.Set.Equivalent` value instead of an encoding in the batcher. (#658) -- Correct typo `trace.Exporter` to `trace.SpanSyncer` in comments. (#653) -- Use type names for return values in jaeger exporter. (#648) -- Increase the visibility of the `api/key` package by updating comments and fixing usages locally. (#650) -- `Checkpoint` only after `Update`; Keep records in the `sync.Map` longer. (#647) -- Do not cache `reflect.ValueOf()` in metric Labels. (#649) -- Batch metrics exported from the OTLP exporter based on `Resource` and labels. (#626) -- Add error wrapping to the prometheus exporter. (#631) -- Update the OTLP exporter batching of traces to use a unique `string` representation of an associated `Resource` as the batching key. (#623) -- Update OTLP `SpanData` transform to only include the `ParentSpanID` if one exists. (#614) -- Update `Resource` internal representation to uniquely and reliably identify resources. (#613) -- Check return value from `CheckpointSet.ForEach` in prometheus exporter. (#622) -- Ensure spans created by httptrace client tracer reflect operation structure. (#618) -- Create a new recorder rather than reuse when multiple observations in same epoch for asynchronous instruments. #610 -- The default port the OTLP exporter uses to connect to the OpenTelemetry collector is updated to match the one the collector listens on by default. (#611) - - -## [0.4.2] - 2020-03-31 - -### Fixed - -- Fix `pre_release.sh` to update version in `sdk/opentelemetry.go`. (#607) -- Fix time conversion from internal to OTLP in OTLP exporter. (#606) - -## [0.4.1] - 2020-03-31 - -### Fixed - -- Update `tag.sh` to create signed tags. (#604) - -## [0.4.0] - 2020-03-30 - -### Added - -- New API package `api/metric/registry` that exposes a `MeterImpl` wrapper for use by SDKs to generate unique instruments. (#580) -- Script to verify examples after a new release. (#579) - -### Removed - -- The dogstatsd exporter due to lack of support. - This additionally removes support for statsd. (#591) -- `LabelSet` from the metric API. - This is replaced by a `[]core.KeyValue` slice. (#595) -- `Labels` from the metric API's `Meter` interface. (#595) - -### Changed - -- The metric `export.Labels` became an interface which the SDK implements and the `export` package provides a simple, immutable implementation of this interface intended for testing purposes. (#574) -- Renamed `internal/metric.Meter` to `MeterImpl`. (#580) -- Renamed `api/global/internal.obsImpl` to `asyncImpl`. (#580) - -### Fixed - -- Corrected missing return in mock span. (#582) -- Update License header for all source files to match CNCF guidelines and include a test to ensure it is present. (#586) (#596) -- Update to v0.3.0 of the OTLP in the OTLP exporter. (#588) -- Update pre-release script to be compatible between GNU and BSD based systems. (#592) -- Add a `RecordBatch` benchmark. (#594) -- Moved span transforms of the OTLP exporter to the internal package. (#593) -- Build both go-1.13 and go-1.14 in circleci to test for all supported versions of Go. (#569) -- Removed unneeded allocation on empty labels in OLTP exporter. (#597) -- Update `BatchedSpanProcessor` to process the queue until no data but respect max batch size. (#599) -- Update project documentation godoc.org links to pkg.go.dev. (#602) - -## [0.3.0] - 2020-03-21 - -This is a first official beta release, which provides almost fully complete metrics, tracing, and context propagation functionality. -There is still a possibility of breaking changes. - -### Added - -- Add `Observer` metric instrument. (#474) -- Add global `Propagators` functionality to enable deferred initialization for propagators registered before the first Meter SDK is installed. (#494) -- Simplified export setup pipeline for the jaeger exporter to match other exporters. (#459) -- The zipkin trace exporter. (#495) -- The OTLP exporter to export metric and trace telemetry to the OpenTelemetry collector. (#497) (#544) (#545) -- The `StatusMessage` field was add to the trace `Span`. (#524) -- Context propagation in OpenTracing bridge in terms of OpenTelemetry context propagation. (#525) -- The `Resource` type was added to the SDK. (#528) -- The global API now supports a `Tracer` and `Meter` function as shortcuts to getting a global `*Provider` and calling these methods directly. (#538) -- The metric API now defines a generic `MeterImpl` interface to support general purpose `Meter` construction. - Additionally, `SyncImpl` and `AsyncImpl` are added to support general purpose instrument construction. (#560) -- A metric `Kind` is added to represent the `MeasureKind`, `ObserverKind`, and `CounterKind`. (#560) -- Scripts to better automate the release process. (#576) - -### Changed - -- Default to to use `AlwaysSampler` instead of `ProbabilitySampler` to match OpenTelemetry specification. (#506) -- Renamed `AlwaysSampleSampler` to `AlwaysOnSampler` in the trace API. (#511) -- Renamed `NeverSampleSampler` to `AlwaysOffSampler` in the trace API. (#511) -- The `Status` field of the `Span` was changed to `StatusCode` to disambiguate with the added `StatusMessage`. (#524) -- Updated the trace `Sampler` interface conform to the OpenTelemetry specification. (#531) -- Rename metric API `Options` to `Config`. (#541) -- Rename metric `Counter` aggregator to be `Sum`. (#541) -- Unify metric options into `Option` from instrument specific options. (#541) -- The trace API's `TraceProvider` now support `Resource`s. (#545) -- Correct error in zipkin module name. (#548) -- The jaeger trace exporter now supports `Resource`s. (#551) -- Metric SDK now supports `Resource`s. - The `WithResource` option was added to configure a `Resource` on creation and the `Resource` method was added to the metric `Descriptor` to return the associated `Resource`. (#552) -- Replace `ErrNoLastValue` and `ErrEmptyDataSet` by `ErrNoData` in the metric SDK. (#557) -- The stdout trace exporter now supports `Resource`s. (#558) -- The metric `Descriptor` is now included at the API instead of the SDK. (#560) -- Replace `Ordered` with an iterator in `export.Labels`. (#567) - -### Removed - -- The vendor specific Stackdriver. It is now hosted on 3rd party vendor infrastructure. (#452) -- The `Unregister` method for metric observers as it is not in the OpenTelemetry specification. (#560) -- `GetDescriptor` from the metric SDK. (#575) -- The `Gauge` instrument from the metric API. (#537) - -### Fixed - -- Make histogram aggregator checkpoint consistent. (#438) -- Update README with import instructions and how to build and test. (#505) -- The default label encoding was updated to be unique. (#508) -- Use `NewRoot` in the othttp plugin for public endpoints. (#513) -- Fix data race in `BatchedSpanProcessor`. (#518) -- Skip test-386 for Mac OS 10.15.x (Catalina and upwards). #521 -- Use a variable-size array to represent ordered labels in maps. (#523) -- Update the OTLP protobuf and update changed import path. (#532) -- Use `StateLocker` implementation in `MinMaxSumCount`. (#546) -- Eliminate goroutine leak in histogram stress test. (#547) -- Update OTLP exporter with latest protobuf. (#550) -- Add filters to the othttp plugin. (#556) -- Provide an implementation of the `Header*` filters that do not depend on Go 1.14. (#565) -- Encode labels once during checkpoint. - The checkpoint function is executed in a single thread so we can do the encoding lazily before passing the encoded version of labels to the exporter. - This is a cheap and quick way to avoid encoding the labels on every collection interval. (#572) -- Run coverage over all packages in `COVERAGE_MOD_DIR`. (#573) - -## [0.2.3] - 2020-03-04 - -### Added - -- `RecordError` method on `Span`s in the trace API to Simplify adding error events to spans. (#473) -- Configurable push frequency for exporters setup pipeline. (#504) - -### Changed - -- Rename the `exporter` directory to `exporters`. - The `go.opentelemetry.io/otel/exporter/trace/jaeger` package was mistakenly released with a `v1.0.0` tag instead of `v0.1.0`. - This resulted in all subsequent releases not becoming the default latest. - A consequence of this was that all `go get`s pulled in the incompatible `v0.1.0` release of that package when pulling in more recent packages from other otel packages. - Renaming the `exporter` directory to `exporters` fixes this issue by renaming the package and therefore clearing any existing dependency tags. - Consequentially, this action also renames *all* exporter packages. (#502) - -### Removed - -- The `CorrelationContextHeader` constant in the `correlation` package is no longer exported. (#503) - -## [0.2.2] - 2020-02-27 - -### Added - -- `HTTPSupplier` interface in the propagation API to specify methods to retrieve and store a single value for a key to be associated with a carrier. (#467) -- `HTTPExtractor` interface in the propagation API to extract information from an `HTTPSupplier` into a context. (#467) -- `HTTPInjector` interface in the propagation API to inject information into an `HTTPSupplier.` (#467) -- `Config` and configuring `Option` to the propagator API. (#467) -- `Propagators` interface in the propagation API to contain the set of injectors and extractors for all supported carrier formats. (#467) -- `HTTPPropagator` interface in the propagation API to inject and extract from an `HTTPSupplier.` (#467) -- `WithInjectors` and `WithExtractors` functions to the propagator API to configure injectors and extractors to use. (#467) -- `ExtractHTTP` and `InjectHTTP` functions to apply configured HTTP extractors and injectors to a passed context. (#467) -- Histogram aggregator. (#433) -- `DefaultPropagator` function and have it return `trace.TraceContext` as the default context propagator. (#456) -- `AlwaysParentSample` sampler to the trace API. (#455) -- `WithNewRoot` option function to the trace API to specify the created span should be considered a root span. (#451) - - -### Changed - -- Renamed `WithMap` to `ContextWithMap` in the correlation package. (#481) -- Renamed `FromContext` to `MapFromContext` in the correlation package. (#481) -- Move correlation context propagation to correlation package. (#479) -- Do not default to putting remote span context into links. (#480) -- Propagators extrac -- `Tracer.WithSpan` updated to accept `StartOptions`. (#472) -- Renamed `MetricKind` to `Kind` to not stutter in the type usage. (#432) -- Renamed the `export` package to `metric` to match directory structure. (#432) -- Rename the `api/distributedcontext` package to `api/correlation`. (#444) -- Rename the `api/propagators` package to `api/propagation`. (#444) -- Move the propagators from the `propagators` package into the `trace` API package. (#444) -- Update `Float64Gauge`, `Int64Gauge`, `Float64Counter`, `Int64Counter`, `Float64Measure`, and `Int64Measure` metric methods to use value receivers instead of pointers. (#462) -- Moved all dependencies of tools package to a tools directory. (#466) - -### Removed - -- Binary propagators. (#467) -- NOOP propagator. (#467) - -### Fixed - -- Upgraded `github.com/golangci/golangci-lint` from `v1.21.0` to `v1.23.6` in `tools/`. (#492) -- Fix a possible nil-dereference crash (#478) -- Correct comments for `InstallNewPipeline` in the stdout exporter. (#483) -- Correct comments for `InstallNewPipeline` in the dogstatsd exporter. (#484) -- Correct comments for `InstallNewPipeline` in the prometheus exporter. (#482) -- Initialize `onError` based on `Config` in prometheus exporter. (#486) -- Correct module name in prometheus exporter README. (#475) -- Removed tracer name prefix from span names. (#430) -- Fix `aggregator_test.go` import package comment. (#431) -- Improved detail in stdout exporter. (#436) -- Fix a dependency issue (generate target should depend on stringer, not lint target) in Makefile. (#442) -- Reorders the Makefile targets within `precommit` target so we generate files and build the code before doing linting, so we can get much nicer errors about syntax errors from the compiler. (#442) -- Reword function documentation in gRPC plugin. (#446) -- Send the `span.kind` tag to Jaeger from the jaeger exporter. (#441) -- Fix `metadataSupplier` in the jaeger exporter to overwrite the header if existing instead of appending to it. (#441) -- Upgraded to Go 1.13 in CI. (#465) -- Correct opentelemetry.io URL in trace SDK documentation. (#464) -- Refactored reference counting logic in SDK determination of stale records. (#468) -- Add call to `runtime.Gosched` in instrument `acquireHandle` logic to not block the collector. (#469) - -## [0.2.1.1] - 2020-01-13 - -### Fixed - -- Use stateful batcher on Prometheus exporter fixing regresion introduced in #395. (#428) - -## [0.2.1] - 2020-01-08 - -### Added - -- Global meter forwarding implementation. - This enables deferred initialization for metric instruments registered before the first Meter SDK is installed. (#392) -- Global trace forwarding implementation. - This enables deferred initialization for tracers registered before the first Trace SDK is installed. (#406) -- Standardize export pipeline creation in all exporters. (#395) -- A testing, organization, and comments for 64-bit field alignment. (#418) -- Script to tag all modules in the project. (#414) - -### Changed - -- Renamed `propagation` package to `propagators`. (#362) -- Renamed `B3Propagator` propagator to `B3`. (#362) -- Renamed `TextFormatPropagator` propagator to `TextFormat`. (#362) -- Renamed `BinaryPropagator` propagator to `Binary`. (#362) -- Renamed `BinaryFormatPropagator` propagator to `BinaryFormat`. (#362) -- Renamed `NoopTextFormatPropagator` propagator to `NoopTextFormat`. (#362) -- Renamed `TraceContextPropagator` propagator to `TraceContext`. (#362) -- Renamed `SpanOption` to `StartOption` in the trace API. (#369) -- Renamed `StartOptions` to `StartConfig` in the trace API. (#369) -- Renamed `EndOptions` to `EndConfig` in the trace API. (#369) -- `Number` now has a pointer receiver for its methods. (#375) -- Renamed `CurrentSpan` to `SpanFromContext` in the trace API. (#379) -- Renamed `SetCurrentSpan` to `ContextWithSpan` in the trace API. (#379) -- Renamed `Message` in Event to `Name` in the trace API. (#389) -- Prometheus exporter no longer aggregates metrics, instead it only exports them. (#385) -- Renamed `HandleImpl` to `BoundInstrumentImpl` in the metric API. (#400) -- Renamed `Float64CounterHandle` to `Float64CounterBoundInstrument` in the metric API. (#400) -- Renamed `Int64CounterHandle` to `Int64CounterBoundInstrument` in the metric API. (#400) -- Renamed `Float64GaugeHandle` to `Float64GaugeBoundInstrument` in the metric API. (#400) -- Renamed `Int64GaugeHandle` to `Int64GaugeBoundInstrument` in the metric API. (#400) -- Renamed `Float64MeasureHandle` to `Float64MeasureBoundInstrument` in the metric API. (#400) -- Renamed `Int64MeasureHandle` to `Int64MeasureBoundInstrument` in the metric API. (#400) -- Renamed `Release` method for bound instruments in the metric API to `Unbind`. (#400) -- Renamed `AcquireHandle` method for bound instruments in the metric API to `Bind`. (#400) -- Renamed the `File` option in the stdout exporter to `Writer`. (#404) -- Renamed all `Options` to `Config` for all metric exports where this wasn't already the case. - -### Fixed - -- Aggregator import path corrected. (#421) -- Correct links in README. (#368) -- The README was updated to match latest code changes in its examples. (#374) -- Don't capitalize error statements. (#375) -- Fix ignored errors. (#375) -- Fix ambiguous variable naming. (#375) -- Removed unnecessary type casting. (#375) -- Use named parameters. (#375) -- Updated release schedule. (#378) -- Correct http-stackdriver example module name. (#394) -- Removed the `http.request` span in `httptrace` package. (#397) -- Add comments in the metrics SDK (#399) -- Initialize checkpoint when creating ddsketch aggregator to prevent panic when merging into a empty one. (#402) (#403) -- Add documentation of compatible exporters in the README. (#405) -- Typo fix. (#408) -- Simplify span check logic in SDK tracer implementation. (#419) - -## [0.2.0] - 2019-12-03 - -### Added - -- Unary gRPC tracing example. (#351) -- Prometheus exporter. (#334) -- Dogstatsd metrics exporter. (#326) - -### Changed - -- Rename `MaxSumCount` aggregation to `MinMaxSumCount` and add the `Min` interface for this aggregation. (#352) -- Rename `GetMeter` to `Meter`. (#357) -- Rename `HTTPTraceContextPropagator` to `TraceContextPropagator`. (#355) -- Rename `HTTPB3Propagator` to `B3Propagator`. (#355) -- Rename `HTTPTraceContextPropagator` to `TraceContextPropagator`. (#355) -- Move `/global` package to `/api/global`. (#356) -- Rename `GetTracer` to `Tracer`. (#347) - -### Removed - -- `SetAttribute` from the `Span` interface in the trace API. (#361) -- `AddLink` from the `Span` interface in the trace API. (#349) -- `Link` from the `Span` interface in the trace API. (#349) - -### Fixed - -- Exclude example directories from coverage report. (#365) -- Lint make target now implements automatic fixes with `golangci-lint` before a second run to report the remaining issues. (#360) -- Drop `GO111MODULE` environment variable in Makefile as Go 1.13 is the project specified minimum version and this is environment variable is not needed for that version of Go. (#359) -- Run the race checker for all test. (#354) -- Redundant commands in the Makefile are removed. (#354) -- Split the `generate` and `lint` targets of the Makefile. (#354) -- Renames `circle-ci` target to more generic `ci` in Makefile. (#354) -- Add example Prometheus binary to gitignore. (#358) -- Support negative numbers with the `MaxSumCount`. (#335) -- Resolve race conditions in `push_test.go` identified in #339. (#340) -- Use `/usr/bin/env bash` as a shebang in scripts rather than `/bin/bash`. (#336) -- Trace benchmark now tests both `AlwaysSample` and `NeverSample`. - Previously it was testing `AlwaysSample` twice. (#325) -- Trace benchmark now uses a `[]byte` for `TraceID` to fix failing test. (#325) -- Added a trace benchmark to test variadic functions in `setAttribute` vs `setAttributes` (#325) -- The `defaultkeys` batcher was only using the encoded label set as its map key while building a checkpoint. - This allowed distinct label sets through, but any metrics sharing a label set could be overwritten or merged incorrectly. - This was corrected. (#333) - - -## [0.1.2] - 2019-11-18 - -### Fixed - -- Optimized the `simplelru` map for attributes to reduce the number of allocations. (#328) -- Removed unnecessary unslicing of parameters that are already a slice. (#324) - -## [0.1.1] - 2019-11-18 - -This release contains a Metrics SDK with stdout exporter and supports basic aggregations such as counter, gauges, array, maxsumcount, and ddsketch. - -### Added - -- Metrics stdout export pipeline. (#265) -- Array aggregation for raw measure metrics. (#282) -- The core.Value now have a `MarshalJSON` method. (#281) - -### Removed - -- `WithService`, `WithResources`, and `WithComponent` methods of tracers. (#314) -- Prefix slash in `Tracer.Start()` for the Jaeger example. (#292) - -### Changed - -- Allocation in LabelSet construction to reduce GC overhead. (#318) -- `trace.WithAttributes` to append values instead of replacing (#315) -- Use a formula for tolerance in sampling tests. (#298) -- Move export types into trace and metric-specific sub-directories. (#289) -- `SpanKind` back to being based on an `int` type. (#288) - -### Fixed - -- URL to OpenTelemetry website in README. (#323) -- Name of othttp default tracer. (#321) -- `ExportSpans` for the stackdriver exporter now handles `nil` context. (#294) -- CI modules cache to correctly restore/save from/to the cache. (#316) -- Fix metric SDK race condition between `LoadOrStore` and the assignment `rec.recorder = i.meter.exporter.AggregatorFor(rec)`. (#293) -- README now reflects the new code structure introduced with these changes. (#291) -- Make the basic example work. (#279) - -## [0.1.0] - 2019-11-04 - -This is the first release of open-telemetry go library. -It contains api and sdk for trace and meter. - -### Added - -- Initial OpenTelemetry trace and metric API prototypes. -- Initial OpenTelemetry trace, metric, and export SDK packages. -- A wireframe bridge to support compatibility with OpenTracing. -- Example code for a basic, http-stackdriver, http, jaeger, and named tracer setup. -- Exporters for Jaeger, Stackdriver, and stdout. -- Propagators for binary, B3, and trace-context protocols. -- Project information and guidelines in the form of a README and CONTRIBUTING. -- Tools to build the project and a Makefile to automate the process. -- Apache-2.0 license. -- CircleCI build CI manifest files. -- CODEOWNERS file to track owners of this project. - - -[Unreleased]: https://github.com/open-telemetry/opentelemetry-go/compare/v0.20.0...HEAD -[0.20.0]: https://github.com/open-telemetry/opentelemetry-go/releases/tag/v0.20.0 -[0.19.0]: https://github.com/open-telemetry/opentelemetry-go/releases/tag/v0.19.0 -[0.18.0]: https://github.com/open-telemetry/opentelemetry-go/releases/tag/v0.18.0 -[0.17.0]: https://github.com/open-telemetry/opentelemetry-go/releases/tag/v0.17.0 -[0.16.0]: https://github.com/open-telemetry/opentelemetry-go/releases/tag/v0.16.0 -[0.15.0]: https://github.com/open-telemetry/opentelemetry-go/releases/tag/v0.15.0 -[0.14.0]: https://github.com/open-telemetry/opentelemetry-go/releases/tag/v0.14.0 -[0.13.0]: https://github.com/open-telemetry/opentelemetry-go/releases/tag/v0.13.0 -[0.12.0]: https://github.com/open-telemetry/opentelemetry-go/releases/tag/v0.12.0 -[0.11.0]: https://github.com/open-telemetry/opentelemetry-go/releases/tag/v0.11.0 -[0.10.0]: https://github.com/open-telemetry/opentelemetry-go/releases/tag/v0.10.0 -[0.9.0]: https://github.com/open-telemetry/opentelemetry-go/releases/tag/v0.9.0 -[0.8.0]: https://github.com/open-telemetry/opentelemetry-go/releases/tag/v0.8.0 -[0.7.0]: https://github.com/open-telemetry/opentelemetry-go/releases/tag/v0.7.0 -[0.6.0]: https://github.com/open-telemetry/opentelemetry-go/releases/tag/v0.6.0 -[0.5.0]: https://github.com/open-telemetry/opentelemetry-go/releases/tag/v0.5.0 -[0.4.3]: https://github.com/open-telemetry/opentelemetry-go/releases/tag/v0.4.3 -[0.4.2]: https://github.com/open-telemetry/opentelemetry-go/releases/tag/v0.4.2 -[0.4.1]: https://github.com/open-telemetry/opentelemetry-go/releases/tag/v0.4.1 -[0.4.0]: https://github.com/open-telemetry/opentelemetry-go/releases/tag/v0.4.0 -[0.3.0]: https://github.com/open-telemetry/opentelemetry-go/releases/tag/v0.3.0 -[0.2.3]: https://github.com/open-telemetry/opentelemetry-go/releases/tag/v0.2.3 -[0.2.2]: https://github.com/open-telemetry/opentelemetry-go/releases/tag/v0.2.2 -[0.2.1.1]: https://github.com/open-telemetry/opentelemetry-go/releases/tag/v0.2.1.1 -[0.2.1]: https://github.com/open-telemetry/opentelemetry-go/releases/tag/v0.2.1 -[0.2.0]: https://github.com/open-telemetry/opentelemetry-go/releases/tag/v0.2.0 -[0.1.2]: https://github.com/open-telemetry/opentelemetry-go/releases/tag/v0.1.2 -[0.1.1]: https://github.com/open-telemetry/opentelemetry-go/releases/tag/v0.1.1 -[0.1.0]: https://github.com/open-telemetry/opentelemetry-go/releases/tag/v0.1.0 diff --git a/vendor/go.opentelemetry.io/otel/CODEOWNERS b/vendor/go.opentelemetry.io/otel/CODEOWNERS deleted file mode 100644 index 196df9cfd8..0000000000 --- a/vendor/go.opentelemetry.io/otel/CODEOWNERS +++ /dev/null @@ -1,17 +0,0 @@ -##################################################### -# -# List of approvers for this repository -# -##################################################### -# -# Learn about membership in OpenTelemetry community: -# https://github.com/open-telemetry/community/blob/main/community-membership.md -# -# -# Learn about CODEOWNERS file format: -# https://help.github.com/en/articles/about-code-owners -# - -* @jmacd @MrAlias @Aneurysm9 @evantorrie @XSAM @dashpole @paivagustavo - -CODEOWNERS @MrAlias @Aneurysm9 diff --git a/vendor/go.opentelemetry.io/otel/CONTRIBUTING.md b/vendor/go.opentelemetry.io/otel/CONTRIBUTING.md deleted file mode 100644 index 51ab52c638..0000000000 --- a/vendor/go.opentelemetry.io/otel/CONTRIBUTING.md +++ /dev/null @@ -1,380 +0,0 @@ -# Contributing to opentelemetry-go - -The Go special interest group (SIG) meets regularly. See the -OpenTelemetry -[community](https://github.com/open-telemetry/community#golang-sdk) -repo for information on this and other language SIGs. - -See the [public meeting -notes](https://docs.google.com/document/d/1A63zSWX0x2CyCK_LoNhmQC4rqhLpYXJzXbEPDUQ2n6w/edit#heading=h.9tngw7jdwd6b) -for a summary description of past meetings. To request edit access, -join the meeting or get in touch on -[Slack](https://cloud-native.slack.com/archives/C01NPAXACKT). - -## Development - -You can view and edit the source code by cloning this repository: - -```bash -git clone https://github.com/open-telemetry/opentelemetry-go.git -``` - -Run `make test` to run the tests instead of `go test`. - -There are some generated files checked into the repo. To make sure -that the generated files are up-to-date, run `make` (or `make -precommit` - the `precommit` target is the default). - -The `precommit` target also fixes the formatting of the code and -checks the status of the go module files. - -If after running `make precommit` the output of `git status` contains -`nothing to commit, working tree clean` then it means that everything -is up-to-date and properly formatted. - -## Pull Requests - -### How to Send Pull Requests - -Everyone is welcome to contribute code to `opentelemetry-go` via -GitHub pull requests (PRs). - -To create a new PR, fork the project in GitHub and clone the upstream -repo: - -```sh -$ go get -d go.opentelemetry.io/otel -``` - -(This may print some warning about "build constraints exclude all Go -files", just ignore it.) - -This will put the project in `${GOPATH}/src/go.opentelemetry.io/otel`. You -can alternatively use `git` directly with: - -```sh -$ git clone https://github.com/open-telemetry/opentelemetry-go -``` - -(Note that `git clone` is *not* using the `go.opentelemetry.io/otel` name - -that name is a kind of a redirector to GitHub that `go get` can -understand, but `git` does not.) - -This would put the project in the `opentelemetry-go` directory in -current working directory. - -Enter the newly created directory and add your fork as a new remote: - -```sh -$ git remote add git@github.com:/opentelemetry-go -``` - -Check out a new branch, make modifications, run linters and tests, update -`CHANGELOG.md`, and push the branch to your fork: - -```sh -$ git checkout -b -# edit files -# update changelog -$ make precommit -$ git add -p -$ git commit -$ git push -``` - -Open a pull request against the main `opentelemetry-go` repo. Be sure to add the pull -request ID to the entry you added to `CHANGELOG.md`. - -### How to Receive Comments - -* If the PR is not ready for review, please put `[WIP]` in the title, - tag it as `work-in-progress`, or mark it as - [`draft`](https://github.blog/2019-02-14-introducing-draft-pull-requests/). -* Make sure CLA is signed and CI is clear. - -### How to Get PRs Merged - -A PR is considered to be **ready to merge** when: - -* It has received two approvals from Collaborators/Maintainers (at - different companies). This is not enforced through technical means - and a PR may be **ready to merge** with a single approval if the change - and its approach have been discussed and consensus reached. -* Feedback has been addressed. -* Any substantive changes to your PR will require that you clear any prior - Approval reviews, this includes changes resulting from other feedback. Unless - the approver explicitly stated that their approval will persist across - changes it should be assumed that the PR needs their review again. Other - project members (e.g. approvers, maintainers) can help with this if there are - any questions or if you forget to clear reviews. -* It has been open for review for at least one working day. This gives - people reasonable time to review. -* Trivial changes (typo, cosmetic, doc, etc.) do not have to wait for - one day and may be merged with a single Maintainer's approval. -* `CHANGELOG.md` has been updated to reflect what has been - added, changed, removed, or fixed. -* Urgent fix can take exception as long as it has been actively - communicated. - -Any Maintainer can merge the PR once it is **ready to merge**. - -## Design Choices - -As with other OpenTelemetry clients, opentelemetry-go follows the -[opentelemetry-specification](https://github.com/open-telemetry/opentelemetry-specification). - -It's especially valuable to read through the [library -guidelines](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/library-guidelines.md). - -### Focus on Capabilities, Not Structure Compliance - -OpenTelemetry is an evolving specification, one where the desires and -use cases are clear, but the method to satisfy those uses cases are -not. - -As such, Contributions should provide functionality and behavior that -conforms to the specification, but the interface and structure is -flexible. - -It is preferable to have contributions follow the idioms of the -language rather than conform to specific API names or argument -patterns in the spec. - -For a deeper discussion, see: -https://github.com/open-telemetry/opentelemetry-specification/issues/165 - -## Style Guide - -One of the primary goals of this project is that it is actually used by -developers. With this goal in mind the project strives to build -user-friendly and idiomatic Go code adhering to the Go community's best -practices. - -For a non-comprehensive but foundational overview of these best practices -the [Effective Go](https://golang.org/doc/effective_go.html) documentation -is an excellent starting place. - -As a convenience for developers building this project the `make precommit` -will format, lint, validate, and in some cases fix the changes you plan to -submit. This check will need to pass for your changes to be able to be -merged. - -In addition to idiomatic Go, the project has adopted certain standards for -implementations of common patterns. These standards should be followed as a -default, and if they are not followed documentation needs to be included as -to the reasons why. - -### Configuration - -When creating an instantiation function for a complex `struct` it is useful -to allow variable number of options to be applied. However, the strong type -system of Go restricts the function design options. There are a few ways to -solve this problem, but we have landed on the following design. - -#### `config` - -Configuration should be held in a `struct` named `config`, or prefixed with -specific type name this Configuration applies to if there are multiple -`config` in the package. This `struct` must contain configuration options. - -```go -// config contains configuration options for a thing. -type config struct { - // options ... -} -``` - -In general the `config` `struct` will not need to be used externally to the -package and should be unexported. If, however, it is expected that the user -will likely want to build custom options for the configuration, the `config` -should be exported. Please, include in the documentation for the `config` -how the user can extend the configuration. - -It is important that `config` are not shared across package boundaries. -Meaning a `config` from one package should not be directly used by another. - -Optionally, it is common to include a `newConfig` function (with the same -naming scheme). This function wraps any defaults setting and looping over -all options to create a configured `config`. - -```go -// newConfig returns an appropriately configured config. -func newConfig([]Option) config { - // Set default values for config. - config := config{/* […] */} - for _, option := range options { - option.Apply(&config) - } - // Preform any validation here. - return config -} -``` - -If validation of the `config` options is also preformed this can return an -error as well that is expected to be handled by the instantiation function -or propagated to the user. - -Given the design goal of not having the user need to work with the `config`, -the `newConfig` function should also be unexported. - -#### `Option` - -To set the value of the options a `config` contains, a corresponding -`Option` interface type should be used. - -```go -type Option interface { - Apply(*config) -} -``` - -The name of the interface should be prefixed in the same way the -corresponding `config` is (if at all). - -#### Options - -All user configurable options for a `config` must have a related unexported -implementation of the `Option` interface and an exported configuration -function that wraps this implementation. - -The wrapping function name should be prefixed with `With*` (or in the -special case of a boolean options `Without*`) and should have the following -function signature. - -```go -func With*(…) Option { … } -``` - -##### `bool` Options - -```go -type defaultFalseOption bool - -func (o defaultFalseOption) Apply(c *config) { - c.Bool = bool(o) -} - -// WithOption sets a T* to have an option included. -func WithOption() Option { - return defaultFalseOption(true) -} -``` - -```go -type defaultTrueOption bool - -func (o defaultTrueOption) Apply(c *config) { - c.Bool = bool(o) -} - -// WithoutOption sets a T* to have Bool option excluded. -func WithoutOption() Option { - return defaultTrueOption(false) -} -```` - -##### Declared Type Options - -```go -type myTypeOption struct { - MyType MyType -} - -func (o myTypeOption) Apply(c *config) { - c.MyType = o.MyType -} - -// WithMyType sets T* to have include MyType. -func WithMyType(t MyType) Option { - return myTypeOption{t} -} -``` - -#### Instantiation - -Using this configuration pattern to configure instantiation with a `New*` -function. - -```go -func NewT*(options ...Option) T* {…} -``` - -Any required parameters can be declared before the variadic `options`. - -#### Dealing with Overlap - -Sometimes there are multiple complex `struct` that share common -configuration and also have distinct configuration. To avoid repeated -portions of `config`s, a common `config` can be used with the union of -options being handled with the `Option` interface. - -For example. - -```go -// config holds options for all animals. -type config struct { - Weight float64 - Color string - MaxAltitude float64 -} - -// DogOption apply Dog specific options. -type DogOption interface { - ApplyDog(*config) -} - -// BirdOption apply Bird specific options. -type BirdOption interface { - ApplyBird(*config) -} - -// Option apply options for all animals. -type Option interface { - BirdOption - DogOption -} - -type weightOption float64 -func (o weightOption) ApplyDog(c *config) { c.Weight = float64(o) } -func (o weightOption) ApplyBird(c *config) { c.Weight = float64(o) } -func WithWeight(w float64) Option { return weightOption(w) } - -type furColorOption string -func (o furColorOption) ApplyDog(c *config) { c.Color = string(o) } -func WithFurColor(c string) DogOption { return furColorOption(c) } - -type maxAltitudeOption float64 -func (o maxAltitudeOption) ApplyBird(c *config) { c.MaxAltitude = float64(o) } -func WithMaxAltitude(a float64) BirdOption { return maxAltitudeOption(a) } - -func NewDog(name string, o ...DogOption) Dog {…} -func NewBird(name string, o ...BirdOption) Bird {…} -``` - -### Interface Type - -To allow other developers to better comprehend the code, it is important -to ensure it is sufficiently documented. One simple measure that contributes -to this aim is self-documenting by naming method parameters. Therefore, -where appropriate, methods of every exported interface type should have -their parameters appropriately named. - -## Approvers and Maintainers - -Approvers: - -- [Evan Torrie](https://github.com/evantorrie), Verizon Media -- [Josh MacDonald](https://github.com/jmacd), LightStep -- [Sam Xie](https://github.com/XSAM) -- [David Ashpole](https://github.com/dashpole), Google -- [Gustavo Silva Paiva](https://github.com/paivagustavo), LightStep - -Maintainers: - -- [Anthony Mirabella](https://github.com/Aneurysm9), AWS -- [Tyler Yahn](https://github.com/MrAlias), Splunk - -### Become an Approver or a Maintainer - -See the [community membership document in OpenTelemetry community -repo](https://github.com/open-telemetry/community/blob/main/community-membership.md). diff --git a/vendor/go.opentelemetry.io/otel/LICENSE b/vendor/go.opentelemetry.io/otel/LICENSE deleted file mode 100644 index 261eeb9e9f..0000000000 --- a/vendor/go.opentelemetry.io/otel/LICENSE +++ /dev/null @@ -1,201 +0,0 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. diff --git a/vendor/go.opentelemetry.io/otel/Makefile b/vendor/go.opentelemetry.io/otel/Makefile deleted file mode 100644 index b290b66710..0000000000 --- a/vendor/go.opentelemetry.io/otel/Makefile +++ /dev/null @@ -1,179 +0,0 @@ -# Copyright The OpenTelemetry Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -EXAMPLES := $(shell ./get_main_pkgs.sh ./example) -TOOLS_MOD_DIR := ./internal/tools - -# All source code and documents. Used in spell check. -ALL_DOCS := $(shell find . -name '*.md' -type f | sort) -# All directories with go.mod files related to opentelemetry library. Used for building, testing and linting. -ALL_GO_MOD_DIRS := $(filter-out $(TOOLS_MOD_DIR), $(shell find . -type f -name 'go.mod' -exec dirname {} \; | egrep -v '^./example' | sort)) $(shell find ./example -type f -name 'go.mod' -exec dirname {} \; | sort) -ALL_COVERAGE_MOD_DIRS := $(shell find . -type f -name 'go.mod' -exec dirname {} \; | egrep -v '^./example|^$(TOOLS_MOD_DIR)' | sort) - -GO = go -TIMEOUT = 60 - -.DEFAULT_GOAL := precommit - -.PHONY: precommit ci -precommit: dependabot-check license-check lint build examples test-default -ci: precommit check-clean-work-tree test-coverage - -# Tools - -TOOLS = $(CURDIR)/.tools - -$(TOOLS): - @mkdir -p $@ -$(TOOLS)/%: | $(TOOLS) - cd $(TOOLS_MOD_DIR) && \ - $(GO) build -o $@ $(PACKAGE) - -CROSSLINK = $(TOOLS)/crosslink -$(TOOLS)/crosslink: PACKAGE=go.opentelemetry.io/otel/$(TOOLS_MOD_DIR)/crosslink - -GOLANGCI_LINT = $(TOOLS)/golangci-lint -$(TOOLS)/golangci-lint: PACKAGE=github.com/golangci/golangci-lint/cmd/golangci-lint - -MISSPELL = $(TOOLS)/misspell -$(TOOLS)/misspell: PACKAGE= github.com/client9/misspell/cmd/misspell - -STRINGER = $(TOOLS)/stringer -$(TOOLS)/stringer: PACKAGE=golang.org/x/tools/cmd/stringer - -$(TOOLS)/gojq: PACKAGE=github.com/itchyny/gojq/cmd/gojq - -.PHONY: tools -tools: $(CROSSLINK) $(GOLANGCI_LINT) $(MISSPELL) $(STRINGER) $(TOOLS)/gojq - - -# Build - -.PHONY: examples generate build -examples: - @set -e; for dir in $(EXAMPLES); do \ - echo "$(GO) build $${dir}/..."; \ - (cd "$${dir}" && \ - $(GO) build .); \ - done - -generate: $(STRINGER) - set -e; for dir in $(ALL_GO_MOD_DIRS); do \ - echo "$(GO) generate $${dir}/..."; \ - (cd "$${dir}" && \ - PATH="$(TOOLS):$${PATH}" $(GO) generate ./...); \ - done - -build: generate - # Build all package code including testing code. - set -e; for dir in $(ALL_GO_MOD_DIRS); do \ - echo "$(GO) build $${dir}/..."; \ - (cd "$${dir}" && \ - $(GO) build ./... && \ - $(GO) list ./... \ - | grep -v third_party \ - | xargs $(GO) test -vet=off -run xxxxxMatchNothingxxxxx >/dev/null); \ - done - -# Tests - -TEST_TARGETS := test-default test-bench test-short test-verbose test-race -.PHONY: $(TEST_TARGETS) test -test-default: ARGS=-v -race -test-bench: ARGS=-run=xxxxxMatchNothingxxxxx -test.benchtime=1ms -bench=. -test-short: ARGS=-short -test-verbose: ARGS=-v -test-race: ARGS=-race -$(TEST_TARGETS): test -test: - @set -e; for dir in $(ALL_GO_MOD_DIRS); do \ - echo "$(GO) test -timeout $(TIMEOUT)s $(ARGS) $${dir}/..."; \ - (cd "$${dir}" && \ - $(GO) list ./... \ - | grep -v third_party \ - | xargs $(GO) test -timeout $(TIMEOUT)s $(ARGS)); \ - done - -COVERAGE_MODE = atomic -COVERAGE_PROFILE = coverage.out -.PHONY: test-coverage -test-coverage: - @set -e; \ - printf "" > coverage.txt; \ - for dir in $(ALL_COVERAGE_MOD_DIRS); do \ - echo "$(GO) test -coverpkg=./... -covermode=$(COVERAGE_MODE) -coverprofile="$(COVERAGE_PROFILE)" $${dir}/..."; \ - (cd "$${dir}" && \ - $(GO) list ./... \ - | grep -v third_party \ - | xargs $(GO) test -coverpkg=./... -covermode=$(COVERAGE_MODE) -coverprofile="$(COVERAGE_PROFILE)" && \ - $(GO) tool cover -html=coverage.out -o coverage.html); \ - [ -f "$${dir}/coverage.out" ] && cat "$${dir}/coverage.out" >> coverage.txt; \ - done; \ - sed -i.bak -e '2,$$ { /^mode: /d; }' coverage.txt - -.PHONY: lint -lint: misspell lint-modules | $(GOLANGCI_LINT) - set -e; for dir in $(ALL_GO_MOD_DIRS); do \ - echo "golangci-lint in $${dir}"; \ - (cd "$${dir}" && \ - $(GOLANGCI_LINT) run --fix && \ - $(GOLANGCI_LINT) run); \ - done - -.PHONY: misspell -misspell: | $(MISSPELL) - $(MISSPELL) -w $(ALL_DOCS) - -.PHONY: lint-modules -lint-modules: | $(CROSSLINK) - set -e; for dir in $(ALL_GO_MOD_DIRS) $(TOOLS_MOD_DIR); do \ - echo "$(GO) mod tidy in $${dir}"; \ - (cd "$${dir}" && \ - $(GO) mod tidy); \ - done - echo "cross-linking all go modules" - $(CROSSLINK) - -.PHONY: license-check -license-check: - @licRes=$$(for f in $$(find . -type f \( -iname '*.go' -o -iname '*.sh' \) ! -path '**/third_party/*' ! -path './exporters/otlp/internal/opentelemetry-proto/*') ; do \ - awk '/Copyright The OpenTelemetry Authors|generated|GENERATED/ && NR<=3 { found=1; next } END { if (!found) print FILENAME }' $$f; \ - done); \ - if [ -n "$${licRes}" ]; then \ - echo "license header checking failed:"; echo "$${licRes}"; \ - exit 1; \ - fi - -.PHONY: dependabot-check -dependabot-check: - @result=$$( \ - for f in $$( find . -type f -name go.mod -exec dirname {} \; | sed 's/^.\/\?/\//' ); \ - do grep -q "$$f" .github/dependabot.yml \ - || echo "$$f"; \ - done; \ - ); \ - if [ -n "$$result" ]; then \ - echo "missing go.mod dependabot check:"; echo "$$result"; \ - exit 1; \ - fi - -.PHONY: check-clean-work-tree -check-clean-work-tree: - @if ! git diff --quiet; then \ - echo; \ - echo 'Working tree is not clean, did you forget to run "make precommit"?'; \ - echo; \ - git status; \ - exit 1; \ - fi diff --git a/vendor/go.opentelemetry.io/otel/README.md b/vendor/go.opentelemetry.io/otel/README.md deleted file mode 100644 index c841ba896e..0000000000 --- a/vendor/go.opentelemetry.io/otel/README.md +++ /dev/null @@ -1,92 +0,0 @@ -# OpenTelemetry-Go - -[![CI](https://github.com/open-telemetry/opentelemetry-go/workflows/ci/badge.svg)](https://github.com/open-telemetry/opentelemetry-go/actions?query=workflow%3Aci+branch%3Amain) -[![PkgGoDev](https://pkg.go.dev/badge/go.opentelemetry.io/otel)](https://pkg.go.dev/go.opentelemetry.io/otel) -[![Go Report Card](https://goreportcard.com/badge/go.opentelemetry.io/otel)](https://goreportcard.com/report/go.opentelemetry.io/otel) -[![Slack](https://img.shields.io/badge/slack-@cncf/otel--go-brightgreen.svg?logo=slack)](https://cloud-native.slack.com/archives/C01NPAXACKT) - - -The Go [OpenTelemetry](https://opentelemetry.io/) implementation. - -## Project Status - -**Warning**: this project is currently in a pre-GA phase. Backwards -incompatible changes may be introduced in subsequent minor version releases as -we work to track the evolving OpenTelemetry specification and user feedback. - -Our progress towards a GA release candidate is tracked in [this project -board](https://github.com/orgs/open-telemetry/projects/5). This release -candidate will follow semantic versioning and will be released with a major -version greater than zero. - -Progress and status specific to this repository is tracked in our local -[project boards](https://github.com/open-telemetry/opentelemetry-go/projects) -and -[milestones](https://github.com/open-telemetry/opentelemetry-go/milestones). - -Project versioning information and stability guarantees can be found in the -[versioning documentation](./VERSIONING.md). - -### Compatibility - -This project is tested on the following systems. - -| OS | Go Version | Architecture | -| ------- | ---------- | ------------ | -| Ubuntu | 1.15 | amd64 | -| Ubuntu | 1.14 | amd64 | -| Ubuntu | 1.15 | 386 | -| Ubuntu | 1.14 | 386 | -| MacOS | 1.15 | amd64 | -| MacOS | 1.14 | amd64 | -| Windows | 1.15 | amd64 | -| Windows | 1.14 | amd64 | -| Windows | 1.15 | 386 | -| Windows | 1.14 | 386 | - -While this project should work for other systems, no compatibility guarantees -are made for those systems currently. - -## Getting Started - -You can find a getting started guide on [opentelemetry.io](https://opentelemetry.io/docs/go/getting-started/). - -OpenTelemetry's goal is to provide a single set of APIs to capture distributed -traces and metrics from your application and send them to an observability -platform. This project allows you to do just that for applications written in -Go. There are two steps to this process: instrument your application, and -configure an exporter. - -### Instrumentation - -To start capturing distributed traces and metric events from your application -it first needs to be instrumented. The easiest way to do this is by using an -instrumentation library for your code. Be sure to check out [the officially -supported instrumentation -libraries](https://github.com/open-telemetry/opentelemetry-go-contrib/tree/main/instrumentation). - -If you need to extend the telemetry an instrumentation library provides or want -to build your own instrumentation for your application directly you will need -to use the -[go.opentelemetry.io/otel/api](https://pkg.go.dev/go.opentelemetry.io/otel/api) -package. The included [examples](./example/) are a good way to see some -practical uses of this process. - -### Export - -Now that your application is instrumented to collect telemetry, it needs an -export pipeline to send that telemetry to an observability platform. - -You can find officially supported exporters [here](./exporters/) and in the -companion [contrib -repository](https://github.com/open-telemetry/opentelemetry-go-contrib/tree/main/exporters/metric). -Additionally, there are many vendor specific or 3rd party exporters for -OpenTelemetry. These exporters are broken down by -[trace](https://pkg.go.dev/go.opentelemetry.io/otel/sdk/export/trace?tab=importedby) -and -[metric](https://pkg.go.dev/go.opentelemetry.io/otel/sdk/export/metric?tab=importedby) -support. - -## Contributing - -See the [contributing documentation](CONTRIBUTING.md). diff --git a/vendor/go.opentelemetry.io/otel/RELEASING.md b/vendor/go.opentelemetry.io/otel/RELEASING.md deleted file mode 100644 index 71d23b47a5..0000000000 --- a/vendor/go.opentelemetry.io/otel/RELEASING.md +++ /dev/null @@ -1,81 +0,0 @@ -# Release Process - -## Pre-Release - -Update go.mod for submodules to depend on the new release which will happen in the next step. - -1. Run the pre-release script. It creates a branch `pre_release_` that will contain all release changes. - - ``` - ./pre_release.sh -t - ``` - -2. Verify the changes. - - ``` - git diff main - ``` - - This should have changed the version for all modules to be ``. - -3. Update the [Changelog](./CHANGELOG.md). - - Make sure all relevant changes for this release are included and are in language that non-contributors to the project can understand. - To verify this, you can look directly at the commits since the ``. - - ``` - git --no-pager log --pretty=oneline "..HEAD" - ``` - - - Move all the `Unreleased` changes into a new section following the title scheme (`[] - `). - - Update all the appropriate links at the bottom. - -4. Push the changes to upstream and create a Pull Request on GitHub. - Be sure to include the curated changes from the [Changelog](./CHANGELOG.md) in the description. - - -## Tag - -Once the Pull Request with all the version changes has been approved and merged it is time to tag the merged commit. - -***IMPORTANT***: It is critical you use the same tag that you used in the Pre-Release step! -Failure to do so will leave things in a broken state. - -***IMPORTANT***: [There is currently no way to remove an incorrectly tagged version of a Go module](https://github.com/golang/go/issues/34189). -It is critical you make sure the version you push upstream is correct. -[Failure to do so will lead to minor emergencies and tough to work around](https://github.com/open-telemetry/opentelemetry-go/issues/331). - -1. Run the tag.sh script using the `` of the commit on the main branch for the merged Pull Request. - - ``` - ./tag.sh - ``` - -2. Push tags to the upstream remote (not your fork: `github.com/open-telemetry/opentelemetry-go.git`). - Make sure you push all sub-modules as well. - - ``` - git push upstream - git push upstream - ... - ``` - -## Release - -Finally create a Release for the new `` on GitHub. -The release body should include all the release notes from the Changelog for this release. -Additionally, the `tag.sh` script generates commit logs since last release which can be used to supplement the release notes. - -## Verify Examples - -After releasing verify that examples build outside of the repository. - -``` -./verify_examples.sh -``` - -The script copies examples into a different directory removes any `replace` declarations in `go.mod` and builds them. -This ensures they build with the published release, not the local copy. - -## Contrib Repository - -Once verified be sure to [make a release for the `contrib` repository](https://github.com/open-telemetry/opentelemetry-go-contrib/blob/main/RELEASING.md) that uses this release. diff --git a/vendor/go.opentelemetry.io/otel/VERSIONING.md b/vendor/go.opentelemetry.io/otel/VERSIONING.md deleted file mode 100644 index 3579b794ee..0000000000 --- a/vendor/go.opentelemetry.io/otel/VERSIONING.md +++ /dev/null @@ -1,217 +0,0 @@ -# Versioning - -This document describes the versioning policy for this repository. This policy -is designed so the following goals can be achieved. - -**Users are provided a codebase of value that is stable and secure.** - -## Policy - -* Versioning of this project will be idiomatic of a Go project using [Go - modules](https://github.com/golang/go/wiki/Modules). - * [Semantic import - versioning](https://github.com/golang/go/wiki/Modules#semantic-import-versioning) - will be used. - * Versions will comply with [semver 2.0](https://semver.org/spec/v2.0.0.html). - * If a module is version `v2` or higher, the major version of the module - must be included as a `/vN` at the end of the module paths used in - `go.mod` files (e.g., `module go.opentelemetry.io/otel/v2`, `require - go.opentelemetry.io/otel/v2 v2.0.1`) and in the package import path - (e.g., `import "go.opentelemetry.io/otel/v2/trace"`). This includes the - paths used in `go get` commands (e.g., `go get - go.opentelemetry.io/otel/v2@v2.0.1`. Note there is both a `/v2` and a - `@v2.0.1` in that example. One way to think about it is that the module - name now includes the `/v2`, so include `/v2` whenever you are using the - module name). - * If a module is version `v0` or `v1`, do not include the major version in - either the module path or the import path. - * Modules will be used to encapsulate signals and components. - * Experimental modules still under active development will be versioned at - `v0` to imply the stability guarantee defined by - [semver](https://semver.org/spec/v2.0.0.html#spec-item-4). - - > Major version zero (0.y.z) is for initial development. Anything MAY - > change at any time. The public API SHOULD NOT be considered stable. - - * Mature modules for which we guarantee a stable public API will be versioned - with a major version greater than `v0`. - * The decision to make a module stable will be made on a case-by-case - basis by the maintainers of this project. - * Experimental modules will start their versioning at `v0.0.0` and will - increment their minor version when backwards incompatible changes are - released and increment their patch version when backwards compatible - changes are released. - * All stable modules that use the same major version number will use the - same entire version number. - * Stable modules may be released with an incremented minor or patch - version even though that module has not been changed, but rather so - that it will remain at the same version as other stable modules that - did undergo change. - * When an experimental module becomes stable a new stable module version - will be released and will include this now stable module. The new - stable module version will be an increment of the minor version number - and will be applied to all existing stable modules as well as the newly - stable module being released. -* Versioning of the associated [contrib - repository](https://github.com/open-telemetry/opentelemetry-go-contrib) of - this project will be idiomatic of a Go project using [Go - modules](https://github.com/golang/go/wiki/Modules). - * [Semantic import - versioning](https://github.com/golang/go/wiki/Modules#semantic-import-versioning) - will be used. - * Versions will comply with [semver 2.0](https://semver.org/spec/v2.0.0.html). - * If a module is version `v2` or higher, the - major version of the module must be included as a `/vN` at the end of the - module paths used in `go.mod` files (e.g., `module - go.opentelemetry.io/contrib/instrumentation/host/v2`, `require - go.opentelemetry.io/contrib/instrumentation/host/v2 v2.0.1`) and in the - package import path (e.g., `import - "go.opentelemetry.io/contrib/instrumentation/host/v2"`). This includes - the paths used in `go get` commands (e.g., `go get - go.opentelemetry.io/contrib/instrumentation/host/v2@v2.0.1`. Note there - is both a `/v2` and a `@v2.0.1` in that example. One way to think about - it is that the module name now includes the `/v2`, so include `/v2` - whenever you are using the module name). - * If a module is version `v0` or `v1`, do not include the major version - in either the module path or the import path. - * In addition to public APIs, telemetry produced by stable instrumentation - will remain stable and backwards compatible. This is to avoid breaking - alerts and dashboard. - * Modules will be used to encapsulate instrumentation, detectors, exporters, - propagators, and any other independent sets of related components. - * Experimental modules still under active development will be versioned at - `v0` to imply the stability guarantee defined by - [semver](https://semver.org/spec/v2.0.0.html#spec-item-4). - - > Major version zero (0.y.z) is for initial development. Anything MAY - > change at any time. The public API SHOULD NOT be considered stable. - - * Mature modules for which we guarantee a stable public API and telemetry will - be versioned with a major version greater than `v0`. - * Experimental modules will start their versioning at `v0.0.0` and will - increment their minor version when backwards incompatible changes are - released and increment their patch version when backwards compatible - changes are released. - * Stable contrib modules cannot depend on experimental modules from this - project. - * All stable contrib modules of the same major version with this project - will use the same entire version as this project. - * Stable modules may be released with an incremented minor or patch - version even though that module's code has not been changed. Instead - the only change that will have been included is to have updated that - modules dependency on this project's stable APIs. - * When an experimental module in contrib becomes stable a new stable - module version will be released and will include this now stable - module. The new stable module version will be an increment of the minor - version number and will be applied to all existing stable contrib - modules, this project's modules, and the newly stable module being - released. - * Contrib modules will be kept up to date with this project's releases. - * Due to the dependency contrib modules will implicitly have on this - project's modules the release of stable contrib modules to match the - released version number will be staggered after this project's release. - There is no explicit time guarantee for how long after this projects - release the contrib release will be. Effort should be made to keep them - as close in time as possible. - * No additional stable release in this project can be made until the - contrib repository has a matching stable release. - * No release can be made in the contrib repository after this project's - stable release except for a stable release of the contrib repository. -* GitHub releases will be made for all releases. -* Go modules will be made available at Go package mirrors. - -## Example Versioning Lifecycle - -To better understand the implementation of the above policy the following -example is provided. This project is simplified to include only the following -modules and their versions: - -* `otel`: `v0.14.0` -* `otel/trace`: `v0.14.0` -* `otel/metric`: `v0.14.0` -* `otel/baggage`: `v0.14.0` -* `otel/sdk/trace`: `v0.14.0` -* `otel/sdk/metric`: `v0.14.0` - -These modules have been developed to a point where the `otel/trace`, -`otel/baggage`, and `otel/sdk/trace` modules have reached a point that they -should be considered for a stable release. The `otel/metric` and -`otel/sdk/metric` are still under active development and the `otel` module -depends on both `otel/trace` and `otel/metric`. - -The `otel` package is refactored to remove its dependencies on `otel/metric` so -it can be released as stable as well. With that done the following release -candidates are made: - -* `otel`: `v1.0.0-rc.1` -* `otel/trace`: `v1.0.0-rc.1` -* `otel/baggage`: `v1.0.0-rc.1` -* `otel/sdk/trace`: `v1.0.0-rc.1` - -The `otel/metric` and `otel/sdk/metric` modules remain at `v0.14.0`. - -A few minor issues are discovered in the `otel/trace` package. These issues are -resolved with some minor, but backwards incompatible, changes and are released -as a second release candidate: - -* `otel`: `v1.0.0-rc.2` -* `otel/trace`: `v1.0.0-rc.2` -* `otel/baggage`: `v1.0.0-rc.2` -* `otel/sdk/trace`: `v1.0.0-rc.2` - -Notice that all module version numbers are incremented to adhere to our -versioning policy. - -After these release candidates have been evaluated to satisfaction, they are -released as version `v1.0.0`. - -* `otel`: `v1.0.0` -* `otel/trace`: `v1.0.0` -* `otel/baggage`: `v1.0.0` -* `otel/sdk/trace`: `v1.0.0` - -Since both the `go` utility and the Go module system support [the semantic -versioning definition of -precedence](https://semver.org/spec/v2.0.0.html#spec-item-11), this release -will correctly be interpreted as the successor to the previous release -candidates. - -Active development of this project continues. The `otel/metric` module now has -backwards incompatible changes to its API that need to be released and the -`otel/baggage` module has a minor bug fix that needs to be released. The -following release is made: - -* `otel`: `v1.0.1` -* `otel/trace`: `v1.0.1` -* `otel/metric`: `v0.15.0` -* `otel/baggage`: `v1.0.1` -* `otel/sdk/trace`: `v1.0.1` -* `otel/sdk/metric`: `v0.15.0` - -Notice that, again, all stable module versions are incremented in unison and -the `otel/sdk/metric` package, which depends on the `otel/metric` package, also -bumped its version. This bump of the `otel/sdk/metric` package makes sense -given their coupling, though it is not explicitly required by our versioning -policy. - -As we progress, the `otel/metric` and `otel/sdk/metric` packages have reached a -point where they should be evaluated for stability. The `otel` module is -reintegrated with the `otel/metric` package and the following release is made: - -* `otel`: `v1.1.0-rc.1` -* `otel/trace`: `v1.1.0-rc.1` -* `otel/metric`: `v1.1.0-rc.1` -* `otel/baggage`: `v1.1.0-rc.1` -* `otel/sdk/trace`: `v1.1.0-rc.1` -* `otel/sdk/metric`: `v1.1.0-rc.1` - -All the modules are evaluated and determined to a viable stable release. They -are then released as version `v1.1.0` (the minor version is incremented to -indicate the addition of new signal). - -* `otel`: `v1.1.0` -* `otel/trace`: `v1.1.0` -* `otel/metric`: `v1.1.0` -* `otel/baggage`: `v1.1.0` -* `otel/sdk/trace`: `v1.1.0` -* `otel/sdk/metric`: `v1.1.0` diff --git a/vendor/go.opentelemetry.io/otel/attribute/doc.go b/vendor/go.opentelemetry.io/otel/attribute/doc.go deleted file mode 100644 index 44bc32c9e0..0000000000 --- a/vendor/go.opentelemetry.io/otel/attribute/doc.go +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// package attribute provides key and value attributes. -// -// This package is currently in a pre-GA phase. Backwards incompatible changes -// may be introduced in subsequent minor version releases as we work to track -// the evolving OpenTelemetry specification and user feedback. -package attribute // import "go.opentelemetry.io/otel/attribute" diff --git a/vendor/go.opentelemetry.io/otel/attribute/encoder.go b/vendor/go.opentelemetry.io/otel/attribute/encoder.go deleted file mode 100644 index 8b940f78dc..0000000000 --- a/vendor/go.opentelemetry.io/otel/attribute/encoder.go +++ /dev/null @@ -1,150 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package attribute // import "go.opentelemetry.io/otel/attribute" - -import ( - "bytes" - "sync" - "sync/atomic" -) - -type ( - // Encoder is a mechanism for serializing a label set into a - // specific string representation that supports caching, to - // avoid repeated serialization. An example could be an - // exporter encoding the label set into a wire representation. - Encoder interface { - // Encode returns the serialized encoding of the label - // set using its Iterator. This result may be cached - // by a attribute.Set. - Encode(iterator Iterator) string - - // ID returns a value that is unique for each class of - // label encoder. Label encoders allocate these using - // `NewEncoderID`. - ID() EncoderID - } - - // EncoderID is used to identify distinct Encoder - // implementations, for caching encoded results. - EncoderID struct { - value uint64 - } - - // defaultLabelEncoder uses a sync.Pool of buffers to reduce - // the number of allocations used in encoding labels. This - // implementation encodes a comma-separated list of key=value, - // with '/'-escaping of '=', ',', and '\'. - defaultLabelEncoder struct { - // pool is a pool of labelset builders. The buffers in this - // pool grow to a size that most label encodings will not - // allocate new memory. - pool sync.Pool // *bytes.Buffer - } -) - -// escapeChar is used to ensure uniqueness of the label encoding where -// keys or values contain either '=' or ','. Since there is no parser -// needed for this encoding and its only requirement is to be unique, -// this choice is arbitrary. Users will see these in some exporters -// (e.g., stdout), so the backslash ('\') is used as a conventional choice. -const escapeChar = '\\' - -var ( - _ Encoder = &defaultLabelEncoder{} - - // encoderIDCounter is for generating IDs for other label - // encoders. - encoderIDCounter uint64 - - defaultEncoderOnce sync.Once - defaultEncoderID = NewEncoderID() - defaultEncoderInstance *defaultLabelEncoder -) - -// NewEncoderID returns a unique label encoder ID. It should be -// called once per each type of label encoder. Preferably in init() or -// in var definition. -func NewEncoderID() EncoderID { - return EncoderID{value: atomic.AddUint64(&encoderIDCounter, 1)} -} - -// DefaultEncoder returns a label encoder that encodes labels -// in such a way that each escaped label's key is followed by an equal -// sign and then by an escaped label's value. All key-value pairs are -// separated by a comma. -// -// Escaping is done by prepending a backslash before either a -// backslash, equal sign or a comma. -func DefaultEncoder() Encoder { - defaultEncoderOnce.Do(func() { - defaultEncoderInstance = &defaultLabelEncoder{ - pool: sync.Pool{ - New: func() interface{} { - return &bytes.Buffer{} - }, - }, - } - }) - return defaultEncoderInstance -} - -// Encode is a part of an implementation of the LabelEncoder -// interface. -func (d *defaultLabelEncoder) Encode(iter Iterator) string { - buf := d.pool.Get().(*bytes.Buffer) - defer d.pool.Put(buf) - buf.Reset() - - for iter.Next() { - i, keyValue := iter.IndexedLabel() - if i > 0 { - _, _ = buf.WriteRune(',') - } - copyAndEscape(buf, string(keyValue.Key)) - - _, _ = buf.WriteRune('=') - - if keyValue.Value.Type() == STRING { - copyAndEscape(buf, keyValue.Value.AsString()) - } else { - _, _ = buf.WriteString(keyValue.Value.Emit()) - } - } - return buf.String() -} - -// ID is a part of an implementation of the LabelEncoder interface. -func (*defaultLabelEncoder) ID() EncoderID { - return defaultEncoderID -} - -// copyAndEscape escapes `=`, `,` and its own escape character (`\`), -// making the default encoding unique. -func copyAndEscape(buf *bytes.Buffer, val string) { - for _, ch := range val { - switch ch { - case '=', ',', escapeChar: - buf.WriteRune(escapeChar) - } - buf.WriteRune(ch) - } -} - -// Valid returns true if this encoder ID was allocated by -// `NewEncoderID`. Invalid encoder IDs will not be cached. -func (id EncoderID) Valid() bool { - return id.value != 0 -} diff --git a/vendor/go.opentelemetry.io/otel/attribute/iterator.go b/vendor/go.opentelemetry.io/otel/attribute/iterator.go deleted file mode 100644 index e03aabb62b..0000000000 --- a/vendor/go.opentelemetry.io/otel/attribute/iterator.go +++ /dev/null @@ -1,143 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package attribute // import "go.opentelemetry.io/otel/attribute" - -// Iterator allows iterating over the set of labels in order, -// sorted by key. -type Iterator struct { - storage *Set - idx int -} - -// MergeIterator supports iterating over two sets of labels while -// eliminating duplicate values from the combined set. The first -// iterator value takes precedence. -type MergeIterator struct { - one oneIterator - two oneIterator - current KeyValue -} - -type oneIterator struct { - iter Iterator - done bool - label KeyValue -} - -// Next moves the iterator to the next position. Returns false if there -// are no more labels. -func (i *Iterator) Next() bool { - i.idx++ - return i.idx < i.Len() -} - -// Label returns current KeyValue. Must be called only after Next returns -// true. -func (i *Iterator) Label() KeyValue { - kv, _ := i.storage.Get(i.idx) - return kv -} - -// Attribute is a synonym for Label(). -func (i *Iterator) Attribute() KeyValue { - return i.Label() -} - -// IndexedLabel returns current index and attribute. Must be called only -// after Next returns true. -func (i *Iterator) IndexedLabel() (int, KeyValue) { - return i.idx, i.Label() -} - -// Len returns a number of labels in the iterator's `*Set`. -func (i *Iterator) Len() int { - return i.storage.Len() -} - -// ToSlice is a convenience function that creates a slice of labels -// from the passed iterator. The iterator is set up to start from the -// beginning before creating the slice. -func (i *Iterator) ToSlice() []KeyValue { - l := i.Len() - if l == 0 { - return nil - } - i.idx = -1 - slice := make([]KeyValue, 0, l) - for i.Next() { - slice = append(slice, i.Label()) - } - return slice -} - -// NewMergeIterator returns a MergeIterator for merging two label sets -// Duplicates are resolved by taking the value from the first set. -func NewMergeIterator(s1, s2 *Set) MergeIterator { - mi := MergeIterator{ - one: makeOne(s1.Iter()), - two: makeOne(s2.Iter()), - } - return mi -} - -func makeOne(iter Iterator) oneIterator { - oi := oneIterator{ - iter: iter, - } - oi.advance() - return oi -} - -func (oi *oneIterator) advance() { - if oi.done = !oi.iter.Next(); !oi.done { - oi.label = oi.iter.Label() - } -} - -// Next returns true if there is another label available. -func (m *MergeIterator) Next() bool { - if m.one.done && m.two.done { - return false - } - if m.one.done { - m.current = m.two.label - m.two.advance() - return true - } - if m.two.done { - m.current = m.one.label - m.one.advance() - return true - } - if m.one.label.Key == m.two.label.Key { - m.current = m.one.label // first iterator label value wins - m.one.advance() - m.two.advance() - return true - } - if m.one.label.Key < m.two.label.Key { - m.current = m.one.label - m.one.advance() - return true - } - m.current = m.two.label - m.two.advance() - return true -} - -// Label returns the current value after Next() returns true. -func (m *MergeIterator) Label() KeyValue { - return m.current -} diff --git a/vendor/go.opentelemetry.io/otel/attribute/key.go b/vendor/go.opentelemetry.io/otel/attribute/key.go deleted file mode 100644 index 492c438a9f..0000000000 --- a/vendor/go.opentelemetry.io/otel/attribute/key.go +++ /dev/null @@ -1,102 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package attribute // import "go.opentelemetry.io/otel/attribute" - -// Key represents the key part in key-value pairs. It's a string. The -// allowed character set in the key depends on the use of the key. -type Key string - -// Bool creates a KeyValue instance with a BOOL Value. -// -// If creating both key and a bool value at the same time, then -// instead of calling Key(name).Bool(value) consider using a -// convenience function provided by the api/key package - -// key.Bool(name, value). -func (k Key) Bool(v bool) KeyValue { - return KeyValue{ - Key: k, - Value: BoolValue(v), - } -} - -// Int64 creates a KeyValue instance with an INT64 Value. -// -// If creating both key and an int64 value at the same time, then -// instead of calling Key(name).Int64(value) consider using a -// convenience function provided by the api/key package - -// key.Int64(name, value). -func (k Key) Int64(v int64) KeyValue { - return KeyValue{ - Key: k, - Value: Int64Value(v), - } -} - -// Float64 creates a KeyValue instance with a FLOAT64 Value. -// -// If creating both key and a float64 value at the same time, then -// instead of calling Key(name).Float64(value) consider using a -// convenience function provided by the api/key package - -// key.Float64(name, value). -func (k Key) Float64(v float64) KeyValue { - return KeyValue{ - Key: k, - Value: Float64Value(v), - } -} - -// String creates a KeyValue instance with a STRING Value. -// -// If creating both key and a string value at the same time, then -// instead of calling Key(name).String(value) consider using a -// convenience function provided by the api/key package - -// key.String(name, value). -func (k Key) String(v string) KeyValue { - return KeyValue{ - Key: k, - Value: StringValue(v), - } -} - -// Int creates a KeyValue instance with an INT64 Value. -// -// If creating both key and an int value at the same time, then -// instead of calling Key(name).Int(value) consider using a -// convenience function provided by the api/key package - -// key.Int(name, value). -func (k Key) Int(v int) KeyValue { - return KeyValue{ - Key: k, - Value: IntValue(v), - } -} - -// Defined returns true for non-empty keys. -func (k Key) Defined() bool { - return len(k) != 0 -} - -// Array creates a KeyValue instance with a ARRAY Value. -// -// If creating both key and a array value at the same time, then -// instead of calling Key(name).String(value) consider using a -// convenience function provided by the api/key package - -// key.Array(name, value). -func (k Key) Array(v interface{}) KeyValue { - return KeyValue{ - Key: k, - Value: ArrayValue(v), - } -} diff --git a/vendor/go.opentelemetry.io/otel/attribute/kv.go b/vendor/go.opentelemetry.io/otel/attribute/kv.go deleted file mode 100644 index 2fcc8863f7..0000000000 --- a/vendor/go.opentelemetry.io/otel/attribute/kv.go +++ /dev/null @@ -1,108 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package attribute // import "go.opentelemetry.io/otel/attribute" - -import ( - "encoding/json" - "fmt" - "reflect" -) - -// KeyValue holds a key and value pair. -type KeyValue struct { - Key Key - Value Value -} - -// Valid returns if kv is a valid OpenTelemetry attribute. -func (kv KeyValue) Valid() bool { - return kv.Key != "" && kv.Value.Type() != INVALID -} - -// Bool creates a new key-value pair with a passed name and a bool -// value. -func Bool(k string, v bool) KeyValue { - return Key(k).Bool(v) -} - -// Int64 creates a new key-value pair with a passed name and an int64 -// value. -func Int64(k string, v int64) KeyValue { - return Key(k).Int64(v) -} - -// Float64 creates a new key-value pair with a passed name and a float64 -// value. -func Float64(k string, v float64) KeyValue { - return Key(k).Float64(v) -} - -// String creates a new key-value pair with a passed name and a string -// value. -func String(k, v string) KeyValue { - return Key(k).String(v) -} - -// Stringer creates a new key-value pair with a passed name and a string -// value generated by the passed Stringer interface. -func Stringer(k string, v fmt.Stringer) KeyValue { - return Key(k).String(v.String()) -} - -// Int creates a new key-value pair instance with a passed name and -// either an int32 or an int64 value, depending on whether the int -// type is 32 or 64 bits wide. -func Int(k string, v int) KeyValue { - return Key(k).Int(v) -} - -// Array creates a new key-value pair with a passed name and a array. -// Only arrays of primitive type are supported. -func Array(k string, v interface{}) KeyValue { - return Key(k).Array(v) -} - -// Any creates a new key-value pair instance with a passed name and -// automatic type inference. This is slower, and not type-safe. -func Any(k string, value interface{}) KeyValue { - if value == nil { - return String(k, "") - } - - if stringer, ok := value.(fmt.Stringer); ok { - return String(k, stringer.String()) - } - - rv := reflect.ValueOf(value) - - switch rv.Kind() { - case reflect.Array, reflect.Slice: - return Array(k, value) - case reflect.Bool: - return Bool(k, rv.Bool()) - case reflect.Int, reflect.Int8, reflect.Int16: - return Int(k, int(rv.Int())) - case reflect.Int64: - return Int64(k, rv.Int()) - case reflect.Float64: - return Float64(k, rv.Float()) - case reflect.String: - return String(k, rv.String()) - } - if b, err := json.Marshal(value); b != nil && err == nil { - return String(k, string(b)) - } - return String(k, fmt.Sprint(value)) -} diff --git a/vendor/go.opentelemetry.io/otel/attribute/set.go b/vendor/go.opentelemetry.io/otel/attribute/set.go deleted file mode 100644 index 882dc112f7..0000000000 --- a/vendor/go.opentelemetry.io/otel/attribute/set.go +++ /dev/null @@ -1,471 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package attribute // import "go.opentelemetry.io/otel/attribute" - -import ( - "encoding/json" - "reflect" - "sort" - "sync" -) - -type ( - // Set is the representation for a distinct label set. It - // manages an immutable set of labels, with an internal cache - // for storing label encodings. - // - // This type supports the `Equivalent` method of comparison - // using values of type `Distinct`. - // - // This type is used to implement: - // 1. Metric labels - // 2. Resource sets - // 3. Correlation map (TODO) - Set struct { - equivalent Distinct - - lock sync.Mutex - encoders [maxConcurrentEncoders]EncoderID - encoded [maxConcurrentEncoders]string - } - - // Distinct wraps a variable-size array of `KeyValue`, - // constructed with keys in sorted order. This can be used as - // a map key or for equality checking between Sets. - Distinct struct { - iface interface{} - } - - // Filter supports removing certain labels from label sets. - // When the filter returns true, the label will be kept in - // the filtered label set. When the filter returns false, the - // label is excluded from the filtered label set, and the - // label instead appears in the `removed` list of excluded labels. - Filter func(KeyValue) bool - - // Sortable implements `sort.Interface`, used for sorting - // `KeyValue`. This is an exported type to support a - // memory optimization. A pointer to one of these is needed - // for the call to `sort.Stable()`, which the caller may - // provide in order to avoid an allocation. See - // `NewSetWithSortable()`. - Sortable []KeyValue -) - -var ( - // keyValueType is used in `computeDistinctReflect`. - keyValueType = reflect.TypeOf(KeyValue{}) - - // emptySet is returned for empty label sets. - emptySet = &Set{ - equivalent: Distinct{ - iface: [0]KeyValue{}, - }, - } -) - -const maxConcurrentEncoders = 3 - -// EmptySet returns a reference to a Set with no elements. -// -// This is a convenience provided for optimized calling utility. -func EmptySet() *Set { - return emptySet -} - -// reflect abbreviates `reflect.ValueOf`. -func (d Distinct) reflect() reflect.Value { - return reflect.ValueOf(d.iface) -} - -// Valid returns true if this value refers to a valid `*Set`. -func (d Distinct) Valid() bool { - return d.iface != nil -} - -// Len returns the number of labels in this set. -func (l *Set) Len() int { - if l == nil || !l.equivalent.Valid() { - return 0 - } - return l.equivalent.reflect().Len() -} - -// Get returns the KeyValue at ordered position `idx` in this set. -func (l *Set) Get(idx int) (KeyValue, bool) { - if l == nil { - return KeyValue{}, false - } - value := l.equivalent.reflect() - - if idx >= 0 && idx < value.Len() { - // Note: The Go compiler successfully avoids an allocation for - // the interface{} conversion here: - return value.Index(idx).Interface().(KeyValue), true - } - - return KeyValue{}, false -} - -// Value returns the value of a specified key in this set. -func (l *Set) Value(k Key) (Value, bool) { - if l == nil { - return Value{}, false - } - rValue := l.equivalent.reflect() - vlen := rValue.Len() - - idx := sort.Search(vlen, func(idx int) bool { - return rValue.Index(idx).Interface().(KeyValue).Key >= k - }) - if idx >= vlen { - return Value{}, false - } - keyValue := rValue.Index(idx).Interface().(KeyValue) - if k == keyValue.Key { - return keyValue.Value, true - } - return Value{}, false -} - -// HasValue tests whether a key is defined in this set. -func (l *Set) HasValue(k Key) bool { - if l == nil { - return false - } - _, ok := l.Value(k) - return ok -} - -// Iter returns an iterator for visiting the labels in this set. -func (l *Set) Iter() Iterator { - return Iterator{ - storage: l, - idx: -1, - } -} - -// ToSlice returns the set of labels belonging to this set, sorted, -// where keys appear no more than once. -func (l *Set) ToSlice() []KeyValue { - iter := l.Iter() - return iter.ToSlice() -} - -// Equivalent returns a value that may be used as a map key. The -// Distinct type guarantees that the result will equal the equivalent -// Distinct value of any label set with the same elements as this, -// where sets are made unique by choosing the last value in the input -// for any given key. -func (l *Set) Equivalent() Distinct { - if l == nil || !l.equivalent.Valid() { - return emptySet.equivalent - } - return l.equivalent -} - -// Equals returns true if the argument set is equivalent to this set. -func (l *Set) Equals(o *Set) bool { - return l.Equivalent() == o.Equivalent() -} - -// Encoded returns the encoded form of this set, according to -// `encoder`. The result will be cached in this `*Set`. -func (l *Set) Encoded(encoder Encoder) string { - if l == nil || encoder == nil { - return "" - } - - id := encoder.ID() - if !id.Valid() { - // Invalid IDs are not cached. - return encoder.Encode(l.Iter()) - } - - var lookup *string - l.lock.Lock() - for idx := 0; idx < maxConcurrentEncoders; idx++ { - if l.encoders[idx] == id { - lookup = &l.encoded[idx] - break - } - } - l.lock.Unlock() - - if lookup != nil { - return *lookup - } - - r := encoder.Encode(l.Iter()) - - l.lock.Lock() - defer l.lock.Unlock() - - for idx := 0; idx < maxConcurrentEncoders; idx++ { - if l.encoders[idx] == id { - return l.encoded[idx] - } - if !l.encoders[idx].Valid() { - l.encoders[idx] = id - l.encoded[idx] = r - return r - } - } - - // TODO: This is a performance cliff. Find a way for this to - // generate a warning. - return r -} - -func empty() Set { - return Set{ - equivalent: emptySet.equivalent, - } -} - -// NewSet returns a new `Set`. See the documentation for -// `NewSetWithSortableFiltered` for more details. -// -// Except for empty sets, this method adds an additional allocation -// compared with calls that include a `*Sortable`. -func NewSet(kvs ...KeyValue) Set { - // Check for empty set. - if len(kvs) == 0 { - return empty() - } - s, _ := NewSetWithSortableFiltered(kvs, new(Sortable), nil) - return s //nolint -} - -// NewSetWithSortable returns a new `Set`. See the documentation for -// `NewSetWithSortableFiltered` for more details. -// -// This call includes a `*Sortable` option as a memory optimization. -func NewSetWithSortable(kvs []KeyValue, tmp *Sortable) Set { - // Check for empty set. - if len(kvs) == 0 { - return empty() - } - s, _ := NewSetWithSortableFiltered(kvs, tmp, nil) - return s //nolint -} - -// NewSetWithFiltered returns a new `Set`. See the documentation for -// `NewSetWithSortableFiltered` for more details. -// -// This call includes a `Filter` to include/exclude label keys from -// the return value. Excluded keys are returned as a slice of label -// values. -func NewSetWithFiltered(kvs []KeyValue, filter Filter) (Set, []KeyValue) { - // Check for empty set. - if len(kvs) == 0 { - return empty(), nil - } - return NewSetWithSortableFiltered(kvs, new(Sortable), filter) -} - -// NewSetWithSortableFiltered returns a new `Set`. -// -// Duplicate keys are eliminated by taking the last value. This -// re-orders the input slice so that unique last-values are contiguous -// at the end of the slice. -// -// This ensures the following: -// -// - Last-value-wins semantics -// - Caller sees the reordering, but doesn't lose values -// - Repeated call preserve last-value wins. -// -// Note that methods are defined on `*Set`, although this returns `Set`. -// Callers can avoid memory allocations by: -// -// - allocating a `Sortable` for use as a temporary in this method -// - allocating a `Set` for storing the return value of this -// constructor. -// -// The result maintains a cache of encoded labels, by attribute.EncoderID. -// This value should not be copied after its first use. -// -// The second `[]KeyValue` return value is a list of labels that were -// excluded by the Filter (if non-nil). -func NewSetWithSortableFiltered(kvs []KeyValue, tmp *Sortable, filter Filter) (Set, []KeyValue) { - // Check for empty set. - if len(kvs) == 0 { - return empty(), nil - } - - *tmp = kvs - - // Stable sort so the following de-duplication can implement - // last-value-wins semantics. - sort.Stable(tmp) - - *tmp = nil - - position := len(kvs) - 1 - offset := position - 1 - - // The requirements stated above require that the stable - // result be placed in the end of the input slice, while - // overwritten values are swapped to the beginning. - // - // De-duplicate with last-value-wins semantics. Preserve - // duplicate values at the beginning of the input slice. - for ; offset >= 0; offset-- { - if kvs[offset].Key == kvs[position].Key { - continue - } - position-- - kvs[offset], kvs[position] = kvs[position], kvs[offset] - } - if filter != nil { - return filterSet(kvs[position:], filter) - } - return Set{ - equivalent: computeDistinct(kvs[position:]), - }, nil -} - -// filterSet reorders `kvs` so that included keys are contiguous at -// the end of the slice, while excluded keys precede the included keys. -func filterSet(kvs []KeyValue, filter Filter) (Set, []KeyValue) { - var excluded []KeyValue - - // Move labels that do not match the filter so - // they're adjacent before calling computeDistinct(). - distinctPosition := len(kvs) - - // Swap indistinct keys forward and distinct keys toward the - // end of the slice. - offset := len(kvs) - 1 - for ; offset >= 0; offset-- { - if filter(kvs[offset]) { - distinctPosition-- - kvs[offset], kvs[distinctPosition] = kvs[distinctPosition], kvs[offset] - continue - } - } - excluded = kvs[:distinctPosition] - - return Set{ - equivalent: computeDistinct(kvs[distinctPosition:]), - }, excluded -} - -// Filter returns a filtered copy of this `Set`. See the -// documentation for `NewSetWithSortableFiltered` for more details. -func (l *Set) Filter(re Filter) (Set, []KeyValue) { - if re == nil { - return Set{ - equivalent: l.equivalent, - }, nil - } - - // Note: This could be refactored to avoid the temporary slice - // allocation, if it proves to be expensive. - return filterSet(l.ToSlice(), re) -} - -// computeDistinct returns a `Distinct` using either the fixed- or -// reflect-oriented code path, depending on the size of the input. -// The input slice is assumed to already be sorted and de-duplicated. -func computeDistinct(kvs []KeyValue) Distinct { - iface := computeDistinctFixed(kvs) - if iface == nil { - iface = computeDistinctReflect(kvs) - } - return Distinct{ - iface: iface, - } -} - -// computeDistinctFixed computes a `Distinct` for small slices. It -// returns nil if the input is too large for this code path. -func computeDistinctFixed(kvs []KeyValue) interface{} { - switch len(kvs) { - case 1: - ptr := new([1]KeyValue) - copy((*ptr)[:], kvs) - return *ptr - case 2: - ptr := new([2]KeyValue) - copy((*ptr)[:], kvs) - return *ptr - case 3: - ptr := new([3]KeyValue) - copy((*ptr)[:], kvs) - return *ptr - case 4: - ptr := new([4]KeyValue) - copy((*ptr)[:], kvs) - return *ptr - case 5: - ptr := new([5]KeyValue) - copy((*ptr)[:], kvs) - return *ptr - case 6: - ptr := new([6]KeyValue) - copy((*ptr)[:], kvs) - return *ptr - case 7: - ptr := new([7]KeyValue) - copy((*ptr)[:], kvs) - return *ptr - case 8: - ptr := new([8]KeyValue) - copy((*ptr)[:], kvs) - return *ptr - case 9: - ptr := new([9]KeyValue) - copy((*ptr)[:], kvs) - return *ptr - case 10: - ptr := new([10]KeyValue) - copy((*ptr)[:], kvs) - return *ptr - default: - return nil - } -} - -// computeDistinctReflect computes a `Distinct` using reflection, -// works for any size input. -func computeDistinctReflect(kvs []KeyValue) interface{} { - at := reflect.New(reflect.ArrayOf(len(kvs), keyValueType)).Elem() - for i, keyValue := range kvs { - *(at.Index(i).Addr().Interface().(*KeyValue)) = keyValue - } - return at.Interface() -} - -// MarshalJSON returns the JSON encoding of the `*Set`. -func (l *Set) MarshalJSON() ([]byte, error) { - return json.Marshal(l.equivalent.iface) -} - -// Len implements `sort.Interface`. -func (l *Sortable) Len() int { - return len(*l) -} - -// Swap implements `sort.Interface`. -func (l *Sortable) Swap(i, j int) { - (*l)[i], (*l)[j] = (*l)[j], (*l)[i] -} - -// Less implements `sort.Interface`. -func (l *Sortable) Less(i, j int) bool { - return (*l)[i].Key < (*l)[j].Key -} diff --git a/vendor/go.opentelemetry.io/otel/attribute/type_string.go b/vendor/go.opentelemetry.io/otel/attribute/type_string.go deleted file mode 100644 index 1f2c7dccfa..0000000000 --- a/vendor/go.opentelemetry.io/otel/attribute/type_string.go +++ /dev/null @@ -1,28 +0,0 @@ -// Code generated by "stringer -type=Type"; DO NOT EDIT. - -package attribute - -import "strconv" - -func _() { - // An "invalid array index" compiler error signifies that the constant values have changed. - // Re-run the stringer command to generate them again. - var x [1]struct{} - _ = x[INVALID-0] - _ = x[BOOL-1] - _ = x[INT64-2] - _ = x[FLOAT64-3] - _ = x[STRING-4] - _ = x[ARRAY-5] -} - -const _Type_name = "INVALIDBOOLINT64FLOAT64STRINGARRAY" - -var _Type_index = [...]uint8{0, 7, 11, 16, 23, 29, 34} - -func (i Type) String() string { - if i < 0 || i >= Type(len(_Type_index)-1) { - return "Type(" + strconv.FormatInt(int64(i), 10) + ")" - } - return _Type_name[_Type_index[i]:_Type_index[i+1]] -} diff --git a/vendor/go.opentelemetry.io/otel/attribute/value.go b/vendor/go.opentelemetry.io/otel/attribute/value.go deleted file mode 100644 index 7b979409e3..0000000000 --- a/vendor/go.opentelemetry.io/otel/attribute/value.go +++ /dev/null @@ -1,204 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package attribute // import "go.opentelemetry.io/otel/attribute" - -import ( - "encoding/json" - "fmt" - "reflect" - "strconv" - - "go.opentelemetry.io/otel/internal" -) - -//go:generate stringer -type=Type - -// Type describes the type of the data Value holds. -type Type int - -// Value represents the value part in key-value pairs. -type Value struct { - vtype Type - numeric uint64 - stringly string - // TODO Lazy value type? - - array interface{} -} - -const ( - // INVALID is used for a Value with no value set. - INVALID Type = iota - // BOOL is a boolean Type Value. - BOOL - // INT64 is a 64-bit signed integral Type Value. - INT64 - // FLOAT64 is a 64-bit floating point Type Value. - FLOAT64 - // STRING is a string Type Value. - STRING - // ARRAY is an array Type Value used to store 1-dimensional slices or - // arrays of bool, int, int32, int64, uint, uint32, uint64, float, - // float32, float64, or string types. - ARRAY -) - -// BoolValue creates a BOOL Value. -func BoolValue(v bool) Value { - return Value{ - vtype: BOOL, - numeric: internal.BoolToRaw(v), - } -} - -// Int64Value creates an INT64 Value. -func Int64Value(v int64) Value { - return Value{ - vtype: INT64, - numeric: internal.Int64ToRaw(v), - } -} - -// Float64Value creates a FLOAT64 Value. -func Float64Value(v float64) Value { - return Value{ - vtype: FLOAT64, - numeric: internal.Float64ToRaw(v), - } -} - -// StringValue creates a STRING Value. -func StringValue(v string) Value { - return Value{ - vtype: STRING, - stringly: v, - } -} - -// IntValue creates an INT64 Value. -func IntValue(v int) Value { - return Int64Value(int64(v)) -} - -// ArrayValue creates an ARRAY value from an array or slice. -// Only arrays or slices of bool, int, int64, float, float64, or string types are allowed. -// Specifically, arrays and slices can not contain other arrays, slices, structs, or non-standard -// types. If the passed value is not an array or slice of these types an -// INVALID value is returned. -func ArrayValue(v interface{}) Value { - switch reflect.TypeOf(v).Kind() { - case reflect.Array, reflect.Slice: - // get array type regardless of dimensions - typ := reflect.TypeOf(v).Elem() - kind := typ.Kind() - switch kind { - case reflect.Bool, reflect.Int, reflect.Int64, - reflect.Float64, reflect.String: - val := reflect.ValueOf(v) - length := val.Len() - frozen := reflect.Indirect(reflect.New(reflect.ArrayOf(length, typ))) - reflect.Copy(frozen, val) - return Value{ - vtype: ARRAY, - array: frozen.Interface(), - } - default: - return Value{vtype: INVALID} - } - } - return Value{vtype: INVALID} -} - -// Type returns a type of the Value. -func (v Value) Type() Type { - return v.vtype -} - -// AsBool returns the bool value. Make sure that the Value's type is -// BOOL. -func (v Value) AsBool() bool { - return internal.RawToBool(v.numeric) -} - -// AsInt64 returns the int64 value. Make sure that the Value's type is -// INT64. -func (v Value) AsInt64() int64 { - return internal.RawToInt64(v.numeric) -} - -// AsFloat64 returns the float64 value. Make sure that the Value's -// type is FLOAT64. -func (v Value) AsFloat64() float64 { - return internal.RawToFloat64(v.numeric) -} - -// AsString returns the string value. Make sure that the Value's type -// is STRING. -func (v Value) AsString() string { - return v.stringly -} - -// AsArray returns the array Value as an interface{}. -func (v Value) AsArray() interface{} { - return v.array -} - -type unknownValueType struct{} - -// AsInterface returns Value's data as interface{}. -func (v Value) AsInterface() interface{} { - switch v.Type() { - case ARRAY: - return v.AsArray() - case BOOL: - return v.AsBool() - case INT64: - return v.AsInt64() - case FLOAT64: - return v.AsFloat64() - case STRING: - return v.stringly - } - return unknownValueType{} -} - -// Emit returns a string representation of Value's data. -func (v Value) Emit() string { - switch v.Type() { - case ARRAY: - return fmt.Sprint(v.array) - case BOOL: - return strconv.FormatBool(v.AsBool()) - case INT64: - return strconv.FormatInt(v.AsInt64(), 10) - case FLOAT64: - return fmt.Sprint(v.AsFloat64()) - case STRING: - return v.stringly - default: - return "unknown" - } -} - -// MarshalJSON returns the JSON encoding of the Value. -func (v Value) MarshalJSON() ([]byte, error) { - var jsonVal struct { - Type string - Value interface{} - } - jsonVal.Type = v.Type().String() - jsonVal.Value = v.AsInterface() - return json.Marshal(jsonVal) -} diff --git a/vendor/go.opentelemetry.io/otel/baggage/baggage.go b/vendor/go.opentelemetry.io/otel/baggage/baggage.go deleted file mode 100644 index 365388c654..0000000000 --- a/vendor/go.opentelemetry.io/otel/baggage/baggage.go +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package baggage // import "go.opentelemetry.io/otel/baggage" - -import ( - "context" - - "go.opentelemetry.io/otel/attribute" - "go.opentelemetry.io/otel/internal/baggage" -) - -// Set returns a copy of the set of baggage key-values in ctx. -func Set(ctx context.Context) attribute.Set { - // TODO (MrAlias, #1222): The underlying storage, the Map, shares many of - // the functional elements of the attribute.Set. These should be unified so - // this conversion is unnecessary and there is no performance hit calling - // this. - m := baggage.MapFromContext(ctx) - values := make([]attribute.KeyValue, 0, m.Len()) - m.Foreach(func(kv attribute.KeyValue) bool { - values = append(values, kv) - return true - }) - return attribute.NewSet(values...) -} - -// Value returns the value related to key in the baggage of ctx. If no -// value is set, the returned attribute.Value will be an uninitialized zero-value -// with type INVALID. -func Value(ctx context.Context, key attribute.Key) attribute.Value { - v, _ := baggage.MapFromContext(ctx).Value(key) - return v -} - -// ContextWithValues returns a copy of parent with pairs updated in the baggage. -func ContextWithValues(parent context.Context, pairs ...attribute.KeyValue) context.Context { - m := baggage.MapFromContext(parent).Apply(baggage.MapUpdate{ - MultiKV: pairs, - }) - return baggage.ContextWithMap(parent, m) -} - -// ContextWithoutValues returns a copy of parent in which the values related -// to keys have been removed from the baggage. -func ContextWithoutValues(parent context.Context, keys ...attribute.Key) context.Context { - m := baggage.MapFromContext(parent).Apply(baggage.MapUpdate{ - DropMultiK: keys, - }) - return baggage.ContextWithMap(parent, m) -} - -// ContextWithEmpty returns a copy of parent without baggage. -func ContextWithEmpty(parent context.Context) context.Context { - return baggage.ContextWithNoCorrelationData(parent) -} diff --git a/vendor/go.opentelemetry.io/otel/baggage/doc.go b/vendor/go.opentelemetry.io/otel/baggage/doc.go deleted file mode 100644 index 4ac3fccee6..0000000000 --- a/vendor/go.opentelemetry.io/otel/baggage/doc.go +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/* -Package baggage provides functionality for storing and retrieving -baggage items in Go context. For propagating the baggage, see the -go.opentelemetry.io/otel/propagation package. - -This package is currently in a pre-GA phase. Backwards incompatible changes -may be introduced in subsequent minor version releases as we work to track the -evolving OpenTelemetry specification and user feedback. -*/ -package baggage // import "go.opentelemetry.io/otel/baggage" diff --git a/vendor/go.opentelemetry.io/otel/codes/codes.go b/vendor/go.opentelemetry.io/otel/codes/codes.go deleted file mode 100644 index 064a9279fd..0000000000 --- a/vendor/go.opentelemetry.io/otel/codes/codes.go +++ /dev/null @@ -1,106 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package codes // import "go.opentelemetry.io/otel/codes" - -import ( - "encoding/json" - "fmt" - "strconv" -) - -const ( - // Unset is the default status code. - Unset Code = 0 - // Error indicates the operation contains an error. - Error Code = 1 - // Ok indicates operation has been validated by an Application developers - // or Operator to have completed successfully, or contain no error. - Ok Code = 2 - - maxCode = 3 -) - -// Code is an 32-bit representation of a status state. -type Code uint32 - -var codeToStr = map[Code]string{ - Unset: "Unset", - Error: "Error", - Ok: "Ok", -} - -var strToCode = map[string]Code{ - `"Unset"`: Unset, - `"Error"`: Error, - `"Ok"`: Ok, -} - -// String returns the Code as a string. -func (c Code) String() string { - return codeToStr[c] -} - -// UnmarshalJSON unmarshals b into the Code. -// -// This is based on the functionality in the gRPC codes package: -// https://github.com/grpc/grpc-go/blob/bb64fee312b46ebee26be43364a7a966033521b1/codes/codes.go#L218-L244 -func (c *Code) UnmarshalJSON(b []byte) error { - // From json.Unmarshaler: By convention, to approximate the behavior of - // Unmarshal itself, Unmarshalers implement UnmarshalJSON([]byte("null")) as - // a no-op. - if string(b) == "null" { - return nil - } - if c == nil { - return fmt.Errorf("nil receiver passed to UnmarshalJSON") - } - - var x interface{} - if err := json.Unmarshal(b, &x); err != nil { - return err - } - switch x.(type) { - case string: - if jc, ok := strToCode[string(b)]; ok { - *c = jc - return nil - } - return fmt.Errorf("invalid code: %q", string(b)) - case float64: - if ci, err := strconv.ParseUint(string(b), 10, 32); err == nil { - if ci >= maxCode { - return fmt.Errorf("invalid code: %q", ci) - } - - *c = Code(ci) - return nil - } - return fmt.Errorf("invalid code: %q", string(b)) - default: - return fmt.Errorf("invalid code: %q", string(b)) - } -} - -// MarshalJSON returns c as the JSON encoding of c. -func (c *Code) MarshalJSON() ([]byte, error) { - if c == nil { - return []byte("null"), nil - } - str, ok := codeToStr[*c] - if !ok { - return nil, fmt.Errorf("invalid code: %d", *c) - } - return []byte(fmt.Sprintf("%q", str)), nil -} diff --git a/vendor/go.opentelemetry.io/otel/codes/doc.go b/vendor/go.opentelemetry.io/otel/codes/doc.go deleted file mode 100644 index fcf89ba1ac..0000000000 --- a/vendor/go.opentelemetry.io/otel/codes/doc.go +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/* -Package codes defines the canonical error codes used by OpenTelemetry. - -This package is currently in a pre-GA phase. Backwards incompatible changes -may be introduced in subsequent minor version releases as we work to track -the evolving OpenTelemetry specification and user feedback. - -It conforms to [the OpenTelemetry -specification](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/api.md#statuscanonicalcode). -*/ -package codes // import "go.opentelemetry.io/otel/codes" diff --git a/vendor/go.opentelemetry.io/otel/doc.go b/vendor/go.opentelemetry.io/otel/doc.go deleted file mode 100644 index 771ce81cc2..0000000000 --- a/vendor/go.opentelemetry.io/otel/doc.go +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/* -Package otel provides global access to the OpenTelemetry API. The subpackages of -the otel package provide an implementation of the OpenTelemetry API. - -This package is currently in a pre-GA phase. Backwards incompatible changes -may be introduced in subsequent minor version releases as we work to track the -evolving OpenTelemetry specification and user feedback. - -The provided API is used to instrument code and measure data about that code's -performance and operation. The measured data, by default, is not processed or -transmitted anywhere. An implementation of the OpenTelemetry SDK, like the -default SDK implementation (go.opentelemetry.io/otel/sdk), and associated -exporters are used to process and transport this data. - -To read the getting started guide, see https://opentelemetry.io/docs/go/getting-started/. - -To read more about tracing, see go.opentelemetry.io/otel/trace. - -To read more about metrics, see go.opentelemetry.io/otel/metric. - -To read more about propagation, see go.opentelemetry.io/otel/propagation and -go.opentelemetry.io/otel/baggage. -*/ -package otel // import "go.opentelemetry.io/otel" diff --git a/vendor/go.opentelemetry.io/otel/error_handler.go b/vendor/go.opentelemetry.io/otel/error_handler.go deleted file mode 100644 index ac42f8be07..0000000000 --- a/vendor/go.opentelemetry.io/otel/error_handler.go +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package otel // import "go.opentelemetry.io/otel" - -// ErrorHandler handles irremediable events. -type ErrorHandler interface { - // Handle handles any error deemed irremediable by an OpenTelemetry - // component. - Handle(error) -} diff --git a/vendor/go.opentelemetry.io/otel/exporters/otlp/LICENSE b/vendor/go.opentelemetry.io/otel/exporters/otlp/LICENSE deleted file mode 100644 index 261eeb9e9f..0000000000 --- a/vendor/go.opentelemetry.io/otel/exporters/otlp/LICENSE +++ /dev/null @@ -1,201 +0,0 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. diff --git a/vendor/go.opentelemetry.io/otel/exporters/otlp/README.md b/vendor/go.opentelemetry.io/otel/exporters/otlp/README.md deleted file mode 100644 index 0cd71f330b..0000000000 --- a/vendor/go.opentelemetry.io/otel/exporters/otlp/README.md +++ /dev/null @@ -1,31 +0,0 @@ -# OpenTelemetry Collector Go Exporter - -[![PkgGoDev](https://pkg.go.dev/badge/go.opentelemetry.io/otel/exporters/otlp)](https://pkg.go.dev/go.opentelemetry.io/otel/exporters/otlp) - -This exporter exports OpenTelemetry spans and metrics to the OpenTelemetry Collector. - - -## Installation and Setup - -The exporter can be installed using standard `go` functionality. - -```bash -$ go get -u go.opentelemetry.io/otel/exporters/otlp -``` - -A new exporter can be created using the `NewExporter` function. - -## Retries - -The exporter will not, by default, retry failed requests to the collector. -However, it is configured in a way that it can be easily enabled. - -To enable retries, the `GRPC_GO_RETRY` environment variable needs to be set to `on`. For example, - -``` -GRPC_GO_RETRY=on go run . -``` - -The [default service config](https://github.com/grpc/proposal/blob/master/A6-client-retries.md) used by default is defined to retry failed requests with exponential backoff (`0.3seconds * (2)^retry`) with [a max of `5` retries](https://github.com/open-telemetry/oteps/blob/be2a3fcbaa417ebbf5845cd485d34fdf0ab4a2a4/text/0035-opentelemetry-protocol.md#export-response)). - -These retries are only attempted for reponses that are [deemed "retry-able" by the collector](https://github.com/grpc/proposal/blob/master/A6-client-retries.md#validation-of-retrypolicy). diff --git a/vendor/go.opentelemetry.io/otel/exporters/otlp/doc.go b/vendor/go.opentelemetry.io/otel/exporters/otlp/doc.go deleted file mode 100644 index d0897bc8cf..0000000000 --- a/vendor/go.opentelemetry.io/otel/exporters/otlp/doc.go +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package otlp contains an exporter for the OpenTelemetry protocol buffers. -// -// This package is currently in a pre-GA phase. Backwards incompatible changes -// may be introduced in subsequent minor version releases as we work to track -// the evolving OpenTelemetry specification and user feedback. -package otlp // import "go.opentelemetry.io/otel/exporters/otlp" diff --git a/vendor/go.opentelemetry.io/otel/exporters/otlp/go.mod b/vendor/go.opentelemetry.io/otel/exporters/otlp/go.mod deleted file mode 100644 index fe4fdba853..0000000000 --- a/vendor/go.opentelemetry.io/otel/exporters/otlp/go.mod +++ /dev/null @@ -1,62 +0,0 @@ -module go.opentelemetry.io/otel/exporters/otlp - -go 1.14 - -replace ( - go.opentelemetry.io/otel => ../.. - go.opentelemetry.io/otel/sdk => ../../sdk -) - -require ( - github.com/google/go-cmp v0.5.5 - github.com/stretchr/testify v1.7.0 - go.opentelemetry.io/otel v0.20.0 - go.opentelemetry.io/otel/metric v0.20.0 - go.opentelemetry.io/otel/sdk v0.20.0 - go.opentelemetry.io/otel/sdk/export/metric v0.20.0 - go.opentelemetry.io/otel/sdk/metric v0.20.0 - go.opentelemetry.io/otel/trace v0.20.0 - go.opentelemetry.io/proto/otlp v0.7.0 - google.golang.org/grpc v1.37.0 - google.golang.org/protobuf v1.26.0 -) - -replace go.opentelemetry.io/otel/bridge/opencensus => ../../bridge/opencensus - -replace go.opentelemetry.io/otel/bridge/opentracing => ../../bridge/opentracing - -replace go.opentelemetry.io/otel/example/jaeger => ../../example/jaeger - -replace go.opentelemetry.io/otel/example/namedtracer => ../../example/namedtracer - -replace go.opentelemetry.io/otel/example/opencensus => ../../example/opencensus - -replace go.opentelemetry.io/otel/example/otel-collector => ../../example/otel-collector - -replace go.opentelemetry.io/otel/example/prom-collector => ../../example/prom-collector - -replace go.opentelemetry.io/otel/example/prometheus => ../../example/prometheus - -replace go.opentelemetry.io/otel/example/zipkin => ../../example/zipkin - -replace go.opentelemetry.io/otel/exporters/metric/prometheus => ../metric/prometheus - -replace go.opentelemetry.io/otel/exporters/otlp => ./ - -replace go.opentelemetry.io/otel/exporters/stdout => ../stdout - -replace go.opentelemetry.io/otel/exporters/trace/jaeger => ../trace/jaeger - -replace go.opentelemetry.io/otel/exporters/trace/zipkin => ../trace/zipkin - -replace go.opentelemetry.io/otel/internal/tools => ../../internal/tools - -replace go.opentelemetry.io/otel/metric => ../../metric - -replace go.opentelemetry.io/otel/oteltest => ../../oteltest - -replace go.opentelemetry.io/otel/sdk/export/metric => ../../sdk/export/metric - -replace go.opentelemetry.io/otel/sdk/metric => ../../sdk/metric - -replace go.opentelemetry.io/otel/trace => ../../trace diff --git a/vendor/go.opentelemetry.io/otel/exporters/otlp/go.sum b/vendor/go.opentelemetry.io/otel/exporters/otlp/go.sum deleted file mode 100644 index 65606007ac..0000000000 --- a/vendor/go.opentelemetry.io/otel/exporters/otlp/go.sum +++ /dev/null @@ -1,123 +0,0 @@ -cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= -github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= -github.com/benbjohnson/clock v1.0.3 h1:vkLuvpK4fmtSCuo60+yC63p7y0BmQ8gm5ZXGuBCJyXg= -github.com/benbjohnson/clock v1.0.3/go.mod h1:bGMdMPoPVvcYyt1gHDf4J2KE153Yf9BuiUKYMaxlTDM= -github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= -github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= -github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= -github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= -github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= -github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= -github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= -github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk= -github.com/envoyproxy/go-control-plane v0.9.9-0.20210217033140-668b12f5399d/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk= -github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= -github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= -github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= -github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= -github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= -github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= -github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= -github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= -github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= -github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= -github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= -github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= -github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= -github.com/golang/protobuf v1.5.0 h1:LUVKkCeviFUMKqHa4tXIIij/lbhnMbP7Fn5wKdKkRh4= -github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= -github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= -github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= -github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= -github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= -github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/grpc-ecosystem/grpc-gateway v1.16.0 h1:gmcG1KaJ57LophUzW0Hy8NmPhnMZb4M0+kPpLofRdBo= -github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= -github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= -github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= -github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -go.opentelemetry.io/proto/otlp v0.7.0 h1:rwOQPCuKAKmwGKq2aVNnYIibI6wnV7EvzgfTCzcdGg8= -go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= -golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= -golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= -golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= -golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20200822124328-c89045814202 h1:VvcQYSHwXgi7W+TpUR6A9g6Up98WAHf3f/ulnJ62IyA= -golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= -golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= -golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= -golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd h1:xhmwyvizuTgC2qz7ZlMluP20uW+C3Rm0FD/WLDX8884= -golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= -golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= -golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= -golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= -google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= -google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= -google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= -google.golang.org/genproto v0.0.0-20200513103714-09dca8ec2884/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= -google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 h1:+kGHl1aib/qcwaRi1CbqBZ1rk19r85MNUf8HaBghugY= -google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= -google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= -google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= -google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= -google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= -google.golang.org/grpc v1.33.1/go.mod h1:fr5YgcSWrqhRRxogOsw7RzIpsmvOZ6IcH4kBYTpR3n0= -google.golang.org/grpc v1.36.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU= -google.golang.org/grpc v1.37.0 h1:uSZWeQJX5j11bIQ4AJoj+McDBo29cY1MCoC1wO3ts+c= -google.golang.org/grpc v1.37.0/go.mod h1:NREThFqKR1f3iQ6oBuvc5LadQuXVGo9rkm5ZGrQdJfM= -google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= -google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= -google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= -google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= -google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= -google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= -google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= -google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= -google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= -google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= -google.golang.org/protobuf v1.26.0 h1:bxAC2xTBsZGibn2RTntX0oH50xLsqy1OxA9tTL3p/lk= -google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= -honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/vendor/go.opentelemetry.io/otel/exporters/otlp/internal/otlpconfig/envconfig.go b/vendor/go.opentelemetry.io/otel/exporters/otlp/internal/otlpconfig/envconfig.go deleted file mode 100644 index b52f3dc537..0000000000 --- a/vendor/go.opentelemetry.io/otel/exporters/otlp/internal/otlpconfig/envconfig.go +++ /dev/null @@ -1,196 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package otlpconfig - -import ( - "crypto/tls" - "fmt" - "io/ioutil" - "net/url" - "os" - "strconv" - "strings" - "time" - - "go.opentelemetry.io/otel/exporters/otlp" - - "go.opentelemetry.io/otel" -) - -func ApplyGRPCEnvConfigs(cfg *Config) { - e := EnvOptionsReader{ - GetEnv: os.Getenv, - ReadFile: ioutil.ReadFile, - } - - e.ApplyGRPCEnvConfigs(cfg) -} - -func ApplyHTTPEnvConfigs(cfg *Config) { - e := EnvOptionsReader{ - GetEnv: os.Getenv, - ReadFile: ioutil.ReadFile, - } - - e.ApplyHTTPEnvConfigs(cfg) -} - -type EnvOptionsReader struct { - GetEnv func(string) string - ReadFile func(filename string) ([]byte, error) -} - -func (e *EnvOptionsReader) ApplyHTTPEnvConfigs(cfg *Config) { - opts := e.GetOptionsFromEnv() - for _, opt := range opts { - opt.ApplyHTTPOption(cfg) - } -} - -func (e *EnvOptionsReader) ApplyGRPCEnvConfigs(cfg *Config) { - opts := e.GetOptionsFromEnv() - for _, opt := range opts { - opt.ApplyGRPCOption(cfg) - } -} - -func (e *EnvOptionsReader) GetOptionsFromEnv() []GenericOption { - var opts []GenericOption - - // Endpoint - if v, ok := e.getEnvValue("ENDPOINT"); ok { - opts = append(opts, WithEndpoint(v)) - } - if v, ok := e.getEnvValue("TRACES_ENDPOINT"); ok { - opts = append(opts, WithTracesEndpoint(v)) - } - if v, ok := e.getEnvValue("METRICS_ENDPOINT"); ok { - opts = append(opts, WithMetricsEndpoint(v)) - } - - // Certificate File - if path, ok := e.getEnvValue("CERTIFICATE"); ok { - if tls, err := e.readTLSConfig(path); err == nil { - opts = append(opts, WithTLSClientConfig(tls)) - } else { - otel.Handle(fmt.Errorf("failed to configure otlp exporter certificate '%s': %w", path, err)) - } - } - if path, ok := e.getEnvValue("TRACES_CERTIFICATE"); ok { - if tls, err := e.readTLSConfig(path); err == nil { - opts = append(opts, WithTracesTLSClientConfig(tls)) - } else { - otel.Handle(fmt.Errorf("failed to configure otlp traces exporter certificate '%s': %w", path, err)) - } - } - if path, ok := e.getEnvValue("METRICS_CERTIFICATE"); ok { - if tls, err := e.readTLSConfig(path); err == nil { - opts = append(opts, WithMetricsTLSClientConfig(tls)) - } else { - otel.Handle(fmt.Errorf("failed to configure otlp metrics exporter certificate '%s': %w", path, err)) - } - } - - // Headers - if h, ok := e.getEnvValue("HEADERS"); ok { - opts = append(opts, WithHeaders(stringToHeader(h))) - } - if h, ok := e.getEnvValue("TRACES_HEADERS"); ok { - opts = append(opts, WithTracesHeaders(stringToHeader(h))) - } - if h, ok := e.getEnvValue("METRICS_HEADERS"); ok { - opts = append(opts, WithMetricsHeaders(stringToHeader(h))) - } - - // Compression - if c, ok := e.getEnvValue("COMPRESSION"); ok { - opts = append(opts, WithCompression(stringToCompression(c))) - } - if c, ok := e.getEnvValue("TRACES_COMPRESSION"); ok { - opts = append(opts, WithTracesCompression(stringToCompression(c))) - } - if c, ok := e.getEnvValue("METRICS_COMPRESSION"); ok { - opts = append(opts, WithMetricsCompression(stringToCompression(c))) - } - - // Timeout - if t, ok := e.getEnvValue("TIMEOUT"); ok { - if d, err := strconv.Atoi(t); err == nil { - opts = append(opts, WithTimeout(time.Duration(d)*time.Millisecond)) - } - } - if t, ok := e.getEnvValue("TRACES_TIMEOUT"); ok { - if d, err := strconv.Atoi(t); err == nil { - opts = append(opts, WithTracesTimeout(time.Duration(d)*time.Millisecond)) - } - } - if t, ok := e.getEnvValue("METRICS_TIMEOUT"); ok { - if d, err := strconv.Atoi(t); err == nil { - opts = append(opts, WithMetricsTimeout(time.Duration(d)*time.Millisecond)) - } - } - - return opts -} - -// getEnvValue gets an OTLP environment variable value of the specified key using the GetEnv function. -// This function already prepends the OTLP prefix to all key lookup. -func (e *EnvOptionsReader) getEnvValue(key string) (string, bool) { - v := strings.TrimSpace(e.GetEnv(fmt.Sprintf("OTEL_EXPORTER_OTLP_%s", key))) - return v, v != "" -} - -func (e *EnvOptionsReader) readTLSConfig(path string) (*tls.Config, error) { - b, err := e.ReadFile(path) - if err != nil { - return nil, err - } - return CreateTLSConfig(b) -} - -func stringToCompression(value string) otlp.Compression { - switch value { - case "gzip": - return otlp.GzipCompression - } - - return otlp.NoCompression -} - -func stringToHeader(value string) map[string]string { - headersPairs := strings.Split(value, ",") - headers := make(map[string]string) - - for _, header := range headersPairs { - nameValue := strings.SplitN(header, "=", 2) - if len(nameValue) < 2 { - continue - } - name, err := url.QueryUnescape(nameValue[0]) - if err != nil { - continue - } - trimmedName := strings.TrimSpace(name) - value, err := url.QueryUnescape(nameValue[1]) - if err != nil { - continue - } - trimmedValue := strings.TrimSpace(value) - - headers[trimmedName] = trimmedValue - } - - return headers -} diff --git a/vendor/go.opentelemetry.io/otel/exporters/otlp/internal/otlpconfig/options.go b/vendor/go.opentelemetry.io/otel/exporters/otlp/internal/otlpconfig/options.go deleted file mode 100644 index 3fd4a30dd3..0000000000 --- a/vendor/go.opentelemetry.io/otel/exporters/otlp/internal/otlpconfig/options.go +++ /dev/null @@ -1,376 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package otlpconfig // import "go.opentelemetry.io/otel/exporters/otlp/internal/otlpconfig" - -import ( - "crypto/tls" - "fmt" - "time" - - "google.golang.org/grpc" - "google.golang.org/grpc/credentials" - - "go.opentelemetry.io/otel/exporters/otlp" -) - -const ( - // DefaultMaxAttempts describes how many times the driver - // should retry the sending of the payload in case of a - // retryable error. - DefaultMaxAttempts int = 5 - // DefaultTracesPath is a default URL path for endpoint that - // receives spans. - DefaultTracesPath string = "/v1/traces" - // DefaultMetricsPath is a default URL path for endpoint that - // receives metrics. - DefaultMetricsPath string = "/v1/metrics" - // DefaultBackoff is a default base backoff time used in the - // exponential backoff strategy. - DefaultBackoff time.Duration = 300 * time.Millisecond - // DefaultTimeout is a default max waiting time for the backend to process - // each span or metrics batch. - DefaultTimeout time.Duration = 10 * time.Second - // DefaultServiceConfig is the gRPC service config used if none is - // provided by the user. - DefaultServiceConfig = `{ - "methodConfig":[{ - "name":[ - { "service":"opentelemetry.proto.collector.metrics.v1.MetricsService" }, - { "service":"opentelemetry.proto.collector.trace.v1.TraceService" } - ], - "retryPolicy":{ - "MaxAttempts":5, - "InitialBackoff":"0.3s", - "MaxBackoff":"5s", - "BackoffMultiplier":2, - "RetryableStatusCodes":[ - "CANCELLED", - "DEADLINE_EXCEEDED", - "RESOURCE_EXHAUSTED", - "ABORTED", - "OUT_OF_RANGE", - "UNAVAILABLE", - "DATA_LOSS" - ] - } - }] -}` -) - -type ( - SignalConfig struct { - Endpoint string - Insecure bool - TLSCfg *tls.Config - Headers map[string]string - Compression otlp.Compression - Timeout time.Duration - URLPath string - - // gRPC configurations - GRPCCredentials credentials.TransportCredentials - } - - Config struct { - // Signal specific configurations - Metrics SignalConfig - Traces SignalConfig - - // General configurations - MaxAttempts int - Backoff time.Duration - - // HTTP configuration - Marshaler otlp.Marshaler - - // gRPC configurations - ReconnectionPeriod time.Duration - ServiceConfig string - DialOptions []grpc.DialOption - } -) - -func NewDefaultConfig() Config { - c := Config{ - Traces: SignalConfig{ - Endpoint: fmt.Sprintf("%s:%d", otlp.DefaultCollectorHost, otlp.DefaultCollectorPort), - URLPath: DefaultTracesPath, - Compression: otlp.NoCompression, - Timeout: DefaultTimeout, - }, - Metrics: SignalConfig{ - Endpoint: fmt.Sprintf("%s:%d", otlp.DefaultCollectorHost, otlp.DefaultCollectorPort), - URLPath: DefaultMetricsPath, - Compression: otlp.NoCompression, - Timeout: DefaultTimeout, - }, - MaxAttempts: DefaultMaxAttempts, - Backoff: DefaultBackoff, - ServiceConfig: DefaultServiceConfig, - } - - return c -} - -type ( - // GenericOption applies an option to the HTTP or gRPC driver. - GenericOption interface { - ApplyHTTPOption(*Config) - ApplyGRPCOption(*Config) - - // A private method to prevent users implementing the - // interface and so future additions to it will not - // violate compatibility. - private() - } - - // HTTPOption applies an option to the HTTP driver. - HTTPOption interface { - ApplyHTTPOption(*Config) - - // A private method to prevent users implementing the - // interface and so future additions to it will not - // violate compatibility. - private() - } - - // GRPCOption applies an option to the gRPC driver. - GRPCOption interface { - ApplyGRPCOption(*Config) - - // A private method to prevent users implementing the - // interface and so future additions to it will not - // violate compatibility. - private() - } -) - -// genericOption is an option that applies the same logic -// for both gRPC and HTTP. -type genericOption struct { - fn func(*Config) -} - -func (g *genericOption) ApplyGRPCOption(cfg *Config) { - g.fn(cfg) -} - -func (g *genericOption) ApplyHTTPOption(cfg *Config) { - g.fn(cfg) -} - -func (genericOption) private() {} - -func newGenericOption(fn func(cfg *Config)) GenericOption { - return &genericOption{fn: fn} -} - -// splitOption is an option that applies different logics -// for gRPC and HTTP. -type splitOption struct { - httpFn func(*Config) - grpcFn func(*Config) -} - -func (g *splitOption) ApplyGRPCOption(cfg *Config) { - g.grpcFn(cfg) -} - -func (g *splitOption) ApplyHTTPOption(cfg *Config) { - g.httpFn(cfg) -} - -func (splitOption) private() {} - -func newSplitOption(httpFn func(cfg *Config), grpcFn func(cfg *Config)) GenericOption { - return &splitOption{httpFn: httpFn, grpcFn: grpcFn} -} - -// httpOption is an option that is only applied to the HTTP driver. -type httpOption struct { - fn func(*Config) -} - -func (h *httpOption) ApplyHTTPOption(cfg *Config) { - h.fn(cfg) -} - -func (httpOption) private() {} - -func NewHTTPOption(fn func(cfg *Config)) HTTPOption { - return &httpOption{fn: fn} -} - -// grpcOption is an option that is only applied to the gRPC driver. -type grpcOption struct { - fn func(*Config) -} - -func (h *grpcOption) ApplyGRPCOption(cfg *Config) { - h.fn(cfg) -} - -func (grpcOption) private() {} - -func NewGRPCOption(fn func(cfg *Config)) GRPCOption { - return &grpcOption{fn: fn} -} - -// Generic Options - -func WithEndpoint(endpoint string) GenericOption { - return newGenericOption(func(cfg *Config) { - cfg.Traces.Endpoint = endpoint - cfg.Metrics.Endpoint = endpoint - }) -} - -func WithTracesEndpoint(endpoint string) GenericOption { - return newGenericOption(func(cfg *Config) { - cfg.Traces.Endpoint = endpoint - }) -} - -func WithMetricsEndpoint(endpoint string) GenericOption { - return newGenericOption(func(cfg *Config) { - cfg.Metrics.Endpoint = endpoint - }) -} - -func WithCompression(compression otlp.Compression) GenericOption { - return newGenericOption(func(cfg *Config) { - cfg.Traces.Compression = compression - cfg.Metrics.Compression = compression - }) -} - -func WithTracesCompression(compression otlp.Compression) GenericOption { - return newGenericOption(func(cfg *Config) { - cfg.Traces.Compression = compression - }) -} - -func WithMetricsCompression(compression otlp.Compression) GenericOption { - return newGenericOption(func(cfg *Config) { - cfg.Metrics.Compression = compression - }) -} - -func WithTracesURLPath(urlPath string) GenericOption { - return newGenericOption(func(cfg *Config) { - cfg.Traces.URLPath = urlPath - }) -} - -func WithMetricsURLPath(urlPath string) GenericOption { - return newGenericOption(func(cfg *Config) { - cfg.Metrics.URLPath = urlPath - }) -} - -func WithMaxAttempts(maxAttempts int) GenericOption { - return newGenericOption(func(cfg *Config) { - cfg.MaxAttempts = maxAttempts - }) -} - -func WithBackoff(duration time.Duration) GenericOption { - return newGenericOption(func(cfg *Config) { - cfg.Backoff = duration - }) -} - -func WithTLSClientConfig(tlsCfg *tls.Config) GenericOption { - return newSplitOption(func(cfg *Config) { - cfg.Traces.TLSCfg = tlsCfg.Clone() - cfg.Metrics.TLSCfg = tlsCfg.Clone() - }, func(cfg *Config) { - cfg.Traces.GRPCCredentials = credentials.NewTLS(tlsCfg) - cfg.Metrics.GRPCCredentials = credentials.NewTLS(tlsCfg) - }) -} - -func WithTracesTLSClientConfig(tlsCfg *tls.Config) GenericOption { - return newSplitOption(func(cfg *Config) { - cfg.Traces.TLSCfg = tlsCfg.Clone() - }, func(cfg *Config) { - cfg.Traces.GRPCCredentials = credentials.NewTLS(tlsCfg) - }) -} - -func WithMetricsTLSClientConfig(tlsCfg *tls.Config) GenericOption { - return newSplitOption(func(cfg *Config) { - cfg.Metrics.TLSCfg = tlsCfg.Clone() - }, func(cfg *Config) { - cfg.Metrics.GRPCCredentials = credentials.NewTLS(tlsCfg) - }) -} - -func WithInsecure() GenericOption { - return newGenericOption(func(cfg *Config) { - cfg.Traces.Insecure = true - cfg.Metrics.Insecure = true - }) -} - -func WithInsecureTraces() GenericOption { - return newGenericOption(func(cfg *Config) { - cfg.Traces.Insecure = true - }) -} - -func WithInsecureMetrics() GenericOption { - return newGenericOption(func(cfg *Config) { - cfg.Metrics.Insecure = true - }) -} - -func WithHeaders(headers map[string]string) GenericOption { - return newGenericOption(func(cfg *Config) { - cfg.Traces.Headers = headers - cfg.Metrics.Headers = headers - }) -} - -func WithTracesHeaders(headers map[string]string) GenericOption { - return newGenericOption(func(cfg *Config) { - cfg.Traces.Headers = headers - }) -} - -func WithMetricsHeaders(headers map[string]string) GenericOption { - return newGenericOption(func(cfg *Config) { - cfg.Metrics.Headers = headers - }) -} - -func WithTimeout(duration time.Duration) GenericOption { - return newGenericOption(func(cfg *Config) { - cfg.Traces.Timeout = duration - cfg.Metrics.Timeout = duration - }) -} - -func WithTracesTimeout(duration time.Duration) GenericOption { - return newGenericOption(func(cfg *Config) { - cfg.Traces.Timeout = duration - }) -} - -func WithMetricsTimeout(duration time.Duration) GenericOption { - return newGenericOption(func(cfg *Config) { - cfg.Metrics.Timeout = duration - }) -} diff --git a/vendor/go.opentelemetry.io/otel/exporters/otlp/internal/otlpconfig/tls.go b/vendor/go.opentelemetry.io/otel/exporters/otlp/internal/otlpconfig/tls.go deleted file mode 100644 index 0cbddb8653..0000000000 --- a/vendor/go.opentelemetry.io/otel/exporters/otlp/internal/otlpconfig/tls.go +++ /dev/null @@ -1,69 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package otlpconfig - -import ( - "crypto/tls" - "crypto/x509" - "errors" - "io/ioutil" -) - -const ( - WeakCertificate = ` ------BEGIN CERTIFICATE----- -MIIBhzCCASygAwIBAgIRANHpHgAWeTnLZpTSxCKs0ggwCgYIKoZIzj0EAwIwEjEQ -MA4GA1UEChMHb3RlbC1nbzAeFw0yMTA0MDExMzU5MDNaFw0yMTA0MDExNDU5MDNa -MBIxEDAOBgNVBAoTB290ZWwtZ28wWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAAS9 -nWSkmPCxShxnp43F+PrOtbGV7sNfkbQ/kxzi9Ego0ZJdiXxkmv/C05QFddCW7Y0Z -sJCLHGogQsYnWJBXUZOVo2MwYTAOBgNVHQ8BAf8EBAMCB4AwEwYDVR0lBAwwCgYI -KwYBBQUHAwEwDAYDVR0TAQH/BAIwADAsBgNVHREEJTAjgglsb2NhbGhvc3SHEAAA -AAAAAAAAAAAAAAAAAAGHBH8AAAEwCgYIKoZIzj0EAwIDSQAwRgIhANwZVVKvfvQ/ -1HXsTvgH+xTQswOwSSKYJ1cVHQhqK7ZbAiEAus8NxpTRnp5DiTMuyVmhVNPB+bVH -Lhnm4N/QDk5rek0= ------END CERTIFICATE----- -` - WeakPrivateKey = ` ------BEGIN PRIVATE KEY----- -MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgN8HEXiXhvByrJ1zK -SFT6Y2l2KqDWwWzKf+t4CyWrNKehRANCAAS9nWSkmPCxShxnp43F+PrOtbGV7sNf -kbQ/kxzi9Ego0ZJdiXxkmv/C05QFddCW7Y0ZsJCLHGogQsYnWJBXUZOV ------END PRIVATE KEY----- -` -) - -// ReadTLSConfigFromFile reads a PEM certificate file and creates -// a tls.Config that will use this certifate to verify a server certificate. -func ReadTLSConfigFromFile(path string) (*tls.Config, error) { - b, err := ioutil.ReadFile(path) - if err != nil { - return nil, err - } - - return CreateTLSConfig(b) -} - -// CreateTLSConfig creates a tls.Config from a raw certificate bytes -// to verify a server certificate. -func CreateTLSConfig(certBytes []byte) (*tls.Config, error) { - cp := x509.NewCertPool() - if ok := cp.AppendCertsFromPEM(certBytes); !ok { - return nil, errors.New("failed to append certificate to the cert pool") - } - - return &tls.Config{ - RootCAs: cp, - }, nil -} diff --git a/vendor/go.opentelemetry.io/otel/exporters/otlp/internal/transform/attribute.go b/vendor/go.opentelemetry.io/otel/exporters/otlp/internal/transform/attribute.go deleted file mode 100644 index 5902cad6ae..0000000000 --- a/vendor/go.opentelemetry.io/otel/exporters/otlp/internal/transform/attribute.go +++ /dev/null @@ -1,141 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package transform - -import ( - "reflect" - - "go.opentelemetry.io/otel/attribute" - commonpb "go.opentelemetry.io/proto/otlp/common/v1" - - "go.opentelemetry.io/otel/sdk/resource" -) - -// Attributes transforms a slice of KeyValues into a slice of OTLP attribute key-values. -func Attributes(attrs []attribute.KeyValue) []*commonpb.KeyValue { - if len(attrs) == 0 { - return nil - } - - out := make([]*commonpb.KeyValue, 0, len(attrs)) - for _, kv := range attrs { - out = append(out, toAttribute(kv)) - } - return out -} - -// ResourceAttributes transforms a Resource into a slice of OTLP attribute key-values. -func ResourceAttributes(resource *resource.Resource) []*commonpb.KeyValue { - if resource.Len() == 0 { - return nil - } - - out := make([]*commonpb.KeyValue, 0, resource.Len()) - for iter := resource.Iter(); iter.Next(); { - out = append(out, toAttribute(iter.Attribute())) - } - - return out -} - -func toAttribute(v attribute.KeyValue) *commonpb.KeyValue { - result := &commonpb.KeyValue{ - Key: string(v.Key), - Value: new(commonpb.AnyValue), - } - switch v.Value.Type() { - case attribute.BOOL: - result.Value.Value = &commonpb.AnyValue_BoolValue{ - BoolValue: v.Value.AsBool(), - } - case attribute.INT64: - result.Value.Value = &commonpb.AnyValue_IntValue{ - IntValue: v.Value.AsInt64(), - } - case attribute.FLOAT64: - result.Value.Value = &commonpb.AnyValue_DoubleValue{ - DoubleValue: v.Value.AsFloat64(), - } - case attribute.STRING: - result.Value.Value = &commonpb.AnyValue_StringValue{ - StringValue: v.Value.AsString(), - } - case attribute.ARRAY: - result.Value.Value = &commonpb.AnyValue_ArrayValue{ - ArrayValue: &commonpb.ArrayValue{ - Values: arrayValues(v), - }, - } - default: - result.Value.Value = &commonpb.AnyValue_StringValue{ - StringValue: "INVALID", - } - } - return result -} - -func arrayValues(kv attribute.KeyValue) []*commonpb.AnyValue { - a := kv.Value.AsArray() - aType := reflect.TypeOf(a) - var valueFunc func(reflect.Value) *commonpb.AnyValue - switch aType.Elem().Kind() { - case reflect.Bool: - valueFunc = func(v reflect.Value) *commonpb.AnyValue { - return &commonpb.AnyValue{ - Value: &commonpb.AnyValue_BoolValue{ - BoolValue: v.Bool(), - }, - } - } - case reflect.Int, reflect.Int64: - valueFunc = func(v reflect.Value) *commonpb.AnyValue { - return &commonpb.AnyValue{ - Value: &commonpb.AnyValue_IntValue{ - IntValue: v.Int(), - }, - } - } - case reflect.Uintptr: - valueFunc = func(v reflect.Value) *commonpb.AnyValue { - return &commonpb.AnyValue{ - Value: &commonpb.AnyValue_IntValue{ - IntValue: int64(v.Uint()), - }, - } - } - case reflect.Float64: - valueFunc = func(v reflect.Value) *commonpb.AnyValue { - return &commonpb.AnyValue{ - Value: &commonpb.AnyValue_DoubleValue{ - DoubleValue: v.Float(), - }, - } - } - case reflect.String: - valueFunc = func(v reflect.Value) *commonpb.AnyValue { - return &commonpb.AnyValue{ - Value: &commonpb.AnyValue_StringValue{ - StringValue: v.String(), - }, - } - } - } - - results := make([]*commonpb.AnyValue, aType.Len()) - for i, aValue := 0, reflect.ValueOf(a); i < aValue.Len(); i++ { - results[i] = valueFunc(aValue.Index(i)) - } - return results -} diff --git a/vendor/go.opentelemetry.io/otel/exporters/otlp/internal/transform/instrumentation.go b/vendor/go.opentelemetry.io/otel/exporters/otlp/internal/transform/instrumentation.go deleted file mode 100644 index 4ed5f96646..0000000000 --- a/vendor/go.opentelemetry.io/otel/exporters/otlp/internal/transform/instrumentation.go +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package transform - -import ( - commonpb "go.opentelemetry.io/proto/otlp/common/v1" - - "go.opentelemetry.io/otel/sdk/instrumentation" -) - -func instrumentationLibrary(il instrumentation.Library) *commonpb.InstrumentationLibrary { - if il == (instrumentation.Library{}) { - return nil - } - return &commonpb.InstrumentationLibrary{ - Name: il.Name, - Version: il.Version, - } -} diff --git a/vendor/go.opentelemetry.io/otel/exporters/otlp/internal/transform/metric.go b/vendor/go.opentelemetry.io/otel/exporters/otlp/internal/transform/metric.go deleted file mode 100644 index 1922b9b9c6..0000000000 --- a/vendor/go.opentelemetry.io/otel/exporters/otlp/internal/transform/metric.go +++ /dev/null @@ -1,631 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package transform provides translations for opentelemetry-go concepts and -// structures to otlp structures. -package transform - -import ( - "context" - "errors" - "fmt" - "strings" - "sync" - "time" - - "go.opentelemetry.io/otel/attribute" - commonpb "go.opentelemetry.io/proto/otlp/common/v1" - metricpb "go.opentelemetry.io/proto/otlp/metrics/v1" - resourcepb "go.opentelemetry.io/proto/otlp/resource/v1" - - "go.opentelemetry.io/otel/metric/number" - export "go.opentelemetry.io/otel/sdk/export/metric" - "go.opentelemetry.io/otel/sdk/export/metric/aggregation" - "go.opentelemetry.io/otel/sdk/instrumentation" - "go.opentelemetry.io/otel/sdk/resource" -) - -var ( - // ErrUnimplementedAgg is returned when a transformation of an unimplemented - // aggregator is attempted. - ErrUnimplementedAgg = errors.New("unimplemented aggregator") - - // ErrIncompatibleAgg is returned when - // aggregation.Kind implies an interface conversion that has - // failed - ErrIncompatibleAgg = errors.New("incompatible aggregation type") - - // ErrUnknownValueType is returned when a transformation of an unknown value - // is attempted. - ErrUnknownValueType = errors.New("invalid value type") - - // ErrContextCanceled is returned when a context cancellation halts a - // transformation. - ErrContextCanceled = errors.New("context canceled") - - // ErrTransforming is returned when an unexected error is encoutered transforming. - ErrTransforming = errors.New("transforming failed") -) - -// result is the product of transforming Records into OTLP Metrics. -type result struct { - Resource *resource.Resource - InstrumentationLibrary instrumentation.Library - Metric *metricpb.Metric - Err error -} - -// toNanos returns the number of nanoseconds since the UNIX epoch. -func toNanos(t time.Time) uint64 { - if t.IsZero() { - return 0 - } - return uint64(t.UnixNano()) -} - -// CheckpointSet transforms all records contained in a checkpoint into -// batched OTLP ResourceMetrics. -func CheckpointSet(ctx context.Context, exportSelector export.ExportKindSelector, cps export.CheckpointSet, numWorkers uint) ([]*metricpb.ResourceMetrics, error) { - records, errc := source(ctx, exportSelector, cps) - - // Start a fixed number of goroutines to transform records. - transformed := make(chan result) - var wg sync.WaitGroup - wg.Add(int(numWorkers)) - for i := uint(0); i < numWorkers; i++ { - go func() { - defer wg.Done() - transformer(ctx, exportSelector, records, transformed) - }() - } - go func() { - wg.Wait() - close(transformed) - }() - - // Synchronously collect the transformed records and transmit. - rms, err := sink(ctx, transformed) - if err != nil { - return nil, err - } - - // source is complete, check for any errors. - if err := <-errc; err != nil { - return nil, err - } - return rms, nil -} - -// source starts a goroutine that sends each one of the Records yielded by -// the CheckpointSet on the returned chan. Any error encoutered will be sent -// on the returned error chan after seeding is complete. -func source(ctx context.Context, exportSelector export.ExportKindSelector, cps export.CheckpointSet) (<-chan export.Record, <-chan error) { - errc := make(chan error, 1) - out := make(chan export.Record) - // Seed records into process. - go func() { - defer close(out) - // No select is needed since errc is buffered. - errc <- cps.ForEach(exportSelector, func(r export.Record) error { - select { - case <-ctx.Done(): - return ErrContextCanceled - case out <- r: - } - return nil - }) - }() - return out, errc -} - -// transformer transforms records read from the passed in chan into -// OTLP Metrics which are sent on the out chan. -func transformer(ctx context.Context, exportSelector export.ExportKindSelector, in <-chan export.Record, out chan<- result) { - for r := range in { - m, err := Record(exportSelector, r) - // Propagate errors, but do not send empty results. - if err == nil && m == nil { - continue - } - res := result{ - Resource: r.Resource(), - InstrumentationLibrary: instrumentation.Library{ - Name: r.Descriptor().InstrumentationName(), - Version: r.Descriptor().InstrumentationVersion(), - }, - Metric: m, - Err: err, - } - select { - case <-ctx.Done(): - return - case out <- res: - } - } -} - -// sink collects transformed Records and batches them. -// -// Any errors encoutered transforming input will be reported with an -// ErrTransforming as well as the completed ResourceMetrics. It is up to the -// caller to handle any incorrect data in these ResourceMetrics. -func sink(ctx context.Context, in <-chan result) ([]*metricpb.ResourceMetrics, error) { - var errStrings []string - - type resourceBatch struct { - Resource *resourcepb.Resource - // Group by instrumentation library name and then the MetricDescriptor. - InstrumentationLibraryBatches map[instrumentation.Library]map[string]*metricpb.Metric - } - - // group by unique Resource string. - grouped := make(map[attribute.Distinct]resourceBatch) - for res := range in { - if res.Err != nil { - errStrings = append(errStrings, res.Err.Error()) - continue - } - - rID := res.Resource.Equivalent() - rb, ok := grouped[rID] - if !ok { - rb = resourceBatch{ - Resource: Resource(res.Resource), - InstrumentationLibraryBatches: make(map[instrumentation.Library]map[string]*metricpb.Metric), - } - grouped[rID] = rb - } - - mb, ok := rb.InstrumentationLibraryBatches[res.InstrumentationLibrary] - if !ok { - mb = make(map[string]*metricpb.Metric) - rb.InstrumentationLibraryBatches[res.InstrumentationLibrary] = mb - } - - mID := res.Metric.GetName() - m, ok := mb[mID] - if !ok { - mb[mID] = res.Metric - continue - } - switch res.Metric.Data.(type) { - case *metricpb.Metric_IntGauge: - m.GetIntGauge().DataPoints = append(m.GetIntGauge().DataPoints, res.Metric.GetIntGauge().DataPoints...) - case *metricpb.Metric_IntHistogram: - m.GetIntHistogram().DataPoints = append(m.GetIntHistogram().DataPoints, res.Metric.GetIntHistogram().DataPoints...) - case *metricpb.Metric_IntSum: - m.GetIntSum().DataPoints = append(m.GetIntSum().DataPoints, res.Metric.GetIntSum().DataPoints...) - case *metricpb.Metric_DoubleGauge: - m.GetDoubleGauge().DataPoints = append(m.GetDoubleGauge().DataPoints, res.Metric.GetDoubleGauge().DataPoints...) - case *metricpb.Metric_DoubleHistogram: - m.GetDoubleHistogram().DataPoints = append(m.GetDoubleHistogram().DataPoints, res.Metric.GetDoubleHistogram().DataPoints...) - case *metricpb.Metric_DoubleSum: - m.GetDoubleSum().DataPoints = append(m.GetDoubleSum().DataPoints, res.Metric.GetDoubleSum().DataPoints...) - default: - } - } - - if len(grouped) == 0 { - return nil, nil - } - - var rms []*metricpb.ResourceMetrics - for _, rb := range grouped { - rm := &metricpb.ResourceMetrics{Resource: rb.Resource} - for il, mb := range rb.InstrumentationLibraryBatches { - ilm := &metricpb.InstrumentationLibraryMetrics{ - Metrics: make([]*metricpb.Metric, 0, len(mb)), - } - if il != (instrumentation.Library{}) { - ilm.InstrumentationLibrary = &commonpb.InstrumentationLibrary{ - Name: il.Name, - Version: il.Version, - } - } - for _, m := range mb { - ilm.Metrics = append(ilm.Metrics, m) - } - rm.InstrumentationLibraryMetrics = append(rm.InstrumentationLibraryMetrics, ilm) - } - rms = append(rms, rm) - } - - // Report any transform errors. - if len(errStrings) > 0 { - return rms, fmt.Errorf("%w:\n -%s", ErrTransforming, strings.Join(errStrings, "\n -")) - } - return rms, nil -} - -// Record transforms a Record into an OTLP Metric. An ErrIncompatibleAgg -// error is returned if the Record Aggregator is not supported. -func Record(exportSelector export.ExportKindSelector, r export.Record) (*metricpb.Metric, error) { - agg := r.Aggregation() - switch agg.Kind() { - case aggregation.MinMaxSumCountKind: - mmsc, ok := agg.(aggregation.MinMaxSumCount) - if !ok { - return nil, fmt.Errorf("%w: %T", ErrIncompatibleAgg, agg) - } - return minMaxSumCount(r, mmsc) - - case aggregation.HistogramKind: - h, ok := agg.(aggregation.Histogram) - if !ok { - return nil, fmt.Errorf("%w: %T", ErrIncompatibleAgg, agg) - } - return histogramPoint(r, exportSelector.ExportKindFor(r.Descriptor(), aggregation.HistogramKind), h) - - case aggregation.SumKind: - s, ok := agg.(aggregation.Sum) - if !ok { - return nil, fmt.Errorf("%w: %T", ErrIncompatibleAgg, agg) - } - sum, err := s.Sum() - if err != nil { - return nil, err - } - return sumPoint(r, sum, r.StartTime(), r.EndTime(), exportSelector.ExportKindFor(r.Descriptor(), aggregation.SumKind), r.Descriptor().InstrumentKind().Monotonic()) - - case aggregation.LastValueKind: - lv, ok := agg.(aggregation.LastValue) - if !ok { - return nil, fmt.Errorf("%w: %T", ErrIncompatibleAgg, agg) - } - value, tm, err := lv.LastValue() - if err != nil { - return nil, err - } - return gaugePoint(r, value, time.Time{}, tm) - - case aggregation.ExactKind: - e, ok := agg.(aggregation.Points) - if !ok { - return nil, fmt.Errorf("%w: %T", ErrIncompatibleAgg, agg) - } - pts, err := e.Points() - if err != nil { - return nil, err - } - - return gaugeArray(r, pts) - - default: - return nil, fmt.Errorf("%w: %T", ErrUnimplementedAgg, agg) - } -} - -func gaugeArray(record export.Record, points []aggregation.Point) (*metricpb.Metric, error) { - desc := record.Descriptor() - labels := record.Labels() - m := &metricpb.Metric{ - Name: desc.Name(), - Description: desc.Description(), - Unit: string(desc.Unit()), - } - - pbLabels := stringKeyValues(labels.Iter()) - - switch nk := desc.NumberKind(); nk { - case number.Int64Kind: - var pts []*metricpb.IntDataPoint - for _, s := range points { - pts = append(pts, &metricpb.IntDataPoint{ - Labels: pbLabels, - StartTimeUnixNano: toNanos(record.StartTime()), - TimeUnixNano: toNanos(record.EndTime()), - Value: s.Number.CoerceToInt64(nk), - }) - } - m.Data = &metricpb.Metric_IntGauge{ - IntGauge: &metricpb.IntGauge{ - DataPoints: pts, - }, - } - - case number.Float64Kind: - var pts []*metricpb.DoubleDataPoint - for _, s := range points { - pts = append(pts, &metricpb.DoubleDataPoint{ - Labels: pbLabels, - StartTimeUnixNano: toNanos(record.StartTime()), - TimeUnixNano: toNanos(record.EndTime()), - Value: s.Number.CoerceToFloat64(nk), - }) - } - m.Data = &metricpb.Metric_DoubleGauge{ - DoubleGauge: &metricpb.DoubleGauge{ - DataPoints: pts, - }, - } - - default: - return nil, fmt.Errorf("%w: %v", ErrUnknownValueType, nk) - } - - return m, nil -} - -func gaugePoint(record export.Record, num number.Number, start, end time.Time) (*metricpb.Metric, error) { - desc := record.Descriptor() - labels := record.Labels() - - m := &metricpb.Metric{ - Name: desc.Name(), - Description: desc.Description(), - Unit: string(desc.Unit()), - } - - switch n := desc.NumberKind(); n { - case number.Int64Kind: - m.Data = &metricpb.Metric_IntGauge{ - IntGauge: &metricpb.IntGauge{ - DataPoints: []*metricpb.IntDataPoint{ - { - Value: num.CoerceToInt64(n), - Labels: stringKeyValues(labels.Iter()), - StartTimeUnixNano: toNanos(start), - TimeUnixNano: toNanos(end), - }, - }, - }, - } - case number.Float64Kind: - m.Data = &metricpb.Metric_DoubleGauge{ - DoubleGauge: &metricpb.DoubleGauge{ - DataPoints: []*metricpb.DoubleDataPoint{ - { - Value: num.CoerceToFloat64(n), - Labels: stringKeyValues(labels.Iter()), - StartTimeUnixNano: toNanos(start), - TimeUnixNano: toNanos(end), - }, - }, - }, - } - default: - return nil, fmt.Errorf("%w: %v", ErrUnknownValueType, n) - } - - return m, nil -} - -func exportKindToTemporality(ek export.ExportKind) metricpb.AggregationTemporality { - switch ek { - case export.DeltaExportKind: - return metricpb.AggregationTemporality_AGGREGATION_TEMPORALITY_DELTA - case export.CumulativeExportKind: - return metricpb.AggregationTemporality_AGGREGATION_TEMPORALITY_CUMULATIVE - } - return metricpb.AggregationTemporality_AGGREGATION_TEMPORALITY_UNSPECIFIED -} - -func sumPoint(record export.Record, num number.Number, start, end time.Time, ek export.ExportKind, monotonic bool) (*metricpb.Metric, error) { - desc := record.Descriptor() - labels := record.Labels() - - m := &metricpb.Metric{ - Name: desc.Name(), - Description: desc.Description(), - Unit: string(desc.Unit()), - } - - switch n := desc.NumberKind(); n { - case number.Int64Kind: - m.Data = &metricpb.Metric_IntSum{ - IntSum: &metricpb.IntSum{ - IsMonotonic: monotonic, - AggregationTemporality: exportKindToTemporality(ek), - DataPoints: []*metricpb.IntDataPoint{ - { - Value: num.CoerceToInt64(n), - Labels: stringKeyValues(labels.Iter()), - StartTimeUnixNano: toNanos(start), - TimeUnixNano: toNanos(end), - }, - }, - }, - } - case number.Float64Kind: - m.Data = &metricpb.Metric_DoubleSum{ - DoubleSum: &metricpb.DoubleSum{ - IsMonotonic: monotonic, - AggregationTemporality: exportKindToTemporality(ek), - DataPoints: []*metricpb.DoubleDataPoint{ - { - Value: num.CoerceToFloat64(n), - Labels: stringKeyValues(labels.Iter()), - StartTimeUnixNano: toNanos(start), - TimeUnixNano: toNanos(end), - }, - }, - }, - } - default: - return nil, fmt.Errorf("%w: %v", ErrUnknownValueType, n) - } - - return m, nil -} - -// minMaxSumCountValue returns the values of the MinMaxSumCount Aggregator -// as discrete values. -func minMaxSumCountValues(a aggregation.MinMaxSumCount) (min, max, sum number.Number, count uint64, err error) { - if min, err = a.Min(); err != nil { - return - } - if max, err = a.Max(); err != nil { - return - } - if sum, err = a.Sum(); err != nil { - return - } - if count, err = a.Count(); err != nil { - return - } - return -} - -// minMaxSumCount transforms a MinMaxSumCount Aggregator into an OTLP Metric. -func minMaxSumCount(record export.Record, a aggregation.MinMaxSumCount) (*metricpb.Metric, error) { - desc := record.Descriptor() - labels := record.Labels() - min, max, sum, count, err := minMaxSumCountValues(a) - if err != nil { - return nil, err - } - - m := &metricpb.Metric{ - Name: desc.Name(), - Description: desc.Description(), - Unit: string(desc.Unit()), - } - - buckets := []uint64{min.AsRaw(), max.AsRaw()} - bounds := []float64{0.0, 100.0} - - switch n := desc.NumberKind(); n { - case number.Int64Kind: - m.Data = &metricpb.Metric_IntHistogram{ - IntHistogram: &metricpb.IntHistogram{ - DataPoints: []*metricpb.IntHistogramDataPoint{ - { - Sum: sum.CoerceToInt64(n), - Labels: stringKeyValues(labels.Iter()), - StartTimeUnixNano: toNanos(record.StartTime()), - TimeUnixNano: toNanos(record.EndTime()), - Count: uint64(count), - BucketCounts: buckets, - ExplicitBounds: bounds, - }, - }, - }, - } - case number.Float64Kind: - m.Data = &metricpb.Metric_DoubleHistogram{ - DoubleHistogram: &metricpb.DoubleHistogram{ - DataPoints: []*metricpb.DoubleHistogramDataPoint{ - { - Sum: sum.CoerceToFloat64(n), - Labels: stringKeyValues(labels.Iter()), - StartTimeUnixNano: toNanos(record.StartTime()), - TimeUnixNano: toNanos(record.EndTime()), - Count: uint64(count), - BucketCounts: buckets, - ExplicitBounds: bounds, - }, - }, - }, - } - default: - return nil, fmt.Errorf("%w: %v", ErrUnknownValueType, n) - } - return m, nil -} - -func histogramValues(a aggregation.Histogram) (boundaries []float64, counts []uint64, err error) { - var buckets aggregation.Buckets - if buckets, err = a.Histogram(); err != nil { - return - } - boundaries, counts = buckets.Boundaries, buckets.Counts - if len(counts) != len(boundaries)+1 { - err = ErrTransforming - return - } - return -} - -// histogram transforms a Histogram Aggregator into an OTLP Metric. -func histogramPoint(record export.Record, ek export.ExportKind, a aggregation.Histogram) (*metricpb.Metric, error) { - desc := record.Descriptor() - labels := record.Labels() - boundaries, counts, err := histogramValues(a) - if err != nil { - return nil, err - } - - count, err := a.Count() - if err != nil { - return nil, err - } - - sum, err := a.Sum() - if err != nil { - return nil, err - } - - m := &metricpb.Metric{ - Name: desc.Name(), - Description: desc.Description(), - Unit: string(desc.Unit()), - } - switch n := desc.NumberKind(); n { - case number.Int64Kind: - m.Data = &metricpb.Metric_IntHistogram{ - IntHistogram: &metricpb.IntHistogram{ - AggregationTemporality: exportKindToTemporality(ek), - DataPoints: []*metricpb.IntHistogramDataPoint{ - { - Sum: sum.CoerceToInt64(n), - Labels: stringKeyValues(labels.Iter()), - StartTimeUnixNano: toNanos(record.StartTime()), - TimeUnixNano: toNanos(record.EndTime()), - Count: uint64(count), - BucketCounts: counts, - ExplicitBounds: boundaries, - }, - }, - }, - } - case number.Float64Kind: - m.Data = &metricpb.Metric_DoubleHistogram{ - DoubleHistogram: &metricpb.DoubleHistogram{ - AggregationTemporality: exportKindToTemporality(ek), - DataPoints: []*metricpb.DoubleHistogramDataPoint{ - { - Sum: sum.CoerceToFloat64(n), - Labels: stringKeyValues(labels.Iter()), - StartTimeUnixNano: toNanos(record.StartTime()), - TimeUnixNano: toNanos(record.EndTime()), - Count: uint64(count), - BucketCounts: counts, - ExplicitBounds: boundaries, - }, - }, - }, - } - default: - return nil, fmt.Errorf("%w: %v", ErrUnknownValueType, n) - } - - return m, nil -} - -// stringKeyValues transforms a label iterator into an OTLP StringKeyValues. -func stringKeyValues(iter attribute.Iterator) []*commonpb.StringKeyValue { - l := iter.Len() - if l == 0 { - return nil - } - result := make([]*commonpb.StringKeyValue, 0, l) - for iter.Next() { - kv := iter.Label() - result = append(result, &commonpb.StringKeyValue{ - Key: string(kv.Key), - Value: kv.Value.Emit(), - }) - } - return result -} diff --git a/vendor/go.opentelemetry.io/otel/exporters/otlp/internal/transform/resource.go b/vendor/go.opentelemetry.io/otel/exporters/otlp/internal/transform/resource.go deleted file mode 100644 index 5be53566bf..0000000000 --- a/vendor/go.opentelemetry.io/otel/exporters/otlp/internal/transform/resource.go +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package transform - -import ( - resourcepb "go.opentelemetry.io/proto/otlp/resource/v1" - - "go.opentelemetry.io/otel/sdk/resource" -) - -// Resource transforms a Resource into an OTLP Resource. -func Resource(r *resource.Resource) *resourcepb.Resource { - if r == nil { - return nil - } - return &resourcepb.Resource{Attributes: ResourceAttributes(r)} -} diff --git a/vendor/go.opentelemetry.io/otel/exporters/otlp/internal/transform/span.go b/vendor/go.opentelemetry.io/otel/exporters/otlp/internal/transform/span.go deleted file mode 100644 index d24cb1e6e5..0000000000 --- a/vendor/go.opentelemetry.io/otel/exporters/otlp/internal/transform/span.go +++ /dev/null @@ -1,218 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package transform - -import ( - "go.opentelemetry.io/otel/attribute" - "go.opentelemetry.io/otel/codes" - tracepb "go.opentelemetry.io/proto/otlp/trace/v1" - - "go.opentelemetry.io/otel/sdk/instrumentation" - tracesdk "go.opentelemetry.io/otel/sdk/trace" - "go.opentelemetry.io/otel/trace" -) - -const ( - maxMessageEventsPerSpan = 128 -) - -// SpanData transforms a slice of SpanSnapshot into a slice of OTLP -// ResourceSpans. -func SpanData(sdl []*tracesdk.SpanSnapshot) []*tracepb.ResourceSpans { - if len(sdl) == 0 { - return nil - } - - rsm := make(map[attribute.Distinct]*tracepb.ResourceSpans) - - type ilsKey struct { - r attribute.Distinct - il instrumentation.Library - } - ilsm := make(map[ilsKey]*tracepb.InstrumentationLibrarySpans) - - var resources int - for _, sd := range sdl { - if sd == nil { - continue - } - - rKey := sd.Resource.Equivalent() - iKey := ilsKey{ - r: rKey, - il: sd.InstrumentationLibrary, - } - ils, iOk := ilsm[iKey] - if !iOk { - // Either the resource or instrumentation library were unknown. - ils = &tracepb.InstrumentationLibrarySpans{ - InstrumentationLibrary: instrumentationLibrary(sd.InstrumentationLibrary), - Spans: []*tracepb.Span{}, - } - } - ils.Spans = append(ils.Spans, span(sd)) - ilsm[iKey] = ils - - rs, rOk := rsm[rKey] - if !rOk { - resources++ - // The resource was unknown. - rs = &tracepb.ResourceSpans{ - Resource: Resource(sd.Resource), - InstrumentationLibrarySpans: []*tracepb.InstrumentationLibrarySpans{ils}, - } - rsm[rKey] = rs - continue - } - - // The resource has been seen before. Check if the instrumentation - // library lookup was unknown because if so we need to add it to the - // ResourceSpans. Otherwise, the instrumentation library has already - // been seen and the append we did above will be included it in the - // InstrumentationLibrarySpans reference. - if !iOk { - rs.InstrumentationLibrarySpans = append(rs.InstrumentationLibrarySpans, ils) - } - } - - // Transform the categorized map into a slice - rss := make([]*tracepb.ResourceSpans, 0, resources) - for _, rs := range rsm { - rss = append(rss, rs) - } - return rss -} - -// span transforms a Span into an OTLP span. -func span(sd *tracesdk.SpanSnapshot) *tracepb.Span { - if sd == nil { - return nil - } - - tid := sd.SpanContext.TraceID() - sid := sd.SpanContext.SpanID() - - s := &tracepb.Span{ - TraceId: tid[:], - SpanId: sid[:], - TraceState: sd.SpanContext.TraceState().String(), - Status: status(sd.StatusCode, sd.StatusMessage), - StartTimeUnixNano: uint64(sd.StartTime.UnixNano()), - EndTimeUnixNano: uint64(sd.EndTime.UnixNano()), - Links: links(sd.Links), - Kind: spanKind(sd.SpanKind), - Name: sd.Name, - Attributes: Attributes(sd.Attributes), - Events: spanEvents(sd.MessageEvents), - DroppedAttributesCount: uint32(sd.DroppedAttributeCount), - DroppedEventsCount: uint32(sd.DroppedMessageEventCount), - DroppedLinksCount: uint32(sd.DroppedLinkCount), - } - - if psid := sd.Parent.SpanID(); psid.IsValid() { - s.ParentSpanId = psid[:] - } - - return s -} - -// status transform a span code and message into an OTLP span status. -func status(status codes.Code, message string) *tracepb.Status { - var c tracepb.Status_StatusCode - switch status { - case codes.Error: - c = tracepb.Status_STATUS_CODE_ERROR - default: - c = tracepb.Status_STATUS_CODE_OK - } - return &tracepb.Status{ - Code: c, - Message: message, - } -} - -// links transforms span Links to OTLP span links. -func links(links []trace.Link) []*tracepb.Span_Link { - if len(links) == 0 { - return nil - } - - sl := make([]*tracepb.Span_Link, 0, len(links)) - for _, otLink := range links { - // This redefinition is necessary to prevent otLink.*ID[:] copies - // being reused -- in short we need a new otLink per iteration. - otLink := otLink - - tid := otLink.TraceID() - sid := otLink.SpanID() - - sl = append(sl, &tracepb.Span_Link{ - TraceId: tid[:], - SpanId: sid[:], - Attributes: Attributes(otLink.Attributes), - }) - } - return sl -} - -// spanEvents transforms span Events to an OTLP span events. -func spanEvents(es []trace.Event) []*tracepb.Span_Event { - if len(es) == 0 { - return nil - } - - evCount := len(es) - if evCount > maxMessageEventsPerSpan { - evCount = maxMessageEventsPerSpan - } - events := make([]*tracepb.Span_Event, 0, evCount) - messageEvents := 0 - - // Transform message events - for _, e := range es { - if messageEvents >= maxMessageEventsPerSpan { - break - } - messageEvents++ - events = append(events, - &tracepb.Span_Event{ - Name: e.Name, - TimeUnixNano: uint64(e.Time.UnixNano()), - Attributes: Attributes(e.Attributes), - // TODO (rghetia) : Add Drop Counts when supported. - }, - ) - } - - return events -} - -// spanKind transforms a SpanKind to an OTLP span kind. -func spanKind(kind trace.SpanKind) tracepb.Span_SpanKind { - switch kind { - case trace.SpanKindInternal: - return tracepb.Span_SPAN_KIND_INTERNAL - case trace.SpanKindClient: - return tracepb.Span_SPAN_KIND_CLIENT - case trace.SpanKindServer: - return tracepb.Span_SPAN_KIND_SERVER - case trace.SpanKindProducer: - return tracepb.Span_SPAN_KIND_PRODUCER - case trace.SpanKindConsumer: - return tracepb.Span_SPAN_KIND_CONSUMER - default: - return tracepb.Span_SPAN_KIND_UNSPECIFIED - } -} diff --git a/vendor/go.opentelemetry.io/otel/exporters/otlp/options.go b/vendor/go.opentelemetry.io/otel/exporters/otlp/options.go deleted file mode 100644 index 7cfaa35d3c..0000000000 --- a/vendor/go.opentelemetry.io/otel/exporters/otlp/options.go +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package otlp // import "go.opentelemetry.io/otel/exporters/otlp" - -import ( - metricsdk "go.opentelemetry.io/otel/sdk/export/metric" -) - -const ( - // DefaultCollectorPort is the port the Exporter will attempt connect to - // if no collector port is provided. - DefaultCollectorPort uint16 = 4317 - // DefaultCollectorHost is the host address the Exporter will attempt - // connect to if no collector address is provided. - DefaultCollectorHost string = "localhost" -) - -// ExporterOption are setting options passed to an Exporter on creation. -type ExporterOption func(*config) - -type config struct { - exportKindSelector metricsdk.ExportKindSelector -} - -// WithMetricExportKindSelector defines the ExportKindSelector used -// for selecting AggregationTemporality (i.e., Cumulative vs. Delta -// aggregation). If not specified otherwise, exporter will use a -// cumulative export kind selector. -func WithMetricExportKindSelector(selector metricsdk.ExportKindSelector) ExporterOption { - return func(cfg *config) { - cfg.exportKindSelector = selector - } -} diff --git a/vendor/go.opentelemetry.io/otel/exporters/otlp/optiontypes.go b/vendor/go.opentelemetry.io/otel/exporters/otlp/optiontypes.go deleted file mode 100644 index 682625f454..0000000000 --- a/vendor/go.opentelemetry.io/otel/exporters/otlp/optiontypes.go +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package otlp // import "go.opentelemetry.io/otel/exporters/otlp" - -// Compression describes the compression used for payloads sent to the -// collector. -type Compression int - -const ( - // NoCompression tells the driver to send payloads without - // compression. - NoCompression Compression = iota - // GzipCompression tells the driver to send payloads after - // compressing them with gzip. - GzipCompression -) - -// Marshaler describes the kind of message format sent to the collector -type Marshaler int - -const ( - // MarshalProto tells the driver to send using the protobuf binary format. - MarshalProto Marshaler = iota - // MarshalJSON tells the driver to send using json format. - MarshalJSON -) diff --git a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlp.go b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlp.go deleted file mode 100644 index 098d93b423..0000000000 --- a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlp.go +++ /dev/null @@ -1,179 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package otlp // import "go.opentelemetry.io/otel/exporters/otlp" - -import ( - "context" - "errors" - "sync" - - "go.opentelemetry.io/otel" - "go.opentelemetry.io/otel/metric" - metricsdk "go.opentelemetry.io/otel/sdk/export/metric" - "go.opentelemetry.io/otel/sdk/export/metric/aggregation" - "go.opentelemetry.io/otel/sdk/metric/selector/simple" - sdktrace "go.opentelemetry.io/otel/sdk/trace" - - "go.opentelemetry.io/otel/sdk/metric/controller/basic" - processor "go.opentelemetry.io/otel/sdk/metric/processor/basic" - tracesdk "go.opentelemetry.io/otel/sdk/trace" -) - -// Exporter is an OpenTelemetry exporter. It exports both traces and metrics -// from OpenTelemetry instrumented to code using OpenTelemetry protocol -// buffers to a configurable receiver. -type Exporter struct { - cfg config - driver ProtocolDriver - - mu sync.RWMutex - started bool - - startOnce sync.Once - stopOnce sync.Once -} - -var _ tracesdk.SpanExporter = (*Exporter)(nil) -var _ metricsdk.Exporter = (*Exporter)(nil) - -// NewExporter constructs a new Exporter and starts it. -func NewExporter(ctx context.Context, driver ProtocolDriver, opts ...ExporterOption) (*Exporter, error) { - exp := NewUnstartedExporter(driver, opts...) - if err := exp.Start(ctx); err != nil { - return nil, err - } - return exp, nil -} - -// NewUnstartedExporter constructs a new Exporter and does not start it. -func NewUnstartedExporter(driver ProtocolDriver, opts ...ExporterOption) *Exporter { - cfg := config{ - // Note: the default ExportKindSelector is specified - // as Cumulative: - // https://github.com/open-telemetry/opentelemetry-specification/issues/731 - exportKindSelector: metricsdk.CumulativeExportKindSelector(), - } - for _, opt := range opts { - opt(&cfg) - } - return &Exporter{ - cfg: cfg, - driver: driver, - } -} - -var ( - errAlreadyStarted = errors.New("already started") -) - -// Start establishes connections to the OpenTelemetry collector. Starting an -// already started exporter returns an error. -func (e *Exporter) Start(ctx context.Context) error { - var err = errAlreadyStarted - e.startOnce.Do(func() { - e.mu.Lock() - e.started = true - e.mu.Unlock() - err = e.driver.Start(ctx) - }) - - return err -} - -// Shutdown closes all connections and releases resources currently being used -// by the exporter. If the exporter is not started this does nothing. A shut -// down exporter can't be started again. Shutting down an already shut down -// exporter does nothing. -func (e *Exporter) Shutdown(ctx context.Context) error { - e.mu.RLock() - started := e.started - e.mu.RUnlock() - - if !started { - return nil - } - - var err error - - e.stopOnce.Do(func() { - err = e.driver.Stop(ctx) - e.mu.Lock() - e.started = false - e.mu.Unlock() - }) - - return err -} - -// Export transforms and batches metric Records into OTLP Metrics and -// transmits them to the configured collector. -func (e *Exporter) Export(parent context.Context, cps metricsdk.CheckpointSet) error { - return e.driver.ExportMetrics(parent, cps, e.cfg.exportKindSelector) -} - -// ExportKindFor reports back to the OpenTelemetry SDK sending this Exporter -// metric telemetry that it needs to be provided in a configured format. -func (e *Exporter) ExportKindFor(desc *metric.Descriptor, kind aggregation.Kind) metricsdk.ExportKind { - return e.cfg.exportKindSelector.ExportKindFor(desc, kind) -} - -// ExportSpans transforms and batches trace SpanSnapshots into OTLP Trace and -// transmits them to the configured collector. -func (e *Exporter) ExportSpans(ctx context.Context, ss []*tracesdk.SpanSnapshot) error { - return e.driver.ExportTraces(ctx, ss) -} - -// NewExportPipeline sets up a complete export pipeline -// with the recommended TracerProvider setup. -func NewExportPipeline(ctx context.Context, driver ProtocolDriver, exporterOpts ...ExporterOption) (*Exporter, - *sdktrace.TracerProvider, *basic.Controller, error) { - - exp, err := NewExporter(ctx, driver, exporterOpts...) - if err != nil { - return nil, nil, nil, err - } - - tracerProvider := sdktrace.NewTracerProvider( - sdktrace.WithBatcher(exp), - ) - - cntr := basic.New( - processor.New( - simple.NewWithInexpensiveDistribution(), - exp, - ), - ) - - return exp, tracerProvider, cntr, nil -} - -// InstallNewPipeline instantiates a NewExportPipeline with the -// recommended configuration and registers it globally. -func InstallNewPipeline(ctx context.Context, driver ProtocolDriver, exporterOpts ...ExporterOption) (*Exporter, - *sdktrace.TracerProvider, *basic.Controller, error) { - - exp, tp, cntr, err := NewExportPipeline(ctx, driver, exporterOpts...) - if err != nil { - return nil, nil, nil, err - } - - otel.SetTracerProvider(tp) - err = cntr.Start(ctx) - if err != nil { - return nil, nil, nil, err - } - - return exp, tp, cntr, err -} diff --git a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpgrpc/connection.go b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpgrpc/connection.go deleted file mode 100644 index d904b56e05..0000000000 --- a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpgrpc/connection.go +++ /dev/null @@ -1,278 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package otlpgrpc - -import ( - "context" - "math/rand" - "sync" - "sync/atomic" - "time" - "unsafe" - - "google.golang.org/grpc/encoding/gzip" - - "go.opentelemetry.io/otel/exporters/otlp" - "go.opentelemetry.io/otel/exporters/otlp/internal/otlpconfig" - - "google.golang.org/grpc" - "google.golang.org/grpc/metadata" -) - -type connection struct { - // Ensure pointer is 64-bit aligned for atomic operations on both 32 and 64 bit machines. - lastConnectErrPtr unsafe.Pointer - - // mu protects the connection as it is accessed by the - // exporter goroutines and background connection goroutine - mu sync.Mutex - cc *grpc.ClientConn - - // these fields are read-only after constructor is finished - cfg otlpconfig.Config - sCfg otlpconfig.SignalConfig - metadata metadata.MD - newConnectionHandler func(cc *grpc.ClientConn) - - // these channels are created once - disconnectedCh chan bool - backgroundConnectionDoneCh chan struct{} - stopCh chan struct{} - - // this is for tests, so they can replace the closing - // routine without a worry of modifying some global variable - // or changing it back to original after the test is done - closeBackgroundConnectionDoneCh func(ch chan struct{}) -} - -func newConnection(cfg otlpconfig.Config, sCfg otlpconfig.SignalConfig, handler func(cc *grpc.ClientConn)) *connection { - c := new(connection) - c.newConnectionHandler = handler - c.cfg = cfg - c.sCfg = sCfg - if len(c.sCfg.Headers) > 0 { - c.metadata = metadata.New(c.sCfg.Headers) - } - c.closeBackgroundConnectionDoneCh = func(ch chan struct{}) { - close(ch) - } - return c -} - -func (c *connection) startConnection(ctx context.Context) { - c.stopCh = make(chan struct{}) - c.disconnectedCh = make(chan bool, 1) - c.backgroundConnectionDoneCh = make(chan struct{}) - - if err := c.connect(ctx); err == nil { - c.setStateConnected() - } else { - c.setStateDisconnected(err) - } - go c.indefiniteBackgroundConnection() -} - -func (c *connection) lastConnectError() error { - errPtr := (*error)(atomic.LoadPointer(&c.lastConnectErrPtr)) - if errPtr == nil { - return nil - } - return *errPtr -} - -func (c *connection) saveLastConnectError(err error) { - var errPtr *error - if err != nil { - errPtr = &err - } - atomic.StorePointer(&c.lastConnectErrPtr, unsafe.Pointer(errPtr)) -} - -func (c *connection) setStateDisconnected(err error) { - c.saveLastConnectError(err) - select { - case c.disconnectedCh <- true: - default: - } - c.newConnectionHandler(nil) -} - -func (c *connection) setStateConnected() { - c.saveLastConnectError(nil) -} - -func (c *connection) connected() bool { - return c.lastConnectError() == nil -} - -const defaultConnReattemptPeriod = 10 * time.Second - -func (c *connection) indefiniteBackgroundConnection() { - defer func() { - c.closeBackgroundConnectionDoneCh(c.backgroundConnectionDoneCh) - }() - - connReattemptPeriod := c.cfg.ReconnectionPeriod - if connReattemptPeriod <= 0 { - connReattemptPeriod = defaultConnReattemptPeriod - } - - // No strong seeding required, nano time can - // already help with pseudo uniqueness. - rng := rand.New(rand.NewSource(time.Now().UnixNano() + rand.Int63n(1024))) - - // maxJitterNanos: 70% of the connectionReattemptPeriod - maxJitterNanos := int64(0.7 * float64(connReattemptPeriod)) - - for { - // Otherwise these will be the normal scenarios to enable - // reconnection if we trip out. - // 1. If we've stopped, return entirely - // 2. Otherwise block until we are disconnected, and - // then retry connecting - select { - case <-c.stopCh: - return - - case <-c.disconnectedCh: - // Quickly check if we haven't stopped at the - // same time. - select { - case <-c.stopCh: - return - - default: - } - - // Normal scenario that we'll wait for - } - - if err := c.connect(context.Background()); err == nil { - c.setStateConnected() - } else { - // this code is unreachable in most cases - // c.connect does not establish connection - c.setStateDisconnected(err) - } - - // Apply some jitter to avoid lockstep retrials of other - // collector-exporters. Lockstep retrials could result in an - // innocent DDOS, by clogging the machine's resources and network. - jitter := time.Duration(rng.Int63n(maxJitterNanos)) - select { - case <-c.stopCh: - return - case <-time.After(connReattemptPeriod + jitter): - } - } -} - -func (c *connection) connect(ctx context.Context) error { - cc, err := c.dialToCollector(ctx) - if err != nil { - return err - } - c.setConnection(cc) - c.newConnectionHandler(cc) - return nil -} - -// setConnection sets cc as the client connection and returns true if -// the connection state changed. -func (c *connection) setConnection(cc *grpc.ClientConn) bool { - c.mu.Lock() - defer c.mu.Unlock() - - // If previous clientConn is same as the current then just return. - // This doesn't happen right now as this func is only called with new ClientConn. - // It is more about future-proofing. - if c.cc == cc { - return false - } - - // If the previous clientConn was non-nil, close it - if c.cc != nil { - _ = c.cc.Close() - } - c.cc = cc - return true -} - -func (c *connection) dialToCollector(ctx context.Context) (*grpc.ClientConn, error) { - dialOpts := []grpc.DialOption{} - if c.cfg.ServiceConfig != "" { - dialOpts = append(dialOpts, grpc.WithDefaultServiceConfig(c.cfg.ServiceConfig)) - } - if c.sCfg.GRPCCredentials != nil { - dialOpts = append(dialOpts, grpc.WithTransportCredentials(c.sCfg.GRPCCredentials)) - } else if c.sCfg.Insecure { - dialOpts = append(dialOpts, grpc.WithInsecure()) - } - if c.sCfg.Compression == otlp.GzipCompression { - dialOpts = append(dialOpts, grpc.WithDefaultCallOptions(grpc.UseCompressor(gzip.Name))) - } - if len(c.cfg.DialOptions) != 0 { - dialOpts = append(dialOpts, c.cfg.DialOptions...) - } - - ctx, cancel := c.contextWithStop(ctx) - defer cancel() - ctx = c.contextWithMetadata(ctx) - return grpc.DialContext(ctx, c.sCfg.Endpoint, dialOpts...) -} - -func (c *connection) contextWithMetadata(ctx context.Context) context.Context { - if c.metadata.Len() > 0 { - return metadata.NewOutgoingContext(ctx, c.metadata) - } - return ctx -} - -func (c *connection) shutdown(ctx context.Context) error { - close(c.stopCh) - // Ensure that the backgroundConnector returns - select { - case <-c.backgroundConnectionDoneCh: - case <-ctx.Done(): - return ctx.Err() - } - - c.mu.Lock() - cc := c.cc - c.cc = nil - c.mu.Unlock() - - if cc != nil { - return cc.Close() - } - - return nil -} - -func (c *connection) contextWithStop(ctx context.Context) (context.Context, context.CancelFunc) { - // Unify the parent context Done signal with the connection's - // stop channel. - ctx, cancel := context.WithCancel(ctx) - go func(ctx context.Context, cancel context.CancelFunc) { - select { - case <-ctx.Done(): - // Nothing to do, either cancelled or deadline - // happened. - case <-c.stopCh: - cancel() - } - }(ctx, cancel) - return ctx, cancel -} diff --git a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpgrpc/doc.go b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpgrpc/doc.go deleted file mode 100644 index 68f53fb0aa..0000000000 --- a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpgrpc/doc.go +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/* -Package otlpgrpc provides an implementation of otlp.ProtocolDriver -that connects to the collector and sends traces and metrics using -gRPC. - -This package is currently in a pre-GA phase. Backwards incompatible -changes may be introduced in subsequent minor version releases as we -work to track the evolving OpenTelemetry specification and user -feedback. -*/ -package otlpgrpc // import "go.opentelemetry.io/otel/exporters/otlp/otlpgrpc" diff --git a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpgrpc/driver.go b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpgrpc/driver.go deleted file mode 100644 index c5df20566c..0000000000 --- a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpgrpc/driver.go +++ /dev/null @@ -1,195 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package otlpgrpc // import "go.opentelemetry.io/otel/exporters/otlp/otlpgrpc" - -import ( - "context" - "errors" - "fmt" - "sync" - - "go.opentelemetry.io/otel/exporters/otlp/internal/otlpconfig" - - "google.golang.org/grpc" - - "go.opentelemetry.io/otel/exporters/otlp" - "go.opentelemetry.io/otel/exporters/otlp/internal/transform" - metricsdk "go.opentelemetry.io/otel/sdk/export/metric" - tracesdk "go.opentelemetry.io/otel/sdk/trace" - colmetricpb "go.opentelemetry.io/proto/otlp/collector/metrics/v1" - coltracepb "go.opentelemetry.io/proto/otlp/collector/trace/v1" - metricpb "go.opentelemetry.io/proto/otlp/metrics/v1" - tracepb "go.opentelemetry.io/proto/otlp/trace/v1" -) - -type driver struct { - metricsDriver metricsDriver - tracesDriver tracesDriver -} - -type metricsDriver struct { - connection *connection - - lock sync.Mutex - metricsClient colmetricpb.MetricsServiceClient -} - -type tracesDriver struct { - connection *connection - - lock sync.Mutex - tracesClient coltracepb.TraceServiceClient -} - -var ( - errNoClient = errors.New("no client") -) - -// NewDriver creates a new gRPC protocol driver. -func NewDriver(opts ...Option) otlp.ProtocolDriver { - cfg := otlpconfig.NewDefaultConfig() - otlpconfig.ApplyGRPCEnvConfigs(&cfg) - for _, opt := range opts { - opt.ApplyGRPCOption(&cfg) - } - - d := &driver{} - - d.tracesDriver = tracesDriver{ - connection: newConnection(cfg, cfg.Traces, d.tracesDriver.handleNewConnection), - } - - d.metricsDriver = metricsDriver{ - connection: newConnection(cfg, cfg.Metrics, d.metricsDriver.handleNewConnection), - } - return d -} - -func (md *metricsDriver) handleNewConnection(cc *grpc.ClientConn) { - md.lock.Lock() - defer md.lock.Unlock() - if cc != nil { - md.metricsClient = colmetricpb.NewMetricsServiceClient(cc) - } else { - md.metricsClient = nil - } -} - -func (td *tracesDriver) handleNewConnection(cc *grpc.ClientConn) { - td.lock.Lock() - defer td.lock.Unlock() - if cc != nil { - td.tracesClient = coltracepb.NewTraceServiceClient(cc) - } else { - td.tracesClient = nil - } -} - -// Start implements otlp.ProtocolDriver. It establishes a connection -// to the collector. -func (d *driver) Start(ctx context.Context) error { - d.tracesDriver.connection.startConnection(ctx) - d.metricsDriver.connection.startConnection(ctx) - return nil -} - -// Stop implements otlp.ProtocolDriver. It shuts down the connection -// to the collector. -func (d *driver) Stop(ctx context.Context) error { - if err := d.tracesDriver.connection.shutdown(ctx); err != nil { - return err - } - - return d.metricsDriver.connection.shutdown(ctx) -} - -// ExportMetrics implements otlp.ProtocolDriver. It transforms metrics -// to protobuf binary format and sends the result to the collector. -func (d *driver) ExportMetrics(ctx context.Context, cps metricsdk.CheckpointSet, selector metricsdk.ExportKindSelector) error { - if !d.metricsDriver.connection.connected() { - return fmt.Errorf("metrics exporter is disconnected from the server %s: %w", d.metricsDriver.connection.sCfg.Endpoint, d.metricsDriver.connection.lastConnectError()) - } - ctx, cancel := d.metricsDriver.connection.contextWithStop(ctx) - defer cancel() - ctx, tCancel := context.WithTimeout(ctx, d.metricsDriver.connection.sCfg.Timeout) - defer tCancel() - - rms, err := transform.CheckpointSet(ctx, selector, cps, 1) - if err != nil { - return err - } - if len(rms) == 0 { - return nil - } - - return d.metricsDriver.uploadMetrics(ctx, rms) -} - -func (md *metricsDriver) uploadMetrics(ctx context.Context, protoMetrics []*metricpb.ResourceMetrics) error { - ctx = md.connection.contextWithMetadata(ctx) - err := func() error { - md.lock.Lock() - defer md.lock.Unlock() - if md.metricsClient == nil { - return errNoClient - } - _, err := md.metricsClient.Export(ctx, &colmetricpb.ExportMetricsServiceRequest{ - ResourceMetrics: protoMetrics, - }) - return err - }() - if err != nil { - md.connection.setStateDisconnected(err) - } - return err -} - -// ExportTraces implements otlp.ProtocolDriver. It transforms spans to -// protobuf binary format and sends the result to the collector. -func (d *driver) ExportTraces(ctx context.Context, ss []*tracesdk.SpanSnapshot) error { - if !d.tracesDriver.connection.connected() { - return fmt.Errorf("traces exporter is disconnected from the server %s: %w", d.tracesDriver.connection.sCfg.Endpoint, d.tracesDriver.connection.lastConnectError()) - } - ctx, cancel := d.tracesDriver.connection.contextWithStop(ctx) - defer cancel() - ctx, tCancel := context.WithTimeout(ctx, d.tracesDriver.connection.sCfg.Timeout) - defer tCancel() - - protoSpans := transform.SpanData(ss) - if len(protoSpans) == 0 { - return nil - } - - return d.tracesDriver.uploadTraces(ctx, protoSpans) -} - -func (td *tracesDriver) uploadTraces(ctx context.Context, protoSpans []*tracepb.ResourceSpans) error { - ctx = td.connection.contextWithMetadata(ctx) - err := func() error { - td.lock.Lock() - defer td.lock.Unlock() - if td.tracesClient == nil { - return errNoClient - } - _, err := td.tracesClient.Export(ctx, &coltracepb.ExportTraceServiceRequest{ - ResourceSpans: protoSpans, - }) - return err - }() - if err != nil { - td.connection.setStateDisconnected(err) - } - return err -} diff --git a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpgrpc/options.go b/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpgrpc/options.go deleted file mode 100644 index dd7201f94a..0000000000 --- a/vendor/go.opentelemetry.io/otel/exporters/otlp/otlpgrpc/options.go +++ /dev/null @@ -1,202 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package otlpgrpc - -import ( - "fmt" - "time" - - "go.opentelemetry.io/otel" - "go.opentelemetry.io/otel/exporters/otlp" - "go.opentelemetry.io/otel/exporters/otlp/internal/otlpconfig" - - "google.golang.org/grpc" - "google.golang.org/grpc/credentials" -) - -// Option applies an option to the gRPC driver. -type Option interface { - otlpconfig.GRPCOption -} - -// WithInsecure disables client transport security for the exporter's gRPC connection -// just like grpc.WithInsecure() https://pkg.go.dev/google.golang.org/grpc#WithInsecure -// does. Note, by default, client security is required unless WithInsecure is used. -func WithInsecure() Option { - return otlpconfig.WithInsecure() -} - -// WithTracesInsecure disables client transport security for the traces exporter's gRPC connection -// just like grpc.WithInsecure() https://pkg.go.dev/google.golang.org/grpc#WithInsecure -// does. Note, by default, client security is required unless WithInsecure is used. -func WithTracesInsecure() Option { - return otlpconfig.WithInsecureTraces() -} - -// WithInsecureMetrics disables client transport security for the metrics exporter's gRPC connection -// just like grpc.WithInsecure() https://pkg.go.dev/google.golang.org/grpc#WithInsecure -// does. Note, by default, client security is required unless WithInsecure is used. -func WithInsecureMetrics() Option { - return otlpconfig.WithInsecureMetrics() -} - -// WithEndpoint allows one to set the endpoint that the exporter will -// connect to the collector on. If unset, it will instead try to use -// connect to DefaultCollectorHost:DefaultCollectorPort. -func WithEndpoint(endpoint string) Option { - return otlpconfig.WithEndpoint(endpoint) -} - -// WithTracesEndpoint allows one to set the traces endpoint that the exporter will -// connect to the collector on. If unset, it will instead try to use -// connect to DefaultCollectorHost:DefaultCollectorPort. -func WithTracesEndpoint(endpoint string) Option { - return otlpconfig.WithTracesEndpoint(endpoint) -} - -// WithMetricsEndpoint allows one to set the metrics endpoint that the exporter will -// connect to the collector on. If unset, it will instead try to use -// connect to DefaultCollectorHost:DefaultCollectorPort. -func WithMetricsEndpoint(endpoint string) Option { - return otlpconfig.WithMetricsEndpoint(endpoint) -} - -// WithReconnectionPeriod allows one to set the delay between next connection attempt -// after failing to connect with the collector. -func WithReconnectionPeriod(rp time.Duration) otlpconfig.GRPCOption { - return otlpconfig.NewGRPCOption(func(cfg *otlpconfig.Config) { - cfg.ReconnectionPeriod = rp - }) -} - -func compressorToCompression(compressor string) otlp.Compression { - switch compressor { - case "gzip": - return otlp.GzipCompression - } - - otel.Handle(fmt.Errorf("invalid compression type: '%s', using no compression as default", compressor)) - return otlp.NoCompression -} - -// WithCompressor will set the compressor for the gRPC client to use when sending requests. -// It is the responsibility of the caller to ensure that the compressor set has been registered -// with google.golang.org/grpc/encoding. This can be done by encoding.RegisterCompressor. Some -// compressors auto-register on import, such as gzip, which can be registered by calling -// `import _ "google.golang.org/grpc/encoding/gzip"`. -func WithCompressor(compressor string) Option { - return otlpconfig.WithCompression(compressorToCompression(compressor)) -} - -// WithTracesCompression will set the compressor for the gRPC client to use when sending traces requests. -// It is the responsibility of the caller to ensure that the compressor set has been registered -// with google.golang.org/grpc/encoding. This can be done by encoding.RegisterCompressor. Some -// compressors auto-register on import, such as gzip, which can be registered by calling -// `import _ "google.golang.org/grpc/encoding/gzip"`. -func WithTracesCompression(compressor string) Option { - return otlpconfig.WithTracesCompression(compressorToCompression(compressor)) -} - -// WithMetricsCompression will set the compressor for the gRPC client to use when sending metrics requests. -// It is the responsibility of the caller to ensure that the compressor set has been registered -// with google.golang.org/grpc/encoding. This can be done by encoding.RegisterCompressor. Some -// compressors auto-register on import, such as gzip, which can be registered by calling -// `import _ "google.golang.org/grpc/encoding/gzip"`. -func WithMetricsCompression(compressor string) Option { - return otlpconfig.WithMetricsCompression(compressorToCompression(compressor)) -} - -// WithHeaders will send the provided headers with gRPC requests. -func WithHeaders(headers map[string]string) Option { - return otlpconfig.WithHeaders(headers) -} - -// WithTracesHeaders will send the provided headers with gRPC traces requests. -func WithTracesHeaders(headers map[string]string) Option { - return otlpconfig.WithTracesHeaders(headers) -} - -// WithMetricsHeaders will send the provided headers with gRPC metrics requests. -func WithMetricsHeaders(headers map[string]string) Option { - return otlpconfig.WithMetricsHeaders(headers) -} - -// WithTLSCredentials allows the connection to use TLS credentials -// when talking to the server. It takes in grpc.TransportCredentials instead -// of say a Certificate file or a tls.Certificate, because the retrieving of -// these credentials can be done in many ways e.g. plain file, in code tls.Config -// or by certificate rotation, so it is up to the caller to decide what to use. -func WithTLSCredentials(creds credentials.TransportCredentials) Option { - return otlpconfig.NewGRPCOption(func(cfg *otlpconfig.Config) { - cfg.Traces.GRPCCredentials = creds - cfg.Metrics.GRPCCredentials = creds - }) -} - -// WithTracesTLSCredentials allows the connection to use TLS credentials -// when talking to the traces server. It takes in grpc.TransportCredentials instead -// of say a Certificate file or a tls.Certificate, because the retrieving of -// these credentials can be done in many ways e.g. plain file, in code tls.Config -// or by certificate rotation, so it is up to the caller to decide what to use. -func WithTracesTLSCredentials(creds credentials.TransportCredentials) Option { - return otlpconfig.NewGRPCOption(func(cfg *otlpconfig.Config) { - cfg.Traces.GRPCCredentials = creds - }) -} - -// WithMetricsTLSCredentials allows the connection to use TLS credentials -// when talking to the metrics server. It takes in grpc.TransportCredentials instead -// of say a Certificate file or a tls.Certificate, because the retrieving of -// these credentials can be done in many ways e.g. plain file, in code tls.Config -// or by certificate rotation, so it is up to the caller to decide what to use. -func WithMetricsTLSCredentials(creds credentials.TransportCredentials) Option { - return otlpconfig.NewGRPCOption(func(cfg *otlpconfig.Config) { - cfg.Metrics.GRPCCredentials = creds - }) -} - -// WithServiceConfig defines the default gRPC service config used. -func WithServiceConfig(serviceConfig string) Option { - return otlpconfig.NewGRPCOption(func(cfg *otlpconfig.Config) { - cfg.ServiceConfig = serviceConfig - }) -} - -// WithDialOption opens support to any grpc.DialOption to be used. If it conflicts -// with some other configuration the GRPC specified via the collector the ones here will -// take preference since they are set last. -func WithDialOption(opts ...grpc.DialOption) Option { - return otlpconfig.NewGRPCOption(func(cfg *otlpconfig.Config) { - cfg.DialOptions = opts - }) -} - -// WithTimeout tells the driver the max waiting time for the backend to process -// each spans or metrics batch. If unset, the default will be 10 seconds. -func WithTimeout(duration time.Duration) Option { - return otlpconfig.WithTimeout(duration) -} - -// WithTracesTimeout tells the driver the max waiting time for the backend to process -// each spans batch. If unset, the default will be 10 seconds. -func WithTracesTimeout(duration time.Duration) Option { - return otlpconfig.WithTracesTimeout(duration) -} - -// WithMetricsTimeout tells the driver the max waiting time for the backend to process -// each metrics batch. If unset, the default will be 10 seconds. -func WithMetricsTimeout(duration time.Duration) Option { - return otlpconfig.WithMetricsTimeout(duration) -} diff --git a/vendor/go.opentelemetry.io/otel/exporters/otlp/protocoldriver.go b/vendor/go.opentelemetry.io/otel/exporters/otlp/protocoldriver.go deleted file mode 100644 index 7c45cefb9f..0000000000 --- a/vendor/go.opentelemetry.io/otel/exporters/otlp/protocoldriver.go +++ /dev/null @@ -1,145 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package otlp // import "go.opentelemetry.io/otel/exporters/otlp" - -import ( - "context" - "sync" - - metricsdk "go.opentelemetry.io/otel/sdk/export/metric" - tracesdk "go.opentelemetry.io/otel/sdk/trace" -) - -// ProtocolDriver is an interface used by OTLP exporter. It's -// responsible for connecting to and disconnecting from the collector, -// and for transforming traces and metrics into wire format and -// transmitting them to the collector. -type ProtocolDriver interface { - // Start should establish connection(s) to endpoint(s). It is - // called just once by the exporter, so the implementation - // does not need to worry about idempotence and locking. - Start(ctx context.Context) error - // Stop should close the connections. The function is called - // only once by the exporter, so the implementation does not - // need to worry about idempotence, but it may be called - // concurrently with ExportMetrics or ExportTraces, so proper - // locking is required. The function serves as a - // synchronization point - after the function returns, the - // process of closing connections is assumed to be finished. - Stop(ctx context.Context) error - // ExportMetrics should transform the passed metrics to the - // wire format and send it to the collector. May be called - // concurrently with ExportTraces, so the manager needs to - // take this into account by doing proper locking. - ExportMetrics(ctx context.Context, cps metricsdk.CheckpointSet, selector metricsdk.ExportKindSelector) error - // ExportTraces should transform the passed traces to the wire - // format and send it to the collector. May be called - // concurrently with ExportMetrics, so the manager needs to - // take this into account by doing proper locking. - ExportTraces(ctx context.Context, ss []*tracesdk.SpanSnapshot) error -} - -// SplitConfig is used to configure a split driver. -type SplitConfig struct { - // ForMetrics driver will be used for sending metrics to the - // collector. - ForMetrics ProtocolDriver - // ForTraces driver will be used for sending spans to the - // collector. - ForTraces ProtocolDriver -} - -type splitDriver struct { - metric ProtocolDriver - trace ProtocolDriver -} - -var _ ProtocolDriver = (*splitDriver)(nil) - -// NewSplitDriver creates a protocol driver which contains two other -// protocol drivers and will forward traces to one of them and metrics -// to another. -func NewSplitDriver(cfg SplitConfig) ProtocolDriver { - return &splitDriver{ - metric: cfg.ForMetrics, - trace: cfg.ForTraces, - } -} - -// Start implements ProtocolDriver. It starts both drivers at the same -// time. -func (d *splitDriver) Start(ctx context.Context) error { - wg := sync.WaitGroup{} - wg.Add(2) - var ( - metricErr error - traceErr error - ) - go func() { - defer wg.Done() - metricErr = d.metric.Start(ctx) - }() - go func() { - defer wg.Done() - traceErr = d.trace.Start(ctx) - }() - wg.Wait() - if metricErr != nil { - return metricErr - } - if traceErr != nil { - return traceErr - } - return nil -} - -// Stop implements ProtocolDriver. It stops both drivers at the same -// time. -func (d *splitDriver) Stop(ctx context.Context) error { - wg := sync.WaitGroup{} - wg.Add(2) - var ( - metricErr error - traceErr error - ) - go func() { - defer wg.Done() - metricErr = d.metric.Stop(ctx) - }() - go func() { - defer wg.Done() - traceErr = d.trace.Stop(ctx) - }() - wg.Wait() - if metricErr != nil { - return metricErr - } - if traceErr != nil { - return traceErr - } - return nil -} - -// ExportMetrics implements ProtocolDriver. It forwards the call to -// the driver used for sending metrics. -func (d *splitDriver) ExportMetrics(ctx context.Context, cps metricsdk.CheckpointSet, selector metricsdk.ExportKindSelector) error { - return d.metric.ExportMetrics(ctx, cps, selector) -} - -// ExportTraces implements ProtocolDriver. It forwards the call to the -// driver used for sending spans. -func (d *splitDriver) ExportTraces(ctx context.Context, ss []*tracesdk.SpanSnapshot) error { - return d.trace.ExportTraces(ctx, ss) -} diff --git a/vendor/go.opentelemetry.io/otel/get_main_pkgs.sh b/vendor/go.opentelemetry.io/otel/get_main_pkgs.sh deleted file mode 100644 index 9a58fb1d37..0000000000 --- a/vendor/go.opentelemetry.io/otel/get_main_pkgs.sh +++ /dev/null @@ -1,41 +0,0 @@ -#!/usr/bin/env bash - -# Copyright The OpenTelemetry Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -set -euo pipefail - -top_dir='.' -if [[ $# -gt 0 ]]; then - top_dir="${1}" -fi - -p=$(pwd) -mod_dirs=() - -# Note `mapfile` does not exist in older bash versions: -# https://stackoverflow.com/questions/41475261/need-alternative-to-readarray-mapfile-for-script-on-older-version-of-bash - -while IFS= read -r line; do - mod_dirs+=("$line") -done < <(find "${top_dir}" -type f -name 'go.mod' -exec dirname {} \; | sort) - -for mod_dir in "${mod_dirs[@]}"; do - cd "${mod_dir}" - - while IFS= read -r line; do - echo ".${line#${p}}" - done < <(go list --find -f '{{.Name}}|{{.Dir}}' ./... | grep '^main|' | cut -f 2- -d '|') - cd "${p}" -done diff --git a/vendor/go.opentelemetry.io/otel/go.mod b/vendor/go.opentelemetry.io/otel/go.mod deleted file mode 100644 index a0e9267ad3..0000000000 --- a/vendor/go.opentelemetry.io/otel/go.mod +++ /dev/null @@ -1,55 +0,0 @@ -module go.opentelemetry.io/otel - -go 1.14 - -require ( - github.com/google/go-cmp v0.5.5 - github.com/stretchr/testify v1.7.0 - go.opentelemetry.io/otel/metric v0.20.0 - go.opentelemetry.io/otel/oteltest v0.20.0 - go.opentelemetry.io/otel/trace v0.20.0 -) - -replace go.opentelemetry.io/otel => ./ - -replace go.opentelemetry.io/otel/bridge/opencensus => ./bridge/opencensus - -replace go.opentelemetry.io/otel/bridge/opentracing => ./bridge/opentracing - -replace go.opentelemetry.io/otel/example/jaeger => ./example/jaeger - -replace go.opentelemetry.io/otel/example/namedtracer => ./example/namedtracer - -replace go.opentelemetry.io/otel/example/opencensus => ./example/opencensus - -replace go.opentelemetry.io/otel/example/otel-collector => ./example/otel-collector - -replace go.opentelemetry.io/otel/example/prom-collector => ./example/prom-collector - -replace go.opentelemetry.io/otel/example/prometheus => ./example/prometheus - -replace go.opentelemetry.io/otel/example/zipkin => ./example/zipkin - -replace go.opentelemetry.io/otel/exporters/metric/prometheus => ./exporters/metric/prometheus - -replace go.opentelemetry.io/otel/exporters/otlp => ./exporters/otlp - -replace go.opentelemetry.io/otel/exporters/stdout => ./exporters/stdout - -replace go.opentelemetry.io/otel/exporters/trace/jaeger => ./exporters/trace/jaeger - -replace go.opentelemetry.io/otel/exporters/trace/zipkin => ./exporters/trace/zipkin - -replace go.opentelemetry.io/otel/internal/tools => ./internal/tools - -replace go.opentelemetry.io/otel/sdk => ./sdk - -replace go.opentelemetry.io/otel/metric => ./metric - -replace go.opentelemetry.io/otel/oteltest => ./oteltest - -replace go.opentelemetry.io/otel/sdk/export/metric => ./sdk/export/metric - -replace go.opentelemetry.io/otel/sdk/metric => ./sdk/metric - -replace go.opentelemetry.io/otel/trace => ./trace diff --git a/vendor/go.opentelemetry.io/otel/go.sum b/vendor/go.opentelemetry.io/otel/go.sum deleted file mode 100644 index b69f2e56da..0000000000 --- a/vendor/go.opentelemetry.io/otel/go.sum +++ /dev/null @@ -1,15 +0,0 @@ -github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= -github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= -github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/vendor/go.opentelemetry.io/otel/handler.go b/vendor/go.opentelemetry.io/otel/handler.go deleted file mode 100644 index 27e1caa30d..0000000000 --- a/vendor/go.opentelemetry.io/otel/handler.go +++ /dev/null @@ -1,89 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package otel // import "go.opentelemetry.io/otel" - -import ( - "log" - "os" - "sync" - "sync/atomic" -) - -var ( - // globalErrorHandler provides an ErrorHandler that can be used - // throughout an OpenTelemetry instrumented project. When a user - // specified ErrorHandler is registered (`SetErrorHandler`) all calls to - // `Handle` and will be delegated to the registered ErrorHandler. - globalErrorHandler = &loggingErrorHandler{ - l: log.New(os.Stderr, "", log.LstdFlags), - } - - // delegateErrorHandlerOnce ensures that a user provided ErrorHandler is - // only ever registered once. - delegateErrorHandlerOnce sync.Once - - // Comiple time check that loggingErrorHandler implements ErrorHandler. - _ ErrorHandler = (*loggingErrorHandler)(nil) -) - -// loggingErrorHandler logs all errors to STDERR. -type loggingErrorHandler struct { - delegate atomic.Value - - l *log.Logger -} - -// setDelegate sets the ErrorHandler delegate if one is not already set. -func (h *loggingErrorHandler) setDelegate(d ErrorHandler) { - if h.delegate.Load() != nil { - // Delegate already registered - return - } - h.delegate.Store(d) -} - -// Handle implements ErrorHandler. -func (h *loggingErrorHandler) Handle(err error) { - if d := h.delegate.Load(); d != nil { - d.(ErrorHandler).Handle(err) - return - } - h.l.Print(err) -} - -// GetErrorHandler returns the global ErrorHandler instance. If no ErrorHandler -// instance has been set (`SetErrorHandler`), the default ErrorHandler which -// logs errors to STDERR is returned. -func GetErrorHandler() ErrorHandler { - return globalErrorHandler -} - -// SetErrorHandler sets the global ErrorHandler to be h. -func SetErrorHandler(h ErrorHandler) { - delegateErrorHandlerOnce.Do(func() { - current := GetErrorHandler() - if current == h { - return - } - if internalHandler, ok := current.(*loggingErrorHandler); ok { - internalHandler.setDelegate(h) - } - }) -} - -// Handle is a convience function for ErrorHandler().Handle(err) -func Handle(err error) { - GetErrorHandler().Handle(err) -} diff --git a/vendor/go.opentelemetry.io/otel/internal/baggage/baggage.go b/vendor/go.opentelemetry.io/otel/internal/baggage/baggage.go deleted file mode 100644 index b1f7daf8d8..0000000000 --- a/vendor/go.opentelemetry.io/otel/internal/baggage/baggage.go +++ /dev/null @@ -1,338 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package baggage provides types and functions to manage W3C Baggage. -package baggage - -import ( - "context" - - "go.opentelemetry.io/otel/attribute" -) - -type rawMap map[attribute.Key]attribute.Value -type keySet map[attribute.Key]struct{} - -// Map is an immutable storage for correlations. -type Map struct { - m rawMap -} - -// MapUpdate contains information about correlation changes to be -// made. -type MapUpdate struct { - // DropSingleK contains a single key to be dropped from - // correlations. Use this to avoid an overhead of a slice - // allocation if there is only one key to drop. - DropSingleK attribute.Key - // DropMultiK contains all the keys to be dropped from - // correlations. - DropMultiK []attribute.Key - - // SingleKV contains a single key-value pair to be added to - // correlations. Use this to avoid an overhead of a slice - // allocation if there is only one key-value pair to add. - SingleKV attribute.KeyValue - // MultiKV contains all the key-value pairs to be added to - // correlations. - MultiKV []attribute.KeyValue -} - -func newMap(raw rawMap) Map { - return Map{ - m: raw, - } -} - -// NewEmptyMap creates an empty correlations map. -func NewEmptyMap() Map { - return newMap(nil) -} - -// NewMap creates a map with the contents of the update applied. In -// this function, having an update with DropSingleK or DropMultiK -// makes no sense - those fields are effectively ignored. -func NewMap(update MapUpdate) Map { - return NewEmptyMap().Apply(update) -} - -// Apply creates a copy of the map with the contents of the update -// applied. Apply will first drop the keys from DropSingleK and -// DropMultiK, then add key-value pairs from SingleKV and MultiKV. -func (m Map) Apply(update MapUpdate) Map { - delSet, addSet := getModificationSets(update) - mapSize := getNewMapSize(m.m, delSet, addSet) - - r := make(rawMap, mapSize) - for k, v := range m.m { - // do not copy items we want to drop - if _, ok := delSet[k]; ok { - continue - } - // do not copy items we would overwrite - if _, ok := addSet[k]; ok { - continue - } - r[k] = v - } - if update.SingleKV.Key.Defined() { - r[update.SingleKV.Key] = update.SingleKV.Value - } - for _, kv := range update.MultiKV { - r[kv.Key] = kv.Value - } - if len(r) == 0 { - r = nil - } - return newMap(r) -} - -func getModificationSets(update MapUpdate) (delSet, addSet keySet) { - deletionsCount := len(update.DropMultiK) - if update.DropSingleK.Defined() { - deletionsCount++ - } - if deletionsCount > 0 { - delSet = make(map[attribute.Key]struct{}, deletionsCount) - for _, k := range update.DropMultiK { - delSet[k] = struct{}{} - } - if update.DropSingleK.Defined() { - delSet[update.DropSingleK] = struct{}{} - } - } - - additionsCount := len(update.MultiKV) - if update.SingleKV.Key.Defined() { - additionsCount++ - } - if additionsCount > 0 { - addSet = make(map[attribute.Key]struct{}, additionsCount) - for _, k := range update.MultiKV { - addSet[k.Key] = struct{}{} - } - if update.SingleKV.Key.Defined() { - addSet[update.SingleKV.Key] = struct{}{} - } - } - - return -} - -func getNewMapSize(m rawMap, delSet, addSet keySet) int { - mapSizeDiff := 0 - for k := range addSet { - if _, ok := m[k]; !ok { - mapSizeDiff++ - } - } - for k := range delSet { - if _, ok := m[k]; ok { - if _, inAddSet := addSet[k]; !inAddSet { - mapSizeDiff-- - } - } - } - return len(m) + mapSizeDiff -} - -// Value gets a value from correlations map and returns a boolean -// value indicating whether the key exist in the map. -func (m Map) Value(k attribute.Key) (attribute.Value, bool) { - value, ok := m.m[k] - return value, ok -} - -// HasValue returns a boolean value indicating whether the key exist -// in the map. -func (m Map) HasValue(k attribute.Key) bool { - _, has := m.Value(k) - return has -} - -// Len returns a length of the map. -func (m Map) Len() int { - return len(m.m) -} - -// Foreach calls a passed callback once on each key-value pair until -// all the key-value pairs of the map were iterated or the callback -// returns false, whichever happens first. -func (m Map) Foreach(f func(attribute.KeyValue) bool) { - for k, v := range m.m { - if !f(attribute.KeyValue{ - Key: k, - Value: v, - }) { - return - } - } -} - -type correlationsType struct{} - -// SetHookFunc describes a type of a callback that is called when -// storing baggage in the context. -type SetHookFunc func(context.Context) context.Context - -// GetHookFunc describes a type of a callback that is called when -// getting baggage from the context. -type GetHookFunc func(context.Context, Map) Map - -// value under this key is either of type Map or correlationsData -var correlationsKey = &correlationsType{} - -type correlationsData struct { - m Map - setHook SetHookFunc - getHook GetHookFunc -} - -func (d correlationsData) isHookless() bool { - return d.setHook == nil && d.getHook == nil -} - -type hookKind int - -const ( - hookKindSet hookKind = iota - hookKindGet -) - -func (d *correlationsData) overrideHook(kind hookKind, setHook SetHookFunc, getHook GetHookFunc) { - switch kind { - case hookKindSet: - d.setHook = setHook - case hookKindGet: - d.getHook = getHook - } -} - -// ContextWithSetHook installs a hook function that will be invoked -// every time ContextWithMap is called. To avoid unnecessary callback -// invocations (recursive or not), the callback can temporarily clear -// the hooks from the context with the ContextWithNoHooks function. -// -// Note that NewContext also calls ContextWithMap, so the hook will be -// invoked. -// -// Passing nil SetHookFunc creates a context with no set hook to call. -// -// This function should not be used by applications or libraries. It -// is mostly for interoperation with other observability APIs. -func ContextWithSetHook(ctx context.Context, hook SetHookFunc) context.Context { - return contextWithHook(ctx, hookKindSet, hook, nil) -} - -// ContextWithGetHook installs a hook function that will be invoked -// every time MapFromContext is called. To avoid unnecessary callback -// invocations (recursive or not), the callback can temporarily clear -// the hooks from the context with the ContextWithNoHooks function. -// -// Note that NewContext also calls MapFromContext, so the hook will be -// invoked. -// -// Passing nil GetHookFunc creates a context with no get hook to call. -// -// This function should not be used by applications or libraries. It -// is mostly for interoperation with other observability APIs. -func ContextWithGetHook(ctx context.Context, hook GetHookFunc) context.Context { - return contextWithHook(ctx, hookKindGet, nil, hook) -} - -func contextWithHook(ctx context.Context, kind hookKind, setHook SetHookFunc, getHook GetHookFunc) context.Context { - switch v := ctx.Value(correlationsKey).(type) { - case correlationsData: - v.overrideHook(kind, setHook, getHook) - if v.isHookless() { - return context.WithValue(ctx, correlationsKey, v.m) - } - return context.WithValue(ctx, correlationsKey, v) - case Map: - return contextWithOneHookAndMap(ctx, kind, setHook, getHook, v) - default: - m := NewEmptyMap() - return contextWithOneHookAndMap(ctx, kind, setHook, getHook, m) - } -} - -func contextWithOneHookAndMap(ctx context.Context, kind hookKind, setHook SetHookFunc, getHook GetHookFunc, m Map) context.Context { - d := correlationsData{m: m} - d.overrideHook(kind, setHook, getHook) - if d.isHookless() { - return ctx - } - return context.WithValue(ctx, correlationsKey, d) -} - -// ContextWithNoHooks creates a context with all the hooks -// disabled. Also returns old set and get hooks. This function can be -// used to temporarily clear the context from hooks and then reinstate -// them by calling ContextWithSetHook and ContextWithGetHook functions -// passing the hooks returned by this function. -// -// This function should not be used by applications or libraries. It -// is mostly for interoperation with other observability APIs. -func ContextWithNoHooks(ctx context.Context) (context.Context, SetHookFunc, GetHookFunc) { - switch v := ctx.Value(correlationsKey).(type) { - case correlationsData: - return context.WithValue(ctx, correlationsKey, v.m), v.setHook, v.getHook - default: - return ctx, nil, nil - } -} - -// ContextWithMap returns a context with the Map entered into it. -func ContextWithMap(ctx context.Context, m Map) context.Context { - switch v := ctx.Value(correlationsKey).(type) { - case correlationsData: - v.m = m - ctx = context.WithValue(ctx, correlationsKey, v) - if v.setHook != nil { - ctx = v.setHook(ctx) - } - return ctx - default: - return context.WithValue(ctx, correlationsKey, m) - } -} - -// ContextWithNoCorrelationData returns a context stripped of correlation -// data. -func ContextWithNoCorrelationData(ctx context.Context) context.Context { - return context.WithValue(ctx, correlationsKey, nil) -} - -// NewContext returns a context with the map from passed context -// updated with the passed key-value pairs. -func NewContext(ctx context.Context, keyvalues ...attribute.KeyValue) context.Context { - return ContextWithMap(ctx, MapFromContext(ctx).Apply(MapUpdate{ - MultiKV: keyvalues, - })) -} - -// MapFromContext gets the current Map from a Context. -func MapFromContext(ctx context.Context) Map { - switch v := ctx.Value(correlationsKey).(type) { - case correlationsData: - if v.getHook != nil { - return v.getHook(ctx, v.m) - } - return v.m - case Map: - return v - default: - return NewEmptyMap() - } -} diff --git a/vendor/go.opentelemetry.io/otel/internal/global/meter.go b/vendor/go.opentelemetry.io/otel/internal/global/meter.go deleted file mode 100644 index 36f9edeb8c..0000000000 --- a/vendor/go.opentelemetry.io/otel/internal/global/meter.go +++ /dev/null @@ -1,348 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package global - -import ( - "context" - "sync" - "sync/atomic" - "unsafe" - - "go.opentelemetry.io/otel/attribute" - "go.opentelemetry.io/otel/metric" - "go.opentelemetry.io/otel/metric/number" - "go.opentelemetry.io/otel/metric/registry" -) - -// This file contains the forwarding implementation of MeterProvider used as -// the default global instance. Metric events using instruments provided by -// this implementation are no-ops until the first Meter implementation is set -// as the global provider. -// -// The implementation here uses Mutexes to maintain a list of active Meters in -// the MeterProvider and Instruments in each Meter, under the assumption that -// these interfaces are not performance-critical. -// -// We have the invariant that setDelegate() will be called before a new -// MeterProvider implementation is registered as the global provider. Mutexes -// in the MeterProvider and Meters ensure that each instrument has a delegate -// before the global provider is set. -// -// Bound instrument operations are implemented by delegating to the -// instrument after it is registered, with a sync.Once initializer to -// protect against races with Release(). -// -// Metric uniqueness checking is implemented by calling the exported -// methods of the api/metric/registry package. - -type meterKey struct { - Name, Version string -} - -type meterProvider struct { - delegate metric.MeterProvider - - // lock protects `delegate` and `meters`. - lock sync.Mutex - - // meters maintains a unique entry for every named Meter - // that has been registered through the global instance. - meters map[meterKey]*meterEntry -} - -type meterImpl struct { - delegate unsafe.Pointer // (*metric.MeterImpl) - - lock sync.Mutex - syncInsts []*syncImpl - asyncInsts []*asyncImpl -} - -type meterEntry struct { - unique metric.MeterImpl - impl meterImpl -} - -type instrument struct { - descriptor metric.Descriptor -} - -type syncImpl struct { - delegate unsafe.Pointer // (*metric.SyncImpl) - - instrument -} - -type asyncImpl struct { - delegate unsafe.Pointer // (*metric.AsyncImpl) - - instrument - - runner metric.AsyncRunner -} - -// SyncImpler is implemented by all of the sync metric -// instruments. -type SyncImpler interface { - SyncImpl() metric.SyncImpl -} - -// AsyncImpler is implemented by all of the async -// metric instruments. -type AsyncImpler interface { - AsyncImpl() metric.AsyncImpl -} - -type syncHandle struct { - delegate unsafe.Pointer // (*metric.BoundInstrumentImpl) - - inst *syncImpl - labels []attribute.KeyValue - - initialize sync.Once -} - -var _ metric.MeterProvider = &meterProvider{} -var _ metric.MeterImpl = &meterImpl{} -var _ metric.InstrumentImpl = &syncImpl{} -var _ metric.BoundSyncImpl = &syncHandle{} -var _ metric.AsyncImpl = &asyncImpl{} - -func (inst *instrument) Descriptor() metric.Descriptor { - return inst.descriptor -} - -// MeterProvider interface and delegation - -func newMeterProvider() *meterProvider { - return &meterProvider{ - meters: map[meterKey]*meterEntry{}, - } -} - -func (p *meterProvider) setDelegate(provider metric.MeterProvider) { - p.lock.Lock() - defer p.lock.Unlock() - - p.delegate = provider - for key, entry := range p.meters { - entry.impl.setDelegate(key.Name, key.Version, provider) - } - p.meters = nil -} - -func (p *meterProvider) Meter(instrumentationName string, opts ...metric.MeterOption) metric.Meter { - p.lock.Lock() - defer p.lock.Unlock() - - if p.delegate != nil { - return p.delegate.Meter(instrumentationName, opts...) - } - - key := meterKey{ - Name: instrumentationName, - Version: metric.NewMeterConfig(opts...).InstrumentationVersion, - } - entry, ok := p.meters[key] - if !ok { - entry = &meterEntry{} - entry.unique = registry.NewUniqueInstrumentMeterImpl(&entry.impl) - p.meters[key] = entry - - } - return metric.WrapMeterImpl(entry.unique, key.Name, metric.WithInstrumentationVersion(key.Version)) -} - -// Meter interface and delegation - -func (m *meterImpl) setDelegate(name, version string, provider metric.MeterProvider) { - m.lock.Lock() - defer m.lock.Unlock() - - d := new(metric.MeterImpl) - *d = provider.Meter(name, metric.WithInstrumentationVersion(version)).MeterImpl() - m.delegate = unsafe.Pointer(d) - - for _, inst := range m.syncInsts { - inst.setDelegate(*d) - } - m.syncInsts = nil - for _, obs := range m.asyncInsts { - obs.setDelegate(*d) - } - m.asyncInsts = nil -} - -func (m *meterImpl) NewSyncInstrument(desc metric.Descriptor) (metric.SyncImpl, error) { - m.lock.Lock() - defer m.lock.Unlock() - - if meterPtr := (*metric.MeterImpl)(atomic.LoadPointer(&m.delegate)); meterPtr != nil { - return (*meterPtr).NewSyncInstrument(desc) - } - - inst := &syncImpl{ - instrument: instrument{ - descriptor: desc, - }, - } - m.syncInsts = append(m.syncInsts, inst) - return inst, nil -} - -// Synchronous delegation - -func (inst *syncImpl) setDelegate(d metric.MeterImpl) { - implPtr := new(metric.SyncImpl) - - var err error - *implPtr, err = d.NewSyncInstrument(inst.descriptor) - - if err != nil { - // TODO: There is no standard way to deliver this error to the user. - // See https://github.com/open-telemetry/opentelemetry-go/issues/514 - // Note that the default SDK will not generate any errors yet, this is - // only for added safety. - panic(err) - } - - atomic.StorePointer(&inst.delegate, unsafe.Pointer(implPtr)) -} - -func (inst *syncImpl) Implementation() interface{} { - if implPtr := (*metric.SyncImpl)(atomic.LoadPointer(&inst.delegate)); implPtr != nil { - return (*implPtr).Implementation() - } - return inst -} - -func (inst *syncImpl) Bind(labels []attribute.KeyValue) metric.BoundSyncImpl { - if implPtr := (*metric.SyncImpl)(atomic.LoadPointer(&inst.delegate)); implPtr != nil { - return (*implPtr).Bind(labels) - } - return &syncHandle{ - inst: inst, - labels: labels, - } -} - -func (bound *syncHandle) Unbind() { - bound.initialize.Do(func() {}) - - implPtr := (*metric.BoundSyncImpl)(atomic.LoadPointer(&bound.delegate)) - - if implPtr == nil { - return - } - - (*implPtr).Unbind() -} - -// Async delegation - -func (m *meterImpl) NewAsyncInstrument( - desc metric.Descriptor, - runner metric.AsyncRunner, -) (metric.AsyncImpl, error) { - - m.lock.Lock() - defer m.lock.Unlock() - - if meterPtr := (*metric.MeterImpl)(atomic.LoadPointer(&m.delegate)); meterPtr != nil { - return (*meterPtr).NewAsyncInstrument(desc, runner) - } - - inst := &asyncImpl{ - instrument: instrument{ - descriptor: desc, - }, - runner: runner, - } - m.asyncInsts = append(m.asyncInsts, inst) - return inst, nil -} - -func (obs *asyncImpl) Implementation() interface{} { - if implPtr := (*metric.AsyncImpl)(atomic.LoadPointer(&obs.delegate)); implPtr != nil { - return (*implPtr).Implementation() - } - return obs -} - -func (obs *asyncImpl) setDelegate(d metric.MeterImpl) { - implPtr := new(metric.AsyncImpl) - - var err error - *implPtr, err = d.NewAsyncInstrument(obs.descriptor, obs.runner) - - if err != nil { - // TODO: There is no standard way to deliver this error to the user. - // See https://github.com/open-telemetry/opentelemetry-go/issues/514 - // Note that the default SDK will not generate any errors yet, this is - // only for added safety. - panic(err) - } - - atomic.StorePointer(&obs.delegate, unsafe.Pointer(implPtr)) -} - -// Metric updates - -func (m *meterImpl) RecordBatch(ctx context.Context, labels []attribute.KeyValue, measurements ...metric.Measurement) { - if delegatePtr := (*metric.MeterImpl)(atomic.LoadPointer(&m.delegate)); delegatePtr != nil { - (*delegatePtr).RecordBatch(ctx, labels, measurements...) - } -} - -func (inst *syncImpl) RecordOne(ctx context.Context, number number.Number, labels []attribute.KeyValue) { - if instPtr := (*metric.SyncImpl)(atomic.LoadPointer(&inst.delegate)); instPtr != nil { - (*instPtr).RecordOne(ctx, number, labels) - } -} - -// Bound instrument initialization - -func (bound *syncHandle) RecordOne(ctx context.Context, number number.Number) { - instPtr := (*metric.SyncImpl)(atomic.LoadPointer(&bound.inst.delegate)) - if instPtr == nil { - return - } - var implPtr *metric.BoundSyncImpl - bound.initialize.Do(func() { - implPtr = new(metric.BoundSyncImpl) - *implPtr = (*instPtr).Bind(bound.labels) - atomic.StorePointer(&bound.delegate, unsafe.Pointer(implPtr)) - }) - if implPtr == nil { - implPtr = (*metric.BoundSyncImpl)(atomic.LoadPointer(&bound.delegate)) - } - // This may still be nil if instrument was created and bound - // without a delegate, then the instrument was set to have a - // delegate and unbound. - if implPtr == nil { - return - } - (*implPtr).RecordOne(ctx, number) -} - -func AtomicFieldOffsets() map[string]uintptr { - return map[string]uintptr{ - "meterProvider.delegate": unsafe.Offsetof(meterProvider{}.delegate), - "meterImpl.delegate": unsafe.Offsetof(meterImpl{}.delegate), - "syncImpl.delegate": unsafe.Offsetof(syncImpl{}.delegate), - "asyncImpl.delegate": unsafe.Offsetof(asyncImpl{}.delegate), - "syncHandle.delegate": unsafe.Offsetof(syncHandle{}.delegate), - } -} diff --git a/vendor/go.opentelemetry.io/otel/internal/global/propagator.go b/vendor/go.opentelemetry.io/otel/internal/global/propagator.go deleted file mode 100644 index 1c8b8589b0..0000000000 --- a/vendor/go.opentelemetry.io/otel/internal/global/propagator.go +++ /dev/null @@ -1,82 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package global - -import ( - "context" - "sync" - - "go.opentelemetry.io/otel/propagation" -) - -// textMapPropagator is a default TextMapPropagator that delegates calls to a -// registered delegate if one is set, otherwise it defaults to delegating the -// calls to a the default no-op propagation.TextMapPropagator. -type textMapPropagator struct { - mtx sync.Mutex - once sync.Once - delegate propagation.TextMapPropagator - noop propagation.TextMapPropagator -} - -// Compile-time guarantee that textMapPropagator implements the -// propagation.TextMapPropagator interface. -var _ propagation.TextMapPropagator = (*textMapPropagator)(nil) - -func newTextMapPropagator() *textMapPropagator { - return &textMapPropagator{ - noop: propagation.NewCompositeTextMapPropagator(), - } -} - -// SetDelegate sets a delegate propagation.TextMapPropagator that all calls are -// forwarded to. Delegation can only be performed once, all subsequent calls -// perform no delegation. -func (p *textMapPropagator) SetDelegate(delegate propagation.TextMapPropagator) { - if delegate == nil { - return - } - - p.mtx.Lock() - p.once.Do(func() { p.delegate = delegate }) - p.mtx.Unlock() -} - -// effectiveDelegate returns the current delegate of p if one is set, -// otherwise the default noop TextMapPropagator is returned. This method -// can be called concurrently. -func (p *textMapPropagator) effectiveDelegate() propagation.TextMapPropagator { - p.mtx.Lock() - defer p.mtx.Unlock() - if p.delegate != nil { - return p.delegate - } - return p.noop -} - -// Inject set cross-cutting concerns from the Context into the carrier. -func (p *textMapPropagator) Inject(ctx context.Context, carrier propagation.TextMapCarrier) { - p.effectiveDelegate().Inject(ctx, carrier) -} - -// Extract reads cross-cutting concerns from the carrier into a Context. -func (p *textMapPropagator) Extract(ctx context.Context, carrier propagation.TextMapCarrier) context.Context { - return p.effectiveDelegate().Extract(ctx, carrier) -} - -// Fields returns the keys whose values are set with Inject. -func (p *textMapPropagator) Fields() []string { - return p.effectiveDelegate().Fields() -} diff --git a/vendor/go.opentelemetry.io/otel/internal/global/state.go b/vendor/go.opentelemetry.io/otel/internal/global/state.go deleted file mode 100644 index f3bf003510..0000000000 --- a/vendor/go.opentelemetry.io/otel/internal/global/state.go +++ /dev/null @@ -1,143 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package global - -import ( - "sync" - "sync/atomic" - - "go.opentelemetry.io/otel/metric" - "go.opentelemetry.io/otel/propagation" - "go.opentelemetry.io/otel/trace" -) - -type ( - tracerProviderHolder struct { - tp trace.TracerProvider - } - - meterProviderHolder struct { - mp metric.MeterProvider - } - - propagatorsHolder struct { - tm propagation.TextMapPropagator - } -) - -var ( - globalTracer = defaultTracerValue() - globalMeter = defaultMeterValue() - globalPropagators = defaultPropagatorsValue() - - delegateMeterOnce sync.Once - delegateTraceOnce sync.Once - delegateTextMapPropagatorOnce sync.Once -) - -// TracerProvider is the internal implementation for global.TracerProvider. -func TracerProvider() trace.TracerProvider { - return globalTracer.Load().(tracerProviderHolder).tp -} - -// SetTracerProvider is the internal implementation for global.SetTracerProvider. -func SetTracerProvider(tp trace.TracerProvider) { - delegateTraceOnce.Do(func() { - current := TracerProvider() - if current == tp { - // Setting the provider to the prior default is nonsense, panic. - // Panic is acceptable because we are likely still early in the - // process lifetime. - panic("invalid TracerProvider, the global instance cannot be reinstalled") - } else if def, ok := current.(*tracerProvider); ok { - def.setDelegate(tp) - } - - }) - globalTracer.Store(tracerProviderHolder{tp: tp}) -} - -// MeterProvider is the internal implementation for global.MeterProvider. -func MeterProvider() metric.MeterProvider { - return globalMeter.Load().(meterProviderHolder).mp -} - -// SetMeterProvider is the internal implementation for global.SetMeterProvider. -func SetMeterProvider(mp metric.MeterProvider) { - delegateMeterOnce.Do(func() { - current := MeterProvider() - - if current == mp { - // Setting the provider to the prior default is nonsense, panic. - // Panic is acceptable because we are likely still early in the - // process lifetime. - panic("invalid MeterProvider, the global instance cannot be reinstalled") - } else if def, ok := current.(*meterProvider); ok { - def.setDelegate(mp) - } - }) - globalMeter.Store(meterProviderHolder{mp: mp}) -} - -// TextMapPropagator is the internal implementation for global.TextMapPropagator. -func TextMapPropagator() propagation.TextMapPropagator { - return globalPropagators.Load().(propagatorsHolder).tm -} - -// SetTextMapPropagator is the internal implementation for global.SetTextMapPropagator. -func SetTextMapPropagator(p propagation.TextMapPropagator) { - // For the textMapPropagator already returned by TextMapPropagator - // delegate to p. - delegateTextMapPropagatorOnce.Do(func() { - if current := TextMapPropagator(); current == p { - // Setting the provider to the prior default is nonsense, panic. - // Panic is acceptable because we are likely still early in the - // process lifetime. - panic("invalid TextMapPropagator, the global instance cannot be reinstalled") - } else if def, ok := current.(*textMapPropagator); ok { - def.SetDelegate(p) - } - }) - // Return p when subsequent calls to TextMapPropagator are made. - globalPropagators.Store(propagatorsHolder{tm: p}) -} - -func defaultTracerValue() *atomic.Value { - v := &atomic.Value{} - v.Store(tracerProviderHolder{tp: &tracerProvider{}}) - return v -} - -func defaultMeterValue() *atomic.Value { - v := &atomic.Value{} - v.Store(meterProviderHolder{mp: newMeterProvider()}) - return v -} - -func defaultPropagatorsValue() *atomic.Value { - v := &atomic.Value{} - v.Store(propagatorsHolder{tm: newTextMapPropagator()}) - return v -} - -// ResetForTest restores the initial global state, for testing purposes. -func ResetForTest() { - globalTracer = defaultTracerValue() - globalMeter = defaultMeterValue() - globalPropagators = defaultPropagatorsValue() - delegateMeterOnce = sync.Once{} - delegateTraceOnce = sync.Once{} - delegateTextMapPropagatorOnce = sync.Once{} -} diff --git a/vendor/go.opentelemetry.io/otel/internal/global/trace.go b/vendor/go.opentelemetry.io/otel/internal/global/trace.go deleted file mode 100644 index d7f71dc06c..0000000000 --- a/vendor/go.opentelemetry.io/otel/internal/global/trace.go +++ /dev/null @@ -1,147 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package global - -/* -This file contains the forwarding implementation of the TracerProvider used as -the default global instance. Prior to initialization of an SDK, Tracers -returned by the global TracerProvider will provide no-op functionality. This -means that all Span created prior to initialization are no-op Spans. - -Once an SDK has been initialized, all provided no-op Tracers are swapped for -Tracers provided by the SDK defined TracerProvider. However, any Span started -prior to this initialization does not change its behavior. Meaning, the Span -remains a no-op Span. - -The implementation to track and swap Tracers locks all new Tracer creation -until the swap is complete. This assumes that this operation is not -performance-critical. If that assumption is incorrect, be sure to configure an -SDK prior to any Tracer creation. -*/ - -import ( - "context" - "sync" - "sync/atomic" - - "go.opentelemetry.io/otel/internal/trace/noop" - "go.opentelemetry.io/otel/trace" -) - -// tracerProvider is a placeholder for a configured SDK TracerProvider. -// -// All TracerProvider functionality is forwarded to a delegate once -// configured. -type tracerProvider struct { - mtx sync.Mutex - tracers map[il]*tracer - delegate trace.TracerProvider -} - -// Compile-time guarantee that tracerProvider implements the TracerProvider -// interface. -var _ trace.TracerProvider = &tracerProvider{} - -// setDelegate configures p to delegate all TracerProvider functionality to -// provider. -// -// All Tracers provided prior to this function call are switched out to be -// Tracers provided by provider. -// -// It is guaranteed by the caller that this happens only once. -func (p *tracerProvider) setDelegate(provider trace.TracerProvider) { - p.mtx.Lock() - defer p.mtx.Unlock() - - p.delegate = provider - - if len(p.tracers) == 0 { - return - } - - for _, t := range p.tracers { - t.setDelegate(provider) - } - - p.tracers = nil -} - -// Tracer implements TracerProvider. -func (p *tracerProvider) Tracer(name string, opts ...trace.TracerOption) trace.Tracer { - p.mtx.Lock() - defer p.mtx.Unlock() - - if p.delegate != nil { - return p.delegate.Tracer(name, opts...) - } - - // At this moment it is guaranteed that no sdk is installed, save the tracer in the tracers map. - - key := il{ - name: name, - version: trace.NewTracerConfig(opts...).InstrumentationVersion, - } - - if p.tracers == nil { - p.tracers = make(map[il]*tracer) - } - - if val, ok := p.tracers[key]; ok { - return val - } - - t := &tracer{name: name, opts: opts} - p.tracers[key] = t - return t -} - -type il struct { - name string - version string -} - -// tracer is a placeholder for a trace.Tracer. -// -// All Tracer functionality is forwarded to a delegate once configured. -// Otherwise, all functionality is forwarded to a NoopTracer. -type tracer struct { - name string - opts []trace.TracerOption - - delegate atomic.Value -} - -// Compile-time guarantee that tracer implements the trace.Tracer interface. -var _ trace.Tracer = &tracer{} - -// setDelegate configures t to delegate all Tracer functionality to Tracers -// created by provider. -// -// All subsequent calls to the Tracer methods will be passed to the delegate. -// -// It is guaranteed by the caller that this happens only once. -func (t *tracer) setDelegate(provider trace.TracerProvider) { - t.delegate.Store(provider.Tracer(t.name, t.opts...)) -} - -// Start implements trace.Tracer by forwarding the call to t.delegate if -// set, otherwise it forwards the call to a NoopTracer. -func (t *tracer) Start(ctx context.Context, name string, opts ...trace.SpanOption) (context.Context, trace.Span) { - delegate := t.delegate.Load() - if delegate != nil { - return delegate.(trace.Tracer).Start(ctx, name, opts...) - } - return noop.Tracer.Start(ctx, name, opts...) -} diff --git a/vendor/go.opentelemetry.io/otel/internal/metric/async.go b/vendor/go.opentelemetry.io/otel/internal/metric/async.go deleted file mode 100644 index f05faca8a9..0000000000 --- a/vendor/go.opentelemetry.io/otel/internal/metric/async.go +++ /dev/null @@ -1,148 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package metric - -import ( - "context" - "errors" - "fmt" - "sync" - - "go.opentelemetry.io/otel" - "go.opentelemetry.io/otel/attribute" - "go.opentelemetry.io/otel/metric" -) - -var ErrInvalidAsyncRunner = errors.New("unknown async runner type") - -// AsyncCollector is an interface used between the MeterImpl and the -// AsyncInstrumentState helper below. This interface is implemented by -// the SDK to provide support for running observer callbacks. -type AsyncCollector interface { - // CollectAsync passes a batch of observations to the MeterImpl. - CollectAsync(labels []attribute.KeyValue, observation ...metric.Observation) -} - -// AsyncInstrumentState manages an ordered set of asynchronous -// instruments and the distinct runners, taking into account batch -// observer callbacks. -type AsyncInstrumentState struct { - lock sync.Mutex - - // errorOnce will use the otel.Handler to report an error - // once in case of an invalid runner attempting to run. - errorOnce sync.Once - - // runnerMap keeps the set of runners that will run each - // collection interval. Singletons are entered with a real - // instrument each, batch observers are entered with a nil - // instrument, ensuring that when a singleton callback is used - // repeatedly, it is executed repeatedly in the interval, while - // when a batch callback is used repeatedly, it only executes - // once per interval. - runnerMap map[asyncRunnerPair]struct{} - - // runners maintains the set of runners in the order they were - // registered. - runners []asyncRunnerPair - - // instruments maintains the set of instruments in the order - // they were registered. - instruments []metric.AsyncImpl -} - -// asyncRunnerPair is a map entry for Observer callback runners. -type asyncRunnerPair struct { - // runner is used as a map key here. The API ensures - // that all callbacks are pointers for this reason. - runner metric.AsyncRunner - - // inst refers to a non-nil instrument when `runner` is a - // AsyncSingleRunner. - inst metric.AsyncImpl -} - -// NewAsyncInstrumentState returns a new *AsyncInstrumentState, for -// use by MeterImpl to manage running the set of observer callbacks in -// the correct order. -func NewAsyncInstrumentState() *AsyncInstrumentState { - return &AsyncInstrumentState{ - runnerMap: map[asyncRunnerPair]struct{}{}, - } -} - -// Instruments returns the asynchronous instruments managed by this -// object, the set that should be checkpointed after observers are -// run. -func (a *AsyncInstrumentState) Instruments() []metric.AsyncImpl { - a.lock.Lock() - defer a.lock.Unlock() - return a.instruments -} - -// Register adds a new asynchronous instrument to by managed by this -// object. This should be called during NewAsyncInstrument() and -// assumes that errors (e.g., duplicate registration) have already -// been checked. -func (a *AsyncInstrumentState) Register(inst metric.AsyncImpl, runner metric.AsyncRunner) { - a.lock.Lock() - defer a.lock.Unlock() - - a.instruments = append(a.instruments, inst) - - // asyncRunnerPair reflects this callback in the asyncRunners - // list. If this is a batch runner, the instrument is nil. - // If this is a single-Observer runner, the instrument is - // included. This ensures that batch callbacks are called - // once and single callbacks are called once per instrument. - rp := asyncRunnerPair{ - runner: runner, - } - if _, ok := runner.(metric.AsyncSingleRunner); ok { - rp.inst = inst - } - - if _, ok := a.runnerMap[rp]; !ok { - a.runnerMap[rp] = struct{}{} - a.runners = append(a.runners, rp) - } -} - -// Run executes the complete set of observer callbacks. -func (a *AsyncInstrumentState) Run(ctx context.Context, collector AsyncCollector) { - a.lock.Lock() - runners := a.runners - a.lock.Unlock() - - for _, rp := range runners { - // The runner must be a single or batch runner, no - // other implementations are possible because the - // interface has un-exported methods. - - if singleRunner, ok := rp.runner.(metric.AsyncSingleRunner); ok { - singleRunner.Run(ctx, rp.inst, collector.CollectAsync) - continue - } - - if multiRunner, ok := rp.runner.(metric.AsyncBatchRunner); ok { - multiRunner.Run(ctx, collector.CollectAsync) - continue - } - - a.errorOnce.Do(func() { - otel.Handle(fmt.Errorf("%w: type %T (reported once)", ErrInvalidAsyncRunner, rp)) - }) - } -} diff --git a/vendor/go.opentelemetry.io/otel/internal/rawhelpers.go b/vendor/go.opentelemetry.io/otel/internal/rawhelpers.go deleted file mode 100644 index 0d806b1c89..0000000000 --- a/vendor/go.opentelemetry.io/otel/internal/rawhelpers.go +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package internal - -import ( - "math" - "unsafe" -) - -func BoolToRaw(b bool) uint64 { - if b { - return 1 - } - return 0 -} - -func RawToBool(r uint64) bool { - return r != 0 -} - -func Int64ToRaw(i int64) uint64 { - return uint64(i) -} - -func RawToInt64(r uint64) int64 { - return int64(r) -} - -func Float64ToRaw(f float64) uint64 { - return math.Float64bits(f) -} - -func RawToFloat64(r uint64) float64 { - return math.Float64frombits(r) -} - -func RawPtrToFloat64Ptr(r *uint64) *float64 { - return (*float64)(unsafe.Pointer(r)) -} - -func RawPtrToInt64Ptr(r *uint64) *int64 { - return (*int64)(unsafe.Pointer(r)) -} diff --git a/vendor/go.opentelemetry.io/otel/internal/trace/noop/noop.go b/vendor/go.opentelemetry.io/otel/internal/trace/noop/noop.go deleted file mode 100644 index 765c21a289..0000000000 --- a/vendor/go.opentelemetry.io/otel/internal/trace/noop/noop.go +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package noop provides noop tracing implementations for tracer and span. -package noop - -import ( - "context" - - "go.opentelemetry.io/otel/trace" -) - -var ( - // Tracer is a noop tracer that starts noop spans. - Tracer trace.Tracer - - // Span is a noop Span. - Span trace.Span -) - -func init() { - Tracer = trace.NewNoopTracerProvider().Tracer("") - _, Span = Tracer.Start(context.Background(), "") -} diff --git a/vendor/go.opentelemetry.io/otel/metric/LICENSE b/vendor/go.opentelemetry.io/otel/metric/LICENSE deleted file mode 100644 index 261eeb9e9f..0000000000 --- a/vendor/go.opentelemetry.io/otel/metric/LICENSE +++ /dev/null @@ -1,201 +0,0 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. diff --git a/vendor/go.opentelemetry.io/otel/metric/config.go b/vendor/go.opentelemetry.io/otel/metric/config.go deleted file mode 100644 index 02f0ff8e0c..0000000000 --- a/vendor/go.opentelemetry.io/otel/metric/config.go +++ /dev/null @@ -1,128 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package metric // import "go.opentelemetry.io/otel/metric" - -import ( - "go.opentelemetry.io/otel/unit" -) - -// InstrumentConfig contains options for metric instrument descriptors. -type InstrumentConfig struct { - // Description describes the instrument in human-readable terms. - Description string - // Unit describes the measurement unit for a instrument. - Unit unit.Unit - // InstrumentationName is the name of the library providing - // instrumentation. - InstrumentationName string - // InstrumentationVersion is the version of the library providing - // instrumentation. - InstrumentationVersion string -} - -// InstrumentOption is an interface for applying metric instrument options. -type InstrumentOption interface { - // ApplyMeter is used to set a InstrumentOption value of a - // InstrumentConfig. - ApplyInstrument(*InstrumentConfig) -} - -// NewInstrumentConfig creates a new InstrumentConfig -// and applies all the given options. -func NewInstrumentConfig(opts ...InstrumentOption) InstrumentConfig { - var config InstrumentConfig - for _, o := range opts { - o.ApplyInstrument(&config) - } - return config -} - -// WithDescription applies provided description. -func WithDescription(desc string) InstrumentOption { - return descriptionOption(desc) -} - -type descriptionOption string - -func (d descriptionOption) ApplyInstrument(config *InstrumentConfig) { - config.Description = string(d) -} - -// WithUnit applies provided unit. -func WithUnit(unit unit.Unit) InstrumentOption { - return unitOption(unit) -} - -type unitOption unit.Unit - -func (u unitOption) ApplyInstrument(config *InstrumentConfig) { - config.Unit = unit.Unit(u) -} - -// WithInstrumentationName sets the instrumentation name. -func WithInstrumentationName(name string) InstrumentOption { - return instrumentationNameOption(name) -} - -type instrumentationNameOption string - -func (i instrumentationNameOption) ApplyInstrument(config *InstrumentConfig) { - config.InstrumentationName = string(i) -} - -// MeterConfig contains options for Meters. -type MeterConfig struct { - // InstrumentationVersion is the version of the library providing - // instrumentation. - InstrumentationVersion string -} - -// MeterOption is an interface for applying Meter options. -type MeterOption interface { - // ApplyMeter is used to set a MeterOption value of a MeterConfig. - ApplyMeter(*MeterConfig) -} - -// NewMeterConfig creates a new MeterConfig and applies -// all the given options. -func NewMeterConfig(opts ...MeterOption) MeterConfig { - var config MeterConfig - for _, o := range opts { - o.ApplyMeter(&config) - } - return config -} - -// InstrumentationOption is an interface for applying instrumentation specific -// options. -type InstrumentationOption interface { - InstrumentOption - MeterOption -} - -// WithInstrumentationVersion sets the instrumentation version. -func WithInstrumentationVersion(version string) InstrumentationOption { - return instrumentationVersionOption(version) -} - -type instrumentationVersionOption string - -func (i instrumentationVersionOption) ApplyMeter(config *MeterConfig) { - config.InstrumentationVersion = string(i) -} - -func (i instrumentationVersionOption) ApplyInstrument(config *InstrumentConfig) { - config.InstrumentationVersion = string(i) -} diff --git a/vendor/go.opentelemetry.io/otel/metric/doc.go b/vendor/go.opentelemetry.io/otel/metric/doc.go deleted file mode 100644 index 7889ff000f..0000000000 --- a/vendor/go.opentelemetry.io/otel/metric/doc.go +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/* -Package metric provides an implementation of the metrics part of the -OpenTelemetry API. - -This package is currently in a pre-GA phase. Backwards incompatible changes -may be introduced in subsequent minor version releases as we work to track the -evolving OpenTelemetry specification and user feedback. - -Measurements can be made about an operation being performed or the state of a -system in general. These measurements can be crucial to the reliable operation -of code and provide valuable insights about the inner workings of a system. - -Measurements are made using instruments provided by this package. The type of -instrument used will depend on the type of measurement being made and of what -part of a system is being measured. - -Instruments are categorized as Synchronous or Asynchronous and independently -as Adding or Grouping. Synchronous instruments are called by the user with a -Context. Asynchronous instruments are called by the SDK during collection. -Additive instruments are semantically intended for capturing a sum. Grouping -instruments are intended for capturing a distribution. - -Additive instruments may be monotonic, in which case they are non-decreasing -and naturally define a rate. - -The synchronous instrument names are: - - Counter: additive, monotonic - UpDownCounter: additive - ValueRecorder: grouping - -and the asynchronous instruments are: - - SumObserver: additive, monotonic - UpDownSumObserver: additive - ValueObserver: grouping - -All instruments are provided with support for either float64 or int64 input -values. - -An instrument is created using a Meter. Additionally, a Meter is used to -record batches of synchronous measurements or asynchronous observations. A -Meter is obtained using a MeterProvider. A Meter, like a Tracer, is unique to -the instrumentation it instruments and must be named and versioned when -created with a MeterProvider with the name and version of the instrumentation -library. - -Instrumentation should be designed to accept a MeterProvider from which it can -create its own unique Meter. Alternatively, the registered global -MeterProvider from the go.opentelemetry.io/otel package can be used as a -default. -*/ -package metric // import "go.opentelemetry.io/otel/metric" diff --git a/vendor/go.opentelemetry.io/otel/metric/go.mod b/vendor/go.opentelemetry.io/otel/metric/go.mod deleted file mode 100644 index 47bc47badd..0000000000 --- a/vendor/go.opentelemetry.io/otel/metric/go.mod +++ /dev/null @@ -1,54 +0,0 @@ -module go.opentelemetry.io/otel/metric - -go 1.14 - -replace go.opentelemetry.io/otel => ../ - -replace go.opentelemetry.io/otel/bridge/opencensus => ../bridge/opencensus - -replace go.opentelemetry.io/otel/bridge/opentracing => ../bridge/opentracing - -replace go.opentelemetry.io/otel/example/jaeger => ../example/jaeger - -replace go.opentelemetry.io/otel/example/namedtracer => ../example/namedtracer - -replace go.opentelemetry.io/otel/example/opencensus => ../example/opencensus - -replace go.opentelemetry.io/otel/example/otel-collector => ../example/otel-collector - -replace go.opentelemetry.io/otel/example/prom-collector => ../example/prom-collector - -replace go.opentelemetry.io/otel/example/prometheus => ../example/prometheus - -replace go.opentelemetry.io/otel/example/zipkin => ../example/zipkin - -replace go.opentelemetry.io/otel/exporters/metric/prometheus => ../exporters/metric/prometheus - -replace go.opentelemetry.io/otel/exporters/otlp => ../exporters/otlp - -replace go.opentelemetry.io/otel/exporters/stdout => ../exporters/stdout - -replace go.opentelemetry.io/otel/exporters/trace/jaeger => ../exporters/trace/jaeger - -replace go.opentelemetry.io/otel/exporters/trace/zipkin => ../exporters/trace/zipkin - -replace go.opentelemetry.io/otel/internal/tools => ../internal/tools - -replace go.opentelemetry.io/otel/metric => ./ - -replace go.opentelemetry.io/otel/oteltest => ../oteltest - -replace go.opentelemetry.io/otel/sdk => ../sdk - -replace go.opentelemetry.io/otel/sdk/export/metric => ../sdk/export/metric - -replace go.opentelemetry.io/otel/sdk/metric => ../sdk/metric - -replace go.opentelemetry.io/otel/trace => ../trace - -require ( - github.com/google/go-cmp v0.5.5 - github.com/stretchr/testify v1.7.0 - go.opentelemetry.io/otel v0.20.0 - go.opentelemetry.io/otel/oteltest v0.20.0 -) diff --git a/vendor/go.opentelemetry.io/otel/metric/go.sum b/vendor/go.opentelemetry.io/otel/metric/go.sum deleted file mode 100644 index b69f2e56da..0000000000 --- a/vendor/go.opentelemetry.io/otel/metric/go.sum +++ /dev/null @@ -1,15 +0,0 @@ -github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= -github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= -github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/vendor/go.opentelemetry.io/otel/metric/instrumentkind_string.go b/vendor/go.opentelemetry.io/otel/metric/instrumentkind_string.go deleted file mode 100644 index 2805e22500..0000000000 --- a/vendor/go.opentelemetry.io/otel/metric/instrumentkind_string.go +++ /dev/null @@ -1,28 +0,0 @@ -// Code generated by "stringer -type=InstrumentKind"; DO NOT EDIT. - -package metric - -import "strconv" - -func _() { - // An "invalid array index" compiler error signifies that the constant values have changed. - // Re-run the stringer command to generate them again. - var x [1]struct{} - _ = x[ValueRecorderInstrumentKind-0] - _ = x[ValueObserverInstrumentKind-1] - _ = x[CounterInstrumentKind-2] - _ = x[UpDownCounterInstrumentKind-3] - _ = x[SumObserverInstrumentKind-4] - _ = x[UpDownSumObserverInstrumentKind-5] -} - -const _InstrumentKind_name = "ValueRecorderInstrumentKindValueObserverInstrumentKindCounterInstrumentKindUpDownCounterInstrumentKindSumObserverInstrumentKindUpDownSumObserverInstrumentKind" - -var _InstrumentKind_index = [...]uint8{0, 27, 54, 75, 102, 127, 158} - -func (i InstrumentKind) String() string { - if i < 0 || i >= InstrumentKind(len(_InstrumentKind_index)-1) { - return "InstrumentKind(" + strconv.FormatInt(int64(i), 10) + ")" - } - return _InstrumentKind_name[_InstrumentKind_index[i]:_InstrumentKind_index[i+1]] -} diff --git a/vendor/go.opentelemetry.io/otel/metric/metric.go b/vendor/go.opentelemetry.io/otel/metric/metric.go deleted file mode 100644 index b591985df6..0000000000 --- a/vendor/go.opentelemetry.io/otel/metric/metric.go +++ /dev/null @@ -1,577 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package metric // import "go.opentelemetry.io/otel/metric" - -import ( - "context" - - "go.opentelemetry.io/otel/attribute" - "go.opentelemetry.io/otel/metric/number" - "go.opentelemetry.io/otel/unit" -) - -// MeterProvider supports named Meter instances. -type MeterProvider interface { - // Meter creates an implementation of the Meter interface. - // The instrumentationName must be the name of the library providing - // instrumentation. This name may be the same as the instrumented code - // only if that code provides built-in instrumentation. If the - // instrumentationName is empty, then a implementation defined default - // name will be used instead. - Meter(instrumentationName string, opts ...MeterOption) Meter -} - -// Meter is the creator of metric instruments. -// -// An uninitialized Meter is a no-op implementation. -type Meter struct { - impl MeterImpl - name, version string -} - -// RecordBatch atomically records a batch of measurements. -func (m Meter) RecordBatch(ctx context.Context, ls []attribute.KeyValue, ms ...Measurement) { - if m.impl == nil { - return - } - m.impl.RecordBatch(ctx, ls, ms...) -} - -// NewBatchObserver creates a new BatchObserver that supports -// making batches of observations for multiple instruments. -func (m Meter) NewBatchObserver(callback BatchObserverFunc) BatchObserver { - return BatchObserver{ - meter: m, - runner: newBatchAsyncRunner(callback), - } -} - -// NewInt64Counter creates a new integer Counter instrument with the -// given name, customized with options. May return an error if the -// name is invalid (e.g., empty) or improperly registered (e.g., -// duplicate registration). -func (m Meter) NewInt64Counter(name string, options ...InstrumentOption) (Int64Counter, error) { - return wrapInt64CounterInstrument( - m.newSync(name, CounterInstrumentKind, number.Int64Kind, options)) -} - -// NewFloat64Counter creates a new floating point Counter with the -// given name, customized with options. May return an error if the -// name is invalid (e.g., empty) or improperly registered (e.g., -// duplicate registration). -func (m Meter) NewFloat64Counter(name string, options ...InstrumentOption) (Float64Counter, error) { - return wrapFloat64CounterInstrument( - m.newSync(name, CounterInstrumentKind, number.Float64Kind, options)) -} - -// NewInt64UpDownCounter creates a new integer UpDownCounter instrument with the -// given name, customized with options. May return an error if the -// name is invalid (e.g., empty) or improperly registered (e.g., -// duplicate registration). -func (m Meter) NewInt64UpDownCounter(name string, options ...InstrumentOption) (Int64UpDownCounter, error) { - return wrapInt64UpDownCounterInstrument( - m.newSync(name, UpDownCounterInstrumentKind, number.Int64Kind, options)) -} - -// NewFloat64UpDownCounter creates a new floating point UpDownCounter with the -// given name, customized with options. May return an error if the -// name is invalid (e.g., empty) or improperly registered (e.g., -// duplicate registration). -func (m Meter) NewFloat64UpDownCounter(name string, options ...InstrumentOption) (Float64UpDownCounter, error) { - return wrapFloat64UpDownCounterInstrument( - m.newSync(name, UpDownCounterInstrumentKind, number.Float64Kind, options)) -} - -// NewInt64ValueRecorder creates a new integer ValueRecorder instrument with the -// given name, customized with options. May return an error if the -// name is invalid (e.g., empty) or improperly registered (e.g., -// duplicate registration). -func (m Meter) NewInt64ValueRecorder(name string, opts ...InstrumentOption) (Int64ValueRecorder, error) { - return wrapInt64ValueRecorderInstrument( - m.newSync(name, ValueRecorderInstrumentKind, number.Int64Kind, opts)) -} - -// NewFloat64ValueRecorder creates a new floating point ValueRecorder with the -// given name, customized with options. May return an error if the -// name is invalid (e.g., empty) or improperly registered (e.g., -// duplicate registration). -func (m Meter) NewFloat64ValueRecorder(name string, opts ...InstrumentOption) (Float64ValueRecorder, error) { - return wrapFloat64ValueRecorderInstrument( - m.newSync(name, ValueRecorderInstrumentKind, number.Float64Kind, opts)) -} - -// NewInt64ValueObserver creates a new integer ValueObserver instrument -// with the given name, running a given callback, and customized with -// options. May return an error if the name is invalid (e.g., empty) -// or improperly registered (e.g., duplicate registration). -func (m Meter) NewInt64ValueObserver(name string, callback Int64ObserverFunc, opts ...InstrumentOption) (Int64ValueObserver, error) { - if callback == nil { - return wrapInt64ValueObserverInstrument(NoopAsync{}, nil) - } - return wrapInt64ValueObserverInstrument( - m.newAsync(name, ValueObserverInstrumentKind, number.Int64Kind, opts, - newInt64AsyncRunner(callback))) -} - -// NewFloat64ValueObserver creates a new floating point ValueObserver with -// the given name, running a given callback, and customized with -// options. May return an error if the name is invalid (e.g., empty) -// or improperly registered (e.g., duplicate registration). -func (m Meter) NewFloat64ValueObserver(name string, callback Float64ObserverFunc, opts ...InstrumentOption) (Float64ValueObserver, error) { - if callback == nil { - return wrapFloat64ValueObserverInstrument(NoopAsync{}, nil) - } - return wrapFloat64ValueObserverInstrument( - m.newAsync(name, ValueObserverInstrumentKind, number.Float64Kind, opts, - newFloat64AsyncRunner(callback))) -} - -// NewInt64SumObserver creates a new integer SumObserver instrument -// with the given name, running a given callback, and customized with -// options. May return an error if the name is invalid (e.g., empty) -// or improperly registered (e.g., duplicate registration). -func (m Meter) NewInt64SumObserver(name string, callback Int64ObserverFunc, opts ...InstrumentOption) (Int64SumObserver, error) { - if callback == nil { - return wrapInt64SumObserverInstrument(NoopAsync{}, nil) - } - return wrapInt64SumObserverInstrument( - m.newAsync(name, SumObserverInstrumentKind, number.Int64Kind, opts, - newInt64AsyncRunner(callback))) -} - -// NewFloat64SumObserver creates a new floating point SumObserver with -// the given name, running a given callback, and customized with -// options. May return an error if the name is invalid (e.g., empty) -// or improperly registered (e.g., duplicate registration). -func (m Meter) NewFloat64SumObserver(name string, callback Float64ObserverFunc, opts ...InstrumentOption) (Float64SumObserver, error) { - if callback == nil { - return wrapFloat64SumObserverInstrument(NoopAsync{}, nil) - } - return wrapFloat64SumObserverInstrument( - m.newAsync(name, SumObserverInstrumentKind, number.Float64Kind, opts, - newFloat64AsyncRunner(callback))) -} - -// NewInt64UpDownSumObserver creates a new integer UpDownSumObserver instrument -// with the given name, running a given callback, and customized with -// options. May return an error if the name is invalid (e.g., empty) -// or improperly registered (e.g., duplicate registration). -func (m Meter) NewInt64UpDownSumObserver(name string, callback Int64ObserverFunc, opts ...InstrumentOption) (Int64UpDownSumObserver, error) { - if callback == nil { - return wrapInt64UpDownSumObserverInstrument(NoopAsync{}, nil) - } - return wrapInt64UpDownSumObserverInstrument( - m.newAsync(name, UpDownSumObserverInstrumentKind, number.Int64Kind, opts, - newInt64AsyncRunner(callback))) -} - -// NewFloat64UpDownSumObserver creates a new floating point UpDownSumObserver with -// the given name, running a given callback, and customized with -// options. May return an error if the name is invalid (e.g., empty) -// or improperly registered (e.g., duplicate registration). -func (m Meter) NewFloat64UpDownSumObserver(name string, callback Float64ObserverFunc, opts ...InstrumentOption) (Float64UpDownSumObserver, error) { - if callback == nil { - return wrapFloat64UpDownSumObserverInstrument(NoopAsync{}, nil) - } - return wrapFloat64UpDownSumObserverInstrument( - m.newAsync(name, UpDownSumObserverInstrumentKind, number.Float64Kind, opts, - newFloat64AsyncRunner(callback))) -} - -// NewInt64ValueObserver creates a new integer ValueObserver instrument -// with the given name, running in a batch callback, and customized with -// options. May return an error if the name is invalid (e.g., empty) -// or improperly registered (e.g., duplicate registration). -func (b BatchObserver) NewInt64ValueObserver(name string, opts ...InstrumentOption) (Int64ValueObserver, error) { - if b.runner == nil { - return wrapInt64ValueObserverInstrument(NoopAsync{}, nil) - } - return wrapInt64ValueObserverInstrument( - b.meter.newAsync(name, ValueObserverInstrumentKind, number.Int64Kind, opts, b.runner)) -} - -// NewFloat64ValueObserver creates a new floating point ValueObserver with -// the given name, running in a batch callback, and customized with -// options. May return an error if the name is invalid (e.g., empty) -// or improperly registered (e.g., duplicate registration). -func (b BatchObserver) NewFloat64ValueObserver(name string, opts ...InstrumentOption) (Float64ValueObserver, error) { - if b.runner == nil { - return wrapFloat64ValueObserverInstrument(NoopAsync{}, nil) - } - return wrapFloat64ValueObserverInstrument( - b.meter.newAsync(name, ValueObserverInstrumentKind, number.Float64Kind, opts, - b.runner)) -} - -// NewInt64SumObserver creates a new integer SumObserver instrument -// with the given name, running in a batch callback, and customized with -// options. May return an error if the name is invalid (e.g., empty) -// or improperly registered (e.g., duplicate registration). -func (b BatchObserver) NewInt64SumObserver(name string, opts ...InstrumentOption) (Int64SumObserver, error) { - if b.runner == nil { - return wrapInt64SumObserverInstrument(NoopAsync{}, nil) - } - return wrapInt64SumObserverInstrument( - b.meter.newAsync(name, SumObserverInstrumentKind, number.Int64Kind, opts, b.runner)) -} - -// NewFloat64SumObserver creates a new floating point SumObserver with -// the given name, running in a batch callback, and customized with -// options. May return an error if the name is invalid (e.g., empty) -// or improperly registered (e.g., duplicate registration). -func (b BatchObserver) NewFloat64SumObserver(name string, opts ...InstrumentOption) (Float64SumObserver, error) { - if b.runner == nil { - return wrapFloat64SumObserverInstrument(NoopAsync{}, nil) - } - return wrapFloat64SumObserverInstrument( - b.meter.newAsync(name, SumObserverInstrumentKind, number.Float64Kind, opts, - b.runner)) -} - -// NewInt64UpDownSumObserver creates a new integer UpDownSumObserver instrument -// with the given name, running in a batch callback, and customized with -// options. May return an error if the name is invalid (e.g., empty) -// or improperly registered (e.g., duplicate registration). -func (b BatchObserver) NewInt64UpDownSumObserver(name string, opts ...InstrumentOption) (Int64UpDownSumObserver, error) { - if b.runner == nil { - return wrapInt64UpDownSumObserverInstrument(NoopAsync{}, nil) - } - return wrapInt64UpDownSumObserverInstrument( - b.meter.newAsync(name, UpDownSumObserverInstrumentKind, number.Int64Kind, opts, b.runner)) -} - -// NewFloat64UpDownSumObserver creates a new floating point UpDownSumObserver with -// the given name, running in a batch callback, and customized with -// options. May return an error if the name is invalid (e.g., empty) -// or improperly registered (e.g., duplicate registration). -func (b BatchObserver) NewFloat64UpDownSumObserver(name string, opts ...InstrumentOption) (Float64UpDownSumObserver, error) { - if b.runner == nil { - return wrapFloat64UpDownSumObserverInstrument(NoopAsync{}, nil) - } - return wrapFloat64UpDownSumObserverInstrument( - b.meter.newAsync(name, UpDownSumObserverInstrumentKind, number.Float64Kind, opts, - b.runner)) -} - -// MeterImpl returns the underlying MeterImpl of this Meter. -func (m Meter) MeterImpl() MeterImpl { - return m.impl -} - -// newAsync constructs one new asynchronous instrument. -func (m Meter) newAsync( - name string, - mkind InstrumentKind, - nkind number.Kind, - opts []InstrumentOption, - runner AsyncRunner, -) ( - AsyncImpl, - error, -) { - if m.impl == nil { - return NoopAsync{}, nil - } - desc := NewDescriptor(name, mkind, nkind, opts...) - desc.config.InstrumentationName = m.name - desc.config.InstrumentationVersion = m.version - return m.impl.NewAsyncInstrument(desc, runner) -} - -// newSync constructs one new synchronous instrument. -func (m Meter) newSync( - name string, - metricKind InstrumentKind, - numberKind number.Kind, - opts []InstrumentOption, -) ( - SyncImpl, - error, -) { - if m.impl == nil { - return NoopSync{}, nil - } - desc := NewDescriptor(name, metricKind, numberKind, opts...) - desc.config.InstrumentationName = m.name - desc.config.InstrumentationVersion = m.version - return m.impl.NewSyncInstrument(desc) -} - -// MeterMust is a wrapper for Meter interfaces that panics when any -// instrument constructor encounters an error. -type MeterMust struct { - meter Meter -} - -// BatchObserverMust is a wrapper for BatchObserver that panics when -// any instrument constructor encounters an error. -type BatchObserverMust struct { - batch BatchObserver -} - -// Must constructs a MeterMust implementation from a Meter, allowing -// the application to panic when any instrument constructor yields an -// error. -func Must(meter Meter) MeterMust { - return MeterMust{meter: meter} -} - -// NewInt64Counter calls `Meter.NewInt64Counter` and returns the -// instrument, panicking if it encounters an error. -func (mm MeterMust) NewInt64Counter(name string, cos ...InstrumentOption) Int64Counter { - if inst, err := mm.meter.NewInt64Counter(name, cos...); err != nil { - panic(err) - } else { - return inst - } -} - -// NewFloat64Counter calls `Meter.NewFloat64Counter` and returns the -// instrument, panicking if it encounters an error. -func (mm MeterMust) NewFloat64Counter(name string, cos ...InstrumentOption) Float64Counter { - if inst, err := mm.meter.NewFloat64Counter(name, cos...); err != nil { - panic(err) - } else { - return inst - } -} - -// NewInt64UpDownCounter calls `Meter.NewInt64UpDownCounter` and returns the -// instrument, panicking if it encounters an error. -func (mm MeterMust) NewInt64UpDownCounter(name string, cos ...InstrumentOption) Int64UpDownCounter { - if inst, err := mm.meter.NewInt64UpDownCounter(name, cos...); err != nil { - panic(err) - } else { - return inst - } -} - -// NewFloat64UpDownCounter calls `Meter.NewFloat64UpDownCounter` and returns the -// instrument, panicking if it encounters an error. -func (mm MeterMust) NewFloat64UpDownCounter(name string, cos ...InstrumentOption) Float64UpDownCounter { - if inst, err := mm.meter.NewFloat64UpDownCounter(name, cos...); err != nil { - panic(err) - } else { - return inst - } -} - -// NewInt64ValueRecorder calls `Meter.NewInt64ValueRecorder` and returns the -// instrument, panicking if it encounters an error. -func (mm MeterMust) NewInt64ValueRecorder(name string, mos ...InstrumentOption) Int64ValueRecorder { - if inst, err := mm.meter.NewInt64ValueRecorder(name, mos...); err != nil { - panic(err) - } else { - return inst - } -} - -// NewFloat64ValueRecorder calls `Meter.NewFloat64ValueRecorder` and returns the -// instrument, panicking if it encounters an error. -func (mm MeterMust) NewFloat64ValueRecorder(name string, mos ...InstrumentOption) Float64ValueRecorder { - if inst, err := mm.meter.NewFloat64ValueRecorder(name, mos...); err != nil { - panic(err) - } else { - return inst - } -} - -// NewInt64ValueObserver calls `Meter.NewInt64ValueObserver` and -// returns the instrument, panicking if it encounters an error. -func (mm MeterMust) NewInt64ValueObserver(name string, callback Int64ObserverFunc, oos ...InstrumentOption) Int64ValueObserver { - if inst, err := mm.meter.NewInt64ValueObserver(name, callback, oos...); err != nil { - panic(err) - } else { - return inst - } -} - -// NewFloat64ValueObserver calls `Meter.NewFloat64ValueObserver` and -// returns the instrument, panicking if it encounters an error. -func (mm MeterMust) NewFloat64ValueObserver(name string, callback Float64ObserverFunc, oos ...InstrumentOption) Float64ValueObserver { - if inst, err := mm.meter.NewFloat64ValueObserver(name, callback, oos...); err != nil { - panic(err) - } else { - return inst - } -} - -// NewInt64SumObserver calls `Meter.NewInt64SumObserver` and -// returns the instrument, panicking if it encounters an error. -func (mm MeterMust) NewInt64SumObserver(name string, callback Int64ObserverFunc, oos ...InstrumentOption) Int64SumObserver { - if inst, err := mm.meter.NewInt64SumObserver(name, callback, oos...); err != nil { - panic(err) - } else { - return inst - } -} - -// NewFloat64SumObserver calls `Meter.NewFloat64SumObserver` and -// returns the instrument, panicking if it encounters an error. -func (mm MeterMust) NewFloat64SumObserver(name string, callback Float64ObserverFunc, oos ...InstrumentOption) Float64SumObserver { - if inst, err := mm.meter.NewFloat64SumObserver(name, callback, oos...); err != nil { - panic(err) - } else { - return inst - } -} - -// NewInt64UpDownSumObserver calls `Meter.NewInt64UpDownSumObserver` and -// returns the instrument, panicking if it encounters an error. -func (mm MeterMust) NewInt64UpDownSumObserver(name string, callback Int64ObserverFunc, oos ...InstrumentOption) Int64UpDownSumObserver { - if inst, err := mm.meter.NewInt64UpDownSumObserver(name, callback, oos...); err != nil { - panic(err) - } else { - return inst - } -} - -// NewFloat64UpDownSumObserver calls `Meter.NewFloat64UpDownSumObserver` and -// returns the instrument, panicking if it encounters an error. -func (mm MeterMust) NewFloat64UpDownSumObserver(name string, callback Float64ObserverFunc, oos ...InstrumentOption) Float64UpDownSumObserver { - if inst, err := mm.meter.NewFloat64UpDownSumObserver(name, callback, oos...); err != nil { - panic(err) - } else { - return inst - } -} - -// NewBatchObserver returns a wrapper around BatchObserver that panics -// when any instrument constructor returns an error. -func (mm MeterMust) NewBatchObserver(callback BatchObserverFunc) BatchObserverMust { - return BatchObserverMust{ - batch: mm.meter.NewBatchObserver(callback), - } -} - -// NewInt64ValueObserver calls `BatchObserver.NewInt64ValueObserver` and -// returns the instrument, panicking if it encounters an error. -func (bm BatchObserverMust) NewInt64ValueObserver(name string, oos ...InstrumentOption) Int64ValueObserver { - if inst, err := bm.batch.NewInt64ValueObserver(name, oos...); err != nil { - panic(err) - } else { - return inst - } -} - -// NewFloat64ValueObserver calls `BatchObserver.NewFloat64ValueObserver` and -// returns the instrument, panicking if it encounters an error. -func (bm BatchObserverMust) NewFloat64ValueObserver(name string, oos ...InstrumentOption) Float64ValueObserver { - if inst, err := bm.batch.NewFloat64ValueObserver(name, oos...); err != nil { - panic(err) - } else { - return inst - } -} - -// NewInt64SumObserver calls `BatchObserver.NewInt64SumObserver` and -// returns the instrument, panicking if it encounters an error. -func (bm BatchObserverMust) NewInt64SumObserver(name string, oos ...InstrumentOption) Int64SumObserver { - if inst, err := bm.batch.NewInt64SumObserver(name, oos...); err != nil { - panic(err) - } else { - return inst - } -} - -// NewFloat64SumObserver calls `BatchObserver.NewFloat64SumObserver` and -// returns the instrument, panicking if it encounters an error. -func (bm BatchObserverMust) NewFloat64SumObserver(name string, oos ...InstrumentOption) Float64SumObserver { - if inst, err := bm.batch.NewFloat64SumObserver(name, oos...); err != nil { - panic(err) - } else { - return inst - } -} - -// NewInt64UpDownSumObserver calls `BatchObserver.NewInt64UpDownSumObserver` and -// returns the instrument, panicking if it encounters an error. -func (bm BatchObserverMust) NewInt64UpDownSumObserver(name string, oos ...InstrumentOption) Int64UpDownSumObserver { - if inst, err := bm.batch.NewInt64UpDownSumObserver(name, oos...); err != nil { - panic(err) - } else { - return inst - } -} - -// NewFloat64UpDownSumObserver calls `BatchObserver.NewFloat64UpDownSumObserver` and -// returns the instrument, panicking if it encounters an error. -func (bm BatchObserverMust) NewFloat64UpDownSumObserver(name string, oos ...InstrumentOption) Float64UpDownSumObserver { - if inst, err := bm.batch.NewFloat64UpDownSumObserver(name, oos...); err != nil { - panic(err) - } else { - return inst - } -} - -// Descriptor contains all the settings that describe an instrument, -// including its name, metric kind, number kind, and the configurable -// options. -type Descriptor struct { - name string - instrumentKind InstrumentKind - numberKind number.Kind - config InstrumentConfig -} - -// NewDescriptor returns a Descriptor with the given contents. -func NewDescriptor(name string, ikind InstrumentKind, nkind number.Kind, opts ...InstrumentOption) Descriptor { - return Descriptor{ - name: name, - instrumentKind: ikind, - numberKind: nkind, - config: NewInstrumentConfig(opts...), - } -} - -// Name returns the metric instrument's name. -func (d Descriptor) Name() string { - return d.name -} - -// InstrumentKind returns the specific kind of instrument. -func (d Descriptor) InstrumentKind() InstrumentKind { - return d.instrumentKind -} - -// Description provides a human-readable description of the metric -// instrument. -func (d Descriptor) Description() string { - return d.config.Description -} - -// Unit describes the units of the metric instrument. Unitless -// metrics return the empty string. -func (d Descriptor) Unit() unit.Unit { - return d.config.Unit -} - -// NumberKind returns whether this instrument is declared over int64, -// float64, or uint64 values. -func (d Descriptor) NumberKind() number.Kind { - return d.numberKind -} - -// InstrumentationName returns the name of the library that provided -// instrumentation for this instrument. -func (d Descriptor) InstrumentationName() string { - return d.config.InstrumentationName -} - -// InstrumentationVersion returns the version of the library that provided -// instrumentation for this instrument. -func (d Descriptor) InstrumentationVersion() string { - return d.config.InstrumentationVersion -} diff --git a/vendor/go.opentelemetry.io/otel/metric/metric_instrument.go b/vendor/go.opentelemetry.io/otel/metric/metric_instrument.go deleted file mode 100644 index 6f3fc997cb..0000000000 --- a/vendor/go.opentelemetry.io/otel/metric/metric_instrument.go +++ /dev/null @@ -1,777 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -//go:generate stringer -type=InstrumentKind - -package metric // import "go.opentelemetry.io/otel/metric" - -import ( - "context" - "errors" - - "go.opentelemetry.io/otel/attribute" - "go.opentelemetry.io/otel/metric/number" -) - -// ErrSDKReturnedNilImpl is returned when a new `MeterImpl` returns nil. -var ErrSDKReturnedNilImpl = errors.New("SDK returned a nil implementation") - -// InstrumentKind describes the kind of instrument. -type InstrumentKind int8 - -const ( - // ValueRecorderInstrumentKind indicates a ValueRecorder instrument. - ValueRecorderInstrumentKind InstrumentKind = iota - // ValueObserverInstrumentKind indicates an ValueObserver instrument. - ValueObserverInstrumentKind - - // CounterInstrumentKind indicates a Counter instrument. - CounterInstrumentKind - // UpDownCounterInstrumentKind indicates a UpDownCounter instrument. - UpDownCounterInstrumentKind - - // SumObserverInstrumentKind indicates a SumObserver instrument. - SumObserverInstrumentKind - // UpDownSumObserverInstrumentKind indicates a UpDownSumObserver - // instrument. - UpDownSumObserverInstrumentKind -) - -// Synchronous returns whether this is a synchronous kind of instrument. -func (k InstrumentKind) Synchronous() bool { - switch k { - case CounterInstrumentKind, UpDownCounterInstrumentKind, ValueRecorderInstrumentKind: - return true - } - return false -} - -// Asynchronous returns whether this is an asynchronous kind of instrument. -func (k InstrumentKind) Asynchronous() bool { - return !k.Synchronous() -} - -// Adding returns whether this kind of instrument adds its inputs (as opposed to Grouping). -func (k InstrumentKind) Adding() bool { - switch k { - case CounterInstrumentKind, UpDownCounterInstrumentKind, SumObserverInstrumentKind, UpDownSumObserverInstrumentKind: - return true - } - return false -} - -// Grouping returns whether this kind of instrument groups its inputs (as opposed to Adding). -func (k InstrumentKind) Grouping() bool { - return !k.Adding() -} - -// Monotonic returns whether this kind of instrument exposes a non-decreasing sum. -func (k InstrumentKind) Monotonic() bool { - switch k { - case CounterInstrumentKind, SumObserverInstrumentKind: - return true - } - return false -} - -// PrecomputedSum returns whether this kind of instrument receives precomputed sums. -func (k InstrumentKind) PrecomputedSum() bool { - return k.Adding() && k.Asynchronous() -} - -// Observation is used for reporting an asynchronous batch of metric -// values. Instances of this type should be created by asynchronous -// instruments (e.g., Int64ValueObserver.Observation()). -type Observation struct { - // number needs to be aligned for 64-bit atomic operations. - number number.Number - instrument AsyncImpl -} - -// Int64ObserverFunc is a type of callback that integral -// observers run. -type Int64ObserverFunc func(context.Context, Int64ObserverResult) - -// Float64ObserverFunc is a type of callback that floating point -// observers run. -type Float64ObserverFunc func(context.Context, Float64ObserverResult) - -// BatchObserverFunc is a callback argument for use with any -// Observer instrument that will be reported as a batch of -// observations. -type BatchObserverFunc func(context.Context, BatchObserverResult) - -// Int64ObserverResult is passed to an observer callback to capture -// observations for one asynchronous integer metric instrument. -type Int64ObserverResult struct { - instrument AsyncImpl - function func([]attribute.KeyValue, ...Observation) -} - -// Float64ObserverResult is passed to an observer callback to capture -// observations for one asynchronous floating point metric instrument. -type Float64ObserverResult struct { - instrument AsyncImpl - function func([]attribute.KeyValue, ...Observation) -} - -// BatchObserverResult is passed to a batch observer callback to -// capture observations for multiple asynchronous instruments. -type BatchObserverResult struct { - function func([]attribute.KeyValue, ...Observation) -} - -// Observe captures a single integer value from the associated -// instrument callback, with the given labels. -func (ir Int64ObserverResult) Observe(value int64, labels ...attribute.KeyValue) { - ir.function(labels, Observation{ - instrument: ir.instrument, - number: number.NewInt64Number(value), - }) -} - -// Observe captures a single floating point value from the associated -// instrument callback, with the given labels. -func (fr Float64ObserverResult) Observe(value float64, labels ...attribute.KeyValue) { - fr.function(labels, Observation{ - instrument: fr.instrument, - number: number.NewFloat64Number(value), - }) -} - -// Observe captures a multiple observations from the associated batch -// instrument callback, with the given labels. -func (br BatchObserverResult) Observe(labels []attribute.KeyValue, obs ...Observation) { - br.function(labels, obs...) -} - -// AsyncRunner is expected to convert into an AsyncSingleRunner or an -// AsyncBatchRunner. SDKs will encounter an error if the AsyncRunner -// does not satisfy one of these interfaces. -type AsyncRunner interface { - // AnyRunner() is a non-exported method with no functional use - // other than to make this a non-empty interface. - AnyRunner() -} - -// AsyncSingleRunner is an interface implemented by single-observer -// callbacks. -type AsyncSingleRunner interface { - // Run accepts a single instrument and function for capturing - // observations of that instrument. Each call to the function - // receives one captured observation. (The function accepts - // multiple observations so the same implementation can be - // used for batch runners.) - Run(ctx context.Context, single AsyncImpl, capture func([]attribute.KeyValue, ...Observation)) - - AsyncRunner -} - -// AsyncBatchRunner is an interface implemented by batch-observer -// callbacks. -type AsyncBatchRunner interface { - // Run accepts a function for capturing observations of - // multiple instruments. - Run(ctx context.Context, capture func([]attribute.KeyValue, ...Observation)) - - AsyncRunner -} - -var _ AsyncSingleRunner = (*Int64ObserverFunc)(nil) -var _ AsyncSingleRunner = (*Float64ObserverFunc)(nil) -var _ AsyncBatchRunner = (*BatchObserverFunc)(nil) - -// newInt64AsyncRunner returns a single-observer callback for integer Observer instruments. -func newInt64AsyncRunner(c Int64ObserverFunc) AsyncSingleRunner { - return &c -} - -// newFloat64AsyncRunner returns a single-observer callback for floating point Observer instruments. -func newFloat64AsyncRunner(c Float64ObserverFunc) AsyncSingleRunner { - return &c -} - -// newBatchAsyncRunner returns a batch-observer callback use with multiple Observer instruments. -func newBatchAsyncRunner(c BatchObserverFunc) AsyncBatchRunner { - return &c -} - -// AnyRunner implements AsyncRunner. -func (*Int64ObserverFunc) AnyRunner() {} - -// AnyRunner implements AsyncRunner. -func (*Float64ObserverFunc) AnyRunner() {} - -// AnyRunner implements AsyncRunner. -func (*BatchObserverFunc) AnyRunner() {} - -// Run implements AsyncSingleRunner. -func (i *Int64ObserverFunc) Run(ctx context.Context, impl AsyncImpl, function func([]attribute.KeyValue, ...Observation)) { - (*i)(ctx, Int64ObserverResult{ - instrument: impl, - function: function, - }) -} - -// Run implements AsyncSingleRunner. -func (f *Float64ObserverFunc) Run(ctx context.Context, impl AsyncImpl, function func([]attribute.KeyValue, ...Observation)) { - (*f)(ctx, Float64ObserverResult{ - instrument: impl, - function: function, - }) -} - -// Run implements AsyncBatchRunner. -func (b *BatchObserverFunc) Run(ctx context.Context, function func([]attribute.KeyValue, ...Observation)) { - (*b)(ctx, BatchObserverResult{ - function: function, - }) -} - -// wrapInt64ValueObserverInstrument converts an AsyncImpl into Int64ValueObserver. -func wrapInt64ValueObserverInstrument(asyncInst AsyncImpl, err error) (Int64ValueObserver, error) { - common, err := checkNewAsync(asyncInst, err) - return Int64ValueObserver{asyncInstrument: common}, err -} - -// wrapFloat64ValueObserverInstrument converts an AsyncImpl into Float64ValueObserver. -func wrapFloat64ValueObserverInstrument(asyncInst AsyncImpl, err error) (Float64ValueObserver, error) { - common, err := checkNewAsync(asyncInst, err) - return Float64ValueObserver{asyncInstrument: common}, err -} - -// wrapInt64SumObserverInstrument converts an AsyncImpl into Int64SumObserver. -func wrapInt64SumObserverInstrument(asyncInst AsyncImpl, err error) (Int64SumObserver, error) { - common, err := checkNewAsync(asyncInst, err) - return Int64SumObserver{asyncInstrument: common}, err -} - -// wrapFloat64SumObserverInstrument converts an AsyncImpl into Float64SumObserver. -func wrapFloat64SumObserverInstrument(asyncInst AsyncImpl, err error) (Float64SumObserver, error) { - common, err := checkNewAsync(asyncInst, err) - return Float64SumObserver{asyncInstrument: common}, err -} - -// wrapInt64UpDownSumObserverInstrument converts an AsyncImpl into Int64UpDownSumObserver. -func wrapInt64UpDownSumObserverInstrument(asyncInst AsyncImpl, err error) (Int64UpDownSumObserver, error) { - common, err := checkNewAsync(asyncInst, err) - return Int64UpDownSumObserver{asyncInstrument: common}, err -} - -// wrapFloat64UpDownSumObserverInstrument converts an AsyncImpl into Float64UpDownSumObserver. -func wrapFloat64UpDownSumObserverInstrument(asyncInst AsyncImpl, err error) (Float64UpDownSumObserver, error) { - common, err := checkNewAsync(asyncInst, err) - return Float64UpDownSumObserver{asyncInstrument: common}, err -} - -// BatchObserver represents an Observer callback that can report -// observations for multiple instruments. -type BatchObserver struct { - meter Meter - runner AsyncBatchRunner -} - -// Int64ValueObserver is a metric that captures a set of int64 values at a -// point in time. -type Int64ValueObserver struct { - asyncInstrument -} - -// Float64ValueObserver is a metric that captures a set of float64 values -// at a point in time. -type Float64ValueObserver struct { - asyncInstrument -} - -// Int64SumObserver is a metric that captures a precomputed sum of -// int64 values at a point in time. -type Int64SumObserver struct { - asyncInstrument -} - -// Float64SumObserver is a metric that captures a precomputed sum of -// float64 values at a point in time. -type Float64SumObserver struct { - asyncInstrument -} - -// Int64UpDownSumObserver is a metric that captures a precomputed sum of -// int64 values at a point in time. -type Int64UpDownSumObserver struct { - asyncInstrument -} - -// Float64UpDownSumObserver is a metric that captures a precomputed sum of -// float64 values at a point in time. -type Float64UpDownSumObserver struct { - asyncInstrument -} - -// Observation returns an Observation, a BatchObserverFunc -// argument, for an asynchronous integer instrument. -// This returns an implementation-level object for use by the SDK, -// users should not refer to this. -func (i Int64ValueObserver) Observation(v int64) Observation { - return Observation{ - number: number.NewInt64Number(v), - instrument: i.instrument, - } -} - -// Observation returns an Observation, a BatchObserverFunc -// argument, for an asynchronous integer instrument. -// This returns an implementation-level object for use by the SDK, -// users should not refer to this. -func (f Float64ValueObserver) Observation(v float64) Observation { - return Observation{ - number: number.NewFloat64Number(v), - instrument: f.instrument, - } -} - -// Observation returns an Observation, a BatchObserverFunc -// argument, for an asynchronous integer instrument. -// This returns an implementation-level object for use by the SDK, -// users should not refer to this. -func (i Int64SumObserver) Observation(v int64) Observation { - return Observation{ - number: number.NewInt64Number(v), - instrument: i.instrument, - } -} - -// Observation returns an Observation, a BatchObserverFunc -// argument, for an asynchronous integer instrument. -// This returns an implementation-level object for use by the SDK, -// users should not refer to this. -func (f Float64SumObserver) Observation(v float64) Observation { - return Observation{ - number: number.NewFloat64Number(v), - instrument: f.instrument, - } -} - -// Observation returns an Observation, a BatchObserverFunc -// argument, for an asynchronous integer instrument. -// This returns an implementation-level object for use by the SDK, -// users should not refer to this. -func (i Int64UpDownSumObserver) Observation(v int64) Observation { - return Observation{ - number: number.NewInt64Number(v), - instrument: i.instrument, - } -} - -// Observation returns an Observation, a BatchObserverFunc -// argument, for an asynchronous integer instrument. -// This returns an implementation-level object for use by the SDK, -// users should not refer to this. -func (f Float64UpDownSumObserver) Observation(v float64) Observation { - return Observation{ - number: number.NewFloat64Number(v), - instrument: f.instrument, - } -} - -// Measurement is used for reporting a synchronous batch of metric -// values. Instances of this type should be created by synchronous -// instruments (e.g., Int64Counter.Measurement()). -type Measurement struct { - // number needs to be aligned for 64-bit atomic operations. - number number.Number - instrument SyncImpl -} - -// syncInstrument contains a SyncImpl. -type syncInstrument struct { - instrument SyncImpl -} - -// syncBoundInstrument contains a BoundSyncImpl. -type syncBoundInstrument struct { - boundInstrument BoundSyncImpl -} - -// asyncInstrument contains a AsyncImpl. -type asyncInstrument struct { - instrument AsyncImpl -} - -// SyncImpl returns the instrument that created this measurement. -// This returns an implementation-level object for use by the SDK, -// users should not refer to this. -func (m Measurement) SyncImpl() SyncImpl { - return m.instrument -} - -// Number returns a number recorded in this measurement. -func (m Measurement) Number() number.Number { - return m.number -} - -// AsyncImpl returns the instrument that created this observation. -// This returns an implementation-level object for use by the SDK, -// users should not refer to this. -func (m Observation) AsyncImpl() AsyncImpl { - return m.instrument -} - -// Number returns a number recorded in this observation. -func (m Observation) Number() number.Number { - return m.number -} - -// AsyncImpl implements AsyncImpl. -func (a asyncInstrument) AsyncImpl() AsyncImpl { - return a.instrument -} - -// SyncImpl returns the implementation object for synchronous instruments. -func (s syncInstrument) SyncImpl() SyncImpl { - return s.instrument -} - -func (s syncInstrument) bind(labels []attribute.KeyValue) syncBoundInstrument { - return newSyncBoundInstrument(s.instrument.Bind(labels)) -} - -func (s syncInstrument) float64Measurement(value float64) Measurement { - return newMeasurement(s.instrument, number.NewFloat64Number(value)) -} - -func (s syncInstrument) int64Measurement(value int64) Measurement { - return newMeasurement(s.instrument, number.NewInt64Number(value)) -} - -func (s syncInstrument) directRecord(ctx context.Context, number number.Number, labels []attribute.KeyValue) { - s.instrument.RecordOne(ctx, number, labels) -} - -func (h syncBoundInstrument) directRecord(ctx context.Context, number number.Number) { - h.boundInstrument.RecordOne(ctx, number) -} - -// Unbind calls SyncImpl.Unbind. -func (h syncBoundInstrument) Unbind() { - h.boundInstrument.Unbind() -} - -// checkNewAsync receives an AsyncImpl and potential -// error, and returns the same types, checking for and ensuring that -// the returned interface is not nil. -func checkNewAsync(instrument AsyncImpl, err error) (asyncInstrument, error) { - if instrument == nil { - if err == nil { - err = ErrSDKReturnedNilImpl - } - instrument = NoopAsync{} - } - return asyncInstrument{ - instrument: instrument, - }, err -} - -// checkNewSync receives an SyncImpl and potential -// error, and returns the same types, checking for and ensuring that -// the returned interface is not nil. -func checkNewSync(instrument SyncImpl, err error) (syncInstrument, error) { - if instrument == nil { - if err == nil { - err = ErrSDKReturnedNilImpl - } - // Note: an alternate behavior would be to synthesize a new name - // or group all duplicately-named instruments of a certain type - // together and use a tag for the original name, e.g., - // name = 'invalid.counter.int64' - // label = 'original-name=duplicate-counter-name' - instrument = NoopSync{} - } - return syncInstrument{ - instrument: instrument, - }, err -} - -func newSyncBoundInstrument(boundInstrument BoundSyncImpl) syncBoundInstrument { - return syncBoundInstrument{ - boundInstrument: boundInstrument, - } -} - -func newMeasurement(instrument SyncImpl, number number.Number) Measurement { - return Measurement{ - instrument: instrument, - number: number, - } -} - -// wrapInt64CounterInstrument converts a SyncImpl into Int64Counter. -func wrapInt64CounterInstrument(syncInst SyncImpl, err error) (Int64Counter, error) { - common, err := checkNewSync(syncInst, err) - return Int64Counter{syncInstrument: common}, err -} - -// wrapFloat64CounterInstrument converts a SyncImpl into Float64Counter. -func wrapFloat64CounterInstrument(syncInst SyncImpl, err error) (Float64Counter, error) { - common, err := checkNewSync(syncInst, err) - return Float64Counter{syncInstrument: common}, err -} - -// wrapInt64UpDownCounterInstrument converts a SyncImpl into Int64UpDownCounter. -func wrapInt64UpDownCounterInstrument(syncInst SyncImpl, err error) (Int64UpDownCounter, error) { - common, err := checkNewSync(syncInst, err) - return Int64UpDownCounter{syncInstrument: common}, err -} - -// wrapFloat64UpDownCounterInstrument converts a SyncImpl into Float64UpDownCounter. -func wrapFloat64UpDownCounterInstrument(syncInst SyncImpl, err error) (Float64UpDownCounter, error) { - common, err := checkNewSync(syncInst, err) - return Float64UpDownCounter{syncInstrument: common}, err -} - -// wrapInt64ValueRecorderInstrument converts a SyncImpl into Int64ValueRecorder. -func wrapInt64ValueRecorderInstrument(syncInst SyncImpl, err error) (Int64ValueRecorder, error) { - common, err := checkNewSync(syncInst, err) - return Int64ValueRecorder{syncInstrument: common}, err -} - -// wrapFloat64ValueRecorderInstrument converts a SyncImpl into Float64ValueRecorder. -func wrapFloat64ValueRecorderInstrument(syncInst SyncImpl, err error) (Float64ValueRecorder, error) { - common, err := checkNewSync(syncInst, err) - return Float64ValueRecorder{syncInstrument: common}, err -} - -// Float64Counter is a metric that accumulates float64 values. -type Float64Counter struct { - syncInstrument -} - -// Int64Counter is a metric that accumulates int64 values. -type Int64Counter struct { - syncInstrument -} - -// BoundFloat64Counter is a bound instrument for Float64Counter. -// -// It inherits the Unbind function from syncBoundInstrument. -type BoundFloat64Counter struct { - syncBoundInstrument -} - -// BoundInt64Counter is a boundInstrument for Int64Counter. -// -// It inherits the Unbind function from syncBoundInstrument. -type BoundInt64Counter struct { - syncBoundInstrument -} - -// Bind creates a bound instrument for this counter. The labels are -// associated with values recorded via subsequent calls to Record. -func (c Float64Counter) Bind(labels ...attribute.KeyValue) (h BoundFloat64Counter) { - h.syncBoundInstrument = c.bind(labels) - return -} - -// Bind creates a bound instrument for this counter. The labels are -// associated with values recorded via subsequent calls to Record. -func (c Int64Counter) Bind(labels ...attribute.KeyValue) (h BoundInt64Counter) { - h.syncBoundInstrument = c.bind(labels) - return -} - -// Measurement creates a Measurement object to use with batch -// recording. -func (c Float64Counter) Measurement(value float64) Measurement { - return c.float64Measurement(value) -} - -// Measurement creates a Measurement object to use with batch -// recording. -func (c Int64Counter) Measurement(value int64) Measurement { - return c.int64Measurement(value) -} - -// Add adds the value to the counter's sum. The labels should contain -// the keys and values to be associated with this value. -func (c Float64Counter) Add(ctx context.Context, value float64, labels ...attribute.KeyValue) { - c.directRecord(ctx, number.NewFloat64Number(value), labels) -} - -// Add adds the value to the counter's sum. The labels should contain -// the keys and values to be associated with this value. -func (c Int64Counter) Add(ctx context.Context, value int64, labels ...attribute.KeyValue) { - c.directRecord(ctx, number.NewInt64Number(value), labels) -} - -// Add adds the value to the counter's sum using the labels -// previously bound to this counter via Bind() -func (b BoundFloat64Counter) Add(ctx context.Context, value float64) { - b.directRecord(ctx, number.NewFloat64Number(value)) -} - -// Add adds the value to the counter's sum using the labels -// previously bound to this counter via Bind() -func (b BoundInt64Counter) Add(ctx context.Context, value int64) { - b.directRecord(ctx, number.NewInt64Number(value)) -} - -// Float64UpDownCounter is a metric instrument that sums floating -// point values. -type Float64UpDownCounter struct { - syncInstrument -} - -// Int64UpDownCounter is a metric instrument that sums integer values. -type Int64UpDownCounter struct { - syncInstrument -} - -// BoundFloat64UpDownCounter is a bound instrument for Float64UpDownCounter. -// -// It inherits the Unbind function from syncBoundInstrument. -type BoundFloat64UpDownCounter struct { - syncBoundInstrument -} - -// BoundInt64UpDownCounter is a boundInstrument for Int64UpDownCounter. -// -// It inherits the Unbind function from syncBoundInstrument. -type BoundInt64UpDownCounter struct { - syncBoundInstrument -} - -// Bind creates a bound instrument for this counter. The labels are -// associated with values recorded via subsequent calls to Record. -func (c Float64UpDownCounter) Bind(labels ...attribute.KeyValue) (h BoundFloat64UpDownCounter) { - h.syncBoundInstrument = c.bind(labels) - return -} - -// Bind creates a bound instrument for this counter. The labels are -// associated with values recorded via subsequent calls to Record. -func (c Int64UpDownCounter) Bind(labels ...attribute.KeyValue) (h BoundInt64UpDownCounter) { - h.syncBoundInstrument = c.bind(labels) - return -} - -// Measurement creates a Measurement object to use with batch -// recording. -func (c Float64UpDownCounter) Measurement(value float64) Measurement { - return c.float64Measurement(value) -} - -// Measurement creates a Measurement object to use with batch -// recording. -func (c Int64UpDownCounter) Measurement(value int64) Measurement { - return c.int64Measurement(value) -} - -// Add adds the value to the counter's sum. The labels should contain -// the keys and values to be associated with this value. -func (c Float64UpDownCounter) Add(ctx context.Context, value float64, labels ...attribute.KeyValue) { - c.directRecord(ctx, number.NewFloat64Number(value), labels) -} - -// Add adds the value to the counter's sum. The labels should contain -// the keys and values to be associated with this value. -func (c Int64UpDownCounter) Add(ctx context.Context, value int64, labels ...attribute.KeyValue) { - c.directRecord(ctx, number.NewInt64Number(value), labels) -} - -// Add adds the value to the counter's sum using the labels -// previously bound to this counter via Bind() -func (b BoundFloat64UpDownCounter) Add(ctx context.Context, value float64) { - b.directRecord(ctx, number.NewFloat64Number(value)) -} - -// Add adds the value to the counter's sum using the labels -// previously bound to this counter via Bind() -func (b BoundInt64UpDownCounter) Add(ctx context.Context, value int64) { - b.directRecord(ctx, number.NewInt64Number(value)) -} - -// Float64ValueRecorder is a metric that records float64 values. -type Float64ValueRecorder struct { - syncInstrument -} - -// Int64ValueRecorder is a metric that records int64 values. -type Int64ValueRecorder struct { - syncInstrument -} - -// BoundFloat64ValueRecorder is a bound instrument for Float64ValueRecorder. -// -// It inherits the Unbind function from syncBoundInstrument. -type BoundFloat64ValueRecorder struct { - syncBoundInstrument -} - -// BoundInt64ValueRecorder is a bound instrument for Int64ValueRecorder. -// -// It inherits the Unbind function from syncBoundInstrument. -type BoundInt64ValueRecorder struct { - syncBoundInstrument -} - -// Bind creates a bound instrument for this ValueRecorder. The labels are -// associated with values recorded via subsequent calls to Record. -func (c Float64ValueRecorder) Bind(labels ...attribute.KeyValue) (h BoundFloat64ValueRecorder) { - h.syncBoundInstrument = c.bind(labels) - return -} - -// Bind creates a bound instrument for this ValueRecorder. The labels are -// associated with values recorded via subsequent calls to Record. -func (c Int64ValueRecorder) Bind(labels ...attribute.KeyValue) (h BoundInt64ValueRecorder) { - h.syncBoundInstrument = c.bind(labels) - return -} - -// Measurement creates a Measurement object to use with batch -// recording. -func (c Float64ValueRecorder) Measurement(value float64) Measurement { - return c.float64Measurement(value) -} - -// Measurement creates a Measurement object to use with batch -// recording. -func (c Int64ValueRecorder) Measurement(value int64) Measurement { - return c.int64Measurement(value) -} - -// Record adds a new value to the list of ValueRecorder's records. The -// labels should contain the keys and values to be associated with -// this value. -func (c Float64ValueRecorder) Record(ctx context.Context, value float64, labels ...attribute.KeyValue) { - c.directRecord(ctx, number.NewFloat64Number(value), labels) -} - -// Record adds a new value to the ValueRecorder's distribution. The -// labels should contain the keys and values to be associated with -// this value. -func (c Int64ValueRecorder) Record(ctx context.Context, value int64, labels ...attribute.KeyValue) { - c.directRecord(ctx, number.NewInt64Number(value), labels) -} - -// Record adds a new value to the ValueRecorder's distribution using the labels -// previously bound to the ValueRecorder via Bind(). -func (b BoundFloat64ValueRecorder) Record(ctx context.Context, value float64) { - b.directRecord(ctx, number.NewFloat64Number(value)) -} - -// Record adds a new value to the ValueRecorder's distribution using the labels -// previously bound to the ValueRecorder via Bind(). -func (b BoundInt64ValueRecorder) Record(ctx context.Context, value int64) { - b.directRecord(ctx, number.NewInt64Number(value)) -} diff --git a/vendor/go.opentelemetry.io/otel/metric/metric_noop.go b/vendor/go.opentelemetry.io/otel/metric/metric_noop.go deleted file mode 100644 index 30e57b6945..0000000000 --- a/vendor/go.opentelemetry.io/otel/metric/metric_noop.go +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package metric // import "go.opentelemetry.io/otel/metric" - -import ( - "context" - - "go.opentelemetry.io/otel/attribute" - "go.opentelemetry.io/otel/metric/number" -) - -type NoopMeterProvider struct{} - -type noopInstrument struct{} -type noopBoundInstrument struct{} -type NoopSync struct{ noopInstrument } -type NoopAsync struct{ noopInstrument } - -var _ MeterProvider = NoopMeterProvider{} -var _ SyncImpl = NoopSync{} -var _ BoundSyncImpl = noopBoundInstrument{} -var _ AsyncImpl = NoopAsync{} - -func (NoopMeterProvider) Meter(_ string, _ ...MeterOption) Meter { - return Meter{} -} - -func (noopInstrument) Implementation() interface{} { - return nil -} - -func (noopInstrument) Descriptor() Descriptor { - return Descriptor{} -} - -func (noopBoundInstrument) RecordOne(context.Context, number.Number) { -} - -func (noopBoundInstrument) Unbind() { -} - -func (NoopSync) Bind([]attribute.KeyValue) BoundSyncImpl { - return noopBoundInstrument{} -} - -func (NoopSync) RecordOne(context.Context, number.Number, []attribute.KeyValue) { -} diff --git a/vendor/go.opentelemetry.io/otel/metric/metric_sdkapi.go b/vendor/go.opentelemetry.io/otel/metric/metric_sdkapi.go deleted file mode 100644 index 94164f7b48..0000000000 --- a/vendor/go.opentelemetry.io/otel/metric/metric_sdkapi.go +++ /dev/null @@ -1,95 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package metric // import "go.opentelemetry.io/otel/metric" - -import ( - "context" - - "go.opentelemetry.io/otel/attribute" - "go.opentelemetry.io/otel/metric/number" -) - -// MeterImpl is the interface an SDK must implement to supply a Meter -// implementation. -type MeterImpl interface { - // RecordBatch atomically records a batch of measurements. - RecordBatch(ctx context.Context, labels []attribute.KeyValue, measurement ...Measurement) - - // NewSyncInstrument returns a newly constructed - // synchronous instrument implementation or an error, should - // one occur. - NewSyncInstrument(descriptor Descriptor) (SyncImpl, error) - - // NewAsyncInstrument returns a newly constructed - // asynchronous instrument implementation or an error, should - // one occur. - NewAsyncInstrument( - descriptor Descriptor, - runner AsyncRunner, - ) (AsyncImpl, error) -} - -// InstrumentImpl is a common interface for synchronous and -// asynchronous instruments. -type InstrumentImpl interface { - // Implementation returns the underlying implementation of the - // instrument, which allows the implementation to gain access - // to its own representation especially from a `Measurement`. - Implementation() interface{} - - // Descriptor returns a copy of the instrument's Descriptor. - Descriptor() Descriptor -} - -// SyncImpl is the implementation-level interface to a generic -// synchronous instrument (e.g., ValueRecorder and Counter instruments). -type SyncImpl interface { - InstrumentImpl - - // Bind creates an implementation-level bound instrument, - // binding a label set with this instrument implementation. - Bind(labels []attribute.KeyValue) BoundSyncImpl - - // RecordOne captures a single synchronous metric event. - RecordOne(ctx context.Context, number number.Number, labels []attribute.KeyValue) -} - -// BoundSyncImpl is the implementation-level interface to a -// generic bound synchronous instrument -type BoundSyncImpl interface { - - // RecordOne captures a single synchronous metric event. - RecordOne(ctx context.Context, number number.Number) - - // Unbind frees the resources associated with this bound instrument. It - // does not affect the metric this bound instrument was created through. - Unbind() -} - -// AsyncImpl is an implementation-level interface to an -// asynchronous instrument (e.g., Observer instruments). -type AsyncImpl interface { - InstrumentImpl -} - -// WrapMeterImpl constructs a `Meter` implementation from a -// `MeterImpl` implementation. -func WrapMeterImpl(impl MeterImpl, instrumentationName string, opts ...MeterOption) Meter { - return Meter{ - impl: impl, - name: instrumentationName, - version: NewMeterConfig(opts...).InstrumentationVersion, - } -} diff --git a/vendor/go.opentelemetry.io/otel/metric/number/doc.go b/vendor/go.opentelemetry.io/otel/metric/number/doc.go deleted file mode 100644 index 0649ff875e..0000000000 --- a/vendor/go.opentelemetry.io/otel/metric/number/doc.go +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/* -Package number provides a number abstraction for instruments that -either support int64 or float64 input values. - -This package is currently in a pre-GA phase. Backwards incompatible changes -may be introduced in subsequent minor version releases as we work to track the -evolving OpenTelemetry specification and user feedback. -*/ -package number // import "go.opentelemetry.io/otel/metric/number" diff --git a/vendor/go.opentelemetry.io/otel/metric/number/kind_string.go b/vendor/go.opentelemetry.io/otel/metric/number/kind_string.go deleted file mode 100644 index 6288c7ea29..0000000000 --- a/vendor/go.opentelemetry.io/otel/metric/number/kind_string.go +++ /dev/null @@ -1,24 +0,0 @@ -// Code generated by "stringer -type=Kind"; DO NOT EDIT. - -package number - -import "strconv" - -func _() { - // An "invalid array index" compiler error signifies that the constant values have changed. - // Re-run the stringer command to generate them again. - var x [1]struct{} - _ = x[Int64Kind-0] - _ = x[Float64Kind-1] -} - -const _Kind_name = "Int64KindFloat64Kind" - -var _Kind_index = [...]uint8{0, 9, 20} - -func (i Kind) String() string { - if i < 0 || i >= Kind(len(_Kind_index)-1) { - return "Kind(" + strconv.FormatInt(int64(i), 10) + ")" - } - return _Kind_name[_Kind_index[i]:_Kind_index[i+1]] -} diff --git a/vendor/go.opentelemetry.io/otel/metric/number/number.go b/vendor/go.opentelemetry.io/otel/metric/number/number.go deleted file mode 100644 index 3ec95e2014..0000000000 --- a/vendor/go.opentelemetry.io/otel/metric/number/number.go +++ /dev/null @@ -1,538 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package number // import "go.opentelemetry.io/otel/metric/number" - -//go:generate stringer -type=Kind - -import ( - "fmt" - "math" - "sync/atomic" - - "go.opentelemetry.io/otel/internal" -) - -// Kind describes the data type of the Number. -type Kind int8 - -const ( - // Int64Kind means that the Number stores int64. - Int64Kind Kind = iota - // Float64Kind means that the Number stores float64. - Float64Kind -) - -// Zero returns a zero value for a given Kind -func (k Kind) Zero() Number { - switch k { - case Int64Kind: - return NewInt64Number(0) - case Float64Kind: - return NewFloat64Number(0.) - default: - return Number(0) - } -} - -// Minimum returns the minimum representable value -// for a given Kind -func (k Kind) Minimum() Number { - switch k { - case Int64Kind: - return NewInt64Number(math.MinInt64) - case Float64Kind: - return NewFloat64Number(-1. * math.MaxFloat64) - default: - return Number(0) - } -} - -// Maximum returns the maximum representable value -// for a given Kind -func (k Kind) Maximum() Number { - switch k { - case Int64Kind: - return NewInt64Number(math.MaxInt64) - case Float64Kind: - return NewFloat64Number(math.MaxFloat64) - default: - return Number(0) - } -} - -// Number represents either an integral or a floating point value. It -// needs to be accompanied with a source of Kind that describes -// the actual type of the value stored within Number. -type Number uint64 - -// - constructors - -// NewNumberFromRaw creates a new Number from a raw value. -func NewNumberFromRaw(r uint64) Number { - return Number(r) -} - -// NewInt64Number creates an integral Number. -func NewInt64Number(i int64) Number { - return NewNumberFromRaw(internal.Int64ToRaw(i)) -} - -// NewFloat64Number creates a floating point Number. -func NewFloat64Number(f float64) Number { - return NewNumberFromRaw(internal.Float64ToRaw(f)) -} - -// NewNumberSignChange returns a number with the same magnitude and -// the opposite sign. `kind` must describe the kind of number in `nn`. -func NewNumberSignChange(kind Kind, nn Number) Number { - switch kind { - case Int64Kind: - return NewInt64Number(-nn.AsInt64()) - case Float64Kind: - return NewFloat64Number(-nn.AsFloat64()) - } - return nn -} - -// - as x - -// AsNumber gets the Number. -func (n *Number) AsNumber() Number { - return *n -} - -// AsRaw gets the uninterpreted raw value. Might be useful for some -// atomic operations. -func (n *Number) AsRaw() uint64 { - return uint64(*n) -} - -// AsInt64 assumes that the value contains an int64 and returns it as -// such. -func (n *Number) AsInt64() int64 { - return internal.RawToInt64(n.AsRaw()) -} - -// AsFloat64 assumes that the measurement value contains a float64 and -// returns it as such. -func (n *Number) AsFloat64() float64 { - return internal.RawToFloat64(n.AsRaw()) -} - -// - as x atomic - -// AsNumberAtomic gets the Number atomically. -func (n *Number) AsNumberAtomic() Number { - return NewNumberFromRaw(n.AsRawAtomic()) -} - -// AsRawAtomic gets the uninterpreted raw value atomically. Might be -// useful for some atomic operations. -func (n *Number) AsRawAtomic() uint64 { - return atomic.LoadUint64(n.AsRawPtr()) -} - -// AsInt64Atomic assumes that the number contains an int64 and returns -// it as such atomically. -func (n *Number) AsInt64Atomic() int64 { - return atomic.LoadInt64(n.AsInt64Ptr()) -} - -// AsFloat64Atomic assumes that the measurement value contains a -// float64 and returns it as such atomically. -func (n *Number) AsFloat64Atomic() float64 { - return internal.RawToFloat64(n.AsRawAtomic()) -} - -// - as x ptr - -// AsRawPtr gets the pointer to the raw, uninterpreted raw -// value. Might be useful for some atomic operations. -func (n *Number) AsRawPtr() *uint64 { - return (*uint64)(n) -} - -// AsInt64Ptr assumes that the number contains an int64 and returns a -// pointer to it. -func (n *Number) AsInt64Ptr() *int64 { - return internal.RawPtrToInt64Ptr(n.AsRawPtr()) -} - -// AsFloat64Ptr assumes that the number contains a float64 and returns a -// pointer to it. -func (n *Number) AsFloat64Ptr() *float64 { - return internal.RawPtrToFloat64Ptr(n.AsRawPtr()) -} - -// - coerce - -// CoerceToInt64 casts the number to int64. May result in -// data/precision loss. -func (n *Number) CoerceToInt64(kind Kind) int64 { - switch kind { - case Int64Kind: - return n.AsInt64() - case Float64Kind: - return int64(n.AsFloat64()) - default: - // you get what you deserve - return 0 - } -} - -// CoerceToFloat64 casts the number to float64. May result in -// data/precision loss. -func (n *Number) CoerceToFloat64(kind Kind) float64 { - switch kind { - case Int64Kind: - return float64(n.AsInt64()) - case Float64Kind: - return n.AsFloat64() - default: - // you get what you deserve - return 0 - } -} - -// - set - -// SetNumber sets the number to the passed number. Both should be of -// the same kind. -func (n *Number) SetNumber(nn Number) { - *n.AsRawPtr() = nn.AsRaw() -} - -// SetRaw sets the number to the passed raw value. Both number and the -// raw number should represent the same kind. -func (n *Number) SetRaw(r uint64) { - *n.AsRawPtr() = r -} - -// SetInt64 assumes that the number contains an int64 and sets it to -// the passed value. -func (n *Number) SetInt64(i int64) { - *n.AsInt64Ptr() = i -} - -// SetFloat64 assumes that the number contains a float64 and sets it -// to the passed value. -func (n *Number) SetFloat64(f float64) { - *n.AsFloat64Ptr() = f -} - -// - set atomic - -// SetNumberAtomic sets the number to the passed number -// atomically. Both should be of the same kind. -func (n *Number) SetNumberAtomic(nn Number) { - atomic.StoreUint64(n.AsRawPtr(), nn.AsRaw()) -} - -// SetRawAtomic sets the number to the passed raw value -// atomically. Both number and the raw number should represent the -// same kind. -func (n *Number) SetRawAtomic(r uint64) { - atomic.StoreUint64(n.AsRawPtr(), r) -} - -// SetInt64Atomic assumes that the number contains an int64 and sets -// it to the passed value atomically. -func (n *Number) SetInt64Atomic(i int64) { - atomic.StoreInt64(n.AsInt64Ptr(), i) -} - -// SetFloat64Atomic assumes that the number contains a float64 and -// sets it to the passed value atomically. -func (n *Number) SetFloat64Atomic(f float64) { - atomic.StoreUint64(n.AsRawPtr(), internal.Float64ToRaw(f)) -} - -// - swap - -// SwapNumber sets the number to the passed number and returns the old -// number. Both this number and the passed number should be of the -// same kind. -func (n *Number) SwapNumber(nn Number) Number { - old := *n - n.SetNumber(nn) - return old -} - -// SwapRaw sets the number to the passed raw value and returns the old -// raw value. Both number and the raw number should represent the same -// kind. -func (n *Number) SwapRaw(r uint64) uint64 { - old := n.AsRaw() - n.SetRaw(r) - return old -} - -// SwapInt64 assumes that the number contains an int64, sets it to the -// passed value and returns the old int64 value. -func (n *Number) SwapInt64(i int64) int64 { - old := n.AsInt64() - n.SetInt64(i) - return old -} - -// SwapFloat64 assumes that the number contains an float64, sets it to -// the passed value and returns the old float64 value. -func (n *Number) SwapFloat64(f float64) float64 { - old := n.AsFloat64() - n.SetFloat64(f) - return old -} - -// - swap atomic - -// SwapNumberAtomic sets the number to the passed number and returns -// the old number atomically. Both this number and the passed number -// should be of the same kind. -func (n *Number) SwapNumberAtomic(nn Number) Number { - return NewNumberFromRaw(atomic.SwapUint64(n.AsRawPtr(), nn.AsRaw())) -} - -// SwapRawAtomic sets the number to the passed raw value and returns -// the old raw value atomically. Both number and the raw number should -// represent the same kind. -func (n *Number) SwapRawAtomic(r uint64) uint64 { - return atomic.SwapUint64(n.AsRawPtr(), r) -} - -// SwapInt64Atomic assumes that the number contains an int64, sets it -// to the passed value and returns the old int64 value atomically. -func (n *Number) SwapInt64Atomic(i int64) int64 { - return atomic.SwapInt64(n.AsInt64Ptr(), i) -} - -// SwapFloat64Atomic assumes that the number contains an float64, sets -// it to the passed value and returns the old float64 value -// atomically. -func (n *Number) SwapFloat64Atomic(f float64) float64 { - return internal.RawToFloat64(atomic.SwapUint64(n.AsRawPtr(), internal.Float64ToRaw(f))) -} - -// - add - -// AddNumber assumes that this and the passed number are of the passed -// kind and adds the passed number to this number. -func (n *Number) AddNumber(kind Kind, nn Number) { - switch kind { - case Int64Kind: - n.AddInt64(nn.AsInt64()) - case Float64Kind: - n.AddFloat64(nn.AsFloat64()) - } -} - -// AddRaw assumes that this number and the passed raw value are of the -// passed kind and adds the passed raw value to this number. -func (n *Number) AddRaw(kind Kind, r uint64) { - n.AddNumber(kind, NewNumberFromRaw(r)) -} - -// AddInt64 assumes that the number contains an int64 and adds the -// passed int64 to it. -func (n *Number) AddInt64(i int64) { - *n.AsInt64Ptr() += i -} - -// AddFloat64 assumes that the number contains a float64 and adds the -// passed float64 to it. -func (n *Number) AddFloat64(f float64) { - *n.AsFloat64Ptr() += f -} - -// - add atomic - -// AddNumberAtomic assumes that this and the passed number are of the -// passed kind and adds the passed number to this number atomically. -func (n *Number) AddNumberAtomic(kind Kind, nn Number) { - switch kind { - case Int64Kind: - n.AddInt64Atomic(nn.AsInt64()) - case Float64Kind: - n.AddFloat64Atomic(nn.AsFloat64()) - } -} - -// AddRawAtomic assumes that this number and the passed raw value are -// of the passed kind and adds the passed raw value to this number -// atomically. -func (n *Number) AddRawAtomic(kind Kind, r uint64) { - n.AddNumberAtomic(kind, NewNumberFromRaw(r)) -} - -// AddInt64Atomic assumes that the number contains an int64 and adds -// the passed int64 to it atomically. -func (n *Number) AddInt64Atomic(i int64) { - atomic.AddInt64(n.AsInt64Ptr(), i) -} - -// AddFloat64Atomic assumes that the number contains a float64 and -// adds the passed float64 to it atomically. -func (n *Number) AddFloat64Atomic(f float64) { - for { - o := n.AsFloat64Atomic() - if n.CompareAndSwapFloat64(o, o+f) { - break - } - } -} - -// - compare and swap (atomic only) - -// CompareAndSwapNumber does the atomic CAS operation on this -// number. This number and passed old and new numbers should be of the -// same kind. -func (n *Number) CompareAndSwapNumber(on, nn Number) bool { - return atomic.CompareAndSwapUint64(n.AsRawPtr(), on.AsRaw(), nn.AsRaw()) -} - -// CompareAndSwapRaw does the atomic CAS operation on this -// number. This number and passed old and new raw values should be of -// the same kind. -func (n *Number) CompareAndSwapRaw(or, nr uint64) bool { - return atomic.CompareAndSwapUint64(n.AsRawPtr(), or, nr) -} - -// CompareAndSwapInt64 assumes that this number contains an int64 and -// does the atomic CAS operation on it. -func (n *Number) CompareAndSwapInt64(oi, ni int64) bool { - return atomic.CompareAndSwapInt64(n.AsInt64Ptr(), oi, ni) -} - -// CompareAndSwapFloat64 assumes that this number contains a float64 and -// does the atomic CAS operation on it. -func (n *Number) CompareAndSwapFloat64(of, nf float64) bool { - return atomic.CompareAndSwapUint64(n.AsRawPtr(), internal.Float64ToRaw(of), internal.Float64ToRaw(nf)) -} - -// - compare - -// CompareNumber compares two Numbers given their kind. Both numbers -// should have the same kind. This returns: -// 0 if the numbers are equal -// -1 if the subject `n` is less than the argument `nn` -// +1 if the subject `n` is greater than the argument `nn` -func (n *Number) CompareNumber(kind Kind, nn Number) int { - switch kind { - case Int64Kind: - return n.CompareInt64(nn.AsInt64()) - case Float64Kind: - return n.CompareFloat64(nn.AsFloat64()) - default: - // you get what you deserve - return 0 - } -} - -// CompareRaw compares two numbers, where one is input as a raw -// uint64, interpreting both values as a `kind` of number. -func (n *Number) CompareRaw(kind Kind, r uint64) int { - return n.CompareNumber(kind, NewNumberFromRaw(r)) -} - -// CompareInt64 assumes that the Number contains an int64 and performs -// a comparison between the value and the other value. It returns the -// typical result of the compare function: -1 if the value is less -// than the other, 0 if both are equal, 1 if the value is greater than -// the other. -func (n *Number) CompareInt64(i int64) int { - this := n.AsInt64() - if this < i { - return -1 - } else if this > i { - return 1 - } - return 0 -} - -// CompareFloat64 assumes that the Number contains a float64 and -// performs a comparison between the value and the other value. It -// returns the typical result of the compare function: -1 if the value -// is less than the other, 0 if both are equal, 1 if the value is -// greater than the other. -// -// Do not compare NaN values. -func (n *Number) CompareFloat64(f float64) int { - this := n.AsFloat64() - if this < f { - return -1 - } else if this > f { - return 1 - } - return 0 -} - -// - relations to zero - -// IsPositive returns true if the actual value is greater than zero. -func (n *Number) IsPositive(kind Kind) bool { - return n.compareWithZero(kind) > 0 -} - -// IsNegative returns true if the actual value is less than zero. -func (n *Number) IsNegative(kind Kind) bool { - return n.compareWithZero(kind) < 0 -} - -// IsZero returns true if the actual value is equal to zero. -func (n *Number) IsZero(kind Kind) bool { - return n.compareWithZero(kind) == 0 -} - -// - misc - -// Emit returns a string representation of the raw value of the -// Number. A %d is used for integral values, %f for floating point -// values. -func (n *Number) Emit(kind Kind) string { - switch kind { - case Int64Kind: - return fmt.Sprintf("%d", n.AsInt64()) - case Float64Kind: - return fmt.Sprintf("%f", n.AsFloat64()) - default: - return "" - } -} - -// AsInterface returns the number as an interface{}, typically used -// for Kind-correct JSON conversion. -func (n *Number) AsInterface(kind Kind) interface{} { - switch kind { - case Int64Kind: - return n.AsInt64() - case Float64Kind: - return n.AsFloat64() - default: - return math.NaN() - } -} - -// - private stuff - -func (n *Number) compareWithZero(kind Kind) int { - switch kind { - case Int64Kind: - return n.CompareInt64(0) - case Float64Kind: - return n.CompareFloat64(0.) - default: - // you get what you deserve - return 0 - } -} diff --git a/vendor/go.opentelemetry.io/otel/metric/registry/doc.go b/vendor/go.opentelemetry.io/otel/metric/registry/doc.go deleted file mode 100644 index a53ba45545..0000000000 --- a/vendor/go.opentelemetry.io/otel/metric/registry/doc.go +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/* -Package registry provides a non-standalone implementation of -MeterProvider that adds uniqueness checking for instrument descriptors -on top of other MeterProvider it wraps. - -This package is currently in a pre-GA phase. Backwards incompatible changes -may be introduced in subsequent minor version releases as we work to track the -evolving OpenTelemetry specification and user feedback. -*/ -package registry // import "go.opentelemetry.io/otel/metric/registry" diff --git a/vendor/go.opentelemetry.io/otel/metric/registry/registry.go b/vendor/go.opentelemetry.io/otel/metric/registry/registry.go deleted file mode 100644 index 0a42a0fdf8..0000000000 --- a/vendor/go.opentelemetry.io/otel/metric/registry/registry.go +++ /dev/null @@ -1,170 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package registry // import "go.opentelemetry.io/otel/metric/registry" - -import ( - "context" - "fmt" - "sync" - - "go.opentelemetry.io/otel/attribute" - "go.opentelemetry.io/otel/metric" -) - -// MeterProvider is a standard MeterProvider for wrapping `MeterImpl` -type MeterProvider struct { - impl metric.MeterImpl -} - -var _ metric.MeterProvider = (*MeterProvider)(nil) - -// uniqueInstrumentMeterImpl implements the metric.MeterImpl interface, adding -// uniqueness checking for instrument descriptors. Use NewUniqueInstrumentMeter -// to wrap an implementation with uniqueness checking. -type uniqueInstrumentMeterImpl struct { - lock sync.Mutex - impl metric.MeterImpl - state map[key]metric.InstrumentImpl -} - -var _ metric.MeterImpl = (*uniqueInstrumentMeterImpl)(nil) - -type key struct { - instrumentName string - instrumentationName string - InstrumentationVersion string -} - -// NewMeterProvider returns a new provider that implements instrument -// name-uniqueness checking. -func NewMeterProvider(impl metric.MeterImpl) *MeterProvider { - return &MeterProvider{ - impl: NewUniqueInstrumentMeterImpl(impl), - } -} - -// Meter implements MeterProvider. -func (p *MeterProvider) Meter(instrumentationName string, opts ...metric.MeterOption) metric.Meter { - return metric.WrapMeterImpl(p.impl, instrumentationName, opts...) -} - -// ErrMetricKindMismatch is the standard error for mismatched metric -// instrument definitions. -var ErrMetricKindMismatch = fmt.Errorf( - "a metric was already registered by this name with another kind or number type") - -// NewUniqueInstrumentMeterImpl returns a wrapped metric.MeterImpl with -// the addition of uniqueness checking. -func NewUniqueInstrumentMeterImpl(impl metric.MeterImpl) metric.MeterImpl { - return &uniqueInstrumentMeterImpl{ - impl: impl, - state: map[key]metric.InstrumentImpl{}, - } -} - -// RecordBatch implements metric.MeterImpl. -func (u *uniqueInstrumentMeterImpl) RecordBatch(ctx context.Context, labels []attribute.KeyValue, ms ...metric.Measurement) { - u.impl.RecordBatch(ctx, labels, ms...) -} - -func keyOf(descriptor metric.Descriptor) key { - return key{ - descriptor.Name(), - descriptor.InstrumentationName(), - descriptor.InstrumentationVersion(), - } -} - -// NewMetricKindMismatchError formats an error that describes a -// mismatched metric instrument definition. -func NewMetricKindMismatchError(desc metric.Descriptor) error { - return fmt.Errorf("metric was %s (%s %s)registered as a %s %s: %w", - desc.Name(), - desc.InstrumentationName(), - desc.InstrumentationVersion(), - desc.NumberKind(), - desc.InstrumentKind(), - ErrMetricKindMismatch) -} - -// Compatible determines whether two metric.Descriptors are considered -// the same for the purpose of uniqueness checking. -func Compatible(candidate, existing metric.Descriptor) bool { - return candidate.InstrumentKind() == existing.InstrumentKind() && - candidate.NumberKind() == existing.NumberKind() -} - -// checkUniqueness returns an ErrMetricKindMismatch error if there is -// a conflict between a descriptor that was already registered and the -// `descriptor` argument. If there is an existing compatible -// registration, this returns the already-registered instrument. If -// there is no conflict and no prior registration, returns (nil, nil). -func (u *uniqueInstrumentMeterImpl) checkUniqueness(descriptor metric.Descriptor) (metric.InstrumentImpl, error) { - impl, ok := u.state[keyOf(descriptor)] - if !ok { - return nil, nil - } - - if !Compatible(descriptor, impl.Descriptor()) { - return nil, NewMetricKindMismatchError(impl.Descriptor()) - } - - return impl, nil -} - -// NewSyncInstrument implements metric.MeterImpl. -func (u *uniqueInstrumentMeterImpl) NewSyncInstrument(descriptor metric.Descriptor) (metric.SyncImpl, error) { - u.lock.Lock() - defer u.lock.Unlock() - - impl, err := u.checkUniqueness(descriptor) - - if err != nil { - return nil, err - } else if impl != nil { - return impl.(metric.SyncImpl), nil - } - - syncInst, err := u.impl.NewSyncInstrument(descriptor) - if err != nil { - return nil, err - } - u.state[keyOf(descriptor)] = syncInst - return syncInst, nil -} - -// NewAsyncInstrument implements metric.MeterImpl. -func (u *uniqueInstrumentMeterImpl) NewAsyncInstrument( - descriptor metric.Descriptor, - runner metric.AsyncRunner, -) (metric.AsyncImpl, error) { - u.lock.Lock() - defer u.lock.Unlock() - - impl, err := u.checkUniqueness(descriptor) - - if err != nil { - return nil, err - } else if impl != nil { - return impl.(metric.AsyncImpl), nil - } - - asyncInst, err := u.impl.NewAsyncInstrument(descriptor, runner) - if err != nil { - return nil, err - } - u.state[keyOf(descriptor)] = asyncInst - return asyncInst, nil -} diff --git a/vendor/go.opentelemetry.io/otel/pre_release.sh b/vendor/go.opentelemetry.io/otel/pre_release.sh deleted file mode 100644 index 0de22169cf..0000000000 --- a/vendor/go.opentelemetry.io/otel/pre_release.sh +++ /dev/null @@ -1,95 +0,0 @@ -#!/bin/bash - -# Copyright The OpenTelemetry Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -set -e - -help() -{ - printf "\n" - printf "Usage: $0 -t tag\n" - printf "\t-t Unreleased tag. Update all go.mod with this tag.\n" - exit 1 # Exit script after printing help -} - -while getopts "t:" opt -do - case "$opt" in - t ) TAG="$OPTARG" ;; - ? ) help ;; # Print help - esac -done - -# Print help in case parameters are empty -if [ -z "$TAG" ] -then - printf "Tag is missing\n"; - help -fi - -# Validate semver -SEMVER_REGEX="^v(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)(\\-[0-9A-Za-z-]+(\\.[0-9A-Za-z-]+)*)?(\\+[0-9A-Za-z-]+(\\.[0-9A-Za-z-]+)*)?$" -if [[ "${TAG}" =~ ${SEMVER_REGEX} ]]; then - printf "${TAG} is valid semver tag.\n" -else - printf "${TAG} is not a valid semver tag.\n" - exit -1 -fi - -TAG_FOUND=`git tag --list ${TAG}` -if [[ ${TAG_FOUND} = ${TAG} ]] ; then - printf "Tag ${TAG} already exists\n" - exit -1 -fi - -# Get version for version.go -OTEL_VERSION=$(echo "${TAG}" | grep -o '^v[0-9]\+\.[0-9]\+\.[0-9]\+') -# Strip leading v -OTEL_VERSION="${OTEL_VERSION#v}" - -cd $(dirname $0) - -if ! git diff --quiet; then \ - printf "Working tree is not clean, can't proceed with the release process\n" - git status - git diff - exit 1 -fi - -# Update version.go -cp ./version.go ./version.go.bak -sed "s/\(return \"\)[0-9]*\.[0-9]*\.[0-9]*\"/\1${OTEL_VERSION}\"/" ./version.go.bak >./version.go -rm -f ./version.go.bak - -# Update go.mod -git checkout -b pre_release_${TAG} main -PACKAGE_DIRS=$(find . -mindepth 2 -type f -name 'go.mod' -exec dirname {} \; | egrep -v 'tools' | sed 's/^\.\///' | sort) - -for dir in $PACKAGE_DIRS; do - cp "${dir}/go.mod" "${dir}/go.mod.bak" - sed "s/opentelemetry.io\/otel\([^ ]*\) v[0-9]*\.[0-9]*\.[0-9]/opentelemetry.io\/otel\1 ${TAG}/" "${dir}/go.mod.bak" >"${dir}/go.mod" - rm -f "${dir}/go.mod.bak" -done - -# Run lint to update go.sum -make lint - -# Add changes and commit. -git add . -make ci -git commit -m "Prepare for releasing $TAG" - -printf "Now run following to verify the changes.\ngit diff main\n" -printf "\nThen push the changes to upstream\n" diff --git a/vendor/go.opentelemetry.io/otel/propagation.go b/vendor/go.opentelemetry.io/otel/propagation.go deleted file mode 100644 index d29aaa32c0..0000000000 --- a/vendor/go.opentelemetry.io/otel/propagation.go +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package otel // import "go.opentelemetry.io/otel" - -import ( - "go.opentelemetry.io/otel/internal/global" - "go.opentelemetry.io/otel/propagation" -) - -// GetTextMapPropagator returns the global TextMapPropagator. If none has been -// set, a No-Op TextMapPropagator is returned. -func GetTextMapPropagator() propagation.TextMapPropagator { - return global.TextMapPropagator() -} - -// SetTextMapPropagator sets propagator as the global TextMapPropagator. -func SetTextMapPropagator(propagator propagation.TextMapPropagator) { - global.SetTextMapPropagator(propagator) -} diff --git a/vendor/go.opentelemetry.io/otel/propagation/baggage.go b/vendor/go.opentelemetry.io/otel/propagation/baggage.go deleted file mode 100644 index bc76191892..0000000000 --- a/vendor/go.opentelemetry.io/otel/propagation/baggage.go +++ /dev/null @@ -1,111 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package propagation // import "go.opentelemetry.io/otel/propagation" - -import ( - "context" - "net/url" - "strings" - - "go.opentelemetry.io/otel/attribute" - "go.opentelemetry.io/otel/internal/baggage" -) - -const baggageHeader = "baggage" - -// Baggage is a propagator that supports the W3C Baggage format. -// -// This propagates user-defined baggage associated with a trace. The complete -// specification is defined at https://w3c.github.io/baggage/. -type Baggage struct{} - -var _ TextMapPropagator = Baggage{} - -// Inject sets baggage key-values from ctx into the carrier. -func (b Baggage) Inject(ctx context.Context, carrier TextMapCarrier) { - baggageMap := baggage.MapFromContext(ctx) - firstIter := true - var headerValueBuilder strings.Builder - baggageMap.Foreach(func(kv attribute.KeyValue) bool { - if !firstIter { - headerValueBuilder.WriteRune(',') - } - firstIter = false - headerValueBuilder.WriteString(url.QueryEscape(strings.TrimSpace((string)(kv.Key)))) - headerValueBuilder.WriteRune('=') - headerValueBuilder.WriteString(url.QueryEscape(strings.TrimSpace(kv.Value.Emit()))) - return true - }) - if headerValueBuilder.Len() > 0 { - headerString := headerValueBuilder.String() - carrier.Set(baggageHeader, headerString) - } -} - -// Extract returns a copy of parent with the baggage from the carrier added. -func (b Baggage) Extract(parent context.Context, carrier TextMapCarrier) context.Context { - bVal := carrier.Get(baggageHeader) - if bVal == "" { - return parent - } - - baggageValues := strings.Split(bVal, ",") - keyValues := make([]attribute.KeyValue, 0, len(baggageValues)) - for _, baggageValue := range baggageValues { - valueAndProps := strings.Split(baggageValue, ";") - if len(valueAndProps) < 1 { - continue - } - nameValue := strings.Split(valueAndProps[0], "=") - if len(nameValue) < 2 { - continue - } - name, err := url.QueryUnescape(nameValue[0]) - if err != nil { - continue - } - trimmedName := strings.TrimSpace(name) - value, err := url.QueryUnescape(nameValue[1]) - if err != nil { - continue - } - trimmedValue := strings.TrimSpace(value) - - // TODO (skaris): properties defiend https://w3c.github.io/correlation-context/, are currently - // just put as part of the value. - var trimmedValueWithProps strings.Builder - trimmedValueWithProps.WriteString(trimmedValue) - for _, prop := range valueAndProps[1:] { - trimmedValueWithProps.WriteRune(';') - trimmedValueWithProps.WriteString(prop) - } - - keyValues = append(keyValues, attribute.String(trimmedName, trimmedValueWithProps.String())) - } - - if len(keyValues) > 0 { - // Only update the context if valid values were found - return baggage.ContextWithMap(parent, baggage.NewMap(baggage.MapUpdate{ - MultiKV: keyValues, - })) - } - - return parent -} - -// Fields returns the keys who's values are set with Inject. -func (b Baggage) Fields() []string { - return []string{baggageHeader} -} diff --git a/vendor/go.opentelemetry.io/otel/propagation/doc.go b/vendor/go.opentelemetry.io/otel/propagation/doc.go deleted file mode 100644 index 89573f1baa..0000000000 --- a/vendor/go.opentelemetry.io/otel/propagation/doc.go +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/* -Package propagation contains OpenTelemetry context propagators. - -This package is currently in a pre-GA phase. Backwards incompatible changes -may be introduced in subsequent minor version releases as we work to track the -evolving OpenTelemetry specification and user feedback. - -OpenTelemetry propagators are used to extract and inject context data from and -into messages exchanged by applications. The propagator supported by this -package is the W3C Trace Context encoding -(https://www.w3.org/TR/trace-context/), and W3C Baggage -(https://w3c.github.io/baggage/). -*/ -package propagation // import "go.opentelemetry.io/otel/propagation" diff --git a/vendor/go.opentelemetry.io/otel/propagation/propagation.go b/vendor/go.opentelemetry.io/otel/propagation/propagation.go deleted file mode 100644 index 9cfeb347a3..0000000000 --- a/vendor/go.opentelemetry.io/otel/propagation/propagation.go +++ /dev/null @@ -1,105 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package propagation // import "go.opentelemetry.io/otel/propagation" - -import ( - "context" - "net/http" -) - -// TextMapCarrier is the storage medium used by a TextMapPropagator. -type TextMapCarrier interface { - // Get returns the value associated with the passed key. - Get(key string) string - // Set stores the key-value pair. - Set(key string, value string) - // Keys lists the keys stored in this carrier. - Keys() []string -} - -// HeaderCarrier adapts http.Header to satisfy the TextMapCarrier interface. -type HeaderCarrier http.Header - -// Get returns the value associated with the passed key. -func (hc HeaderCarrier) Get(key string) string { - return http.Header(hc).Get(key) -} - -// Set stores the key-value pair. -func (hc HeaderCarrier) Set(key string, value string) { - http.Header(hc).Set(key, value) -} - -// Keys lists the keys stored in this carrier. -func (hc HeaderCarrier) Keys() []string { - keys := make([]string, 0, len(hc)) - for k := range hc { - keys = append(keys, k) - } - return keys -} - -// TextMapPropagator propagates cross-cutting concerns as key-value text -// pairs within a carrier that travels in-band across process boundaries. -type TextMapPropagator interface { - // Inject set cross-cutting concerns from the Context into the carrier. - Inject(ctx context.Context, carrier TextMapCarrier) - // Extract reads cross-cutting concerns from the carrier into a Context. - Extract(ctx context.Context, carrier TextMapCarrier) context.Context - // Fields returns the keys who's values are set with Inject. - Fields() []string -} - -type compositeTextMapPropagator []TextMapPropagator - -func (p compositeTextMapPropagator) Inject(ctx context.Context, carrier TextMapCarrier) { - for _, i := range p { - i.Inject(ctx, carrier) - } -} - -func (p compositeTextMapPropagator) Extract(ctx context.Context, carrier TextMapCarrier) context.Context { - for _, i := range p { - ctx = i.Extract(ctx, carrier) - } - return ctx -} - -func (p compositeTextMapPropagator) Fields() []string { - unique := make(map[string]struct{}) - for _, i := range p { - for _, k := range i.Fields() { - unique[k] = struct{}{} - } - } - - fields := make([]string, 0, len(unique)) - for k := range unique { - fields = append(fields, k) - } - return fields -} - -// NewCompositeTextMapPropagator returns a unified TextMapPropagator from the -// group of passed TextMapPropagator. This allows different cross-cutting -// concerns to be propagates in a unified manner. -// -// The returned TextMapPropagator will inject and extract cross-cutting -// concerns in the order the TextMapPropagators were provided. Additionally, -// the Fields method will return a de-duplicated slice of the keys that are -// set with the Inject method. -func NewCompositeTextMapPropagator(p ...TextMapPropagator) TextMapPropagator { - return compositeTextMapPropagator(p) -} diff --git a/vendor/go.opentelemetry.io/otel/propagation/trace_context.go b/vendor/go.opentelemetry.io/otel/propagation/trace_context.go deleted file mode 100644 index 82de416bea..0000000000 --- a/vendor/go.opentelemetry.io/otel/propagation/trace_context.go +++ /dev/null @@ -1,178 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package propagation // import "go.opentelemetry.io/otel/propagation" - -import ( - "context" - "encoding/hex" - "fmt" - "regexp" - "strings" - - "go.opentelemetry.io/otel/attribute" - "go.opentelemetry.io/otel/trace" -) - -const ( - supportedVersion = 0 - maxVersion = 254 - traceparentHeader = "traceparent" - tracestateHeader = "tracestate" -) - -// TraceContext is a propagator that supports the W3C Trace Context format -// (https://www.w3.org/TR/trace-context/) -// -// This propagator will propagate the traceparent and tracestate headers to -// guarantee traces are not broken. It is up to the users of this propagator -// to choose if they want to participate in a trace by modifying the -// traceparent header and relevant parts of the tracestate header containing -// their proprietary information. -type TraceContext struct{} - -var _ TextMapPropagator = TraceContext{} -var traceCtxRegExp = regexp.MustCompile("^(?P[0-9a-f]{2})-(?P[a-f0-9]{32})-(?P[a-f0-9]{16})-(?P[a-f0-9]{2})(?:-.*)?$") - -// Inject set tracecontext from the Context into the carrier. -func (tc TraceContext) Inject(ctx context.Context, carrier TextMapCarrier) { - sc := trace.SpanContextFromContext(ctx) - if !sc.IsValid() { - return - } - - carrier.Set(tracestateHeader, sc.TraceState().String()) - - // Clear all flags other than the trace-context supported sampling bit. - flags := sc.TraceFlags() & trace.FlagsSampled - - h := fmt.Sprintf("%.2x-%s-%s-%s", - supportedVersion, - sc.TraceID(), - sc.SpanID(), - flags) - carrier.Set(traceparentHeader, h) -} - -// Extract reads tracecontext from the carrier into a returned Context. -// -// The returned Context will be a copy of ctx and contain the extracted -// tracecontext as the remote SpanContext. If the extracted tracecontext is -// invalid, the passed ctx will be returned directly instead. -func (tc TraceContext) Extract(ctx context.Context, carrier TextMapCarrier) context.Context { - sc := tc.extract(carrier) - if !sc.IsValid() { - return ctx - } - return trace.ContextWithRemoteSpanContext(ctx, sc) -} - -func (tc TraceContext) extract(carrier TextMapCarrier) trace.SpanContext { - h := carrier.Get(traceparentHeader) - if h == "" { - return trace.SpanContext{} - } - - matches := traceCtxRegExp.FindStringSubmatch(h) - - if len(matches) == 0 { - return trace.SpanContext{} - } - - if len(matches) < 5 { // four subgroups plus the overall match - return trace.SpanContext{} - } - - if len(matches[1]) != 2 { - return trace.SpanContext{} - } - ver, err := hex.DecodeString(matches[1]) - if err != nil { - return trace.SpanContext{} - } - version := int(ver[0]) - if version > maxVersion { - return trace.SpanContext{} - } - - if version == 0 && len(matches) != 5 { // four subgroups plus the overall match - return trace.SpanContext{} - } - - if len(matches[2]) != 32 { - return trace.SpanContext{} - } - - var scc trace.SpanContextConfig - - scc.TraceID, err = trace.TraceIDFromHex(matches[2][:32]) - if err != nil { - return trace.SpanContext{} - } - - if len(matches[3]) != 16 { - return trace.SpanContext{} - } - scc.SpanID, err = trace.SpanIDFromHex(matches[3]) - if err != nil { - return trace.SpanContext{} - } - - if len(matches[4]) != 2 { - return trace.SpanContext{} - } - opts, err := hex.DecodeString(matches[4]) - if err != nil || len(opts) < 1 || (version == 0 && opts[0] > 2) { - return trace.SpanContext{} - } - // Clear all flags other than the trace-context supported sampling bit. - scc.TraceFlags = trace.TraceFlags(opts[0]) & trace.FlagsSampled - - scc.TraceState = parseTraceState(carrier.Get(tracestateHeader)) - scc.Remote = true - - sc := trace.NewSpanContext(scc) - if !sc.IsValid() { - return trace.SpanContext{} - } - - return sc -} - -// Fields returns the keys who's values are set with Inject. -func (tc TraceContext) Fields() []string { - return []string{traceparentHeader, tracestateHeader} -} - -func parseTraceState(in string) trace.TraceState { - if in == "" { - return trace.TraceState{} - } - - kvs := []attribute.KeyValue{} - for _, entry := range strings.Split(in, ",") { - parts := strings.SplitN(entry, "=", 2) - if len(parts) != 2 { - // Parse failure, abort! - return trace.TraceState{} - } - kvs = append(kvs, attribute.String(parts[0], parts[1])) - } - - // Ignoring error here as "failure to parse tracestate MUST NOT - // affect the parsing of traceparent." - // https://www.w3.org/TR/trace-context/#tracestate-header - ts, _ := trace.TraceStateFromKeyValues(kvs...) - return ts -} diff --git a/vendor/go.opentelemetry.io/otel/sdk/LICENSE b/vendor/go.opentelemetry.io/otel/sdk/LICENSE deleted file mode 100644 index 261eeb9e9f..0000000000 --- a/vendor/go.opentelemetry.io/otel/sdk/LICENSE +++ /dev/null @@ -1,201 +0,0 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. diff --git a/vendor/go.opentelemetry.io/otel/sdk/export/metric/LICENSE b/vendor/go.opentelemetry.io/otel/sdk/export/metric/LICENSE deleted file mode 100644 index 261eeb9e9f..0000000000 --- a/vendor/go.opentelemetry.io/otel/sdk/export/metric/LICENSE +++ /dev/null @@ -1,201 +0,0 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. diff --git a/vendor/go.opentelemetry.io/otel/sdk/export/metric/aggregation/aggregation.go b/vendor/go.opentelemetry.io/otel/sdk/export/metric/aggregation/aggregation.go deleted file mode 100644 index 73e98aaa85..0000000000 --- a/vendor/go.opentelemetry.io/otel/sdk/export/metric/aggregation/aggregation.go +++ /dev/null @@ -1,154 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package aggregation // import "go.opentelemetry.io/otel/sdk/export/metric/aggregation" - -import ( - "fmt" - "time" - - "go.opentelemetry.io/otel/metric/number" -) - -// These interfaces describe the various ways to access state from an -// Aggregation. - -type ( - // Aggregation is an interface returned by the Aggregator - // containing an interval of metric data. - Aggregation interface { - // Kind returns a short identifying string to identify - // the Aggregator that was used to produce the - // Aggregation (e.g., "Sum"). - Kind() Kind - } - - // Sum returns an aggregated sum. - Sum interface { - Aggregation - Sum() (number.Number, error) - } - - // Count returns the number of values that were aggregated. - Count interface { - Aggregation - Count() (uint64, error) - } - - // Min returns the minimum value over the set of values that were aggregated. - Min interface { - Aggregation - Min() (number.Number, error) - } - - // Max returns the maximum value over the set of values that were aggregated. - Max interface { - Aggregation - Max() (number.Number, error) - } - - // LastValue returns the latest value that was aggregated. - LastValue interface { - Aggregation - LastValue() (number.Number, time.Time, error) - } - - // Points returns the raw values that were aggregated. - Points interface { - Aggregation - - // Points returns points in the order they were - // recorded. Points are approximately ordered by - // timestamp, but this is not guaranteed. - Points() ([]Point, error) - } - - // Point is a raw data point, consisting of a number and value. - Point struct { - number.Number - time.Time - } - - // Buckets represents histogram buckets boundaries and counts. - // - // For a Histogram with N defined boundaries, e.g, [x, y, z]. - // There are N+1 counts: [-inf, x), [x, y), [y, z), [z, +inf] - Buckets struct { - // Boundaries are floating point numbers, even when - // aggregating integers. - Boundaries []float64 - - // Counts holds the count in each bucket. - Counts []uint64 - } - - // Histogram returns the count of events in pre-determined buckets. - Histogram interface { - Aggregation - Count() (uint64, error) - Sum() (number.Number, error) - Histogram() (Buckets, error) - } - - // MinMaxSumCount supports the Min, Max, Sum, and Count interfaces. - MinMaxSumCount interface { - Aggregation - Min() (number.Number, error) - Max() (number.Number, error) - Sum() (number.Number, error) - Count() (uint64, error) - } -) - -type ( - // Kind is a short name for the Aggregator that produces an - // Aggregation, used for descriptive purpose only. Kind is a - // string to allow user-defined Aggregators. - // - // When deciding how to handle an Aggregation, Exporters are - // encouraged to decide based on conversion to the above - // interfaces based on strength, not on Kind value, when - // deciding how to expose metric data. This enables - // user-supplied Aggregators to replace builtin Aggregators. - // - // For example, test for a Distribution before testing for a - // MinMaxSumCount, test for a Histogram before testing for a - // Sum, and so on. - Kind string -) - -const ( - SumKind Kind = "Sum" - MinMaxSumCountKind Kind = "MinMaxSumCount" - HistogramKind Kind = "Histogram" - LastValueKind Kind = "Lastvalue" - ExactKind Kind = "Exact" -) - -var ( - ErrNegativeInput = fmt.Errorf("negative value is out of range for this instrument") - ErrNaNInput = fmt.Errorf("NaN value is an invalid input") - ErrInconsistentType = fmt.Errorf("inconsistent aggregator types") - ErrNoSubtraction = fmt.Errorf("aggregator does not subtract") - - // ErrNoData is returned when (due to a race with collection) - // the Aggregator is check-pointed before the first value is set. - // The aggregator should simply be skipped in this case. - ErrNoData = fmt.Errorf("no data collected by this aggregator") -) - -// String returns the string value of Kind. -func (k Kind) String() string { - return string(k) -} diff --git a/vendor/go.opentelemetry.io/otel/sdk/export/metric/exportkind_string.go b/vendor/go.opentelemetry.io/otel/sdk/export/metric/exportkind_string.go deleted file mode 100644 index a92c1c1f2d..0000000000 --- a/vendor/go.opentelemetry.io/otel/sdk/export/metric/exportkind_string.go +++ /dev/null @@ -1,25 +0,0 @@ -// Code generated by "stringer -type=ExportKind"; DO NOT EDIT. - -package metric - -import "strconv" - -func _() { - // An "invalid array index" compiler error signifies that the constant values have changed. - // Re-run the stringer command to generate them again. - var x [1]struct{} - _ = x[CumulativeExportKind-1] - _ = x[DeltaExportKind-2] -} - -const _ExportKind_name = "CumulativeExportKindDeltaExportKind" - -var _ExportKind_index = [...]uint8{0, 20, 35} - -func (i ExportKind) String() string { - i -= 1 - if i < 0 || i >= ExportKind(len(_ExportKind_index)-1) { - return "ExportKind(" + strconv.FormatInt(int64(i+1), 10) + ")" - } - return _ExportKind_name[_ExportKind_index[i]:_ExportKind_index[i+1]] -} diff --git a/vendor/go.opentelemetry.io/otel/sdk/export/metric/go.mod b/vendor/go.opentelemetry.io/otel/sdk/export/metric/go.mod deleted file mode 100644 index 170d38157f..0000000000 --- a/vendor/go.opentelemetry.io/otel/sdk/export/metric/go.mod +++ /dev/null @@ -1,54 +0,0 @@ -module go.opentelemetry.io/otel/sdk/export/metric - -go 1.14 - -replace go.opentelemetry.io/otel => ../../.. - -replace go.opentelemetry.io/otel/bridge/opencensus => ../../../bridge/opencensus - -replace go.opentelemetry.io/otel/bridge/opentracing => ../../../bridge/opentracing - -replace go.opentelemetry.io/otel/example/jaeger => ../../../example/jaeger - -replace go.opentelemetry.io/otel/example/namedtracer => ../../../example/namedtracer - -replace go.opentelemetry.io/otel/example/opencensus => ../../../example/opencensus - -replace go.opentelemetry.io/otel/example/otel-collector => ../../../example/otel-collector - -replace go.opentelemetry.io/otel/example/prom-collector => ../../../example/prom-collector - -replace go.opentelemetry.io/otel/example/prometheus => ../../../example/prometheus - -replace go.opentelemetry.io/otel/example/zipkin => ../../../example/zipkin - -replace go.opentelemetry.io/otel/exporters/metric/prometheus => ../../../exporters/metric/prometheus - -replace go.opentelemetry.io/otel/exporters/otlp => ../../../exporters/otlp - -replace go.opentelemetry.io/otel/exporters/stdout => ../../../exporters/stdout - -replace go.opentelemetry.io/otel/exporters/trace/jaeger => ../../../exporters/trace/jaeger - -replace go.opentelemetry.io/otel/exporters/trace/zipkin => ../../../exporters/trace/zipkin - -replace go.opentelemetry.io/otel/internal/tools => ../../../internal/tools - -replace go.opentelemetry.io/otel/metric => ../../../metric - -replace go.opentelemetry.io/otel/oteltest => ../../../oteltest - -replace go.opentelemetry.io/otel/sdk => ../.. - -replace go.opentelemetry.io/otel/sdk/export/metric => ./ - -replace go.opentelemetry.io/otel/sdk/metric => ../../metric - -replace go.opentelemetry.io/otel/trace => ../../../trace - -require ( - github.com/stretchr/testify v1.7.0 - go.opentelemetry.io/otel v0.20.0 - go.opentelemetry.io/otel/metric v0.20.0 - go.opentelemetry.io/otel/sdk v0.20.0 -) diff --git a/vendor/go.opentelemetry.io/otel/sdk/export/metric/go.sum b/vendor/go.opentelemetry.io/otel/sdk/export/metric/go.sum deleted file mode 100644 index b69f2e56da..0000000000 --- a/vendor/go.opentelemetry.io/otel/sdk/export/metric/go.sum +++ /dev/null @@ -1,15 +0,0 @@ -github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= -github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= -github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/vendor/go.opentelemetry.io/otel/sdk/export/metric/metric.go b/vendor/go.opentelemetry.io/otel/sdk/export/metric/metric.go deleted file mode 100644 index 55965a2392..0000000000 --- a/vendor/go.opentelemetry.io/otel/sdk/export/metric/metric.go +++ /dev/null @@ -1,445 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -//go:generate stringer -type=ExportKind - -package metric // import "go.opentelemetry.io/otel/sdk/export/metric" - -import ( - "context" - "sync" - "time" - - "go.opentelemetry.io/otel/attribute" - "go.opentelemetry.io/otel/metric" - "go.opentelemetry.io/otel/metric/number" - "go.opentelemetry.io/otel/sdk/export/metric/aggregation" - "go.opentelemetry.io/otel/sdk/resource" -) - -// Processor is responsible for deciding which kind of aggregation to -// use (via AggregatorSelector), gathering exported results from the -// SDK during collection, and deciding over which dimensions to group -// the exported data. -// -// The SDK supports binding only one of these interfaces, as it has -// the sole responsibility of determining which Aggregator to use for -// each record. -// -// The embedded AggregatorSelector interface is called (concurrently) -// in instrumentation context to select the appropriate Aggregator for -// an instrument. -// -// The `Process` method is called during collection in a -// single-threaded context from the SDK, after the aggregator is -// checkpointed, allowing the processor to build the set of metrics -// currently being exported. -type Processor interface { - // AggregatorSelector is responsible for selecting the - // concrete type of Aggregator used for a metric in the SDK. - // - // This may be a static decision based on fields of the - // Descriptor, or it could use an external configuration - // source to customize the treatment of each metric - // instrument. - // - // The result from AggregatorSelector.AggregatorFor should be - // the same type for a given Descriptor or else nil. The same - // type should be returned for a given descriptor, because - // Aggregators only know how to Merge with their own type. If - // the result is nil, the metric instrument will be disabled. - // - // Note that the SDK only calls AggregatorFor when new records - // require an Aggregator. This does not provide a way to - // disable metrics with active records. - AggregatorSelector - - // Process is called by the SDK once per internal record, - // passing the export Accumulation (a Descriptor, the corresponding - // Labels, and the checkpointed Aggregator). This call has no - // Context argument because it is expected to perform only - // computation. An SDK is not expected to call exporters from - // with Process, use a controller for that (see - // ./controllers/{pull,push}. - Process(accum Accumulation) error -} - -// AggregatorSelector supports selecting the kind of Aggregator to -// use at runtime for a specific metric instrument. -type AggregatorSelector interface { - // AggregatorFor allocates a variable number of aggregators of - // a kind suitable for the requested export. This method - // initializes a `...*Aggregator`, to support making a single - // allocation. - // - // When the call returns without initializing the *Aggregator - // to a non-nil value, the metric instrument is explicitly - // disabled. - // - // This must return a consistent type to avoid confusion in - // later stages of the metrics export process, i.e., when - // Merging or Checkpointing aggregators for a specific - // instrument. - // - // Note: This is context-free because the aggregator should - // not relate to the incoming context. This call should not - // block. - AggregatorFor(descriptor *metric.Descriptor, aggregator ...*Aggregator) -} - -// Checkpointer is the interface used by a Controller to coordinate -// the Processor with Accumulator(s) and Exporter(s). The -// StartCollection() and FinishCollection() methods start and finish a -// collection interval. Controllers call the Accumulator(s) during -// collection to process Accumulations. -type Checkpointer interface { - // Processor processes metric data for export. The Process - // method is bracketed by StartCollection and FinishCollection - // calls. The embedded AggregatorSelector can be called at - // any time. - Processor - - // CheckpointSet returns the current data set. This may be - // called before and after collection. The - // implementation is required to return the same value - // throughout its lifetime, since CheckpointSet exposes a - // sync.Locker interface. The caller is responsible for - // locking the CheckpointSet before initiating collection. - CheckpointSet() CheckpointSet - - // StartCollection begins a collection interval. - StartCollection() - - // FinishCollection ends a collection interval. - FinishCollection() error -} - -// Aggregator implements a specific aggregation behavior, e.g., a -// behavior to track a sequence of updates to an instrument. Sum-only -// instruments commonly use a simple Sum aggregator, but for the -// distribution instruments (ValueRecorder, ValueObserver) there are a -// number of possible aggregators with different cost and accuracy -// tradeoffs. -// -// Note that any Aggregator may be attached to any instrument--this is -// the result of the OpenTelemetry API/SDK separation. It is possible -// to attach a Sum aggregator to a ValueRecorder instrument or a -// MinMaxSumCount aggregator to a Counter instrument. -type Aggregator interface { - // Aggregation returns an Aggregation interface to access the - // current state of this Aggregator. The caller is - // responsible for synchronization and must not call any the - // other methods in this interface concurrently while using - // the Aggregation. - Aggregation() aggregation.Aggregation - - // Update receives a new measured value and incorporates it - // into the aggregation. Update() calls may be called - // concurrently. - // - // Descriptor.NumberKind() should be consulted to determine - // whether the provided number is an int64 or float64. - // - // The Context argument comes from user-level code and could be - // inspected for a `correlation.Map` or `trace.SpanContext`. - Update(ctx context.Context, number number.Number, descriptor *metric.Descriptor) error - - // SynchronizedMove is called during collection to finish one - // period of aggregation by atomically saving the - // currently-updating state into the argument Aggregator AND - // resetting the current value to the zero state. - // - // SynchronizedMove() is called concurrently with Update(). These - // two methods must be synchronized with respect to each - // other, for correctness. - // - // After saving a synchronized copy, the Aggregator can be converted - // into one or more of the interfaces in the `aggregation` sub-package, - // according to kind of Aggregator that was selected. - // - // This method will return an InconsistentAggregatorError if - // this Aggregator cannot be copied into the destination due - // to an incompatible type. - // - // This call has no Context argument because it is expected to - // perform only computation. - // - // When called with a nil `destination`, this Aggregator is reset - // and the current value is discarded. - SynchronizedMove(destination Aggregator, descriptor *metric.Descriptor) error - - // Merge combines the checkpointed state from the argument - // Aggregator into this Aggregator. Merge is not synchronized - // with respect to Update or SynchronizedMove. - // - // The owner of an Aggregator being merged is responsible for - // synchronization of both Aggregator states. - Merge(aggregator Aggregator, descriptor *metric.Descriptor) error -} - -// Subtractor is an optional interface implemented by some -// Aggregators. An Aggregator must support `Subtract()` in order to -// be configured for a Precomputed-Sum instrument (SumObserver, -// UpDownSumObserver) using a DeltaExporter. -type Subtractor interface { - // Subtract subtracts the `operand` from this Aggregator and - // outputs the value in `result`. - Subtract(operand, result Aggregator, descriptor *metric.Descriptor) error -} - -// Exporter handles presentation of the checkpoint of aggregate -// metrics. This is the final stage of a metrics export pipeline, -// where metric data are formatted for a specific system. -type Exporter interface { - // Export is called immediately after completing a collection - // pass in the SDK. - // - // The Context comes from the controller that initiated - // collection. - // - // The CheckpointSet interface refers to the Processor that just - // completed collection. - Export(ctx context.Context, checkpointSet CheckpointSet) error - - // ExportKindSelector is an interface used by the Processor - // in deciding whether to compute Delta or Cumulative - // Aggregations when passing Records to this Exporter. - ExportKindSelector -} - -// ExportKindSelector is a sub-interface of Exporter used to indicate -// whether the Processor should compute Delta or Cumulative -// Aggregations. -type ExportKindSelector interface { - // ExportKindFor should return the correct ExportKind that - // should be used when exporting data for the given metric - // instrument and Aggregator kind. - ExportKindFor(descriptor *metric.Descriptor, aggregatorKind aggregation.Kind) ExportKind -} - -// CheckpointSet allows a controller to access a complete checkpoint of -// aggregated metrics from the Processor. This is passed to the -// Exporter which may then use ForEach to iterate over the collection -// of aggregated metrics. -type CheckpointSet interface { - // ForEach iterates over aggregated checkpoints for all - // metrics that were updated during the last collection - // period. Each aggregated checkpoint returned by the - // function parameter may return an error. - // - // The ExportKindSelector argument is used to determine - // whether the Record is computed using Delta or Cumulative - // aggregation. - // - // ForEach tolerates ErrNoData silently, as this is - // expected from the Meter implementation. Any other kind - // of error will immediately halt ForEach and return - // the error to the caller. - ForEach(kindSelector ExportKindSelector, recordFunc func(Record) error) error - - // Locker supports locking the checkpoint set. Collection - // into the checkpoint set cannot take place (in case of a - // stateful processor) while it is locked. - // - // The Processor attached to the Accumulator MUST be called - // with the lock held. - sync.Locker - - // RLock acquires a read lock corresponding to this Locker. - RLock() - // RUnlock releases a read lock corresponding to this Locker. - RUnlock() -} - -// Metadata contains the common elements for exported metric data that -// are shared by the Accumulator->Processor and Processor->Exporter -// steps. -type Metadata struct { - descriptor *metric.Descriptor - labels *attribute.Set - resource *resource.Resource -} - -// Accumulation contains the exported data for a single metric instrument -// and label set, as prepared by an Accumulator for the Processor. -type Accumulation struct { - Metadata - aggregator Aggregator -} - -// Record contains the exported data for a single metric instrument -// and label set, as prepared by the Processor for the Exporter. -// This includes the effective start and end time for the aggregation. -type Record struct { - Metadata - aggregation aggregation.Aggregation - start time.Time - end time.Time -} - -// Descriptor describes the metric instrument being exported. -func (m Metadata) Descriptor() *metric.Descriptor { - return m.descriptor -} - -// Labels describes the labels associated with the instrument and the -// aggregated data. -func (m Metadata) Labels() *attribute.Set { - return m.labels -} - -// Resource contains common attributes that apply to this metric event. -func (m Metadata) Resource() *resource.Resource { - return m.resource -} - -// NewAccumulation allows Accumulator implementations to construct new -// Accumulations to send to Processors. The Descriptor, Labels, Resource, -// and Aggregator represent aggregate metric events received over a single -// collection period. -func NewAccumulation(descriptor *metric.Descriptor, labels *attribute.Set, resource *resource.Resource, aggregator Aggregator) Accumulation { - return Accumulation{ - Metadata: Metadata{ - descriptor: descriptor, - labels: labels, - resource: resource, - }, - aggregator: aggregator, - } -} - -// Aggregator returns the checkpointed aggregator. It is safe to -// access the checkpointed state without locking. -func (r Accumulation) Aggregator() Aggregator { - return r.aggregator -} - -// NewRecord allows Processor implementations to construct export -// records. The Descriptor, Labels, and Aggregator represent -// aggregate metric events received over a single collection period. -func NewRecord(descriptor *metric.Descriptor, labels *attribute.Set, resource *resource.Resource, aggregation aggregation.Aggregation, start, end time.Time) Record { - return Record{ - Metadata: Metadata{ - descriptor: descriptor, - labels: labels, - resource: resource, - }, - aggregation: aggregation, - start: start, - end: end, - } -} - -// Aggregation returns the aggregation, an interface to the record and -// its aggregator, dependent on the kind of both the input and exporter. -func (r Record) Aggregation() aggregation.Aggregation { - return r.aggregation -} - -// StartTime is the start time of the interval covered by this aggregation. -func (r Record) StartTime() time.Time { - return r.start -} - -// EndTime is the end time of the interval covered by this aggregation. -func (r Record) EndTime() time.Time { - return r.end -} - -// ExportKind indicates the kind of data exported by an exporter. -// These bits may be OR-d together when multiple exporters are in use. -type ExportKind int - -const ( - // CumulativeExportKind indicates that an Exporter expects a - // Cumulative Aggregation. - CumulativeExportKind ExportKind = 1 - - // DeltaExportKind indicates that an Exporter expects a - // Delta Aggregation. - DeltaExportKind ExportKind = 2 -) - -// Includes tests whether `kind` includes a specific kind of -// exporter. -func (kind ExportKind) Includes(has ExportKind) bool { - return kind&has != 0 -} - -// MemoryRequired returns whether an exporter of this kind requires -// memory to export correctly. -func (kind ExportKind) MemoryRequired(mkind metric.InstrumentKind) bool { - switch mkind { - case metric.ValueRecorderInstrumentKind, metric.ValueObserverInstrumentKind, - metric.CounterInstrumentKind, metric.UpDownCounterInstrumentKind: - // Delta-oriented instruments: - return kind.Includes(CumulativeExportKind) - - case metric.SumObserverInstrumentKind, metric.UpDownSumObserverInstrumentKind: - // Cumulative-oriented instruments: - return kind.Includes(DeltaExportKind) - } - // Something unexpected is happening--we could panic. This - // will become an error when the exporter tries to access a - // checkpoint, presumably, so let it be. - return false -} - -type ( - constantExportKindSelector ExportKind - statelessExportKindSelector struct{} -) - -var ( - _ ExportKindSelector = constantExportKindSelector(0) - _ ExportKindSelector = statelessExportKindSelector{} -) - -// ConstantExportKindSelector returns an ExportKindSelector that returns -// a constant ExportKind, one that is either always cumulative or always delta. -func ConstantExportKindSelector(kind ExportKind) ExportKindSelector { - return constantExportKindSelector(kind) -} - -// CumulativeExportKindSelector returns an ExportKindSelector that -// always returns CumulativeExportKind. -func CumulativeExportKindSelector() ExportKindSelector { - return ConstantExportKindSelector(CumulativeExportKind) -} - -// DeltaExportKindSelector returns an ExportKindSelector that -// always returns DeltaExportKind. -func DeltaExportKindSelector() ExportKindSelector { - return ConstantExportKindSelector(DeltaExportKind) -} - -// StatelessExportKindSelector returns an ExportKindSelector that -// always returns the ExportKind that avoids long-term memory -// requirements. -func StatelessExportKindSelector() ExportKindSelector { - return statelessExportKindSelector{} -} - -// ExportKindFor implements ExportKindSelector. -func (c constantExportKindSelector) ExportKindFor(_ *metric.Descriptor, _ aggregation.Kind) ExportKind { - return ExportKind(c) -} - -// ExportKindFor implements ExportKindSelector. -func (s statelessExportKindSelector) ExportKindFor(desc *metric.Descriptor, kind aggregation.Kind) ExportKind { - if kind == aggregation.SumKind && desc.InstrumentKind().PrecomputedSum() { - return CumulativeExportKind - } - return DeltaExportKind -} diff --git a/vendor/go.opentelemetry.io/otel/sdk/instrumentation/library.go b/vendor/go.opentelemetry.io/otel/sdk/instrumentation/library.go deleted file mode 100644 index c897c04de3..0000000000 --- a/vendor/go.opentelemetry.io/otel/sdk/instrumentation/library.go +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/* -Package instrumentation provides an instrumentation library structure to be -passed to both the OpenTelemetry Tracer and Meter components. - -This package is currently in a pre-GA phase. Backwards incompatible changes -may be introduced in subsequent minor version releases as we work to track the -evolving OpenTelemetry specification and user feedback. - -For more information see -[this](https://github.com/open-telemetry/oteps/blob/main/text/0083-component.md). -*/ -package instrumentation // import "go.opentelemetry.io/otel/sdk/instrumentation" - -// Library represents the instrumentation library. -type Library struct { - // Name is the name of the instrumentation library. This should be the - // Go package name of that library. - Name string - // Version is the version of the instrumentation library. - Version string -} diff --git a/vendor/go.opentelemetry.io/otel/sdk/internal/internal.go b/vendor/go.opentelemetry.io/otel/sdk/internal/internal.go deleted file mode 100644 index 84a02306e6..0000000000 --- a/vendor/go.opentelemetry.io/otel/sdk/internal/internal.go +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package internal // import "go.opentelemetry.io/otel/sdk/internal" - -import ( - "fmt" - "time" - - "go.opentelemetry.io/otel" -) - -// UserAgent is the user agent to be added to the outgoing -// requests from the exporters. -var UserAgent = fmt.Sprintf("opentelemetry-go/%s", otel.Version()) - -// MonotonicEndTime returns the end time at present -// but offset from start, monotonically. -// -// The monotonic clock is used in subtractions hence -// the duration since start added back to start gives -// end as a monotonic time. -// See https://golang.org/pkg/time/#hdr-Monotonic_Clocks -func MonotonicEndTime(start time.Time) time.Time { - return start.Add(time.Since(start)) -} diff --git a/vendor/go.opentelemetry.io/otel/sdk/internal/sanitize.go b/vendor/go.opentelemetry.io/otel/sdk/internal/sanitize.go deleted file mode 100644 index e6d8b7d599..0000000000 --- a/vendor/go.opentelemetry.io/otel/sdk/internal/sanitize.go +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package internal - -import ( - "strings" - "unicode" -) - -const labelKeySizeLimit = 100 - -// Sanitize returns a string that is trunacated to 100 characters if it's too -// long, and replaces non-alphanumeric characters to underscores. -func Sanitize(s string) string { - if len(s) == 0 { - return s - } - if len(s) > labelKeySizeLimit { - s = s[:labelKeySizeLimit] - } - s = strings.Map(sanitizeRune, s) - if unicode.IsDigit(rune(s[0])) { - s = "key_" + s - } - if s[0] == '_' { - s = "key" + s - } - return s -} - -// converts anything that is not a letter or digit to an underscore -func sanitizeRune(r rune) rune { - if unicode.IsLetter(r) || unicode.IsDigit(r) { - return r - } - // Everything else turns into an underscore - return '_' -} diff --git a/vendor/go.opentelemetry.io/otel/sdk/metric/LICENSE b/vendor/go.opentelemetry.io/otel/sdk/metric/LICENSE deleted file mode 100644 index 261eeb9e9f..0000000000 --- a/vendor/go.opentelemetry.io/otel/sdk/metric/LICENSE +++ /dev/null @@ -1,201 +0,0 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. diff --git a/vendor/go.opentelemetry.io/otel/sdk/metric/aggregator/aggregator.go b/vendor/go.opentelemetry.io/otel/sdk/metric/aggregator/aggregator.go deleted file mode 100644 index afda991e86..0000000000 --- a/vendor/go.opentelemetry.io/otel/sdk/metric/aggregator/aggregator.go +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package aggregator // import "go.opentelemetry.io/otel/sdk/metric/aggregator" - -import ( - "fmt" - "math" - - "go.opentelemetry.io/otel/metric" - "go.opentelemetry.io/otel/metric/number" - export "go.opentelemetry.io/otel/sdk/export/metric" - "go.opentelemetry.io/otel/sdk/export/metric/aggregation" -) - -// NewInconsistentAggregatorError formats an error describing an attempt to -// Checkpoint or Merge different-type aggregators. The result can be unwrapped as -// an ErrInconsistentType. -func NewInconsistentAggregatorError(a1, a2 export.Aggregator) error { - return fmt.Errorf("%w: %T and %T", aggregation.ErrInconsistentType, a1, a2) -} - -// RangeTest is a common routine for testing for valid input values. -// This rejects NaN values. This rejects negative values when the -// metric instrument does not support negative values, including -// monotonic counter metrics and absolute ValueRecorder metrics. -func RangeTest(num number.Number, descriptor *metric.Descriptor) error { - numberKind := descriptor.NumberKind() - - if numberKind == number.Float64Kind && math.IsNaN(num.AsFloat64()) { - return aggregation.ErrNaNInput - } - - switch descriptor.InstrumentKind() { - case metric.CounterInstrumentKind, metric.SumObserverInstrumentKind: - if num.IsNegative(numberKind) { - return aggregation.ErrNegativeInput - } - } - return nil -} diff --git a/vendor/go.opentelemetry.io/otel/sdk/metric/aggregator/exact/exact.go b/vendor/go.opentelemetry.io/otel/sdk/metric/aggregator/exact/exact.go deleted file mode 100644 index c2c7adaf25..0000000000 --- a/vendor/go.opentelemetry.io/otel/sdk/metric/aggregator/exact/exact.go +++ /dev/null @@ -1,130 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package exact // import "go.opentelemetry.io/otel/sdk/metric/aggregator/exact" - -import ( - "context" - "sync" - "time" - - "go.opentelemetry.io/otel/metric" - "go.opentelemetry.io/otel/metric/number" - export "go.opentelemetry.io/otel/sdk/export/metric" - "go.opentelemetry.io/otel/sdk/export/metric/aggregation" - "go.opentelemetry.io/otel/sdk/metric/aggregator" -) - -type ( - // Aggregator aggregates events that form a distribution, keeping - // an array with the exact set of values. - Aggregator struct { - lock sync.Mutex - samples []aggregation.Point - } -) - -var _ export.Aggregator = &Aggregator{} -var _ aggregation.Points = &Aggregator{} -var _ aggregation.Count = &Aggregator{} - -// New returns cnt many new exact aggregators, which aggregate recorded -// measurements by storing them in an array. This type uses a mutex -// for Update() and SynchronizedMove() concurrency. -func New(cnt int) []Aggregator { - return make([]Aggregator, cnt) -} - -// Aggregation returns an interface for reading the state of this aggregator. -func (c *Aggregator) Aggregation() aggregation.Aggregation { - return c -} - -// Kind returns aggregation.ExactKind. -func (c *Aggregator) Kind() aggregation.Kind { - return aggregation.ExactKind -} - -// Count returns the number of values in the checkpoint. -func (c *Aggregator) Count() (uint64, error) { - return uint64(len(c.samples)), nil -} - -// Points returns access to the raw data set. -func (c *Aggregator) Points() ([]aggregation.Point, error) { - return c.samples, nil -} - -// SynchronizedMove saves the current state to oa and resets the current state to -// the empty set, taking a lock to prevent concurrent Update() calls. -func (c *Aggregator) SynchronizedMove(oa export.Aggregator, desc *metric.Descriptor) error { - o, _ := oa.(*Aggregator) - - if oa != nil && o == nil { - return aggregator.NewInconsistentAggregatorError(c, oa) - } - - c.lock.Lock() - defer c.lock.Unlock() - - if o != nil { - o.samples = c.samples - } - c.samples = nil - - return nil -} - -// Update adds the recorded measurement to the current data set. -// Update takes a lock to prevent concurrent Update() and SynchronizedMove() -// calls. -func (c *Aggregator) Update(_ context.Context, number number.Number, desc *metric.Descriptor) error { - now := time.Now() - c.lock.Lock() - defer c.lock.Unlock() - c.samples = append(c.samples, aggregation.Point{ - Number: number, - Time: now, - }) - - return nil -} - -// Merge combines two data sets into one. -func (c *Aggregator) Merge(oa export.Aggregator, desc *metric.Descriptor) error { - o, _ := oa.(*Aggregator) - if o == nil { - return aggregator.NewInconsistentAggregatorError(c, oa) - } - - c.samples = combine(c.samples, o.samples) - return nil -} - -func combine(a, b []aggregation.Point) []aggregation.Point { - result := make([]aggregation.Point, 0, len(a)+len(b)) - - for len(a) != 0 && len(b) != 0 { - if a[0].Time.Before(b[0].Time) { - result = append(result, a[0]) - a = a[1:] - } else { - result = append(result, b[0]) - b = b[1:] - } - } - result = append(result, a...) - result = append(result, b...) - return result -} diff --git a/vendor/go.opentelemetry.io/otel/sdk/metric/aggregator/histogram/histogram.go b/vendor/go.opentelemetry.io/otel/sdk/metric/aggregator/histogram/histogram.go deleted file mode 100644 index ea3ecdbb5b..0000000000 --- a/vendor/go.opentelemetry.io/otel/sdk/metric/aggregator/histogram/histogram.go +++ /dev/null @@ -1,270 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package histogram // import "go.opentelemetry.io/otel/sdk/metric/aggregator/histogram" - -import ( - "context" - "sort" - "sync" - - "go.opentelemetry.io/otel/metric" - "go.opentelemetry.io/otel/metric/number" - export "go.opentelemetry.io/otel/sdk/export/metric" - "go.opentelemetry.io/otel/sdk/export/metric/aggregation" - "go.opentelemetry.io/otel/sdk/metric/aggregator" -) - -// Note: This code uses a Mutex to govern access to the exclusive -// aggregator state. This is in contrast to a lock-free approach -// (as in the Go prometheus client) that was reverted here: -// https://github.com/open-telemetry/opentelemetry-go/pull/669 - -type ( - // Aggregator observe events and counts them in pre-determined buckets. - // It also calculates the sum and count of all events. - Aggregator struct { - lock sync.Mutex - boundaries []float64 - kind number.Kind - state *state - } - - // config describes how the histogram is aggregated. - config struct { - // explicitBoundaries support arbitrary bucketing schemes. This - // is the general case. - explicitBoundaries []float64 - } - - // Option configures a histogram config. - Option interface { - // apply sets one or more config fields. - apply(*config) - } - - // state represents the state of a histogram, consisting of - // the sum and counts for all observed values and - // the less than equal bucket count for the pre-determined boundaries. - state struct { - bucketCounts []uint64 - sum number.Number - count uint64 - } -) - -// WithExplicitBoundaries sets the ExplicitBoundaries configuration option of a config. -func WithExplicitBoundaries(explicitBoundaries []float64) Option { - return explicitBoundariesOption{explicitBoundaries} -} - -type explicitBoundariesOption struct { - boundaries []float64 -} - -func (o explicitBoundariesOption) apply(config *config) { - config.explicitBoundaries = o.boundaries -} - -// defaultExplicitBoundaries have been copied from prometheus.DefBuckets. -// -// Note we anticipate the use of a high-precision histogram sketch as -// the standard histogram aggregator for OTLP export. -// (https://github.com/open-telemetry/opentelemetry-specification/issues/982). -var defaultFloat64ExplicitBoundaries = []float64{.005, .01, .025, .05, .1, .25, .5, 1, 2.5, 5, 10} - -// defaultInt64ExplicitBoundaryMultiplier determines the default -// integer histogram boundaries. -const defaultInt64ExplicitBoundaryMultiplier = 1e6 - -// defaultInt64ExplicitBoundaries applies a multiplier to the default -// float64 boundaries: [ 5K, 10K, 25K, ..., 2.5M, 5M, 10M ] -var defaultInt64ExplicitBoundaries = func(bounds []float64) (asint []float64) { - for _, f := range bounds { - asint = append(asint, defaultInt64ExplicitBoundaryMultiplier*f) - } - return -}(defaultFloat64ExplicitBoundaries) - -var _ export.Aggregator = &Aggregator{} -var _ aggregation.Sum = &Aggregator{} -var _ aggregation.Count = &Aggregator{} -var _ aggregation.Histogram = &Aggregator{} - -// New returns a new aggregator for computing Histograms. -// -// A Histogram observe events and counts them in pre-defined buckets. -// And also provides the total sum and count of all observations. -// -// Note that this aggregator maintains each value using independent -// atomic operations, which introduces the possibility that -// checkpoints are inconsistent. -func New(cnt int, desc *metric.Descriptor, opts ...Option) []Aggregator { - var cfg config - - if desc.NumberKind() == number.Int64Kind { - cfg.explicitBoundaries = defaultInt64ExplicitBoundaries - } else { - cfg.explicitBoundaries = defaultFloat64ExplicitBoundaries - } - - for _, opt := range opts { - opt.apply(&cfg) - } - - aggs := make([]Aggregator, cnt) - - // Boundaries MUST be ordered otherwise the histogram could not - // be properly computed. - sortedBoundaries := make([]float64, len(cfg.explicitBoundaries)) - - copy(sortedBoundaries, cfg.explicitBoundaries) - sort.Float64s(sortedBoundaries) - - for i := range aggs { - aggs[i] = Aggregator{ - kind: desc.NumberKind(), - boundaries: sortedBoundaries, - } - aggs[i].state = aggs[i].newState() - } - return aggs -} - -// Aggregation returns an interface for reading the state of this aggregator. -func (c *Aggregator) Aggregation() aggregation.Aggregation { - return c -} - -// Kind returns aggregation.HistogramKind. -func (c *Aggregator) Kind() aggregation.Kind { - return aggregation.HistogramKind -} - -// Sum returns the sum of all values in the checkpoint. -func (c *Aggregator) Sum() (number.Number, error) { - return c.state.sum, nil -} - -// Count returns the number of values in the checkpoint. -func (c *Aggregator) Count() (uint64, error) { - return c.state.count, nil -} - -// Histogram returns the count of events in pre-determined buckets. -func (c *Aggregator) Histogram() (aggregation.Buckets, error) { - return aggregation.Buckets{ - Boundaries: c.boundaries, - Counts: c.state.bucketCounts, - }, nil -} - -// SynchronizedMove saves the current state into oa and resets the current state to -// the empty set. Since no locks are taken, there is a chance that -// the independent Sum, Count and Bucket Count are not consistent with each -// other. -func (c *Aggregator) SynchronizedMove(oa export.Aggregator, desc *metric.Descriptor) error { - o, _ := oa.(*Aggregator) - - if oa != nil && o == nil { - return aggregator.NewInconsistentAggregatorError(c, oa) - } - - if o != nil { - // Swap case: This is the ordinary case for a - // synchronous instrument, where the SDK allocates two - // Aggregators and lock contention is anticipated. - // Reset the target state before swapping it under the - // lock below. - o.clearState() - } - - c.lock.Lock() - if o != nil { - c.state, o.state = o.state, c.state - } else { - // No swap case: This is the ordinary case for an - // asynchronous instrument, where the SDK allocates a - // single Aggregator and there is no anticipated lock - // contention. - c.clearState() - } - c.lock.Unlock() - - return nil -} - -func (c *Aggregator) newState() *state { - return &state{ - bucketCounts: make([]uint64, len(c.boundaries)+1), - } -} - -func (c *Aggregator) clearState() { - for i := range c.state.bucketCounts { - c.state.bucketCounts[i] = 0 - } - c.state.sum = 0 - c.state.count = 0 -} - -// Update adds the recorded measurement to the current data set. -func (c *Aggregator) Update(_ context.Context, number number.Number, desc *metric.Descriptor) error { - kind := desc.NumberKind() - asFloat := number.CoerceToFloat64(kind) - - bucketID := len(c.boundaries) - for i, boundary := range c.boundaries { - if asFloat < boundary { - bucketID = i - break - } - } - // Note: Binary-search was compared using the benchmarks. The following - // code is equivalent to the linear search above: - // - // bucketID := sort.Search(len(c.boundaries), func(i int) bool { - // return asFloat < c.boundaries[i] - // }) - // - // The binary search wins for very large boundary sets, but - // the linear search performs better up through arrays between - // 256 and 512 elements, which is a relatively large histogram, so we - // continue to prefer linear search. - - c.lock.Lock() - defer c.lock.Unlock() - - c.state.count++ - c.state.sum.AddNumber(kind, number) - c.state.bucketCounts[bucketID]++ - - return nil -} - -// Merge combines two histograms that have the same buckets into a single one. -func (c *Aggregator) Merge(oa export.Aggregator, desc *metric.Descriptor) error { - o, _ := oa.(*Aggregator) - if o == nil { - return aggregator.NewInconsistentAggregatorError(c, oa) - } - - c.state.sum.AddNumber(desc.NumberKind(), o.state.sum) - c.state.count += o.state.count - - for i := 0; i < len(c.state.bucketCounts); i++ { - c.state.bucketCounts[i] += o.state.bucketCounts[i] - } - return nil -} diff --git a/vendor/go.opentelemetry.io/otel/sdk/metric/aggregator/lastvalue/lastvalue.go b/vendor/go.opentelemetry.io/otel/sdk/metric/aggregator/lastvalue/lastvalue.go deleted file mode 100644 index 3cc5f7055c..0000000000 --- a/vendor/go.opentelemetry.io/otel/sdk/metric/aggregator/lastvalue/lastvalue.go +++ /dev/null @@ -1,135 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package lastvalue // import "go.opentelemetry.io/otel/sdk/metric/aggregator/lastvalue" - -import ( - "context" - "sync/atomic" - "time" - "unsafe" - - "go.opentelemetry.io/otel/metric" - "go.opentelemetry.io/otel/metric/number" - export "go.opentelemetry.io/otel/sdk/export/metric" - "go.opentelemetry.io/otel/sdk/export/metric/aggregation" - "go.opentelemetry.io/otel/sdk/metric/aggregator" -) - -type ( - - // Aggregator aggregates lastValue events. - Aggregator struct { - // value is an atomic pointer to *lastValueData. It is never nil. - value unsafe.Pointer - } - - // lastValueData stores the current value of a lastValue along with - // a sequence number to determine the winner of a race. - lastValueData struct { - // value is the int64- or float64-encoded Set() data - // - // value needs to be aligned for 64-bit atomic operations. - value number.Number - - // timestamp indicates when this record was submitted. - // this can be used to pick a winner when multiple - // records contain lastValue data for the same labels due - // to races. - timestamp time.Time - } -) - -var _ export.Aggregator = &Aggregator{} -var _ aggregation.LastValue = &Aggregator{} - -// An unset lastValue has zero timestamp and zero value. -var unsetLastValue = &lastValueData{} - -// New returns a new lastValue aggregator. This aggregator retains the -// last value and timestamp that were recorded. -func New(cnt int) []Aggregator { - aggs := make([]Aggregator, cnt) - for i := range aggs { - aggs[i] = Aggregator{ - value: unsafe.Pointer(unsetLastValue), - } - } - return aggs -} - -// Aggregation returns an interface for reading the state of this aggregator. -func (g *Aggregator) Aggregation() aggregation.Aggregation { - return g -} - -// Kind returns aggregation.LastValueKind. -func (g *Aggregator) Kind() aggregation.Kind { - return aggregation.LastValueKind -} - -// LastValue returns the last-recorded lastValue value and the -// corresponding timestamp. The error value aggregation.ErrNoData -// will be returned if (due to a race condition) the checkpoint was -// computed before the first value was set. -func (g *Aggregator) LastValue() (number.Number, time.Time, error) { - gd := (*lastValueData)(g.value) - if gd == unsetLastValue { - return 0, time.Time{}, aggregation.ErrNoData - } - return gd.value.AsNumber(), gd.timestamp, nil -} - -// SynchronizedMove atomically saves the current value. -func (g *Aggregator) SynchronizedMove(oa export.Aggregator, _ *metric.Descriptor) error { - if oa == nil { - atomic.StorePointer(&g.value, unsafe.Pointer(unsetLastValue)) - return nil - } - o, _ := oa.(*Aggregator) - if o == nil { - return aggregator.NewInconsistentAggregatorError(g, oa) - } - o.value = atomic.SwapPointer(&g.value, unsafe.Pointer(unsetLastValue)) - return nil -} - -// Update atomically sets the current "last" value. -func (g *Aggregator) Update(_ context.Context, number number.Number, desc *metric.Descriptor) error { - ngd := &lastValueData{ - value: number, - timestamp: time.Now(), - } - atomic.StorePointer(&g.value, unsafe.Pointer(ngd)) - return nil -} - -// Merge combines state from two aggregators. The most-recently set -// value is chosen. -func (g *Aggregator) Merge(oa export.Aggregator, desc *metric.Descriptor) error { - o, _ := oa.(*Aggregator) - if o == nil { - return aggregator.NewInconsistentAggregatorError(g, oa) - } - - ggd := (*lastValueData)(atomic.LoadPointer(&g.value)) - ogd := (*lastValueData)(atomic.LoadPointer(&o.value)) - - if ggd.timestamp.After(ogd.timestamp) { - return nil - } - - g.value = unsafe.Pointer(ogd) - return nil -} diff --git a/vendor/go.opentelemetry.io/otel/sdk/metric/aggregator/minmaxsumcount/mmsc.go b/vendor/go.opentelemetry.io/otel/sdk/metric/aggregator/minmaxsumcount/mmsc.go deleted file mode 100644 index e21fd75ab7..0000000000 --- a/vendor/go.opentelemetry.io/otel/sdk/metric/aggregator/minmaxsumcount/mmsc.go +++ /dev/null @@ -1,165 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package minmaxsumcount // import "go.opentelemetry.io/otel/sdk/metric/aggregator/minmaxsumcount" - -import ( - "context" - "sync" - - "go.opentelemetry.io/otel/metric" - "go.opentelemetry.io/otel/metric/number" - export "go.opentelemetry.io/otel/sdk/export/metric" - "go.opentelemetry.io/otel/sdk/export/metric/aggregation" - "go.opentelemetry.io/otel/sdk/metric/aggregator" -) - -type ( - // Aggregator aggregates events that form a distribution, - // keeping only the min, max, sum, and count. - Aggregator struct { - lock sync.Mutex - kind number.Kind - state - } - - state struct { - sum number.Number - min number.Number - max number.Number - count uint64 - } -) - -var _ export.Aggregator = &Aggregator{} -var _ aggregation.MinMaxSumCount = &Aggregator{} - -// New returns a new aggregator for computing the min, max, sum, and -// count. -// -// This type uses a mutex for Update() and SynchronizedMove() concurrency. -func New(cnt int, desc *metric.Descriptor) []Aggregator { - kind := desc.NumberKind() - aggs := make([]Aggregator, cnt) - for i := range aggs { - aggs[i] = Aggregator{ - kind: kind, - state: emptyState(kind), - } - } - return aggs -} - -// Aggregation returns an interface for reading the state of this aggregator. -func (c *Aggregator) Aggregation() aggregation.Aggregation { - return c -} - -// Kind returns aggregation.MinMaxSumCountKind. -func (c *Aggregator) Kind() aggregation.Kind { - return aggregation.MinMaxSumCountKind -} - -// Sum returns the sum of values in the checkpoint. -func (c *Aggregator) Sum() (number.Number, error) { - return c.sum, nil -} - -// Count returns the number of values in the checkpoint. -func (c *Aggregator) Count() (uint64, error) { - return c.count, nil -} - -// Min returns the minimum value in the checkpoint. -// The error value aggregation.ErrNoData will be returned -// if there were no measurements recorded during the checkpoint. -func (c *Aggregator) Min() (number.Number, error) { - if c.count == 0 { - return 0, aggregation.ErrNoData - } - return c.min, nil -} - -// Max returns the maximum value in the checkpoint. -// The error value aggregation.ErrNoData will be returned -// if there were no measurements recorded during the checkpoint. -func (c *Aggregator) Max() (number.Number, error) { - if c.count == 0 { - return 0, aggregation.ErrNoData - } - return c.max, nil -} - -// SynchronizedMove saves the current state into oa and resets the current state to -// the empty set. -func (c *Aggregator) SynchronizedMove(oa export.Aggregator, desc *metric.Descriptor) error { - o, _ := oa.(*Aggregator) - - if oa != nil && o == nil { - return aggregator.NewInconsistentAggregatorError(c, oa) - } - c.lock.Lock() - if o != nil { - o.state = c.state - } - c.state = emptyState(c.kind) - c.lock.Unlock() - - return nil -} - -func emptyState(kind number.Kind) state { - return state{ - count: 0, - sum: 0, - min: kind.Maximum(), - max: kind.Minimum(), - } -} - -// Update adds the recorded measurement to the current data set. -func (c *Aggregator) Update(_ context.Context, number number.Number, desc *metric.Descriptor) error { - kind := desc.NumberKind() - - c.lock.Lock() - defer c.lock.Unlock() - c.count++ - c.sum.AddNumber(kind, number) - if number.CompareNumber(kind, c.min) < 0 { - c.min = number - } - if number.CompareNumber(kind, c.max) > 0 { - c.max = number - } - return nil -} - -// Merge combines two data sets into one. -func (c *Aggregator) Merge(oa export.Aggregator, desc *metric.Descriptor) error { - o, _ := oa.(*Aggregator) - if o == nil { - return aggregator.NewInconsistentAggregatorError(c, oa) - } - - c.count += o.count - c.sum.AddNumber(desc.NumberKind(), o.sum) - - if c.min.CompareNumber(desc.NumberKind(), o.min) > 0 { - c.min.SetNumber(o.min) - } - if c.max.CompareNumber(desc.NumberKind(), o.max) < 0 { - c.max.SetNumber(o.max) - } - return nil -} diff --git a/vendor/go.opentelemetry.io/otel/sdk/metric/aggregator/sum/sum.go b/vendor/go.opentelemetry.io/otel/sdk/metric/aggregator/sum/sum.go deleted file mode 100644 index fc96ddb4cb..0000000000 --- a/vendor/go.opentelemetry.io/otel/sdk/metric/aggregator/sum/sum.go +++ /dev/null @@ -1,106 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package sum // import "go.opentelemetry.io/otel/sdk/metric/aggregator/sum" - -import ( - "context" - - "go.opentelemetry.io/otel/metric" - "go.opentelemetry.io/otel/metric/number" - export "go.opentelemetry.io/otel/sdk/export/metric" - "go.opentelemetry.io/otel/sdk/export/metric/aggregation" - "go.opentelemetry.io/otel/sdk/metric/aggregator" -) - -// Aggregator aggregates counter events. -type Aggregator struct { - // current holds current increments to this counter record - // current needs to be aligned for 64-bit atomic operations. - value number.Number -} - -var _ export.Aggregator = &Aggregator{} -var _ export.Subtractor = &Aggregator{} -var _ aggregation.Sum = &Aggregator{} - -// New returns a new counter aggregator implemented by atomic -// operations. This aggregator implements the aggregation.Sum -// export interface. -func New(cnt int) []Aggregator { - return make([]Aggregator, cnt) -} - -// Aggregation returns an interface for reading the state of this aggregator. -func (c *Aggregator) Aggregation() aggregation.Aggregation { - return c -} - -// Kind returns aggregation.SumKind. -func (c *Aggregator) Kind() aggregation.Kind { - return aggregation.SumKind -} - -// Sum returns the last-checkpointed sum. This will never return an -// error. -func (c *Aggregator) Sum() (number.Number, error) { - return c.value, nil -} - -// SynchronizedMove atomically saves the current value into oa and resets the -// current sum to zero. -func (c *Aggregator) SynchronizedMove(oa export.Aggregator, _ *metric.Descriptor) error { - if oa == nil { - c.value.SetRawAtomic(0) - return nil - } - o, _ := oa.(*Aggregator) - if o == nil { - return aggregator.NewInconsistentAggregatorError(c, oa) - } - o.value = c.value.SwapNumberAtomic(number.Number(0)) - return nil -} - -// Update atomically adds to the current value. -func (c *Aggregator) Update(_ context.Context, num number.Number, desc *metric.Descriptor) error { - c.value.AddNumberAtomic(desc.NumberKind(), num) - return nil -} - -// Merge combines two counters by adding their sums. -func (c *Aggregator) Merge(oa export.Aggregator, desc *metric.Descriptor) error { - o, _ := oa.(*Aggregator) - if o == nil { - return aggregator.NewInconsistentAggregatorError(c, oa) - } - c.value.AddNumber(desc.NumberKind(), o.value) - return nil -} - -func (c *Aggregator) Subtract(opAgg, resAgg export.Aggregator, descriptor *metric.Descriptor) error { - op, _ := opAgg.(*Aggregator) - if op == nil { - return aggregator.NewInconsistentAggregatorError(c, opAgg) - } - - res, _ := resAgg.(*Aggregator) - if res == nil { - return aggregator.NewInconsistentAggregatorError(c, resAgg) - } - - res.value = c.value - res.value.AddNumber(descriptor.NumberKind(), number.NewNumberSignChange(descriptor.NumberKind(), op.value)) - return nil -} diff --git a/vendor/go.opentelemetry.io/otel/sdk/metric/atomicfields.go b/vendor/go.opentelemetry.io/otel/sdk/metric/atomicfields.go deleted file mode 100644 index bcb56b7eaa..0000000000 --- a/vendor/go.opentelemetry.io/otel/sdk/metric/atomicfields.go +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package metric // import "go.opentelemetry.io/otel/sdk/metric" - -import "unsafe" - -func AtomicFieldOffsets() map[string]uintptr { - return map[string]uintptr{ - "record.refMapped.value": unsafe.Offsetof(record{}.refMapped.value), - "record.updateCount": unsafe.Offsetof(record{}.updateCount), - } -} diff --git a/vendor/go.opentelemetry.io/otel/sdk/metric/controller/basic/config.go b/vendor/go.opentelemetry.io/otel/sdk/metric/controller/basic/config.go deleted file mode 100644 index 87be85b900..0000000000 --- a/vendor/go.opentelemetry.io/otel/sdk/metric/controller/basic/config.go +++ /dev/null @@ -1,122 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package basic // import "go.opentelemetry.io/otel/sdk/metric/controller/basic" - -import ( - "time" - - export "go.opentelemetry.io/otel/sdk/export/metric" - "go.opentelemetry.io/otel/sdk/resource" -) - -// Config contains configuration for a basic Controller. -type Config struct { - // Resource is the OpenTelemetry resource associated with all Meters - // created by the Controller. - Resource *resource.Resource - - // CollectPeriod is the interval between calls to Collect a - // checkpoint. - // - // When pulling metrics and not exporting, this is the minimum - // time between calls to Collect. In a pull-only - // configuration, collection is performed on demand; set - // CollectPeriod to 0 always recompute the export record set. - // - // When exporting metrics, this must be > 0. - // - // Default value is 10s. - CollectPeriod time.Duration - - // CollectTimeout is the timeout of the Context passed to - // Collect() and subsequently to Observer instrument callbacks. - // - // Default value is 10s. If zero, no Collect timeout is applied. - CollectTimeout time.Duration - - // Exporter is used for exporting metric data. - // - // Note: Exporters such as Prometheus that pull data do not implement - // export.Exporter. These will directly call Collect() and ForEach(). - Exporter export.Exporter - - // PushTimeout is the timeout of the Context when a exporter is configured. - // - // Default value is 10s. If zero, no Export timeout is applied. - PushTimeout time.Duration -} - -// Option is the interface that applies the value to a configuration option. -type Option interface { - // Apply sets the Option value of a Config. - Apply(*Config) -} - -// WithResource sets the Resource configuration option of a Config by merging it -// with the Resource configuration in the environment. -func WithResource(r *resource.Resource) Option { - res := resource.Merge(resource.Environment(), r) - return resourceOption{res} -} - -type resourceOption struct{ *resource.Resource } - -func (o resourceOption) Apply(config *Config) { - config.Resource = o.Resource -} - -// WithCollectPeriod sets the CollectPeriod configuration option of a Config. -func WithCollectPeriod(period time.Duration) Option { - return collectPeriodOption(period) -} - -type collectPeriodOption time.Duration - -func (o collectPeriodOption) Apply(config *Config) { - config.CollectPeriod = time.Duration(o) -} - -// WithCollectTimeout sets the CollectTimeout configuration option of a Config. -func WithCollectTimeout(timeout time.Duration) Option { - return collectTimeoutOption(timeout) -} - -type collectTimeoutOption time.Duration - -func (o collectTimeoutOption) Apply(config *Config) { - config.CollectTimeout = time.Duration(o) -} - -// WithExporter sets the exporter configuration option of a Config. -func WithExporter(exporter export.Exporter) Option { - return exporterOption{exporter} -} - -type exporterOption struct{ exporter export.Exporter } - -func (o exporterOption) Apply(config *Config) { - config.Exporter = o.exporter -} - -// WithPushTimeout sets the PushTimeout configuration option of a Config. -func WithPushTimeout(timeout time.Duration) Option { - return pushTimeoutOption(timeout) -} - -type pushTimeoutOption time.Duration - -func (o pushTimeoutOption) Apply(config *Config) { - config.PushTimeout = time.Duration(o) -} diff --git a/vendor/go.opentelemetry.io/otel/sdk/metric/controller/basic/controller.go b/vendor/go.opentelemetry.io/otel/sdk/metric/controller/basic/controller.go deleted file mode 100644 index 9a2e12777b..0000000000 --- a/vendor/go.opentelemetry.io/otel/sdk/metric/controller/basic/controller.go +++ /dev/null @@ -1,312 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package basic // import "go.opentelemetry.io/otel/sdk/metric/controller/basic" - -import ( - "context" - "fmt" - "sync" - "time" - - "go.opentelemetry.io/otel" - "go.opentelemetry.io/otel/metric" - "go.opentelemetry.io/otel/metric/registry" - export "go.opentelemetry.io/otel/sdk/export/metric" - sdk "go.opentelemetry.io/otel/sdk/metric" - controllerTime "go.opentelemetry.io/otel/sdk/metric/controller/time" - "go.opentelemetry.io/otel/sdk/resource" -) - -// DefaultPeriod is used for: -// -// - the minimum time between calls to Collect() -// - the timeout for Export() -// - the timeout for Collect(). -const DefaultPeriod = 10 * time.Second - -// ErrControllerStarted indicates that a controller was started more -// than once. -var ErrControllerStarted = fmt.Errorf("controller already started") - -// Controller organizes and synchronizes collection of metric data in -// both "pull" and "push" configurations. This supports two distinct -// modes: -// -// - Push and Pull: Start() must be called to begin calling the exporter; -// Collect() is called periodically by a background thread after starting -// the controller. -// - Pull-Only: Start() is optional in this case, to call Collect periodically. -// If Start() is not called, Collect() can be called manually to initiate -// collection -// -// The controller supports mixing push and pull access to metric data -// using the export.CheckpointSet RWLock interface. Collection will -// be blocked by a pull request in the basic controller. -type Controller struct { - lock sync.Mutex - accumulator *sdk.Accumulator - provider *registry.MeterProvider - checkpointer export.Checkpointer - exporter export.Exporter - wg sync.WaitGroup - stopCh chan struct{} - clock controllerTime.Clock - ticker controllerTime.Ticker - - collectPeriod time.Duration - collectTimeout time.Duration - pushTimeout time.Duration - - // collectedTime is used only in configurations with no - // exporter, when ticker != nil. - collectedTime time.Time -} - -// New constructs a Controller using the provided checkpointer and -// options (including optional exporter) to configure a metric -// export pipeline. -func New(checkpointer export.Checkpointer, opts ...Option) *Controller { - c := &Config{ - CollectPeriod: DefaultPeriod, - CollectTimeout: DefaultPeriod, - PushTimeout: DefaultPeriod, - } - for _, opt := range opts { - opt.Apply(c) - } - if c.Resource == nil { - c.Resource = resource.Default() - } - - impl := sdk.NewAccumulator( - checkpointer, - c.Resource, - ) - return &Controller{ - provider: registry.NewMeterProvider(impl), - accumulator: impl, - checkpointer: checkpointer, - exporter: c.Exporter, - stopCh: nil, - clock: controllerTime.RealClock{}, - - collectPeriod: c.CollectPeriod, - collectTimeout: c.CollectTimeout, - pushTimeout: c.PushTimeout, - } -} - -// SetClock supports setting a mock clock for testing. This must be -// called before Start(). -func (c *Controller) SetClock(clock controllerTime.Clock) { - c.lock.Lock() - defer c.lock.Unlock() - c.clock = clock -} - -// MeterProvider returns a MeterProvider instance for this controller. -func (c *Controller) MeterProvider() metric.MeterProvider { - return c.provider -} - -// Start begins a ticker that periodically collects and exports -// metrics with the configured interval. This is required for calling -// a configured Exporter (see WithExporter) and is otherwise optional -// when only pulling metric data. -// -// The passed context is passed to Collect() and subsequently to -// asynchronous instrument callbacks. Returns an error when the -// controller was already started. -// -// Note that it is not necessary to Start a controller when only -// pulling data; use the Collect() and ForEach() methods directly in -// this case. -func (c *Controller) Start(ctx context.Context) error { - c.lock.Lock() - defer c.lock.Unlock() - - if c.stopCh != nil { - return ErrControllerStarted - } - - c.wg.Add(1) - c.stopCh = make(chan struct{}) - c.ticker = c.clock.Ticker(c.collectPeriod) - go c.runTicker(ctx, c.stopCh) - return nil -} - -// Stop waits for the background goroutine to return and then collects -// and exports metrics one last time before returning. The passed -// context is passed to the final Collect() and subsequently to the -// final asynchronous instruments. -// -// Note that Stop() will not cancel an ongoing collection or export. -func (c *Controller) Stop(ctx context.Context) error { - c.lock.Lock() - defer c.lock.Unlock() - - if c.stopCh == nil { - return nil - } - - close(c.stopCh) - c.stopCh = nil - c.wg.Wait() - c.ticker.Stop() - c.ticker = nil - - return c.collect(ctx) -} - -// runTicker collection on ticker events until the stop channel is closed. -func (c *Controller) runTicker(ctx context.Context, stopCh chan struct{}) { - defer c.wg.Done() - for { - select { - case <-stopCh: - return - case <-c.ticker.C(): - if err := c.collect(ctx); err != nil { - otel.Handle(err) - } - } - } -} - -// collect computes a checkpoint and optionally exports it. -func (c *Controller) collect(ctx context.Context) error { - if err := c.checkpoint(ctx, func() bool { - return true - }); err != nil { - return err - } - if c.exporter == nil { - return nil - } - // Note: this is not subject to collectTimeout. This blocks the next - // collection despite collectTimeout because it holds a lock. - if err := c.export(ctx); err != nil { - return err - } - return nil -} - -// checkpoint calls the Accumulator and Checkpointer interfaces to -// compute the CheckpointSet. This applies the configured collection -// timeout. Note that this does not try to cancel a Collect or Export -// when Stop() is called. -func (c *Controller) checkpoint(ctx context.Context, cond func() bool) error { - ckpt := c.checkpointer.CheckpointSet() - ckpt.Lock() - defer ckpt.Unlock() - - if !cond() { - return nil - } - c.checkpointer.StartCollection() - - if c.collectTimeout > 0 { - var cancel context.CancelFunc - ctx, cancel = context.WithTimeout(ctx, c.collectTimeout) - defer cancel() - } - - _ = c.accumulator.Collect(ctx) - - var err error - select { - case <-ctx.Done(): - err = ctx.Err() - default: - // The context wasn't done, ok. - } - - // Finish the checkpoint whether the accumulator timed out or not. - if cerr := c.checkpointer.FinishCollection(); cerr != nil { - if err == nil { - err = cerr - } else { - err = fmt.Errorf("%s: %w", cerr.Error(), err) - } - } - - return err -} - -// export calls the exporter with a read lock on the CheckpointSet, -// applying the configured export timeout. -func (c *Controller) export(ctx context.Context) error { - ckpt := c.checkpointer.CheckpointSet() - ckpt.RLock() - defer ckpt.RUnlock() - - if c.pushTimeout > 0 { - var cancel context.CancelFunc - ctx, cancel = context.WithTimeout(ctx, c.pushTimeout) - defer cancel() - } - - return c.exporter.Export(ctx, ckpt) -} - -// Foreach gives the caller read-locked access to the current -// export.CheckpointSet. -func (c *Controller) ForEach(ks export.ExportKindSelector, f func(export.Record) error) error { - ckpt := c.checkpointer.CheckpointSet() - ckpt.RLock() - defer ckpt.RUnlock() - - return ckpt.ForEach(ks, f) -} - -// IsRunning returns true if the controller was started via Start(), -// indicating that the current export.CheckpointSet is being kept -// up-to-date. -func (c *Controller) IsRunning() bool { - c.lock.Lock() - defer c.lock.Unlock() - return c.ticker != nil -} - -// Collect requests a collection. The collection will be skipped if -// the last collection is aged less than the configured collection -// period. -func (c *Controller) Collect(ctx context.Context) error { - if c.IsRunning() { - // When there's a non-nil ticker, there's a goroutine - // computing checkpoints with the collection period. - return ErrControllerStarted - } - - return c.checkpoint(ctx, c.shouldCollect) -} - -// shouldCollect returns true if the collector should collect now, -// based on the timestamp, the last collection time, and the -// configured period. -func (c *Controller) shouldCollect() bool { - // This is called with the CheckpointSet exclusive - // lock held. - if c.collectPeriod == 0 { - return true - } - now := c.clock.Now() - if now.Sub(c.collectedTime) < c.collectPeriod { - return false - } - c.collectedTime = now - return true -} diff --git a/vendor/go.opentelemetry.io/otel/sdk/metric/controller/time/time.go b/vendor/go.opentelemetry.io/otel/sdk/metric/controller/time/time.go deleted file mode 100644 index 08bc44dbf7..0000000000 --- a/vendor/go.opentelemetry.io/otel/sdk/metric/controller/time/time.go +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package time // import "go.opentelemetry.io/otel/sdk/metric/controller/time" - -import ( - "time" - lib "time" -) - -// Several types below are created to match "github.com/benbjohnson/clock" -// so that it remains a test-only dependency. - -type Clock interface { - Now() lib.Time - Ticker(duration lib.Duration) Ticker -} - -type Ticker interface { - Stop() - C() <-chan lib.Time -} - -type RealClock struct { -} - -type RealTicker struct { - ticker *lib.Ticker -} - -var _ Clock = RealClock{} -var _ Ticker = RealTicker{} - -func (RealClock) Now() time.Time { - return time.Now() -} - -func (RealClock) Ticker(period time.Duration) Ticker { - return RealTicker{time.NewTicker(period)} -} - -func (t RealTicker) Stop() { - t.ticker.Stop() -} - -func (t RealTicker) C() <-chan time.Time { - return t.ticker.C -} diff --git a/vendor/go.opentelemetry.io/otel/sdk/metric/doc.go b/vendor/go.opentelemetry.io/otel/sdk/metric/doc.go deleted file mode 100644 index c6ac21c497..0000000000 --- a/vendor/go.opentelemetry.io/otel/sdk/metric/doc.go +++ /dev/null @@ -1,141 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/* -Package metric implements the OpenTelemetry metric API. - -This package is currently in a pre-GA phase. Backwards incompatible changes -may be introduced in subsequent minor version releases as we work to track the -evolving OpenTelemetry specification and user feedback. - -The Accumulator type supports configurable metrics export behavior through a -collection of export interfaces that support various export strategies, -described below. - -The OpenTelemetry metric API consists of methods for constructing synchronous -and asynchronous instruments. There are two constructors per instrument for -the two kinds of number (int64, float64). - -Synchronous instruments are managed by a sync.Map containing a *record -with the current state for each synchronous instrument. A bound -instrument encapsulates a direct pointer to the record, allowing -bound metric events to bypass a sync.Map lookup. A lock-free -algorithm is used to protect against races when adding and removing -items from the sync.Map. - -Asynchronous instruments are managed by an internal -AsyncInstrumentState, which coordinates calling batch and single -instrument callbacks. - -Internal Structure - -Each observer also has its own kind of record stored in the SDK. This -record contains a set of recorders for every specific label set used in the -callback. - -A sync.Map maintains the mapping of current instruments and label sets to -internal records. To create a new bound instrument, the SDK consults the Map to -locate an existing record, otherwise it constructs a new record. The SDK -maintains a count of the number of references to each record, ensuring -that records are not reclaimed from the Map while they are still active -from the user's perspective. - -Metric collection is performed via a single-threaded call to Collect that -sweeps through all records in the SDK, checkpointing their state. When a -record is discovered that has no references and has not been updated since -the prior collection pass, it is removed from the Map. - -Both synchronous and asynchronous instruments have an associated -aggregator, which maintains the current state resulting from all metric -events since its last checkpoint. Aggregators may be lock-free or they may -use locking, but they should expect to be called concurrently. Aggregators -must be capable of merging with another aggregator of the same type. - -Export Pipeline - -While the SDK serves to maintain a current set of records and -coordinate collection, the behavior of a metrics export pipeline is -configured through the export types in -go.opentelemetry.io/otel/sdk/export/metric. It is important to keep -in mind the context these interfaces are called from. There are two -contexts, instrumentation context, where a user-level goroutine that -enters the SDK resulting in a new record, and collection context, -where a system-level thread performs a collection pass through the -SDK. - -Descriptor is a struct that describes the metric instrument to the -export pipeline, containing the name, units, description, metric kind, -number kind (int64 or float64). A Descriptor accompanies metric data -as it passes through the export pipeline. - -The AggregatorSelector interface supports choosing the method of -aggregation to apply to a particular instrument, by delegating the -construction of an Aggregator to this interface. Given the Descriptor, -the AggregatorFor method returns an implementation of Aggregator. If this -interface returns nil, the metric will be disabled. The aggregator should -be matched to the capabilities of the exporter. Selecting the aggregator -for Adding instruments is relatively straightforward, but many options -are available for aggregating distributions from Grouping instruments. - -Aggregator is an interface which implements a concrete strategy for -aggregating metric updates. Several Aggregator implementations are -provided by the SDK. Aggregators may be lock-free or use locking, -depending on their structure and semantics. Aggregators implement an -Update method, called in instrumentation context, to receive a single -metric event. Aggregators implement a Checkpoint method, called in -collection context, to save a checkpoint of the current state. -Aggregators implement a Merge method, also called in collection -context, that combines state from two aggregators into one. Each SDK -record has an associated aggregator. - -Processor is an interface which sits between the SDK and an exporter. -The Processor embeds an AggregatorSelector, used by the SDK to assign -new Aggregators. The Processor supports a Process() API for submitting -checkpointed aggregators to the processor, and a CheckpointSet() API -for producing a complete checkpoint for the exporter. Two default -Processor implementations are provided, the "defaultkeys" Processor groups -aggregate metrics by their recommended Descriptor.Keys(), the -"simple" Processor aggregates metrics at full dimensionality. - -LabelEncoder is an optional optimization that allows an exporter to -provide the serialization logic for labels. This allows avoiding -duplicate serialization of labels, once as a unique key in the SDK (or -Processor) and once in the exporter. - -CheckpointSet is an interface between the Processor and the Exporter. -After completing a collection pass, the Processor.CheckpointSet() method -returns a CheckpointSet, which the Exporter uses to iterate over all -the updated metrics. - -Record is a struct containing the state of an individual exported -metric. This is the result of one collection interface for one -instrument and one label set. - -Labels is a struct containing an ordered set of labels, the -corresponding unique encoding, and the encoder that produced it. - -Exporter is the final stage of an export pipeline. It is called with -a CheckpointSet capable of enumerating all the updated metrics. - -Controller is not an export interface per se, but it orchestrates the -export pipeline. For example, a "push" controller will establish a -periodic timer to regularly collect and export metrics. A "pull" -controller will await a pull request before initiating metric -collection. Either way, the job of the controller is to call the SDK -Collect() method, then read the checkpoint, then invoke the exporter. -Controllers are expected to implement the public metric.MeterProvider -API, meaning they can be installed as the global Meter provider. - -*/ -package metric // import "go.opentelemetry.io/otel/sdk/metric" diff --git a/vendor/go.opentelemetry.io/otel/sdk/metric/go.mod b/vendor/go.opentelemetry.io/otel/sdk/metric/go.mod deleted file mode 100644 index 6ad529662c..0000000000 --- a/vendor/go.opentelemetry.io/otel/sdk/metric/go.mod +++ /dev/null @@ -1,56 +0,0 @@ -module go.opentelemetry.io/otel/sdk/metric - -go 1.14 - -replace go.opentelemetry.io/otel => ../.. - -replace go.opentelemetry.io/otel/bridge/opencensus => ../../bridge/opencensus - -replace go.opentelemetry.io/otel/bridge/opentracing => ../../bridge/opentracing - -replace go.opentelemetry.io/otel/example/jaeger => ../../example/jaeger - -replace go.opentelemetry.io/otel/example/namedtracer => ../../example/namedtracer - -replace go.opentelemetry.io/otel/example/opencensus => ../../example/opencensus - -replace go.opentelemetry.io/otel/example/otel-collector => ../../example/otel-collector - -replace go.opentelemetry.io/otel/example/prom-collector => ../../example/prom-collector - -replace go.opentelemetry.io/otel/example/prometheus => ../../example/prometheus - -replace go.opentelemetry.io/otel/example/zipkin => ../../example/zipkin - -replace go.opentelemetry.io/otel/exporters/metric/prometheus => ../../exporters/metric/prometheus - -replace go.opentelemetry.io/otel/exporters/otlp => ../../exporters/otlp - -replace go.opentelemetry.io/otel/exporters/stdout => ../../exporters/stdout - -replace go.opentelemetry.io/otel/exporters/trace/jaeger => ../../exporters/trace/jaeger - -replace go.opentelemetry.io/otel/exporters/trace/zipkin => ../../exporters/trace/zipkin - -replace go.opentelemetry.io/otel/internal/tools => ../../internal/tools - -replace go.opentelemetry.io/otel/metric => ../../metric - -replace go.opentelemetry.io/otel/oteltest => ../../oteltest - -replace go.opentelemetry.io/otel/sdk => ../ - -replace go.opentelemetry.io/otel/sdk/export/metric => ../export/metric - -replace go.opentelemetry.io/otel/sdk/metric => ./ - -replace go.opentelemetry.io/otel/trace => ../../trace - -require ( - github.com/benbjohnson/clock v1.0.3 // do not upgrade to v1.1.x because it would require Go >= 1.15 - github.com/stretchr/testify v1.7.0 - go.opentelemetry.io/otel v0.20.0 - go.opentelemetry.io/otel/metric v0.20.0 - go.opentelemetry.io/otel/sdk v0.20.0 - go.opentelemetry.io/otel/sdk/export/metric v0.20.0 -) diff --git a/vendor/go.opentelemetry.io/otel/sdk/metric/go.sum b/vendor/go.opentelemetry.io/otel/sdk/metric/go.sum deleted file mode 100644 index dcd8304550..0000000000 --- a/vendor/go.opentelemetry.io/otel/sdk/metric/go.sum +++ /dev/null @@ -1,17 +0,0 @@ -github.com/benbjohnson/clock v1.0.3 h1:vkLuvpK4fmtSCuo60+yC63p7y0BmQ8gm5ZXGuBCJyXg= -github.com/benbjohnson/clock v1.0.3/go.mod h1:bGMdMPoPVvcYyt1gHDf4J2KE153Yf9BuiUKYMaxlTDM= -github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= -github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= -github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/vendor/go.opentelemetry.io/otel/sdk/metric/processor/basic/basic.go b/vendor/go.opentelemetry.io/otel/sdk/metric/processor/basic/basic.go deleted file mode 100644 index 39d1972dc9..0000000000 --- a/vendor/go.opentelemetry.io/otel/sdk/metric/processor/basic/basic.go +++ /dev/null @@ -1,377 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package basic // import "go.opentelemetry.io/otel/sdk/metric/processor/basic" - -import ( - "errors" - "fmt" - "sync" - "time" - - "go.opentelemetry.io/otel/attribute" - "go.opentelemetry.io/otel/metric" - export "go.opentelemetry.io/otel/sdk/export/metric" - "go.opentelemetry.io/otel/sdk/export/metric/aggregation" - "go.opentelemetry.io/otel/sdk/resource" -) - -type ( - Processor struct { - export.ExportKindSelector - export.AggregatorSelector - - state - } - - stateKey struct { - // TODO: This code is organized to support multiple - // accumulators which could theoretically produce the - // data for the same instrument with the same - // resources, and this code has logic to combine data - // properly from multiple accumulators. However, the - // use of *metric.Descriptor in the stateKey makes - // such combination impossible, because each - // accumulator allocates its own instruments. This - // can be fixed by using the instrument name and kind - // instead of the descriptor pointer. See - // https://github.com/open-telemetry/opentelemetry-go/issues/862. - descriptor *metric.Descriptor - distinct attribute.Distinct - resource attribute.Distinct - } - - stateValue struct { - // labels corresponds to the stateKey.distinct field. - labels *attribute.Set - - // resource corresponds to the stateKey.resource field. - resource *resource.Resource - - // updated indicates the last sequence number when this value had - // Process() called by an accumulator. - updated int64 - - // stateful indicates that a cumulative aggregation is - // being maintained, taken from the process start time. - stateful bool - - // currentOwned indicates that "current" was allocated - // by the processor in order to merge results from - // multiple Accumulators during a single collection - // round, which may happen either because: - // (1) multiple Accumulators output the same Accumulation. - // (2) one Accumulator is configured with dimensionality reduction. - currentOwned bool - - // current refers to the output from a single Accumulator - // (if !currentOwned) or it refers to an Aggregator - // owned by the processor used to accumulate multiple - // values in a single collection round. - current export.Aggregator - - // delta, if non-nil, refers to an Aggregator owned by - // the processor used to compute deltas between - // precomputed sums. - delta export.Aggregator - - // cumulative, if non-nil, refers to an Aggregator owned - // by the processor used to store the last cumulative - // value. - cumulative export.Aggregator - } - - state struct { - config Config - - // RWMutex implements locking for the `CheckpointSet` interface. - sync.RWMutex - values map[stateKey]*stateValue - - // Note: the timestamp logic currently assumes all - // exports are deltas. - - processStart time.Time - intervalStart time.Time - intervalEnd time.Time - - // startedCollection and finishedCollection are the - // number of StartCollection() and FinishCollection() - // calls, used to ensure that the sequence of starts - // and finishes are correctly balanced. - - startedCollection int64 - finishedCollection int64 - } -) - -var _ export.Processor = &Processor{} -var _ export.Checkpointer = &Processor{} -var _ export.CheckpointSet = &state{} -var ErrInconsistentState = fmt.Errorf("inconsistent processor state") -var ErrInvalidExportKind = fmt.Errorf("invalid export kind") - -// New returns a basic Processor that is also a Checkpointer using the provided -// AggregatorSelector to select Aggregators. The ExportKindSelector -// is consulted to determine the kind(s) of exporter that will consume -// data, so that this Processor can prepare to compute Delta or -// Cumulative Aggregations as needed. -func New(aselector export.AggregatorSelector, eselector export.ExportKindSelector, opts ...Option) *Processor { - now := time.Now() - p := &Processor{ - AggregatorSelector: aselector, - ExportKindSelector: eselector, - state: state{ - values: map[stateKey]*stateValue{}, - processStart: now, - intervalStart: now, - }, - } - for _, opt := range opts { - opt.ApplyProcessor(&p.config) - } - return p -} - -// Process implements export.Processor. -func (b *Processor) Process(accum export.Accumulation) error { - if b.startedCollection != b.finishedCollection+1 { - return ErrInconsistentState - } - desc := accum.Descriptor() - key := stateKey{ - descriptor: desc, - distinct: accum.Labels().Equivalent(), - resource: accum.Resource().Equivalent(), - } - agg := accum.Aggregator() - - // Check if there is an existing value. - value, ok := b.state.values[key] - if !ok { - stateful := b.ExportKindFor(desc, agg.Aggregation().Kind()).MemoryRequired(desc.InstrumentKind()) - - newValue := &stateValue{ - labels: accum.Labels(), - resource: accum.Resource(), - updated: b.state.finishedCollection, - stateful: stateful, - current: agg, - } - if stateful { - if desc.InstrumentKind().PrecomputedSum() { - // If we know we need to compute deltas, allocate two aggregators. - b.AggregatorFor(desc, &newValue.cumulative, &newValue.delta) - } else { - // In this case we are certain not to need a delta, only allocate - // a cumulative aggregator. - b.AggregatorFor(desc, &newValue.cumulative) - } - } - b.state.values[key] = newValue - return nil - } - - // Advance the update sequence number. - sameCollection := b.state.finishedCollection == value.updated - value.updated = b.state.finishedCollection - - // At this point in the code, we have located an existing - // value for some stateKey. This can be because: - // - // (a) stateful aggregation is being used, the entry was - // entered during a prior collection, and this is the first - // time processing an accumulation for this stateKey in the - // current collection. Since this is the first time - // processing an accumulation for this stateKey during this - // collection, we don't know yet whether there are multiple - // accumulators at work. If there are multiple accumulators, - // they'll hit case (b) the second time through. - // - // (b) multiple accumulators are being used, whether stateful - // or not. - // - // Case (a) occurs when the instrument and the exporter - // require memory to work correctly, either because the - // instrument reports a PrecomputedSum to a DeltaExporter or - // the reverse, a non-PrecomputedSum instrument with a - // CumulativeExporter. This logic is encapsulated in - // ExportKind.MemoryRequired(InstrumentKind). - // - // Case (b) occurs when the variable `sameCollection` is true, - // indicating that the stateKey for Accumulation has already - // been seen in the same collection. When this happens, it - // implies that multiple Accumulators are being used, or that - // a single Accumulator has been configured with a label key - // filter. - - if !sameCollection { - if !value.currentOwned { - // This is the first Accumulation we've seen - // for this stateKey during this collection. - // Just keep a reference to the Accumulator's - // Aggregator. All the other cases copy - // Aggregator state. - value.current = agg - return nil - } - return agg.SynchronizedMove(value.current, desc) - } - - // If the current is not owned, take ownership of a copy - // before merging below. - if !value.currentOwned { - tmp := value.current - b.AggregatorSelector.AggregatorFor(desc, &value.current) - value.currentOwned = true - if err := tmp.SynchronizedMove(value.current, desc); err != nil { - return err - } - } - - // Combine this Accumulation with the prior Accumulation. - return value.current.Merge(agg, desc) -} - -// CheckpointSet returns the associated CheckpointSet. Use the -// CheckpointSet Locker interface to synchronize access to this -// object. The CheckpointSet.ForEach() method cannot be called -// concurrently with Process(). -func (b *Processor) CheckpointSet() export.CheckpointSet { - return &b.state -} - -// StartCollection signals to the Processor one or more Accumulators -// will begin calling Process() calls during collection. -func (b *Processor) StartCollection() { - if b.startedCollection != 0 { - b.intervalStart = b.intervalEnd - } - b.startedCollection++ -} - -// FinishCollection signals to the Processor that a complete -// collection has finished and that ForEach will be called to access -// the CheckpointSet. -func (b *Processor) FinishCollection() error { - b.intervalEnd = time.Now() - if b.startedCollection != b.finishedCollection+1 { - return ErrInconsistentState - } - defer func() { b.finishedCollection++ }() - - for key, value := range b.values { - mkind := key.descriptor.InstrumentKind() - stale := value.updated != b.finishedCollection - stateless := !value.stateful - - // The following branch updates stateful aggregators. Skip - // these updates if the aggregator is not stateful or if the - // aggregator is stale. - if stale || stateless { - // If this processor does not require memeory, - // stale, stateless entries can be removed. - // This implies that they were not updated - // over the previous full collection interval. - if stale && stateless && !b.config.Memory { - delete(b.values, key) - } - continue - } - - // Update Aggregator state to support exporting either a - // delta or a cumulative aggregation. - var err error - if mkind.PrecomputedSum() { - if currentSubtractor, ok := value.current.(export.Subtractor); ok { - // This line is equivalent to: - // value.delta = currentSubtractor - value.cumulative - err = currentSubtractor.Subtract(value.cumulative, value.delta, key.descriptor) - - if err == nil { - err = value.current.SynchronizedMove(value.cumulative, key.descriptor) - } - } else { - err = aggregation.ErrNoSubtraction - } - } else { - // This line is equivalent to: - // value.cumulative = value.cumulative + value.delta - err = value.cumulative.Merge(value.current, key.descriptor) - } - if err != nil { - return err - } - } - return nil -} - -// ForEach iterates through the CheckpointSet, passing an -// export.Record with the appropriate Cumulative or Delta aggregation -// to an exporter. -func (b *state) ForEach(exporter export.ExportKindSelector, f func(export.Record) error) error { - if b.startedCollection != b.finishedCollection { - return ErrInconsistentState - } - for key, value := range b.values { - mkind := key.descriptor.InstrumentKind() - - var agg aggregation.Aggregation - var start time.Time - - // If the processor does not have Config.Memory and it was not updated - // in the prior round, do not visit this value. - if !b.config.Memory && value.updated != (b.finishedCollection-1) { - continue - } - - ekind := exporter.ExportKindFor(key.descriptor, value.current.Aggregation().Kind()) - switch ekind { - case export.CumulativeExportKind: - // If stateful, the sum has been computed. If stateless, the - // input was already cumulative. Either way, use the checkpointed - // value: - if value.stateful { - agg = value.cumulative.Aggregation() - } else { - agg = value.current.Aggregation() - } - start = b.processStart - - case export.DeltaExportKind: - // Precomputed sums are a special case. - if mkind.PrecomputedSum() { - agg = value.delta.Aggregation() - } else { - agg = value.current.Aggregation() - } - start = b.intervalStart - - default: - return fmt.Errorf("%v: %w", ekind, ErrInvalidExportKind) - } - - if err := f(export.NewRecord( - key.descriptor, - value.labels, - value.resource, - agg, - start, - b.intervalEnd, - )); err != nil && !errors.Is(err, aggregation.ErrNoData) { - return err - } - } - return nil -} diff --git a/vendor/go.opentelemetry.io/otel/sdk/metric/processor/basic/config.go b/vendor/go.opentelemetry.io/otel/sdk/metric/processor/basic/config.go deleted file mode 100644 index bf9d976c80..0000000000 --- a/vendor/go.opentelemetry.io/otel/sdk/metric/processor/basic/config.go +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package basic // import "go.opentelemetry.io/otel/sdk/metric/processor/basic" - -// Config contains the options for configuring a basic metric processor. -type Config struct { - // Memory controls whether the processor remembers metric - // instruments and label sets that were previously reported. - // When Memory is true, CheckpointSet.ForEach() will visit - // metrics that were not updated in the most recent interval. - Memory bool -} - -type Option interface { - ApplyProcessor(*Config) -} - -// WithMemory sets the memory behavior of a Processor. If this is -// true, the processor will report metric instruments and label sets -// that were previously reported but not updated in the most recent -// interval. -func WithMemory(memory bool) Option { - return memoryOption(memory) -} - -type memoryOption bool - -func (m memoryOption) ApplyProcessor(config *Config) { - config.Memory = bool(m) -} diff --git a/vendor/go.opentelemetry.io/otel/sdk/metric/refcount_mapped.go b/vendor/go.opentelemetry.io/otel/sdk/metric/refcount_mapped.go deleted file mode 100644 index 9abfb9cca7..0000000000 --- a/vendor/go.opentelemetry.io/otel/sdk/metric/refcount_mapped.go +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package metric // import "go.opentelemetry.io/otel/sdk/metric" - -import ( - "sync/atomic" -) - -// refcountMapped atomically counts the number of references (usages) of an entry -// while also keeping a state of mapped/unmapped into a different data structure -// (an external map or list for example). -// -// refcountMapped uses an atomic value where the least significant bit is used to -// keep the state of mapping ('1' is used for unmapped and '0' is for mapped) and -// the rest of the bits are used for refcounting. -type refcountMapped struct { - // refcount has to be aligned for 64-bit atomic operations. - value int64 -} - -// ref returns true if the entry is still mapped and increases the -// reference usages, if unmapped returns false. -func (rm *refcountMapped) ref() bool { - // Check if this entry was marked as unmapped between the moment - // we got a reference to it (or will be removed very soon) and here. - return atomic.AddInt64(&rm.value, 2)&1 == 0 -} - -func (rm *refcountMapped) unref() { - atomic.AddInt64(&rm.value, -2) -} - -// tryUnmap flips the mapped bit to "unmapped" state and returns true if both of the -// following conditions are true upon entry to this function: -// * There are no active references; -// * The mapped bit is in "mapped" state. -// Otherwise no changes are done to mapped bit and false is returned. -func (rm *refcountMapped) tryUnmap() bool { - if atomic.LoadInt64(&rm.value) != 0 { - return false - } - return atomic.CompareAndSwapInt64( - &rm.value, - 0, - 1, - ) -} diff --git a/vendor/go.opentelemetry.io/otel/sdk/metric/sdk.go b/vendor/go.opentelemetry.io/otel/sdk/metric/sdk.go deleted file mode 100644 index 268fa742da..0000000000 --- a/vendor/go.opentelemetry.io/otel/sdk/metric/sdk.go +++ /dev/null @@ -1,555 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package metric // import "go.opentelemetry.io/otel/sdk/metric" - -import ( - "context" - "fmt" - "runtime" - "sync" - "sync/atomic" - - "go.opentelemetry.io/otel" - "go.opentelemetry.io/otel/attribute" - internal "go.opentelemetry.io/otel/internal/metric" - "go.opentelemetry.io/otel/metric" - "go.opentelemetry.io/otel/metric/number" - export "go.opentelemetry.io/otel/sdk/export/metric" - "go.opentelemetry.io/otel/sdk/metric/aggregator" - "go.opentelemetry.io/otel/sdk/resource" -) - -type ( - // Accumulator implements the OpenTelemetry Meter API. The - // Accumulator is bound to a single export.Processor in - // `NewAccumulator()`. - // - // The Accumulator supports a Collect() API to gather and export - // current data. Collect() should be arranged according to - // the processor model. Push-based processors will setup a - // timer to call Collect() periodically. Pull-based processors - // will call Collect() when a pull request arrives. - Accumulator struct { - // current maps `mapkey` to *record. - current sync.Map - - // asyncInstruments is a set of - // `*asyncInstrument` instances - asyncLock sync.Mutex - asyncInstruments *internal.AsyncInstrumentState - - // currentEpoch is the current epoch number. It is - // incremented in `Collect()`. - currentEpoch int64 - - // processor is the configured processor+configuration. - processor export.Processor - - // collectLock prevents simultaneous calls to Collect(). - collectLock sync.Mutex - - // asyncSortSlice has a single purpose - as a temporary - // place for sorting during labels creation to avoid - // allocation. It is cleared after use. - asyncSortSlice attribute.Sortable - - // resource is applied to all records in this Accumulator. - resource *resource.Resource - } - - syncInstrument struct { - instrument - } - - // mapkey uniquely describes a metric instrument in terms of - // its InstrumentID and the encoded form of its labels. - mapkey struct { - descriptor *metric.Descriptor - ordered attribute.Distinct - } - - // record maintains the state of one metric instrument. Due - // the use of lock-free algorithms, there may be more than one - // `record` in existence at a time, although at most one can - // be referenced from the `Accumulator.current` map. - record struct { - // refMapped keeps track of refcounts and the mapping state to the - // Accumulator.current map. - refMapped refcountMapped - - // updateCount is incremented on every Update. - updateCount int64 - - // collectedCount is set to updateCount on collection, - // supports checking for no updates during a round. - collectedCount int64 - - // storage is the stored label set for this record, - // except in cases where a label set is shared due to - // batch recording. - storage attribute.Set - - // labels is the processed label set for this record. - // this may refer to the `storage` field in another - // record if this label set is shared resulting from - // `RecordBatch`. - labels *attribute.Set - - // sortSlice has a single purpose - as a temporary - // place for sorting during labels creation to avoid - // allocation. - sortSlice attribute.Sortable - - // inst is a pointer to the corresponding instrument. - inst *syncInstrument - - // current implements the actual RecordOne() API, - // depending on the type of aggregation. If nil, the - // metric was disabled by the exporter. - current export.Aggregator - checkpoint export.Aggregator - } - - instrument struct { - meter *Accumulator - descriptor metric.Descriptor - } - - asyncInstrument struct { - instrument - // recorders maps ordered labels to the pair of - // labelset and recorder - recorders map[attribute.Distinct]*labeledRecorder - } - - labeledRecorder struct { - observedEpoch int64 - labels *attribute.Set - observed export.Aggregator - } -) - -var ( - _ metric.MeterImpl = &Accumulator{} - _ metric.AsyncImpl = &asyncInstrument{} - _ metric.SyncImpl = &syncInstrument{} - _ metric.BoundSyncImpl = &record{} - - ErrUninitializedInstrument = fmt.Errorf("use of an uninitialized instrument") -) - -func (inst *instrument) Descriptor() metric.Descriptor { - return inst.descriptor -} - -func (a *asyncInstrument) Implementation() interface{} { - return a -} - -func (s *syncInstrument) Implementation() interface{} { - return s -} - -func (a *asyncInstrument) observe(num number.Number, labels *attribute.Set) { - if err := aggregator.RangeTest(num, &a.descriptor); err != nil { - otel.Handle(err) - return - } - recorder := a.getRecorder(labels) - if recorder == nil { - // The instrument is disabled according to the - // AggregatorSelector. - return - } - if err := recorder.Update(context.Background(), num, &a.descriptor); err != nil { - otel.Handle(err) - return - } -} - -func (a *asyncInstrument) getRecorder(labels *attribute.Set) export.Aggregator { - lrec, ok := a.recorders[labels.Equivalent()] - if ok { - // Note: SynchronizedMove(nil) can't return an error - _ = lrec.observed.SynchronizedMove(nil, &a.descriptor) - lrec.observedEpoch = a.meter.currentEpoch - a.recorders[labels.Equivalent()] = lrec - return lrec.observed - } - var rec export.Aggregator - a.meter.processor.AggregatorFor(&a.descriptor, &rec) - if a.recorders == nil { - a.recorders = make(map[attribute.Distinct]*labeledRecorder) - } - // This may store nil recorder in the map, thus disabling the - // asyncInstrument for the labelset for good. This is intentional, - // but will be revisited later. - a.recorders[labels.Equivalent()] = &labeledRecorder{ - observed: rec, - labels: labels, - observedEpoch: a.meter.currentEpoch, - } - return rec -} - -// acquireHandle gets or creates a `*record` corresponding to `kvs`, -// the input labels. The second argument `labels` is passed in to -// support re-use of the orderedLabels computed by a previous -// measurement in the same batch. This performs two allocations -// in the common case. -func (s *syncInstrument) acquireHandle(kvs []attribute.KeyValue, labelPtr *attribute.Set) *record { - var rec *record - var equiv attribute.Distinct - - if labelPtr == nil { - // This memory allocation may not be used, but it's - // needed for the `sortSlice` field, to avoid an - // allocation while sorting. - rec = &record{} - rec.storage = attribute.NewSetWithSortable(kvs, &rec.sortSlice) - rec.labels = &rec.storage - equiv = rec.storage.Equivalent() - } else { - equiv = labelPtr.Equivalent() - } - - // Create lookup key for sync.Map (one allocation, as this - // passes through an interface{}) - mk := mapkey{ - descriptor: &s.descriptor, - ordered: equiv, - } - - if actual, ok := s.meter.current.Load(mk); ok { - // Existing record case. - existingRec := actual.(*record) - if existingRec.refMapped.ref() { - // At this moment it is guaranteed that the entry is in - // the map and will not be removed. - return existingRec - } - // This entry is no longer mapped, try to add a new entry. - } - - if rec == nil { - rec = &record{} - rec.labels = labelPtr - } - rec.refMapped = refcountMapped{value: 2} - rec.inst = s - - s.meter.processor.AggregatorFor(&s.descriptor, &rec.current, &rec.checkpoint) - - for { - // Load/Store: there's a memory allocation to place `mk` into - // an interface here. - if actual, loaded := s.meter.current.LoadOrStore(mk, rec); loaded { - // Existing record case. Cannot change rec here because if fail - // will try to add rec again to avoid new allocations. - oldRec := actual.(*record) - if oldRec.refMapped.ref() { - // At this moment it is guaranteed that the entry is in - // the map and will not be removed. - return oldRec - } - // This loaded entry is marked as unmapped (so Collect will remove - // it from the map immediately), try again - this is a busy waiting - // strategy to wait until Collect() removes this entry from the map. - // - // This can be improved by having a list of "Unmapped" entries for - // one time only usages, OR we can make this a blocking path and use - // a Mutex that protects the delete operation (delete only if the old - // record is associated with the key). - - // Let collector get work done to remove the entry from the map. - runtime.Gosched() - continue - } - // The new entry was added to the map, good to go. - return rec - } -} - -// The order of the input array `kvs` may be sorted after the function is called. -func (s *syncInstrument) Bind(kvs []attribute.KeyValue) metric.BoundSyncImpl { - return s.acquireHandle(kvs, nil) -} - -// The order of the input array `kvs` may be sorted after the function is called. -func (s *syncInstrument) RecordOne(ctx context.Context, num number.Number, kvs []attribute.KeyValue) { - h := s.acquireHandle(kvs, nil) - defer h.Unbind() - h.RecordOne(ctx, num) -} - -// NewAccumulator constructs a new Accumulator for the given -// processor. This Accumulator supports only a single processor. -// -// The Accumulator does not start any background process to collect itself -// periodically, this responsibility lies with the processor, typically, -// depending on the type of export. For example, a pull-based -// processor will call Collect() when it receives a request to scrape -// current metric values. A push-based processor should configure its -// own periodic collection. -func NewAccumulator(processor export.Processor, resource *resource.Resource) *Accumulator { - return &Accumulator{ - processor: processor, - asyncInstruments: internal.NewAsyncInstrumentState(), - resource: resource, - } -} - -// NewSyncInstrument implements metric.MetricImpl. -func (m *Accumulator) NewSyncInstrument(descriptor metric.Descriptor) (metric.SyncImpl, error) { - return &syncInstrument{ - instrument: instrument{ - descriptor: descriptor, - meter: m, - }, - }, nil -} - -// NewAsyncInstrument implements metric.MetricImpl. -func (m *Accumulator) NewAsyncInstrument(descriptor metric.Descriptor, runner metric.AsyncRunner) (metric.AsyncImpl, error) { - a := &asyncInstrument{ - instrument: instrument{ - descriptor: descriptor, - meter: m, - }, - } - m.asyncLock.Lock() - defer m.asyncLock.Unlock() - m.asyncInstruments.Register(a, runner) - return a, nil -} - -// Collect traverses the list of active records and observers and -// exports data for each active instrument. Collect() may not be -// called concurrently. -// -// During the collection pass, the export.Processor will receive -// one Export() call per current aggregation. -// -// Returns the number of records that were checkpointed. -func (m *Accumulator) Collect(ctx context.Context) int { - m.collectLock.Lock() - defer m.collectLock.Unlock() - - checkpointed := m.observeAsyncInstruments(ctx) - checkpointed += m.collectSyncInstruments() - m.currentEpoch++ - - return checkpointed -} - -func (m *Accumulator) collectSyncInstruments() int { - checkpointed := 0 - - m.current.Range(func(key interface{}, value interface{}) bool { - // Note: always continue to iterate over the entire - // map by returning `true` in this function. - inuse := value.(*record) - - mods := atomic.LoadInt64(&inuse.updateCount) - coll := inuse.collectedCount - - if mods != coll { - // Updates happened in this interval, - // checkpoint and continue. - checkpointed += m.checkpointRecord(inuse) - inuse.collectedCount = mods - return true - } - - // Having no updates since last collection, try to unmap: - if unmapped := inuse.refMapped.tryUnmap(); !unmapped { - // The record is referenced by a binding, continue. - return true - } - - // If any other goroutines are now trying to re-insert this - // entry in the map, they are busy calling Gosched() awaiting - // this deletion: - m.current.Delete(inuse.mapkey()) - - // There's a potential race between `LoadInt64` and - // `tryUnmap` in this function. Since this is the - // last we'll see of this record, checkpoint - mods = atomic.LoadInt64(&inuse.updateCount) - if mods != coll { - checkpointed += m.checkpointRecord(inuse) - } - return true - }) - - return checkpointed -} - -// CollectAsync implements internal.AsyncCollector. -// The order of the input array `kvs` may be sorted after the function is called. -func (m *Accumulator) CollectAsync(kv []attribute.KeyValue, obs ...metric.Observation) { - labels := attribute.NewSetWithSortable(kv, &m.asyncSortSlice) - - for _, ob := range obs { - if a := m.fromAsync(ob.AsyncImpl()); a != nil { - a.observe(ob.Number(), &labels) - } - } -} - -func (m *Accumulator) observeAsyncInstruments(ctx context.Context) int { - m.asyncLock.Lock() - defer m.asyncLock.Unlock() - - asyncCollected := 0 - - m.asyncInstruments.Run(ctx, m) - - for _, inst := range m.asyncInstruments.Instruments() { - if a := m.fromAsync(inst); a != nil { - asyncCollected += m.checkpointAsync(a) - } - } - - return asyncCollected -} - -func (m *Accumulator) checkpointRecord(r *record) int { - if r.current == nil { - return 0 - } - err := r.current.SynchronizedMove(r.checkpoint, &r.inst.descriptor) - if err != nil { - otel.Handle(err) - return 0 - } - - a := export.NewAccumulation(&r.inst.descriptor, r.labels, m.resource, r.checkpoint) - err = m.processor.Process(a) - if err != nil { - otel.Handle(err) - } - return 1 -} - -func (m *Accumulator) checkpointAsync(a *asyncInstrument) int { - if len(a.recorders) == 0 { - return 0 - } - checkpointed := 0 - for encodedLabels, lrec := range a.recorders { - lrec := lrec - epochDiff := m.currentEpoch - lrec.observedEpoch - if epochDiff == 0 { - if lrec.observed != nil { - a := export.NewAccumulation(&a.descriptor, lrec.labels, m.resource, lrec.observed) - err := m.processor.Process(a) - if err != nil { - otel.Handle(err) - } - checkpointed++ - } - } else if epochDiff > 1 { - // This is second collection cycle with no - // observations for this labelset. Remove the - // recorder. - delete(a.recorders, encodedLabels) - } - } - if len(a.recorders) == 0 { - a.recorders = nil - } - return checkpointed -} - -// RecordBatch enters a batch of metric events. -// The order of the input array `kvs` may be sorted after the function is called. -func (m *Accumulator) RecordBatch(ctx context.Context, kvs []attribute.KeyValue, measurements ...metric.Measurement) { - // Labels will be computed the first time acquireHandle is - // called. Subsequent calls to acquireHandle will re-use the - // previously computed value instead of recomputing the - // ordered labels. - var labelsPtr *attribute.Set - for i, meas := range measurements { - s := m.fromSync(meas.SyncImpl()) - if s == nil { - continue - } - h := s.acquireHandle(kvs, labelsPtr) - - // Re-use labels for the next measurement. - if i == 0 { - labelsPtr = h.labels - } - - defer h.Unbind() - h.RecordOne(ctx, meas.Number()) - } -} - -// RecordOne implements metric.SyncImpl. -func (r *record) RecordOne(ctx context.Context, num number.Number) { - if r.current == nil { - // The instrument is disabled according to the AggregatorSelector. - return - } - if err := aggregator.RangeTest(num, &r.inst.descriptor); err != nil { - otel.Handle(err) - return - } - if err := r.current.Update(ctx, num, &r.inst.descriptor); err != nil { - otel.Handle(err) - return - } - // Record was modified, inform the Collect() that things need - // to be collected while the record is still mapped. - atomic.AddInt64(&r.updateCount, 1) -} - -// Unbind implements metric.SyncImpl. -func (r *record) Unbind() { - r.refMapped.unref() -} - -func (r *record) mapkey() mapkey { - return mapkey{ - descriptor: &r.inst.descriptor, - ordered: r.labels.Equivalent(), - } -} - -// fromSync gets a sync implementation object, checking for -// uninitialized instruments and instruments created by another SDK. -func (m *Accumulator) fromSync(sync metric.SyncImpl) *syncInstrument { - if sync != nil { - if inst, ok := sync.Implementation().(*syncInstrument); ok { - return inst - } - } - otel.Handle(ErrUninitializedInstrument) - return nil -} - -// fromSync gets an async implementation object, checking for -// uninitialized instruments and instruments created by another SDK. -func (m *Accumulator) fromAsync(async metric.AsyncImpl) *asyncInstrument { - if async != nil { - if inst, ok := async.Implementation().(*asyncInstrument); ok { - return inst - } - } - otel.Handle(ErrUninitializedInstrument) - return nil -} diff --git a/vendor/go.opentelemetry.io/otel/sdk/metric/selector/simple/simple.go b/vendor/go.opentelemetry.io/otel/sdk/metric/selector/simple/simple.go deleted file mode 100644 index bb5760994a..0000000000 --- a/vendor/go.opentelemetry.io/otel/sdk/metric/selector/simple/simple.go +++ /dev/null @@ -1,120 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package simple // import "go.opentelemetry.io/otel/sdk/metric/selector/simple" - -import ( - "go.opentelemetry.io/otel/metric" - export "go.opentelemetry.io/otel/sdk/export/metric" - "go.opentelemetry.io/otel/sdk/metric/aggregator/exact" - "go.opentelemetry.io/otel/sdk/metric/aggregator/histogram" - "go.opentelemetry.io/otel/sdk/metric/aggregator/lastvalue" - "go.opentelemetry.io/otel/sdk/metric/aggregator/minmaxsumcount" - "go.opentelemetry.io/otel/sdk/metric/aggregator/sum" -) - -type ( - selectorInexpensive struct{} - selectorExact struct{} - selectorHistogram struct { - options []histogram.Option - } -) - -var ( - _ export.AggregatorSelector = selectorInexpensive{} - _ export.AggregatorSelector = selectorExact{} - _ export.AggregatorSelector = selectorHistogram{} -) - -// NewWithInexpensiveDistribution returns a simple aggregator selector -// that uses minmaxsumcount aggregators for `ValueRecorder` -// instruments. This selector is faster and uses less memory than the -// others in this package because minmaxsumcount aggregators maintain -// the least information about the distribution among these choices. -func NewWithInexpensiveDistribution() export.AggregatorSelector { - return selectorInexpensive{} -} - -// NewWithExactDistribution returns a simple aggregator selector that -// uses exact aggregators for `ValueRecorder` instruments. This -// selector uses more memory than the others in this package because -// exact aggregators maintain the most information about the -// distribution among these choices. -func NewWithExactDistribution() export.AggregatorSelector { - return selectorExact{} -} - -// NewWithHistogramDistribution returns a simple aggregator selector -// that uses histogram aggregators for `ValueRecorder` instruments. -// This selector is a good default choice for most metric exporters. -func NewWithHistogramDistribution(options ...histogram.Option) export.AggregatorSelector { - return selectorHistogram{options: options} -} - -func sumAggs(aggPtrs []*export.Aggregator) { - aggs := sum.New(len(aggPtrs)) - for i := range aggPtrs { - *aggPtrs[i] = &aggs[i] - } -} - -func lastValueAggs(aggPtrs []*export.Aggregator) { - aggs := lastvalue.New(len(aggPtrs)) - for i := range aggPtrs { - *aggPtrs[i] = &aggs[i] - } -} - -func (selectorInexpensive) AggregatorFor(descriptor *metric.Descriptor, aggPtrs ...*export.Aggregator) { - switch descriptor.InstrumentKind() { - case metric.ValueObserverInstrumentKind: - lastValueAggs(aggPtrs) - case metric.ValueRecorderInstrumentKind: - aggs := minmaxsumcount.New(len(aggPtrs), descriptor) - for i := range aggPtrs { - *aggPtrs[i] = &aggs[i] - } - default: - sumAggs(aggPtrs) - } -} - -func (selectorExact) AggregatorFor(descriptor *metric.Descriptor, aggPtrs ...*export.Aggregator) { - switch descriptor.InstrumentKind() { - case metric.ValueObserverInstrumentKind: - lastValueAggs(aggPtrs) - case metric.ValueRecorderInstrumentKind: - aggs := exact.New(len(aggPtrs)) - for i := range aggPtrs { - *aggPtrs[i] = &aggs[i] - } - default: - sumAggs(aggPtrs) - } -} - -func (s selectorHistogram) AggregatorFor(descriptor *metric.Descriptor, aggPtrs ...*export.Aggregator) { - switch descriptor.InstrumentKind() { - case metric.ValueObserverInstrumentKind: - lastValueAggs(aggPtrs) - case metric.ValueRecorderInstrumentKind: - aggs := histogram.New(len(aggPtrs), descriptor, s.options...) - for i := range aggPtrs { - *aggPtrs[i] = &aggs[i] - } - default: - sumAggs(aggPtrs) - } -} diff --git a/vendor/go.opentelemetry.io/otel/sdk/resource/auto.go b/vendor/go.opentelemetry.io/otel/sdk/resource/auto.go deleted file mode 100644 index c754e221ee..0000000000 --- a/vendor/go.opentelemetry.io/otel/sdk/resource/auto.go +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package resource // import "go.opentelemetry.io/otel/sdk/resource" - -import ( - "context" - "errors" - "fmt" -) - -var ( - // ErrPartialResource is returned by a detector when complete source - // information for a Resource is unavailable or the source information - // contains invalid values that are omitted from the returned Resource. - ErrPartialResource = errors.New("partial resource") -) - -// Detector detects OpenTelemetry resource information -type Detector interface { - // Detect returns an initialized Resource based on gathered information. - // If the source information to construct a Resource contains invalid - // values, a Resource is returned with the valid parts of the source - // information used for initialization along with an appropriately - // wrapped ErrPartialResource error. - Detect(ctx context.Context) (*Resource, error) -} - -// Detect calls all input detectors sequentially and merges each result with the previous one. -// It returns the merged error too. -func Detect(ctx context.Context, detectors ...Detector) (*Resource, error) { - var autoDetectedRes *Resource - var errInfo []string - for _, detector := range detectors { - if detector == nil { - continue - } - res, err := detector.Detect(ctx) - if err != nil { - errInfo = append(errInfo, err.Error()) - if !errors.Is(err, ErrPartialResource) { - continue - } - } - autoDetectedRes = Merge(autoDetectedRes, res) - } - - var aggregatedError error - if len(errInfo) > 0 { - aggregatedError = fmt.Errorf("detecting resources: %s", errInfo) - } - return autoDetectedRes, aggregatedError -} diff --git a/vendor/go.opentelemetry.io/otel/sdk/resource/builtin.go b/vendor/go.opentelemetry.io/otel/sdk/resource/builtin.go deleted file mode 100644 index c80ab697c6..0000000000 --- a/vendor/go.opentelemetry.io/otel/sdk/resource/builtin.go +++ /dev/null @@ -1,103 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package resource // import "go.opentelemetry.io/otel/sdk/resource" - -import ( - "context" - "fmt" - "os" - "path/filepath" - - "go.opentelemetry.io/otel" - "go.opentelemetry.io/otel/attribute" - "go.opentelemetry.io/otel/semconv" -) - -type ( - // TelemetrySDK is a Detector that provides information about - // the OpenTelemetry SDK used. This Detector is included as a - // builtin. If these resource attributes are not wanted, use - // the WithTelemetrySDK(nil) or WithoutBuiltin() options to - // explicitly disable them. - TelemetrySDK struct{} - - // Host is a Detector that provides information about the host - // being run on. This Detector is included as a builtin. If - // these resource attributes are not wanted, use the - // WithHost(nil) or WithoutBuiltin() options to explicitly - // disable them. - Host struct{} - - stringDetector struct { - K attribute.Key - F func() (string, error) - } - - defaultServiceNameDetector struct{} -) - -var ( - _ Detector = TelemetrySDK{} - _ Detector = Host{} - _ Detector = stringDetector{} - _ Detector = defaultServiceNameDetector{} -) - -// Detect returns a *Resource that describes the OpenTelemetry SDK used. -func (TelemetrySDK) Detect(context.Context) (*Resource, error) { - return NewWithAttributes( - semconv.TelemetrySDKNameKey.String("opentelemetry"), - semconv.TelemetrySDKLanguageKey.String("go"), - semconv.TelemetrySDKVersionKey.String(otel.Version()), - ), nil -} - -// Detect returns a *Resource that describes the host being run on. -func (Host) Detect(ctx context.Context) (*Resource, error) { - return StringDetector(semconv.HostNameKey, os.Hostname).Detect(ctx) -} - -// StringDetector returns a Detector that will produce a *Resource -// containing the string as a value corresponding to k. -func StringDetector(k attribute.Key, f func() (string, error)) Detector { - return stringDetector{K: k, F: f} -} - -// Detect implements Detector. -func (sd stringDetector) Detect(ctx context.Context) (*Resource, error) { - value, err := sd.F() - if err != nil { - return nil, fmt.Errorf("%s: %w", string(sd.K), err) - } - a := sd.K.String(value) - if !a.Valid() { - return nil, fmt.Errorf("invalid attribute: %q -> %q", a.Key, a.Value.Emit()) - } - return NewWithAttributes(sd.K.String(value)), nil -} - -// Detect implements Detector -func (defaultServiceNameDetector) Detect(ctx context.Context) (*Resource, error) { - return StringDetector( - semconv.ServiceNameKey, - func() (string, error) { - executable, err := os.Executable() - if err != nil { - return "unknown_service:go", nil - } - return "unknown_service:" + filepath.Base(executable), nil - }, - ).Detect(ctx) -} diff --git a/vendor/go.opentelemetry.io/otel/sdk/resource/config.go b/vendor/go.opentelemetry.io/otel/sdk/resource/config.go deleted file mode 100644 index 0365caa26a..0000000000 --- a/vendor/go.opentelemetry.io/otel/sdk/resource/config.go +++ /dev/null @@ -1,165 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package resource // import "go.opentelemetry.io/otel/sdk/resource" - -import ( - "context" - - "go.opentelemetry.io/otel/attribute" -) - -// config contains configuration for Resource creation. -type config struct { - // detectors that will be evaluated. - detectors []Detector - - // telemetrySDK is used to specify non-default - // `telemetry.sdk.*` attributes. - telemetrySDK Detector - - // HostResource is used to specify non-default `host.*` - // attributes. - host Detector - - // FromEnv is used to specify non-default OTEL_RESOURCE_ATTRIBUTES - // attributes. - fromEnv Detector -} - -// Option is the interface that applies a configuration option. -type Option interface { - // Apply sets the Option value of a config. - Apply(*config) - - // A private method to prevent users implementing the - // interface and so future additions to it will not - // violate compatibility. - private() -} - -type option struct{} - -func (option) private() {} - -// WithAttributes adds attributes to the configured Resource. -func WithAttributes(attributes ...attribute.KeyValue) Option { - return WithDetectors(detectAttributes{attributes}) -} - -type detectAttributes struct { - attributes []attribute.KeyValue -} - -func (d detectAttributes) Detect(context.Context) (*Resource, error) { - return NewWithAttributes(d.attributes...), nil -} - -// WithDetectors adds detectors to be evaluated for the configured resource. -func WithDetectors(detectors ...Detector) Option { - return detectorsOption{detectors: detectors} -} - -type detectorsOption struct { - option - detectors []Detector -} - -// Apply implements Option. -func (o detectorsOption) Apply(cfg *config) { - cfg.detectors = append(cfg.detectors, o.detectors...) -} - -// WithTelemetrySDK overrides the builtin `telemetry.sdk.*` -// attributes. Use nil to disable these attributes entirely. -func WithTelemetrySDK(d Detector) Option { - return telemetrySDKOption{Detector: d} -} - -type telemetrySDKOption struct { - option - Detector -} - -// Apply implements Option. -func (o telemetrySDKOption) Apply(cfg *config) { - cfg.telemetrySDK = o.Detector -} - -// WithHost overrides the builtin `host.*` attributes. Use nil to -// disable these attributes entirely. -func WithHost(d Detector) Option { - return hostOption{Detector: d} -} - -type hostOption struct { - option - Detector -} - -// Apply implements Option. -func (o hostOption) Apply(cfg *config) { - cfg.host = o.Detector -} - -// WithFromEnv overrides the builtin detector for -// OTEL_RESOURCE_ATTRIBUTES. Use nil to disable environment checking. -func WithFromEnv(d Detector) Option { - return fromEnvOption{Detector: d} -} - -type fromEnvOption struct { - option - Detector -} - -// Apply implements Option. -func (o fromEnvOption) Apply(cfg *config) { - cfg.fromEnv = o.Detector -} - -// WithoutBuiltin disables all the builtin detectors, including the -// telemetry.sdk.*, host.*, and the environment detector. -func WithoutBuiltin() Option { - return noBuiltinOption{} -} - -type noBuiltinOption struct { - option -} - -// Apply implements Option. -func (o noBuiltinOption) Apply(cfg *config) { - cfg.host = nil - cfg.telemetrySDK = nil - cfg.fromEnv = nil -} - -// New returns a Resource combined from the provided attributes, -// user-provided detectors and builtin detectors. -func New(ctx context.Context, opts ...Option) (*Resource, error) { - cfg := config{ - telemetrySDK: TelemetrySDK{}, - host: Host{}, - fromEnv: FromEnv{}, - } - for _, opt := range opts { - opt.Apply(&cfg) - } - detectors := append( - []Detector{cfg.telemetrySDK, cfg.host, cfg.fromEnv}, - cfg.detectors..., - ) - return Detect(ctx, detectors...) -} diff --git a/vendor/go.opentelemetry.io/otel/sdk/resource/doc.go b/vendor/go.opentelemetry.io/otel/sdk/resource/doc.go deleted file mode 100644 index fe34f896af..0000000000 --- a/vendor/go.opentelemetry.io/otel/sdk/resource/doc.go +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package resource provides detecting and representing resources. -// -// This package is currently in a pre-GA phase. Backwards incompatible changes -// may be introduced in subsequent minor version releases as we work to track -// the evolving OpenTelemetry specification and user feedback. -// -// The fundamental struct is a Resource which holds identifying information -// about the entities for which telemetry is exported. -// -// To automatically construct Resources from an environment a Detector -// interface is defined. Implementations of this interface can be passed to -// the Detect function to generate a Resource from the merged information. -// -// To load a user defined Resource from the environment variable -// OTEL_RESOURCE_ATTRIBUTES the FromEnv Detector can be used. It will interpret -// the value as a list of comma delimited key/value pairs -// (e.g. `=,=,...`). -package resource // import "go.opentelemetry.io/otel/sdk/resource" diff --git a/vendor/go.opentelemetry.io/otel/sdk/resource/env.go b/vendor/go.opentelemetry.io/otel/sdk/resource/env.go deleted file mode 100644 index defb455382..0000000000 --- a/vendor/go.opentelemetry.io/otel/sdk/resource/env.go +++ /dev/null @@ -1,72 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package resource // import "go.opentelemetry.io/otel/sdk/resource" - -import ( - "context" - "fmt" - "os" - "strings" - - "go.opentelemetry.io/otel/attribute" -) - -// envVar is the environment variable name OpenTelemetry Resource information can be assigned to. -const envVar = "OTEL_RESOURCE_ATTRIBUTES" - -var ( - // errMissingValue is returned when a resource value is missing. - errMissingValue = fmt.Errorf("%w: missing value", ErrPartialResource) -) - -// FromEnv is a Detector that implements the Detector and collects -// resources from environment. This Detector is included as a -// builtin. If these resource attributes are not wanted, use the -// WithFromEnv(nil) or WithoutBuiltin() options to explicitly disable -// them. -type FromEnv struct{} - -// compile time assertion that FromEnv implements Detector interface -var _ Detector = FromEnv{} - -// Detect collects resources from environment -func (FromEnv) Detect(context.Context) (*Resource, error) { - attrs := strings.TrimSpace(os.Getenv(envVar)) - - if attrs == "" { - return Empty(), nil - } - return constructOTResources(attrs) -} - -func constructOTResources(s string) (*Resource, error) { - pairs := strings.Split(s, ",") - attrs := []attribute.KeyValue{} - var invalid []string - for _, p := range pairs { - field := strings.SplitN(p, "=", 2) - if len(field) != 2 { - invalid = append(invalid, p) - continue - } - k, v := strings.TrimSpace(field[0]), strings.TrimSpace(field[1]) - attrs = append(attrs, attribute.String(k, v)) - } - var err error - if len(invalid) > 0 { - err = fmt.Errorf("%w: %v", errMissingValue, invalid) - } - return NewWithAttributes(attrs...), err -} diff --git a/vendor/go.opentelemetry.io/otel/sdk/resource/os.go b/vendor/go.opentelemetry.io/otel/sdk/resource/os.go deleted file mode 100644 index 816d209217..0000000000 --- a/vendor/go.opentelemetry.io/otel/sdk/resource/os.go +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package resource // import "go.opentelemetry.io/otel/sdk/resource" - -import ( - "context" - "strings" - - "go.opentelemetry.io/otel/semconv" -) - -type osTypeDetector struct{} - -// Detect returns a *Resource that describes the operating system type the -// service is running on. -func (osTypeDetector) Detect(ctx context.Context) (*Resource, error) { - osType := runtimeOS() - - return NewWithAttributes( - semconv.OSTypeKey.String(strings.ToLower(osType)), - ), nil -} - -// WithOSType adds an attribute with the operating system type to the configured Resource. -func WithOSType() Option { - return WithDetectors(osTypeDetector{}) -} diff --git a/vendor/go.opentelemetry.io/otel/sdk/resource/process.go b/vendor/go.opentelemetry.io/otel/sdk/resource/process.go deleted file mode 100644 index f15f97ec5a..0000000000 --- a/vendor/go.opentelemetry.io/otel/sdk/resource/process.go +++ /dev/null @@ -1,237 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package resource // import "go.opentelemetry.io/otel/sdk/resource" - -import ( - "context" - "fmt" - "os" - "os/user" - "path/filepath" - "runtime" - - "go.opentelemetry.io/otel/semconv" -) - -type pidProvider func() int -type executablePathProvider func() (string, error) -type commandArgsProvider func() []string -type ownerProvider func() (*user.User, error) -type runtimeNameProvider func() string -type runtimeVersionProvider func() string -type runtimeOSProvider func() string -type runtimeArchProvider func() string - -var ( - defaultPidProvider pidProvider = os.Getpid - defaultExecutablePathProvider executablePathProvider = os.Executable - defaultCommandArgsProvider commandArgsProvider = func() []string { return os.Args } - defaultOwnerProvider ownerProvider = user.Current - defaultRuntimeNameProvider runtimeNameProvider = func() string { return runtime.Compiler } - defaultRuntimeVersionProvider runtimeVersionProvider = runtime.Version - defaultRuntimeOSProvider runtimeOSProvider = func() string { return runtime.GOOS } - defaultRuntimeArchProvider runtimeArchProvider = func() string { return runtime.GOARCH } -) - -var ( - pid = defaultPidProvider - executablePath = defaultExecutablePathProvider - commandArgs = defaultCommandArgsProvider - owner = defaultOwnerProvider - runtimeName = defaultRuntimeNameProvider - runtimeVersion = defaultRuntimeVersionProvider - runtimeOS = defaultRuntimeOSProvider - runtimeArch = defaultRuntimeArchProvider -) - -func setDefaultOSProviders() { - setOSProviders( - defaultPidProvider, - defaultExecutablePathProvider, - defaultCommandArgsProvider, - ) -} - -func setOSProviders( - pidProvider pidProvider, - executablePathProvider executablePathProvider, - commandArgsProvider commandArgsProvider, -) { - pid = pidProvider - executablePath = executablePathProvider - commandArgs = commandArgsProvider -} - -func setDefaultRuntimeProviders() { - setRuntimeProviders( - defaultRuntimeNameProvider, - defaultRuntimeVersionProvider, - defaultRuntimeOSProvider, - defaultRuntimeArchProvider, - ) -} - -func setRuntimeProviders( - runtimeNameProvider runtimeNameProvider, - runtimeVersionProvider runtimeVersionProvider, - runtimeOSProvider runtimeOSProvider, - runtimeArchProvider runtimeArchProvider, -) { - runtimeName = runtimeNameProvider - runtimeVersion = runtimeVersionProvider - runtimeOS = runtimeOSProvider - runtimeArch = runtimeArchProvider -} - -func setDefaultUserProviders() { - setUserProviders(defaultOwnerProvider) -} - -func setUserProviders(ownerProvider ownerProvider) { - owner = ownerProvider -} - -type processPIDDetector struct{} -type processExecutableNameDetector struct{} -type processExecutablePathDetector struct{} -type processCommandArgsDetector struct{} -type processOwnerDetector struct{} -type processRuntimeNameDetector struct{} -type processRuntimeVersionDetector struct{} -type processRuntimeDescriptionDetector struct{} - -// Detect returns a *Resource that describes the process identifier (PID) of the -// executing process. -func (processPIDDetector) Detect(ctx context.Context) (*Resource, error) { - return NewWithAttributes(semconv.ProcessPIDKey.Int(pid())), nil -} - -// Detect returns a *Resource that describes the name of the process executable. -func (processExecutableNameDetector) Detect(ctx context.Context) (*Resource, error) { - executableName := filepath.Base(commandArgs()[0]) - - return NewWithAttributes(semconv.ProcessExecutableNameKey.String(executableName)), nil -} - -// Detect returns a *Resource that describes the full path of the process executable. -func (processExecutablePathDetector) Detect(ctx context.Context) (*Resource, error) { - executablePath, err := executablePath() - if err != nil { - return nil, err - } - - return NewWithAttributes(semconv.ProcessExecutablePathKey.String(executablePath)), nil -} - -// Detect returns a *Resource that describes all the command arguments as received -// by the process. -func (processCommandArgsDetector) Detect(ctx context.Context) (*Resource, error) { - return NewWithAttributes(semconv.ProcessCommandArgsKey.Array(commandArgs())), nil -} - -// Detect returns a *Resource that describes the username of the user that owns the -// process. -func (processOwnerDetector) Detect(ctx context.Context) (*Resource, error) { - owner, err := owner() - if err != nil { - return nil, err - } - - return NewWithAttributes(semconv.ProcessOwnerKey.String(owner.Username)), nil -} - -// Detect returns a *Resource that describes the name of the compiler used to compile -// this process image. -func (processRuntimeNameDetector) Detect(ctx context.Context) (*Resource, error) { - return NewWithAttributes(semconv.ProcessRuntimeNameKey.String(runtimeName())), nil -} - -// Detect returns a *Resource that describes the version of the runtime of this process. -func (processRuntimeVersionDetector) Detect(ctx context.Context) (*Resource, error) { - return NewWithAttributes(semconv.ProcessRuntimeVersionKey.String(runtimeVersion())), nil -} - -// Detect returns a *Resource that describes the runtime of this process. -func (processRuntimeDescriptionDetector) Detect(ctx context.Context) (*Resource, error) { - runtimeDescription := fmt.Sprintf( - "go version %s %s/%s", runtimeVersion(), runtimeOS(), runtimeArch()) - - return NewWithAttributes( - semconv.ProcessRuntimeDescriptionKey.String(runtimeDescription), - ), nil -} - -// WithProcessPID adds an attribute with the process identifier (PID) to the -// configured Resource. -func WithProcessPID() Option { - return WithDetectors(processPIDDetector{}) -} - -// WithProcessExecutableName adds an attribute with the name of the process -// executable to the configured Resource. -func WithProcessExecutableName() Option { - return WithDetectors(processExecutableNameDetector{}) -} - -// WithProcessExecutablePath adds an attribute with the full path to the process -// executable to the configured Resource. -func WithProcessExecutablePath() Option { - return WithDetectors(processExecutablePathDetector{}) -} - -// WithProcessCommandArgs adds an attribute with all the command arguments (including -// the command/executable itself) as received by the process the configured Resource. -func WithProcessCommandArgs() Option { - return WithDetectors(processCommandArgsDetector{}) -} - -// WithProcessOwner adds an attribute with the username of the user that owns the process -// to the configured Resource. -func WithProcessOwner() Option { - return WithDetectors(processOwnerDetector{}) -} - -// WithProcessRuntimeName adds an attribute with the name of the runtime of this -// process to the configured Resource. -func WithProcessRuntimeName() Option { - return WithDetectors(processRuntimeNameDetector{}) -} - -// WithProcessRuntimeVersion adds an attribute with the version of the runtime of -// this process to the configured Resource. -func WithProcessRuntimeVersion() Option { - return WithDetectors(processRuntimeVersionDetector{}) -} - -// WithProcessRuntimeDescription adds an attribute with an additional description -// about the runtime of the process to the configured Resource. -func WithProcessRuntimeDescription() Option { - return WithDetectors(processRuntimeDescriptionDetector{}) -} - -// WithProcess adds all the Process attributes to the configured Resource. -// See individual WithProcess* functions to configure specific attributes. -func WithProcess() Option { - return WithDetectors( - processPIDDetector{}, - processExecutableNameDetector{}, - processExecutablePathDetector{}, - processCommandArgsDetector{}, - processOwnerDetector{}, - processRuntimeNameDetector{}, - processRuntimeVersionDetector{}, - processRuntimeDescriptionDetector{}, - ) -} diff --git a/vendor/go.opentelemetry.io/otel/sdk/resource/resource.go b/vendor/go.opentelemetry.io/otel/sdk/resource/resource.go deleted file mode 100644 index 2e5d10151c..0000000000 --- a/vendor/go.opentelemetry.io/otel/sdk/resource/resource.go +++ /dev/null @@ -1,196 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package resource // import "go.opentelemetry.io/otel/sdk/resource" - -import ( - "context" - - "go.opentelemetry.io/otel" - "go.opentelemetry.io/otel/attribute" -) - -// Resource describes an entity about which identifying information -// and metadata is exposed. Resource is an immutable object, -// equivalent to a map from key to unique value. -// -// Resources should be passed and stored as pointers -// (`*resource.Resource`). The `nil` value is equivalent to an empty -// Resource. -type Resource struct { - attrs attribute.Set -} - -var ( - emptyResource Resource - - defaultResource *Resource = func(r *Resource, err error) *Resource { - if err != nil { - otel.Handle(err) - } - return r - }(Detect(context.Background(), defaultServiceNameDetector{}, FromEnv{}, TelemetrySDK{})) -) - -// NewWithAttributes creates a resource from attrs. If attrs contains -// duplicate keys, the last value will be used. If attrs contains any invalid -// items those items will be dropped. -func NewWithAttributes(attrs ...attribute.KeyValue) *Resource { - if len(attrs) == 0 { - return &emptyResource - } - - // Ensure attributes comply with the specification: - // https://github.com/open-telemetry/opentelemetry-specification/blob/v1.0.1/specification/common/common.md#attributes - s, _ := attribute.NewSetWithFiltered(attrs, func(kv attribute.KeyValue) bool { - return kv.Valid() - }) - - // If attrs only contains invalid entries do not allocate a new resource. - if s.Len() == 0 { - return &emptyResource - } - - return &Resource{s} //nolint -} - -// String implements the Stringer interface and provides a -// human-readable form of the resource. -// -// Avoid using this representation as the key in a map of resources, -// use Equivalent() as the key instead. -func (r *Resource) String() string { - if r == nil { - return "" - } - return r.attrs.Encoded(attribute.DefaultEncoder()) -} - -// Attributes returns a copy of attributes from the resource in a sorted order. -// To avoid allocating a new slice, use an iterator. -func (r *Resource) Attributes() []attribute.KeyValue { - if r == nil { - r = Empty() - } - return r.attrs.ToSlice() -} - -// Iter returns an interator of the Resource attributes. -// This is ideal to use if you do not want a copy of the attributes. -func (r *Resource) Iter() attribute.Iterator { - if r == nil { - r = Empty() - } - return r.attrs.Iter() -} - -// Equal returns true when a Resource is equivalent to this Resource. -func (r *Resource) Equal(eq *Resource) bool { - if r == nil { - r = Empty() - } - if eq == nil { - eq = Empty() - } - return r.Equivalent() == eq.Equivalent() -} - -// Merge creates a new resource by combining resource a and b. -// -// If there are common keys between resource a and b, then the value -// from resource b will overwrite the value from resource a, even -// if resource b's value is empty. -func Merge(a, b *Resource) *Resource { - if a == nil && b == nil { - return Empty() - } - if a == nil { - return b - } - if b == nil { - return a - } - - // Note: 'b' attributes will overwrite 'a' with last-value-wins in attribute.Key() - // Meaning this is equivalent to: append(a.Attributes(), b.Attributes()...) - mi := attribute.NewMergeIterator(b.Set(), a.Set()) - combine := make([]attribute.KeyValue, 0, a.Len()+b.Len()) - for mi.Next() { - combine = append(combine, mi.Label()) - } - return NewWithAttributes(combine...) -} - -// Empty returns an instance of Resource with no attributes. It is -// equivalent to a `nil` Resource. -func Empty() *Resource { - return &emptyResource -} - -// Default returns an instance of Resource with a default -// "service.name" and OpenTelemetrySDK attributes -func Default() *Resource { - return defaultResource -} - -// Environment returns an instance of Resource with attributes -// extracted from the OTEL_RESOURCE_ATTRIBUTES environment variable. -func Environment() *Resource { - detector := &FromEnv{} - resource, err := detector.Detect(context.Background()) - if err == nil { - otel.Handle(err) - } - return resource -} - -// Equivalent returns an object that can be compared for equality -// between two resources. This value is suitable for use as a key in -// a map. -func (r *Resource) Equivalent() attribute.Distinct { - return r.Set().Equivalent() -} - -// Set returns the equivalent *attribute.Set of this resources attributes. -func (r *Resource) Set() *attribute.Set { - if r == nil { - r = Empty() - } - return &r.attrs -} - -// MarshalJSON encodes the resource attributes as a JSON list of { "Key": -// "...", "Value": ... } pairs in order sorted by key. -func (r *Resource) MarshalJSON() ([]byte, error) { - if r == nil { - r = Empty() - } - return r.attrs.MarshalJSON() -} - -// Len returns the number of unique key-values in this Resource. -func (r *Resource) Len() int { - if r == nil { - return 0 - } - return r.attrs.Len() -} - -// Encoded returns an encoded representation of the resource. -func (r *Resource) Encoded(enc attribute.Encoder) string { - if r == nil { - return "" - } - return r.attrs.Encoded(enc) -} diff --git a/vendor/go.opentelemetry.io/otel/sdk/trace/attributesmap.go b/vendor/go.opentelemetry.io/otel/sdk/trace/attributesmap.go deleted file mode 100644 index b891c8178b..0000000000 --- a/vendor/go.opentelemetry.io/otel/sdk/trace/attributesmap.go +++ /dev/null @@ -1,91 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package trace // import "go.opentelemetry.io/otel/sdk/trace" - -import ( - "container/list" - - "go.opentelemetry.io/otel/attribute" -) - -// attributesMap is a capped map of attributes, holding the most recent attributes. -// Eviction is done via a LRU method, the oldest entry is removed to create room for a new entry. -// Updates are allowed and they refresh the usage of the key. -// -// This is based from https://github.com/hashicorp/golang-lru/blob/master/simplelru/lru.go -// With a subset of the its operations and specific for holding attribute.KeyValue -type attributesMap struct { - attributes map[attribute.Key]*list.Element - evictList *list.List - droppedCount int - capacity int -} - -func newAttributesMap(capacity int) *attributesMap { - lm := &attributesMap{ - attributes: make(map[attribute.Key]*list.Element), - evictList: list.New(), - capacity: capacity, - } - return lm -} - -func (am *attributesMap) add(kv attribute.KeyValue) { - // Check for existing item - if ent, ok := am.attributes[kv.Key]; ok { - am.evictList.MoveToFront(ent) - ent.Value = &kv - return - } - - // Add new item - entry := am.evictList.PushFront(&kv) - am.attributes[kv.Key] = entry - - // Verify size not exceeded - if am.evictList.Len() > am.capacity { - am.removeOldest() - am.droppedCount++ - } -} - -// toKeyValue copies the attributesMap into a slice of attribute.KeyValue and -// returns it. If the map is empty, a nil is returned. -// TODO: Is it more efficient to return a pointer to the slice? -func (am *attributesMap) toKeyValue() []attribute.KeyValue { - len := am.evictList.Len() - if len == 0 { - return nil - } - - attributes := make([]attribute.KeyValue, 0, len) - for ent := am.evictList.Back(); ent != nil; ent = ent.Prev() { - if value, ok := ent.Value.(*attribute.KeyValue); ok { - attributes = append(attributes, *value) - } - } - - return attributes -} - -// removeOldest removes the oldest item from the cache. -func (am *attributesMap) removeOldest() { - ent := am.evictList.Back() - if ent != nil { - am.evictList.Remove(ent) - kv := ent.Value.(*attribute.KeyValue) - delete(am.attributes, kv.Key) - } -} diff --git a/vendor/go.opentelemetry.io/otel/sdk/trace/batch_span_processor.go b/vendor/go.opentelemetry.io/otel/sdk/trace/batch_span_processor.go deleted file mode 100644 index f63aa7a940..0000000000 --- a/vendor/go.opentelemetry.io/otel/sdk/trace/batch_span_processor.go +++ /dev/null @@ -1,328 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package trace // import "go.opentelemetry.io/otel/sdk/trace" - -import ( - "context" - "runtime" - "sync" - "sync/atomic" - "time" - - "go.opentelemetry.io/otel" -) - -const ( - DefaultMaxQueueSize = 2048 - DefaultBatchTimeout = 5000 * time.Millisecond - DefaultExportTimeout = 30000 * time.Millisecond - DefaultMaxExportBatchSize = 512 -) - -type BatchSpanProcessorOption func(o *BatchSpanProcessorOptions) - -type BatchSpanProcessorOptions struct { - // MaxQueueSize is the maximum queue size to buffer spans for delayed processing. If the - // queue gets full it drops the spans. Use BlockOnQueueFull to change this behavior. - // The default value of MaxQueueSize is 2048. - MaxQueueSize int - - // BatchTimeout is the maximum duration for constructing a batch. Processor - // forcefully sends available spans when timeout is reached. - // The default value of BatchTimeout is 5000 msec. - BatchTimeout time.Duration - - // ExportTimeout specifies the maximum duration for exporting spans. If the timeout - // is reached, the export will be cancelled. - // The default value of ExportTimeout is 30000 msec. - ExportTimeout time.Duration - - // MaxExportBatchSize is the maximum number of spans to process in a single batch. - // If there are more than one batch worth of spans then it processes multiple batches - // of spans one batch after the other without any delay. - // The default value of MaxExportBatchSize is 512. - MaxExportBatchSize int - - // BlockOnQueueFull blocks onEnd() and onStart() method if the queue is full - // AND if BlockOnQueueFull is set to true. - // Blocking option should be used carefully as it can severely affect the performance of an - // application. - BlockOnQueueFull bool -} - -// batchSpanProcessor is a SpanProcessor that batches asynchronously-received -// SpanSnapshots and sends them to a trace.Exporter when complete. -type batchSpanProcessor struct { - e SpanExporter - o BatchSpanProcessorOptions - - queue chan *SpanSnapshot - dropped uint32 - - batch []*SpanSnapshot - batchMutex sync.Mutex - timer *time.Timer - stopWait sync.WaitGroup - stopOnce sync.Once - stopCh chan struct{} -} - -var _ SpanProcessor = (*batchSpanProcessor)(nil) - -// NewBatchSpanProcessor creates a new SpanProcessor that will send completed -// span batches to the exporter with the supplied options. -// -// If the exporter is nil, the span processor will preform no action. -func NewBatchSpanProcessor(exporter SpanExporter, options ...BatchSpanProcessorOption) SpanProcessor { - o := BatchSpanProcessorOptions{ - BatchTimeout: DefaultBatchTimeout, - ExportTimeout: DefaultExportTimeout, - MaxQueueSize: DefaultMaxQueueSize, - MaxExportBatchSize: DefaultMaxExportBatchSize, - } - for _, opt := range options { - opt(&o) - } - bsp := &batchSpanProcessor{ - e: exporter, - o: o, - batch: make([]*SpanSnapshot, 0, o.MaxExportBatchSize), - timer: time.NewTimer(o.BatchTimeout), - queue: make(chan *SpanSnapshot, o.MaxQueueSize), - stopCh: make(chan struct{}), - } - - bsp.stopWait.Add(1) - go func() { - defer bsp.stopWait.Done() - bsp.processQueue() - bsp.drainQueue() - }() - - return bsp -} - -// OnStart method does nothing. -func (bsp *batchSpanProcessor) OnStart(parent context.Context, s ReadWriteSpan) {} - -// OnEnd method enqueues a ReadOnlySpan for later processing. -func (bsp *batchSpanProcessor) OnEnd(s ReadOnlySpan) { - // Do not enqueue spans if we are just going to drop them. - if bsp.e == nil { - return - } - bsp.enqueue(s.Snapshot()) -} - -// Shutdown flushes the queue and waits until all spans are processed. -// It only executes once. Subsequent call does nothing. -func (bsp *batchSpanProcessor) Shutdown(ctx context.Context) error { - var err error - bsp.stopOnce.Do(func() { - wait := make(chan struct{}) - go func() { - close(bsp.stopCh) - bsp.stopWait.Wait() - if bsp.e != nil { - if err := bsp.e.Shutdown(ctx); err != nil { - otel.Handle(err) - } - } - close(wait) - }() - // Wait until the wait group is done or the context is cancelled - select { - case <-wait: - case <-ctx.Done(): - err = ctx.Err() - } - }) - return err -} - -// ForceFlush exports all ended spans that have not yet been exported. -func (bsp *batchSpanProcessor) ForceFlush(ctx context.Context) error { - var err error - if bsp.e != nil { - wait := make(chan struct{}) - go func() { - if err := bsp.exportSpans(ctx); err != nil { - otel.Handle(err) - } - close(wait) - }() - // Wait until the export is finished or the context is cancelled/timed out - select { - case <-wait: - case <-ctx.Done(): - err = ctx.Err() - } - } - return err -} - -func WithMaxQueueSize(size int) BatchSpanProcessorOption { - return func(o *BatchSpanProcessorOptions) { - o.MaxQueueSize = size - } -} - -func WithMaxExportBatchSize(size int) BatchSpanProcessorOption { - return func(o *BatchSpanProcessorOptions) { - o.MaxExportBatchSize = size - } -} - -func WithBatchTimeout(delay time.Duration) BatchSpanProcessorOption { - return func(o *BatchSpanProcessorOptions) { - o.BatchTimeout = delay - } -} - -func WithExportTimeout(timeout time.Duration) BatchSpanProcessorOption { - return func(o *BatchSpanProcessorOptions) { - o.ExportTimeout = timeout - } -} - -func WithBlocking() BatchSpanProcessorOption { - return func(o *BatchSpanProcessorOptions) { - o.BlockOnQueueFull = true - } -} - -// exportSpans is a subroutine of processing and draining the queue. -func (bsp *batchSpanProcessor) exportSpans(ctx context.Context) error { - bsp.timer.Reset(bsp.o.BatchTimeout) - - bsp.batchMutex.Lock() - defer bsp.batchMutex.Unlock() - - if bsp.o.ExportTimeout > 0 { - var cancel context.CancelFunc - ctx, cancel = context.WithTimeout(ctx, bsp.o.ExportTimeout) - defer cancel() - } - - if len(bsp.batch) > 0 { - if err := bsp.e.ExportSpans(ctx, bsp.batch); err != nil { - return err - } - bsp.batch = bsp.batch[:0] - } - return nil -} - -// processQueue removes spans from the `queue` channel until processor -// is shut down. It calls the exporter in batches of up to MaxExportBatchSize -// waiting up to BatchTimeout to form a batch. -func (bsp *batchSpanProcessor) processQueue() { - defer bsp.timer.Stop() - - ctx, cancel := context.WithCancel(context.Background()) - defer cancel() - for { - select { - case <-bsp.stopCh: - return - case <-bsp.timer.C: - if err := bsp.exportSpans(ctx); err != nil { - otel.Handle(err) - } - case sd := <-bsp.queue: - bsp.batchMutex.Lock() - bsp.batch = append(bsp.batch, sd) - shouldExport := len(bsp.batch) == bsp.o.MaxExportBatchSize - bsp.batchMutex.Unlock() - if shouldExport { - if !bsp.timer.Stop() { - <-bsp.timer.C - } - if err := bsp.exportSpans(ctx); err != nil { - otel.Handle(err) - } - } - } - } -} - -// drainQueue awaits the any caller that had added to bsp.stopWait -// to finish the enqueue, then exports the final batch. -func (bsp *batchSpanProcessor) drainQueue() { - ctx, cancel := context.WithCancel(context.Background()) - defer cancel() - for { - select { - case sd := <-bsp.queue: - if sd == nil { - if err := bsp.exportSpans(ctx); err != nil { - otel.Handle(err) - } - return - } - - bsp.batchMutex.Lock() - bsp.batch = append(bsp.batch, sd) - shouldExport := len(bsp.batch) == bsp.o.MaxExportBatchSize - bsp.batchMutex.Unlock() - - if shouldExport { - if err := bsp.exportSpans(ctx); err != nil { - otel.Handle(err) - } - } - default: - close(bsp.queue) - } - } -} - -func (bsp *batchSpanProcessor) enqueue(sd *SpanSnapshot) { - if !sd.SpanContext.IsSampled() { - return - } - - // This ensures the bsp.queue<- below does not panic as the - // processor shuts down. - defer func() { - x := recover() - switch err := x.(type) { - case nil: - return - case runtime.Error: - if err.Error() == "send on closed channel" { - return - } - } - panic(x) - }() - - select { - case <-bsp.stopCh: - return - default: - } - - if bsp.o.BlockOnQueueFull { - bsp.queue <- sd - return - } - - select { - case bsp.queue <- sd: - default: - atomic.AddUint32(&bsp.dropped, 1) - } -} diff --git a/vendor/go.opentelemetry.io/otel/sdk/trace/config.go b/vendor/go.opentelemetry.io/otel/sdk/trace/config.go deleted file mode 100644 index 61a3043925..0000000000 --- a/vendor/go.opentelemetry.io/otel/sdk/trace/config.go +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package trace // import "go.opentelemetry.io/otel/sdk/trace" - -// SpanLimits represents the limits of a span. -type SpanLimits struct { - // AttributeCountLimit is the maximum allowed span attribute count. - AttributeCountLimit int - - // EventCountLimit is the maximum allowed span event count. - EventCountLimit int - - // LinkCountLimit is the maximum allowed span link count. - LinkCountLimit int - - // AttributePerEventCountLimit is the maximum allowed attribute per span event count. - AttributePerEventCountLimit int - - // AttributePerLinkCountLimit is the maximum allowed attribute per span link count. - AttributePerLinkCountLimit int -} - -func (sl *SpanLimits) ensureDefault() { - if sl.EventCountLimit <= 0 { - sl.EventCountLimit = DefaultEventCountLimit - } - if sl.AttributeCountLimit <= 0 { - sl.AttributeCountLimit = DefaultAttributeCountLimit - } - if sl.LinkCountLimit <= 0 { - sl.LinkCountLimit = DefaultLinkCountLimit - } - if sl.AttributePerEventCountLimit <= 0 { - sl.AttributePerEventCountLimit = DefaultAttributePerEventCountLimit - } - if sl.AttributePerLinkCountLimit <= 0 { - sl.AttributePerLinkCountLimit = DefaultAttributePerLinkCountLimit - } -} - -const ( - // DefaultAttributeCountLimit is the default maximum allowed span attribute count. - DefaultAttributeCountLimit = 128 - - // DefaultEventCountLimit is the default maximum allowed span event count. - DefaultEventCountLimit = 128 - - // DefaultLinkCountLimit is the default maximum allowed span link count. - DefaultLinkCountLimit = 128 - - // DefaultAttributePerEventCountLimit is the default maximum allowed attribute per span event count. - DefaultAttributePerEventCountLimit = 128 - - // DefaultAttributePerLinkCountLimit is the default maximum allowed attribute per span link count. - DefaultAttributePerLinkCountLimit = 128 -) diff --git a/vendor/go.opentelemetry.io/otel/sdk/trace/doc.go b/vendor/go.opentelemetry.io/otel/sdk/trace/doc.go deleted file mode 100644 index fd6ead8645..0000000000 --- a/vendor/go.opentelemetry.io/otel/sdk/trace/doc.go +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/* -Package trace contains support for OpenTelemetry distributed tracing. - -This package is currently in a pre-GA phase. Backwards incompatible changes -may be introduced in subsequent minor version releases as we work to track the -evolving OpenTelemetry specification and user feedback. - -The following assumes a basic familiarity with OpenTelemetry concepts. -See https://opentelemetry.io. -*/ -package trace // import "go.opentelemetry.io/otel/sdk/trace" diff --git a/vendor/go.opentelemetry.io/otel/sdk/trace/evictedqueue.go b/vendor/go.opentelemetry.io/otel/sdk/trace/evictedqueue.go deleted file mode 100644 index 3c5817a6a0..0000000000 --- a/vendor/go.opentelemetry.io/otel/sdk/trace/evictedqueue.go +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package trace // import "go.opentelemetry.io/otel/sdk/trace" - -type evictedQueue struct { - queue []interface{} - capacity int - droppedCount int -} - -func newEvictedQueue(capacity int) *evictedQueue { - eq := &evictedQueue{ - capacity: capacity, - queue: make([]interface{}, 0), - } - - return eq -} - -func (eq *evictedQueue) add(value interface{}) { - if len(eq.queue) == eq.capacity { - eq.queue = eq.queue[1:] - eq.droppedCount++ - } - eq.queue = append(eq.queue, value) -} diff --git a/vendor/go.opentelemetry.io/otel/sdk/trace/id_generator.go b/vendor/go.opentelemetry.io/otel/sdk/trace/id_generator.go deleted file mode 100644 index e60a421cde..0000000000 --- a/vendor/go.opentelemetry.io/otel/sdk/trace/id_generator.go +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package trace // import "go.opentelemetry.io/otel/sdk/trace" - -import ( - "context" - crand "crypto/rand" - "encoding/binary" - "math/rand" - "sync" - - "go.opentelemetry.io/otel/trace" -) - -// IDGenerator allows custom generators for TraceID and SpanID. -type IDGenerator interface { - NewIDs(ctx context.Context) (trace.TraceID, trace.SpanID) - NewSpanID(ctx context.Context, traceID trace.TraceID) trace.SpanID -} - -type randomIDGenerator struct { - sync.Mutex - randSource *rand.Rand -} - -var _ IDGenerator = &randomIDGenerator{} - -// NewSpanID returns a non-zero span ID from a randomly-chosen sequence. -func (gen *randomIDGenerator) NewSpanID(ctx context.Context, traceID trace.TraceID) trace.SpanID { - gen.Lock() - defer gen.Unlock() - sid := trace.SpanID{} - gen.randSource.Read(sid[:]) - return sid -} - -// NewIDs returns a non-zero trace ID and a non-zero span ID from a -// randomly-chosen sequence. -func (gen *randomIDGenerator) NewIDs(ctx context.Context) (trace.TraceID, trace.SpanID) { - gen.Lock() - defer gen.Unlock() - tid := trace.TraceID{} - gen.randSource.Read(tid[:]) - sid := trace.SpanID{} - gen.randSource.Read(sid[:]) - return tid, sid -} - -func defaultIDGenerator() IDGenerator { - gen := &randomIDGenerator{} - var rngSeed int64 - _ = binary.Read(crand.Reader, binary.LittleEndian, &rngSeed) - gen.randSource = rand.New(rand.NewSource(rngSeed)) - return gen -} diff --git a/vendor/go.opentelemetry.io/otel/sdk/trace/provider.go b/vendor/go.opentelemetry.io/otel/sdk/trace/provider.go deleted file mode 100644 index 601c239c0e..0000000000 --- a/vendor/go.opentelemetry.io/otel/sdk/trace/provider.go +++ /dev/null @@ -1,324 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package trace // import "go.opentelemetry.io/otel/sdk/trace" - -import ( - "context" - "fmt" - "sync" - "sync/atomic" - - "go.opentelemetry.io/otel" - "go.opentelemetry.io/otel/trace" - - "go.opentelemetry.io/otel/sdk/instrumentation" - "go.opentelemetry.io/otel/sdk/resource" -) - -const ( - defaultTracerName = "go.opentelemetry.io/otel/sdk/tracer" -) - -// TODO (MrAlias): unify this API option design: -// https://github.com/open-telemetry/opentelemetry-go/issues/536 - -// TracerProviderConfig -type TracerProviderConfig struct { - processors []SpanProcessor - - // sampler is the default sampler used when creating new spans. - sampler Sampler - - // idGenerator is used to generate all Span and Trace IDs when needed. - idGenerator IDGenerator - - // spanLimits defines the attribute, event, and link limits for spans. - spanLimits SpanLimits - - // resource contains attributes representing an entity that produces telemetry. - resource *resource.Resource -} - -type TracerProviderOption func(*TracerProviderConfig) - -type TracerProvider struct { - mu sync.Mutex - namedTracer map[instrumentation.Library]*tracer - spanProcessors atomic.Value - sampler Sampler - idGenerator IDGenerator - spanLimits SpanLimits - resource *resource.Resource -} - -var _ trace.TracerProvider = &TracerProvider{} - -// NewTracerProvider returns a new and configured TracerProvider. -// -// By default the returned TracerProvider is configured with: -// - a ParentBased(AlwaysSample) Sampler -// - a random number IDGenerator -// - the resource.Default() Resource -// - the default SpanLimits. -// -// The passed opts are used to override these default values and configure the -// returned TracerProvider appropriately. -func NewTracerProvider(opts ...TracerProviderOption) *TracerProvider { - o := &TracerProviderConfig{} - - for _, opt := range opts { - opt(o) - } - - ensureValidTracerProviderConfig(o) - - tp := &TracerProvider{ - namedTracer: make(map[instrumentation.Library]*tracer), - sampler: o.sampler, - idGenerator: o.idGenerator, - spanLimits: o.spanLimits, - resource: o.resource, - } - - for _, sp := range o.processors { - tp.RegisterSpanProcessor(sp) - } - - return tp -} - -// Tracer returns a Tracer with the given name and options. If a Tracer for -// the given name and options does not exist it is created, otherwise the -// existing Tracer is returned. -// -// If name is empty, DefaultTracerName is used instead. -// -// This method is safe to be called concurrently. -func (p *TracerProvider) Tracer(name string, opts ...trace.TracerOption) trace.Tracer { - c := trace.NewTracerConfig(opts...) - - p.mu.Lock() - defer p.mu.Unlock() - if name == "" { - name = defaultTracerName - } - il := instrumentation.Library{ - Name: name, - Version: c.InstrumentationVersion, - } - t, ok := p.namedTracer[il] - if !ok { - t = &tracer{ - provider: p, - instrumentationLibrary: il, - } - p.namedTracer[il] = t - } - return t -} - -// RegisterSpanProcessor adds the given SpanProcessor to the list of SpanProcessors -func (p *TracerProvider) RegisterSpanProcessor(s SpanProcessor) { - p.mu.Lock() - defer p.mu.Unlock() - new := spanProcessorStates{} - if old, ok := p.spanProcessors.Load().(spanProcessorStates); ok { - new = append(new, old...) - } - newSpanSync := &spanProcessorState{ - sp: s, - state: &sync.Once{}, - } - new = append(new, newSpanSync) - p.spanProcessors.Store(new) -} - -// UnregisterSpanProcessor removes the given SpanProcessor from the list of SpanProcessors -func (p *TracerProvider) UnregisterSpanProcessor(s SpanProcessor) { - p.mu.Lock() - defer p.mu.Unlock() - spss := spanProcessorStates{} - old, ok := p.spanProcessors.Load().(spanProcessorStates) - if !ok || len(old) == 0 { - return - } - spss = append(spss, old...) - - // stop the span processor if it is started and remove it from the list - var stopOnce *spanProcessorState - var idx int - for i, sps := range spss { - if sps.sp == s { - stopOnce = sps - idx = i - } - } - if stopOnce != nil { - stopOnce.state.Do(func() { - if err := s.Shutdown(context.Background()); err != nil { - otel.Handle(err) - } - }) - } - if len(spss) > 1 { - copy(spss[idx:], spss[idx+1:]) - } - spss[len(spss)-1] = nil - spss = spss[:len(spss)-1] - - p.spanProcessors.Store(spss) -} - -// ForceFlush immediately exports all spans that have not yet been exported for -// all the registered span processors. -func (p *TracerProvider) ForceFlush(ctx context.Context) error { - spss, ok := p.spanProcessors.Load().(spanProcessorStates) - if !ok { - return fmt.Errorf("failed to load span processors") - } - if len(spss) == 0 { - return nil - } - - for _, sps := range spss { - select { - case <-ctx.Done(): - return ctx.Err() - default: - } - - if err := sps.sp.ForceFlush(ctx); err != nil { - return err - } - } - return nil -} - -// Shutdown shuts down the span processors in the order they were registered. -func (p *TracerProvider) Shutdown(ctx context.Context) error { - spss, ok := p.spanProcessors.Load().(spanProcessorStates) - if !ok { - return fmt.Errorf("failed to load span processors") - } - if len(spss) == 0 { - return nil - } - - for _, sps := range spss { - select { - case <-ctx.Done(): - return ctx.Err() - default: - } - - var err error - sps.state.Do(func() { - err = sps.sp.Shutdown(ctx) - }) - if err != nil { - return err - } - } - return nil -} - -// WithSyncer registers the exporter with the TracerProvider using a -// SimpleSpanProcessor. -func WithSyncer(e SpanExporter) TracerProviderOption { - return WithSpanProcessor(NewSimpleSpanProcessor(e)) -} - -// WithBatcher registers the exporter with the TracerProvider using a -// BatchSpanProcessor configured with the passed opts. -func WithBatcher(e SpanExporter, opts ...BatchSpanProcessorOption) TracerProviderOption { - return WithSpanProcessor(NewBatchSpanProcessor(e, opts...)) -} - -// WithSpanProcessor registers the SpanProcessor with a TracerProvider. -func WithSpanProcessor(sp SpanProcessor) TracerProviderOption { - return func(opts *TracerProviderConfig) { - opts.processors = append(opts.processors, sp) - } -} - -// WithResource returns a TracerProviderOption that will configure the -// Resource r as a TracerProvider's Resource. The configured Resource is -// referenced by all the Tracers the TracerProvider creates. It represents the -// entity producing telemetry. -// -// If this option is not used, the TracerProvider will use the -// resource.Default() Resource by default. -func WithResource(r *resource.Resource) TracerProviderOption { - return func(opts *TracerProviderConfig) { - opts.resource = resource.Merge(resource.Environment(), r) - } -} - -// WithIDGenerator returns a TracerProviderOption that will configure the -// IDGenerator g as a TracerProvider's IDGenerator. The configured IDGenerator -// is used by the Tracers the TracerProvider creates to generate new Span and -// Trace IDs. -// -// If this option is not used, the TracerProvider will use a random number -// IDGenerator by default. -func WithIDGenerator(g IDGenerator) TracerProviderOption { - return func(opts *TracerProviderConfig) { - if g != nil { - opts.idGenerator = g - } - } -} - -// WithSampler returns a TracerProviderOption that will configure the Sampler -// s as a TracerProvider's Sampler. The configured Sampler is used by the -// Tracers the TracerProvider creates to make their sampling decisions for the -// Spans they create. -// -// If this option is not used, the TracerProvider will use a -// ParentBased(AlwaysSample) Sampler by default. -func WithSampler(s Sampler) TracerProviderOption { - return func(opts *TracerProviderConfig) { - if s != nil { - opts.sampler = s - } - } -} - -// WithSpanLimits returns a TracerProviderOption that will configure the -// SpanLimits sl as a TracerProvider's SpanLimits. The configured SpanLimits -// are used used by the Tracers the TracerProvider and the Spans they create -// to limit tracing resources used. -// -// If this option is not used, the TracerProvider will use the default -// SpanLimits. -func WithSpanLimits(sl SpanLimits) TracerProviderOption { - return func(opts *TracerProviderConfig) { - opts.spanLimits = sl - } -} - -// ensureValidTracerProviderConfig ensures that given TracerProviderConfig is valid. -func ensureValidTracerProviderConfig(cfg *TracerProviderConfig) { - if cfg.sampler == nil { - cfg.sampler = ParentBased(AlwaysSample()) - } - if cfg.idGenerator == nil { - cfg.idGenerator = defaultIDGenerator() - } - cfg.spanLimits.ensureDefault() - if cfg.resource == nil { - cfg.resource = resource.Default() - } -} diff --git a/vendor/go.opentelemetry.io/otel/sdk/trace/sampling.go b/vendor/go.opentelemetry.io/otel/sdk/trace/sampling.go deleted file mode 100644 index 86fc3108dc..0000000000 --- a/vendor/go.opentelemetry.io/otel/sdk/trace/sampling.go +++ /dev/null @@ -1,290 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package trace // import "go.opentelemetry.io/otel/sdk/trace" - -import ( - "context" - "encoding/binary" - "fmt" - - "go.opentelemetry.io/otel/attribute" - "go.opentelemetry.io/otel/trace" -) - -// Sampler decides whether a trace should be sampled and exported. -type Sampler interface { - ShouldSample(parameters SamplingParameters) SamplingResult - Description() string -} - -// SamplingParameters contains the values passed to a Sampler. -type SamplingParameters struct { - ParentContext context.Context - TraceID trace.TraceID - Name string - Kind trace.SpanKind - Attributes []attribute.KeyValue - Links []trace.Link -} - -// SamplingDecision indicates whether a span is dropped, recorded and/or sampled. -type SamplingDecision uint8 - -// Valid sampling decisions -const ( - // Drop will not record the span and all attributes/events will be dropped - Drop SamplingDecision = iota - - // Record indicates the span's `IsRecording() == true`, but `Sampled` flag - // *must not* be set - RecordOnly - - // RecordAndSample has span's `IsRecording() == true` and `Sampled` flag - // *must* be set - RecordAndSample -) - -// SamplingResult conveys a SamplingDecision, set of Attributes and a Tracestate. -type SamplingResult struct { - Decision SamplingDecision - Attributes []attribute.KeyValue - Tracestate trace.TraceState -} - -type traceIDRatioSampler struct { - traceIDUpperBound uint64 - description string -} - -func (ts traceIDRatioSampler) ShouldSample(p SamplingParameters) SamplingResult { - psc := trace.SpanContextFromContext(p.ParentContext) - x := binary.BigEndian.Uint64(p.TraceID[0:8]) >> 1 - if x < ts.traceIDUpperBound { - return SamplingResult{ - Decision: RecordAndSample, - Tracestate: psc.TraceState(), - } - } - return SamplingResult{ - Decision: Drop, - Tracestate: psc.TraceState(), - } -} - -func (ts traceIDRatioSampler) Description() string { - return ts.description -} - -// TraceIDRatioBased samples a given fraction of traces. Fractions >= 1 will -// always sample. Fractions < 0 are treated as zero. To respect the -// parent trace's `SampledFlag`, the `TraceIDRatioBased` sampler should be used -// as a delegate of a `Parent` sampler. -//nolint:golint // golint complains about stutter of `trace.TraceIDRatioBased` -func TraceIDRatioBased(fraction float64) Sampler { - if fraction >= 1 { - return AlwaysSample() - } - - if fraction <= 0 { - fraction = 0 - } - - return &traceIDRatioSampler{ - traceIDUpperBound: uint64(fraction * (1 << 63)), - description: fmt.Sprintf("TraceIDRatioBased{%g}", fraction), - } -} - -type alwaysOnSampler struct{} - -func (as alwaysOnSampler) ShouldSample(p SamplingParameters) SamplingResult { - return SamplingResult{ - Decision: RecordAndSample, - Tracestate: trace.SpanContextFromContext(p.ParentContext).TraceState(), - } -} - -func (as alwaysOnSampler) Description() string { - return "AlwaysOnSampler" -} - -// AlwaysSample returns a Sampler that samples every trace. -// Be careful about using this sampler in a production application with -// significant traffic: a new trace will be started and exported for every -// request. -func AlwaysSample() Sampler { - return alwaysOnSampler{} -} - -type alwaysOffSampler struct{} - -func (as alwaysOffSampler) ShouldSample(p SamplingParameters) SamplingResult { - return SamplingResult{ - Decision: Drop, - Tracestate: trace.SpanContextFromContext(p.ParentContext).TraceState(), - } -} - -func (as alwaysOffSampler) Description() string { - return "AlwaysOffSampler" -} - -// NeverSample returns a Sampler that samples no traces. -func NeverSample() Sampler { - return alwaysOffSampler{} -} - -// ParentBased returns a composite sampler which behaves differently, -// based on the parent of the span. If the span has no parent, -// the root(Sampler) is used to make sampling decision. If the span has -// a parent, depending on whether the parent is remote and whether it -// is sampled, one of the following samplers will apply: -// - remoteParentSampled(Sampler) (default: AlwaysOn) -// - remoteParentNotSampled(Sampler) (default: AlwaysOff) -// - localParentSampled(Sampler) (default: AlwaysOn) -// - localParentNotSampled(Sampler) (default: AlwaysOff) -func ParentBased(root Sampler, samplers ...ParentBasedSamplerOption) Sampler { - return parentBased{ - root: root, - config: configureSamplersForParentBased(samplers), - } -} - -type parentBased struct { - root Sampler - config config -} - -func configureSamplersForParentBased(samplers []ParentBasedSamplerOption) config { - c := config{ - remoteParentSampled: AlwaysSample(), - remoteParentNotSampled: NeverSample(), - localParentSampled: AlwaysSample(), - localParentNotSampled: NeverSample(), - } - - for _, so := range samplers { - so.Apply(&c) - } - - return c -} - -// config is a group of options for parentBased sampler. -type config struct { - remoteParentSampled, remoteParentNotSampled Sampler - localParentSampled, localParentNotSampled Sampler -} - -// ParentBasedSamplerOption configures the sampler for a particular sampling case. -type ParentBasedSamplerOption interface { - Apply(*config) - - // A private method to prevent users implementing the - // interface and so future additions to it will not - // violate compatibility. - private() -} - -// WithRemoteParentSampled sets the sampler for the case of sampled remote parent. -func WithRemoteParentSampled(s Sampler) ParentBasedSamplerOption { - return remoteParentSampledOption{s} -} - -type remoteParentSampledOption struct { - s Sampler -} - -func (o remoteParentSampledOption) Apply(config *config) { - config.remoteParentSampled = o.s -} - -func (remoteParentSampledOption) private() {} - -// WithRemoteParentNotSampled sets the sampler for the case of remote parent -// which is not sampled. -func WithRemoteParentNotSampled(s Sampler) ParentBasedSamplerOption { - return remoteParentNotSampledOption{s} -} - -type remoteParentNotSampledOption struct { - s Sampler -} - -func (o remoteParentNotSampledOption) Apply(config *config) { - config.remoteParentNotSampled = o.s -} - -func (remoteParentNotSampledOption) private() {} - -// WithLocalParentSampled sets the sampler for the case of sampled local parent. -func WithLocalParentSampled(s Sampler) ParentBasedSamplerOption { - return localParentSampledOption{s} -} - -type localParentSampledOption struct { - s Sampler -} - -func (o localParentSampledOption) Apply(config *config) { - config.localParentSampled = o.s -} - -func (localParentSampledOption) private() {} - -// WithLocalParentNotSampled sets the sampler for the case of local parent -// which is not sampled. -func WithLocalParentNotSampled(s Sampler) ParentBasedSamplerOption { - return localParentNotSampledOption{s} -} - -type localParentNotSampledOption struct { - s Sampler -} - -func (o localParentNotSampledOption) Apply(config *config) { - config.localParentNotSampled = o.s -} - -func (localParentNotSampledOption) private() {} - -func (pb parentBased) ShouldSample(p SamplingParameters) SamplingResult { - psc := trace.SpanContextFromContext(p.ParentContext) - if psc.IsValid() { - if psc.IsRemote() { - if psc.IsSampled() { - return pb.config.remoteParentSampled.ShouldSample(p) - } - return pb.config.remoteParentNotSampled.ShouldSample(p) - } - - if psc.IsSampled() { - return pb.config.localParentSampled.ShouldSample(p) - } - return pb.config.localParentNotSampled.ShouldSample(p) - } - return pb.root.ShouldSample(p) -} - -func (pb parentBased) Description() string { - return fmt.Sprintf("ParentBased{root:%s,remoteParentSampled:%s,"+ - "remoteParentNotSampled:%s,localParentSampled:%s,localParentNotSampled:%s}", - pb.root.Description(), - pb.config.remoteParentSampled.Description(), - pb.config.remoteParentNotSampled.Description(), - pb.config.localParentSampled.Description(), - pb.config.localParentNotSampled.Description(), - ) -} diff --git a/vendor/go.opentelemetry.io/otel/sdk/trace/simple_span_processor.go b/vendor/go.opentelemetry.io/otel/sdk/trace/simple_span_processor.go deleted file mode 100644 index b66a87a2a3..0000000000 --- a/vendor/go.opentelemetry.io/otel/sdk/trace/simple_span_processor.go +++ /dev/null @@ -1,80 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package trace // import "go.opentelemetry.io/otel/sdk/trace" - -import ( - "context" - "sync" - - "go.opentelemetry.io/otel" -) - -// simpleSpanProcessor is a SpanProcessor that synchronously sends all -// completed Spans to a trace.Exporter immediately. -type simpleSpanProcessor struct { - exporterMu sync.RWMutex - exporter SpanExporter - stopOnce sync.Once -} - -var _ SpanProcessor = (*simpleSpanProcessor)(nil) - -// NewSimpleSpanProcessor returns a new SpanProcessor that will synchronously -// send completed spans to the exporter immediately. -func NewSimpleSpanProcessor(exporter SpanExporter) SpanProcessor { - ssp := &simpleSpanProcessor{ - exporter: exporter, - } - return ssp -} - -// OnStart does nothing. -func (ssp *simpleSpanProcessor) OnStart(context.Context, ReadWriteSpan) {} - -// OnEnd immediately exports a ReadOnlySpan. -func (ssp *simpleSpanProcessor) OnEnd(s ReadOnlySpan) { - ssp.exporterMu.RLock() - defer ssp.exporterMu.RUnlock() - - if ssp.exporter != nil && s.SpanContext().TraceFlags().IsSampled() { - ss := s.Snapshot() - if err := ssp.exporter.ExportSpans(context.Background(), []*SpanSnapshot{ss}); err != nil { - otel.Handle(err) - } - } -} - -// Shutdown shuts down the exporter this SimpleSpanProcessor exports to. -func (ssp *simpleSpanProcessor) Shutdown(ctx context.Context) error { - var err error - ssp.stopOnce.Do(func() { - ssp.exporterMu.Lock() - exporter := ssp.exporter - // Set exporter to nil so subsequent calls to OnEnd are ignored - // gracefully. - ssp.exporter = nil - ssp.exporterMu.Unlock() - - // Clear the ssp.exporter prior to shutting it down so if that creates - // a span that needs to be exported there is no deadlock. - err = exporter.Shutdown(ctx) - }) - return err -} - -// ForceFlush does nothing as there is no data to flush. -func (ssp *simpleSpanProcessor) ForceFlush(context.Context) error { - return nil -} diff --git a/vendor/go.opentelemetry.io/otel/sdk/trace/span.go b/vendor/go.opentelemetry.io/otel/sdk/trace/span.go deleted file mode 100644 index f13967d2b5..0000000000 --- a/vendor/go.opentelemetry.io/otel/sdk/trace/span.go +++ /dev/null @@ -1,617 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package trace // import "go.opentelemetry.io/otel/sdk/trace" - -import ( - "context" - "fmt" - "reflect" - "sync" - "time" - - "go.opentelemetry.io/otel/attribute" - "go.opentelemetry.io/otel/codes" - "go.opentelemetry.io/otel/semconv" - "go.opentelemetry.io/otel/trace" - - "go.opentelemetry.io/otel/sdk/instrumentation" - "go.opentelemetry.io/otel/sdk/internal" - "go.opentelemetry.io/otel/sdk/resource" -) - -// ReadOnlySpan allows reading information from the data structure underlying a -// trace.Span. It is used in places where reading information from a span is -// necessary but changing the span isn't necessary or allowed. -// TODO: Should we make the methods unexported? The purpose of this interface -// is controlling access to `span` fields, not having multiple implementations. -type ReadOnlySpan interface { - Name() string - SpanContext() trace.SpanContext - Parent() trace.SpanContext - SpanKind() trace.SpanKind - StartTime() time.Time - EndTime() time.Time - Attributes() []attribute.KeyValue - Links() []trace.Link - Events() []trace.Event - StatusCode() codes.Code - StatusMessage() string - Tracer() trace.Tracer - IsRecording() bool - InstrumentationLibrary() instrumentation.Library - Resource() *resource.Resource - Snapshot() *SpanSnapshot - - // A private method to prevent users implementing the - // interface and so future additions to it will not - // violate compatibility. - private() -} - -// ReadWriteSpan exposes the same methods as trace.Span and in addition allows -// reading information from the underlying data structure. -// This interface exposes the union of the methods of trace.Span (which is a -// "write-only" span) and ReadOnlySpan. New methods for writing or reading span -// information should be added under trace.Span or ReadOnlySpan, respectively. -type ReadWriteSpan interface { - trace.Span - ReadOnlySpan -} - -// span is an implementation of the OpenTelemetry Span API representing the -// individual component of a trace. -type span struct { - // mu protects the contents of this span. - mu sync.Mutex - - // parent holds the parent span of this span as a trace.SpanContext. - parent trace.SpanContext - - // spanKind represents the kind of this span as a trace.SpanKind. - spanKind trace.SpanKind - - // name is the name of this span. - name string - - // startTime is the time at which this span was started. - startTime time.Time - - // endTime is the time at which this span was ended. It contains the zero - // value of time.Time until the span is ended. - endTime time.Time - - // statusCode represents the status of this span as a codes.Code value. - statusCode codes.Code - - // statusMessage represents the status of this span as a string. - statusMessage string - - // childSpanCount holds the number of child spans created for this span. - childSpanCount int - - // resource contains attributes representing an entity that produced this - // span. - resource *resource.Resource - - // instrumentationLibrary defines the instrumentation library used to - // provide instrumentation. - instrumentationLibrary instrumentation.Library - - // spanContext holds the SpanContext of this span. - spanContext trace.SpanContext - - // attributes are capped at configured limit. When the capacity is reached - // an oldest entry is removed to create room for a new entry. - attributes *attributesMap - - // messageEvents are stored in FIFO queue capped by configured limit. - messageEvents *evictedQueue - - // links are stored in FIFO queue capped by configured limit. - links *evictedQueue - - // executionTracerTaskEnd ends the execution tracer span. - executionTracerTaskEnd func() - - // tracer is the SDK tracer that created this span. - tracer *tracer - - // spanLimits holds the limits to this span. - spanLimits SpanLimits -} - -var _ trace.Span = &span{} - -// SpanContext returns the SpanContext of this span. -func (s *span) SpanContext() trace.SpanContext { - if s == nil { - return trace.SpanContext{} - } - return s.spanContext -} - -// IsRecording returns if this span is being recorded. If this span has ended -// this will return false. -func (s *span) IsRecording() bool { - if s == nil { - return false - } - s.mu.Lock() - defer s.mu.Unlock() - - return !s.startTime.IsZero() && s.endTime.IsZero() -} - -// SetStatus sets the status of this span in the form of a code and a -// message. This overrides the existing value of this span's status if one -// exists. Message will be set only if status is error. If this span is not being -// recorded than this method does nothing. -func (s *span) SetStatus(code codes.Code, msg string) { - if !s.IsRecording() { - return - } - s.mu.Lock() - s.statusCode = code - if code == codes.Error { - s.statusMessage = msg - } - s.mu.Unlock() -} - -// SetAttributes sets attributes of this span. -// -// If a key from attributes already exists the value associated with that key -// will be overwritten with the value contained in attributes. -// -// If this span is not being recorded than this method does nothing. -func (s *span) SetAttributes(attributes ...attribute.KeyValue) { - if !s.IsRecording() { - return - } - s.copyToCappedAttributes(attributes...) -} - -// End ends the span. This method does nothing if the span is already ended or -// is not being recorded. -// -// The only SpanOption currently supported is WithTimestamp which will set the -// end time for a Span's life-cycle. -// -// If this method is called while panicking an error event is added to the -// Span before ending it and the panic is continued. -func (s *span) End(options ...trace.SpanOption) { - // Do not start by checking if the span is being recorded which requires - // acquiring a lock. Make a minimal check that the span is not nil. - if s == nil { - return - } - - // Store the end time as soon as possible to avoid artificially increasing - // the span's duration in case some operation below takes a while. - et := internal.MonotonicEndTime(s.startTime) - - // Do relative expensive check now that we have an end time and see if we - // need to do any more processing. - if !s.IsRecording() { - return - } - - if recovered := recover(); recovered != nil { - // Record but don't stop the panic. - defer panic(recovered) - s.addEvent( - semconv.ExceptionEventName, - trace.WithAttributes( - semconv.ExceptionTypeKey.String(typeStr(recovered)), - semconv.ExceptionMessageKey.String(fmt.Sprint(recovered)), - ), - ) - } - - if s.executionTracerTaskEnd != nil { - s.executionTracerTaskEnd() - } - - config := trace.NewSpanConfig(options...) - - s.mu.Lock() - // Setting endTime to non-zero marks the span as ended and not recording. - if config.Timestamp.IsZero() { - s.endTime = et - } else { - s.endTime = config.Timestamp - } - s.mu.Unlock() - - sps, ok := s.tracer.provider.spanProcessors.Load().(spanProcessorStates) - mustExportOrProcess := ok && len(sps) > 0 - if mustExportOrProcess { - for _, sp := range sps { - sp.sp.OnEnd(s) - } - } -} - -// RecordError will record err as a span event for this span. An additional call to -// SetStatus is required if the Status of the Span should be set to Error, this method -// does not change the Span status. If this span is not being recorded or err is nil -// than this method does nothing. -func (s *span) RecordError(err error, opts ...trace.EventOption) { - if s == nil || err == nil || !s.IsRecording() { - return - } - - opts = append(opts, trace.WithAttributes( - semconv.ExceptionTypeKey.String(typeStr(err)), - semconv.ExceptionMessageKey.String(err.Error()), - )) - s.addEvent(semconv.ExceptionEventName, opts...) -} - -func typeStr(i interface{}) string { - t := reflect.TypeOf(i) - if t.PkgPath() == "" && t.Name() == "" { - // Likely a builtin type. - return t.String() - } - return fmt.Sprintf("%s.%s", t.PkgPath(), t.Name()) -} - -// Tracer returns the Tracer that created this span. -func (s *span) Tracer() trace.Tracer { - return s.tracer -} - -// AddEvent adds an event with the provided name and options. If this span is -// not being recorded than this method does nothing. -func (s *span) AddEvent(name string, o ...trace.EventOption) { - if !s.IsRecording() { - return - } - s.addEvent(name, o...) -} - -func (s *span) addEvent(name string, o ...trace.EventOption) { - c := trace.NewEventConfig(o...) - - // Discard over limited attributes - var discarded int - if len(c.Attributes) > s.spanLimits.AttributePerEventCountLimit { - discarded = len(c.Attributes) - s.spanLimits.AttributePerEventCountLimit - c.Attributes = c.Attributes[:s.spanLimits.AttributePerEventCountLimit] - } - - s.mu.Lock() - defer s.mu.Unlock() - s.messageEvents.add(trace.Event{ - Name: name, - Attributes: c.Attributes, - DroppedAttributeCount: discarded, - Time: c.Timestamp, - }) -} - -// SetName sets the name of this span. If this span is not being recorded than -// this method does nothing. -func (s *span) SetName(name string) { - if !s.IsRecording() { - return - } - - s.mu.Lock() - defer s.mu.Unlock() - s.name = name -} - -// Name returns the name of this span. -func (s *span) Name() string { - s.mu.Lock() - defer s.mu.Unlock() - return s.name -} - -// Name returns the SpanContext of this span's parent span. -func (s *span) Parent() trace.SpanContext { - s.mu.Lock() - defer s.mu.Unlock() - return s.parent -} - -// SpanKind returns the SpanKind of this span. -func (s *span) SpanKind() trace.SpanKind { - s.mu.Lock() - defer s.mu.Unlock() - return s.spanKind -} - -// StartTime returns the time this span started. -func (s *span) StartTime() time.Time { - s.mu.Lock() - defer s.mu.Unlock() - return s.startTime -} - -// EndTime returns the time this span ended. For spans that have not yet -// ended, the returned value will be the zero value of time.Time. -func (s *span) EndTime() time.Time { - s.mu.Lock() - defer s.mu.Unlock() - return s.endTime -} - -// Attributes returns the attributes of this span. -func (s *span) Attributes() []attribute.KeyValue { - s.mu.Lock() - defer s.mu.Unlock() - if s.attributes.evictList.Len() == 0 { - return []attribute.KeyValue{} - } - return s.attributes.toKeyValue() -} - -// Links returns the links of this span. -func (s *span) Links() []trace.Link { - s.mu.Lock() - defer s.mu.Unlock() - if len(s.links.queue) == 0 { - return []trace.Link{} - } - return s.interfaceArrayToLinksArray() -} - -// Events returns the events of this span. -func (s *span) Events() []trace.Event { - s.mu.Lock() - defer s.mu.Unlock() - if len(s.messageEvents.queue) == 0 { - return []trace.Event{} - } - return s.interfaceArrayToMessageEventArray() -} - -// StatusCode returns the status code of this span. -func (s *span) StatusCode() codes.Code { - s.mu.Lock() - defer s.mu.Unlock() - return s.statusCode -} - -// StatusMessage returns the status message of this span. -func (s *span) StatusMessage() string { - s.mu.Lock() - defer s.mu.Unlock() - return s.statusMessage -} - -// InstrumentationLibrary returns the instrumentation.Library associated with -// the Tracer that created this span. -func (s *span) InstrumentationLibrary() instrumentation.Library { - s.mu.Lock() - defer s.mu.Unlock() - return s.instrumentationLibrary -} - -// Resource returns the Resource associated with the Tracer that created this -// span. -func (s *span) Resource() *resource.Resource { - s.mu.Lock() - defer s.mu.Unlock() - return s.resource -} - -func (s *span) addLink(link trace.Link) { - if !s.IsRecording() { - return - } - s.mu.Lock() - defer s.mu.Unlock() - - // Discard over limited attributes - if len(link.Attributes) > s.spanLimits.AttributePerLinkCountLimit { - link.DroppedAttributeCount = len(link.Attributes) - s.spanLimits.AttributePerLinkCountLimit - link.Attributes = link.Attributes[:s.spanLimits.AttributePerLinkCountLimit] - } - - s.links.add(link) -} - -// Snapshot creates a snapshot representing the current state of the span as an -// export.SpanSnapshot and returns a pointer to it. -func (s *span) Snapshot() *SpanSnapshot { - var sd SpanSnapshot - s.mu.Lock() - defer s.mu.Unlock() - - sd.ChildSpanCount = s.childSpanCount - sd.EndTime = s.endTime - sd.InstrumentationLibrary = s.instrumentationLibrary - sd.Name = s.name - sd.Parent = s.parent - sd.Resource = s.resource - sd.SpanContext = s.spanContext - sd.SpanKind = s.spanKind - sd.StartTime = s.startTime - sd.StatusCode = s.statusCode - sd.StatusMessage = s.statusMessage - - if s.attributes.evictList.Len() > 0 { - sd.Attributes = s.attributes.toKeyValue() - sd.DroppedAttributeCount = s.attributes.droppedCount - } - if len(s.messageEvents.queue) > 0 { - sd.MessageEvents = s.interfaceArrayToMessageEventArray() - sd.DroppedMessageEventCount = s.messageEvents.droppedCount - } - if len(s.links.queue) > 0 { - sd.Links = s.interfaceArrayToLinksArray() - sd.DroppedLinkCount = s.links.droppedCount - } - return &sd -} - -func (s *span) interfaceArrayToLinksArray() []trace.Link { - linkArr := make([]trace.Link, 0) - for _, value := range s.links.queue { - linkArr = append(linkArr, value.(trace.Link)) - } - return linkArr -} - -func (s *span) interfaceArrayToMessageEventArray() []trace.Event { - messageEventArr := make([]trace.Event, 0) - for _, value := range s.messageEvents.queue { - messageEventArr = append(messageEventArr, value.(trace.Event)) - } - return messageEventArr -} - -func (s *span) copyToCappedAttributes(attributes ...attribute.KeyValue) { - s.mu.Lock() - defer s.mu.Unlock() - for _, a := range attributes { - // Ensure attributes conform to the specification: - // https://github.com/open-telemetry/opentelemetry-specification/blob/v1.0.1/specification/common/common.md#attributes - if a.Valid() { - s.attributes.add(a) - } - } -} - -func (s *span) addChild() { - if !s.IsRecording() { - return - } - s.mu.Lock() - s.childSpanCount++ - s.mu.Unlock() -} - -func (*span) private() {} - -func startSpanInternal(ctx context.Context, tr *tracer, name string, o *trace.SpanConfig) *span { - span := &span{} - - provider := tr.provider - - // If told explicitly to make this a new root use a zero value SpanContext - // as a parent which contains an invalid trace ID and is not remote. - var psc trace.SpanContext - if !o.NewRoot { - psc = trace.SpanContextFromContext(ctx) - } - - // If there is a valid parent trace ID, use it to ensure the continuity of - // the trace. Always generate a new span ID so other components can rely - // on a unique span ID, even if the Span is non-recording. - var tid trace.TraceID - var sid trace.SpanID - if !psc.TraceID().IsValid() { - tid, sid = provider.idGenerator.NewIDs(ctx) - } else { - tid = psc.TraceID() - sid = provider.idGenerator.NewSpanID(ctx, tid) - } - - spanLimits := provider.spanLimits - span.attributes = newAttributesMap(spanLimits.AttributeCountLimit) - span.messageEvents = newEvictedQueue(spanLimits.EventCountLimit) - span.links = newEvictedQueue(spanLimits.LinkCountLimit) - span.spanLimits = spanLimits - - samplingResult := provider.sampler.ShouldSample(SamplingParameters{ - ParentContext: ctx, - TraceID: tid, - Name: name, - Kind: o.SpanKind, - Attributes: o.Attributes, - Links: o.Links, - }) - - scc := trace.SpanContextConfig{ - TraceID: tid, - SpanID: sid, - TraceState: samplingResult.Tracestate, - } - if isSampled(samplingResult) { - scc.TraceFlags = psc.TraceFlags() | trace.FlagsSampled - } else { - scc.TraceFlags = psc.TraceFlags() &^ trace.FlagsSampled - } - span.spanContext = trace.NewSpanContext(scc) - - if !isRecording(samplingResult) { - return span - } - - startTime := o.Timestamp - if startTime.IsZero() { - startTime = time.Now() - } - span.startTime = startTime - - span.spanKind = trace.ValidateSpanKind(o.SpanKind) - span.name = name - span.parent = psc - span.resource = provider.resource - span.instrumentationLibrary = tr.instrumentationLibrary - - span.SetAttributes(samplingResult.Attributes...) - - return span -} - -func isRecording(s SamplingResult) bool { - return s.Decision == RecordOnly || s.Decision == RecordAndSample -} - -func isSampled(s SamplingResult) bool { - return s.Decision == RecordAndSample -} - -// SpanSnapshot is a snapshot of a span which contains all the information -// collected by the span. Its main purpose is exporting completed spans. -// Although SpanSnapshot fields can be accessed and potentially modified, -// SpanSnapshot should be treated as immutable. Changes to the span from which -// the SpanSnapshot was created are NOT reflected in the SpanSnapshot. -type SpanSnapshot struct { - SpanContext trace.SpanContext - Parent trace.SpanContext - SpanKind trace.SpanKind - Name string - StartTime time.Time - // The wall clock time of EndTime will be adjusted to always be offset - // from StartTime by the duration of the span. - EndTime time.Time - Attributes []attribute.KeyValue - MessageEvents []trace.Event - Links []trace.Link - StatusCode codes.Code - StatusMessage string - - // DroppedAttributeCount contains dropped attributes for the span itself. - DroppedAttributeCount int - DroppedMessageEventCount int - DroppedLinkCount int - - // ChildSpanCount holds the number of child span created for this span. - ChildSpanCount int - - // Resource contains attributes representing an entity that produced this span. - Resource *resource.Resource - - // InstrumentationLibrary defines the instrumentation library used to - // provide instrumentation. - InstrumentationLibrary instrumentation.Library -} diff --git a/vendor/go.opentelemetry.io/otel/sdk/trace/span_exporter.go b/vendor/go.opentelemetry.io/otel/sdk/trace/span_exporter.go deleted file mode 100644 index 40e121069d..0000000000 --- a/vendor/go.opentelemetry.io/otel/sdk/trace/span_exporter.go +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package trace // import "go.opentelemetry.io/otel/sdk/trace" - -import "context" - -// SpanExporter handles the delivery of SpanSnapshot structs to external -// receivers. This is the final component in the trace export pipeline. -type SpanExporter interface { - // ExportSpans exports a batch of SpanSnapshots. - // - // This function is called synchronously, so there is no concurrency - // safety requirement. However, due to the synchronous calling pattern, - // it is critical that all timeouts and cancellations contained in the - // passed context must be honored. - // - // Any retry logic must be contained in this function. The SDK that - // calls this function will not implement any retry logic. All errors - // returned by this function are considered unrecoverable and will be - // reported to a configured error Handler. - ExportSpans(ctx context.Context, ss []*SpanSnapshot) error - // Shutdown notifies the exporter of a pending halt to operations. The - // exporter is expected to preform any cleanup or synchronization it - // requires while honoring all timeouts and cancellations contained in - // the passed context. - Shutdown(ctx context.Context) error -} diff --git a/vendor/go.opentelemetry.io/otel/sdk/trace/span_processor.go b/vendor/go.opentelemetry.io/otel/sdk/trace/span_processor.go deleted file mode 100644 index 73f49815e8..0000000000 --- a/vendor/go.opentelemetry.io/otel/sdk/trace/span_processor.go +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package trace // import "go.opentelemetry.io/otel/sdk/trace" - -import ( - "context" - "sync" -) - -// SpanProcessor is a processing pipeline for spans in the trace signal. -// SpanProcessors registered with a TracerProvider and are called at the start -// and end of a Span's lifecycle, and are called in the order they are -// registered. -type SpanProcessor interface { - // OnStart is called when a span is started. It is called synchronously - // and should not block. - OnStart(parent context.Context, s ReadWriteSpan) - - // OnEnd is called when span is finished. It is called synchronously and - // hence not block. - OnEnd(s ReadOnlySpan) - - // Shutdown is called when the SDK shuts down. Any cleanup or release of - // resources held by the processor should be done in this call. - // - // Calls to OnStart, OnEnd, or ForceFlush after this has been called - // should be ignored. - // - // All timeouts and cancellations contained in ctx must be honored, this - // should not block indefinitely. - Shutdown(ctx context.Context) error - - // ForceFlush exports all ended spans to the configured Exporter that have not yet - // been exported. It should only be called when absolutely necessary, such as when - // using a FaaS provider that may suspend the process after an invocation, but before - // the Processor can export the completed spans. - ForceFlush(ctx context.Context) error -} - -type spanProcessorState struct { - sp SpanProcessor - state *sync.Once -} -type spanProcessorStates []*spanProcessorState diff --git a/vendor/go.opentelemetry.io/otel/sdk/trace/tracer.go b/vendor/go.opentelemetry.io/otel/sdk/trace/tracer.go deleted file mode 100644 index b7869eddd2..0000000000 --- a/vendor/go.opentelemetry.io/otel/sdk/trace/tracer.go +++ /dev/null @@ -1,75 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package trace // import "go.opentelemetry.io/otel/sdk/trace" - -import ( - "context" - rt "runtime/trace" - - "go.opentelemetry.io/otel/trace" - - "go.opentelemetry.io/otel/sdk/instrumentation" -) - -type tracer struct { - provider *TracerProvider - instrumentationLibrary instrumentation.Library -} - -var _ trace.Tracer = &tracer{} - -// Start starts a Span and returns it along with a context containing it. -// -// The Span is created with the provided name and as a child of any existing -// span context found in the passed context. The created Span will be -// configured appropriately by any SpanOption passed. Any Timestamp option -// passed will be used as the start time of the Span's life-cycle. -func (tr *tracer) Start(ctx context.Context, name string, options ...trace.SpanOption) (context.Context, trace.Span) { - config := trace.NewSpanConfig(options...) - - // For local spans created by this SDK, track child span count. - if p := trace.SpanFromContext(ctx); p != nil { - if sdkSpan, ok := p.(*span); ok { - sdkSpan.addChild() - } - } - - span := startSpanInternal(ctx, tr, name, config) - for _, l := range config.Links { - span.addLink(l) - } - span.SetAttributes(config.Attributes...) - - span.tracer = tr - - if span.IsRecording() { - sps, _ := tr.provider.spanProcessors.Load().(spanProcessorStates) - for _, sp := range sps { - sp.sp.OnStart(ctx, span) - } - } - - ctx, span.executionTracerTaskEnd = func(ctx context.Context) (context.Context, func()) { - if !rt.IsEnabled() { - // Avoid additional overhead if - // runtime/trace is not enabled. - return ctx, func() {} - } - nctx, task := rt.NewTask(ctx, name) - return nctx, task.End - }(ctx) - - return trace.ContextWithSpan(ctx, span), span -} diff --git a/vendor/go.opentelemetry.io/otel/semconv/doc.go b/vendor/go.opentelemetry.io/otel/semconv/doc.go deleted file mode 100644 index 9a729fdecb..0000000000 --- a/vendor/go.opentelemetry.io/otel/semconv/doc.go +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package semconv implements OpenTelemetry semantic conventions. -// -// This package is currently in a pre-GA phase. Backwards incompatible changes -// may be introduced in subsequent minor version releases as we work to track -// the evolving OpenTelemetry specification and user feedback. -// -// OpenTelemetry semantic conventions are agreed standardized naming -// patterns for OpenTelemetry things. This package aims to be the -// centralized place to interact with these conventions. -package semconv // import "go.opentelemetry.io/otel/semconv" diff --git a/vendor/go.opentelemetry.io/otel/semconv/exception.go b/vendor/go.opentelemetry.io/otel/semconv/exception.go deleted file mode 100644 index 9700261122..0000000000 --- a/vendor/go.opentelemetry.io/otel/semconv/exception.go +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -package semconv - -import "go.opentelemetry.io/otel/attribute" - -// Semantic conventions for exception attribute keys. -const ( - // The Go type containing the error or exception. - ExceptionTypeKey = attribute.Key("exception.type") - - // The exception message. - ExceptionMessageKey = attribute.Key("exception.message") - - // A stacktrace as a string. This most commonly will come from - // "runtime/debug".Stack. - ExceptionStacktraceKey = attribute.Key("exception.stacktrace") - - // If the exception event is recorded at a point where it is known - // that the exception is escaping the scope of the span this - // attribute is set to true. - ExceptionEscapedKey = attribute.Key("exception.escaped") -) - -const ( - // ExceptionEventName is the name of the Span event representing an exception. - ExceptionEventName = "exception" -) diff --git a/vendor/go.opentelemetry.io/otel/semconv/http.go b/vendor/go.opentelemetry.io/otel/semconv/http.go deleted file mode 100644 index d8160f9242..0000000000 --- a/vendor/go.opentelemetry.io/otel/semconv/http.go +++ /dev/null @@ -1,297 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package semconv // import "go.opentelemetry.io/otel/semconv" - -import ( - "fmt" - "net" - "net/http" - "strconv" - "strings" - - "go.opentelemetry.io/otel/attribute" - "go.opentelemetry.io/otel/codes" -) - -// NetAttributesFromHTTPRequest generates attributes of the net -// namespace as specified by the OpenTelemetry specification for a -// span. The network parameter is a string that net.Dial function -// from standard library can understand. -func NetAttributesFromHTTPRequest(network string, request *http.Request) []attribute.KeyValue { - attrs := []attribute.KeyValue{} - - switch network { - case "tcp", "tcp4", "tcp6": - attrs = append(attrs, NetTransportTCP) - case "udp", "udp4", "udp6": - attrs = append(attrs, NetTransportUDP) - case "ip", "ip4", "ip6": - attrs = append(attrs, NetTransportIP) - case "unix", "unixgram", "unixpacket": - attrs = append(attrs, NetTransportUnix) - default: - attrs = append(attrs, NetTransportOther) - } - - peerName, peerIP, peerPort := "", "", 0 - { - hostPart := request.RemoteAddr - portPart := "" - if idx := strings.LastIndex(hostPart, ":"); idx >= 0 { - hostPart = request.RemoteAddr[:idx] - portPart = request.RemoteAddr[idx+1:] - } - if hostPart != "" { - if ip := net.ParseIP(hostPart); ip != nil { - peerIP = ip.String() - } else { - peerName = hostPart - } - - if portPart != "" { - numPort, err := strconv.ParseUint(portPart, 10, 16) - if err == nil { - peerPort = (int)(numPort) - } else { - peerName, peerIP = "", "" - } - } - } - } - if peerName != "" { - attrs = append(attrs, NetPeerNameKey.String(peerName)) - } - if peerIP != "" { - attrs = append(attrs, NetPeerIPKey.String(peerIP)) - } - if peerPort != 0 { - attrs = append(attrs, NetPeerPortKey.Int(peerPort)) - } - - hostIP, hostName, hostPort := "", "", 0 - for _, someHost := range []string{request.Host, request.Header.Get("Host"), request.URL.Host} { - hostPart := "" - if idx := strings.LastIndex(someHost, ":"); idx >= 0 { - strPort := someHost[idx+1:] - numPort, err := strconv.ParseUint(strPort, 10, 16) - if err == nil { - hostPort = (int)(numPort) - } - hostPart = someHost[:idx] - } else { - hostPart = someHost - } - if hostPart != "" { - ip := net.ParseIP(hostPart) - if ip != nil { - hostIP = ip.String() - } else { - hostName = hostPart - } - break - } else { - hostPort = 0 - } - } - if hostIP != "" { - attrs = append(attrs, NetHostIPKey.String(hostIP)) - } - if hostName != "" { - attrs = append(attrs, NetHostNameKey.String(hostName)) - } - if hostPort != 0 { - attrs = append(attrs, NetHostPortKey.Int(hostPort)) - } - - return attrs -} - -// EndUserAttributesFromHTTPRequest generates attributes of the -// enduser namespace as specified by the OpenTelemetry specification -// for a span. -func EndUserAttributesFromHTTPRequest(request *http.Request) []attribute.KeyValue { - if username, _, ok := request.BasicAuth(); ok { - return []attribute.KeyValue{EnduserIDKey.String(username)} - } - return nil -} - -// HTTPClientAttributesFromHTTPRequest generates attributes of the -// http namespace as specified by the OpenTelemetry specification for -// a span on the client side. -func HTTPClientAttributesFromHTTPRequest(request *http.Request) []attribute.KeyValue { - attrs := []attribute.KeyValue{} - - if request.Method != "" { - attrs = append(attrs, HTTPMethodKey.String(request.Method)) - } else { - attrs = append(attrs, HTTPMethodKey.String(http.MethodGet)) - } - - attrs = append(attrs, HTTPURLKey.String(request.URL.String())) - - return append(attrs, httpCommonAttributesFromHTTPRequest(request)...) -} - -func httpCommonAttributesFromHTTPRequest(request *http.Request) []attribute.KeyValue { - attrs := []attribute.KeyValue{} - if ua := request.UserAgent(); ua != "" { - attrs = append(attrs, HTTPUserAgentKey.String(ua)) - } - if request.ContentLength > 0 { - attrs = append(attrs, HTTPRequestContentLengthKey.Int64(request.ContentLength)) - } - - return append(attrs, httpBasicAttributesFromHTTPRequest(request)...) -} - -func httpBasicAttributesFromHTTPRequest(request *http.Request) []attribute.KeyValue { - // as these attributes are used by HTTPServerMetricAttributesFromHTTPRequest, they should be low-cardinality - attrs := []attribute.KeyValue{} - - if request.TLS != nil { - attrs = append(attrs, HTTPSchemeHTTPS) - } else { - attrs = append(attrs, HTTPSchemeHTTP) - } - - if request.Host != "" { - attrs = append(attrs, HTTPHostKey.String(request.Host)) - } - - flavor := "" - if request.ProtoMajor == 1 { - flavor = fmt.Sprintf("1.%d", request.ProtoMinor) - } else if request.ProtoMajor == 2 { - flavor = "2" - } - if flavor != "" { - attrs = append(attrs, HTTPFlavorKey.String(flavor)) - } - - return attrs -} - -// HTTPServerMetricAttributesFromHTTPRequest generates low-cardinality attributes -// to be used with server-side HTTP metrics. -func HTTPServerMetricAttributesFromHTTPRequest(serverName string, request *http.Request) []attribute.KeyValue { - attrs := []attribute.KeyValue{} - if serverName != "" { - attrs = append(attrs, HTTPServerNameKey.String(serverName)) - } - return append(attrs, httpBasicAttributesFromHTTPRequest(request)...) -} - -// HTTPServerAttributesFromHTTPRequest generates attributes of the -// http namespace as specified by the OpenTelemetry specification for -// a span on the server side. Currently, only basic authentication is -// supported. -func HTTPServerAttributesFromHTTPRequest(serverName, route string, request *http.Request) []attribute.KeyValue { - attrs := []attribute.KeyValue{ - HTTPMethodKey.String(request.Method), - HTTPTargetKey.String(request.RequestURI), - } - - if serverName != "" { - attrs = append(attrs, HTTPServerNameKey.String(serverName)) - } - if route != "" { - attrs = append(attrs, HTTPRouteKey.String(route)) - } - if values, ok := request.Header["X-Forwarded-For"]; ok && len(values) > 0 { - attrs = append(attrs, HTTPClientIPKey.String(values[0])) - } - - return append(attrs, httpCommonAttributesFromHTTPRequest(request)...) -} - -// HTTPAttributesFromHTTPStatusCode generates attributes of the http -// namespace as specified by the OpenTelemetry specification for a -// span. -func HTTPAttributesFromHTTPStatusCode(code int) []attribute.KeyValue { - attrs := []attribute.KeyValue{ - HTTPStatusCodeKey.Int(code), - } - return attrs -} - -type codeRange struct { - fromInclusive int - toInclusive int -} - -func (r codeRange) contains(code int) bool { - return r.fromInclusive <= code && code <= r.toInclusive -} - -var validRangesPerCategory = map[int][]codeRange{ - 1: { - {http.StatusContinue, http.StatusEarlyHints}, - }, - 2: { - {http.StatusOK, http.StatusAlreadyReported}, - {http.StatusIMUsed, http.StatusIMUsed}, - }, - 3: { - {http.StatusMultipleChoices, http.StatusUseProxy}, - {http.StatusTemporaryRedirect, http.StatusPermanentRedirect}, - }, - 4: { - {http.StatusBadRequest, http.StatusTeapot}, // yes, teapot is so useful… - {http.StatusMisdirectedRequest, http.StatusUpgradeRequired}, - {http.StatusPreconditionRequired, http.StatusTooManyRequests}, - {http.StatusRequestHeaderFieldsTooLarge, http.StatusRequestHeaderFieldsTooLarge}, - {http.StatusUnavailableForLegalReasons, http.StatusUnavailableForLegalReasons}, - }, - 5: { - {http.StatusInternalServerError, http.StatusLoopDetected}, - {http.StatusNotExtended, http.StatusNetworkAuthenticationRequired}, - }, -} - -// SpanStatusFromHTTPStatusCode generates a status code and a message -// as specified by the OpenTelemetry specification for a span. -func SpanStatusFromHTTPStatusCode(code int) (codes.Code, string) { - spanCode, valid := validateHTTPStatusCode(code) - if !valid { - return spanCode, fmt.Sprintf("Invalid HTTP status code %d", code) - } - return spanCode, "" -} - -// Validates the HTTP status code and returns corresponding span status code. -// If the `code` is not a valid HTTP status code, returns span status Error -// and false. -func validateHTTPStatusCode(code int) (codes.Code, bool) { - category := code / 100 - ranges, ok := validRangesPerCategory[category] - if !ok { - return codes.Error, false - } - ok = false - for _, crange := range ranges { - ok = crange.contains(code) - if ok { - break - } - } - if !ok { - return codes.Error, false - } - if category > 0 && category < 4 { - return codes.Unset, true - } - return codes.Error, true -} diff --git a/vendor/go.opentelemetry.io/otel/semconv/resource.go b/vendor/go.opentelemetry.io/otel/semconv/resource.go deleted file mode 100644 index 69a9b5a6f3..0000000000 --- a/vendor/go.opentelemetry.io/otel/semconv/resource.go +++ /dev/null @@ -1,257 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package semconv // import "go.opentelemetry.io/otel/semconv" - -import "go.opentelemetry.io/otel/attribute" - -// Semantic conventions for service resource attribute keys. -const ( - // Name of the service. - ServiceNameKey = attribute.Key("service.name") - - // A namespace for `service.name`. This needs to have meaning that helps - // to distinguish a group of services. For example, the team name that - // owns a group of services. `service.name` is expected to be unique - // within the same namespace. - ServiceNamespaceKey = attribute.Key("service.namespace") - - // A unique identifier of the service instance. In conjunction with the - // `service.name` and `service.namespace` this must be unique. - ServiceInstanceIDKey = attribute.Key("service.instance.id") - - // The version of the service API. - ServiceVersionKey = attribute.Key("service.version") -) - -// Semantic conventions for telemetry SDK resource attribute keys. -const ( - // The name of the telemetry SDK. - // - // The default OpenTelemetry SDK provided by the OpenTelemetry project - // MUST set telemetry.sdk.name to the value `opentelemetry`. - // - // If another SDK is used, this attribute MUST be set to the import path - // of that SDK's package. - // - // The value `opentelemetry` is reserved and MUST NOT be used by - // non-OpenTelemetry SDKs. - TelemetrySDKNameKey = attribute.Key("telemetry.sdk.name") - - // The language of the telemetry SDK. - TelemetrySDKLanguageKey = attribute.Key("telemetry.sdk.language") - - // The version string of the telemetry SDK. - TelemetrySDKVersionKey = attribute.Key("telemetry.sdk.version") -) - -// Semantic conventions for telemetry SDK resource attributes. -var ( - TelemetrySDKLanguageGo = TelemetrySDKLanguageKey.String("go") -) - -// Semantic conventions for container resource attribute keys. -const ( - // A uniquely identifying name for the Container. - ContainerNameKey = attribute.Key("container.name") - - // Container ID, usually a UUID, as for example used to - // identify Docker containers. The UUID might be abbreviated. - ContainerIDKey = attribute.Key("container.id") - - // Name of the image the container was built on. - ContainerImageNameKey = attribute.Key("container.image.name") - - // Container image tag. - ContainerImageTagKey = attribute.Key("container.image.tag") -) - -// Semantic conventions for Function-as-a-Service resource attribute keys. -const ( - // A uniquely identifying name for the FaaS. - FaaSNameKey = attribute.Key("faas.name") - - // The unique name of the function being executed. - FaaSIDKey = attribute.Key("faas.id") - - // The version of the function being executed. - FaaSVersionKey = attribute.Key("faas.version") - - // The execution environment identifier. - FaaSInstanceKey = attribute.Key("faas.instance") -) - -// Semantic conventions for operating system process resource attribute keys. -const ( - // Process identifier (PID). - ProcessPIDKey = attribute.Key("process.pid") - // The name of the process executable. On Linux based systems, can be - // set to the `Name` in `proc/[pid]/status`. On Windows, can be set to - // the base name of `GetProcessImageFileNameW`. - ProcessExecutableNameKey = attribute.Key("process.executable.name") - // The full path to the process executable. On Linux based systems, can - // be set to the target of `proc/[pid]/exe`. On Windows, can be set to - // the result of `GetProcessImageFileNameW`. - ProcessExecutablePathKey = attribute.Key("process.executable.path") - // The command used to launch the process (i.e. the command name). On - // Linux based systems, can be set to the zeroth string in - // `proc/[pid]/cmdline`. On Windows, can be set to the first parameter - // extracted from `GetCommandLineW`. - ProcessCommandKey = attribute.Key("process.command") - // The full command used to launch the process. The value can be either - // a list of strings representing the ordered list of arguments, or a - // single string representing the full command. On Linux based systems, - // can be set to the list of null-delimited strings extracted from - // `proc/[pid]/cmdline`. On Windows, can be set to the result of - // `GetCommandLineW`. - ProcessCommandLineKey = attribute.Key("process.command_line") - // All the command arguments (including the command/executable itself) - // as received by the process. On Linux-based systems (and some other - // Unixoid systems supporting procfs), can be set according to the list - // of null-delimited strings extracted from `proc/[pid]/cmdline`. For - // libc-based executables, this would be the full argv vector passed to - // `main`. - ProcessCommandArgsKey = attribute.Key("process.command_args") - // The username of the user that owns the process. - ProcessOwnerKey = attribute.Key("process.owner") - // The name of the runtime of this process. For compiled native - // binaries, this SHOULD be the name of the compiler. - ProcessRuntimeNameKey = attribute.Key("process.runtime.name") - // The version of the runtime of this process, as returned by the - // runtime without modification. - ProcessRuntimeVersionKey = attribute.Key("process.runtime.version") - // An additional description about the runtime of the process, for - // example a specific vendor customization of the runtime environment. - ProcessRuntimeDescriptionKey = attribute.Key("process.runtime.description") -) - -// Semantic conventions for Kubernetes resource attribute keys. -const ( - // A uniquely identifying name for the Kubernetes cluster. Kubernetes - // does not have cluster names as an internal concept so this may be - // set to any meaningful value within the environment. For example, - // GKE clusters have a name which can be used for this attribute. - K8SClusterNameKey = attribute.Key("k8s.cluster.name") - - // The name of the Node. - K8SNodeNameKey = attribute.Key("k8s.node.name") - - // The UID of the Node. - K8SNodeUIDKey = attribute.Key("k8s.node.uid") - - // The name of the namespace that the pod is running in. - K8SNamespaceNameKey = attribute.Key("k8s.namespace.name") - - // The uid of the Pod. - K8SPodUIDKey = attribute.Key("k8s.pod.uid") - - // The name of the pod. - K8SPodNameKey = attribute.Key("k8s.pod.name") - - // The name of the Container in a Pod template. - K8SContainerNameKey = attribute.Key("k8s.container.name") - - // The uid of the ReplicaSet. - K8SReplicaSetUIDKey = attribute.Key("k8s.replicaset.uid") - - // The name of the ReplicaSet. - K8SReplicaSetNameKey = attribute.Key("k8s.replicaset.name") - - // The uid of the Deployment. - K8SDeploymentUIDKey = attribute.Key("k8s.deployment.uid") - - // The name of the deployment. - K8SDeploymentNameKey = attribute.Key("k8s.deployment.name") - - // The uid of the StatefulSet. - K8SStatefulSetUIDKey = attribute.Key("k8s.statefulset.uid") - - // The name of the StatefulSet. - K8SStatefulSetNameKey = attribute.Key("k8s.statefulset.name") - - // The uid of the DaemonSet. - K8SDaemonSetUIDKey = attribute.Key("k8s.daemonset.uid") - - // The name of the DaemonSet. - K8SDaemonSetNameKey = attribute.Key("k8s.daemonset.name") - - // The uid of the Job. - K8SJobUIDKey = attribute.Key("k8s.job.uid") - - // The name of the Job. - K8SJobNameKey = attribute.Key("k8s.job.name") - - // The uid of the CronJob. - K8SCronJobUIDKey = attribute.Key("k8s.cronjob.uid") - - // The name of the CronJob. - K8SCronJobNameKey = attribute.Key("k8s.cronjob.name") -) - -// Semantic conventions for OS resource attribute keys. -const ( - // The operating system type. - OSTypeKey = attribute.Key("os.type") - // Human readable (not intended to be parsed) OS version information. - OSDescriptionKey = attribute.Key("os.description") -) - -// Semantic conventions for host resource attribute keys. -const ( - // A uniquely identifying name for the host: 'hostname', FQDN, or user specified name - HostNameKey = attribute.Key("host.name") - - // Unique host ID. For cloud environments this will be the instance ID. - HostIDKey = attribute.Key("host.id") - - // Type of host. For cloud environments this will be the machine type. - HostTypeKey = attribute.Key("host.type") - - // Name of the OS or VM image the host is running. - HostImageNameKey = attribute.Key("host.image.name") - - // Identifier of the image the host is running. - HostImageIDKey = attribute.Key("host.image.id") - - // Version of the image the host is running. - HostImageVersionKey = attribute.Key("host.image.version") -) - -// Semantic conventions for cloud environment resource attribute keys. -const ( - // Name of the cloud provider. - CloudProviderKey = attribute.Key("cloud.provider") - - // The account ID from the cloud provider used for authorization. - CloudAccountIDKey = attribute.Key("cloud.account.id") - - // Geographical region where this resource is. - CloudRegionKey = attribute.Key("cloud.region") - - // Zone of the region where this resource is. - CloudZoneKey = attribute.Key("cloud.zone") -) - -// Semantic conventions for common cloud provider resource attributes. -var ( - CloudProviderAWS = CloudProviderKey.String("aws") - CloudProviderAzure = CloudProviderKey.String("azure") - CloudProviderGCP = CloudProviderKey.String("gcp") -) - -// Semantic conventions for deployment attributes. -const ( - // Name of the deployment environment (aka deployment tier); e.g. (staging, production). - DeploymentEnvironmentKey = attribute.Key("deployment.environment") -) diff --git a/vendor/go.opentelemetry.io/otel/semconv/trace.go b/vendor/go.opentelemetry.io/otel/semconv/trace.go deleted file mode 100644 index 145fc60768..0000000000 --- a/vendor/go.opentelemetry.io/otel/semconv/trace.go +++ /dev/null @@ -1,376 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package semconv // import "go.opentelemetry.io/otel/semconv" - -import "go.opentelemetry.io/otel/attribute" - -// Semantic conventions for attribute keys used for network related -// operations. -const ( - // Transport protocol used. - NetTransportKey = attribute.Key("net.transport") - - // Remote address of the peer. - NetPeerIPKey = attribute.Key("net.peer.ip") - - // Remote port number. - NetPeerPortKey = attribute.Key("net.peer.port") - - // Remote hostname or similar. - NetPeerNameKey = attribute.Key("net.peer.name") - - // Local host IP. Useful in case of a multi-IP host. - NetHostIPKey = attribute.Key("net.host.ip") - - // Local host port. - NetHostPortKey = attribute.Key("net.host.port") - - // Local hostname or similar. - NetHostNameKey = attribute.Key("net.host.name") -) - -// Semantic conventions for common transport protocol attributes. -var ( - NetTransportTCP = NetTransportKey.String("IP.TCP") - NetTransportUDP = NetTransportKey.String("IP.UDP") - NetTransportIP = NetTransportKey.String("IP") - NetTransportUnix = NetTransportKey.String("Unix") - NetTransportPipe = NetTransportKey.String("pipe") - NetTransportInProc = NetTransportKey.String("inproc") - NetTransportOther = NetTransportKey.String("other") -) - -// General attribute keys for spans. -const ( - // Service name of the remote service. Should equal the actual - // `service.name` resource attribute of the remote service, if any. - PeerServiceKey = attribute.Key("peer.service") -) - -// Semantic conventions for attribute keys used to identify an authorized -// user. -const ( - // Username or the client identifier extracted from the access token or - // authorization header in the inbound request from outside the system. - EnduserIDKey = attribute.Key("enduser.id") - - // Actual or assumed role the client is making the request with. - EnduserRoleKey = attribute.Key("enduser.role") - - // Scopes or granted authorities the client currently possesses. - EnduserScopeKey = attribute.Key("enduser.scope") -) - -// Semantic conventions for attribute keys for HTTP. -const ( - // HTTP request method. - HTTPMethodKey = attribute.Key("http.method") - - // Full HTTP request URL in the form: - // scheme://host[:port]/path?query[#fragment]. - HTTPURLKey = attribute.Key("http.url") - - // The full request target as passed in a HTTP request line or - // equivalent, e.g. "/path/12314/?q=ddds#123". - HTTPTargetKey = attribute.Key("http.target") - - // The value of the HTTP host header. - HTTPHostKey = attribute.Key("http.host") - - // The URI scheme identifying the used protocol. - HTTPSchemeKey = attribute.Key("http.scheme") - - // HTTP response status code. - HTTPStatusCodeKey = attribute.Key("http.status_code") - - // Kind of HTTP protocol used. - HTTPFlavorKey = attribute.Key("http.flavor") - - // Value of the HTTP User-Agent header sent by the client. - HTTPUserAgentKey = attribute.Key("http.user_agent") - - // The primary server name of the matched virtual host. - HTTPServerNameKey = attribute.Key("http.server_name") - - // The matched route served (path template). For example, - // "/users/:userID?". - HTTPRouteKey = attribute.Key("http.route") - - // The IP address of the original client behind all proxies, if known - // (e.g. from X-Forwarded-For). - HTTPClientIPKey = attribute.Key("http.client_ip") - - // The size of the request payload body in bytes. - HTTPRequestContentLengthKey = attribute.Key("http.request_content_length") - - // The size of the uncompressed request payload body after transport decoding. - // Not set if transport encoding not used. - HTTPRequestContentLengthUncompressedKey = attribute.Key("http.request_content_length_uncompressed") - - // The size of the response payload body in bytes. - HTTPResponseContentLengthKey = attribute.Key("http.response_content_length") - - // The size of the uncompressed response payload body after transport decoding. - // Not set if transport encoding not used. - HTTPResponseContentLengthUncompressedKey = attribute.Key("http.response_content_length_uncompressed") -) - -// Semantic conventions for common HTTP attributes. -var ( - // Semantic conventions for HTTP(S) URI schemes. - HTTPSchemeHTTP = HTTPSchemeKey.String("http") - HTTPSchemeHTTPS = HTTPSchemeKey.String("https") - - // Semantic conventions for HTTP protocols. - HTTPFlavor1_0 = HTTPFlavorKey.String("1.0") - HTTPFlavor1_1 = HTTPFlavorKey.String("1.1") - HTTPFlavor2 = HTTPFlavorKey.String("2") - HTTPFlavorSPDY = HTTPFlavorKey.String("SPDY") - HTTPFlavorQUIC = HTTPFlavorKey.String("QUIC") -) - -// Semantic conventions for attribute keys for database connections. -const ( - // Identifier for the database system (DBMS) being used. - DBSystemKey = attribute.Key("db.system") - - // Database Connection String with embedded credentials removed. - DBConnectionStringKey = attribute.Key("db.connection_string") - - // Username for accessing database. - DBUserKey = attribute.Key("db.user") -) - -// Semantic conventions for common database system attributes. -var ( - DBSystemDB2 = DBSystemKey.String("db2") // IBM DB2 - DBSystemDerby = DBSystemKey.String("derby") // Apache Derby - DBSystemHive = DBSystemKey.String("hive") // Apache Hive - DBSystemMariaDB = DBSystemKey.String("mariadb") // MariaDB - DBSystemMSSql = DBSystemKey.String("mssql") // Microsoft SQL Server - DBSystemMySQL = DBSystemKey.String("mysql") // MySQL - DBSystemOracle = DBSystemKey.String("oracle") // Oracle Database - DBSystemPostgres = DBSystemKey.String("postgresql") // PostgreSQL - DBSystemSqlite = DBSystemKey.String("sqlite") // SQLite - DBSystemTeradata = DBSystemKey.String("teradata") // Teradata - DBSystemOtherSQL = DBSystemKey.String("other_sql") // Some other Sql database. Fallback only - DBSystemCassandra = DBSystemKey.String("cassandra") // Cassandra - DBSystemCosmosDB = DBSystemKey.String("cosmosdb") // Microsoft Azure CosmosDB - DBSystemCouchbase = DBSystemKey.String("couchbase") // Couchbase - DBSystemCouchDB = DBSystemKey.String("couchdb") // CouchDB - DBSystemDynamoDB = DBSystemKey.String("dynamodb") // Amazon DynamoDB - DBSystemHBase = DBSystemKey.String("hbase") // HBase - DBSystemMongodb = DBSystemKey.String("mongodb") // MongoDB - DBSystemNeo4j = DBSystemKey.String("neo4j") // Neo4j - DBSystemRedis = DBSystemKey.String("redis") // Redis -) - -// Semantic conventions for attribute keys for database calls. -const ( - // Database instance name. - DBNameKey = attribute.Key("db.name") - - // A database statement for the given database type. - DBStatementKey = attribute.Key("db.statement") - - // A database operation for the given database type. - DBOperationKey = attribute.Key("db.operation") -) - -// Database technology-specific attributes -const ( - // Name of the Cassandra keyspace accessed. Use instead of `db.name`. - DBCassandraKeyspaceKey = attribute.Key("db.cassandra.keyspace") - - // HBase namespace accessed. Use instead of `db.name`. - DBHBaseNamespaceKey = attribute.Key("db.hbase.namespace") - - // Index of Redis database accessed. Use instead of `db.name`. - DBRedisDBIndexKey = attribute.Key("db.redis.database_index") - - // Collection being accessed within the database in `db.name`. - DBMongoDBCollectionKey = attribute.Key("db.mongodb.collection") -) - -// Semantic conventions for attribute keys for RPC. -const ( - // A string identifying the remoting system. - RPCSystemKey = attribute.Key("rpc.system") - - // The full name of the service being called. - RPCServiceKey = attribute.Key("rpc.service") - - // The name of the method being called. - RPCMethodKey = attribute.Key("rpc.method") - - // Name of message transmitted or received. - RPCNameKey = attribute.Key("name") - - // Type of message transmitted or received. - RPCMessageTypeKey = attribute.Key("message.type") - - // Identifier of message transmitted or received. - RPCMessageIDKey = attribute.Key("message.id") - - // The compressed size of the message transmitted or received in bytes. - RPCMessageCompressedSizeKey = attribute.Key("message.compressed_size") - - // The uncompressed size of the message transmitted or received in - // bytes. - RPCMessageUncompressedSizeKey = attribute.Key("message.uncompressed_size") -) - -// Semantic conventions for common RPC attributes. -var ( - // Semantic convention for gRPC as the remoting system. - RPCSystemGRPC = RPCSystemKey.String("grpc") - - // Semantic convention for a message named message. - RPCNameMessage = RPCNameKey.String("message") - - // Semantic conventions for RPC message types. - RPCMessageTypeSent = RPCMessageTypeKey.String("SENT") - RPCMessageTypeReceived = RPCMessageTypeKey.String("RECEIVED") -) - -// Semantic conventions for attribute keys for messaging systems. -const ( - // A unique identifier describing the messaging system. For example, - // kafka, rabbitmq or activemq. - MessagingSystemKey = attribute.Key("messaging.system") - - // The message destination name, e.g. MyQueue or MyTopic. - MessagingDestinationKey = attribute.Key("messaging.destination") - - // The kind of message destination. - MessagingDestinationKindKey = attribute.Key("messaging.destination_kind") - - // Describes if the destination is temporary or not. - MessagingTempDestinationKey = attribute.Key("messaging.temp_destination") - - // The name of the transport protocol. - MessagingProtocolKey = attribute.Key("messaging.protocol") - - // The version of the transport protocol. - MessagingProtocolVersionKey = attribute.Key("messaging.protocol_version") - - // Messaging service URL. - MessagingURLKey = attribute.Key("messaging.url") - - // Identifier used by the messaging system for a message. - MessagingMessageIDKey = attribute.Key("messaging.message_id") - - // Identifier used by the messaging system for a conversation. - MessagingConversationIDKey = attribute.Key("messaging.conversation_id") - - // The (uncompressed) size of the message payload in bytes. - MessagingMessagePayloadSizeBytesKey = attribute.Key("messaging.message_payload_size_bytes") - - // The compressed size of the message payload in bytes. - MessagingMessagePayloadCompressedSizeBytesKey = attribute.Key("messaging.message_payload_compressed_size_bytes") - - // Identifies which part and kind of message consumption is being - // preformed. - MessagingOperationKey = attribute.Key("messaging.operation") - - // RabbitMQ specific attribute describing the destination routing key. - MessagingRabbitMQRoutingKeyKey = attribute.Key("messaging.rabbitmq.routing_key") -) - -// Semantic conventions for common messaging system attributes. -var ( - // Semantic conventions for message destinations. - MessagingDestinationKindKeyQueue = MessagingDestinationKindKey.String("queue") - MessagingDestinationKindKeyTopic = MessagingDestinationKindKey.String("topic") - - // Semantic convention for message destinations that are temporary. - MessagingTempDestination = MessagingTempDestinationKey.Bool(true) - - // Semantic convention for the operation parts of message consumption. - // This does not include a "send" attribute as that is explicitly not - // allowed in the OpenTelemetry specification. - MessagingOperationReceive = MessagingOperationKey.String("receive") - MessagingOperationProcess = MessagingOperationKey.String("process") -) - -// Semantic conventions for attribute keys for FaaS systems. -const ( - - // Type of the trigger on which the function is executed. - FaaSTriggerKey = attribute.Key("faas.trigger") - - // String containing the execution identifier of the function. - FaaSExecutionKey = attribute.Key("faas.execution") - - // A boolean indicating that the serverless function is executed - // for the first time (aka cold start). - FaaSColdstartKey = attribute.Key("faas.coldstart") - - // The name of the source on which the operation was performed. - // For example, in Cloud Storage or S3 corresponds to the bucket name, - // and in Cosmos DB to the database name. - FaaSDocumentCollectionKey = attribute.Key("faas.document.collection") - - // The type of the operation that was performed on the data. - FaaSDocumentOperationKey = attribute.Key("faas.document.operation") - - // A string containing the time when the data was accessed. - FaaSDocumentTimeKey = attribute.Key("faas.document.time") - - // The document name/table subjected to the operation. - FaaSDocumentNameKey = attribute.Key("faas.document.name") - - // The function invocation time. - FaaSTimeKey = attribute.Key("faas.time") - - // The schedule period as Cron Expression. - FaaSCronKey = attribute.Key("faas.cron") -) - -// Semantic conventions for common FaaS system attributes. -var ( - // Semantic conventions for the types of triggers. - FaasTriggerDatasource = FaaSTriggerKey.String("datasource") - FaasTriggerHTTP = FaaSTriggerKey.String("http") - FaasTriggerPubSub = FaaSTriggerKey.String("pubsub") - FaasTriggerTimer = FaaSTriggerKey.String("timer") - FaasTriggerOther = FaaSTriggerKey.String("other") - - // Semantic conventions for the types of operations performed. - FaaSDocumentOperationInsert = FaaSDocumentOperationKey.String("insert") - FaaSDocumentOperationEdit = FaaSDocumentOperationKey.String("edit") - FaaSDocumentOperationDelete = FaaSDocumentOperationKey.String("delete") -) - -// Semantic conventions for source code attributes. -const ( - // The method or function name, or equivalent (usually rightmost part of - // the code unit's name). - CodeFunctionKey = attribute.Key("code.function") - - // The "namespace" within which `code.function` is defined. Usually the - // qualified class or module name, such that - // `code.namespace` + some separator + `code.function` form a unique - // identifier for the code unit. - CodeNamespaceKey = attribute.Key("code.namespace") - - // The source code file name that identifies the code unit as uniquely as - // possible (preferably an absolute file path). - CodeFilepathKey = attribute.Key("code.filepath") - - // The line number in `code.filepath` best representing the operation. - // It SHOULD point within the code unit named in `code.function`. - CodeLineNumberKey = attribute.Key("code.lineno") -) diff --git a/vendor/go.opentelemetry.io/otel/tag.sh b/vendor/go.opentelemetry.io/otel/tag.sh deleted file mode 100644 index 70767c7037..0000000000 --- a/vendor/go.opentelemetry.io/otel/tag.sh +++ /dev/null @@ -1,178 +0,0 @@ -#!/usr/bin/env bash - -# Copyright The OpenTelemetry Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -readonly PROGNAME=$(basename "$0") -readonly PROGDIR=$(readlink -m "$(dirname "$0")") - -readonly EXCLUDE_PACKAGES="internal/tools" -readonly SEMVER_REGEX="v(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)(\\-[0-9A-Za-z-]+(\\.[0-9A-Za-z-]+)*)?(\\+[0-9A-Za-z-]+(\\.[0-9A-Za-z-]+)*)?" - -usage() { - cat <<- EOF -Usage: $PROGNAME [OPTIONS] SEMVER_TAG COMMIT_HASH - -Creates git tag for all Go packages in project. - -OPTIONS: - -h --help Show this help. - -ARGUMENTS: - SEMVER_TAG Semantic version to tag with. - COMMIT_HASH Git commit hash to tag. -EOF -} - -cmdline() { - local arg commit - - for arg - do - local delim="" - case "$arg" in - # Translate long form options to short form. - --help) args="${args}-h ";; - # Pass through for everything else. - *) [[ "${arg:0:1}" == "-" ]] || delim="\"" - args="${args}${delim}${arg}${delim} ";; - esac - done - - # Reset and process short form options. - eval set -- "$args" - - while getopts "h" OPTION - do - case $OPTION in - h) - usage - exit 0 - ;; - *) - echo "unknown option: $OPTION" - usage - exit 1 - ;; - esac - done - - # Positional arguments. - shift $((OPTIND-1)) - readonly TAG="$1" - if [ -z "$TAG" ] - then - echo "missing SEMVER_TAG" - usage - exit 1 - fi - if [[ ! "$TAG" =~ $SEMVER_REGEX ]] - then - printf "invalid semantic version: %s\n" "$TAG" - exit 2 - fi - if [[ "$( git tag --list "$TAG" )" ]] - then - printf "tag already exists: %s\n" "$TAG" - exit 2 - fi - - shift - commit="$1" - if [ -z "$commit" ] - then - echo "missing COMMIT_HASH" - usage - exit 1 - fi - # Verify rev is for a commit and unify hashes into a complete SHA1. - readonly SHA="$( git rev-parse --quiet --verify "${commit}^{commit}" )" - if [ -z "$SHA" ] - then - printf "invalid commit hash: %s\n" "$commit" - exit 2 - fi - if [ "$( git merge-base "$SHA" HEAD )" != "$SHA" ] - then - printf "commit '%s' not found on this branch\n" "$commit" - exit 2 - fi -} - -package_dirs() { - # Return a list of package directories in the form: - # - # package/directory/a - # package/directory/b - # deeper/package/directory/a - # ... - # - # Making sure to exclude any packages in the EXCLUDE_PACKAGES regexp. - find . -mindepth 2 -type f -name 'go.mod' -exec dirname {} \; \ - | grep -E -v "$EXCLUDE_PACKAGES" \ - | sed 's/^\.\///' \ - | sort -} - -git_tag() { - local tag="$1" - local commit="$2" - - git tag -a "$tag" -s -m "Version $tag" "$commit" -} - -previous_version() { - local current="$1" - - # Requires git > 2.0 - git tag -l --sort=v:refname \ - | grep -E "^${SEMVER_REGEX}$" \ - | grep -v "$current" \ - | tail -1 -} - -print_changes() { - local tag="$1" - local previous - - previous="$( previous_version "$tag" )" - if [ -n "$previous" ] - then - printf "\nRaw changes made between %s and %s\n" "$previous" "$tag" - printf "======================================\n" - git --no-pager log --pretty=oneline "${previous}..$tag" - fi -} - -main() { - local dir - - cmdline "$@" - - cd "$PROGDIR" || exit 3 - - # Create tag for root package. - git_tag "$TAG" "$SHA" - printf "created tag: %s\n" "$TAG" - - # Create tag for all sub-packages. - for dir in $( package_dirs ) - do - git_tag "${dir}/$TAG" "$SHA" - printf "created tag: %s\n" "${dir}/$TAG" - done - - print_changes "$TAG" -} -main "$@" diff --git a/vendor/go.opentelemetry.io/otel/trace.go b/vendor/go.opentelemetry.io/otel/trace.go deleted file mode 100644 index 1d5ffb8ea5..0000000000 --- a/vendor/go.opentelemetry.io/otel/trace.go +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package otel // import "go.opentelemetry.io/otel" - -import ( - "go.opentelemetry.io/otel/internal/global" - "go.opentelemetry.io/otel/trace" -) - -// Tracer creates a named tracer that implements Tracer interface. -// If the name is an empty string then provider uses default name. -// -// This is short for GetTracerProvider().Tracer(name) -func Tracer(name string) trace.Tracer { - return GetTracerProvider().Tracer(name) -} - -// GetTracerProvider returns the registered global trace provider. -// If none is registered then an instance of NoopTracerProvider is returned. -// -// Use the trace provider to create a named tracer. E.g. -// tracer := global.GetTracerProvider().Tracer("example.com/foo") -// or -// tracer := global.Tracer("example.com/foo") -func GetTracerProvider() trace.TracerProvider { - return global.TracerProvider() -} - -// SetTracerProvider registers `tp` as the global trace provider. -func SetTracerProvider(tp trace.TracerProvider) { - global.SetTracerProvider(tp) -} diff --git a/vendor/go.opentelemetry.io/otel/trace/LICENSE b/vendor/go.opentelemetry.io/otel/trace/LICENSE deleted file mode 100644 index 261eeb9e9f..0000000000 --- a/vendor/go.opentelemetry.io/otel/trace/LICENSE +++ /dev/null @@ -1,201 +0,0 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. diff --git a/vendor/go.opentelemetry.io/otel/trace/config.go b/vendor/go.opentelemetry.io/otel/trace/config.go deleted file mode 100644 index ea30ee35f1..0000000000 --- a/vendor/go.opentelemetry.io/otel/trace/config.go +++ /dev/null @@ -1,205 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package trace - -import ( - "time" - - "go.opentelemetry.io/otel/attribute" -) - -// TracerConfig is a group of options for a Tracer. -type TracerConfig struct { - // InstrumentationVersion is the version of the library providing - // instrumentation. - InstrumentationVersion string -} - -// NewTracerConfig applies all the options to a returned TracerConfig. -func NewTracerConfig(options ...TracerOption) *TracerConfig { - config := new(TracerConfig) - for _, option := range options { - option.ApplyTracer(config) - } - return config -} - -// TracerOption applies an option to a TracerConfig. -type TracerOption interface { - ApplyTracer(*TracerConfig) - - // A private method to prevent users implementing the - // interface and so future additions to it will not - // violate compatibility. - private() -} - -// SpanConfig is a group of options for a Span. -type SpanConfig struct { - // Attributes describe the associated qualities of a Span. - Attributes []attribute.KeyValue - // Timestamp is a time in a Span life-cycle. - Timestamp time.Time - // Links are the associations a Span has with other Spans. - Links []Link - // NewRoot identifies a Span as the root Span for a new trace. This is - // commonly used when an existing trace crosses trust boundaries and the - // remote parent span context should be ignored for security. - NewRoot bool - // SpanKind is the role a Span has in a trace. - SpanKind SpanKind -} - -// NewSpanConfig applies all the options to a returned SpanConfig. -// No validation is performed on the returned SpanConfig (e.g. no uniqueness -// checking or bounding of data), it is left to the SDK to perform this -// action. -func NewSpanConfig(options ...SpanOption) *SpanConfig { - c := new(SpanConfig) - for _, option := range options { - option.ApplySpan(c) - } - return c -} - -// SpanOption applies an option to a SpanConfig. -type SpanOption interface { - ApplySpan(*SpanConfig) - - // A private method to prevent users implementing the - // interface and so future additions to it will not - // violate compatibility. - private() -} - -// NewEventConfig applies all the EventOptions to a returned SpanConfig. If no -// timestamp option is passed, the returned SpanConfig will have a Timestamp -// set to the call time, otherwise no validation is performed on the returned -// SpanConfig. -func NewEventConfig(options ...EventOption) *SpanConfig { - c := new(SpanConfig) - for _, option := range options { - option.ApplyEvent(c) - } - if c.Timestamp.IsZero() { - c.Timestamp = time.Now() - } - return c -} - -// EventOption applies span event options to a SpanConfig. -type EventOption interface { - ApplyEvent(*SpanConfig) - - // A private method to prevent users implementing the - // interface and so future additions to it will not - // violate compatibility. - private() -} - -// LifeCycleOption applies span life-cycle options to a SpanConfig. These -// options set values releated to events in a spans life-cycle like starting, -// ending, experiencing an error and other user defined notable events. -type LifeCycleOption interface { - SpanOption - EventOption -} - -type attributeSpanOption []attribute.KeyValue - -func (o attributeSpanOption) ApplySpan(c *SpanConfig) { o.apply(c) } -func (o attributeSpanOption) ApplyEvent(c *SpanConfig) { o.apply(c) } -func (attributeSpanOption) private() {} -func (o attributeSpanOption) apply(c *SpanConfig) { - c.Attributes = append(c.Attributes, []attribute.KeyValue(o)...) -} - -// WithAttributes adds the attributes related to a span life-cycle event. -// These attributes are used to describe the work a Span represents when this -// option is provided to a Span's start or end events. Otherwise, these -// attributes provide additional information about the event being recorded -// (e.g. error, state change, processing progress, system event). -// -// If multiple of these options are passed the attributes of each successive -// option will extend the attributes instead of overwriting. There is no -// guarantee of uniqueness in the resulting attributes. -func WithAttributes(attributes ...attribute.KeyValue) LifeCycleOption { - return attributeSpanOption(attributes) -} - -type timestampSpanOption time.Time - -func (o timestampSpanOption) ApplySpan(c *SpanConfig) { o.apply(c) } -func (o timestampSpanOption) ApplyEvent(c *SpanConfig) { o.apply(c) } -func (timestampSpanOption) private() {} -func (o timestampSpanOption) apply(c *SpanConfig) { c.Timestamp = time.Time(o) } - -// WithTimestamp sets the time of a Span life-cycle moment (e.g. started, -// stopped, errored). -func WithTimestamp(t time.Time) LifeCycleOption { - return timestampSpanOption(t) -} - -type linksSpanOption []Link - -func (o linksSpanOption) ApplySpan(c *SpanConfig) { c.Links = append(c.Links, []Link(o)...) } -func (linksSpanOption) private() {} - -// WithLinks adds links to a Span. The links are added to the existing Span -// links, i.e. this does not overwrite. -func WithLinks(links ...Link) SpanOption { - return linksSpanOption(links) -} - -type newRootSpanOption bool - -func (o newRootSpanOption) ApplySpan(c *SpanConfig) { c.NewRoot = bool(o) } -func (newRootSpanOption) private() {} - -// WithNewRoot specifies that the Span should be treated as a root Span. Any -// existing parent span context will be ignored when defining the Span's trace -// identifiers. -func WithNewRoot() SpanOption { - return newRootSpanOption(true) -} - -type spanKindSpanOption SpanKind - -func (o spanKindSpanOption) ApplySpan(c *SpanConfig) { c.SpanKind = SpanKind(o) } -func (o spanKindSpanOption) private() {} - -// WithSpanKind sets the SpanKind of a Span. -func WithSpanKind(kind SpanKind) SpanOption { - return spanKindSpanOption(kind) -} - -// InstrumentationOption is an interface for applying instrumentation specific -// options. -type InstrumentationOption interface { - TracerOption -} - -// WithInstrumentationVersion sets the instrumentation version. -func WithInstrumentationVersion(version string) InstrumentationOption { - return instrumentationVersionOption(version) -} - -type instrumentationVersionOption string - -func (i instrumentationVersionOption) ApplyTracer(config *TracerConfig) { - config.InstrumentationVersion = string(i) -} - -func (instrumentationVersionOption) private() {} diff --git a/vendor/go.opentelemetry.io/otel/trace/context.go b/vendor/go.opentelemetry.io/otel/trace/context.go deleted file mode 100644 index 76f9a083c4..0000000000 --- a/vendor/go.opentelemetry.io/otel/trace/context.go +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package trace // import "go.opentelemetry.io/otel/trace" - -import "context" - -type traceContextKeyType int - -const currentSpanKey traceContextKeyType = iota - -// ContextWithSpan returns a copy of parent with span set as the current Span. -func ContextWithSpan(parent context.Context, span Span) context.Context { - return context.WithValue(parent, currentSpanKey, span) -} - -// ContextWithSpanContext returns a copy of parent with sc as the current -// Span. The Span implementation that wraps sc is non-recording and performs -// no operations other than to return sc as the SpanContext from the -// SpanContext method. -func ContextWithSpanContext(parent context.Context, sc SpanContext) context.Context { - return ContextWithSpan(parent, nonRecordingSpan{sc: sc}) -} - -// ContextWithRemoteSpanContext returns a copy of parent with rsc set explicly -// as a remote SpanContext and as the current Span. The Span implementation -// that wraps rsc is non-recording and performs no operations other than to -// return rsc as the SpanContext from the SpanContext method. -func ContextWithRemoteSpanContext(parent context.Context, rsc SpanContext) context.Context { - return ContextWithSpanContext(parent, rsc.WithRemote(true)) -} - -// SpanFromContext returns the current Span from ctx. -// -// If no Span is currently set in ctx an implementation of a Span that -// performs no operations is returned. -func SpanFromContext(ctx context.Context) Span { - if ctx == nil { - return noopSpan{} - } - if span, ok := ctx.Value(currentSpanKey).(Span); ok { - return span - } - return noopSpan{} -} - -// SpanContextFromContext returns the current Span's SpanContext. -func SpanContextFromContext(ctx context.Context) SpanContext { - return SpanFromContext(ctx).SpanContext() -} diff --git a/vendor/go.opentelemetry.io/otel/trace/doc.go b/vendor/go.opentelemetry.io/otel/trace/doc.go deleted file mode 100644 index c962f3bc62..0000000000 --- a/vendor/go.opentelemetry.io/otel/trace/doc.go +++ /dev/null @@ -1,70 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/* -Package trace provides an implementation of the tracing part of the -OpenTelemetry API. - -This package is currently in a pre-GA phase. Backwards incompatible changes -may be introduced in subsequent minor version releases as we work to track the -evolving OpenTelemetry specification and user feedback. - -To participate in distributed traces a Span needs to be created for the -operation being performed as part of a traced workflow. It its simplest form: - - var tracer trace.Tracer - - func init() { - tracer = otel.Tracer("instrumentation/package/name") - } - - func operation(ctx context.Context) { - var span trace.Span - ctx, span = tracer.Start(ctx, "operation") - defer span.End() - // ... - } - -A Tracer is unique to the instrumentation and is used to create Spans. -Instrumentation should be designed to accept a TracerProvider from which it -can create its own unique Tracer. Alternatively, the registered global -TracerProvider from the go.opentelemetry.io/otel package can be used as -a default. - - const ( - name = "instrumentation/package/name" - version = "0.1.0" - ) - - type Instrumentation struct { - tracer trace.Tracer - } - - func NewInstrumentation(tp trace.TracerProvider) *Instrumentation { - if tp == nil { - tp = otel.TracerProvider() - } - return &Instrumentation{ - tracer: tp.Tracer(name, trace.WithInstrumentationVersion(version)), - } - } - - func operation(ctx context.Context, inst *Instrumentation) { - var span trace.Span - ctx, span = inst.tracer.Start(ctx, "operation") - defer span.End() - // ... - } -*/ -package trace // import "go.opentelemetry.io/otel/trace" diff --git a/vendor/go.opentelemetry.io/otel/trace/go.mod b/vendor/go.opentelemetry.io/otel/trace/go.mod deleted file mode 100644 index 914e4f4384..0000000000 --- a/vendor/go.opentelemetry.io/otel/trace/go.mod +++ /dev/null @@ -1,53 +0,0 @@ -module go.opentelemetry.io/otel/trace - -go 1.14 - -replace go.opentelemetry.io/otel => ../ - -replace go.opentelemetry.io/otel/bridge/opencensus => ../bridge/opencensus - -replace go.opentelemetry.io/otel/bridge/opentracing => ../bridge/opentracing - -replace go.opentelemetry.io/otel/example/jaeger => ../example/jaeger - -replace go.opentelemetry.io/otel/example/namedtracer => ../example/namedtracer - -replace go.opentelemetry.io/otel/example/opencensus => ../example/opencensus - -replace go.opentelemetry.io/otel/example/otel-collector => ../example/otel-collector - -replace go.opentelemetry.io/otel/example/prom-collector => ../example/prom-collector - -replace go.opentelemetry.io/otel/example/prometheus => ../example/prometheus - -replace go.opentelemetry.io/otel/example/zipkin => ../example/zipkin - -replace go.opentelemetry.io/otel/exporters/metric/prometheus => ../exporters/metric/prometheus - -replace go.opentelemetry.io/otel/exporters/otlp => ../exporters/otlp - -replace go.opentelemetry.io/otel/exporters/stdout => ../exporters/stdout - -replace go.opentelemetry.io/otel/exporters/trace/jaeger => ../exporters/trace/jaeger - -replace go.opentelemetry.io/otel/exporters/trace/zipkin => ../exporters/trace/zipkin - -replace go.opentelemetry.io/otel/internal/tools => ../internal/tools - -replace go.opentelemetry.io/otel/metric => ../metric - -replace go.opentelemetry.io/otel/oteltest => ../oteltest - -replace go.opentelemetry.io/otel/sdk => ../sdk - -replace go.opentelemetry.io/otel/sdk/export/metric => ../sdk/export/metric - -replace go.opentelemetry.io/otel/sdk/metric => ../sdk/metric - -replace go.opentelemetry.io/otel/trace => ./ - -require ( - github.com/google/go-cmp v0.5.5 - github.com/stretchr/testify v1.7.0 - go.opentelemetry.io/otel v0.20.0 -) diff --git a/vendor/go.opentelemetry.io/otel/trace/go.sum b/vendor/go.opentelemetry.io/otel/trace/go.sum deleted file mode 100644 index b69f2e56da..0000000000 --- a/vendor/go.opentelemetry.io/otel/trace/go.sum +++ /dev/null @@ -1,15 +0,0 @@ -github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= -github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= -github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/vendor/go.opentelemetry.io/otel/trace/nonrecording.go b/vendor/go.opentelemetry.io/otel/trace/nonrecording.go deleted file mode 100644 index 88fcb81611..0000000000 --- a/vendor/go.opentelemetry.io/otel/trace/nonrecording.go +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package trace // import "go.opentelemetry.io/otel/trace" - -// nonRecordingSpan is a minimal implementation of a Span that wraps a -// SpanContext. It performs no operations other than to return the wrapped -// SpanContext. -type nonRecordingSpan struct { - noopSpan - - sc SpanContext -} - -// SpanContext returns the wrapped SpanContext. -func (s nonRecordingSpan) SpanContext() SpanContext { return s.sc } diff --git a/vendor/go.opentelemetry.io/otel/trace/noop.go b/vendor/go.opentelemetry.io/otel/trace/noop.go deleted file mode 100644 index 4a20f20cb4..0000000000 --- a/vendor/go.opentelemetry.io/otel/trace/noop.go +++ /dev/null @@ -1,84 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package trace // import "go.opentelemetry.io/otel/trace" - -import ( - "context" - - "go.opentelemetry.io/otel/attribute" - "go.opentelemetry.io/otel/codes" -) - -// NewNoopTracerProvider returns an implementation of TracerProvider that -// performs no operations. The Tracer and Spans created from the returned -// TracerProvider also perform no operations. -func NewNoopTracerProvider() TracerProvider { - return noopTracerProvider{} -} - -type noopTracerProvider struct{} - -var _ TracerProvider = noopTracerProvider{} - -// Tracer returns noop implementation of Tracer. -func (p noopTracerProvider) Tracer(string, ...TracerOption) Tracer { - return noopTracer{} -} - -// noopTracer is an implementation of Tracer that preforms no operations. -type noopTracer struct{} - -var _ Tracer = noopTracer{} - -// Start starts a noop span. -func (t noopTracer) Start(ctx context.Context, name string, _ ...SpanOption) (context.Context, Span) { - span := noopSpan{} - return ContextWithSpan(ctx, span), span -} - -// noopSpan is an implementation of Span that preforms no operations. -type noopSpan struct{} - -var _ Span = noopSpan{} - -// SpanContext returns an empty span context. -func (noopSpan) SpanContext() SpanContext { return SpanContext{} } - -// IsRecording always returns false. -func (noopSpan) IsRecording() bool { return false } - -// SetStatus does nothing. -func (noopSpan) SetStatus(codes.Code, string) {} - -// SetError does nothing. -func (noopSpan) SetError(bool) {} - -// SetAttributes does nothing. -func (noopSpan) SetAttributes(...attribute.KeyValue) {} - -// End does nothing. -func (noopSpan) End(...SpanOption) {} - -// RecordError does nothing. -func (noopSpan) RecordError(error, ...EventOption) {} - -// Tracer returns the Tracer that created this Span. -func (noopSpan) Tracer() Tracer { return noopTracer{} } - -// AddEvent does nothing. -func (noopSpan) AddEvent(string, ...EventOption) {} - -// SetName does nothing. -func (noopSpan) SetName(string) {} diff --git a/vendor/go.opentelemetry.io/otel/trace/trace.go b/vendor/go.opentelemetry.io/otel/trace/trace.go deleted file mode 100644 index d372e7d9d7..0000000000 --- a/vendor/go.opentelemetry.io/otel/trace/trace.go +++ /dev/null @@ -1,673 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package trace // import "go.opentelemetry.io/otel/trace" - -import ( - "bytes" - "context" - "encoding/hex" - "encoding/json" - "regexp" - "strings" - "time" - - "go.opentelemetry.io/otel/attribute" - "go.opentelemetry.io/otel/codes" -) - -const ( - // FlagsSampled is a bitmask with the sampled bit set. A SpanContext - // with the sampling bit set means the span is sampled. - FlagsSampled = TraceFlags(0x01) - - errInvalidHexID errorConst = "trace-id and span-id can only contain [0-9a-f] characters, all lowercase" - - errInvalidTraceIDLength errorConst = "hex encoded trace-id must have length equals to 32" - errNilTraceID errorConst = "trace-id can't be all zero" - - errInvalidSpanIDLength errorConst = "hex encoded span-id must have length equals to 16" - errNilSpanID errorConst = "span-id can't be all zero" - - // based on the W3C Trace Context specification, see https://www.w3.org/TR/trace-context-1/#tracestate-header - traceStateKeyFormat = `[a-z][_0-9a-z\-\*\/]{0,255}` - traceStateKeyFormatWithMultiTenantVendor = `[a-z0-9][_0-9a-z\-\*\/]{0,240}@[a-z][_0-9a-z\-\*\/]{0,13}` - traceStateValueFormat = `[\x20-\x2b\x2d-\x3c\x3e-\x7e]{0,255}[\x21-\x2b\x2d-\x3c\x3e-\x7e]` - - traceStateMaxListMembers = 32 - - errInvalidTraceStateKeyValue errorConst = "provided key or value is not valid according to the" + - " W3C Trace Context specification" - errInvalidTraceStateMembersNumber errorConst = "trace state would exceed the maximum limit of members (32)" - errInvalidTraceStateDuplicate errorConst = "trace state key/value pairs with duplicate keys provided" -) - -type errorConst string - -func (e errorConst) Error() string { - return string(e) -} - -// TraceID is a unique identity of a trace. -// nolint:golint -type TraceID [16]byte - -var nilTraceID TraceID -var _ json.Marshaler = nilTraceID - -// IsValid checks whether the trace TraceID is valid. A valid trace ID does -// not consist of zeros only. -func (t TraceID) IsValid() bool { - return !bytes.Equal(t[:], nilTraceID[:]) -} - -// MarshalJSON implements a custom marshal function to encode TraceID -// as a hex string. -func (t TraceID) MarshalJSON() ([]byte, error) { - return json.Marshal(t.String()) -} - -// String returns the hex string representation form of a TraceID -func (t TraceID) String() string { - return hex.EncodeToString(t[:]) -} - -// SpanID is a unique identity of a span in a trace. -type SpanID [8]byte - -var nilSpanID SpanID -var _ json.Marshaler = nilSpanID - -// IsValid checks whether the SpanID is valid. A valid SpanID does not consist -// of zeros only. -func (s SpanID) IsValid() bool { - return !bytes.Equal(s[:], nilSpanID[:]) -} - -// MarshalJSON implements a custom marshal function to encode SpanID -// as a hex string. -func (s SpanID) MarshalJSON() ([]byte, error) { - return json.Marshal(s.String()) -} - -// String returns the hex string representation form of a SpanID -func (s SpanID) String() string { - return hex.EncodeToString(s[:]) -} - -// TraceIDFromHex returns a TraceID from a hex string if it is compliant with -// the W3C trace-context specification. See more at -// https://www.w3.org/TR/trace-context/#trace-id -// nolint:golint -func TraceIDFromHex(h string) (TraceID, error) { - t := TraceID{} - if len(h) != 32 { - return t, errInvalidTraceIDLength - } - - if err := decodeHex(h, t[:]); err != nil { - return t, err - } - - if !t.IsValid() { - return t, errNilTraceID - } - return t, nil -} - -// SpanIDFromHex returns a SpanID from a hex string if it is compliant -// with the w3c trace-context specification. -// See more at https://www.w3.org/TR/trace-context/#parent-id -func SpanIDFromHex(h string) (SpanID, error) { - s := SpanID{} - if len(h) != 16 { - return s, errInvalidSpanIDLength - } - - if err := decodeHex(h, s[:]); err != nil { - return s, err - } - - if !s.IsValid() { - return s, errNilSpanID - } - return s, nil -} - -func decodeHex(h string, b []byte) error { - for _, r := range h { - switch { - case 'a' <= r && r <= 'f': - continue - case '0' <= r && r <= '9': - continue - default: - return errInvalidHexID - } - } - - decoded, err := hex.DecodeString(h) - if err != nil { - return err - } - - copy(b, decoded) - return nil -} - -// TraceState provides additional vendor-specific trace identification information -// across different distributed tracing systems. It represents an immutable list consisting -// of key/value pairs. There can be a maximum of 32 entries in the list. -// -// Key and value of each list member must be valid according to the W3C Trace Context specification -// (see https://www.w3.org/TR/trace-context-1/#key and https://www.w3.org/TR/trace-context-1/#value -// respectively). -// -// Trace state must be valid according to the W3C Trace Context specification at all times. All -// mutating operations validate their input and, in case of valid parameters, return a new TraceState. -type TraceState struct { //nolint:golint - // TODO @matej-g: Consider implementing this as attribute.Set, see - // comment https://github.com/open-telemetry/opentelemetry-go/pull/1340#discussion_r540599226 - kvs []attribute.KeyValue -} - -var _ json.Marshaler = TraceState{} -var _ json.Marshaler = SpanContext{} - -var keyFormatRegExp = regexp.MustCompile( - `^((` + traceStateKeyFormat + `)|(` + traceStateKeyFormatWithMultiTenantVendor + `))$`, -) -var valueFormatRegExp = regexp.MustCompile(`^(` + traceStateValueFormat + `)$`) - -// MarshalJSON implements a custom marshal function to encode trace state. -func (ts TraceState) MarshalJSON() ([]byte, error) { - return json.Marshal(ts.kvs) -} - -// String returns trace state as a string valid according to the -// W3C Trace Context specification. -func (ts TraceState) String() string { - var sb strings.Builder - - for i, kv := range ts.kvs { - sb.WriteString((string)(kv.Key)) - sb.WriteByte('=') - sb.WriteString(kv.Value.Emit()) - - if i != len(ts.kvs)-1 { - sb.WriteByte(',') - } - } - - return sb.String() -} - -// Get returns a value for given key from the trace state. -// If no key is found or provided key is invalid, returns an empty value. -func (ts TraceState) Get(key attribute.Key) attribute.Value { - if !isTraceStateKeyValid(key) { - return attribute.Value{} - } - - for _, kv := range ts.kvs { - if kv.Key == key { - return kv.Value - } - } - - return attribute.Value{} -} - -// Insert adds a new key/value, if one doesn't exists; otherwise updates the existing entry. -// The new or updated entry is always inserted at the beginning of the TraceState, i.e. -// on the left side, as per the W3C Trace Context specification requirement. -func (ts TraceState) Insert(entry attribute.KeyValue) (TraceState, error) { - if !isTraceStateKeyValueValid(entry) { - return ts, errInvalidTraceStateKeyValue - } - - ckvs := ts.copyKVsAndDeleteEntry(entry.Key) - if len(ckvs)+1 > traceStateMaxListMembers { - return ts, errInvalidTraceStateMembersNumber - } - - ckvs = append(ckvs, attribute.KeyValue{}) - copy(ckvs[1:], ckvs) - ckvs[0] = entry - - return TraceState{ckvs}, nil -} - -// Delete removes specified entry from the trace state. -func (ts TraceState) Delete(key attribute.Key) (TraceState, error) { - if !isTraceStateKeyValid(key) { - return ts, errInvalidTraceStateKeyValue - } - - return TraceState{ts.copyKVsAndDeleteEntry(key)}, nil -} - -// IsEmpty returns true if the TraceState does not contain any entries -func (ts TraceState) IsEmpty() bool { - return len(ts.kvs) == 0 -} - -func (ts TraceState) copyKVsAndDeleteEntry(key attribute.Key) []attribute.KeyValue { - ckvs := make([]attribute.KeyValue, len(ts.kvs)) - copy(ckvs, ts.kvs) - for i, kv := range ts.kvs { - if kv.Key == key { - ckvs = append(ckvs[:i], ckvs[i+1:]...) - break - } - } - - return ckvs -} - -// TraceStateFromKeyValues is a convenience method to create a new TraceState from -// provided key/value pairs. -func TraceStateFromKeyValues(kvs ...attribute.KeyValue) (TraceState, error) { //nolint:golint - if len(kvs) == 0 { - return TraceState{}, nil - } - - if len(kvs) > traceStateMaxListMembers { - return TraceState{}, errInvalidTraceStateMembersNumber - } - - km := make(map[attribute.Key]bool) - for _, kv := range kvs { - if !isTraceStateKeyValueValid(kv) { - return TraceState{}, errInvalidTraceStateKeyValue - } - _, ok := km[kv.Key] - if ok { - return TraceState{}, errInvalidTraceStateDuplicate - } - km[kv.Key] = true - } - - ckvs := make([]attribute.KeyValue, len(kvs)) - copy(ckvs, kvs) - return TraceState{ckvs}, nil -} - -func isTraceStateKeyValid(key attribute.Key) bool { - return keyFormatRegExp.MatchString(string(key)) -} - -func isTraceStateKeyValueValid(kv attribute.KeyValue) bool { - return isTraceStateKeyValid(kv.Key) && - valueFormatRegExp.MatchString(kv.Value.Emit()) -} - -// TraceFlags contains flags that can be set on a SpanContext -type TraceFlags byte //nolint:golint - -// IsSampled returns if the sampling bit is set in the TraceFlags. -func (tf TraceFlags) IsSampled() bool { - return tf&FlagsSampled == FlagsSampled -} - -// WithSampled sets the sampling bit in a new copy of the TraceFlags. -func (tf TraceFlags) WithSampled(sampled bool) TraceFlags { - if sampled { - return tf | FlagsSampled - } - - return tf &^ FlagsSampled -} - -// MarshalJSON implements a custom marshal function to encode TraceFlags -// as a hex string. -func (tf TraceFlags) MarshalJSON() ([]byte, error) { - return json.Marshal(tf.String()) -} - -// String returns the hex string representation form of TraceFlags -func (tf TraceFlags) String() string { - return hex.EncodeToString([]byte{byte(tf)}[:]) -} - -// SpanContextConfig contains mutable fields usable for constructing -// an immutable SpanContext. -type SpanContextConfig struct { - TraceID TraceID - SpanID SpanID - TraceFlags TraceFlags - TraceState TraceState - Remote bool -} - -// NewSpanContext constructs a SpanContext using values from the provided -// SpanContextConfig. -func NewSpanContext(config SpanContextConfig) SpanContext { - return SpanContext{ - traceID: config.TraceID, - spanID: config.SpanID, - traceFlags: config.TraceFlags, - traceState: config.TraceState, - remote: config.Remote, - } -} - -// SpanContext contains identifying trace information about a Span. -type SpanContext struct { - traceID TraceID - spanID SpanID - traceFlags TraceFlags - traceState TraceState - remote bool -} - -// IsValid returns if the SpanContext is valid. A valid span context has a -// valid TraceID and SpanID. -func (sc SpanContext) IsValid() bool { - return sc.HasTraceID() && sc.HasSpanID() -} - -// IsRemote indicates whether the SpanContext represents a remotely-created Span. -func (sc SpanContext) IsRemote() bool { - return sc.remote -} - -// WithRemote returns a copy of sc with the Remote property set to remote. -func (sc SpanContext) WithRemote(remote bool) SpanContext { - return SpanContext{ - traceID: sc.traceID, - spanID: sc.spanID, - traceFlags: sc.traceFlags, - traceState: sc.traceState, - remote: remote, - } -} - -// TraceID returns the TraceID from the SpanContext. -func (sc SpanContext) TraceID() TraceID { - return sc.traceID -} - -// HasTraceID checks if the SpanContext has a valid TraceID. -func (sc SpanContext) HasTraceID() bool { - return sc.traceID.IsValid() -} - -// WithTraceID returns a new SpanContext with the TraceID replaced. -func (sc SpanContext) WithTraceID(traceID TraceID) SpanContext { - return SpanContext{ - traceID: traceID, - spanID: sc.spanID, - traceFlags: sc.traceFlags, - traceState: sc.traceState, - remote: sc.remote, - } -} - -// SpanID returns the SpanID from the SpanContext. -func (sc SpanContext) SpanID() SpanID { - return sc.spanID -} - -// HasSpanID checks if the SpanContext has a valid SpanID. -func (sc SpanContext) HasSpanID() bool { - return sc.spanID.IsValid() -} - -// WithSpanID returns a new SpanContext with the SpanID replaced. -func (sc SpanContext) WithSpanID(spanID SpanID) SpanContext { - return SpanContext{ - traceID: sc.traceID, - spanID: spanID, - traceFlags: sc.traceFlags, - traceState: sc.traceState, - remote: sc.remote, - } -} - -// TraceFlags returns the flags from the SpanContext. -func (sc SpanContext) TraceFlags() TraceFlags { - return sc.traceFlags -} - -// IsSampled returns if the sampling bit is set in the SpanContext's TraceFlags. -func (sc SpanContext) IsSampled() bool { - return sc.traceFlags.IsSampled() -} - -// WithTraceFlags returns a new SpanContext with the TraceFlags replaced. -func (sc SpanContext) WithTraceFlags(flags TraceFlags) SpanContext { - return SpanContext{ - traceID: sc.traceID, - spanID: sc.spanID, - traceFlags: flags, - traceState: sc.traceState, - remote: sc.remote, - } -} - -// TraceState returns the TraceState from the SpanContext. -func (sc SpanContext) TraceState() TraceState { - return sc.traceState -} - -// WithTraceState returns a new SpanContext with the TraceState replaced. -func (sc SpanContext) WithTraceState(state TraceState) SpanContext { - return SpanContext{ - traceID: sc.traceID, - spanID: sc.spanID, - traceFlags: sc.traceFlags, - traceState: state, - remote: sc.remote, - } -} - -// Equal is a predicate that determines whether two SpanContext values are equal. -func (sc SpanContext) Equal(other SpanContext) bool { - return sc.traceID == other.traceID && - sc.spanID == other.spanID && - sc.traceFlags == other.traceFlags && - sc.traceState.String() == other.traceState.String() && - sc.remote == other.remote -} - -// MarshalJSON implements a custom marshal function to encode a SpanContext. -func (sc SpanContext) MarshalJSON() ([]byte, error) { - return json.Marshal(SpanContextConfig{ - TraceID: sc.traceID, - SpanID: sc.spanID, - TraceFlags: sc.traceFlags, - TraceState: sc.traceState, - Remote: sc.remote, - }) -} - -// Span is the individual component of a trace. It represents a single named -// and timed operation of a workflow that is traced. A Tracer is used to -// create a Span and it is then up to the operation the Span represents to -// properly end the Span when the operation itself ends. -type Span interface { - // Tracer returns the Tracer that created the Span. Tracer MUST NOT be - // nil. - Tracer() Tracer - - // End completes the Span. The Span is considered complete and ready to be - // delivered through the rest of the telemetry pipeline after this method - // is called. Therefore, updates to the Span are not allowed after this - // method has been called. - End(options ...SpanOption) - - // AddEvent adds an event with the provided name and options. - AddEvent(name string, options ...EventOption) - - // IsRecording returns the recording state of the Span. It will return - // true if the Span is active and events can be recorded. - IsRecording() bool - - // RecordError will record err as an exception span event for this span. An - // additional call toSetStatus is required if the Status of the Span should - // be set to Error, this method does not change the Span status. If this - // span is not being recorded or err is nil than this method does nothing. - RecordError(err error, options ...EventOption) - - // SpanContext returns the SpanContext of the Span. The returned - // SpanContext is usable even after the End has been called for the Span. - SpanContext() SpanContext - - // SetStatus sets the status of the Span in the form of a code and a - // message. SetStatus overrides the value of previous calls to SetStatus - // on the Span. - SetStatus(code codes.Code, msg string) - - // SetName sets the Span name. - SetName(name string) - - // SetAttributes sets kv as attributes of the Span. If a key from kv - // already exists for an attribute of the Span it will be overwritten with - // the value contained in kv. - SetAttributes(kv ...attribute.KeyValue) -} - -// Event is a thing that happened during a Span's lifetime. -type Event struct { - // Name is the name of this event - Name string - - // Attributes describe the aspects of the event. - Attributes []attribute.KeyValue - - // DroppedAttributeCount is the number of attributes that were not - // recorded due to configured limits being reached. - DroppedAttributeCount int - - // Time at which this event was recorded. - Time time.Time -} - -// Link is the relationship between two Spans. The relationship can be within -// the same Trace or across different Traces. -// -// For example, a Link is used in the following situations: -// -// 1. Batch Processing: A batch of operations may contain operations -// associated with one or more traces/spans. Since there can only be one -// parent SpanContext, a Link is used to keep reference to the -// SpanContext of all operations in the batch. -// 2. Public Endpoint: A SpanContext for an in incoming client request on a -// public endpoint should be considered untrusted. In such a case, a new -// trace with its own identity and sampling decision needs to be created, -// but this new trace needs to be related to the original trace in some -// form. A Link is used to keep reference to the original SpanContext and -// track the relationship. -type Link struct { - // SpanContext of the linked Span. - SpanContext - - // Attributes describe the aspects of the link. - Attributes []attribute.KeyValue - - // DroppedAttributeCount is the number of attributes that were not - // recorded due to configured limits being reached. - DroppedAttributeCount int -} - -// SpanKind is the role a Span plays in a Trace. -type SpanKind int - -// As a convenience, these match the proto definition, see -// https://github.com/open-telemetry/opentelemetry-proto/blob/30d237e1ff3ab7aa50e0922b5bebdd93505090af/opentelemetry/proto/trace/v1/trace.proto#L101-L129 -// -// The unspecified value is not a valid `SpanKind`. Use `ValidateSpanKind()` -// to coerce a span kind to a valid value. -const ( - // SpanKindUnspecified is an unspecified SpanKind and is not a valid - // SpanKind. SpanKindUnspecified should be replaced with SpanKindInternal - // if it is received. - SpanKindUnspecified SpanKind = 0 - // SpanKindInternal is a SpanKind for a Span that represents an internal - // operation within an application. - SpanKindInternal SpanKind = 1 - // SpanKindServer is a SpanKind for a Span that represents the operation - // of handling a request from a client. - SpanKindServer SpanKind = 2 - // SpanKindClient is a SpanKind for a Span that represents the operation - // of client making a request to a server. - SpanKindClient SpanKind = 3 - // SpanKindProducer is a SpanKind for a Span that represents the operation - // of a producer sending a message to a message broker. Unlike - // SpanKindClient and SpanKindServer, there is often no direct - // relationship between this kind of Span and a SpanKindConsumer kind. A - // SpanKindProducer Span will end once the message is accepted by the - // message broker which might not overlap with the processing of that - // message. - SpanKindProducer SpanKind = 4 - // SpanKindConsumer is a SpanKind for a Span that represents the operation - // of a consumer receiving a message from a message broker. Like - // SpanKindProducer Spans, there is often no direct relationship between - // this Span and the Span that produced the message. - SpanKindConsumer SpanKind = 5 -) - -// ValidateSpanKind returns a valid span kind value. This will coerce -// invalid values into the default value, SpanKindInternal. -func ValidateSpanKind(spanKind SpanKind) SpanKind { - switch spanKind { - case SpanKindInternal, - SpanKindServer, - SpanKindClient, - SpanKindProducer, - SpanKindConsumer: - // valid - return spanKind - default: - return SpanKindInternal - } -} - -// String returns the specified name of the SpanKind in lower-case. -func (sk SpanKind) String() string { - switch sk { - case SpanKindInternal: - return "internal" - case SpanKindServer: - return "server" - case SpanKindClient: - return "client" - case SpanKindProducer: - return "producer" - case SpanKindConsumer: - return "consumer" - default: - return "unspecified" - } -} - -// Tracer is the creator of Spans. -type Tracer interface { - // Start creates a span. - Start(ctx context.Context, spanName string, opts ...SpanOption) (context.Context, Span) -} - -// TracerProvider provides access to instrumentation Tracers. -type TracerProvider interface { - // Tracer creates an implementation of the Tracer interface. - // The instrumentationName must be the name of the library providing - // instrumentation. This name may be the same as the instrumented code - // only if that code provides built-in instrumentation. If the - // instrumentationName is empty, then a implementation defined default - // name will be used instead. - // - // This method must be concurrency safe. - Tracer(instrumentationName string, opts ...TracerOption) Tracer -} diff --git a/vendor/go.opentelemetry.io/otel/unit/doc.go b/vendor/go.opentelemetry.io/otel/unit/doc.go deleted file mode 100644 index 0d77a750cc..0000000000 --- a/vendor/go.opentelemetry.io/otel/unit/doc.go +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package unit provides units. -// -// This package is currently in a pre-GA phase. Backwards incompatible changes -// may be introduced in subsequent minor version releases as we work to track -// the evolving OpenTelemetry specification and user feedback. -package unit // import "go.opentelemetry.io/otel/unit" diff --git a/vendor/go.opentelemetry.io/otel/unit/unit.go b/vendor/go.opentelemetry.io/otel/unit/unit.go deleted file mode 100644 index 523bfe1d0a..0000000000 --- a/vendor/go.opentelemetry.io/otel/unit/unit.go +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package unit // import "go.opentelemetry.io/otel/unit" - -type Unit string - -const ( - Dimensionless Unit = "1" - Bytes Unit = "By" - Milliseconds Unit = "ms" -) diff --git a/vendor/go.opentelemetry.io/otel/verify_examples.sh b/vendor/go.opentelemetry.io/otel/verify_examples.sh deleted file mode 100644 index dbb61a4227..0000000000 --- a/vendor/go.opentelemetry.io/otel/verify_examples.sh +++ /dev/null @@ -1,85 +0,0 @@ -#!/bin/bash - -# Copyright The OpenTelemetry Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -set -euo pipefail - -cd $(dirname $0) -TOOLS_DIR=$(pwd)/.tools - -if [ -z "${GOPATH}" ] ; then - printf "GOPATH is not defined.\n" - exit -1 -fi - -if [ ! -d "${GOPATH}" ] ; then - printf "GOPATH ${GOPATH} is invalid \n" - exit -1 -fi - -# Pre-requisites -if ! git diff --quiet; then \ - git status - printf "\n\nError: working tree is not clean\n" - exit -1 -fi - -if [ "$(git tag --contains $(git log -1 --pretty=format:"%H"))" = "" ] ; then - printf "$(git log -1)" - printf "\n\nError: HEAD is not pointing to a tagged version" -fi - -make ${TOOLS_DIR}/gojq - -DIR_TMP="${GOPATH}/src/oteltmp/" -rm -rf $DIR_TMP -mkdir -p $DIR_TMP - -printf "Copy examples to ${DIR_TMP}\n" -cp -a ./example ${DIR_TMP} - -# Update go.mod files -printf "Update go.mod: rename module and remove replace\n" - -PACKAGE_DIRS=$(find . -mindepth 2 -type f -name 'go.mod' -exec dirname {} \; | egrep 'example' | sed 's/^\.\///' | sort) - -for dir in $PACKAGE_DIRS; do - printf " Update go.mod for $dir\n" - (cd "${DIR_TMP}/${dir}" && \ - # replaces is ("mod1" "mod2" …) - replaces=($(go mod edit -json | ${TOOLS_DIR}/gojq '.Replace[].Old.Path')) && \ - # strip double quotes - replaces=("${replaces[@]%\"}") && \ - replaces=("${replaces[@]#\"}") && \ - # make an array (-dropreplace=mod1 -dropreplace=mod2 …) - dropreplaces=("${replaces[@]/#/-dropreplace=}") && \ - go mod edit -module "oteltmp/${dir}" "${dropreplaces[@]}" && \ - go mod tidy) -done -printf "Update done:\n\n" - -# Build directories that contain main package. These directories are different than -# directories that contain go.mod files. -printf "Build examples:\n" -EXAMPLES=$(./get_main_pkgs.sh ./example) -for ex in $EXAMPLES; do - printf " Build $ex in ${DIR_TMP}/${ex}\n" - (cd "${DIR_TMP}/${ex}" && \ - go build .) -done - -# Cleanup -printf "Remove copied files.\n" -rm -rf $DIR_TMP diff --git a/vendor/go.opentelemetry.io/otel/version.go b/vendor/go.opentelemetry.io/otel/version.go deleted file mode 100644 index 81be6f3681..0000000000 --- a/vendor/go.opentelemetry.io/otel/version.go +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package otel // import "go.opentelemetry.io/otel" - -// Version is the current release version of OpenTelemetry in use. -func Version() string { - return "0.20.0" -} diff --git a/vendor/go.opentelemetry.io/proto/otlp/LICENSE b/vendor/go.opentelemetry.io/proto/otlp/LICENSE deleted file mode 100644 index 261eeb9e9f..0000000000 --- a/vendor/go.opentelemetry.io/proto/otlp/LICENSE +++ /dev/null @@ -1,201 +0,0 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. diff --git a/vendor/go.opentelemetry.io/proto/otlp/collector/metrics/v1/metrics_service.pb.go b/vendor/go.opentelemetry.io/proto/otlp/collector/metrics/v1/metrics_service.pb.go deleted file mode 100644 index d496a141b0..0000000000 --- a/vendor/go.opentelemetry.io/proto/otlp/collector/metrics/v1/metrics_service.pb.go +++ /dev/null @@ -1,255 +0,0 @@ -// Copyright 2019, OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Code generated by protoc-gen-go. DO NOT EDIT. -// versions: -// protoc-gen-go v1.23.0 -// protoc v3.13.0 -// source: opentelemetry/proto/collector/metrics/v1/metrics_service.proto - -package v1 - -import ( - proto "github.com/golang/protobuf/proto" - v1 "go.opentelemetry.io/proto/otlp/metrics/v1" - protoreflect "google.golang.org/protobuf/reflect/protoreflect" - protoimpl "google.golang.org/protobuf/runtime/protoimpl" - reflect "reflect" - sync "sync" -) - -const ( - // Verify that this generated code is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) - // Verify that runtime/protoimpl is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) -) - -// This is a compile-time assertion that a sufficiently up-to-date version -// of the legacy proto package is being used. -const _ = proto.ProtoPackageIsVersion4 - -type ExportMetricsServiceRequest struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - // An array of ResourceMetrics. - // For data coming from a single resource this array will typically contain one - // element. Intermediary nodes (such as OpenTelemetry Collector) that receive - // data from multiple origins typically batch the data before forwarding further and - // in that case this array will contain multiple elements. - ResourceMetrics []*v1.ResourceMetrics `protobuf:"bytes,1,rep,name=resource_metrics,json=resourceMetrics,proto3" json:"resource_metrics,omitempty"` -} - -func (x *ExportMetricsServiceRequest) Reset() { - *x = ExportMetricsServiceRequest{} - if protoimpl.UnsafeEnabled { - mi := &file_opentelemetry_proto_collector_metrics_v1_metrics_service_proto_msgTypes[0] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *ExportMetricsServiceRequest) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*ExportMetricsServiceRequest) ProtoMessage() {} - -func (x *ExportMetricsServiceRequest) ProtoReflect() protoreflect.Message { - mi := &file_opentelemetry_proto_collector_metrics_v1_metrics_service_proto_msgTypes[0] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use ExportMetricsServiceRequest.ProtoReflect.Descriptor instead. -func (*ExportMetricsServiceRequest) Descriptor() ([]byte, []int) { - return file_opentelemetry_proto_collector_metrics_v1_metrics_service_proto_rawDescGZIP(), []int{0} -} - -func (x *ExportMetricsServiceRequest) GetResourceMetrics() []*v1.ResourceMetrics { - if x != nil { - return x.ResourceMetrics - } - return nil -} - -type ExportMetricsServiceResponse struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields -} - -func (x *ExportMetricsServiceResponse) Reset() { - *x = ExportMetricsServiceResponse{} - if protoimpl.UnsafeEnabled { - mi := &file_opentelemetry_proto_collector_metrics_v1_metrics_service_proto_msgTypes[1] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *ExportMetricsServiceResponse) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*ExportMetricsServiceResponse) ProtoMessage() {} - -func (x *ExportMetricsServiceResponse) ProtoReflect() protoreflect.Message { - mi := &file_opentelemetry_proto_collector_metrics_v1_metrics_service_proto_msgTypes[1] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use ExportMetricsServiceResponse.ProtoReflect.Descriptor instead. -func (*ExportMetricsServiceResponse) Descriptor() ([]byte, []int) { - return file_opentelemetry_proto_collector_metrics_v1_metrics_service_proto_rawDescGZIP(), []int{1} -} - -var File_opentelemetry_proto_collector_metrics_v1_metrics_service_proto protoreflect.FileDescriptor - -var file_opentelemetry_proto_collector_metrics_v1_metrics_service_proto_rawDesc = []byte{ - 0x0a, 0x3e, 0x6f, 0x70, 0x65, 0x6e, 0x74, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x74, 0x72, 0x79, 0x2f, - 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x63, 0x6f, 0x6c, 0x6c, 0x65, 0x63, 0x74, 0x6f, 0x72, 0x2f, - 0x6d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x73, 0x2f, 0x76, 0x31, 0x2f, 0x6d, 0x65, 0x74, 0x72, 0x69, - 0x63, 0x73, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x12, 0x28, 0x6f, 0x70, 0x65, 0x6e, 0x74, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x74, 0x72, 0x79, 0x2e, - 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x63, 0x6f, 0x6c, 0x6c, 0x65, 0x63, 0x74, 0x6f, 0x72, 0x2e, - 0x6d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x73, 0x2e, 0x76, 0x31, 0x1a, 0x2c, 0x6f, 0x70, 0x65, 0x6e, - 0x74, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x74, 0x72, 0x79, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, - 0x6d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x73, 0x2f, 0x76, 0x31, 0x2f, 0x6d, 0x65, 0x74, 0x72, 0x69, - 0x63, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x79, 0x0a, 0x1b, 0x45, 0x78, 0x70, 0x6f, - 0x72, 0x74, 0x4d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x73, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, - 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x5a, 0x0a, 0x10, 0x72, 0x65, 0x73, 0x6f, 0x75, - 0x72, 0x63, 0x65, 0x5f, 0x6d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, - 0x0b, 0x32, 0x2f, 0x2e, 0x6f, 0x70, 0x65, 0x6e, 0x74, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x74, 0x72, - 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x6d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x73, 0x2e, - 0x76, 0x31, 0x2e, 0x52, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x4d, 0x65, 0x74, 0x72, 0x69, - 0x63, 0x73, 0x52, 0x0f, 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x4d, 0x65, 0x74, 0x72, - 0x69, 0x63, 0x73, 0x22, 0x1e, 0x0a, 0x1c, 0x45, 0x78, 0x70, 0x6f, 0x72, 0x74, 0x4d, 0x65, 0x74, - 0x72, 0x69, 0x63, 0x73, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, - 0x6e, 0x73, 0x65, 0x32, 0xac, 0x01, 0x0a, 0x0e, 0x4d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x73, 0x53, - 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x99, 0x01, 0x0a, 0x06, 0x45, 0x78, 0x70, 0x6f, 0x72, - 0x74, 0x12, 0x45, 0x2e, 0x6f, 0x70, 0x65, 0x6e, 0x74, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x74, 0x72, - 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x63, 0x6f, 0x6c, 0x6c, 0x65, 0x63, 0x74, 0x6f, - 0x72, 0x2e, 0x6d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x45, 0x78, 0x70, - 0x6f, 0x72, 0x74, 0x4d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x73, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, - 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x46, 0x2e, 0x6f, 0x70, 0x65, 0x6e, 0x74, - 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x74, 0x72, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x63, - 0x6f, 0x6c, 0x6c, 0x65, 0x63, 0x74, 0x6f, 0x72, 0x2e, 0x6d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x73, - 0x2e, 0x76, 0x31, 0x2e, 0x45, 0x78, 0x70, 0x6f, 0x72, 0x74, 0x4d, 0x65, 0x74, 0x72, 0x69, 0x63, - 0x73, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, - 0x22, 0x00, 0x42, 0x79, 0x0a, 0x2b, 0x69, 0x6f, 0x2e, 0x6f, 0x70, 0x65, 0x6e, 0x74, 0x65, 0x6c, - 0x65, 0x6d, 0x65, 0x74, 0x72, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x63, 0x6f, 0x6c, - 0x6c, 0x65, 0x63, 0x74, 0x6f, 0x72, 0x2e, 0x6d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x73, 0x2e, 0x76, - 0x31, 0x42, 0x13, 0x4d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x73, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, - 0x65, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x33, 0x67, 0x6f, 0x2e, 0x6f, 0x70, 0x65, - 0x6e, 0x74, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x74, 0x72, 0x79, 0x2e, 0x69, 0x6f, 0x2f, 0x70, 0x72, - 0x6f, 0x74, 0x6f, 0x2f, 0x6f, 0x74, 0x6c, 0x70, 0x2f, 0x63, 0x6f, 0x6c, 0x6c, 0x65, 0x63, 0x74, - 0x6f, 0x72, 0x2f, 0x6d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x73, 0x2f, 0x76, 0x31, 0x62, 0x06, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x33, -} - -var ( - file_opentelemetry_proto_collector_metrics_v1_metrics_service_proto_rawDescOnce sync.Once - file_opentelemetry_proto_collector_metrics_v1_metrics_service_proto_rawDescData = file_opentelemetry_proto_collector_metrics_v1_metrics_service_proto_rawDesc -) - -func file_opentelemetry_proto_collector_metrics_v1_metrics_service_proto_rawDescGZIP() []byte { - file_opentelemetry_proto_collector_metrics_v1_metrics_service_proto_rawDescOnce.Do(func() { - file_opentelemetry_proto_collector_metrics_v1_metrics_service_proto_rawDescData = protoimpl.X.CompressGZIP(file_opentelemetry_proto_collector_metrics_v1_metrics_service_proto_rawDescData) - }) - return file_opentelemetry_proto_collector_metrics_v1_metrics_service_proto_rawDescData -} - -var file_opentelemetry_proto_collector_metrics_v1_metrics_service_proto_msgTypes = make([]protoimpl.MessageInfo, 2) -var file_opentelemetry_proto_collector_metrics_v1_metrics_service_proto_goTypes = []interface{}{ - (*ExportMetricsServiceRequest)(nil), // 0: opentelemetry.proto.collector.metrics.v1.ExportMetricsServiceRequest - (*ExportMetricsServiceResponse)(nil), // 1: opentelemetry.proto.collector.metrics.v1.ExportMetricsServiceResponse - (*v1.ResourceMetrics)(nil), // 2: opentelemetry.proto.metrics.v1.ResourceMetrics -} -var file_opentelemetry_proto_collector_metrics_v1_metrics_service_proto_depIdxs = []int32{ - 2, // 0: opentelemetry.proto.collector.metrics.v1.ExportMetricsServiceRequest.resource_metrics:type_name -> opentelemetry.proto.metrics.v1.ResourceMetrics - 0, // 1: opentelemetry.proto.collector.metrics.v1.MetricsService.Export:input_type -> opentelemetry.proto.collector.metrics.v1.ExportMetricsServiceRequest - 1, // 2: opentelemetry.proto.collector.metrics.v1.MetricsService.Export:output_type -> opentelemetry.proto.collector.metrics.v1.ExportMetricsServiceResponse - 2, // [2:3] is the sub-list for method output_type - 1, // [1:2] is the sub-list for method input_type - 1, // [1:1] is the sub-list for extension type_name - 1, // [1:1] is the sub-list for extension extendee - 0, // [0:1] is the sub-list for field type_name -} - -func init() { file_opentelemetry_proto_collector_metrics_v1_metrics_service_proto_init() } -func file_opentelemetry_proto_collector_metrics_v1_metrics_service_proto_init() { - if File_opentelemetry_proto_collector_metrics_v1_metrics_service_proto != nil { - return - } - if !protoimpl.UnsafeEnabled { - file_opentelemetry_proto_collector_metrics_v1_metrics_service_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*ExportMetricsServiceRequest); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_opentelemetry_proto_collector_metrics_v1_metrics_service_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*ExportMetricsServiceResponse); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - } - type x struct{} - out := protoimpl.TypeBuilder{ - File: protoimpl.DescBuilder{ - GoPackagePath: reflect.TypeOf(x{}).PkgPath(), - RawDescriptor: file_opentelemetry_proto_collector_metrics_v1_metrics_service_proto_rawDesc, - NumEnums: 0, - NumMessages: 2, - NumExtensions: 0, - NumServices: 1, - }, - GoTypes: file_opentelemetry_proto_collector_metrics_v1_metrics_service_proto_goTypes, - DependencyIndexes: file_opentelemetry_proto_collector_metrics_v1_metrics_service_proto_depIdxs, - MessageInfos: file_opentelemetry_proto_collector_metrics_v1_metrics_service_proto_msgTypes, - }.Build() - File_opentelemetry_proto_collector_metrics_v1_metrics_service_proto = out.File - file_opentelemetry_proto_collector_metrics_v1_metrics_service_proto_rawDesc = nil - file_opentelemetry_proto_collector_metrics_v1_metrics_service_proto_goTypes = nil - file_opentelemetry_proto_collector_metrics_v1_metrics_service_proto_depIdxs = nil -} diff --git a/vendor/go.opentelemetry.io/proto/otlp/collector/metrics/v1/metrics_service.pb.gw.go b/vendor/go.opentelemetry.io/proto/otlp/collector/metrics/v1/metrics_service.pb.gw.go deleted file mode 100644 index f0dc06e5f5..0000000000 --- a/vendor/go.opentelemetry.io/proto/otlp/collector/metrics/v1/metrics_service.pb.gw.go +++ /dev/null @@ -1,169 +0,0 @@ -// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. -// source: opentelemetry/proto/collector/metrics/v1/metrics_service.proto - -/* -Package v1 is a reverse proxy. - -It translates gRPC into RESTful JSON APIs. -*/ -package v1 - -import ( - "context" - "io" - "net/http" - - "github.com/golang/protobuf/descriptor" - "github.com/golang/protobuf/proto" - "github.com/grpc-ecosystem/grpc-gateway/runtime" - "github.com/grpc-ecosystem/grpc-gateway/utilities" - "google.golang.org/grpc" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/grpclog" - "google.golang.org/grpc/metadata" - "google.golang.org/grpc/status" -) - -// Suppress "imported and not used" errors -var _ codes.Code -var _ io.Reader -var _ status.Status -var _ = runtime.String -var _ = utilities.NewDoubleArray -var _ = descriptor.ForMessage -var _ = metadata.Join - -func request_MetricsService_Export_0(ctx context.Context, marshaler runtime.Marshaler, client MetricsServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq ExportMetricsServiceRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.Export(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func local_request_MetricsService_Export_0(ctx context.Context, marshaler runtime.Marshaler, server MetricsServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq ExportMetricsServiceRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := server.Export(ctx, &protoReq) - return msg, metadata, err - -} - -// RegisterMetricsServiceHandlerServer registers the http handlers for service MetricsService to "mux". -// UnaryRPC :call MetricsServiceServer directly. -// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. -// Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterMetricsServiceHandlerFromEndpoint instead. -func RegisterMetricsServiceHandlerServer(ctx context.Context, mux *runtime.ServeMux, server MetricsServiceServer) error { - - mux.Handle("POST", pattern_MetricsService_Export_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - var stream runtime.ServerTransportStream - ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := local_request_MetricsService_Export_0(rctx, inboundMarshaler, server, req, pathParams) - md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_MetricsService_Export_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - return nil -} - -// RegisterMetricsServiceHandlerFromEndpoint is same as RegisterMetricsServiceHandler but -// automatically dials to "endpoint" and closes the connection when "ctx" gets done. -func RegisterMetricsServiceHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { - conn, err := grpc.Dial(endpoint, opts...) - if err != nil { - return err - } - defer func() { - if err != nil { - if cerr := conn.Close(); cerr != nil { - grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) - } - return - } - go func() { - <-ctx.Done() - if cerr := conn.Close(); cerr != nil { - grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) - } - }() - }() - - return RegisterMetricsServiceHandler(ctx, mux, conn) -} - -// RegisterMetricsServiceHandler registers the http handlers for service MetricsService to "mux". -// The handlers forward requests to the grpc endpoint over "conn". -func RegisterMetricsServiceHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { - return RegisterMetricsServiceHandlerClient(ctx, mux, NewMetricsServiceClient(conn)) -} - -// RegisterMetricsServiceHandlerClient registers the http handlers for service MetricsService -// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "MetricsServiceClient". -// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "MetricsServiceClient" -// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in -// "MetricsServiceClient" to call the correct interceptors. -func RegisterMetricsServiceHandlerClient(ctx context.Context, mux *runtime.ServeMux, client MetricsServiceClient) error { - - mux.Handle("POST", pattern_MetricsService_Export_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_MetricsService_Export_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_MetricsService_Export_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - return nil -} - -var ( - pattern_MetricsService_Export_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "metrics"}, "", runtime.AssumeColonVerbOpt(true))) -) - -var ( - forward_MetricsService_Export_0 = runtime.ForwardResponseMessage -) diff --git a/vendor/go.opentelemetry.io/proto/otlp/collector/metrics/v1/metrics_service_grpc.pb.go b/vendor/go.opentelemetry.io/proto/otlp/collector/metrics/v1/metrics_service_grpc.pb.go deleted file mode 100644 index eca49e5c4f..0000000000 --- a/vendor/go.opentelemetry.io/proto/otlp/collector/metrics/v1/metrics_service_grpc.pb.go +++ /dev/null @@ -1,101 +0,0 @@ -// Code generated by protoc-gen-go-grpc. DO NOT EDIT. - -package v1 - -import ( - context "context" - grpc "google.golang.org/grpc" - codes "google.golang.org/grpc/codes" - status "google.golang.org/grpc/status" -) - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the grpc package it is being compiled against. -const _ = grpc.SupportPackageIsVersion7 - -// MetricsServiceClient is the client API for MetricsService service. -// -// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. -type MetricsServiceClient interface { - // For performance reasons, it is recommended to keep this RPC - // alive for the entire life of the application. - Export(ctx context.Context, in *ExportMetricsServiceRequest, opts ...grpc.CallOption) (*ExportMetricsServiceResponse, error) -} - -type metricsServiceClient struct { - cc grpc.ClientConnInterface -} - -func NewMetricsServiceClient(cc grpc.ClientConnInterface) MetricsServiceClient { - return &metricsServiceClient{cc} -} - -func (c *metricsServiceClient) Export(ctx context.Context, in *ExportMetricsServiceRequest, opts ...grpc.CallOption) (*ExportMetricsServiceResponse, error) { - out := new(ExportMetricsServiceResponse) - err := c.cc.Invoke(ctx, "/opentelemetry.proto.collector.metrics.v1.MetricsService/Export", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -// MetricsServiceServer is the server API for MetricsService service. -// All implementations must embed UnimplementedMetricsServiceServer -// for forward compatibility -type MetricsServiceServer interface { - // For performance reasons, it is recommended to keep this RPC - // alive for the entire life of the application. - Export(context.Context, *ExportMetricsServiceRequest) (*ExportMetricsServiceResponse, error) - mustEmbedUnimplementedMetricsServiceServer() -} - -// UnimplementedMetricsServiceServer must be embedded to have forward compatible implementations. -type UnimplementedMetricsServiceServer struct { -} - -func (UnimplementedMetricsServiceServer) Export(context.Context, *ExportMetricsServiceRequest) (*ExportMetricsServiceResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method Export not implemented") -} -func (UnimplementedMetricsServiceServer) mustEmbedUnimplementedMetricsServiceServer() {} - -// UnsafeMetricsServiceServer may be embedded to opt out of forward compatibility for this service. -// Use of this interface is not recommended, as added methods to MetricsServiceServer will -// result in compilation errors. -type UnsafeMetricsServiceServer interface { - mustEmbedUnimplementedMetricsServiceServer() -} - -func RegisterMetricsServiceServer(s grpc.ServiceRegistrar, srv MetricsServiceServer) { - s.RegisterService(&_MetricsService_serviceDesc, srv) -} - -func _MetricsService_Export_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(ExportMetricsServiceRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(MetricsServiceServer).Export(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/opentelemetry.proto.collector.metrics.v1.MetricsService/Export", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(MetricsServiceServer).Export(ctx, req.(*ExportMetricsServiceRequest)) - } - return interceptor(ctx, in, info, handler) -} - -var _MetricsService_serviceDesc = grpc.ServiceDesc{ - ServiceName: "opentelemetry.proto.collector.metrics.v1.MetricsService", - HandlerType: (*MetricsServiceServer)(nil), - Methods: []grpc.MethodDesc{ - { - MethodName: "Export", - Handler: _MetricsService_Export_Handler, - }, - }, - Streams: []grpc.StreamDesc{}, - Metadata: "opentelemetry/proto/collector/metrics/v1/metrics_service.proto", -} diff --git a/vendor/go.opentelemetry.io/proto/otlp/collector/trace/v1/trace_config.pb.go b/vendor/go.opentelemetry.io/proto/otlp/collector/trace/v1/trace_config.pb.go deleted file mode 100644 index 07f7e9b1fa..0000000000 --- a/vendor/go.opentelemetry.io/proto/otlp/collector/trace/v1/trace_config.pb.go +++ /dev/null @@ -1,573 +0,0 @@ -// Copyright 2019, OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Code generated by protoc-gen-go. DO NOT EDIT. -// versions: -// protoc-gen-go v1.23.0 -// protoc v3.13.0 -// source: opentelemetry/proto/trace/v1/trace_config.proto - -package v1 - -import ( - proto "github.com/golang/protobuf/proto" - protoreflect "google.golang.org/protobuf/reflect/protoreflect" - protoimpl "google.golang.org/protobuf/runtime/protoimpl" - reflect "reflect" - sync "sync" -) - -const ( - // Verify that this generated code is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) - // Verify that runtime/protoimpl is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) -) - -// This is a compile-time assertion that a sufficiently up-to-date version -// of the legacy proto package is being used. -const _ = proto.ProtoPackageIsVersion4 - -// How spans should be sampled: -// - Always off -// - Always on -// - Always follow the parent Span's decision (off if no parent). -type ConstantSampler_ConstantDecision int32 - -const ( - ConstantSampler_ALWAYS_OFF ConstantSampler_ConstantDecision = 0 - ConstantSampler_ALWAYS_ON ConstantSampler_ConstantDecision = 1 - ConstantSampler_ALWAYS_PARENT ConstantSampler_ConstantDecision = 2 -) - -// Enum value maps for ConstantSampler_ConstantDecision. -var ( - ConstantSampler_ConstantDecision_name = map[int32]string{ - 0: "ALWAYS_OFF", - 1: "ALWAYS_ON", - 2: "ALWAYS_PARENT", - } - ConstantSampler_ConstantDecision_value = map[string]int32{ - "ALWAYS_OFF": 0, - "ALWAYS_ON": 1, - "ALWAYS_PARENT": 2, - } -) - -func (x ConstantSampler_ConstantDecision) Enum() *ConstantSampler_ConstantDecision { - p := new(ConstantSampler_ConstantDecision) - *p = x - return p -} - -func (x ConstantSampler_ConstantDecision) String() string { - return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x)) -} - -func (ConstantSampler_ConstantDecision) Descriptor() protoreflect.EnumDescriptor { - return file_opentelemetry_proto_trace_v1_trace_config_proto_enumTypes[0].Descriptor() -} - -func (ConstantSampler_ConstantDecision) Type() protoreflect.EnumType { - return &file_opentelemetry_proto_trace_v1_trace_config_proto_enumTypes[0] -} - -func (x ConstantSampler_ConstantDecision) Number() protoreflect.EnumNumber { - return protoreflect.EnumNumber(x) -} - -// Deprecated: Use ConstantSampler_ConstantDecision.Descriptor instead. -func (ConstantSampler_ConstantDecision) EnumDescriptor() ([]byte, []int) { - return file_opentelemetry_proto_trace_v1_trace_config_proto_rawDescGZIP(), []int{1, 0} -} - -// Global configuration of the trace service. All fields must be specified, or -// the default (zero) values will be used for each type. -type TraceConfig struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - // The global default sampler used to make decisions on span sampling. - // - // Types that are assignable to Sampler: - // *TraceConfig_ConstantSampler - // *TraceConfig_TraceIdRatioBased - // *TraceConfig_RateLimitingSampler - Sampler isTraceConfig_Sampler `protobuf_oneof:"sampler"` - // The global default max number of attributes per span. - MaxNumberOfAttributes int64 `protobuf:"varint,4,opt,name=max_number_of_attributes,json=maxNumberOfAttributes,proto3" json:"max_number_of_attributes,omitempty"` - // The global default max number of annotation events per span. - MaxNumberOfTimedEvents int64 `protobuf:"varint,5,opt,name=max_number_of_timed_events,json=maxNumberOfTimedEvents,proto3" json:"max_number_of_timed_events,omitempty"` - // The global default max number of attributes per timed event. - MaxNumberOfAttributesPerTimedEvent int64 `protobuf:"varint,6,opt,name=max_number_of_attributes_per_timed_event,json=maxNumberOfAttributesPerTimedEvent,proto3" json:"max_number_of_attributes_per_timed_event,omitempty"` - // The global default max number of link entries per span. - MaxNumberOfLinks int64 `protobuf:"varint,7,opt,name=max_number_of_links,json=maxNumberOfLinks,proto3" json:"max_number_of_links,omitempty"` - // The global default max number of attributes per span. - MaxNumberOfAttributesPerLink int64 `protobuf:"varint,8,opt,name=max_number_of_attributes_per_link,json=maxNumberOfAttributesPerLink,proto3" json:"max_number_of_attributes_per_link,omitempty"` -} - -func (x *TraceConfig) Reset() { - *x = TraceConfig{} - if protoimpl.UnsafeEnabled { - mi := &file_opentelemetry_proto_trace_v1_trace_config_proto_msgTypes[0] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *TraceConfig) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*TraceConfig) ProtoMessage() {} - -func (x *TraceConfig) ProtoReflect() protoreflect.Message { - mi := &file_opentelemetry_proto_trace_v1_trace_config_proto_msgTypes[0] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use TraceConfig.ProtoReflect.Descriptor instead. -func (*TraceConfig) Descriptor() ([]byte, []int) { - return file_opentelemetry_proto_trace_v1_trace_config_proto_rawDescGZIP(), []int{0} -} - -func (m *TraceConfig) GetSampler() isTraceConfig_Sampler { - if m != nil { - return m.Sampler - } - return nil -} - -func (x *TraceConfig) GetConstantSampler() *ConstantSampler { - if x, ok := x.GetSampler().(*TraceConfig_ConstantSampler); ok { - return x.ConstantSampler - } - return nil -} - -func (x *TraceConfig) GetTraceIdRatioBased() *TraceIdRatioBased { - if x, ok := x.GetSampler().(*TraceConfig_TraceIdRatioBased); ok { - return x.TraceIdRatioBased - } - return nil -} - -func (x *TraceConfig) GetRateLimitingSampler() *RateLimitingSampler { - if x, ok := x.GetSampler().(*TraceConfig_RateLimitingSampler); ok { - return x.RateLimitingSampler - } - return nil -} - -func (x *TraceConfig) GetMaxNumberOfAttributes() int64 { - if x != nil { - return x.MaxNumberOfAttributes - } - return 0 -} - -func (x *TraceConfig) GetMaxNumberOfTimedEvents() int64 { - if x != nil { - return x.MaxNumberOfTimedEvents - } - return 0 -} - -func (x *TraceConfig) GetMaxNumberOfAttributesPerTimedEvent() int64 { - if x != nil { - return x.MaxNumberOfAttributesPerTimedEvent - } - return 0 -} - -func (x *TraceConfig) GetMaxNumberOfLinks() int64 { - if x != nil { - return x.MaxNumberOfLinks - } - return 0 -} - -func (x *TraceConfig) GetMaxNumberOfAttributesPerLink() int64 { - if x != nil { - return x.MaxNumberOfAttributesPerLink - } - return 0 -} - -type isTraceConfig_Sampler interface { - isTraceConfig_Sampler() -} - -type TraceConfig_ConstantSampler struct { - ConstantSampler *ConstantSampler `protobuf:"bytes,1,opt,name=constant_sampler,json=constantSampler,proto3,oneof"` -} - -type TraceConfig_TraceIdRatioBased struct { - TraceIdRatioBased *TraceIdRatioBased `protobuf:"bytes,2,opt,name=trace_id_ratio_based,json=traceIdRatioBased,proto3,oneof"` -} - -type TraceConfig_RateLimitingSampler struct { - RateLimitingSampler *RateLimitingSampler `protobuf:"bytes,3,opt,name=rate_limiting_sampler,json=rateLimitingSampler,proto3,oneof"` -} - -func (*TraceConfig_ConstantSampler) isTraceConfig_Sampler() {} - -func (*TraceConfig_TraceIdRatioBased) isTraceConfig_Sampler() {} - -func (*TraceConfig_RateLimitingSampler) isTraceConfig_Sampler() {} - -// Sampler that always makes a constant decision on span sampling. -type ConstantSampler struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Decision ConstantSampler_ConstantDecision `protobuf:"varint,1,opt,name=decision,proto3,enum=opentelemetry.proto.trace.v1.ConstantSampler_ConstantDecision" json:"decision,omitempty"` -} - -func (x *ConstantSampler) Reset() { - *x = ConstantSampler{} - if protoimpl.UnsafeEnabled { - mi := &file_opentelemetry_proto_trace_v1_trace_config_proto_msgTypes[1] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *ConstantSampler) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*ConstantSampler) ProtoMessage() {} - -func (x *ConstantSampler) ProtoReflect() protoreflect.Message { - mi := &file_opentelemetry_proto_trace_v1_trace_config_proto_msgTypes[1] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use ConstantSampler.ProtoReflect.Descriptor instead. -func (*ConstantSampler) Descriptor() ([]byte, []int) { - return file_opentelemetry_proto_trace_v1_trace_config_proto_rawDescGZIP(), []int{1} -} - -func (x *ConstantSampler) GetDecision() ConstantSampler_ConstantDecision { - if x != nil { - return x.Decision - } - return ConstantSampler_ALWAYS_OFF -} - -// Sampler that tries to uniformly sample traces with a given ratio. -// The ratio of sampling a trace is equal to that of the specified ratio. -type TraceIdRatioBased struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - // The desired ratio of sampling. Must be within [0.0, 1.0]. - SamplingRatio float64 `protobuf:"fixed64,1,opt,name=samplingRatio,proto3" json:"samplingRatio,omitempty"` -} - -func (x *TraceIdRatioBased) Reset() { - *x = TraceIdRatioBased{} - if protoimpl.UnsafeEnabled { - mi := &file_opentelemetry_proto_trace_v1_trace_config_proto_msgTypes[2] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *TraceIdRatioBased) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*TraceIdRatioBased) ProtoMessage() {} - -func (x *TraceIdRatioBased) ProtoReflect() protoreflect.Message { - mi := &file_opentelemetry_proto_trace_v1_trace_config_proto_msgTypes[2] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use TraceIdRatioBased.ProtoReflect.Descriptor instead. -func (*TraceIdRatioBased) Descriptor() ([]byte, []int) { - return file_opentelemetry_proto_trace_v1_trace_config_proto_rawDescGZIP(), []int{2} -} - -func (x *TraceIdRatioBased) GetSamplingRatio() float64 { - if x != nil { - return x.SamplingRatio - } - return 0 -} - -// Sampler that tries to sample with a rate per time window. -type RateLimitingSampler struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - // Rate per second. - Qps int64 `protobuf:"varint,1,opt,name=qps,proto3" json:"qps,omitempty"` -} - -func (x *RateLimitingSampler) Reset() { - *x = RateLimitingSampler{} - if protoimpl.UnsafeEnabled { - mi := &file_opentelemetry_proto_trace_v1_trace_config_proto_msgTypes[3] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *RateLimitingSampler) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*RateLimitingSampler) ProtoMessage() {} - -func (x *RateLimitingSampler) ProtoReflect() protoreflect.Message { - mi := &file_opentelemetry_proto_trace_v1_trace_config_proto_msgTypes[3] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use RateLimitingSampler.ProtoReflect.Descriptor instead. -func (*RateLimitingSampler) Descriptor() ([]byte, []int) { - return file_opentelemetry_proto_trace_v1_trace_config_proto_rawDescGZIP(), []int{3} -} - -func (x *RateLimitingSampler) GetQps() int64 { - if x != nil { - return x.Qps - } - return 0 -} - -var File_opentelemetry_proto_trace_v1_trace_config_proto protoreflect.FileDescriptor - -var file_opentelemetry_proto_trace_v1_trace_config_proto_rawDesc = []byte{ - 0x0a, 0x2f, 0x6f, 0x70, 0x65, 0x6e, 0x74, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x74, 0x72, 0x79, 0x2f, - 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x74, 0x72, 0x61, 0x63, 0x65, 0x2f, 0x76, 0x31, 0x2f, 0x74, - 0x72, 0x61, 0x63, 0x65, 0x5f, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x70, 0x72, 0x6f, 0x74, - 0x6f, 0x12, 0x1c, 0x6f, 0x70, 0x65, 0x6e, 0x74, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x74, 0x72, 0x79, - 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x74, 0x72, 0x61, 0x63, 0x65, 0x2e, 0x76, 0x31, 0x22, - 0x84, 0x05, 0x0a, 0x0b, 0x54, 0x72, 0x61, 0x63, 0x65, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x12, - 0x5a, 0x0a, 0x10, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x74, 0x5f, 0x73, 0x61, 0x6d, 0x70, - 0x6c, 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x2d, 0x2e, 0x6f, 0x70, 0x65, 0x6e, - 0x74, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x74, 0x72, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, - 0x74, 0x72, 0x61, 0x63, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x6f, 0x6e, 0x73, 0x74, 0x61, 0x6e, - 0x74, 0x53, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x72, 0x48, 0x00, 0x52, 0x0f, 0x63, 0x6f, 0x6e, 0x73, - 0x74, 0x61, 0x6e, 0x74, 0x53, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x72, 0x12, 0x62, 0x0a, 0x14, 0x74, - 0x72, 0x61, 0x63, 0x65, 0x5f, 0x69, 0x64, 0x5f, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x5f, 0x62, 0x61, - 0x73, 0x65, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x2f, 0x2e, 0x6f, 0x70, 0x65, 0x6e, - 0x74, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x74, 0x72, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, - 0x74, 0x72, 0x61, 0x63, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x54, 0x72, 0x61, 0x63, 0x65, 0x49, 0x64, - 0x52, 0x61, 0x74, 0x69, 0x6f, 0x42, 0x61, 0x73, 0x65, 0x64, 0x48, 0x00, 0x52, 0x11, 0x74, 0x72, - 0x61, 0x63, 0x65, 0x49, 0x64, 0x52, 0x61, 0x74, 0x69, 0x6f, 0x42, 0x61, 0x73, 0x65, 0x64, 0x12, - 0x67, 0x0a, 0x15, 0x72, 0x61, 0x74, 0x65, 0x5f, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x69, 0x6e, 0x67, - 0x5f, 0x73, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x72, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x31, - 0x2e, 0x6f, 0x70, 0x65, 0x6e, 0x74, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x74, 0x72, 0x79, 0x2e, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x74, 0x72, 0x61, 0x63, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x52, 0x61, - 0x74, 0x65, 0x4c, 0x69, 0x6d, 0x69, 0x74, 0x69, 0x6e, 0x67, 0x53, 0x61, 0x6d, 0x70, 0x6c, 0x65, - 0x72, 0x48, 0x00, 0x52, 0x13, 0x72, 0x61, 0x74, 0x65, 0x4c, 0x69, 0x6d, 0x69, 0x74, 0x69, 0x6e, - 0x67, 0x53, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x72, 0x12, 0x37, 0x0a, 0x18, 0x6d, 0x61, 0x78, 0x5f, - 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x5f, 0x6f, 0x66, 0x5f, 0x61, 0x74, 0x74, 0x72, 0x69, 0x62, - 0x75, 0x74, 0x65, 0x73, 0x18, 0x04, 0x20, 0x01, 0x28, 0x03, 0x52, 0x15, 0x6d, 0x61, 0x78, 0x4e, - 0x75, 0x6d, 0x62, 0x65, 0x72, 0x4f, 0x66, 0x41, 0x74, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, - 0x73, 0x12, 0x3a, 0x0a, 0x1a, 0x6d, 0x61, 0x78, 0x5f, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x5f, - 0x6f, 0x66, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x64, 0x5f, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x73, 0x18, - 0x05, 0x20, 0x01, 0x28, 0x03, 0x52, 0x16, 0x6d, 0x61, 0x78, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, - 0x4f, 0x66, 0x54, 0x69, 0x6d, 0x65, 0x64, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x73, 0x12, 0x54, 0x0a, - 0x28, 0x6d, 0x61, 0x78, 0x5f, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x5f, 0x6f, 0x66, 0x5f, 0x61, - 0x74, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x73, 0x5f, 0x70, 0x65, 0x72, 0x5f, 0x74, 0x69, - 0x6d, 0x65, 0x64, 0x5f, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x18, 0x06, 0x20, 0x01, 0x28, 0x03, 0x52, - 0x22, 0x6d, 0x61, 0x78, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x4f, 0x66, 0x41, 0x74, 0x74, 0x72, - 0x69, 0x62, 0x75, 0x74, 0x65, 0x73, 0x50, 0x65, 0x72, 0x54, 0x69, 0x6d, 0x65, 0x64, 0x45, 0x76, - 0x65, 0x6e, 0x74, 0x12, 0x2d, 0x0a, 0x13, 0x6d, 0x61, 0x78, 0x5f, 0x6e, 0x75, 0x6d, 0x62, 0x65, - 0x72, 0x5f, 0x6f, 0x66, 0x5f, 0x6c, 0x69, 0x6e, 0x6b, 0x73, 0x18, 0x07, 0x20, 0x01, 0x28, 0x03, - 0x52, 0x10, 0x6d, 0x61, 0x78, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x4f, 0x66, 0x4c, 0x69, 0x6e, - 0x6b, 0x73, 0x12, 0x47, 0x0a, 0x21, 0x6d, 0x61, 0x78, 0x5f, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, - 0x5f, 0x6f, 0x66, 0x5f, 0x61, 0x74, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x73, 0x5f, 0x70, - 0x65, 0x72, 0x5f, 0x6c, 0x69, 0x6e, 0x6b, 0x18, 0x08, 0x20, 0x01, 0x28, 0x03, 0x52, 0x1c, 0x6d, - 0x61, 0x78, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x4f, 0x66, 0x41, 0x74, 0x74, 0x72, 0x69, 0x62, - 0x75, 0x74, 0x65, 0x73, 0x50, 0x65, 0x72, 0x4c, 0x69, 0x6e, 0x6b, 0x42, 0x09, 0x0a, 0x07, 0x73, - 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x72, 0x22, 0xb3, 0x01, 0x0a, 0x0f, 0x43, 0x6f, 0x6e, 0x73, 0x74, - 0x61, 0x6e, 0x74, 0x53, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x72, 0x12, 0x5a, 0x0a, 0x08, 0x64, 0x65, - 0x63, 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x3e, 0x2e, 0x6f, - 0x70, 0x65, 0x6e, 0x74, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x74, 0x72, 0x79, 0x2e, 0x70, 0x72, 0x6f, - 0x74, 0x6f, 0x2e, 0x74, 0x72, 0x61, 0x63, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x6f, 0x6e, 0x73, - 0x74, 0x61, 0x6e, 0x74, 0x53, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x72, 0x2e, 0x43, 0x6f, 0x6e, 0x73, - 0x74, 0x61, 0x6e, 0x74, 0x44, 0x65, 0x63, 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x52, 0x08, 0x64, 0x65, - 0x63, 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x22, 0x44, 0x0a, 0x10, 0x43, 0x6f, 0x6e, 0x73, 0x74, 0x61, - 0x6e, 0x74, 0x44, 0x65, 0x63, 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x0e, 0x0a, 0x0a, 0x41, 0x4c, - 0x57, 0x41, 0x59, 0x53, 0x5f, 0x4f, 0x46, 0x46, 0x10, 0x00, 0x12, 0x0d, 0x0a, 0x09, 0x41, 0x4c, - 0x57, 0x41, 0x59, 0x53, 0x5f, 0x4f, 0x4e, 0x10, 0x01, 0x12, 0x11, 0x0a, 0x0d, 0x41, 0x4c, 0x57, - 0x41, 0x59, 0x53, 0x5f, 0x50, 0x41, 0x52, 0x45, 0x4e, 0x54, 0x10, 0x02, 0x22, 0x39, 0x0a, 0x11, - 0x54, 0x72, 0x61, 0x63, 0x65, 0x49, 0x64, 0x52, 0x61, 0x74, 0x69, 0x6f, 0x42, 0x61, 0x73, 0x65, - 0x64, 0x12, 0x24, 0x0a, 0x0d, 0x73, 0x61, 0x6d, 0x70, 0x6c, 0x69, 0x6e, 0x67, 0x52, 0x61, 0x74, - 0x69, 0x6f, 0x18, 0x01, 0x20, 0x01, 0x28, 0x01, 0x52, 0x0d, 0x73, 0x61, 0x6d, 0x70, 0x6c, 0x69, - 0x6e, 0x67, 0x52, 0x61, 0x74, 0x69, 0x6f, 0x22, 0x27, 0x0a, 0x13, 0x52, 0x61, 0x74, 0x65, 0x4c, - 0x69, 0x6d, 0x69, 0x74, 0x69, 0x6e, 0x67, 0x53, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x72, 0x12, 0x10, - 0x0a, 0x03, 0x71, 0x70, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x03, 0x71, 0x70, 0x73, - 0x42, 0x68, 0x0a, 0x1f, 0x69, 0x6f, 0x2e, 0x6f, 0x70, 0x65, 0x6e, 0x74, 0x65, 0x6c, 0x65, 0x6d, - 0x65, 0x74, 0x72, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x74, 0x72, 0x61, 0x63, 0x65, - 0x2e, 0x76, 0x31, 0x42, 0x10, 0x54, 0x72, 0x61, 0x63, 0x65, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, - 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x31, 0x67, 0x6f, 0x2e, 0x6f, 0x70, 0x65, 0x6e, - 0x74, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x74, 0x72, 0x79, 0x2e, 0x69, 0x6f, 0x2f, 0x70, 0x72, 0x6f, - 0x74, 0x6f, 0x2f, 0x6f, 0x74, 0x6c, 0x70, 0x2f, 0x63, 0x6f, 0x6c, 0x6c, 0x65, 0x63, 0x74, 0x6f, - 0x72, 0x2f, 0x74, 0x72, 0x61, 0x63, 0x65, 0x2f, 0x76, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, - 0x6f, 0x33, -} - -var ( - file_opentelemetry_proto_trace_v1_trace_config_proto_rawDescOnce sync.Once - file_opentelemetry_proto_trace_v1_trace_config_proto_rawDescData = file_opentelemetry_proto_trace_v1_trace_config_proto_rawDesc -) - -func file_opentelemetry_proto_trace_v1_trace_config_proto_rawDescGZIP() []byte { - file_opentelemetry_proto_trace_v1_trace_config_proto_rawDescOnce.Do(func() { - file_opentelemetry_proto_trace_v1_trace_config_proto_rawDescData = protoimpl.X.CompressGZIP(file_opentelemetry_proto_trace_v1_trace_config_proto_rawDescData) - }) - return file_opentelemetry_proto_trace_v1_trace_config_proto_rawDescData -} - -var file_opentelemetry_proto_trace_v1_trace_config_proto_enumTypes = make([]protoimpl.EnumInfo, 1) -var file_opentelemetry_proto_trace_v1_trace_config_proto_msgTypes = make([]protoimpl.MessageInfo, 4) -var file_opentelemetry_proto_trace_v1_trace_config_proto_goTypes = []interface{}{ - (ConstantSampler_ConstantDecision)(0), // 0: opentelemetry.proto.trace.v1.ConstantSampler.ConstantDecision - (*TraceConfig)(nil), // 1: opentelemetry.proto.trace.v1.TraceConfig - (*ConstantSampler)(nil), // 2: opentelemetry.proto.trace.v1.ConstantSampler - (*TraceIdRatioBased)(nil), // 3: opentelemetry.proto.trace.v1.TraceIdRatioBased - (*RateLimitingSampler)(nil), // 4: opentelemetry.proto.trace.v1.RateLimitingSampler -} -var file_opentelemetry_proto_trace_v1_trace_config_proto_depIdxs = []int32{ - 2, // 0: opentelemetry.proto.trace.v1.TraceConfig.constant_sampler:type_name -> opentelemetry.proto.trace.v1.ConstantSampler - 3, // 1: opentelemetry.proto.trace.v1.TraceConfig.trace_id_ratio_based:type_name -> opentelemetry.proto.trace.v1.TraceIdRatioBased - 4, // 2: opentelemetry.proto.trace.v1.TraceConfig.rate_limiting_sampler:type_name -> opentelemetry.proto.trace.v1.RateLimitingSampler - 0, // 3: opentelemetry.proto.trace.v1.ConstantSampler.decision:type_name -> opentelemetry.proto.trace.v1.ConstantSampler.ConstantDecision - 4, // [4:4] is the sub-list for method output_type - 4, // [4:4] is the sub-list for method input_type - 4, // [4:4] is the sub-list for extension type_name - 4, // [4:4] is the sub-list for extension extendee - 0, // [0:4] is the sub-list for field type_name -} - -func init() { file_opentelemetry_proto_trace_v1_trace_config_proto_init() } -func file_opentelemetry_proto_trace_v1_trace_config_proto_init() { - if File_opentelemetry_proto_trace_v1_trace_config_proto != nil { - return - } - if !protoimpl.UnsafeEnabled { - file_opentelemetry_proto_trace_v1_trace_config_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*TraceConfig); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_opentelemetry_proto_trace_v1_trace_config_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*ConstantSampler); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_opentelemetry_proto_trace_v1_trace_config_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*TraceIdRatioBased); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_opentelemetry_proto_trace_v1_trace_config_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*RateLimitingSampler); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - } - file_opentelemetry_proto_trace_v1_trace_config_proto_msgTypes[0].OneofWrappers = []interface{}{ - (*TraceConfig_ConstantSampler)(nil), - (*TraceConfig_TraceIdRatioBased)(nil), - (*TraceConfig_RateLimitingSampler)(nil), - } - type x struct{} - out := protoimpl.TypeBuilder{ - File: protoimpl.DescBuilder{ - GoPackagePath: reflect.TypeOf(x{}).PkgPath(), - RawDescriptor: file_opentelemetry_proto_trace_v1_trace_config_proto_rawDesc, - NumEnums: 1, - NumMessages: 4, - NumExtensions: 0, - NumServices: 0, - }, - GoTypes: file_opentelemetry_proto_trace_v1_trace_config_proto_goTypes, - DependencyIndexes: file_opentelemetry_proto_trace_v1_trace_config_proto_depIdxs, - EnumInfos: file_opentelemetry_proto_trace_v1_trace_config_proto_enumTypes, - MessageInfos: file_opentelemetry_proto_trace_v1_trace_config_proto_msgTypes, - }.Build() - File_opentelemetry_proto_trace_v1_trace_config_proto = out.File - file_opentelemetry_proto_trace_v1_trace_config_proto_rawDesc = nil - file_opentelemetry_proto_trace_v1_trace_config_proto_goTypes = nil - file_opentelemetry_proto_trace_v1_trace_config_proto_depIdxs = nil -} diff --git a/vendor/go.opentelemetry.io/proto/otlp/collector/trace/v1/trace_service.pb.go b/vendor/go.opentelemetry.io/proto/otlp/collector/trace/v1/trace_service.pb.go deleted file mode 100644 index 402614f1d3..0000000000 --- a/vendor/go.opentelemetry.io/proto/otlp/collector/trace/v1/trace_service.pb.go +++ /dev/null @@ -1,252 +0,0 @@ -// Copyright 2019, OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Code generated by protoc-gen-go. DO NOT EDIT. -// versions: -// protoc-gen-go v1.23.0 -// protoc v3.13.0 -// source: opentelemetry/proto/collector/trace/v1/trace_service.proto - -package v1 - -import ( - proto "github.com/golang/protobuf/proto" - v1 "go.opentelemetry.io/proto/otlp/trace/v1" - protoreflect "google.golang.org/protobuf/reflect/protoreflect" - protoimpl "google.golang.org/protobuf/runtime/protoimpl" - reflect "reflect" - sync "sync" -) - -const ( - // Verify that this generated code is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) - // Verify that runtime/protoimpl is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) -) - -// This is a compile-time assertion that a sufficiently up-to-date version -// of the legacy proto package is being used. -const _ = proto.ProtoPackageIsVersion4 - -type ExportTraceServiceRequest struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - // An array of ResourceSpans. - // For data coming from a single resource this array will typically contain one - // element. Intermediary nodes (such as OpenTelemetry Collector) that receive - // data from multiple origins typically batch the data before forwarding further and - // in that case this array will contain multiple elements. - ResourceSpans []*v1.ResourceSpans `protobuf:"bytes,1,rep,name=resource_spans,json=resourceSpans,proto3" json:"resource_spans,omitempty"` -} - -func (x *ExportTraceServiceRequest) Reset() { - *x = ExportTraceServiceRequest{} - if protoimpl.UnsafeEnabled { - mi := &file_opentelemetry_proto_collector_trace_v1_trace_service_proto_msgTypes[0] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *ExportTraceServiceRequest) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*ExportTraceServiceRequest) ProtoMessage() {} - -func (x *ExportTraceServiceRequest) ProtoReflect() protoreflect.Message { - mi := &file_opentelemetry_proto_collector_trace_v1_trace_service_proto_msgTypes[0] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use ExportTraceServiceRequest.ProtoReflect.Descriptor instead. -func (*ExportTraceServiceRequest) Descriptor() ([]byte, []int) { - return file_opentelemetry_proto_collector_trace_v1_trace_service_proto_rawDescGZIP(), []int{0} -} - -func (x *ExportTraceServiceRequest) GetResourceSpans() []*v1.ResourceSpans { - if x != nil { - return x.ResourceSpans - } - return nil -} - -type ExportTraceServiceResponse struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields -} - -func (x *ExportTraceServiceResponse) Reset() { - *x = ExportTraceServiceResponse{} - if protoimpl.UnsafeEnabled { - mi := &file_opentelemetry_proto_collector_trace_v1_trace_service_proto_msgTypes[1] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *ExportTraceServiceResponse) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*ExportTraceServiceResponse) ProtoMessage() {} - -func (x *ExportTraceServiceResponse) ProtoReflect() protoreflect.Message { - mi := &file_opentelemetry_proto_collector_trace_v1_trace_service_proto_msgTypes[1] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use ExportTraceServiceResponse.ProtoReflect.Descriptor instead. -func (*ExportTraceServiceResponse) Descriptor() ([]byte, []int) { - return file_opentelemetry_proto_collector_trace_v1_trace_service_proto_rawDescGZIP(), []int{1} -} - -var File_opentelemetry_proto_collector_trace_v1_trace_service_proto protoreflect.FileDescriptor - -var file_opentelemetry_proto_collector_trace_v1_trace_service_proto_rawDesc = []byte{ - 0x0a, 0x3a, 0x6f, 0x70, 0x65, 0x6e, 0x74, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x74, 0x72, 0x79, 0x2f, - 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x63, 0x6f, 0x6c, 0x6c, 0x65, 0x63, 0x74, 0x6f, 0x72, 0x2f, - 0x74, 0x72, 0x61, 0x63, 0x65, 0x2f, 0x76, 0x31, 0x2f, 0x74, 0x72, 0x61, 0x63, 0x65, 0x5f, 0x73, - 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x26, 0x6f, 0x70, - 0x65, 0x6e, 0x74, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x74, 0x72, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, - 0x6f, 0x2e, 0x63, 0x6f, 0x6c, 0x6c, 0x65, 0x63, 0x74, 0x6f, 0x72, 0x2e, 0x74, 0x72, 0x61, 0x63, - 0x65, 0x2e, 0x76, 0x31, 0x1a, 0x28, 0x6f, 0x70, 0x65, 0x6e, 0x74, 0x65, 0x6c, 0x65, 0x6d, 0x65, - 0x74, 0x72, 0x79, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x74, 0x72, 0x61, 0x63, 0x65, 0x2f, - 0x76, 0x31, 0x2f, 0x74, 0x72, 0x61, 0x63, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x6f, - 0x0a, 0x19, 0x45, 0x78, 0x70, 0x6f, 0x72, 0x74, 0x54, 0x72, 0x61, 0x63, 0x65, 0x53, 0x65, 0x72, - 0x76, 0x69, 0x63, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x52, 0x0a, 0x0e, 0x72, - 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x5f, 0x73, 0x70, 0x61, 0x6e, 0x73, 0x18, 0x01, 0x20, - 0x03, 0x28, 0x0b, 0x32, 0x2b, 0x2e, 0x6f, 0x70, 0x65, 0x6e, 0x74, 0x65, 0x6c, 0x65, 0x6d, 0x65, - 0x74, 0x72, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x74, 0x72, 0x61, 0x63, 0x65, 0x2e, - 0x76, 0x31, 0x2e, 0x52, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x53, 0x70, 0x61, 0x6e, 0x73, - 0x52, 0x0d, 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x53, 0x70, 0x61, 0x6e, 0x73, 0x22, - 0x1c, 0x0a, 0x1a, 0x45, 0x78, 0x70, 0x6f, 0x72, 0x74, 0x54, 0x72, 0x61, 0x63, 0x65, 0x53, 0x65, - 0x72, 0x76, 0x69, 0x63, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x32, 0xa2, 0x01, - 0x0a, 0x0c, 0x54, 0x72, 0x61, 0x63, 0x65, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x91, - 0x01, 0x0a, 0x06, 0x45, 0x78, 0x70, 0x6f, 0x72, 0x74, 0x12, 0x41, 0x2e, 0x6f, 0x70, 0x65, 0x6e, - 0x74, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x74, 0x72, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, - 0x63, 0x6f, 0x6c, 0x6c, 0x65, 0x63, 0x74, 0x6f, 0x72, 0x2e, 0x74, 0x72, 0x61, 0x63, 0x65, 0x2e, - 0x76, 0x31, 0x2e, 0x45, 0x78, 0x70, 0x6f, 0x72, 0x74, 0x54, 0x72, 0x61, 0x63, 0x65, 0x53, 0x65, - 0x72, 0x76, 0x69, 0x63, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x42, 0x2e, 0x6f, - 0x70, 0x65, 0x6e, 0x74, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x74, 0x72, 0x79, 0x2e, 0x70, 0x72, 0x6f, - 0x74, 0x6f, 0x2e, 0x63, 0x6f, 0x6c, 0x6c, 0x65, 0x63, 0x74, 0x6f, 0x72, 0x2e, 0x74, 0x72, 0x61, - 0x63, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x45, 0x78, 0x70, 0x6f, 0x72, 0x74, 0x54, 0x72, 0x61, 0x63, - 0x65, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, - 0x22, 0x00, 0x42, 0x73, 0x0a, 0x29, 0x69, 0x6f, 0x2e, 0x6f, 0x70, 0x65, 0x6e, 0x74, 0x65, 0x6c, - 0x65, 0x6d, 0x65, 0x74, 0x72, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x63, 0x6f, 0x6c, - 0x6c, 0x65, 0x63, 0x74, 0x6f, 0x72, 0x2e, 0x74, 0x72, 0x61, 0x63, 0x65, 0x2e, 0x76, 0x31, 0x42, - 0x11, 0x54, 0x72, 0x61, 0x63, 0x65, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x50, 0x72, 0x6f, - 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x31, 0x67, 0x6f, 0x2e, 0x6f, 0x70, 0x65, 0x6e, 0x74, 0x65, 0x6c, - 0x65, 0x6d, 0x65, 0x74, 0x72, 0x79, 0x2e, 0x69, 0x6f, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, - 0x6f, 0x74, 0x6c, 0x70, 0x2f, 0x63, 0x6f, 0x6c, 0x6c, 0x65, 0x63, 0x74, 0x6f, 0x72, 0x2f, 0x74, - 0x72, 0x61, 0x63, 0x65, 0x2f, 0x76, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, -} - -var ( - file_opentelemetry_proto_collector_trace_v1_trace_service_proto_rawDescOnce sync.Once - file_opentelemetry_proto_collector_trace_v1_trace_service_proto_rawDescData = file_opentelemetry_proto_collector_trace_v1_trace_service_proto_rawDesc -) - -func file_opentelemetry_proto_collector_trace_v1_trace_service_proto_rawDescGZIP() []byte { - file_opentelemetry_proto_collector_trace_v1_trace_service_proto_rawDescOnce.Do(func() { - file_opentelemetry_proto_collector_trace_v1_trace_service_proto_rawDescData = protoimpl.X.CompressGZIP(file_opentelemetry_proto_collector_trace_v1_trace_service_proto_rawDescData) - }) - return file_opentelemetry_proto_collector_trace_v1_trace_service_proto_rawDescData -} - -var file_opentelemetry_proto_collector_trace_v1_trace_service_proto_msgTypes = make([]protoimpl.MessageInfo, 2) -var file_opentelemetry_proto_collector_trace_v1_trace_service_proto_goTypes = []interface{}{ - (*ExportTraceServiceRequest)(nil), // 0: opentelemetry.proto.collector.trace.v1.ExportTraceServiceRequest - (*ExportTraceServiceResponse)(nil), // 1: opentelemetry.proto.collector.trace.v1.ExportTraceServiceResponse - (*v1.ResourceSpans)(nil), // 2: opentelemetry.proto.trace.v1.ResourceSpans -} -var file_opentelemetry_proto_collector_trace_v1_trace_service_proto_depIdxs = []int32{ - 2, // 0: opentelemetry.proto.collector.trace.v1.ExportTraceServiceRequest.resource_spans:type_name -> opentelemetry.proto.trace.v1.ResourceSpans - 0, // 1: opentelemetry.proto.collector.trace.v1.TraceService.Export:input_type -> opentelemetry.proto.collector.trace.v1.ExportTraceServiceRequest - 1, // 2: opentelemetry.proto.collector.trace.v1.TraceService.Export:output_type -> opentelemetry.proto.collector.trace.v1.ExportTraceServiceResponse - 2, // [2:3] is the sub-list for method output_type - 1, // [1:2] is the sub-list for method input_type - 1, // [1:1] is the sub-list for extension type_name - 1, // [1:1] is the sub-list for extension extendee - 0, // [0:1] is the sub-list for field type_name -} - -func init() { file_opentelemetry_proto_collector_trace_v1_trace_service_proto_init() } -func file_opentelemetry_proto_collector_trace_v1_trace_service_proto_init() { - if File_opentelemetry_proto_collector_trace_v1_trace_service_proto != nil { - return - } - if !protoimpl.UnsafeEnabled { - file_opentelemetry_proto_collector_trace_v1_trace_service_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*ExportTraceServiceRequest); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_opentelemetry_proto_collector_trace_v1_trace_service_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*ExportTraceServiceResponse); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - } - type x struct{} - out := protoimpl.TypeBuilder{ - File: protoimpl.DescBuilder{ - GoPackagePath: reflect.TypeOf(x{}).PkgPath(), - RawDescriptor: file_opentelemetry_proto_collector_trace_v1_trace_service_proto_rawDesc, - NumEnums: 0, - NumMessages: 2, - NumExtensions: 0, - NumServices: 1, - }, - GoTypes: file_opentelemetry_proto_collector_trace_v1_trace_service_proto_goTypes, - DependencyIndexes: file_opentelemetry_proto_collector_trace_v1_trace_service_proto_depIdxs, - MessageInfos: file_opentelemetry_proto_collector_trace_v1_trace_service_proto_msgTypes, - }.Build() - File_opentelemetry_proto_collector_trace_v1_trace_service_proto = out.File - file_opentelemetry_proto_collector_trace_v1_trace_service_proto_rawDesc = nil - file_opentelemetry_proto_collector_trace_v1_trace_service_proto_goTypes = nil - file_opentelemetry_proto_collector_trace_v1_trace_service_proto_depIdxs = nil -} diff --git a/vendor/go.opentelemetry.io/proto/otlp/collector/trace/v1/trace_service.pb.gw.go b/vendor/go.opentelemetry.io/proto/otlp/collector/trace/v1/trace_service.pb.gw.go deleted file mode 100644 index 18dff3d03e..0000000000 --- a/vendor/go.opentelemetry.io/proto/otlp/collector/trace/v1/trace_service.pb.gw.go +++ /dev/null @@ -1,169 +0,0 @@ -// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. -// source: opentelemetry/proto/collector/trace/v1/trace_service.proto - -/* -Package v1 is a reverse proxy. - -It translates gRPC into RESTful JSON APIs. -*/ -package v1 - -import ( - "context" - "io" - "net/http" - - "github.com/golang/protobuf/descriptor" - "github.com/golang/protobuf/proto" - "github.com/grpc-ecosystem/grpc-gateway/runtime" - "github.com/grpc-ecosystem/grpc-gateway/utilities" - "google.golang.org/grpc" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/grpclog" - "google.golang.org/grpc/metadata" - "google.golang.org/grpc/status" -) - -// Suppress "imported and not used" errors -var _ codes.Code -var _ io.Reader -var _ status.Status -var _ = runtime.String -var _ = utilities.NewDoubleArray -var _ = descriptor.ForMessage -var _ = metadata.Join - -func request_TraceService_Export_0(ctx context.Context, marshaler runtime.Marshaler, client TraceServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq ExportTraceServiceRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.Export(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func local_request_TraceService_Export_0(ctx context.Context, marshaler runtime.Marshaler, server TraceServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq ExportTraceServiceRequest - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := server.Export(ctx, &protoReq) - return msg, metadata, err - -} - -// RegisterTraceServiceHandlerServer registers the http handlers for service TraceService to "mux". -// UnaryRPC :call TraceServiceServer directly. -// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. -// Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterTraceServiceHandlerFromEndpoint instead. -func RegisterTraceServiceHandlerServer(ctx context.Context, mux *runtime.ServeMux, server TraceServiceServer) error { - - mux.Handle("POST", pattern_TraceService_Export_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - var stream runtime.ServerTransportStream - ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := local_request_TraceService_Export_0(rctx, inboundMarshaler, server, req, pathParams) - md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_TraceService_Export_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - return nil -} - -// RegisterTraceServiceHandlerFromEndpoint is same as RegisterTraceServiceHandler but -// automatically dials to "endpoint" and closes the connection when "ctx" gets done. -func RegisterTraceServiceHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { - conn, err := grpc.Dial(endpoint, opts...) - if err != nil { - return err - } - defer func() { - if err != nil { - if cerr := conn.Close(); cerr != nil { - grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) - } - return - } - go func() { - <-ctx.Done() - if cerr := conn.Close(); cerr != nil { - grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) - } - }() - }() - - return RegisterTraceServiceHandler(ctx, mux, conn) -} - -// RegisterTraceServiceHandler registers the http handlers for service TraceService to "mux". -// The handlers forward requests to the grpc endpoint over "conn". -func RegisterTraceServiceHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { - return RegisterTraceServiceHandlerClient(ctx, mux, NewTraceServiceClient(conn)) -} - -// RegisterTraceServiceHandlerClient registers the http handlers for service TraceService -// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "TraceServiceClient". -// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "TraceServiceClient" -// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in -// "TraceServiceClient" to call the correct interceptors. -func RegisterTraceServiceHandlerClient(ctx context.Context, mux *runtime.ServeMux, client TraceServiceClient) error { - - mux.Handle("POST", pattern_TraceService_Export_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_TraceService_Export_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_TraceService_Export_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - return nil -} - -var ( - pattern_TraceService_Export_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "trace"}, "", runtime.AssumeColonVerbOpt(true))) -) - -var ( - forward_TraceService_Export_0 = runtime.ForwardResponseMessage -) diff --git a/vendor/go.opentelemetry.io/proto/otlp/collector/trace/v1/trace_service_grpc.pb.go b/vendor/go.opentelemetry.io/proto/otlp/collector/trace/v1/trace_service_grpc.pb.go deleted file mode 100644 index 4e4c24c0c8..0000000000 --- a/vendor/go.opentelemetry.io/proto/otlp/collector/trace/v1/trace_service_grpc.pb.go +++ /dev/null @@ -1,101 +0,0 @@ -// Code generated by protoc-gen-go-grpc. DO NOT EDIT. - -package v1 - -import ( - context "context" - grpc "google.golang.org/grpc" - codes "google.golang.org/grpc/codes" - status "google.golang.org/grpc/status" -) - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the grpc package it is being compiled against. -const _ = grpc.SupportPackageIsVersion7 - -// TraceServiceClient is the client API for TraceService service. -// -// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. -type TraceServiceClient interface { - // For performance reasons, it is recommended to keep this RPC - // alive for the entire life of the application. - Export(ctx context.Context, in *ExportTraceServiceRequest, opts ...grpc.CallOption) (*ExportTraceServiceResponse, error) -} - -type traceServiceClient struct { - cc grpc.ClientConnInterface -} - -func NewTraceServiceClient(cc grpc.ClientConnInterface) TraceServiceClient { - return &traceServiceClient{cc} -} - -func (c *traceServiceClient) Export(ctx context.Context, in *ExportTraceServiceRequest, opts ...grpc.CallOption) (*ExportTraceServiceResponse, error) { - out := new(ExportTraceServiceResponse) - err := c.cc.Invoke(ctx, "/opentelemetry.proto.collector.trace.v1.TraceService/Export", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -// TraceServiceServer is the server API for TraceService service. -// All implementations must embed UnimplementedTraceServiceServer -// for forward compatibility -type TraceServiceServer interface { - // For performance reasons, it is recommended to keep this RPC - // alive for the entire life of the application. - Export(context.Context, *ExportTraceServiceRequest) (*ExportTraceServiceResponse, error) - mustEmbedUnimplementedTraceServiceServer() -} - -// UnimplementedTraceServiceServer must be embedded to have forward compatible implementations. -type UnimplementedTraceServiceServer struct { -} - -func (UnimplementedTraceServiceServer) Export(context.Context, *ExportTraceServiceRequest) (*ExportTraceServiceResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method Export not implemented") -} -func (UnimplementedTraceServiceServer) mustEmbedUnimplementedTraceServiceServer() {} - -// UnsafeTraceServiceServer may be embedded to opt out of forward compatibility for this service. -// Use of this interface is not recommended, as added methods to TraceServiceServer will -// result in compilation errors. -type UnsafeTraceServiceServer interface { - mustEmbedUnimplementedTraceServiceServer() -} - -func RegisterTraceServiceServer(s grpc.ServiceRegistrar, srv TraceServiceServer) { - s.RegisterService(&_TraceService_serviceDesc, srv) -} - -func _TraceService_Export_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(ExportTraceServiceRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(TraceServiceServer).Export(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/opentelemetry.proto.collector.trace.v1.TraceService/Export", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(TraceServiceServer).Export(ctx, req.(*ExportTraceServiceRequest)) - } - return interceptor(ctx, in, info, handler) -} - -var _TraceService_serviceDesc = grpc.ServiceDesc{ - ServiceName: "opentelemetry.proto.collector.trace.v1.TraceService", - HandlerType: (*TraceServiceServer)(nil), - Methods: []grpc.MethodDesc{ - { - MethodName: "Export", - Handler: _TraceService_Export_Handler, - }, - }, - Streams: []grpc.StreamDesc{}, - Metadata: "opentelemetry/proto/collector/trace/v1/trace_service.proto", -} diff --git a/vendor/go.opentelemetry.io/proto/otlp/common/v1/common.pb.go b/vendor/go.opentelemetry.io/proto/otlp/common/v1/common.pb.go deleted file mode 100644 index 567e55849a..0000000000 --- a/vendor/go.opentelemetry.io/proto/otlp/common/v1/common.pb.go +++ /dev/null @@ -1,659 +0,0 @@ -// Copyright 2019, OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Code generated by protoc-gen-go. DO NOT EDIT. -// versions: -// protoc-gen-go v1.23.0 -// protoc v3.13.0 -// source: opentelemetry/proto/common/v1/common.proto - -package v1 - -import ( - proto "github.com/golang/protobuf/proto" - protoreflect "google.golang.org/protobuf/reflect/protoreflect" - protoimpl "google.golang.org/protobuf/runtime/protoimpl" - reflect "reflect" - sync "sync" -) - -const ( - // Verify that this generated code is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) - // Verify that runtime/protoimpl is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) -) - -// This is a compile-time assertion that a sufficiently up-to-date version -// of the legacy proto package is being used. -const _ = proto.ProtoPackageIsVersion4 - -// AnyValue is used to represent any type of attribute value. AnyValue may contain a -// primitive value such as a string or integer or it may contain an arbitrary nested -// object containing arrays, key-value lists and primitives. -type AnyValue struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - // The value is one of the listed fields. It is valid for all values to be unspecified - // in which case this AnyValue is considered to be "null". - // - // Types that are assignable to Value: - // *AnyValue_StringValue - // *AnyValue_BoolValue - // *AnyValue_IntValue - // *AnyValue_DoubleValue - // *AnyValue_ArrayValue - // *AnyValue_KvlistValue - Value isAnyValue_Value `protobuf_oneof:"value"` -} - -func (x *AnyValue) Reset() { - *x = AnyValue{} - if protoimpl.UnsafeEnabled { - mi := &file_opentelemetry_proto_common_v1_common_proto_msgTypes[0] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *AnyValue) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*AnyValue) ProtoMessage() {} - -func (x *AnyValue) ProtoReflect() protoreflect.Message { - mi := &file_opentelemetry_proto_common_v1_common_proto_msgTypes[0] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use AnyValue.ProtoReflect.Descriptor instead. -func (*AnyValue) Descriptor() ([]byte, []int) { - return file_opentelemetry_proto_common_v1_common_proto_rawDescGZIP(), []int{0} -} - -func (m *AnyValue) GetValue() isAnyValue_Value { - if m != nil { - return m.Value - } - return nil -} - -func (x *AnyValue) GetStringValue() string { - if x, ok := x.GetValue().(*AnyValue_StringValue); ok { - return x.StringValue - } - return "" -} - -func (x *AnyValue) GetBoolValue() bool { - if x, ok := x.GetValue().(*AnyValue_BoolValue); ok { - return x.BoolValue - } - return false -} - -func (x *AnyValue) GetIntValue() int64 { - if x, ok := x.GetValue().(*AnyValue_IntValue); ok { - return x.IntValue - } - return 0 -} - -func (x *AnyValue) GetDoubleValue() float64 { - if x, ok := x.GetValue().(*AnyValue_DoubleValue); ok { - return x.DoubleValue - } - return 0 -} - -func (x *AnyValue) GetArrayValue() *ArrayValue { - if x, ok := x.GetValue().(*AnyValue_ArrayValue); ok { - return x.ArrayValue - } - return nil -} - -func (x *AnyValue) GetKvlistValue() *KeyValueList { - if x, ok := x.GetValue().(*AnyValue_KvlistValue); ok { - return x.KvlistValue - } - return nil -} - -type isAnyValue_Value interface { - isAnyValue_Value() -} - -type AnyValue_StringValue struct { - StringValue string `protobuf:"bytes,1,opt,name=string_value,json=stringValue,proto3,oneof"` -} - -type AnyValue_BoolValue struct { - BoolValue bool `protobuf:"varint,2,opt,name=bool_value,json=boolValue,proto3,oneof"` -} - -type AnyValue_IntValue struct { - IntValue int64 `protobuf:"varint,3,opt,name=int_value,json=intValue,proto3,oneof"` -} - -type AnyValue_DoubleValue struct { - DoubleValue float64 `protobuf:"fixed64,4,opt,name=double_value,json=doubleValue,proto3,oneof"` -} - -type AnyValue_ArrayValue struct { - ArrayValue *ArrayValue `protobuf:"bytes,5,opt,name=array_value,json=arrayValue,proto3,oneof"` -} - -type AnyValue_KvlistValue struct { - KvlistValue *KeyValueList `protobuf:"bytes,6,opt,name=kvlist_value,json=kvlistValue,proto3,oneof"` -} - -func (*AnyValue_StringValue) isAnyValue_Value() {} - -func (*AnyValue_BoolValue) isAnyValue_Value() {} - -func (*AnyValue_IntValue) isAnyValue_Value() {} - -func (*AnyValue_DoubleValue) isAnyValue_Value() {} - -func (*AnyValue_ArrayValue) isAnyValue_Value() {} - -func (*AnyValue_KvlistValue) isAnyValue_Value() {} - -// ArrayValue is a list of AnyValue messages. We need ArrayValue as a message -// since oneof in AnyValue does not allow repeated fields. -type ArrayValue struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - // Array of values. The array may be empty (contain 0 elements). - Values []*AnyValue `protobuf:"bytes,1,rep,name=values,proto3" json:"values,omitempty"` -} - -func (x *ArrayValue) Reset() { - *x = ArrayValue{} - if protoimpl.UnsafeEnabled { - mi := &file_opentelemetry_proto_common_v1_common_proto_msgTypes[1] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *ArrayValue) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*ArrayValue) ProtoMessage() {} - -func (x *ArrayValue) ProtoReflect() protoreflect.Message { - mi := &file_opentelemetry_proto_common_v1_common_proto_msgTypes[1] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use ArrayValue.ProtoReflect.Descriptor instead. -func (*ArrayValue) Descriptor() ([]byte, []int) { - return file_opentelemetry_proto_common_v1_common_proto_rawDescGZIP(), []int{1} -} - -func (x *ArrayValue) GetValues() []*AnyValue { - if x != nil { - return x.Values - } - return nil -} - -// KeyValueList is a list of KeyValue messages. We need KeyValueList as a message -// since `oneof` in AnyValue does not allow repeated fields. Everywhere else where we need -// a list of KeyValue messages (e.g. in Span) we use `repeated KeyValue` directly to -// avoid unnecessary extra wrapping (which slows down the protocol). The 2 approaches -// are semantically equivalent. -type KeyValueList struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - // A collection of key/value pairs of key-value pairs. The list may be empty (may - // contain 0 elements). - Values []*KeyValue `protobuf:"bytes,1,rep,name=values,proto3" json:"values,omitempty"` -} - -func (x *KeyValueList) Reset() { - *x = KeyValueList{} - if protoimpl.UnsafeEnabled { - mi := &file_opentelemetry_proto_common_v1_common_proto_msgTypes[2] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *KeyValueList) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*KeyValueList) ProtoMessage() {} - -func (x *KeyValueList) ProtoReflect() protoreflect.Message { - mi := &file_opentelemetry_proto_common_v1_common_proto_msgTypes[2] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use KeyValueList.ProtoReflect.Descriptor instead. -func (*KeyValueList) Descriptor() ([]byte, []int) { - return file_opentelemetry_proto_common_v1_common_proto_rawDescGZIP(), []int{2} -} - -func (x *KeyValueList) GetValues() []*KeyValue { - if x != nil { - return x.Values - } - return nil -} - -// KeyValue is a key-value pair that is used to store Span attributes, Link -// attributes, etc. -type KeyValue struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` - Value *AnyValue `protobuf:"bytes,2,opt,name=value,proto3" json:"value,omitempty"` -} - -func (x *KeyValue) Reset() { - *x = KeyValue{} - if protoimpl.UnsafeEnabled { - mi := &file_opentelemetry_proto_common_v1_common_proto_msgTypes[3] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *KeyValue) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*KeyValue) ProtoMessage() {} - -func (x *KeyValue) ProtoReflect() protoreflect.Message { - mi := &file_opentelemetry_proto_common_v1_common_proto_msgTypes[3] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use KeyValue.ProtoReflect.Descriptor instead. -func (*KeyValue) Descriptor() ([]byte, []int) { - return file_opentelemetry_proto_common_v1_common_proto_rawDescGZIP(), []int{3} -} - -func (x *KeyValue) GetKey() string { - if x != nil { - return x.Key - } - return "" -} - -func (x *KeyValue) GetValue() *AnyValue { - if x != nil { - return x.Value - } - return nil -} - -// StringKeyValue is a pair of key/value strings. This is the simpler (and faster) version -// of KeyValue that only supports string values. -type StringKeyValue struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` - Value string `protobuf:"bytes,2,opt,name=value,proto3" json:"value,omitempty"` -} - -func (x *StringKeyValue) Reset() { - *x = StringKeyValue{} - if protoimpl.UnsafeEnabled { - mi := &file_opentelemetry_proto_common_v1_common_proto_msgTypes[4] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *StringKeyValue) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*StringKeyValue) ProtoMessage() {} - -func (x *StringKeyValue) ProtoReflect() protoreflect.Message { - mi := &file_opentelemetry_proto_common_v1_common_proto_msgTypes[4] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use StringKeyValue.ProtoReflect.Descriptor instead. -func (*StringKeyValue) Descriptor() ([]byte, []int) { - return file_opentelemetry_proto_common_v1_common_proto_rawDescGZIP(), []int{4} -} - -func (x *StringKeyValue) GetKey() string { - if x != nil { - return x.Key - } - return "" -} - -func (x *StringKeyValue) GetValue() string { - if x != nil { - return x.Value - } - return "" -} - -// InstrumentationLibrary is a message representing the instrumentation library information -// such as the fully qualified name and version. -type InstrumentationLibrary struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - // An empty instrumentation library name means the name is unknown. - Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` - Version string `protobuf:"bytes,2,opt,name=version,proto3" json:"version,omitempty"` -} - -func (x *InstrumentationLibrary) Reset() { - *x = InstrumentationLibrary{} - if protoimpl.UnsafeEnabled { - mi := &file_opentelemetry_proto_common_v1_common_proto_msgTypes[5] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *InstrumentationLibrary) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*InstrumentationLibrary) ProtoMessage() {} - -func (x *InstrumentationLibrary) ProtoReflect() protoreflect.Message { - mi := &file_opentelemetry_proto_common_v1_common_proto_msgTypes[5] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use InstrumentationLibrary.ProtoReflect.Descriptor instead. -func (*InstrumentationLibrary) Descriptor() ([]byte, []int) { - return file_opentelemetry_proto_common_v1_common_proto_rawDescGZIP(), []int{5} -} - -func (x *InstrumentationLibrary) GetName() string { - if x != nil { - return x.Name - } - return "" -} - -func (x *InstrumentationLibrary) GetVersion() string { - if x != nil { - return x.Version - } - return "" -} - -var File_opentelemetry_proto_common_v1_common_proto protoreflect.FileDescriptor - -var file_opentelemetry_proto_common_v1_common_proto_rawDesc = []byte{ - 0x0a, 0x2a, 0x6f, 0x70, 0x65, 0x6e, 0x74, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x74, 0x72, 0x79, 0x2f, - 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2f, 0x76, 0x31, 0x2f, - 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x1d, 0x6f, 0x70, - 0x65, 0x6e, 0x74, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x74, 0x72, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, - 0x6f, 0x2e, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2e, 0x76, 0x31, 0x22, 0xbd, 0x02, 0x0a, 0x08, - 0x41, 0x6e, 0x79, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x12, 0x23, 0x0a, 0x0c, 0x73, 0x74, 0x72, 0x69, - 0x6e, 0x67, 0x5f, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x48, 0x00, - 0x52, 0x0b, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x12, 0x1f, 0x0a, - 0x0a, 0x62, 0x6f, 0x6f, 0x6c, 0x5f, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, - 0x08, 0x48, 0x00, 0x52, 0x09, 0x62, 0x6f, 0x6f, 0x6c, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x12, 0x1d, - 0x0a, 0x09, 0x69, 0x6e, 0x74, 0x5f, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, - 0x03, 0x48, 0x00, 0x52, 0x08, 0x69, 0x6e, 0x74, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x12, 0x23, 0x0a, - 0x0c, 0x64, 0x6f, 0x75, 0x62, 0x6c, 0x65, 0x5f, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x04, 0x20, - 0x01, 0x28, 0x01, 0x48, 0x00, 0x52, 0x0b, 0x64, 0x6f, 0x75, 0x62, 0x6c, 0x65, 0x56, 0x61, 0x6c, - 0x75, 0x65, 0x12, 0x4c, 0x0a, 0x0b, 0x61, 0x72, 0x72, 0x61, 0x79, 0x5f, 0x76, 0x61, 0x6c, 0x75, - 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x29, 0x2e, 0x6f, 0x70, 0x65, 0x6e, 0x74, 0x65, - 0x6c, 0x65, 0x6d, 0x65, 0x74, 0x72, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x63, 0x6f, - 0x6d, 0x6d, 0x6f, 0x6e, 0x2e, 0x76, 0x31, 0x2e, 0x41, 0x72, 0x72, 0x61, 0x79, 0x56, 0x61, 0x6c, - 0x75, 0x65, 0x48, 0x00, 0x52, 0x0a, 0x61, 0x72, 0x72, 0x61, 0x79, 0x56, 0x61, 0x6c, 0x75, 0x65, - 0x12, 0x50, 0x0a, 0x0c, 0x6b, 0x76, 0x6c, 0x69, 0x73, 0x74, 0x5f, 0x76, 0x61, 0x6c, 0x75, 0x65, - 0x18, 0x06, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x2b, 0x2e, 0x6f, 0x70, 0x65, 0x6e, 0x74, 0x65, 0x6c, - 0x65, 0x6d, 0x65, 0x74, 0x72, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x63, 0x6f, 0x6d, - 0x6d, 0x6f, 0x6e, 0x2e, 0x76, 0x31, 0x2e, 0x4b, 0x65, 0x79, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x4c, - 0x69, 0x73, 0x74, 0x48, 0x00, 0x52, 0x0b, 0x6b, 0x76, 0x6c, 0x69, 0x73, 0x74, 0x56, 0x61, 0x6c, - 0x75, 0x65, 0x42, 0x07, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x22, 0x4d, 0x0a, 0x0a, 0x41, - 0x72, 0x72, 0x61, 0x79, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x12, 0x3f, 0x0a, 0x06, 0x76, 0x61, 0x6c, - 0x75, 0x65, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x27, 0x2e, 0x6f, 0x70, 0x65, 0x6e, - 0x74, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x74, 0x72, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, - 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2e, 0x76, 0x31, 0x2e, 0x41, 0x6e, 0x79, 0x56, 0x61, 0x6c, - 0x75, 0x65, 0x52, 0x06, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x73, 0x22, 0x4f, 0x0a, 0x0c, 0x4b, 0x65, - 0x79, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x4c, 0x69, 0x73, 0x74, 0x12, 0x3f, 0x0a, 0x06, 0x76, 0x61, - 0x6c, 0x75, 0x65, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x27, 0x2e, 0x6f, 0x70, 0x65, - 0x6e, 0x74, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x74, 0x72, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x2e, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2e, 0x76, 0x31, 0x2e, 0x4b, 0x65, 0x79, 0x56, 0x61, - 0x6c, 0x75, 0x65, 0x52, 0x06, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x73, 0x22, 0x5b, 0x0a, 0x08, 0x4b, - 0x65, 0x79, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, - 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x3d, 0x0a, 0x05, 0x76, 0x61, 0x6c, - 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x27, 0x2e, 0x6f, 0x70, 0x65, 0x6e, 0x74, - 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x74, 0x72, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x63, - 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2e, 0x76, 0x31, 0x2e, 0x41, 0x6e, 0x79, 0x56, 0x61, 0x6c, 0x75, - 0x65, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x22, 0x38, 0x0a, 0x0e, 0x53, 0x74, 0x72, 0x69, - 0x6e, 0x67, 0x4b, 0x65, 0x79, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, - 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, - 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, - 0x75, 0x65, 0x22, 0x46, 0x0a, 0x16, 0x49, 0x6e, 0x73, 0x74, 0x72, 0x75, 0x6d, 0x65, 0x6e, 0x74, - 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x4c, 0x69, 0x62, 0x72, 0x61, 0x72, 0x79, 0x12, 0x12, 0x0a, 0x04, - 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, - 0x12, 0x18, 0x0a, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, - 0x09, 0x52, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x42, 0x5b, 0x0a, 0x20, 0x69, 0x6f, - 0x2e, 0x6f, 0x70, 0x65, 0x6e, 0x74, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x74, 0x72, 0x79, 0x2e, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2e, 0x76, 0x31, 0x42, 0x0b, - 0x43, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x28, 0x67, - 0x6f, 0x2e, 0x6f, 0x70, 0x65, 0x6e, 0x74, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x74, 0x72, 0x79, 0x2e, - 0x69, 0x6f, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x6f, 0x74, 0x6c, 0x70, 0x2f, 0x63, 0x6f, - 0x6d, 0x6d, 0x6f, 0x6e, 0x2f, 0x76, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, -} - -var ( - file_opentelemetry_proto_common_v1_common_proto_rawDescOnce sync.Once - file_opentelemetry_proto_common_v1_common_proto_rawDescData = file_opentelemetry_proto_common_v1_common_proto_rawDesc -) - -func file_opentelemetry_proto_common_v1_common_proto_rawDescGZIP() []byte { - file_opentelemetry_proto_common_v1_common_proto_rawDescOnce.Do(func() { - file_opentelemetry_proto_common_v1_common_proto_rawDescData = protoimpl.X.CompressGZIP(file_opentelemetry_proto_common_v1_common_proto_rawDescData) - }) - return file_opentelemetry_proto_common_v1_common_proto_rawDescData -} - -var file_opentelemetry_proto_common_v1_common_proto_msgTypes = make([]protoimpl.MessageInfo, 6) -var file_opentelemetry_proto_common_v1_common_proto_goTypes = []interface{}{ - (*AnyValue)(nil), // 0: opentelemetry.proto.common.v1.AnyValue - (*ArrayValue)(nil), // 1: opentelemetry.proto.common.v1.ArrayValue - (*KeyValueList)(nil), // 2: opentelemetry.proto.common.v1.KeyValueList - (*KeyValue)(nil), // 3: opentelemetry.proto.common.v1.KeyValue - (*StringKeyValue)(nil), // 4: opentelemetry.proto.common.v1.StringKeyValue - (*InstrumentationLibrary)(nil), // 5: opentelemetry.proto.common.v1.InstrumentationLibrary -} -var file_opentelemetry_proto_common_v1_common_proto_depIdxs = []int32{ - 1, // 0: opentelemetry.proto.common.v1.AnyValue.array_value:type_name -> opentelemetry.proto.common.v1.ArrayValue - 2, // 1: opentelemetry.proto.common.v1.AnyValue.kvlist_value:type_name -> opentelemetry.proto.common.v1.KeyValueList - 0, // 2: opentelemetry.proto.common.v1.ArrayValue.values:type_name -> opentelemetry.proto.common.v1.AnyValue - 3, // 3: opentelemetry.proto.common.v1.KeyValueList.values:type_name -> opentelemetry.proto.common.v1.KeyValue - 0, // 4: opentelemetry.proto.common.v1.KeyValue.value:type_name -> opentelemetry.proto.common.v1.AnyValue - 5, // [5:5] is the sub-list for method output_type - 5, // [5:5] is the sub-list for method input_type - 5, // [5:5] is the sub-list for extension type_name - 5, // [5:5] is the sub-list for extension extendee - 0, // [0:5] is the sub-list for field type_name -} - -func init() { file_opentelemetry_proto_common_v1_common_proto_init() } -func file_opentelemetry_proto_common_v1_common_proto_init() { - if File_opentelemetry_proto_common_v1_common_proto != nil { - return - } - if !protoimpl.UnsafeEnabled { - file_opentelemetry_proto_common_v1_common_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*AnyValue); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_opentelemetry_proto_common_v1_common_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*ArrayValue); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_opentelemetry_proto_common_v1_common_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*KeyValueList); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_opentelemetry_proto_common_v1_common_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*KeyValue); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_opentelemetry_proto_common_v1_common_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*StringKeyValue); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_opentelemetry_proto_common_v1_common_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*InstrumentationLibrary); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - } - file_opentelemetry_proto_common_v1_common_proto_msgTypes[0].OneofWrappers = []interface{}{ - (*AnyValue_StringValue)(nil), - (*AnyValue_BoolValue)(nil), - (*AnyValue_IntValue)(nil), - (*AnyValue_DoubleValue)(nil), - (*AnyValue_ArrayValue)(nil), - (*AnyValue_KvlistValue)(nil), - } - type x struct{} - out := protoimpl.TypeBuilder{ - File: protoimpl.DescBuilder{ - GoPackagePath: reflect.TypeOf(x{}).PkgPath(), - RawDescriptor: file_opentelemetry_proto_common_v1_common_proto_rawDesc, - NumEnums: 0, - NumMessages: 6, - NumExtensions: 0, - NumServices: 0, - }, - GoTypes: file_opentelemetry_proto_common_v1_common_proto_goTypes, - DependencyIndexes: file_opentelemetry_proto_common_v1_common_proto_depIdxs, - MessageInfos: file_opentelemetry_proto_common_v1_common_proto_msgTypes, - }.Build() - File_opentelemetry_proto_common_v1_common_proto = out.File - file_opentelemetry_proto_common_v1_common_proto_rawDesc = nil - file_opentelemetry_proto_common_v1_common_proto_goTypes = nil - file_opentelemetry_proto_common_v1_common_proto_depIdxs = nil -} diff --git a/vendor/go.opentelemetry.io/proto/otlp/metrics/v1/metrics.pb.go b/vendor/go.opentelemetry.io/proto/otlp/metrics/v1/metrics.pb.go deleted file mode 100644 index 64364a184d..0000000000 --- a/vendor/go.opentelemetry.io/proto/otlp/metrics/v1/metrics.pb.go +++ /dev/null @@ -1,2469 +0,0 @@ -// Copyright 2019, OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Code generated by protoc-gen-go. DO NOT EDIT. -// versions: -// protoc-gen-go v1.23.0 -// protoc v3.13.0 -// source: opentelemetry/proto/metrics/v1/metrics.proto - -package v1 - -import ( - proto "github.com/golang/protobuf/proto" - v11 "go.opentelemetry.io/proto/otlp/common/v1" - v1 "go.opentelemetry.io/proto/otlp/resource/v1" - protoreflect "google.golang.org/protobuf/reflect/protoreflect" - protoimpl "google.golang.org/protobuf/runtime/protoimpl" - reflect "reflect" - sync "sync" -) - -const ( - // Verify that this generated code is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) - // Verify that runtime/protoimpl is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) -) - -// This is a compile-time assertion that a sufficiently up-to-date version -// of the legacy proto package is being used. -const _ = proto.ProtoPackageIsVersion4 - -// AggregationTemporality defines how a metric aggregator reports aggregated -// values. It describes how those values relate to the time interval over -// which they are aggregated. -type AggregationTemporality int32 - -const ( - // UNSPECIFIED is the default AggregationTemporality, it MUST not be used. - AggregationTemporality_AGGREGATION_TEMPORALITY_UNSPECIFIED AggregationTemporality = 0 - // DELTA is an AggregationTemporality for a metric aggregator which reports - // changes since last report time. Successive metrics contain aggregation of - // values from continuous and non-overlapping intervals. - // - // The values for a DELTA metric are based only on the time interval - // associated with one measurement cycle. There is no dependency on - // previous measurements like is the case for CUMULATIVE metrics. - // - // For example, consider a system measuring the number of requests that - // it receives and reports the sum of these requests every second as a - // DELTA metric: - // - // 1. The system starts receiving at time=t_0. - // 2. A request is received, the system measures 1 request. - // 3. A request is received, the system measures 1 request. - // 4. A request is received, the system measures 1 request. - // 5. The 1 second collection cycle ends. A metric is exported for the - // number of requests received over the interval of time t_0 to - // t_0+1 with a value of 3. - // 6. A request is received, the system measures 1 request. - // 7. A request is received, the system measures 1 request. - // 8. The 1 second collection cycle ends. A metric is exported for the - // number of requests received over the interval of time t_0+1 to - // t_0+2 with a value of 2. - AggregationTemporality_AGGREGATION_TEMPORALITY_DELTA AggregationTemporality = 1 - // CUMULATIVE is an AggregationTemporality for a metric aggregator which - // reports changes since a fixed start time. This means that current values - // of a CUMULATIVE metric depend on all previous measurements since the - // start time. Because of this, the sender is required to retain this state - // in some form. If this state is lost or invalidated, the CUMULATIVE metric - // values MUST be reset and a new fixed start time following the last - // reported measurement time sent MUST be used. - // - // For example, consider a system measuring the number of requests that - // it receives and reports the sum of these requests every second as a - // CUMULATIVE metric: - // - // 1. The system starts receiving at time=t_0. - // 2. A request is received, the system measures 1 request. - // 3. A request is received, the system measures 1 request. - // 4. A request is received, the system measures 1 request. - // 5. The 1 second collection cycle ends. A metric is exported for the - // number of requests received over the interval of time t_0 to - // t_0+1 with a value of 3. - // 6. A request is received, the system measures 1 request. - // 7. A request is received, the system measures 1 request. - // 8. The 1 second collection cycle ends. A metric is exported for the - // number of requests received over the interval of time t_0 to - // t_0+2 with a value of 5. - // 9. The system experiences a fault and loses state. - // 10. The system recovers and resumes receiving at time=t_1. - // 11. A request is received, the system measures 1 request. - // 12. The 1 second collection cycle ends. A metric is exported for the - // number of requests received over the interval of time t_1 to - // t_0+1 with a value of 1. - // - // Note: Even though, when reporting changes since last report time, using - // CUMULATIVE is valid, it is not recommended. This may cause problems for - // systems that do not use start_time to determine when the aggregation - // value was reset (e.g. Prometheus). - AggregationTemporality_AGGREGATION_TEMPORALITY_CUMULATIVE AggregationTemporality = 2 -) - -// Enum value maps for AggregationTemporality. -var ( - AggregationTemporality_name = map[int32]string{ - 0: "AGGREGATION_TEMPORALITY_UNSPECIFIED", - 1: "AGGREGATION_TEMPORALITY_DELTA", - 2: "AGGREGATION_TEMPORALITY_CUMULATIVE", - } - AggregationTemporality_value = map[string]int32{ - "AGGREGATION_TEMPORALITY_UNSPECIFIED": 0, - "AGGREGATION_TEMPORALITY_DELTA": 1, - "AGGREGATION_TEMPORALITY_CUMULATIVE": 2, - } -) - -func (x AggregationTemporality) Enum() *AggregationTemporality { - p := new(AggregationTemporality) - *p = x - return p -} - -func (x AggregationTemporality) String() string { - return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x)) -} - -func (AggregationTemporality) Descriptor() protoreflect.EnumDescriptor { - return file_opentelemetry_proto_metrics_v1_metrics_proto_enumTypes[0].Descriptor() -} - -func (AggregationTemporality) Type() protoreflect.EnumType { - return &file_opentelemetry_proto_metrics_v1_metrics_proto_enumTypes[0] -} - -func (x AggregationTemporality) Number() protoreflect.EnumNumber { - return protoreflect.EnumNumber(x) -} - -// Deprecated: Use AggregationTemporality.Descriptor instead. -func (AggregationTemporality) EnumDescriptor() ([]byte, []int) { - return file_opentelemetry_proto_metrics_v1_metrics_proto_rawDescGZIP(), []int{0} -} - -// A collection of InstrumentationLibraryMetrics from a Resource. -type ResourceMetrics struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - // The resource for the metrics in this message. - // If this field is not set then no resource info is known. - Resource *v1.Resource `protobuf:"bytes,1,opt,name=resource,proto3" json:"resource,omitempty"` - // A list of metrics that originate from a resource. - InstrumentationLibraryMetrics []*InstrumentationLibraryMetrics `protobuf:"bytes,2,rep,name=instrumentation_library_metrics,json=instrumentationLibraryMetrics,proto3" json:"instrumentation_library_metrics,omitempty"` -} - -func (x *ResourceMetrics) Reset() { - *x = ResourceMetrics{} - if protoimpl.UnsafeEnabled { - mi := &file_opentelemetry_proto_metrics_v1_metrics_proto_msgTypes[0] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *ResourceMetrics) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*ResourceMetrics) ProtoMessage() {} - -func (x *ResourceMetrics) ProtoReflect() protoreflect.Message { - mi := &file_opentelemetry_proto_metrics_v1_metrics_proto_msgTypes[0] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use ResourceMetrics.ProtoReflect.Descriptor instead. -func (*ResourceMetrics) Descriptor() ([]byte, []int) { - return file_opentelemetry_proto_metrics_v1_metrics_proto_rawDescGZIP(), []int{0} -} - -func (x *ResourceMetrics) GetResource() *v1.Resource { - if x != nil { - return x.Resource - } - return nil -} - -func (x *ResourceMetrics) GetInstrumentationLibraryMetrics() []*InstrumentationLibraryMetrics { - if x != nil { - return x.InstrumentationLibraryMetrics - } - return nil -} - -// A collection of Metrics produced by an InstrumentationLibrary. -type InstrumentationLibraryMetrics struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - // The instrumentation library information for the metrics in this message. - // Semantically when InstrumentationLibrary isn't set, it is equivalent with - // an empty instrumentation library name (unknown). - InstrumentationLibrary *v11.InstrumentationLibrary `protobuf:"bytes,1,opt,name=instrumentation_library,json=instrumentationLibrary,proto3" json:"instrumentation_library,omitempty"` - // A list of metrics that originate from an instrumentation library. - Metrics []*Metric `protobuf:"bytes,2,rep,name=metrics,proto3" json:"metrics,omitempty"` -} - -func (x *InstrumentationLibraryMetrics) Reset() { - *x = InstrumentationLibraryMetrics{} - if protoimpl.UnsafeEnabled { - mi := &file_opentelemetry_proto_metrics_v1_metrics_proto_msgTypes[1] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *InstrumentationLibraryMetrics) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*InstrumentationLibraryMetrics) ProtoMessage() {} - -func (x *InstrumentationLibraryMetrics) ProtoReflect() protoreflect.Message { - mi := &file_opentelemetry_proto_metrics_v1_metrics_proto_msgTypes[1] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use InstrumentationLibraryMetrics.ProtoReflect.Descriptor instead. -func (*InstrumentationLibraryMetrics) Descriptor() ([]byte, []int) { - return file_opentelemetry_proto_metrics_v1_metrics_proto_rawDescGZIP(), []int{1} -} - -func (x *InstrumentationLibraryMetrics) GetInstrumentationLibrary() *v11.InstrumentationLibrary { - if x != nil { - return x.InstrumentationLibrary - } - return nil -} - -func (x *InstrumentationLibraryMetrics) GetMetrics() []*Metric { - if x != nil { - return x.Metrics - } - return nil -} - -// Defines a Metric which has one or more timeseries. -// -// The data model and relation between entities is shown in the -// diagram below. Here, "DataPoint" is the term used to refer to any -// one of the specific data point value types, and "points" is the term used -// to refer to any one of the lists of points contained in the Metric. -// -// - Metric is composed of a metadata and data. -// - Metadata part contains a name, description, unit. -// - Data is one of the possible types (Gauge, Sum, Histogram, etc.). -// - DataPoint contains timestamps, labels, and one of the possible value type -// fields. -// -// Metric -// +------------+ -// |name | -// |description | -// |unit | +------------------------------------+ -// |data |---> |Gauge, Sum, Histogram, Summary, ... | -// +------------+ +------------------------------------+ -// -// Data [One of Gauge, Sum, Histogram, Summary, ...] -// +-----------+ -// |... | // Metadata about the Data. -// |points |--+ -// +-----------+ | -// | +---------------------------+ -// | |DataPoint 1 | -// v |+------+------+ +------+ | -// +-----+ ||label |label |...|label | | -// | 1 |-->||value1|value2|...|valueN| | -// +-----+ |+------+------+ +------+ | -// | . | |+-----+ | -// | . | ||value| | -// | . | |+-----+ | -// | . | +---------------------------+ -// | . | . -// | . | . -// | . | . -// | . | +---------------------------+ -// | . | |DataPoint M | -// +-----+ |+------+------+ +------+ | -// | M |-->||label |label |...|label | | -// +-----+ ||value1|value2|...|valueN| | -// |+------+------+ +------+ | -// |+-----+ | -// ||value| | -// |+-----+ | -// +---------------------------+ -// -// All DataPoint types have three common fields: -// - Labels zero or more key-value pairs associated with the data point. -// - StartTimeUnixNano MUST be set to the start of the interval when the data's -// type includes an AggregationTemporality. This field is not set otherwise. -// - TimeUnixNano MUST be set to: -// - the moment when an aggregation is reported (independent of the -// aggregation temporality). -// - the instantaneous time of the event. -type Metric struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - // name of the metric, including its DNS name prefix. It must be unique. - Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` - // description of the metric, which can be used in documentation. - Description string `protobuf:"bytes,2,opt,name=description,proto3" json:"description,omitempty"` - // unit in which the metric value is reported. Follows the format - // described by http://unitsofmeasure.org/ucum.html. - Unit string `protobuf:"bytes,3,opt,name=unit,proto3" json:"unit,omitempty"` - // Data determines the aggregation type (if any) of the metric, what is the - // reported value type for the data points, as well as the relatationship to - // the time interval over which they are reported. - // - // TODO: Update table after the decision on: - // https://github.com/open-telemetry/opentelemetry-specification/issues/731. - // By default, metrics recording using the OpenTelemetry API are exported as - // (the table does not include MeasurementValueType to avoid extra rows): - // - // Instrument Type - // ---------------------------------------------- - // Counter Sum(aggregation_temporality=delta;is_monotonic=true) - // UpDownCounter Sum(aggregation_temporality=delta;is_monotonic=false) - // ValueRecorder TBD - // SumObserver Sum(aggregation_temporality=cumulative;is_monotonic=true) - // UpDownSumObserver Sum(aggregation_temporality=cumulative;is_monotonic=false) - // ValueObserver Gauge() - // - // Types that are assignable to Data: - // *Metric_IntGauge - // *Metric_DoubleGauge - // *Metric_IntSum - // *Metric_DoubleSum - // *Metric_IntHistogram - // *Metric_DoubleHistogram - // *Metric_DoubleSummary - Data isMetric_Data `protobuf_oneof:"data"` -} - -func (x *Metric) Reset() { - *x = Metric{} - if protoimpl.UnsafeEnabled { - mi := &file_opentelemetry_proto_metrics_v1_metrics_proto_msgTypes[2] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *Metric) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*Metric) ProtoMessage() {} - -func (x *Metric) ProtoReflect() protoreflect.Message { - mi := &file_opentelemetry_proto_metrics_v1_metrics_proto_msgTypes[2] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use Metric.ProtoReflect.Descriptor instead. -func (*Metric) Descriptor() ([]byte, []int) { - return file_opentelemetry_proto_metrics_v1_metrics_proto_rawDescGZIP(), []int{2} -} - -func (x *Metric) GetName() string { - if x != nil { - return x.Name - } - return "" -} - -func (x *Metric) GetDescription() string { - if x != nil { - return x.Description - } - return "" -} - -func (x *Metric) GetUnit() string { - if x != nil { - return x.Unit - } - return "" -} - -func (m *Metric) GetData() isMetric_Data { - if m != nil { - return m.Data - } - return nil -} - -func (x *Metric) GetIntGauge() *IntGauge { - if x, ok := x.GetData().(*Metric_IntGauge); ok { - return x.IntGauge - } - return nil -} - -func (x *Metric) GetDoubleGauge() *DoubleGauge { - if x, ok := x.GetData().(*Metric_DoubleGauge); ok { - return x.DoubleGauge - } - return nil -} - -func (x *Metric) GetIntSum() *IntSum { - if x, ok := x.GetData().(*Metric_IntSum); ok { - return x.IntSum - } - return nil -} - -func (x *Metric) GetDoubleSum() *DoubleSum { - if x, ok := x.GetData().(*Metric_DoubleSum); ok { - return x.DoubleSum - } - return nil -} - -func (x *Metric) GetIntHistogram() *IntHistogram { - if x, ok := x.GetData().(*Metric_IntHistogram); ok { - return x.IntHistogram - } - return nil -} - -func (x *Metric) GetDoubleHistogram() *DoubleHistogram { - if x, ok := x.GetData().(*Metric_DoubleHistogram); ok { - return x.DoubleHistogram - } - return nil -} - -func (x *Metric) GetDoubleSummary() *DoubleSummary { - if x, ok := x.GetData().(*Metric_DoubleSummary); ok { - return x.DoubleSummary - } - return nil -} - -type isMetric_Data interface { - isMetric_Data() -} - -type Metric_IntGauge struct { - IntGauge *IntGauge `protobuf:"bytes,4,opt,name=int_gauge,json=intGauge,proto3,oneof"` -} - -type Metric_DoubleGauge struct { - DoubleGauge *DoubleGauge `protobuf:"bytes,5,opt,name=double_gauge,json=doubleGauge,proto3,oneof"` -} - -type Metric_IntSum struct { - IntSum *IntSum `protobuf:"bytes,6,opt,name=int_sum,json=intSum,proto3,oneof"` -} - -type Metric_DoubleSum struct { - DoubleSum *DoubleSum `protobuf:"bytes,7,opt,name=double_sum,json=doubleSum,proto3,oneof"` -} - -type Metric_IntHistogram struct { - IntHistogram *IntHistogram `protobuf:"bytes,8,opt,name=int_histogram,json=intHistogram,proto3,oneof"` -} - -type Metric_DoubleHistogram struct { - DoubleHistogram *DoubleHistogram `protobuf:"bytes,9,opt,name=double_histogram,json=doubleHistogram,proto3,oneof"` -} - -type Metric_DoubleSummary struct { - DoubleSummary *DoubleSummary `protobuf:"bytes,11,opt,name=double_summary,json=doubleSummary,proto3,oneof"` -} - -func (*Metric_IntGauge) isMetric_Data() {} - -func (*Metric_DoubleGauge) isMetric_Data() {} - -func (*Metric_IntSum) isMetric_Data() {} - -func (*Metric_DoubleSum) isMetric_Data() {} - -func (*Metric_IntHistogram) isMetric_Data() {} - -func (*Metric_DoubleHistogram) isMetric_Data() {} - -func (*Metric_DoubleSummary) isMetric_Data() {} - -// Gauge represents the type of a int scalar metric that always exports the -// "current value" for every data point. It should be used for an "unknown" -// aggregation. -// -// A Gauge does not support different aggregation temporalities. Given the -// aggregation is unknown, points cannot be combined using the same -// aggregation, regardless of aggregation temporalities. Therefore, -// AggregationTemporality is not included. Consequently, this also means -// "StartTimeUnixNano" is ignored for all data points. -type IntGauge struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - DataPoints []*IntDataPoint `protobuf:"bytes,1,rep,name=data_points,json=dataPoints,proto3" json:"data_points,omitempty"` -} - -func (x *IntGauge) Reset() { - *x = IntGauge{} - if protoimpl.UnsafeEnabled { - mi := &file_opentelemetry_proto_metrics_v1_metrics_proto_msgTypes[3] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *IntGauge) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*IntGauge) ProtoMessage() {} - -func (x *IntGauge) ProtoReflect() protoreflect.Message { - mi := &file_opentelemetry_proto_metrics_v1_metrics_proto_msgTypes[3] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use IntGauge.ProtoReflect.Descriptor instead. -func (*IntGauge) Descriptor() ([]byte, []int) { - return file_opentelemetry_proto_metrics_v1_metrics_proto_rawDescGZIP(), []int{3} -} - -func (x *IntGauge) GetDataPoints() []*IntDataPoint { - if x != nil { - return x.DataPoints - } - return nil -} - -// Gauge represents the type of a double scalar metric that always exports the -// "current value" for every data point. It should be used for an "unknown" -// aggregation. -// -// A Gauge does not support different aggregation temporalities. Given the -// aggregation is unknown, points cannot be combined using the same -// aggregation, regardless of aggregation temporalities. Therefore, -// AggregationTemporality is not included. Consequently, this also means -// "StartTimeUnixNano" is ignored for all data points. -type DoubleGauge struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - DataPoints []*DoubleDataPoint `protobuf:"bytes,1,rep,name=data_points,json=dataPoints,proto3" json:"data_points,omitempty"` -} - -func (x *DoubleGauge) Reset() { - *x = DoubleGauge{} - if protoimpl.UnsafeEnabled { - mi := &file_opentelemetry_proto_metrics_v1_metrics_proto_msgTypes[4] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *DoubleGauge) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*DoubleGauge) ProtoMessage() {} - -func (x *DoubleGauge) ProtoReflect() protoreflect.Message { - mi := &file_opentelemetry_proto_metrics_v1_metrics_proto_msgTypes[4] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use DoubleGauge.ProtoReflect.Descriptor instead. -func (*DoubleGauge) Descriptor() ([]byte, []int) { - return file_opentelemetry_proto_metrics_v1_metrics_proto_rawDescGZIP(), []int{4} -} - -func (x *DoubleGauge) GetDataPoints() []*DoubleDataPoint { - if x != nil { - return x.DataPoints - } - return nil -} - -// Sum represents the type of a numeric int scalar metric that is calculated as -// a sum of all reported measurements over a time interval. -type IntSum struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - DataPoints []*IntDataPoint `protobuf:"bytes,1,rep,name=data_points,json=dataPoints,proto3" json:"data_points,omitempty"` - // aggregation_temporality describes if the aggregator reports delta changes - // since last report time, or cumulative changes since a fixed start time. - AggregationTemporality AggregationTemporality `protobuf:"varint,2,opt,name=aggregation_temporality,json=aggregationTemporality,proto3,enum=opentelemetry.proto.metrics.v1.AggregationTemporality" json:"aggregation_temporality,omitempty"` - // If "true" means that the sum is monotonic. - IsMonotonic bool `protobuf:"varint,3,opt,name=is_monotonic,json=isMonotonic,proto3" json:"is_monotonic,omitempty"` -} - -func (x *IntSum) Reset() { - *x = IntSum{} - if protoimpl.UnsafeEnabled { - mi := &file_opentelemetry_proto_metrics_v1_metrics_proto_msgTypes[5] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *IntSum) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*IntSum) ProtoMessage() {} - -func (x *IntSum) ProtoReflect() protoreflect.Message { - mi := &file_opentelemetry_proto_metrics_v1_metrics_proto_msgTypes[5] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use IntSum.ProtoReflect.Descriptor instead. -func (*IntSum) Descriptor() ([]byte, []int) { - return file_opentelemetry_proto_metrics_v1_metrics_proto_rawDescGZIP(), []int{5} -} - -func (x *IntSum) GetDataPoints() []*IntDataPoint { - if x != nil { - return x.DataPoints - } - return nil -} - -func (x *IntSum) GetAggregationTemporality() AggregationTemporality { - if x != nil { - return x.AggregationTemporality - } - return AggregationTemporality_AGGREGATION_TEMPORALITY_UNSPECIFIED -} - -func (x *IntSum) GetIsMonotonic() bool { - if x != nil { - return x.IsMonotonic - } - return false -} - -// Sum represents the type of a numeric double scalar metric that is calculated -// as a sum of all reported measurements over a time interval. -type DoubleSum struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - DataPoints []*DoubleDataPoint `protobuf:"bytes,1,rep,name=data_points,json=dataPoints,proto3" json:"data_points,omitempty"` - // aggregation_temporality describes if the aggregator reports delta changes - // since last report time, or cumulative changes since a fixed start time. - AggregationTemporality AggregationTemporality `protobuf:"varint,2,opt,name=aggregation_temporality,json=aggregationTemporality,proto3,enum=opentelemetry.proto.metrics.v1.AggregationTemporality" json:"aggregation_temporality,omitempty"` - // If "true" means that the sum is monotonic. - IsMonotonic bool `protobuf:"varint,3,opt,name=is_monotonic,json=isMonotonic,proto3" json:"is_monotonic,omitempty"` -} - -func (x *DoubleSum) Reset() { - *x = DoubleSum{} - if protoimpl.UnsafeEnabled { - mi := &file_opentelemetry_proto_metrics_v1_metrics_proto_msgTypes[6] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *DoubleSum) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*DoubleSum) ProtoMessage() {} - -func (x *DoubleSum) ProtoReflect() protoreflect.Message { - mi := &file_opentelemetry_proto_metrics_v1_metrics_proto_msgTypes[6] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use DoubleSum.ProtoReflect.Descriptor instead. -func (*DoubleSum) Descriptor() ([]byte, []int) { - return file_opentelemetry_proto_metrics_v1_metrics_proto_rawDescGZIP(), []int{6} -} - -func (x *DoubleSum) GetDataPoints() []*DoubleDataPoint { - if x != nil { - return x.DataPoints - } - return nil -} - -func (x *DoubleSum) GetAggregationTemporality() AggregationTemporality { - if x != nil { - return x.AggregationTemporality - } - return AggregationTemporality_AGGREGATION_TEMPORALITY_UNSPECIFIED -} - -func (x *DoubleSum) GetIsMonotonic() bool { - if x != nil { - return x.IsMonotonic - } - return false -} - -// Represents the type of a metric that is calculated by aggregating as a -// Histogram of all reported int measurements over a time interval. -type IntHistogram struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - DataPoints []*IntHistogramDataPoint `protobuf:"bytes,1,rep,name=data_points,json=dataPoints,proto3" json:"data_points,omitempty"` - // aggregation_temporality describes if the aggregator reports delta changes - // since last report time, or cumulative changes since a fixed start time. - AggregationTemporality AggregationTemporality `protobuf:"varint,2,opt,name=aggregation_temporality,json=aggregationTemporality,proto3,enum=opentelemetry.proto.metrics.v1.AggregationTemporality" json:"aggregation_temporality,omitempty"` -} - -func (x *IntHistogram) Reset() { - *x = IntHistogram{} - if protoimpl.UnsafeEnabled { - mi := &file_opentelemetry_proto_metrics_v1_metrics_proto_msgTypes[7] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *IntHistogram) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*IntHistogram) ProtoMessage() {} - -func (x *IntHistogram) ProtoReflect() protoreflect.Message { - mi := &file_opentelemetry_proto_metrics_v1_metrics_proto_msgTypes[7] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use IntHistogram.ProtoReflect.Descriptor instead. -func (*IntHistogram) Descriptor() ([]byte, []int) { - return file_opentelemetry_proto_metrics_v1_metrics_proto_rawDescGZIP(), []int{7} -} - -func (x *IntHistogram) GetDataPoints() []*IntHistogramDataPoint { - if x != nil { - return x.DataPoints - } - return nil -} - -func (x *IntHistogram) GetAggregationTemporality() AggregationTemporality { - if x != nil { - return x.AggregationTemporality - } - return AggregationTemporality_AGGREGATION_TEMPORALITY_UNSPECIFIED -} - -// Represents the type of a metric that is calculated by aggregating as a -// Histogram of all reported double measurements over a time interval. -type DoubleHistogram struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - DataPoints []*DoubleHistogramDataPoint `protobuf:"bytes,1,rep,name=data_points,json=dataPoints,proto3" json:"data_points,omitempty"` - // aggregation_temporality describes if the aggregator reports delta changes - // since last report time, or cumulative changes since a fixed start time. - AggregationTemporality AggregationTemporality `protobuf:"varint,2,opt,name=aggregation_temporality,json=aggregationTemporality,proto3,enum=opentelemetry.proto.metrics.v1.AggregationTemporality" json:"aggregation_temporality,omitempty"` -} - -func (x *DoubleHistogram) Reset() { - *x = DoubleHistogram{} - if protoimpl.UnsafeEnabled { - mi := &file_opentelemetry_proto_metrics_v1_metrics_proto_msgTypes[8] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *DoubleHistogram) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*DoubleHistogram) ProtoMessage() {} - -func (x *DoubleHistogram) ProtoReflect() protoreflect.Message { - mi := &file_opentelemetry_proto_metrics_v1_metrics_proto_msgTypes[8] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use DoubleHistogram.ProtoReflect.Descriptor instead. -func (*DoubleHistogram) Descriptor() ([]byte, []int) { - return file_opentelemetry_proto_metrics_v1_metrics_proto_rawDescGZIP(), []int{8} -} - -func (x *DoubleHistogram) GetDataPoints() []*DoubleHistogramDataPoint { - if x != nil { - return x.DataPoints - } - return nil -} - -func (x *DoubleHistogram) GetAggregationTemporality() AggregationTemporality { - if x != nil { - return x.AggregationTemporality - } - return AggregationTemporality_AGGREGATION_TEMPORALITY_UNSPECIFIED -} - -// DoubleSummary metric data are used to convey quantile summaries, -// a Prometheus (see: https://prometheus.io/docs/concepts/metric_types/#summary) -// and OpenMetrics (see: https://github.com/OpenObservability/OpenMetrics/blob/4dbf6075567ab43296eed941037c12951faafb92/protos/prometheus.proto#L45) -// data type. These data points cannot always be merged in a meaningful way. -// While they can be useful in some applications, histogram data points are -// recommended for new applications. -type DoubleSummary struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - DataPoints []*DoubleSummaryDataPoint `protobuf:"bytes,1,rep,name=data_points,json=dataPoints,proto3" json:"data_points,omitempty"` -} - -func (x *DoubleSummary) Reset() { - *x = DoubleSummary{} - if protoimpl.UnsafeEnabled { - mi := &file_opentelemetry_proto_metrics_v1_metrics_proto_msgTypes[9] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *DoubleSummary) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*DoubleSummary) ProtoMessage() {} - -func (x *DoubleSummary) ProtoReflect() protoreflect.Message { - mi := &file_opentelemetry_proto_metrics_v1_metrics_proto_msgTypes[9] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use DoubleSummary.ProtoReflect.Descriptor instead. -func (*DoubleSummary) Descriptor() ([]byte, []int) { - return file_opentelemetry_proto_metrics_v1_metrics_proto_rawDescGZIP(), []int{9} -} - -func (x *DoubleSummary) GetDataPoints() []*DoubleSummaryDataPoint { - if x != nil { - return x.DataPoints - } - return nil -} - -// IntDataPoint is a single data point in a timeseries that describes the -// time-varying values of a int64 metric. -type IntDataPoint struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - // The set of labels that uniquely identify this timeseries. - Labels []*v11.StringKeyValue `protobuf:"bytes,1,rep,name=labels,proto3" json:"labels,omitempty"` - // start_time_unix_nano is the last time when the aggregation value was reset - // to "zero". For some metric types this is ignored, see data types for more - // details. - // - // The aggregation value is over the time interval (start_time_unix_nano, - // time_unix_nano]. - // - // Value is UNIX Epoch time in nanoseconds since 00:00:00 UTC on 1 January - // 1970. - // - // Value of 0 indicates that the timestamp is unspecified. In that case the - // timestamp may be decided by the backend. - StartTimeUnixNano uint64 `protobuf:"fixed64,2,opt,name=start_time_unix_nano,json=startTimeUnixNano,proto3" json:"start_time_unix_nano,omitempty"` - // time_unix_nano is the moment when this aggregation value was reported. - // - // Value is UNIX Epoch time in nanoseconds since 00:00:00 UTC on 1 January - // 1970. - TimeUnixNano uint64 `protobuf:"fixed64,3,opt,name=time_unix_nano,json=timeUnixNano,proto3" json:"time_unix_nano,omitempty"` - // value itself. - Value int64 `protobuf:"fixed64,4,opt,name=value,proto3" json:"value,omitempty"` - // (Optional) List of exemplars collected from - // measurements that were used to form the data point - Exemplars []*IntExemplar `protobuf:"bytes,5,rep,name=exemplars,proto3" json:"exemplars,omitempty"` -} - -func (x *IntDataPoint) Reset() { - *x = IntDataPoint{} - if protoimpl.UnsafeEnabled { - mi := &file_opentelemetry_proto_metrics_v1_metrics_proto_msgTypes[10] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *IntDataPoint) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*IntDataPoint) ProtoMessage() {} - -func (x *IntDataPoint) ProtoReflect() protoreflect.Message { - mi := &file_opentelemetry_proto_metrics_v1_metrics_proto_msgTypes[10] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use IntDataPoint.ProtoReflect.Descriptor instead. -func (*IntDataPoint) Descriptor() ([]byte, []int) { - return file_opentelemetry_proto_metrics_v1_metrics_proto_rawDescGZIP(), []int{10} -} - -func (x *IntDataPoint) GetLabels() []*v11.StringKeyValue { - if x != nil { - return x.Labels - } - return nil -} - -func (x *IntDataPoint) GetStartTimeUnixNano() uint64 { - if x != nil { - return x.StartTimeUnixNano - } - return 0 -} - -func (x *IntDataPoint) GetTimeUnixNano() uint64 { - if x != nil { - return x.TimeUnixNano - } - return 0 -} - -func (x *IntDataPoint) GetValue() int64 { - if x != nil { - return x.Value - } - return 0 -} - -func (x *IntDataPoint) GetExemplars() []*IntExemplar { - if x != nil { - return x.Exemplars - } - return nil -} - -// DoubleDataPoint is a single data point in a timeseries that describes the -// time-varying value of a double metric. -type DoubleDataPoint struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - // The set of labels that uniquely identify this timeseries. - Labels []*v11.StringKeyValue `protobuf:"bytes,1,rep,name=labels,proto3" json:"labels,omitempty"` - // start_time_unix_nano is the last time when the aggregation value was reset - // to "zero". For some metric types this is ignored, see data types for more - // details. - // - // The aggregation value is over the time interval (start_time_unix_nano, - // time_unix_nano]. - // - // Value is UNIX Epoch time in nanoseconds since 00:00:00 UTC on 1 January - // 1970. - // - // Value of 0 indicates that the timestamp is unspecified. In that case the - // timestamp may be decided by the backend. - StartTimeUnixNano uint64 `protobuf:"fixed64,2,opt,name=start_time_unix_nano,json=startTimeUnixNano,proto3" json:"start_time_unix_nano,omitempty"` - // time_unix_nano is the moment when this aggregation value was reported. - // - // Value is UNIX Epoch time in nanoseconds since 00:00:00 UTC on 1 January - // 1970. - TimeUnixNano uint64 `protobuf:"fixed64,3,opt,name=time_unix_nano,json=timeUnixNano,proto3" json:"time_unix_nano,omitempty"` - // value itself. - Value float64 `protobuf:"fixed64,4,opt,name=value,proto3" json:"value,omitempty"` - // (Optional) List of exemplars collected from - // measurements that were used to form the data point - Exemplars []*DoubleExemplar `protobuf:"bytes,5,rep,name=exemplars,proto3" json:"exemplars,omitempty"` -} - -func (x *DoubleDataPoint) Reset() { - *x = DoubleDataPoint{} - if protoimpl.UnsafeEnabled { - mi := &file_opentelemetry_proto_metrics_v1_metrics_proto_msgTypes[11] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *DoubleDataPoint) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*DoubleDataPoint) ProtoMessage() {} - -func (x *DoubleDataPoint) ProtoReflect() protoreflect.Message { - mi := &file_opentelemetry_proto_metrics_v1_metrics_proto_msgTypes[11] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use DoubleDataPoint.ProtoReflect.Descriptor instead. -func (*DoubleDataPoint) Descriptor() ([]byte, []int) { - return file_opentelemetry_proto_metrics_v1_metrics_proto_rawDescGZIP(), []int{11} -} - -func (x *DoubleDataPoint) GetLabels() []*v11.StringKeyValue { - if x != nil { - return x.Labels - } - return nil -} - -func (x *DoubleDataPoint) GetStartTimeUnixNano() uint64 { - if x != nil { - return x.StartTimeUnixNano - } - return 0 -} - -func (x *DoubleDataPoint) GetTimeUnixNano() uint64 { - if x != nil { - return x.TimeUnixNano - } - return 0 -} - -func (x *DoubleDataPoint) GetValue() float64 { - if x != nil { - return x.Value - } - return 0 -} - -func (x *DoubleDataPoint) GetExemplars() []*DoubleExemplar { - if x != nil { - return x.Exemplars - } - return nil -} - -// IntHistogramDataPoint is a single data point in a timeseries that describes -// the time-varying values of a Histogram of int values. A Histogram contains -// summary statistics for a population of values, it may optionally contain -// the distribution of those values across a set of buckets. -type IntHistogramDataPoint struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - // The set of labels that uniquely identify this timeseries. - Labels []*v11.StringKeyValue `protobuf:"bytes,1,rep,name=labels,proto3" json:"labels,omitempty"` - // start_time_unix_nano is the last time when the aggregation value was reset - // to "zero". For some metric types this is ignored, see data types for more - // details. - // - // The aggregation value is over the time interval (start_time_unix_nano, - // time_unix_nano]. - // - // Value is UNIX Epoch time in nanoseconds since 00:00:00 UTC on 1 January - // 1970. - // - // Value of 0 indicates that the timestamp is unspecified. In that case the - // timestamp may be decided by the backend. - StartTimeUnixNano uint64 `protobuf:"fixed64,2,opt,name=start_time_unix_nano,json=startTimeUnixNano,proto3" json:"start_time_unix_nano,omitempty"` - // time_unix_nano is the moment when this aggregation value was reported. - // - // Value is UNIX Epoch time in nanoseconds since 00:00:00 UTC on 1 January - // 1970. - TimeUnixNano uint64 `protobuf:"fixed64,3,opt,name=time_unix_nano,json=timeUnixNano,proto3" json:"time_unix_nano,omitempty"` - // count is the number of values in the population. Must be non-negative. This - // value must be equal to the sum of the "count" fields in buckets if a - // histogram is provided. - Count uint64 `protobuf:"fixed64,4,opt,name=count,proto3" json:"count,omitempty"` - // sum of the values in the population. If count is zero then this field - // must be zero. This value must be equal to the sum of the "sum" fields in - // buckets if a histogram is provided. - Sum int64 `protobuf:"fixed64,5,opt,name=sum,proto3" json:"sum,omitempty"` - // bucket_counts is an optional field contains the count values of histogram - // for each bucket. - // - // The sum of the bucket_counts must equal the value in the count field. - // - // The number of elements in bucket_counts array must be by one greater than - // the number of elements in explicit_bounds array. - BucketCounts []uint64 `protobuf:"fixed64,6,rep,packed,name=bucket_counts,json=bucketCounts,proto3" json:"bucket_counts,omitempty"` - // explicit_bounds specifies buckets with explicitly defined bounds for values. - // The bucket boundaries are described by "bounds" field. - // - // This defines size(bounds) + 1 (= N) buckets. The boundaries for bucket - // at index i are: - // - // (-infinity, bounds[i]) for i == 0 - // [bounds[i-1], bounds[i]) for 0 < i < N-1 - // [bounds[i], +infinity) for i == N-1 - // The values in bounds array must be strictly increasing. - // - // Note: only [a, b) intervals are currently supported for each bucket except the first one. - // If we decide to also support (a, b] intervals we should add support for these by defining - // a boolean value which decides what type of intervals to use. - ExplicitBounds []float64 `protobuf:"fixed64,7,rep,packed,name=explicit_bounds,json=explicitBounds,proto3" json:"explicit_bounds,omitempty"` - // (Optional) List of exemplars collected from - // measurements that were used to form the data point - Exemplars []*IntExemplar `protobuf:"bytes,8,rep,name=exemplars,proto3" json:"exemplars,omitempty"` -} - -func (x *IntHistogramDataPoint) Reset() { - *x = IntHistogramDataPoint{} - if protoimpl.UnsafeEnabled { - mi := &file_opentelemetry_proto_metrics_v1_metrics_proto_msgTypes[12] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *IntHistogramDataPoint) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*IntHistogramDataPoint) ProtoMessage() {} - -func (x *IntHistogramDataPoint) ProtoReflect() protoreflect.Message { - mi := &file_opentelemetry_proto_metrics_v1_metrics_proto_msgTypes[12] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use IntHistogramDataPoint.ProtoReflect.Descriptor instead. -func (*IntHistogramDataPoint) Descriptor() ([]byte, []int) { - return file_opentelemetry_proto_metrics_v1_metrics_proto_rawDescGZIP(), []int{12} -} - -func (x *IntHistogramDataPoint) GetLabels() []*v11.StringKeyValue { - if x != nil { - return x.Labels - } - return nil -} - -func (x *IntHistogramDataPoint) GetStartTimeUnixNano() uint64 { - if x != nil { - return x.StartTimeUnixNano - } - return 0 -} - -func (x *IntHistogramDataPoint) GetTimeUnixNano() uint64 { - if x != nil { - return x.TimeUnixNano - } - return 0 -} - -func (x *IntHistogramDataPoint) GetCount() uint64 { - if x != nil { - return x.Count - } - return 0 -} - -func (x *IntHistogramDataPoint) GetSum() int64 { - if x != nil { - return x.Sum - } - return 0 -} - -func (x *IntHistogramDataPoint) GetBucketCounts() []uint64 { - if x != nil { - return x.BucketCounts - } - return nil -} - -func (x *IntHistogramDataPoint) GetExplicitBounds() []float64 { - if x != nil { - return x.ExplicitBounds - } - return nil -} - -func (x *IntHistogramDataPoint) GetExemplars() []*IntExemplar { - if x != nil { - return x.Exemplars - } - return nil -} - -// HistogramDataPoint is a single data point in a timeseries that describes the -// time-varying values of a Histogram of double values. A Histogram contains -// summary statistics for a population of values, it may optionally contain the -// distribution of those values across a set of buckets. -type DoubleHistogramDataPoint struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - // The set of labels that uniquely identify this timeseries. - Labels []*v11.StringKeyValue `protobuf:"bytes,1,rep,name=labels,proto3" json:"labels,omitempty"` - // start_time_unix_nano is the last time when the aggregation value was reset - // to "zero". For some metric types this is ignored, see data types for more - // details. - // - // The aggregation value is over the time interval (start_time_unix_nano, - // time_unix_nano]. - // - // Value is UNIX Epoch time in nanoseconds since 00:00:00 UTC on 1 January - // 1970. - // - // Value of 0 indicates that the timestamp is unspecified. In that case the - // timestamp may be decided by the backend. - StartTimeUnixNano uint64 `protobuf:"fixed64,2,opt,name=start_time_unix_nano,json=startTimeUnixNano,proto3" json:"start_time_unix_nano,omitempty"` - // time_unix_nano is the moment when this aggregation value was reported. - // - // Value is UNIX Epoch time in nanoseconds since 00:00:00 UTC on 1 January - // 1970. - TimeUnixNano uint64 `protobuf:"fixed64,3,opt,name=time_unix_nano,json=timeUnixNano,proto3" json:"time_unix_nano,omitempty"` - // count is the number of values in the population. Must be non-negative. This - // value must be equal to the sum of the "count" fields in buckets if a - // histogram is provided. - Count uint64 `protobuf:"fixed64,4,opt,name=count,proto3" json:"count,omitempty"` - // sum of the values in the population. If count is zero then this field - // must be zero. This value must be equal to the sum of the "sum" fields in - // buckets if a histogram is provided. - Sum float64 `protobuf:"fixed64,5,opt,name=sum,proto3" json:"sum,omitempty"` - // bucket_counts is an optional field contains the count values of histogram - // for each bucket. - // - // The sum of the bucket_counts must equal the value in the count field. - // - // The number of elements in bucket_counts array must be by one greater than - // the number of elements in explicit_bounds array. - BucketCounts []uint64 `protobuf:"fixed64,6,rep,packed,name=bucket_counts,json=bucketCounts,proto3" json:"bucket_counts,omitempty"` - // explicit_bounds specifies buckets with explicitly defined bounds for values. - // The bucket boundaries are described by "bounds" field. - // - // This defines size(bounds) + 1 (= N) buckets. The boundaries for bucket - // at index i are: - // - // (-infinity, bounds[i]) for i == 0 - // [bounds[i-1], bounds[i]) for 0 < i < N-1 - // [bounds[i], +infinity) for i == N-1 - // The values in bounds array must be strictly increasing. - // - // Note: only [a, b) intervals are currently supported for each bucket except the first one. - // If we decide to also support (a, b] intervals we should add support for these by defining - // a boolean value which decides what type of intervals to use. - ExplicitBounds []float64 `protobuf:"fixed64,7,rep,packed,name=explicit_bounds,json=explicitBounds,proto3" json:"explicit_bounds,omitempty"` - // (Optional) List of exemplars collected from - // measurements that were used to form the data point - Exemplars []*DoubleExemplar `protobuf:"bytes,8,rep,name=exemplars,proto3" json:"exemplars,omitempty"` -} - -func (x *DoubleHistogramDataPoint) Reset() { - *x = DoubleHistogramDataPoint{} - if protoimpl.UnsafeEnabled { - mi := &file_opentelemetry_proto_metrics_v1_metrics_proto_msgTypes[13] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *DoubleHistogramDataPoint) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*DoubleHistogramDataPoint) ProtoMessage() {} - -func (x *DoubleHistogramDataPoint) ProtoReflect() protoreflect.Message { - mi := &file_opentelemetry_proto_metrics_v1_metrics_proto_msgTypes[13] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use DoubleHistogramDataPoint.ProtoReflect.Descriptor instead. -func (*DoubleHistogramDataPoint) Descriptor() ([]byte, []int) { - return file_opentelemetry_proto_metrics_v1_metrics_proto_rawDescGZIP(), []int{13} -} - -func (x *DoubleHistogramDataPoint) GetLabels() []*v11.StringKeyValue { - if x != nil { - return x.Labels - } - return nil -} - -func (x *DoubleHistogramDataPoint) GetStartTimeUnixNano() uint64 { - if x != nil { - return x.StartTimeUnixNano - } - return 0 -} - -func (x *DoubleHistogramDataPoint) GetTimeUnixNano() uint64 { - if x != nil { - return x.TimeUnixNano - } - return 0 -} - -func (x *DoubleHistogramDataPoint) GetCount() uint64 { - if x != nil { - return x.Count - } - return 0 -} - -func (x *DoubleHistogramDataPoint) GetSum() float64 { - if x != nil { - return x.Sum - } - return 0 -} - -func (x *DoubleHistogramDataPoint) GetBucketCounts() []uint64 { - if x != nil { - return x.BucketCounts - } - return nil -} - -func (x *DoubleHistogramDataPoint) GetExplicitBounds() []float64 { - if x != nil { - return x.ExplicitBounds - } - return nil -} - -func (x *DoubleHistogramDataPoint) GetExemplars() []*DoubleExemplar { - if x != nil { - return x.Exemplars - } - return nil -} - -// DoubleSummaryDataPoint is a single data point in a timeseries that describes the -// time-varying values of a Summary metric. -type DoubleSummaryDataPoint struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - // The set of labels that uniquely identify this timeseries. - Labels []*v11.StringKeyValue `protobuf:"bytes,1,rep,name=labels,proto3" json:"labels,omitempty"` - // start_time_unix_nano is the last time when the aggregation value was reset - // to "zero". For some metric types this is ignored, see data types for more - // details. - // - // The aggregation value is over the time interval (start_time_unix_nano, - // time_unix_nano]. - // - // Value is UNIX Epoch time in nanoseconds since 00:00:00 UTC on 1 January - // 1970. - // - // Value of 0 indicates that the timestamp is unspecified. In that case the - // timestamp may be decided by the backend. - StartTimeUnixNano uint64 `protobuf:"fixed64,2,opt,name=start_time_unix_nano,json=startTimeUnixNano,proto3" json:"start_time_unix_nano,omitempty"` - // time_unix_nano is the moment when this aggregation value was reported. - // - // Value is UNIX Epoch time in nanoseconds since 00:00:00 UTC on 1 January - // 1970. - TimeUnixNano uint64 `protobuf:"fixed64,3,opt,name=time_unix_nano,json=timeUnixNano,proto3" json:"time_unix_nano,omitempty"` - // count is the number of values in the population. Must be non-negative. - Count uint64 `protobuf:"fixed64,4,opt,name=count,proto3" json:"count,omitempty"` - // sum of the values in the population. If count is zero then this field - // must be zero. - Sum float64 `protobuf:"fixed64,5,opt,name=sum,proto3" json:"sum,omitempty"` - // (Optional) list of values at different quantiles of the distribution calculated - // from the current snapshot. The quantiles must be strictly increasing. - QuantileValues []*DoubleSummaryDataPoint_ValueAtQuantile `protobuf:"bytes,6,rep,name=quantile_values,json=quantileValues,proto3" json:"quantile_values,omitempty"` -} - -func (x *DoubleSummaryDataPoint) Reset() { - *x = DoubleSummaryDataPoint{} - if protoimpl.UnsafeEnabled { - mi := &file_opentelemetry_proto_metrics_v1_metrics_proto_msgTypes[14] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *DoubleSummaryDataPoint) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*DoubleSummaryDataPoint) ProtoMessage() {} - -func (x *DoubleSummaryDataPoint) ProtoReflect() protoreflect.Message { - mi := &file_opentelemetry_proto_metrics_v1_metrics_proto_msgTypes[14] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use DoubleSummaryDataPoint.ProtoReflect.Descriptor instead. -func (*DoubleSummaryDataPoint) Descriptor() ([]byte, []int) { - return file_opentelemetry_proto_metrics_v1_metrics_proto_rawDescGZIP(), []int{14} -} - -func (x *DoubleSummaryDataPoint) GetLabels() []*v11.StringKeyValue { - if x != nil { - return x.Labels - } - return nil -} - -func (x *DoubleSummaryDataPoint) GetStartTimeUnixNano() uint64 { - if x != nil { - return x.StartTimeUnixNano - } - return 0 -} - -func (x *DoubleSummaryDataPoint) GetTimeUnixNano() uint64 { - if x != nil { - return x.TimeUnixNano - } - return 0 -} - -func (x *DoubleSummaryDataPoint) GetCount() uint64 { - if x != nil { - return x.Count - } - return 0 -} - -func (x *DoubleSummaryDataPoint) GetSum() float64 { - if x != nil { - return x.Sum - } - return 0 -} - -func (x *DoubleSummaryDataPoint) GetQuantileValues() []*DoubleSummaryDataPoint_ValueAtQuantile { - if x != nil { - return x.QuantileValues - } - return nil -} - -// A representation of an exemplar, which is a sample input int measurement. -// Exemplars also hold information about the environment when the measurement -// was recorded, for example the span and trace ID of the active span when the -// exemplar was recorded. -type IntExemplar struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - // The set of labels that were filtered out by the aggregator, but recorded - // alongside the original measurement. Only labels that were filtered out - // by the aggregator should be included - FilteredLabels []*v11.StringKeyValue `protobuf:"bytes,1,rep,name=filtered_labels,json=filteredLabels,proto3" json:"filtered_labels,omitempty"` - // time_unix_nano is the exact time when this exemplar was recorded - // - // Value is UNIX Epoch time in nanoseconds since 00:00:00 UTC on 1 January - // 1970. - TimeUnixNano uint64 `protobuf:"fixed64,2,opt,name=time_unix_nano,json=timeUnixNano,proto3" json:"time_unix_nano,omitempty"` - // Numerical int value of the measurement that was recorded. - Value int64 `protobuf:"fixed64,3,opt,name=value,proto3" json:"value,omitempty"` - // (Optional) Span ID of the exemplar trace. - // span_id may be missing if the measurement is not recorded inside a trace - // or if the trace is not sampled. - SpanId []byte `protobuf:"bytes,4,opt,name=span_id,json=spanId,proto3" json:"span_id,omitempty"` - // (Optional) Trace ID of the exemplar trace. - // trace_id may be missing if the measurement is not recorded inside a trace - // or if the trace is not sampled. - TraceId []byte `protobuf:"bytes,5,opt,name=trace_id,json=traceId,proto3" json:"trace_id,omitempty"` -} - -func (x *IntExemplar) Reset() { - *x = IntExemplar{} - if protoimpl.UnsafeEnabled { - mi := &file_opentelemetry_proto_metrics_v1_metrics_proto_msgTypes[15] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *IntExemplar) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*IntExemplar) ProtoMessage() {} - -func (x *IntExemplar) ProtoReflect() protoreflect.Message { - mi := &file_opentelemetry_proto_metrics_v1_metrics_proto_msgTypes[15] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use IntExemplar.ProtoReflect.Descriptor instead. -func (*IntExemplar) Descriptor() ([]byte, []int) { - return file_opentelemetry_proto_metrics_v1_metrics_proto_rawDescGZIP(), []int{15} -} - -func (x *IntExemplar) GetFilteredLabels() []*v11.StringKeyValue { - if x != nil { - return x.FilteredLabels - } - return nil -} - -func (x *IntExemplar) GetTimeUnixNano() uint64 { - if x != nil { - return x.TimeUnixNano - } - return 0 -} - -func (x *IntExemplar) GetValue() int64 { - if x != nil { - return x.Value - } - return 0 -} - -func (x *IntExemplar) GetSpanId() []byte { - if x != nil { - return x.SpanId - } - return nil -} - -func (x *IntExemplar) GetTraceId() []byte { - if x != nil { - return x.TraceId - } - return nil -} - -// A representation of an exemplar, which is a sample input double measurement. -// Exemplars also hold information about the environment when the measurement -// was recorded, for example the span and trace ID of the active span when the -// exemplar was recorded. -type DoubleExemplar struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - // The set of labels that were filtered out by the aggregator, but recorded - // alongside the original measurement. Only labels that were filtered out - // by the aggregator should be included - FilteredLabels []*v11.StringKeyValue `protobuf:"bytes,1,rep,name=filtered_labels,json=filteredLabels,proto3" json:"filtered_labels,omitempty"` - // time_unix_nano is the exact time when this exemplar was recorded - // - // Value is UNIX Epoch time in nanoseconds since 00:00:00 UTC on 1 January - // 1970. - TimeUnixNano uint64 `protobuf:"fixed64,2,opt,name=time_unix_nano,json=timeUnixNano,proto3" json:"time_unix_nano,omitempty"` - // Numerical double value of the measurement that was recorded. - Value float64 `protobuf:"fixed64,3,opt,name=value,proto3" json:"value,omitempty"` - // (Optional) Span ID of the exemplar trace. - // span_id may be missing if the measurement is not recorded inside a trace - // or if the trace is not sampled. - SpanId []byte `protobuf:"bytes,4,opt,name=span_id,json=spanId,proto3" json:"span_id,omitempty"` - // (Optional) Trace ID of the exemplar trace. - // trace_id may be missing if the measurement is not recorded inside a trace - // or if the trace is not sampled. - TraceId []byte `protobuf:"bytes,5,opt,name=trace_id,json=traceId,proto3" json:"trace_id,omitempty"` -} - -func (x *DoubleExemplar) Reset() { - *x = DoubleExemplar{} - if protoimpl.UnsafeEnabled { - mi := &file_opentelemetry_proto_metrics_v1_metrics_proto_msgTypes[16] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *DoubleExemplar) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*DoubleExemplar) ProtoMessage() {} - -func (x *DoubleExemplar) ProtoReflect() protoreflect.Message { - mi := &file_opentelemetry_proto_metrics_v1_metrics_proto_msgTypes[16] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use DoubleExemplar.ProtoReflect.Descriptor instead. -func (*DoubleExemplar) Descriptor() ([]byte, []int) { - return file_opentelemetry_proto_metrics_v1_metrics_proto_rawDescGZIP(), []int{16} -} - -func (x *DoubleExemplar) GetFilteredLabels() []*v11.StringKeyValue { - if x != nil { - return x.FilteredLabels - } - return nil -} - -func (x *DoubleExemplar) GetTimeUnixNano() uint64 { - if x != nil { - return x.TimeUnixNano - } - return 0 -} - -func (x *DoubleExemplar) GetValue() float64 { - if x != nil { - return x.Value - } - return 0 -} - -func (x *DoubleExemplar) GetSpanId() []byte { - if x != nil { - return x.SpanId - } - return nil -} - -func (x *DoubleExemplar) GetTraceId() []byte { - if x != nil { - return x.TraceId - } - return nil -} - -// Represents the value at a given quantile of a distribution. -// -// To record Min and Max values following conventions are used: -// - The 1.0 quantile is equivalent to the maximum value observed. -// - The 0.0 quantile is equivalent to the minimum value observed. -// -// See the following issue for more context: -// https://github.com/open-telemetry/opentelemetry-proto/issues/125 -type DoubleSummaryDataPoint_ValueAtQuantile struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - // The quantile of a distribution. Must be in the interval - // [0.0, 1.0]. - Quantile float64 `protobuf:"fixed64,1,opt,name=quantile,proto3" json:"quantile,omitempty"` - // The value at the given quantile of a distribution. - Value float64 `protobuf:"fixed64,2,opt,name=value,proto3" json:"value,omitempty"` -} - -func (x *DoubleSummaryDataPoint_ValueAtQuantile) Reset() { - *x = DoubleSummaryDataPoint_ValueAtQuantile{} - if protoimpl.UnsafeEnabled { - mi := &file_opentelemetry_proto_metrics_v1_metrics_proto_msgTypes[17] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *DoubleSummaryDataPoint_ValueAtQuantile) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*DoubleSummaryDataPoint_ValueAtQuantile) ProtoMessage() {} - -func (x *DoubleSummaryDataPoint_ValueAtQuantile) ProtoReflect() protoreflect.Message { - mi := &file_opentelemetry_proto_metrics_v1_metrics_proto_msgTypes[17] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use DoubleSummaryDataPoint_ValueAtQuantile.ProtoReflect.Descriptor instead. -func (*DoubleSummaryDataPoint_ValueAtQuantile) Descriptor() ([]byte, []int) { - return file_opentelemetry_proto_metrics_v1_metrics_proto_rawDescGZIP(), []int{14, 0} -} - -func (x *DoubleSummaryDataPoint_ValueAtQuantile) GetQuantile() float64 { - if x != nil { - return x.Quantile - } - return 0 -} - -func (x *DoubleSummaryDataPoint_ValueAtQuantile) GetValue() float64 { - if x != nil { - return x.Value - } - return 0 -} - -var File_opentelemetry_proto_metrics_v1_metrics_proto protoreflect.FileDescriptor - -var file_opentelemetry_proto_metrics_v1_metrics_proto_rawDesc = []byte{ - 0x0a, 0x2c, 0x6f, 0x70, 0x65, 0x6e, 0x74, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x74, 0x72, 0x79, 0x2f, - 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x6d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x73, 0x2f, 0x76, 0x31, - 0x2f, 0x6d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x1e, - 0x6f, 0x70, 0x65, 0x6e, 0x74, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x74, 0x72, 0x79, 0x2e, 0x70, 0x72, - 0x6f, 0x74, 0x6f, 0x2e, 0x6d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x73, 0x2e, 0x76, 0x31, 0x1a, 0x2a, - 0x6f, 0x70, 0x65, 0x6e, 0x74, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x74, 0x72, 0x79, 0x2f, 0x70, 0x72, - 0x6f, 0x74, 0x6f, 0x2f, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2f, 0x76, 0x31, 0x2f, 0x63, 0x6f, - 0x6d, 0x6d, 0x6f, 0x6e, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x2e, 0x6f, 0x70, 0x65, 0x6e, - 0x74, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x74, 0x72, 0x79, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, - 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x2f, 0x76, 0x31, 0x2f, 0x72, 0x65, 0x73, 0x6f, - 0x75, 0x72, 0x63, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xe0, 0x01, 0x0a, 0x0f, 0x52, - 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x4d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x73, 0x12, 0x45, - 0x0a, 0x08, 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, - 0x32, 0x29, 0x2e, 0x6f, 0x70, 0x65, 0x6e, 0x74, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x74, 0x72, 0x79, - 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x2e, - 0x76, 0x31, 0x2e, 0x52, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x52, 0x08, 0x72, 0x65, 0x73, - 0x6f, 0x75, 0x72, 0x63, 0x65, 0x12, 0x85, 0x01, 0x0a, 0x1f, 0x69, 0x6e, 0x73, 0x74, 0x72, 0x75, - 0x6d, 0x65, 0x6e, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x6c, 0x69, 0x62, 0x72, 0x61, 0x72, - 0x79, 0x5f, 0x6d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, - 0x3d, 0x2e, 0x6f, 0x70, 0x65, 0x6e, 0x74, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x74, 0x72, 0x79, 0x2e, - 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x6d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x73, 0x2e, 0x76, 0x31, - 0x2e, 0x49, 0x6e, 0x73, 0x74, 0x72, 0x75, 0x6d, 0x65, 0x6e, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, - 0x4c, 0x69, 0x62, 0x72, 0x61, 0x72, 0x79, 0x4d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x73, 0x52, 0x1d, - 0x69, 0x6e, 0x73, 0x74, 0x72, 0x75, 0x6d, 0x65, 0x6e, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x4c, - 0x69, 0x62, 0x72, 0x61, 0x72, 0x79, 0x4d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x73, 0x22, 0xd1, 0x01, - 0x0a, 0x1d, 0x49, 0x6e, 0x73, 0x74, 0x72, 0x75, 0x6d, 0x65, 0x6e, 0x74, 0x61, 0x74, 0x69, 0x6f, - 0x6e, 0x4c, 0x69, 0x62, 0x72, 0x61, 0x72, 0x79, 0x4d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x73, 0x12, - 0x6e, 0x0a, 0x17, 0x69, 0x6e, 0x73, 0x74, 0x72, 0x75, 0x6d, 0x65, 0x6e, 0x74, 0x61, 0x74, 0x69, - 0x6f, 0x6e, 0x5f, 0x6c, 0x69, 0x62, 0x72, 0x61, 0x72, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, - 0x32, 0x35, 0x2e, 0x6f, 0x70, 0x65, 0x6e, 0x74, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x74, 0x72, 0x79, - 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2e, 0x76, 0x31, - 0x2e, 0x49, 0x6e, 0x73, 0x74, 0x72, 0x75, 0x6d, 0x65, 0x6e, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, - 0x4c, 0x69, 0x62, 0x72, 0x61, 0x72, 0x79, 0x52, 0x16, 0x69, 0x6e, 0x73, 0x74, 0x72, 0x75, 0x6d, - 0x65, 0x6e, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x4c, 0x69, 0x62, 0x72, 0x61, 0x72, 0x79, 0x12, - 0x40, 0x0a, 0x07, 0x6d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, - 0x32, 0x26, 0x2e, 0x6f, 0x70, 0x65, 0x6e, 0x74, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x74, 0x72, 0x79, - 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x6d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x73, 0x2e, 0x76, - 0x31, 0x2e, 0x4d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x52, 0x07, 0x6d, 0x65, 0x74, 0x72, 0x69, 0x63, - 0x73, 0x22, 0x8f, 0x05, 0x0a, 0x06, 0x4d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x12, 0x12, 0x0a, 0x04, - 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, - 0x12, 0x20, 0x0a, 0x0b, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x18, - 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, - 0x6f, 0x6e, 0x12, 0x12, 0x0a, 0x04, 0x75, 0x6e, 0x69, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, - 0x52, 0x04, 0x75, 0x6e, 0x69, 0x74, 0x12, 0x47, 0x0a, 0x09, 0x69, 0x6e, 0x74, 0x5f, 0x67, 0x61, - 0x75, 0x67, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x28, 0x2e, 0x6f, 0x70, 0x65, 0x6e, - 0x74, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x74, 0x72, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, - 0x6d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x49, 0x6e, 0x74, 0x47, 0x61, - 0x75, 0x67, 0x65, 0x48, 0x00, 0x52, 0x08, 0x69, 0x6e, 0x74, 0x47, 0x61, 0x75, 0x67, 0x65, 0x12, - 0x50, 0x0a, 0x0c, 0x64, 0x6f, 0x75, 0x62, 0x6c, 0x65, 0x5f, 0x67, 0x61, 0x75, 0x67, 0x65, 0x18, - 0x05, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x2b, 0x2e, 0x6f, 0x70, 0x65, 0x6e, 0x74, 0x65, 0x6c, 0x65, - 0x6d, 0x65, 0x74, 0x72, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x6d, 0x65, 0x74, 0x72, - 0x69, 0x63, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x44, 0x6f, 0x75, 0x62, 0x6c, 0x65, 0x47, 0x61, 0x75, - 0x67, 0x65, 0x48, 0x00, 0x52, 0x0b, 0x64, 0x6f, 0x75, 0x62, 0x6c, 0x65, 0x47, 0x61, 0x75, 0x67, - 0x65, 0x12, 0x41, 0x0a, 0x07, 0x69, 0x6e, 0x74, 0x5f, 0x73, 0x75, 0x6d, 0x18, 0x06, 0x20, 0x01, - 0x28, 0x0b, 0x32, 0x26, 0x2e, 0x6f, 0x70, 0x65, 0x6e, 0x74, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x74, - 0x72, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x6d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x73, - 0x2e, 0x76, 0x31, 0x2e, 0x49, 0x6e, 0x74, 0x53, 0x75, 0x6d, 0x48, 0x00, 0x52, 0x06, 0x69, 0x6e, - 0x74, 0x53, 0x75, 0x6d, 0x12, 0x4a, 0x0a, 0x0a, 0x64, 0x6f, 0x75, 0x62, 0x6c, 0x65, 0x5f, 0x73, - 0x75, 0x6d, 0x18, 0x07, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x29, 0x2e, 0x6f, 0x70, 0x65, 0x6e, 0x74, - 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x74, 0x72, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x6d, - 0x65, 0x74, 0x72, 0x69, 0x63, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x44, 0x6f, 0x75, 0x62, 0x6c, 0x65, - 0x53, 0x75, 0x6d, 0x48, 0x00, 0x52, 0x09, 0x64, 0x6f, 0x75, 0x62, 0x6c, 0x65, 0x53, 0x75, 0x6d, - 0x12, 0x53, 0x0a, 0x0d, 0x69, 0x6e, 0x74, 0x5f, 0x68, 0x69, 0x73, 0x74, 0x6f, 0x67, 0x72, 0x61, - 0x6d, 0x18, 0x08, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x2c, 0x2e, 0x6f, 0x70, 0x65, 0x6e, 0x74, 0x65, - 0x6c, 0x65, 0x6d, 0x65, 0x74, 0x72, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x6d, 0x65, - 0x74, 0x72, 0x69, 0x63, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x49, 0x6e, 0x74, 0x48, 0x69, 0x73, 0x74, - 0x6f, 0x67, 0x72, 0x61, 0x6d, 0x48, 0x00, 0x52, 0x0c, 0x69, 0x6e, 0x74, 0x48, 0x69, 0x73, 0x74, - 0x6f, 0x67, 0x72, 0x61, 0x6d, 0x12, 0x5c, 0x0a, 0x10, 0x64, 0x6f, 0x75, 0x62, 0x6c, 0x65, 0x5f, - 0x68, 0x69, 0x73, 0x74, 0x6f, 0x67, 0x72, 0x61, 0x6d, 0x18, 0x09, 0x20, 0x01, 0x28, 0x0b, 0x32, - 0x2f, 0x2e, 0x6f, 0x70, 0x65, 0x6e, 0x74, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x74, 0x72, 0x79, 0x2e, - 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x6d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x73, 0x2e, 0x76, 0x31, - 0x2e, 0x44, 0x6f, 0x75, 0x62, 0x6c, 0x65, 0x48, 0x69, 0x73, 0x74, 0x6f, 0x67, 0x72, 0x61, 0x6d, - 0x48, 0x00, 0x52, 0x0f, 0x64, 0x6f, 0x75, 0x62, 0x6c, 0x65, 0x48, 0x69, 0x73, 0x74, 0x6f, 0x67, - 0x72, 0x61, 0x6d, 0x12, 0x56, 0x0a, 0x0e, 0x64, 0x6f, 0x75, 0x62, 0x6c, 0x65, 0x5f, 0x73, 0x75, - 0x6d, 0x6d, 0x61, 0x72, 0x79, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x2d, 0x2e, 0x6f, 0x70, - 0x65, 0x6e, 0x74, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x74, 0x72, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, - 0x6f, 0x2e, 0x6d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x44, 0x6f, 0x75, - 0x62, 0x6c, 0x65, 0x53, 0x75, 0x6d, 0x6d, 0x61, 0x72, 0x79, 0x48, 0x00, 0x52, 0x0d, 0x64, 0x6f, - 0x75, 0x62, 0x6c, 0x65, 0x53, 0x75, 0x6d, 0x6d, 0x61, 0x72, 0x79, 0x42, 0x06, 0x0a, 0x04, 0x64, - 0x61, 0x74, 0x61, 0x22, 0x59, 0x0a, 0x08, 0x49, 0x6e, 0x74, 0x47, 0x61, 0x75, 0x67, 0x65, 0x12, - 0x4d, 0x0a, 0x0b, 0x64, 0x61, 0x74, 0x61, 0x5f, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x73, 0x18, 0x01, - 0x20, 0x03, 0x28, 0x0b, 0x32, 0x2c, 0x2e, 0x6f, 0x70, 0x65, 0x6e, 0x74, 0x65, 0x6c, 0x65, 0x6d, - 0x65, 0x74, 0x72, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x6d, 0x65, 0x74, 0x72, 0x69, - 0x63, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x49, 0x6e, 0x74, 0x44, 0x61, 0x74, 0x61, 0x50, 0x6f, 0x69, - 0x6e, 0x74, 0x52, 0x0a, 0x64, 0x61, 0x74, 0x61, 0x50, 0x6f, 0x69, 0x6e, 0x74, 0x73, 0x22, 0x5f, - 0x0a, 0x0b, 0x44, 0x6f, 0x75, 0x62, 0x6c, 0x65, 0x47, 0x61, 0x75, 0x67, 0x65, 0x12, 0x50, 0x0a, - 0x0b, 0x64, 0x61, 0x74, 0x61, 0x5f, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x73, 0x18, 0x01, 0x20, 0x03, - 0x28, 0x0b, 0x32, 0x2f, 0x2e, 0x6f, 0x70, 0x65, 0x6e, 0x74, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x74, - 0x72, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x6d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x73, - 0x2e, 0x76, 0x31, 0x2e, 0x44, 0x6f, 0x75, 0x62, 0x6c, 0x65, 0x44, 0x61, 0x74, 0x61, 0x50, 0x6f, - 0x69, 0x6e, 0x74, 0x52, 0x0a, 0x64, 0x61, 0x74, 0x61, 0x50, 0x6f, 0x69, 0x6e, 0x74, 0x73, 0x22, - 0xeb, 0x01, 0x0a, 0x06, 0x49, 0x6e, 0x74, 0x53, 0x75, 0x6d, 0x12, 0x4d, 0x0a, 0x0b, 0x64, 0x61, - 0x74, 0x61, 0x5f, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, - 0x2c, 0x2e, 0x6f, 0x70, 0x65, 0x6e, 0x74, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x74, 0x72, 0x79, 0x2e, - 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x6d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x73, 0x2e, 0x76, 0x31, - 0x2e, 0x49, 0x6e, 0x74, 0x44, 0x61, 0x74, 0x61, 0x50, 0x6f, 0x69, 0x6e, 0x74, 0x52, 0x0a, 0x64, - 0x61, 0x74, 0x61, 0x50, 0x6f, 0x69, 0x6e, 0x74, 0x73, 0x12, 0x6f, 0x0a, 0x17, 0x61, 0x67, 0x67, - 0x72, 0x65, 0x67, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x74, 0x65, 0x6d, 0x70, 0x6f, 0x72, 0x61, - 0x6c, 0x69, 0x74, 0x79, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x36, 0x2e, 0x6f, 0x70, 0x65, - 0x6e, 0x74, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x74, 0x72, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x2e, 0x6d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x41, 0x67, 0x67, 0x72, - 0x65, 0x67, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x54, 0x65, 0x6d, 0x70, 0x6f, 0x72, 0x61, 0x6c, 0x69, - 0x74, 0x79, 0x52, 0x16, 0x61, 0x67, 0x67, 0x72, 0x65, 0x67, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x54, - 0x65, 0x6d, 0x70, 0x6f, 0x72, 0x61, 0x6c, 0x69, 0x74, 0x79, 0x12, 0x21, 0x0a, 0x0c, 0x69, 0x73, - 0x5f, 0x6d, 0x6f, 0x6e, 0x6f, 0x74, 0x6f, 0x6e, 0x69, 0x63, 0x18, 0x03, 0x20, 0x01, 0x28, 0x08, - 0x52, 0x0b, 0x69, 0x73, 0x4d, 0x6f, 0x6e, 0x6f, 0x74, 0x6f, 0x6e, 0x69, 0x63, 0x22, 0xf1, 0x01, - 0x0a, 0x09, 0x44, 0x6f, 0x75, 0x62, 0x6c, 0x65, 0x53, 0x75, 0x6d, 0x12, 0x50, 0x0a, 0x0b, 0x64, - 0x61, 0x74, 0x61, 0x5f, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, - 0x32, 0x2f, 0x2e, 0x6f, 0x70, 0x65, 0x6e, 0x74, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x74, 0x72, 0x79, - 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x6d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x73, 0x2e, 0x76, - 0x31, 0x2e, 0x44, 0x6f, 0x75, 0x62, 0x6c, 0x65, 0x44, 0x61, 0x74, 0x61, 0x50, 0x6f, 0x69, 0x6e, - 0x74, 0x52, 0x0a, 0x64, 0x61, 0x74, 0x61, 0x50, 0x6f, 0x69, 0x6e, 0x74, 0x73, 0x12, 0x6f, 0x0a, - 0x17, 0x61, 0x67, 0x67, 0x72, 0x65, 0x67, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x74, 0x65, 0x6d, - 0x70, 0x6f, 0x72, 0x61, 0x6c, 0x69, 0x74, 0x79, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x36, - 0x2e, 0x6f, 0x70, 0x65, 0x6e, 0x74, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x74, 0x72, 0x79, 0x2e, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x6d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x73, 0x2e, 0x76, 0x31, 0x2e, - 0x41, 0x67, 0x67, 0x72, 0x65, 0x67, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x54, 0x65, 0x6d, 0x70, 0x6f, - 0x72, 0x61, 0x6c, 0x69, 0x74, 0x79, 0x52, 0x16, 0x61, 0x67, 0x67, 0x72, 0x65, 0x67, 0x61, 0x74, - 0x69, 0x6f, 0x6e, 0x54, 0x65, 0x6d, 0x70, 0x6f, 0x72, 0x61, 0x6c, 0x69, 0x74, 0x79, 0x12, 0x21, - 0x0a, 0x0c, 0x69, 0x73, 0x5f, 0x6d, 0x6f, 0x6e, 0x6f, 0x74, 0x6f, 0x6e, 0x69, 0x63, 0x18, 0x03, - 0x20, 0x01, 0x28, 0x08, 0x52, 0x0b, 0x69, 0x73, 0x4d, 0x6f, 0x6e, 0x6f, 0x74, 0x6f, 0x6e, 0x69, - 0x63, 0x22, 0xd7, 0x01, 0x0a, 0x0c, 0x49, 0x6e, 0x74, 0x48, 0x69, 0x73, 0x74, 0x6f, 0x67, 0x72, - 0x61, 0x6d, 0x12, 0x56, 0x0a, 0x0b, 0x64, 0x61, 0x74, 0x61, 0x5f, 0x70, 0x6f, 0x69, 0x6e, 0x74, - 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x35, 0x2e, 0x6f, 0x70, 0x65, 0x6e, 0x74, 0x65, - 0x6c, 0x65, 0x6d, 0x65, 0x74, 0x72, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x6d, 0x65, - 0x74, 0x72, 0x69, 0x63, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x49, 0x6e, 0x74, 0x48, 0x69, 0x73, 0x74, - 0x6f, 0x67, 0x72, 0x61, 0x6d, 0x44, 0x61, 0x74, 0x61, 0x50, 0x6f, 0x69, 0x6e, 0x74, 0x52, 0x0a, - 0x64, 0x61, 0x74, 0x61, 0x50, 0x6f, 0x69, 0x6e, 0x74, 0x73, 0x12, 0x6f, 0x0a, 0x17, 0x61, 0x67, - 0x67, 0x72, 0x65, 0x67, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x74, 0x65, 0x6d, 0x70, 0x6f, 0x72, - 0x61, 0x6c, 0x69, 0x74, 0x79, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x36, 0x2e, 0x6f, 0x70, - 0x65, 0x6e, 0x74, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x74, 0x72, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, - 0x6f, 0x2e, 0x6d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x41, 0x67, 0x67, - 0x72, 0x65, 0x67, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x54, 0x65, 0x6d, 0x70, 0x6f, 0x72, 0x61, 0x6c, - 0x69, 0x74, 0x79, 0x52, 0x16, 0x61, 0x67, 0x67, 0x72, 0x65, 0x67, 0x61, 0x74, 0x69, 0x6f, 0x6e, - 0x54, 0x65, 0x6d, 0x70, 0x6f, 0x72, 0x61, 0x6c, 0x69, 0x74, 0x79, 0x22, 0xdd, 0x01, 0x0a, 0x0f, - 0x44, 0x6f, 0x75, 0x62, 0x6c, 0x65, 0x48, 0x69, 0x73, 0x74, 0x6f, 0x67, 0x72, 0x61, 0x6d, 0x12, - 0x59, 0x0a, 0x0b, 0x64, 0x61, 0x74, 0x61, 0x5f, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x73, 0x18, 0x01, - 0x20, 0x03, 0x28, 0x0b, 0x32, 0x38, 0x2e, 0x6f, 0x70, 0x65, 0x6e, 0x74, 0x65, 0x6c, 0x65, 0x6d, - 0x65, 0x74, 0x72, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x6d, 0x65, 0x74, 0x72, 0x69, - 0x63, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x44, 0x6f, 0x75, 0x62, 0x6c, 0x65, 0x48, 0x69, 0x73, 0x74, - 0x6f, 0x67, 0x72, 0x61, 0x6d, 0x44, 0x61, 0x74, 0x61, 0x50, 0x6f, 0x69, 0x6e, 0x74, 0x52, 0x0a, - 0x64, 0x61, 0x74, 0x61, 0x50, 0x6f, 0x69, 0x6e, 0x74, 0x73, 0x12, 0x6f, 0x0a, 0x17, 0x61, 0x67, - 0x67, 0x72, 0x65, 0x67, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x74, 0x65, 0x6d, 0x70, 0x6f, 0x72, - 0x61, 0x6c, 0x69, 0x74, 0x79, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x36, 0x2e, 0x6f, 0x70, - 0x65, 0x6e, 0x74, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x74, 0x72, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, - 0x6f, 0x2e, 0x6d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x41, 0x67, 0x67, - 0x72, 0x65, 0x67, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x54, 0x65, 0x6d, 0x70, 0x6f, 0x72, 0x61, 0x6c, - 0x69, 0x74, 0x79, 0x52, 0x16, 0x61, 0x67, 0x67, 0x72, 0x65, 0x67, 0x61, 0x74, 0x69, 0x6f, 0x6e, - 0x54, 0x65, 0x6d, 0x70, 0x6f, 0x72, 0x61, 0x6c, 0x69, 0x74, 0x79, 0x22, 0x68, 0x0a, 0x0d, 0x44, - 0x6f, 0x75, 0x62, 0x6c, 0x65, 0x53, 0x75, 0x6d, 0x6d, 0x61, 0x72, 0x79, 0x12, 0x57, 0x0a, 0x0b, - 0x64, 0x61, 0x74, 0x61, 0x5f, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, - 0x0b, 0x32, 0x36, 0x2e, 0x6f, 0x70, 0x65, 0x6e, 0x74, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x74, 0x72, - 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x6d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x73, 0x2e, - 0x76, 0x31, 0x2e, 0x44, 0x6f, 0x75, 0x62, 0x6c, 0x65, 0x53, 0x75, 0x6d, 0x6d, 0x61, 0x72, 0x79, - 0x44, 0x61, 0x74, 0x61, 0x50, 0x6f, 0x69, 0x6e, 0x74, 0x52, 0x0a, 0x64, 0x61, 0x74, 0x61, 0x50, - 0x6f, 0x69, 0x6e, 0x74, 0x73, 0x22, 0x8d, 0x02, 0x0a, 0x0c, 0x49, 0x6e, 0x74, 0x44, 0x61, 0x74, - 0x61, 0x50, 0x6f, 0x69, 0x6e, 0x74, 0x12, 0x45, 0x0a, 0x06, 0x6c, 0x61, 0x62, 0x65, 0x6c, 0x73, - 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x2d, 0x2e, 0x6f, 0x70, 0x65, 0x6e, 0x74, 0x65, 0x6c, - 0x65, 0x6d, 0x65, 0x74, 0x72, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x63, 0x6f, 0x6d, - 0x6d, 0x6f, 0x6e, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x4b, 0x65, 0x79, - 0x56, 0x61, 0x6c, 0x75, 0x65, 0x52, 0x06, 0x6c, 0x61, 0x62, 0x65, 0x6c, 0x73, 0x12, 0x2f, 0x0a, - 0x14, 0x73, 0x74, 0x61, 0x72, 0x74, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x5f, 0x75, 0x6e, 0x69, 0x78, - 0x5f, 0x6e, 0x61, 0x6e, 0x6f, 0x18, 0x02, 0x20, 0x01, 0x28, 0x06, 0x52, 0x11, 0x73, 0x74, 0x61, - 0x72, 0x74, 0x54, 0x69, 0x6d, 0x65, 0x55, 0x6e, 0x69, 0x78, 0x4e, 0x61, 0x6e, 0x6f, 0x12, 0x24, - 0x0a, 0x0e, 0x74, 0x69, 0x6d, 0x65, 0x5f, 0x75, 0x6e, 0x69, 0x78, 0x5f, 0x6e, 0x61, 0x6e, 0x6f, - 0x18, 0x03, 0x20, 0x01, 0x28, 0x06, 0x52, 0x0c, 0x74, 0x69, 0x6d, 0x65, 0x55, 0x6e, 0x69, 0x78, - 0x4e, 0x61, 0x6e, 0x6f, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x04, 0x20, - 0x01, 0x28, 0x10, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x12, 0x49, 0x0a, 0x09, 0x65, 0x78, - 0x65, 0x6d, 0x70, 0x6c, 0x61, 0x72, 0x73, 0x18, 0x05, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x2b, 0x2e, - 0x6f, 0x70, 0x65, 0x6e, 0x74, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x74, 0x72, 0x79, 0x2e, 0x70, 0x72, - 0x6f, 0x74, 0x6f, 0x2e, 0x6d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x49, - 0x6e, 0x74, 0x45, 0x78, 0x65, 0x6d, 0x70, 0x6c, 0x61, 0x72, 0x52, 0x09, 0x65, 0x78, 0x65, 0x6d, - 0x70, 0x6c, 0x61, 0x72, 0x73, 0x22, 0x93, 0x02, 0x0a, 0x0f, 0x44, 0x6f, 0x75, 0x62, 0x6c, 0x65, - 0x44, 0x61, 0x74, 0x61, 0x50, 0x6f, 0x69, 0x6e, 0x74, 0x12, 0x45, 0x0a, 0x06, 0x6c, 0x61, 0x62, - 0x65, 0x6c, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x2d, 0x2e, 0x6f, 0x70, 0x65, 0x6e, - 0x74, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x74, 0x72, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, - 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, - 0x4b, 0x65, 0x79, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x52, 0x06, 0x6c, 0x61, 0x62, 0x65, 0x6c, 0x73, - 0x12, 0x2f, 0x0a, 0x14, 0x73, 0x74, 0x61, 0x72, 0x74, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x5f, 0x75, - 0x6e, 0x69, 0x78, 0x5f, 0x6e, 0x61, 0x6e, 0x6f, 0x18, 0x02, 0x20, 0x01, 0x28, 0x06, 0x52, 0x11, - 0x73, 0x74, 0x61, 0x72, 0x74, 0x54, 0x69, 0x6d, 0x65, 0x55, 0x6e, 0x69, 0x78, 0x4e, 0x61, 0x6e, - 0x6f, 0x12, 0x24, 0x0a, 0x0e, 0x74, 0x69, 0x6d, 0x65, 0x5f, 0x75, 0x6e, 0x69, 0x78, 0x5f, 0x6e, - 0x61, 0x6e, 0x6f, 0x18, 0x03, 0x20, 0x01, 0x28, 0x06, 0x52, 0x0c, 0x74, 0x69, 0x6d, 0x65, 0x55, - 0x6e, 0x69, 0x78, 0x4e, 0x61, 0x6e, 0x6f, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, - 0x18, 0x04, 0x20, 0x01, 0x28, 0x01, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x12, 0x4c, 0x0a, - 0x09, 0x65, 0x78, 0x65, 0x6d, 0x70, 0x6c, 0x61, 0x72, 0x73, 0x18, 0x05, 0x20, 0x03, 0x28, 0x0b, - 0x32, 0x2e, 0x2e, 0x6f, 0x70, 0x65, 0x6e, 0x74, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x74, 0x72, 0x79, - 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x6d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x73, 0x2e, 0x76, - 0x31, 0x2e, 0x44, 0x6f, 0x75, 0x62, 0x6c, 0x65, 0x45, 0x78, 0x65, 0x6d, 0x70, 0x6c, 0x61, 0x72, - 0x52, 0x09, 0x65, 0x78, 0x65, 0x6d, 0x70, 0x6c, 0x61, 0x72, 0x73, 0x22, 0xf6, 0x02, 0x0a, 0x15, - 0x49, 0x6e, 0x74, 0x48, 0x69, 0x73, 0x74, 0x6f, 0x67, 0x72, 0x61, 0x6d, 0x44, 0x61, 0x74, 0x61, - 0x50, 0x6f, 0x69, 0x6e, 0x74, 0x12, 0x45, 0x0a, 0x06, 0x6c, 0x61, 0x62, 0x65, 0x6c, 0x73, 0x18, - 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x2d, 0x2e, 0x6f, 0x70, 0x65, 0x6e, 0x74, 0x65, 0x6c, 0x65, - 0x6d, 0x65, 0x74, 0x72, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x63, 0x6f, 0x6d, 0x6d, - 0x6f, 0x6e, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x4b, 0x65, 0x79, 0x56, - 0x61, 0x6c, 0x75, 0x65, 0x52, 0x06, 0x6c, 0x61, 0x62, 0x65, 0x6c, 0x73, 0x12, 0x2f, 0x0a, 0x14, - 0x73, 0x74, 0x61, 0x72, 0x74, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x5f, 0x75, 0x6e, 0x69, 0x78, 0x5f, - 0x6e, 0x61, 0x6e, 0x6f, 0x18, 0x02, 0x20, 0x01, 0x28, 0x06, 0x52, 0x11, 0x73, 0x74, 0x61, 0x72, - 0x74, 0x54, 0x69, 0x6d, 0x65, 0x55, 0x6e, 0x69, 0x78, 0x4e, 0x61, 0x6e, 0x6f, 0x12, 0x24, 0x0a, - 0x0e, 0x74, 0x69, 0x6d, 0x65, 0x5f, 0x75, 0x6e, 0x69, 0x78, 0x5f, 0x6e, 0x61, 0x6e, 0x6f, 0x18, - 0x03, 0x20, 0x01, 0x28, 0x06, 0x52, 0x0c, 0x74, 0x69, 0x6d, 0x65, 0x55, 0x6e, 0x69, 0x78, 0x4e, - 0x61, 0x6e, 0x6f, 0x12, 0x14, 0x0a, 0x05, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x04, 0x20, 0x01, - 0x28, 0x06, 0x52, 0x05, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x10, 0x0a, 0x03, 0x73, 0x75, 0x6d, - 0x18, 0x05, 0x20, 0x01, 0x28, 0x10, 0x52, 0x03, 0x73, 0x75, 0x6d, 0x12, 0x23, 0x0a, 0x0d, 0x62, - 0x75, 0x63, 0x6b, 0x65, 0x74, 0x5f, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x18, 0x06, 0x20, 0x03, - 0x28, 0x06, 0x52, 0x0c, 0x62, 0x75, 0x63, 0x6b, 0x65, 0x74, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x73, - 0x12, 0x27, 0x0a, 0x0f, 0x65, 0x78, 0x70, 0x6c, 0x69, 0x63, 0x69, 0x74, 0x5f, 0x62, 0x6f, 0x75, - 0x6e, 0x64, 0x73, 0x18, 0x07, 0x20, 0x03, 0x28, 0x01, 0x52, 0x0e, 0x65, 0x78, 0x70, 0x6c, 0x69, - 0x63, 0x69, 0x74, 0x42, 0x6f, 0x75, 0x6e, 0x64, 0x73, 0x12, 0x49, 0x0a, 0x09, 0x65, 0x78, 0x65, - 0x6d, 0x70, 0x6c, 0x61, 0x72, 0x73, 0x18, 0x08, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x2b, 0x2e, 0x6f, - 0x70, 0x65, 0x6e, 0x74, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x74, 0x72, 0x79, 0x2e, 0x70, 0x72, 0x6f, - 0x74, 0x6f, 0x2e, 0x6d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x49, 0x6e, - 0x74, 0x45, 0x78, 0x65, 0x6d, 0x70, 0x6c, 0x61, 0x72, 0x52, 0x09, 0x65, 0x78, 0x65, 0x6d, 0x70, - 0x6c, 0x61, 0x72, 0x73, 0x22, 0xfc, 0x02, 0x0a, 0x18, 0x44, 0x6f, 0x75, 0x62, 0x6c, 0x65, 0x48, - 0x69, 0x73, 0x74, 0x6f, 0x67, 0x72, 0x61, 0x6d, 0x44, 0x61, 0x74, 0x61, 0x50, 0x6f, 0x69, 0x6e, - 0x74, 0x12, 0x45, 0x0a, 0x06, 0x6c, 0x61, 0x62, 0x65, 0x6c, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, - 0x0b, 0x32, 0x2d, 0x2e, 0x6f, 0x70, 0x65, 0x6e, 0x74, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x74, 0x72, - 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2e, 0x76, - 0x31, 0x2e, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x4b, 0x65, 0x79, 0x56, 0x61, 0x6c, 0x75, 0x65, - 0x52, 0x06, 0x6c, 0x61, 0x62, 0x65, 0x6c, 0x73, 0x12, 0x2f, 0x0a, 0x14, 0x73, 0x74, 0x61, 0x72, - 0x74, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x5f, 0x75, 0x6e, 0x69, 0x78, 0x5f, 0x6e, 0x61, 0x6e, 0x6f, - 0x18, 0x02, 0x20, 0x01, 0x28, 0x06, 0x52, 0x11, 0x73, 0x74, 0x61, 0x72, 0x74, 0x54, 0x69, 0x6d, - 0x65, 0x55, 0x6e, 0x69, 0x78, 0x4e, 0x61, 0x6e, 0x6f, 0x12, 0x24, 0x0a, 0x0e, 0x74, 0x69, 0x6d, - 0x65, 0x5f, 0x75, 0x6e, 0x69, 0x78, 0x5f, 0x6e, 0x61, 0x6e, 0x6f, 0x18, 0x03, 0x20, 0x01, 0x28, - 0x06, 0x52, 0x0c, 0x74, 0x69, 0x6d, 0x65, 0x55, 0x6e, 0x69, 0x78, 0x4e, 0x61, 0x6e, 0x6f, 0x12, - 0x14, 0x0a, 0x05, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x06, 0x52, 0x05, - 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x10, 0x0a, 0x03, 0x73, 0x75, 0x6d, 0x18, 0x05, 0x20, 0x01, - 0x28, 0x01, 0x52, 0x03, 0x73, 0x75, 0x6d, 0x12, 0x23, 0x0a, 0x0d, 0x62, 0x75, 0x63, 0x6b, 0x65, - 0x74, 0x5f, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x18, 0x06, 0x20, 0x03, 0x28, 0x06, 0x52, 0x0c, - 0x62, 0x75, 0x63, 0x6b, 0x65, 0x74, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x12, 0x27, 0x0a, 0x0f, - 0x65, 0x78, 0x70, 0x6c, 0x69, 0x63, 0x69, 0x74, 0x5f, 0x62, 0x6f, 0x75, 0x6e, 0x64, 0x73, 0x18, - 0x07, 0x20, 0x03, 0x28, 0x01, 0x52, 0x0e, 0x65, 0x78, 0x70, 0x6c, 0x69, 0x63, 0x69, 0x74, 0x42, - 0x6f, 0x75, 0x6e, 0x64, 0x73, 0x12, 0x4c, 0x0a, 0x09, 0x65, 0x78, 0x65, 0x6d, 0x70, 0x6c, 0x61, - 0x72, 0x73, 0x18, 0x08, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x2e, 0x2e, 0x6f, 0x70, 0x65, 0x6e, 0x74, - 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x74, 0x72, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x6d, - 0x65, 0x74, 0x72, 0x69, 0x63, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x44, 0x6f, 0x75, 0x62, 0x6c, 0x65, - 0x45, 0x78, 0x65, 0x6d, 0x70, 0x6c, 0x61, 0x72, 0x52, 0x09, 0x65, 0x78, 0x65, 0x6d, 0x70, 0x6c, - 0x61, 0x72, 0x73, 0x22, 0x94, 0x03, 0x0a, 0x16, 0x44, 0x6f, 0x75, 0x62, 0x6c, 0x65, 0x53, 0x75, - 0x6d, 0x6d, 0x61, 0x72, 0x79, 0x44, 0x61, 0x74, 0x61, 0x50, 0x6f, 0x69, 0x6e, 0x74, 0x12, 0x45, - 0x0a, 0x06, 0x6c, 0x61, 0x62, 0x65, 0x6c, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x2d, - 0x2e, 0x6f, 0x70, 0x65, 0x6e, 0x74, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x74, 0x72, 0x79, 0x2e, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2e, 0x76, 0x31, 0x2e, 0x53, - 0x74, 0x72, 0x69, 0x6e, 0x67, 0x4b, 0x65, 0x79, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x52, 0x06, 0x6c, - 0x61, 0x62, 0x65, 0x6c, 0x73, 0x12, 0x2f, 0x0a, 0x14, 0x73, 0x74, 0x61, 0x72, 0x74, 0x5f, 0x74, - 0x69, 0x6d, 0x65, 0x5f, 0x75, 0x6e, 0x69, 0x78, 0x5f, 0x6e, 0x61, 0x6e, 0x6f, 0x18, 0x02, 0x20, - 0x01, 0x28, 0x06, 0x52, 0x11, 0x73, 0x74, 0x61, 0x72, 0x74, 0x54, 0x69, 0x6d, 0x65, 0x55, 0x6e, - 0x69, 0x78, 0x4e, 0x61, 0x6e, 0x6f, 0x12, 0x24, 0x0a, 0x0e, 0x74, 0x69, 0x6d, 0x65, 0x5f, 0x75, - 0x6e, 0x69, 0x78, 0x5f, 0x6e, 0x61, 0x6e, 0x6f, 0x18, 0x03, 0x20, 0x01, 0x28, 0x06, 0x52, 0x0c, - 0x74, 0x69, 0x6d, 0x65, 0x55, 0x6e, 0x69, 0x78, 0x4e, 0x61, 0x6e, 0x6f, 0x12, 0x14, 0x0a, 0x05, - 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x06, 0x52, 0x05, 0x63, 0x6f, 0x75, - 0x6e, 0x74, 0x12, 0x10, 0x0a, 0x03, 0x73, 0x75, 0x6d, 0x18, 0x05, 0x20, 0x01, 0x28, 0x01, 0x52, - 0x03, 0x73, 0x75, 0x6d, 0x12, 0x6f, 0x0a, 0x0f, 0x71, 0x75, 0x61, 0x6e, 0x74, 0x69, 0x6c, 0x65, - 0x5f, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x73, 0x18, 0x06, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x46, 0x2e, - 0x6f, 0x70, 0x65, 0x6e, 0x74, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x74, 0x72, 0x79, 0x2e, 0x70, 0x72, - 0x6f, 0x74, 0x6f, 0x2e, 0x6d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x44, - 0x6f, 0x75, 0x62, 0x6c, 0x65, 0x53, 0x75, 0x6d, 0x6d, 0x61, 0x72, 0x79, 0x44, 0x61, 0x74, 0x61, - 0x50, 0x6f, 0x69, 0x6e, 0x74, 0x2e, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x41, 0x74, 0x51, 0x75, 0x61, - 0x6e, 0x74, 0x69, 0x6c, 0x65, 0x52, 0x0e, 0x71, 0x75, 0x61, 0x6e, 0x74, 0x69, 0x6c, 0x65, 0x56, - 0x61, 0x6c, 0x75, 0x65, 0x73, 0x1a, 0x43, 0x0a, 0x0f, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x41, 0x74, - 0x51, 0x75, 0x61, 0x6e, 0x74, 0x69, 0x6c, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x71, 0x75, 0x61, 0x6e, - 0x74, 0x69, 0x6c, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x01, 0x52, 0x08, 0x71, 0x75, 0x61, 0x6e, - 0x74, 0x69, 0x6c, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, - 0x01, 0x28, 0x01, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x22, 0xd5, 0x01, 0x0a, 0x0b, 0x49, - 0x6e, 0x74, 0x45, 0x78, 0x65, 0x6d, 0x70, 0x6c, 0x61, 0x72, 0x12, 0x56, 0x0a, 0x0f, 0x66, 0x69, - 0x6c, 0x74, 0x65, 0x72, 0x65, 0x64, 0x5f, 0x6c, 0x61, 0x62, 0x65, 0x6c, 0x73, 0x18, 0x01, 0x20, - 0x03, 0x28, 0x0b, 0x32, 0x2d, 0x2e, 0x6f, 0x70, 0x65, 0x6e, 0x74, 0x65, 0x6c, 0x65, 0x6d, 0x65, - 0x74, 0x72, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, - 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x4b, 0x65, 0x79, 0x56, 0x61, 0x6c, - 0x75, 0x65, 0x52, 0x0e, 0x66, 0x69, 0x6c, 0x74, 0x65, 0x72, 0x65, 0x64, 0x4c, 0x61, 0x62, 0x65, - 0x6c, 0x73, 0x12, 0x24, 0x0a, 0x0e, 0x74, 0x69, 0x6d, 0x65, 0x5f, 0x75, 0x6e, 0x69, 0x78, 0x5f, - 0x6e, 0x61, 0x6e, 0x6f, 0x18, 0x02, 0x20, 0x01, 0x28, 0x06, 0x52, 0x0c, 0x74, 0x69, 0x6d, 0x65, - 0x55, 0x6e, 0x69, 0x78, 0x4e, 0x61, 0x6e, 0x6f, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, - 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x10, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x12, 0x17, - 0x0a, 0x07, 0x73, 0x70, 0x61, 0x6e, 0x5f, 0x69, 0x64, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0c, 0x52, - 0x06, 0x73, 0x70, 0x61, 0x6e, 0x49, 0x64, 0x12, 0x19, 0x0a, 0x08, 0x74, 0x72, 0x61, 0x63, 0x65, - 0x5f, 0x69, 0x64, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x07, 0x74, 0x72, 0x61, 0x63, 0x65, - 0x49, 0x64, 0x22, 0xd8, 0x01, 0x0a, 0x0e, 0x44, 0x6f, 0x75, 0x62, 0x6c, 0x65, 0x45, 0x78, 0x65, - 0x6d, 0x70, 0x6c, 0x61, 0x72, 0x12, 0x56, 0x0a, 0x0f, 0x66, 0x69, 0x6c, 0x74, 0x65, 0x72, 0x65, - 0x64, 0x5f, 0x6c, 0x61, 0x62, 0x65, 0x6c, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x2d, - 0x2e, 0x6f, 0x70, 0x65, 0x6e, 0x74, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x74, 0x72, 0x79, 0x2e, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2e, 0x76, 0x31, 0x2e, 0x53, - 0x74, 0x72, 0x69, 0x6e, 0x67, 0x4b, 0x65, 0x79, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x52, 0x0e, 0x66, - 0x69, 0x6c, 0x74, 0x65, 0x72, 0x65, 0x64, 0x4c, 0x61, 0x62, 0x65, 0x6c, 0x73, 0x12, 0x24, 0x0a, - 0x0e, 0x74, 0x69, 0x6d, 0x65, 0x5f, 0x75, 0x6e, 0x69, 0x78, 0x5f, 0x6e, 0x61, 0x6e, 0x6f, 0x18, - 0x02, 0x20, 0x01, 0x28, 0x06, 0x52, 0x0c, 0x74, 0x69, 0x6d, 0x65, 0x55, 0x6e, 0x69, 0x78, 0x4e, - 0x61, 0x6e, 0x6f, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x03, 0x20, 0x01, - 0x28, 0x01, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x12, 0x17, 0x0a, 0x07, 0x73, 0x70, 0x61, - 0x6e, 0x5f, 0x69, 0x64, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x06, 0x73, 0x70, 0x61, 0x6e, - 0x49, 0x64, 0x12, 0x19, 0x0a, 0x08, 0x74, 0x72, 0x61, 0x63, 0x65, 0x5f, 0x69, 0x64, 0x18, 0x05, - 0x20, 0x01, 0x28, 0x0c, 0x52, 0x07, 0x74, 0x72, 0x61, 0x63, 0x65, 0x49, 0x64, 0x2a, 0x8c, 0x01, - 0x0a, 0x16, 0x41, 0x67, 0x67, 0x72, 0x65, 0x67, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x54, 0x65, 0x6d, - 0x70, 0x6f, 0x72, 0x61, 0x6c, 0x69, 0x74, 0x79, 0x12, 0x27, 0x0a, 0x23, 0x41, 0x47, 0x47, 0x52, - 0x45, 0x47, 0x41, 0x54, 0x49, 0x4f, 0x4e, 0x5f, 0x54, 0x45, 0x4d, 0x50, 0x4f, 0x52, 0x41, 0x4c, - 0x49, 0x54, 0x59, 0x5f, 0x55, 0x4e, 0x53, 0x50, 0x45, 0x43, 0x49, 0x46, 0x49, 0x45, 0x44, 0x10, - 0x00, 0x12, 0x21, 0x0a, 0x1d, 0x41, 0x47, 0x47, 0x52, 0x45, 0x47, 0x41, 0x54, 0x49, 0x4f, 0x4e, - 0x5f, 0x54, 0x45, 0x4d, 0x50, 0x4f, 0x52, 0x41, 0x4c, 0x49, 0x54, 0x59, 0x5f, 0x44, 0x45, 0x4c, - 0x54, 0x41, 0x10, 0x01, 0x12, 0x26, 0x0a, 0x22, 0x41, 0x47, 0x47, 0x52, 0x45, 0x47, 0x41, 0x54, - 0x49, 0x4f, 0x4e, 0x5f, 0x54, 0x45, 0x4d, 0x50, 0x4f, 0x52, 0x41, 0x4c, 0x49, 0x54, 0x59, 0x5f, - 0x43, 0x55, 0x4d, 0x55, 0x4c, 0x41, 0x54, 0x49, 0x56, 0x45, 0x10, 0x02, 0x42, 0x5e, 0x0a, 0x21, - 0x69, 0x6f, 0x2e, 0x6f, 0x70, 0x65, 0x6e, 0x74, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x74, 0x72, 0x79, - 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x6d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x73, 0x2e, 0x76, - 0x31, 0x42, 0x0c, 0x4d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x73, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, - 0x01, 0x5a, 0x29, 0x67, 0x6f, 0x2e, 0x6f, 0x70, 0x65, 0x6e, 0x74, 0x65, 0x6c, 0x65, 0x6d, 0x65, - 0x74, 0x72, 0x79, 0x2e, 0x69, 0x6f, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x6f, 0x74, 0x6c, - 0x70, 0x2f, 0x6d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x73, 0x2f, 0x76, 0x31, 0x62, 0x06, 0x70, 0x72, - 0x6f, 0x74, 0x6f, 0x33, -} - -var ( - file_opentelemetry_proto_metrics_v1_metrics_proto_rawDescOnce sync.Once - file_opentelemetry_proto_metrics_v1_metrics_proto_rawDescData = file_opentelemetry_proto_metrics_v1_metrics_proto_rawDesc -) - -func file_opentelemetry_proto_metrics_v1_metrics_proto_rawDescGZIP() []byte { - file_opentelemetry_proto_metrics_v1_metrics_proto_rawDescOnce.Do(func() { - file_opentelemetry_proto_metrics_v1_metrics_proto_rawDescData = protoimpl.X.CompressGZIP(file_opentelemetry_proto_metrics_v1_metrics_proto_rawDescData) - }) - return file_opentelemetry_proto_metrics_v1_metrics_proto_rawDescData -} - -var file_opentelemetry_proto_metrics_v1_metrics_proto_enumTypes = make([]protoimpl.EnumInfo, 1) -var file_opentelemetry_proto_metrics_v1_metrics_proto_msgTypes = make([]protoimpl.MessageInfo, 18) -var file_opentelemetry_proto_metrics_v1_metrics_proto_goTypes = []interface{}{ - (AggregationTemporality)(0), // 0: opentelemetry.proto.metrics.v1.AggregationTemporality - (*ResourceMetrics)(nil), // 1: opentelemetry.proto.metrics.v1.ResourceMetrics - (*InstrumentationLibraryMetrics)(nil), // 2: opentelemetry.proto.metrics.v1.InstrumentationLibraryMetrics - (*Metric)(nil), // 3: opentelemetry.proto.metrics.v1.Metric - (*IntGauge)(nil), // 4: opentelemetry.proto.metrics.v1.IntGauge - (*DoubleGauge)(nil), // 5: opentelemetry.proto.metrics.v1.DoubleGauge - (*IntSum)(nil), // 6: opentelemetry.proto.metrics.v1.IntSum - (*DoubleSum)(nil), // 7: opentelemetry.proto.metrics.v1.DoubleSum - (*IntHistogram)(nil), // 8: opentelemetry.proto.metrics.v1.IntHistogram - (*DoubleHistogram)(nil), // 9: opentelemetry.proto.metrics.v1.DoubleHistogram - (*DoubleSummary)(nil), // 10: opentelemetry.proto.metrics.v1.DoubleSummary - (*IntDataPoint)(nil), // 11: opentelemetry.proto.metrics.v1.IntDataPoint - (*DoubleDataPoint)(nil), // 12: opentelemetry.proto.metrics.v1.DoubleDataPoint - (*IntHistogramDataPoint)(nil), // 13: opentelemetry.proto.metrics.v1.IntHistogramDataPoint - (*DoubleHistogramDataPoint)(nil), // 14: opentelemetry.proto.metrics.v1.DoubleHistogramDataPoint - (*DoubleSummaryDataPoint)(nil), // 15: opentelemetry.proto.metrics.v1.DoubleSummaryDataPoint - (*IntExemplar)(nil), // 16: opentelemetry.proto.metrics.v1.IntExemplar - (*DoubleExemplar)(nil), // 17: opentelemetry.proto.metrics.v1.DoubleExemplar - (*DoubleSummaryDataPoint_ValueAtQuantile)(nil), // 18: opentelemetry.proto.metrics.v1.DoubleSummaryDataPoint.ValueAtQuantile - (*v1.Resource)(nil), // 19: opentelemetry.proto.resource.v1.Resource - (*v11.InstrumentationLibrary)(nil), // 20: opentelemetry.proto.common.v1.InstrumentationLibrary - (*v11.StringKeyValue)(nil), // 21: opentelemetry.proto.common.v1.StringKeyValue -} -var file_opentelemetry_proto_metrics_v1_metrics_proto_depIdxs = []int32{ - 19, // 0: opentelemetry.proto.metrics.v1.ResourceMetrics.resource:type_name -> opentelemetry.proto.resource.v1.Resource - 2, // 1: opentelemetry.proto.metrics.v1.ResourceMetrics.instrumentation_library_metrics:type_name -> opentelemetry.proto.metrics.v1.InstrumentationLibraryMetrics - 20, // 2: opentelemetry.proto.metrics.v1.InstrumentationLibraryMetrics.instrumentation_library:type_name -> opentelemetry.proto.common.v1.InstrumentationLibrary - 3, // 3: opentelemetry.proto.metrics.v1.InstrumentationLibraryMetrics.metrics:type_name -> opentelemetry.proto.metrics.v1.Metric - 4, // 4: opentelemetry.proto.metrics.v1.Metric.int_gauge:type_name -> opentelemetry.proto.metrics.v1.IntGauge - 5, // 5: opentelemetry.proto.metrics.v1.Metric.double_gauge:type_name -> opentelemetry.proto.metrics.v1.DoubleGauge - 6, // 6: opentelemetry.proto.metrics.v1.Metric.int_sum:type_name -> opentelemetry.proto.metrics.v1.IntSum - 7, // 7: opentelemetry.proto.metrics.v1.Metric.double_sum:type_name -> opentelemetry.proto.metrics.v1.DoubleSum - 8, // 8: opentelemetry.proto.metrics.v1.Metric.int_histogram:type_name -> opentelemetry.proto.metrics.v1.IntHistogram - 9, // 9: opentelemetry.proto.metrics.v1.Metric.double_histogram:type_name -> opentelemetry.proto.metrics.v1.DoubleHistogram - 10, // 10: opentelemetry.proto.metrics.v1.Metric.double_summary:type_name -> opentelemetry.proto.metrics.v1.DoubleSummary - 11, // 11: opentelemetry.proto.metrics.v1.IntGauge.data_points:type_name -> opentelemetry.proto.metrics.v1.IntDataPoint - 12, // 12: opentelemetry.proto.metrics.v1.DoubleGauge.data_points:type_name -> opentelemetry.proto.metrics.v1.DoubleDataPoint - 11, // 13: opentelemetry.proto.metrics.v1.IntSum.data_points:type_name -> opentelemetry.proto.metrics.v1.IntDataPoint - 0, // 14: opentelemetry.proto.metrics.v1.IntSum.aggregation_temporality:type_name -> opentelemetry.proto.metrics.v1.AggregationTemporality - 12, // 15: opentelemetry.proto.metrics.v1.DoubleSum.data_points:type_name -> opentelemetry.proto.metrics.v1.DoubleDataPoint - 0, // 16: opentelemetry.proto.metrics.v1.DoubleSum.aggregation_temporality:type_name -> opentelemetry.proto.metrics.v1.AggregationTemporality - 13, // 17: opentelemetry.proto.metrics.v1.IntHistogram.data_points:type_name -> opentelemetry.proto.metrics.v1.IntHistogramDataPoint - 0, // 18: opentelemetry.proto.metrics.v1.IntHistogram.aggregation_temporality:type_name -> opentelemetry.proto.metrics.v1.AggregationTemporality - 14, // 19: opentelemetry.proto.metrics.v1.DoubleHistogram.data_points:type_name -> opentelemetry.proto.metrics.v1.DoubleHistogramDataPoint - 0, // 20: opentelemetry.proto.metrics.v1.DoubleHistogram.aggregation_temporality:type_name -> opentelemetry.proto.metrics.v1.AggregationTemporality - 15, // 21: opentelemetry.proto.metrics.v1.DoubleSummary.data_points:type_name -> opentelemetry.proto.metrics.v1.DoubleSummaryDataPoint - 21, // 22: opentelemetry.proto.metrics.v1.IntDataPoint.labels:type_name -> opentelemetry.proto.common.v1.StringKeyValue - 16, // 23: opentelemetry.proto.metrics.v1.IntDataPoint.exemplars:type_name -> opentelemetry.proto.metrics.v1.IntExemplar - 21, // 24: opentelemetry.proto.metrics.v1.DoubleDataPoint.labels:type_name -> opentelemetry.proto.common.v1.StringKeyValue - 17, // 25: opentelemetry.proto.metrics.v1.DoubleDataPoint.exemplars:type_name -> opentelemetry.proto.metrics.v1.DoubleExemplar - 21, // 26: opentelemetry.proto.metrics.v1.IntHistogramDataPoint.labels:type_name -> opentelemetry.proto.common.v1.StringKeyValue - 16, // 27: opentelemetry.proto.metrics.v1.IntHistogramDataPoint.exemplars:type_name -> opentelemetry.proto.metrics.v1.IntExemplar - 21, // 28: opentelemetry.proto.metrics.v1.DoubleHistogramDataPoint.labels:type_name -> opentelemetry.proto.common.v1.StringKeyValue - 17, // 29: opentelemetry.proto.metrics.v1.DoubleHistogramDataPoint.exemplars:type_name -> opentelemetry.proto.metrics.v1.DoubleExemplar - 21, // 30: opentelemetry.proto.metrics.v1.DoubleSummaryDataPoint.labels:type_name -> opentelemetry.proto.common.v1.StringKeyValue - 18, // 31: opentelemetry.proto.metrics.v1.DoubleSummaryDataPoint.quantile_values:type_name -> opentelemetry.proto.metrics.v1.DoubleSummaryDataPoint.ValueAtQuantile - 21, // 32: opentelemetry.proto.metrics.v1.IntExemplar.filtered_labels:type_name -> opentelemetry.proto.common.v1.StringKeyValue - 21, // 33: opentelemetry.proto.metrics.v1.DoubleExemplar.filtered_labels:type_name -> opentelemetry.proto.common.v1.StringKeyValue - 34, // [34:34] is the sub-list for method output_type - 34, // [34:34] is the sub-list for method input_type - 34, // [34:34] is the sub-list for extension type_name - 34, // [34:34] is the sub-list for extension extendee - 0, // [0:34] is the sub-list for field type_name -} - -func init() { file_opentelemetry_proto_metrics_v1_metrics_proto_init() } -func file_opentelemetry_proto_metrics_v1_metrics_proto_init() { - if File_opentelemetry_proto_metrics_v1_metrics_proto != nil { - return - } - if !protoimpl.UnsafeEnabled { - file_opentelemetry_proto_metrics_v1_metrics_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*ResourceMetrics); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_opentelemetry_proto_metrics_v1_metrics_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*InstrumentationLibraryMetrics); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_opentelemetry_proto_metrics_v1_metrics_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*Metric); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_opentelemetry_proto_metrics_v1_metrics_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*IntGauge); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_opentelemetry_proto_metrics_v1_metrics_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*DoubleGauge); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_opentelemetry_proto_metrics_v1_metrics_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*IntSum); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_opentelemetry_proto_metrics_v1_metrics_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*DoubleSum); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_opentelemetry_proto_metrics_v1_metrics_proto_msgTypes[7].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*IntHistogram); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_opentelemetry_proto_metrics_v1_metrics_proto_msgTypes[8].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*DoubleHistogram); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_opentelemetry_proto_metrics_v1_metrics_proto_msgTypes[9].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*DoubleSummary); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_opentelemetry_proto_metrics_v1_metrics_proto_msgTypes[10].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*IntDataPoint); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_opentelemetry_proto_metrics_v1_metrics_proto_msgTypes[11].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*DoubleDataPoint); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_opentelemetry_proto_metrics_v1_metrics_proto_msgTypes[12].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*IntHistogramDataPoint); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_opentelemetry_proto_metrics_v1_metrics_proto_msgTypes[13].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*DoubleHistogramDataPoint); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_opentelemetry_proto_metrics_v1_metrics_proto_msgTypes[14].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*DoubleSummaryDataPoint); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_opentelemetry_proto_metrics_v1_metrics_proto_msgTypes[15].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*IntExemplar); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_opentelemetry_proto_metrics_v1_metrics_proto_msgTypes[16].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*DoubleExemplar); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_opentelemetry_proto_metrics_v1_metrics_proto_msgTypes[17].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*DoubleSummaryDataPoint_ValueAtQuantile); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - } - file_opentelemetry_proto_metrics_v1_metrics_proto_msgTypes[2].OneofWrappers = []interface{}{ - (*Metric_IntGauge)(nil), - (*Metric_DoubleGauge)(nil), - (*Metric_IntSum)(nil), - (*Metric_DoubleSum)(nil), - (*Metric_IntHistogram)(nil), - (*Metric_DoubleHistogram)(nil), - (*Metric_DoubleSummary)(nil), - } - type x struct{} - out := protoimpl.TypeBuilder{ - File: protoimpl.DescBuilder{ - GoPackagePath: reflect.TypeOf(x{}).PkgPath(), - RawDescriptor: file_opentelemetry_proto_metrics_v1_metrics_proto_rawDesc, - NumEnums: 1, - NumMessages: 18, - NumExtensions: 0, - NumServices: 0, - }, - GoTypes: file_opentelemetry_proto_metrics_v1_metrics_proto_goTypes, - DependencyIndexes: file_opentelemetry_proto_metrics_v1_metrics_proto_depIdxs, - EnumInfos: file_opentelemetry_proto_metrics_v1_metrics_proto_enumTypes, - MessageInfos: file_opentelemetry_proto_metrics_v1_metrics_proto_msgTypes, - }.Build() - File_opentelemetry_proto_metrics_v1_metrics_proto = out.File - file_opentelemetry_proto_metrics_v1_metrics_proto_rawDesc = nil - file_opentelemetry_proto_metrics_v1_metrics_proto_goTypes = nil - file_opentelemetry_proto_metrics_v1_metrics_proto_depIdxs = nil -} diff --git a/vendor/go.opentelemetry.io/proto/otlp/resource/v1/resource.pb.go b/vendor/go.opentelemetry.io/proto/otlp/resource/v1/resource.pb.go deleted file mode 100644 index ac347acb23..0000000000 --- a/vendor/go.opentelemetry.io/proto/otlp/resource/v1/resource.pb.go +++ /dev/null @@ -1,194 +0,0 @@ -// Copyright 2019, OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Code generated by protoc-gen-go. DO NOT EDIT. -// versions: -// protoc-gen-go v1.23.0 -// protoc v3.13.0 -// source: opentelemetry/proto/resource/v1/resource.proto - -package v1 - -import ( - proto "github.com/golang/protobuf/proto" - v1 "go.opentelemetry.io/proto/otlp/common/v1" - protoreflect "google.golang.org/protobuf/reflect/protoreflect" - protoimpl "google.golang.org/protobuf/runtime/protoimpl" - reflect "reflect" - sync "sync" -) - -const ( - // Verify that this generated code is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) - // Verify that runtime/protoimpl is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) -) - -// This is a compile-time assertion that a sufficiently up-to-date version -// of the legacy proto package is being used. -const _ = proto.ProtoPackageIsVersion4 - -// Resource information. -type Resource struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - // Set of labels that describe the resource. - Attributes []*v1.KeyValue `protobuf:"bytes,1,rep,name=attributes,proto3" json:"attributes,omitempty"` - // dropped_attributes_count is the number of dropped attributes. If the value is 0, then - // no attributes were dropped. - DroppedAttributesCount uint32 `protobuf:"varint,2,opt,name=dropped_attributes_count,json=droppedAttributesCount,proto3" json:"dropped_attributes_count,omitempty"` -} - -func (x *Resource) Reset() { - *x = Resource{} - if protoimpl.UnsafeEnabled { - mi := &file_opentelemetry_proto_resource_v1_resource_proto_msgTypes[0] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *Resource) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*Resource) ProtoMessage() {} - -func (x *Resource) ProtoReflect() protoreflect.Message { - mi := &file_opentelemetry_proto_resource_v1_resource_proto_msgTypes[0] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use Resource.ProtoReflect.Descriptor instead. -func (*Resource) Descriptor() ([]byte, []int) { - return file_opentelemetry_proto_resource_v1_resource_proto_rawDescGZIP(), []int{0} -} - -func (x *Resource) GetAttributes() []*v1.KeyValue { - if x != nil { - return x.Attributes - } - return nil -} - -func (x *Resource) GetDroppedAttributesCount() uint32 { - if x != nil { - return x.DroppedAttributesCount - } - return 0 -} - -var File_opentelemetry_proto_resource_v1_resource_proto protoreflect.FileDescriptor - -var file_opentelemetry_proto_resource_v1_resource_proto_rawDesc = []byte{ - 0x0a, 0x2e, 0x6f, 0x70, 0x65, 0x6e, 0x74, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x74, 0x72, 0x79, 0x2f, - 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x2f, 0x76, - 0x31, 0x2f, 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x12, 0x1f, 0x6f, 0x70, 0x65, 0x6e, 0x74, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x74, 0x72, 0x79, 0x2e, - 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x2e, 0x76, - 0x31, 0x1a, 0x2a, 0x6f, 0x70, 0x65, 0x6e, 0x74, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x74, 0x72, 0x79, - 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2f, 0x76, 0x31, - 0x2f, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x8d, 0x01, - 0x0a, 0x08, 0x52, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x12, 0x47, 0x0a, 0x0a, 0x61, 0x74, - 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x27, - 0x2e, 0x6f, 0x70, 0x65, 0x6e, 0x74, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x74, 0x72, 0x79, 0x2e, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2e, 0x76, 0x31, 0x2e, 0x4b, - 0x65, 0x79, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x52, 0x0a, 0x61, 0x74, 0x74, 0x72, 0x69, 0x62, 0x75, - 0x74, 0x65, 0x73, 0x12, 0x38, 0x0a, 0x18, 0x64, 0x72, 0x6f, 0x70, 0x70, 0x65, 0x64, 0x5f, 0x61, - 0x74, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x73, 0x5f, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x18, - 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x16, 0x64, 0x72, 0x6f, 0x70, 0x70, 0x65, 0x64, 0x41, 0x74, - 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x73, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x42, 0x61, 0x0a, - 0x22, 0x69, 0x6f, 0x2e, 0x6f, 0x70, 0x65, 0x6e, 0x74, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x74, 0x72, - 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, - 0x2e, 0x76, 0x31, 0x42, 0x0d, 0x52, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x50, 0x72, 0x6f, - 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x2a, 0x67, 0x6f, 0x2e, 0x6f, 0x70, 0x65, 0x6e, 0x74, 0x65, 0x6c, - 0x65, 0x6d, 0x65, 0x74, 0x72, 0x79, 0x2e, 0x69, 0x6f, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, - 0x6f, 0x74, 0x6c, 0x70, 0x2f, 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x2f, 0x76, 0x31, - 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, -} - -var ( - file_opentelemetry_proto_resource_v1_resource_proto_rawDescOnce sync.Once - file_opentelemetry_proto_resource_v1_resource_proto_rawDescData = file_opentelemetry_proto_resource_v1_resource_proto_rawDesc -) - -func file_opentelemetry_proto_resource_v1_resource_proto_rawDescGZIP() []byte { - file_opentelemetry_proto_resource_v1_resource_proto_rawDescOnce.Do(func() { - file_opentelemetry_proto_resource_v1_resource_proto_rawDescData = protoimpl.X.CompressGZIP(file_opentelemetry_proto_resource_v1_resource_proto_rawDescData) - }) - return file_opentelemetry_proto_resource_v1_resource_proto_rawDescData -} - -var file_opentelemetry_proto_resource_v1_resource_proto_msgTypes = make([]protoimpl.MessageInfo, 1) -var file_opentelemetry_proto_resource_v1_resource_proto_goTypes = []interface{}{ - (*Resource)(nil), // 0: opentelemetry.proto.resource.v1.Resource - (*v1.KeyValue)(nil), // 1: opentelemetry.proto.common.v1.KeyValue -} -var file_opentelemetry_proto_resource_v1_resource_proto_depIdxs = []int32{ - 1, // 0: opentelemetry.proto.resource.v1.Resource.attributes:type_name -> opentelemetry.proto.common.v1.KeyValue - 1, // [1:1] is the sub-list for method output_type - 1, // [1:1] is the sub-list for method input_type - 1, // [1:1] is the sub-list for extension type_name - 1, // [1:1] is the sub-list for extension extendee - 0, // [0:1] is the sub-list for field type_name -} - -func init() { file_opentelemetry_proto_resource_v1_resource_proto_init() } -func file_opentelemetry_proto_resource_v1_resource_proto_init() { - if File_opentelemetry_proto_resource_v1_resource_proto != nil { - return - } - if !protoimpl.UnsafeEnabled { - file_opentelemetry_proto_resource_v1_resource_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*Resource); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - } - type x struct{} - out := protoimpl.TypeBuilder{ - File: protoimpl.DescBuilder{ - GoPackagePath: reflect.TypeOf(x{}).PkgPath(), - RawDescriptor: file_opentelemetry_proto_resource_v1_resource_proto_rawDesc, - NumEnums: 0, - NumMessages: 1, - NumExtensions: 0, - NumServices: 0, - }, - GoTypes: file_opentelemetry_proto_resource_v1_resource_proto_goTypes, - DependencyIndexes: file_opentelemetry_proto_resource_v1_resource_proto_depIdxs, - MessageInfos: file_opentelemetry_proto_resource_v1_resource_proto_msgTypes, - }.Build() - File_opentelemetry_proto_resource_v1_resource_proto = out.File - file_opentelemetry_proto_resource_v1_resource_proto_rawDesc = nil - file_opentelemetry_proto_resource_v1_resource_proto_goTypes = nil - file_opentelemetry_proto_resource_v1_resource_proto_depIdxs = nil -} diff --git a/vendor/go.opentelemetry.io/proto/otlp/trace/v1/trace.pb.go b/vendor/go.opentelemetry.io/proto/otlp/trace/v1/trace.pb.go deleted file mode 100644 index f37084af88..0000000000 --- a/vendor/go.opentelemetry.io/proto/otlp/trace/v1/trace.pb.go +++ /dev/null @@ -1,1206 +0,0 @@ -// Copyright 2019, OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Code generated by protoc-gen-go. DO NOT EDIT. -// versions: -// protoc-gen-go v1.23.0 -// protoc v3.13.0 -// source: opentelemetry/proto/trace/v1/trace.proto - -package v1 - -import ( - proto "github.com/golang/protobuf/proto" - v11 "go.opentelemetry.io/proto/otlp/common/v1" - v1 "go.opentelemetry.io/proto/otlp/resource/v1" - protoreflect "google.golang.org/protobuf/reflect/protoreflect" - protoimpl "google.golang.org/protobuf/runtime/protoimpl" - reflect "reflect" - sync "sync" -) - -const ( - // Verify that this generated code is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) - // Verify that runtime/protoimpl is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) -) - -// This is a compile-time assertion that a sufficiently up-to-date version -// of the legacy proto package is being used. -const _ = proto.ProtoPackageIsVersion4 - -// SpanKind is the type of span. Can be used to specify additional relationships between spans -// in addition to a parent/child relationship. -type Span_SpanKind int32 - -const ( - // Unspecified. Do NOT use as default. - // Implementations MAY assume SpanKind to be INTERNAL when receiving UNSPECIFIED. - Span_SPAN_KIND_UNSPECIFIED Span_SpanKind = 0 - // Indicates that the span represents an internal operation within an application, - // as opposed to an operations happening at the boundaries. Default value. - Span_SPAN_KIND_INTERNAL Span_SpanKind = 1 - // Indicates that the span covers server-side handling of an RPC or other - // remote network request. - Span_SPAN_KIND_SERVER Span_SpanKind = 2 - // Indicates that the span describes a request to some remote service. - Span_SPAN_KIND_CLIENT Span_SpanKind = 3 - // Indicates that the span describes a producer sending a message to a broker. - // Unlike CLIENT and SERVER, there is often no direct critical path latency relationship - // between producer and consumer spans. A PRODUCER span ends when the message was accepted - // by the broker while the logical processing of the message might span a much longer time. - Span_SPAN_KIND_PRODUCER Span_SpanKind = 4 - // Indicates that the span describes consumer receiving a message from a broker. - // Like the PRODUCER kind, there is often no direct critical path latency relationship - // between producer and consumer spans. - Span_SPAN_KIND_CONSUMER Span_SpanKind = 5 -) - -// Enum value maps for Span_SpanKind. -var ( - Span_SpanKind_name = map[int32]string{ - 0: "SPAN_KIND_UNSPECIFIED", - 1: "SPAN_KIND_INTERNAL", - 2: "SPAN_KIND_SERVER", - 3: "SPAN_KIND_CLIENT", - 4: "SPAN_KIND_PRODUCER", - 5: "SPAN_KIND_CONSUMER", - } - Span_SpanKind_value = map[string]int32{ - "SPAN_KIND_UNSPECIFIED": 0, - "SPAN_KIND_INTERNAL": 1, - "SPAN_KIND_SERVER": 2, - "SPAN_KIND_CLIENT": 3, - "SPAN_KIND_PRODUCER": 4, - "SPAN_KIND_CONSUMER": 5, - } -) - -func (x Span_SpanKind) Enum() *Span_SpanKind { - p := new(Span_SpanKind) - *p = x - return p -} - -func (x Span_SpanKind) String() string { - return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x)) -} - -func (Span_SpanKind) Descriptor() protoreflect.EnumDescriptor { - return file_opentelemetry_proto_trace_v1_trace_proto_enumTypes[0].Descriptor() -} - -func (Span_SpanKind) Type() protoreflect.EnumType { - return &file_opentelemetry_proto_trace_v1_trace_proto_enumTypes[0] -} - -func (x Span_SpanKind) Number() protoreflect.EnumNumber { - return protoreflect.EnumNumber(x) -} - -// Deprecated: Use Span_SpanKind.Descriptor instead. -func (Span_SpanKind) EnumDescriptor() ([]byte, []int) { - return file_opentelemetry_proto_trace_v1_trace_proto_rawDescGZIP(), []int{2, 0} -} - -type Status_DeprecatedStatusCode int32 - -const ( - Status_DEPRECATED_STATUS_CODE_OK Status_DeprecatedStatusCode = 0 - Status_DEPRECATED_STATUS_CODE_CANCELLED Status_DeprecatedStatusCode = 1 - Status_DEPRECATED_STATUS_CODE_UNKNOWN_ERROR Status_DeprecatedStatusCode = 2 - Status_DEPRECATED_STATUS_CODE_INVALID_ARGUMENT Status_DeprecatedStatusCode = 3 - Status_DEPRECATED_STATUS_CODE_DEADLINE_EXCEEDED Status_DeprecatedStatusCode = 4 - Status_DEPRECATED_STATUS_CODE_NOT_FOUND Status_DeprecatedStatusCode = 5 - Status_DEPRECATED_STATUS_CODE_ALREADY_EXISTS Status_DeprecatedStatusCode = 6 - Status_DEPRECATED_STATUS_CODE_PERMISSION_DENIED Status_DeprecatedStatusCode = 7 - Status_DEPRECATED_STATUS_CODE_RESOURCE_EXHAUSTED Status_DeprecatedStatusCode = 8 - Status_DEPRECATED_STATUS_CODE_FAILED_PRECONDITION Status_DeprecatedStatusCode = 9 - Status_DEPRECATED_STATUS_CODE_ABORTED Status_DeprecatedStatusCode = 10 - Status_DEPRECATED_STATUS_CODE_OUT_OF_RANGE Status_DeprecatedStatusCode = 11 - Status_DEPRECATED_STATUS_CODE_UNIMPLEMENTED Status_DeprecatedStatusCode = 12 - Status_DEPRECATED_STATUS_CODE_INTERNAL_ERROR Status_DeprecatedStatusCode = 13 - Status_DEPRECATED_STATUS_CODE_UNAVAILABLE Status_DeprecatedStatusCode = 14 - Status_DEPRECATED_STATUS_CODE_DATA_LOSS Status_DeprecatedStatusCode = 15 - Status_DEPRECATED_STATUS_CODE_UNAUTHENTICATED Status_DeprecatedStatusCode = 16 -) - -// Enum value maps for Status_DeprecatedStatusCode. -var ( - Status_DeprecatedStatusCode_name = map[int32]string{ - 0: "DEPRECATED_STATUS_CODE_OK", - 1: "DEPRECATED_STATUS_CODE_CANCELLED", - 2: "DEPRECATED_STATUS_CODE_UNKNOWN_ERROR", - 3: "DEPRECATED_STATUS_CODE_INVALID_ARGUMENT", - 4: "DEPRECATED_STATUS_CODE_DEADLINE_EXCEEDED", - 5: "DEPRECATED_STATUS_CODE_NOT_FOUND", - 6: "DEPRECATED_STATUS_CODE_ALREADY_EXISTS", - 7: "DEPRECATED_STATUS_CODE_PERMISSION_DENIED", - 8: "DEPRECATED_STATUS_CODE_RESOURCE_EXHAUSTED", - 9: "DEPRECATED_STATUS_CODE_FAILED_PRECONDITION", - 10: "DEPRECATED_STATUS_CODE_ABORTED", - 11: "DEPRECATED_STATUS_CODE_OUT_OF_RANGE", - 12: "DEPRECATED_STATUS_CODE_UNIMPLEMENTED", - 13: "DEPRECATED_STATUS_CODE_INTERNAL_ERROR", - 14: "DEPRECATED_STATUS_CODE_UNAVAILABLE", - 15: "DEPRECATED_STATUS_CODE_DATA_LOSS", - 16: "DEPRECATED_STATUS_CODE_UNAUTHENTICATED", - } - Status_DeprecatedStatusCode_value = map[string]int32{ - "DEPRECATED_STATUS_CODE_OK": 0, - "DEPRECATED_STATUS_CODE_CANCELLED": 1, - "DEPRECATED_STATUS_CODE_UNKNOWN_ERROR": 2, - "DEPRECATED_STATUS_CODE_INVALID_ARGUMENT": 3, - "DEPRECATED_STATUS_CODE_DEADLINE_EXCEEDED": 4, - "DEPRECATED_STATUS_CODE_NOT_FOUND": 5, - "DEPRECATED_STATUS_CODE_ALREADY_EXISTS": 6, - "DEPRECATED_STATUS_CODE_PERMISSION_DENIED": 7, - "DEPRECATED_STATUS_CODE_RESOURCE_EXHAUSTED": 8, - "DEPRECATED_STATUS_CODE_FAILED_PRECONDITION": 9, - "DEPRECATED_STATUS_CODE_ABORTED": 10, - "DEPRECATED_STATUS_CODE_OUT_OF_RANGE": 11, - "DEPRECATED_STATUS_CODE_UNIMPLEMENTED": 12, - "DEPRECATED_STATUS_CODE_INTERNAL_ERROR": 13, - "DEPRECATED_STATUS_CODE_UNAVAILABLE": 14, - "DEPRECATED_STATUS_CODE_DATA_LOSS": 15, - "DEPRECATED_STATUS_CODE_UNAUTHENTICATED": 16, - } -) - -func (x Status_DeprecatedStatusCode) Enum() *Status_DeprecatedStatusCode { - p := new(Status_DeprecatedStatusCode) - *p = x - return p -} - -func (x Status_DeprecatedStatusCode) String() string { - return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x)) -} - -func (Status_DeprecatedStatusCode) Descriptor() protoreflect.EnumDescriptor { - return file_opentelemetry_proto_trace_v1_trace_proto_enumTypes[1].Descriptor() -} - -func (Status_DeprecatedStatusCode) Type() protoreflect.EnumType { - return &file_opentelemetry_proto_trace_v1_trace_proto_enumTypes[1] -} - -func (x Status_DeprecatedStatusCode) Number() protoreflect.EnumNumber { - return protoreflect.EnumNumber(x) -} - -// Deprecated: Use Status_DeprecatedStatusCode.Descriptor instead. -func (Status_DeprecatedStatusCode) EnumDescriptor() ([]byte, []int) { - return file_opentelemetry_proto_trace_v1_trace_proto_rawDescGZIP(), []int{3, 0} -} - -// For the semantics of status codes see -// https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/api.md#set-status -type Status_StatusCode int32 - -const ( - // The default status. - Status_STATUS_CODE_UNSET Status_StatusCode = 0 - // The Span has been validated by an Application developers or Operator to have - // completed successfully. - Status_STATUS_CODE_OK Status_StatusCode = 1 - // The Span contains an error. - Status_STATUS_CODE_ERROR Status_StatusCode = 2 -) - -// Enum value maps for Status_StatusCode. -var ( - Status_StatusCode_name = map[int32]string{ - 0: "STATUS_CODE_UNSET", - 1: "STATUS_CODE_OK", - 2: "STATUS_CODE_ERROR", - } - Status_StatusCode_value = map[string]int32{ - "STATUS_CODE_UNSET": 0, - "STATUS_CODE_OK": 1, - "STATUS_CODE_ERROR": 2, - } -) - -func (x Status_StatusCode) Enum() *Status_StatusCode { - p := new(Status_StatusCode) - *p = x - return p -} - -func (x Status_StatusCode) String() string { - return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x)) -} - -func (Status_StatusCode) Descriptor() protoreflect.EnumDescriptor { - return file_opentelemetry_proto_trace_v1_trace_proto_enumTypes[2].Descriptor() -} - -func (Status_StatusCode) Type() protoreflect.EnumType { - return &file_opentelemetry_proto_trace_v1_trace_proto_enumTypes[2] -} - -func (x Status_StatusCode) Number() protoreflect.EnumNumber { - return protoreflect.EnumNumber(x) -} - -// Deprecated: Use Status_StatusCode.Descriptor instead. -func (Status_StatusCode) EnumDescriptor() ([]byte, []int) { - return file_opentelemetry_proto_trace_v1_trace_proto_rawDescGZIP(), []int{3, 1} -} - -// A collection of InstrumentationLibrarySpans from a Resource. -type ResourceSpans struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - // The resource for the spans in this message. - // If this field is not set then no resource info is known. - Resource *v1.Resource `protobuf:"bytes,1,opt,name=resource,proto3" json:"resource,omitempty"` - // A list of InstrumentationLibrarySpans that originate from a resource. - InstrumentationLibrarySpans []*InstrumentationLibrarySpans `protobuf:"bytes,2,rep,name=instrumentation_library_spans,json=instrumentationLibrarySpans,proto3" json:"instrumentation_library_spans,omitempty"` -} - -func (x *ResourceSpans) Reset() { - *x = ResourceSpans{} - if protoimpl.UnsafeEnabled { - mi := &file_opentelemetry_proto_trace_v1_trace_proto_msgTypes[0] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *ResourceSpans) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*ResourceSpans) ProtoMessage() {} - -func (x *ResourceSpans) ProtoReflect() protoreflect.Message { - mi := &file_opentelemetry_proto_trace_v1_trace_proto_msgTypes[0] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use ResourceSpans.ProtoReflect.Descriptor instead. -func (*ResourceSpans) Descriptor() ([]byte, []int) { - return file_opentelemetry_proto_trace_v1_trace_proto_rawDescGZIP(), []int{0} -} - -func (x *ResourceSpans) GetResource() *v1.Resource { - if x != nil { - return x.Resource - } - return nil -} - -func (x *ResourceSpans) GetInstrumentationLibrarySpans() []*InstrumentationLibrarySpans { - if x != nil { - return x.InstrumentationLibrarySpans - } - return nil -} - -// A collection of Spans produced by an InstrumentationLibrary. -type InstrumentationLibrarySpans struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - // The instrumentation library information for the spans in this message. - // Semantically when InstrumentationLibrary isn't set, it is equivalent with - // an empty instrumentation library name (unknown). - InstrumentationLibrary *v11.InstrumentationLibrary `protobuf:"bytes,1,opt,name=instrumentation_library,json=instrumentationLibrary,proto3" json:"instrumentation_library,omitempty"` - // A list of Spans that originate from an instrumentation library. - Spans []*Span `protobuf:"bytes,2,rep,name=spans,proto3" json:"spans,omitempty"` -} - -func (x *InstrumentationLibrarySpans) Reset() { - *x = InstrumentationLibrarySpans{} - if protoimpl.UnsafeEnabled { - mi := &file_opentelemetry_proto_trace_v1_trace_proto_msgTypes[1] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *InstrumentationLibrarySpans) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*InstrumentationLibrarySpans) ProtoMessage() {} - -func (x *InstrumentationLibrarySpans) ProtoReflect() protoreflect.Message { - mi := &file_opentelemetry_proto_trace_v1_trace_proto_msgTypes[1] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use InstrumentationLibrarySpans.ProtoReflect.Descriptor instead. -func (*InstrumentationLibrarySpans) Descriptor() ([]byte, []int) { - return file_opentelemetry_proto_trace_v1_trace_proto_rawDescGZIP(), []int{1} -} - -func (x *InstrumentationLibrarySpans) GetInstrumentationLibrary() *v11.InstrumentationLibrary { - if x != nil { - return x.InstrumentationLibrary - } - return nil -} - -func (x *InstrumentationLibrarySpans) GetSpans() []*Span { - if x != nil { - return x.Spans - } - return nil -} - -// Span represents a single operation within a trace. Spans can be -// nested to form a trace tree. Spans may also be linked to other spans -// from the same or different trace and form graphs. Often, a trace -// contains a root span that describes the end-to-end latency, and one -// or more subspans for its sub-operations. A trace can also contain -// multiple root spans, or none at all. Spans do not need to be -// contiguous - there may be gaps or overlaps between spans in a trace. -// -// The next available field id is 17. -type Span struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - // A unique identifier for a trace. All spans from the same trace share - // the same `trace_id`. The ID is a 16-byte array. An ID with all zeroes - // is considered invalid. - // - // This field is semantically required. Receiver should generate new - // random trace_id if empty or invalid trace_id was received. - // - // This field is required. - TraceId []byte `protobuf:"bytes,1,opt,name=trace_id,json=traceId,proto3" json:"trace_id,omitempty"` - // A unique identifier for a span within a trace, assigned when the span - // is created. The ID is an 8-byte array. An ID with all zeroes is considered - // invalid. - // - // This field is semantically required. Receiver should generate new - // random span_id if empty or invalid span_id was received. - // - // This field is required. - SpanId []byte `protobuf:"bytes,2,opt,name=span_id,json=spanId,proto3" json:"span_id,omitempty"` - // trace_state conveys information about request position in multiple distributed tracing graphs. - // It is a trace_state in w3c-trace-context format: https://www.w3.org/TR/trace-context/#tracestate-header - // See also https://github.com/w3c/distributed-tracing for more details about this field. - TraceState string `protobuf:"bytes,3,opt,name=trace_state,json=traceState,proto3" json:"trace_state,omitempty"` - // The `span_id` of this span's parent span. If this is a root span, then this - // field must be empty. The ID is an 8-byte array. - ParentSpanId []byte `protobuf:"bytes,4,opt,name=parent_span_id,json=parentSpanId,proto3" json:"parent_span_id,omitempty"` - // A description of the span's operation. - // - // For example, the name can be a qualified method name or a file name - // and a line number where the operation is called. A best practice is to use - // the same display name at the same call point in an application. - // This makes it easier to correlate spans in different traces. - // - // This field is semantically required to be set to non-empty string. - // When null or empty string received - receiver may use string "name" - // as a replacement. There might be smarted algorithms implemented by - // receiver to fix the empty span name. - // - // This field is required. - Name string `protobuf:"bytes,5,opt,name=name,proto3" json:"name,omitempty"` - // Distinguishes between spans generated in a particular context. For example, - // two spans with the same name may be distinguished using `CLIENT` (caller) - // and `SERVER` (callee) to identify queueing latency associated with the span. - Kind Span_SpanKind `protobuf:"varint,6,opt,name=kind,proto3,enum=opentelemetry.proto.trace.v1.Span_SpanKind" json:"kind,omitempty"` - // start_time_unix_nano is the start time of the span. On the client side, this is the time - // kept by the local machine where the span execution starts. On the server side, this - // is the time when the server's application handler starts running. - // Value is UNIX Epoch time in nanoseconds since 00:00:00 UTC on 1 January 1970. - // - // This field is semantically required and it is expected that end_time >= start_time. - StartTimeUnixNano uint64 `protobuf:"fixed64,7,opt,name=start_time_unix_nano,json=startTimeUnixNano,proto3" json:"start_time_unix_nano,omitempty"` - // end_time_unix_nano is the end time of the span. On the client side, this is the time - // kept by the local machine where the span execution ends. On the server side, this - // is the time when the server application handler stops running. - // Value is UNIX Epoch time in nanoseconds since 00:00:00 UTC on 1 January 1970. - // - // This field is semantically required and it is expected that end_time >= start_time. - EndTimeUnixNano uint64 `protobuf:"fixed64,8,opt,name=end_time_unix_nano,json=endTimeUnixNano,proto3" json:"end_time_unix_nano,omitempty"` - // attributes is a collection of key/value pairs. The value can be a string, - // an integer, a double or the Boolean values `true` or `false`. Note, global attributes - // like server name can be set using the resource API. Examples of attributes: - // - // "/http/user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36" - // "/http/server_latency": 300 - // "abc.com/myattribute": true - // "abc.com/score": 10.239 - Attributes []*v11.KeyValue `protobuf:"bytes,9,rep,name=attributes,proto3" json:"attributes,omitempty"` - // dropped_attributes_count is the number of attributes that were discarded. Attributes - // can be discarded because their keys are too long or because there are too many - // attributes. If this value is 0, then no attributes were dropped. - DroppedAttributesCount uint32 `protobuf:"varint,10,opt,name=dropped_attributes_count,json=droppedAttributesCount,proto3" json:"dropped_attributes_count,omitempty"` - // events is a collection of Event items. - Events []*Span_Event `protobuf:"bytes,11,rep,name=events,proto3" json:"events,omitempty"` - // dropped_events_count is the number of dropped events. If the value is 0, then no - // events were dropped. - DroppedEventsCount uint32 `protobuf:"varint,12,opt,name=dropped_events_count,json=droppedEventsCount,proto3" json:"dropped_events_count,omitempty"` - // links is a collection of Links, which are references from this span to a span - // in the same or different trace. - Links []*Span_Link `protobuf:"bytes,13,rep,name=links,proto3" json:"links,omitempty"` - // dropped_links_count is the number of dropped links after the maximum size was - // enforced. If this value is 0, then no links were dropped. - DroppedLinksCount uint32 `protobuf:"varint,14,opt,name=dropped_links_count,json=droppedLinksCount,proto3" json:"dropped_links_count,omitempty"` - // An optional final status for this span. Semantically when Status isn't set, it means - // span's status code is unset, i.e. assume STATUS_CODE_UNSET (code = 0). - Status *Status `protobuf:"bytes,15,opt,name=status,proto3" json:"status,omitempty"` -} - -func (x *Span) Reset() { - *x = Span{} - if protoimpl.UnsafeEnabled { - mi := &file_opentelemetry_proto_trace_v1_trace_proto_msgTypes[2] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *Span) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*Span) ProtoMessage() {} - -func (x *Span) ProtoReflect() protoreflect.Message { - mi := &file_opentelemetry_proto_trace_v1_trace_proto_msgTypes[2] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use Span.ProtoReflect.Descriptor instead. -func (*Span) Descriptor() ([]byte, []int) { - return file_opentelemetry_proto_trace_v1_trace_proto_rawDescGZIP(), []int{2} -} - -func (x *Span) GetTraceId() []byte { - if x != nil { - return x.TraceId - } - return nil -} - -func (x *Span) GetSpanId() []byte { - if x != nil { - return x.SpanId - } - return nil -} - -func (x *Span) GetTraceState() string { - if x != nil { - return x.TraceState - } - return "" -} - -func (x *Span) GetParentSpanId() []byte { - if x != nil { - return x.ParentSpanId - } - return nil -} - -func (x *Span) GetName() string { - if x != nil { - return x.Name - } - return "" -} - -func (x *Span) GetKind() Span_SpanKind { - if x != nil { - return x.Kind - } - return Span_SPAN_KIND_UNSPECIFIED -} - -func (x *Span) GetStartTimeUnixNano() uint64 { - if x != nil { - return x.StartTimeUnixNano - } - return 0 -} - -func (x *Span) GetEndTimeUnixNano() uint64 { - if x != nil { - return x.EndTimeUnixNano - } - return 0 -} - -func (x *Span) GetAttributes() []*v11.KeyValue { - if x != nil { - return x.Attributes - } - return nil -} - -func (x *Span) GetDroppedAttributesCount() uint32 { - if x != nil { - return x.DroppedAttributesCount - } - return 0 -} - -func (x *Span) GetEvents() []*Span_Event { - if x != nil { - return x.Events - } - return nil -} - -func (x *Span) GetDroppedEventsCount() uint32 { - if x != nil { - return x.DroppedEventsCount - } - return 0 -} - -func (x *Span) GetLinks() []*Span_Link { - if x != nil { - return x.Links - } - return nil -} - -func (x *Span) GetDroppedLinksCount() uint32 { - if x != nil { - return x.DroppedLinksCount - } - return 0 -} - -func (x *Span) GetStatus() *Status { - if x != nil { - return x.Status - } - return nil -} - -// The Status type defines a logical error model that is suitable for different -// programming environments, including REST APIs and RPC APIs. -type Status struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - // The deprecated status code. This is an optional field. - // - // This field is deprecated and is replaced by the `code` field below. See backward - // compatibility notes below. According to our stability guarantees this field - // will be removed in 12 months, on Oct 22, 2021. All usage of old senders and - // receivers that do not understand the `code` field MUST be phased out by then. - // - // Deprecated: Do not use. - DeprecatedCode Status_DeprecatedStatusCode `protobuf:"varint,1,opt,name=deprecated_code,json=deprecatedCode,proto3,enum=opentelemetry.proto.trace.v1.Status_DeprecatedStatusCode" json:"deprecated_code,omitempty"` - // A developer-facing human readable error message. - Message string `protobuf:"bytes,2,opt,name=message,proto3" json:"message,omitempty"` - // The status code. - Code Status_StatusCode `protobuf:"varint,3,opt,name=code,proto3,enum=opentelemetry.proto.trace.v1.Status_StatusCode" json:"code,omitempty"` -} - -func (x *Status) Reset() { - *x = Status{} - if protoimpl.UnsafeEnabled { - mi := &file_opentelemetry_proto_trace_v1_trace_proto_msgTypes[3] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *Status) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*Status) ProtoMessage() {} - -func (x *Status) ProtoReflect() protoreflect.Message { - mi := &file_opentelemetry_proto_trace_v1_trace_proto_msgTypes[3] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use Status.ProtoReflect.Descriptor instead. -func (*Status) Descriptor() ([]byte, []int) { - return file_opentelemetry_proto_trace_v1_trace_proto_rawDescGZIP(), []int{3} -} - -// Deprecated: Do not use. -func (x *Status) GetDeprecatedCode() Status_DeprecatedStatusCode { - if x != nil { - return x.DeprecatedCode - } - return Status_DEPRECATED_STATUS_CODE_OK -} - -func (x *Status) GetMessage() string { - if x != nil { - return x.Message - } - return "" -} - -func (x *Status) GetCode() Status_StatusCode { - if x != nil { - return x.Code - } - return Status_STATUS_CODE_UNSET -} - -// Event is a time-stamped annotation of the span, consisting of user-supplied -// text description and key-value pairs. -type Span_Event struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - // time_unix_nano is the time the event occurred. - TimeUnixNano uint64 `protobuf:"fixed64,1,opt,name=time_unix_nano,json=timeUnixNano,proto3" json:"time_unix_nano,omitempty"` - // name of the event. - // This field is semantically required to be set to non-empty string. - Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"` - // attributes is a collection of attribute key/value pairs on the event. - Attributes []*v11.KeyValue `protobuf:"bytes,3,rep,name=attributes,proto3" json:"attributes,omitempty"` - // dropped_attributes_count is the number of dropped attributes. If the value is 0, - // then no attributes were dropped. - DroppedAttributesCount uint32 `protobuf:"varint,4,opt,name=dropped_attributes_count,json=droppedAttributesCount,proto3" json:"dropped_attributes_count,omitempty"` -} - -func (x *Span_Event) Reset() { - *x = Span_Event{} - if protoimpl.UnsafeEnabled { - mi := &file_opentelemetry_proto_trace_v1_trace_proto_msgTypes[4] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *Span_Event) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*Span_Event) ProtoMessage() {} - -func (x *Span_Event) ProtoReflect() protoreflect.Message { - mi := &file_opentelemetry_proto_trace_v1_trace_proto_msgTypes[4] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use Span_Event.ProtoReflect.Descriptor instead. -func (*Span_Event) Descriptor() ([]byte, []int) { - return file_opentelemetry_proto_trace_v1_trace_proto_rawDescGZIP(), []int{2, 0} -} - -func (x *Span_Event) GetTimeUnixNano() uint64 { - if x != nil { - return x.TimeUnixNano - } - return 0 -} - -func (x *Span_Event) GetName() string { - if x != nil { - return x.Name - } - return "" -} - -func (x *Span_Event) GetAttributes() []*v11.KeyValue { - if x != nil { - return x.Attributes - } - return nil -} - -func (x *Span_Event) GetDroppedAttributesCount() uint32 { - if x != nil { - return x.DroppedAttributesCount - } - return 0 -} - -// A pointer from the current span to another span in the same trace or in a -// different trace. For example, this can be used in batching operations, -// where a single batch handler processes multiple requests from different -// traces or when the handler receives a request from a different project. -type Span_Link struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - // A unique identifier of a trace that this linked span is part of. The ID is a - // 16-byte array. - TraceId []byte `protobuf:"bytes,1,opt,name=trace_id,json=traceId,proto3" json:"trace_id,omitempty"` - // A unique identifier for the linked span. The ID is an 8-byte array. - SpanId []byte `protobuf:"bytes,2,opt,name=span_id,json=spanId,proto3" json:"span_id,omitempty"` - // The trace_state associated with the link. - TraceState string `protobuf:"bytes,3,opt,name=trace_state,json=traceState,proto3" json:"trace_state,omitempty"` - // attributes is a collection of attribute key/value pairs on the link. - Attributes []*v11.KeyValue `protobuf:"bytes,4,rep,name=attributes,proto3" json:"attributes,omitempty"` - // dropped_attributes_count is the number of dropped attributes. If the value is 0, - // then no attributes were dropped. - DroppedAttributesCount uint32 `protobuf:"varint,5,opt,name=dropped_attributes_count,json=droppedAttributesCount,proto3" json:"dropped_attributes_count,omitempty"` -} - -func (x *Span_Link) Reset() { - *x = Span_Link{} - if protoimpl.UnsafeEnabled { - mi := &file_opentelemetry_proto_trace_v1_trace_proto_msgTypes[5] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *Span_Link) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*Span_Link) ProtoMessage() {} - -func (x *Span_Link) ProtoReflect() protoreflect.Message { - mi := &file_opentelemetry_proto_trace_v1_trace_proto_msgTypes[5] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use Span_Link.ProtoReflect.Descriptor instead. -func (*Span_Link) Descriptor() ([]byte, []int) { - return file_opentelemetry_proto_trace_v1_trace_proto_rawDescGZIP(), []int{2, 1} -} - -func (x *Span_Link) GetTraceId() []byte { - if x != nil { - return x.TraceId - } - return nil -} - -func (x *Span_Link) GetSpanId() []byte { - if x != nil { - return x.SpanId - } - return nil -} - -func (x *Span_Link) GetTraceState() string { - if x != nil { - return x.TraceState - } - return "" -} - -func (x *Span_Link) GetAttributes() []*v11.KeyValue { - if x != nil { - return x.Attributes - } - return nil -} - -func (x *Span_Link) GetDroppedAttributesCount() uint32 { - if x != nil { - return x.DroppedAttributesCount - } - return 0 -} - -var File_opentelemetry_proto_trace_v1_trace_proto protoreflect.FileDescriptor - -var file_opentelemetry_proto_trace_v1_trace_proto_rawDesc = []byte{ - 0x0a, 0x28, 0x6f, 0x70, 0x65, 0x6e, 0x74, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x74, 0x72, 0x79, 0x2f, - 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x74, 0x72, 0x61, 0x63, 0x65, 0x2f, 0x76, 0x31, 0x2f, 0x74, - 0x72, 0x61, 0x63, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x1c, 0x6f, 0x70, 0x65, 0x6e, - 0x74, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x74, 0x72, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, - 0x74, 0x72, 0x61, 0x63, 0x65, 0x2e, 0x76, 0x31, 0x1a, 0x2a, 0x6f, 0x70, 0x65, 0x6e, 0x74, 0x65, - 0x6c, 0x65, 0x6d, 0x65, 0x74, 0x72, 0x79, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x63, 0x6f, - 0x6d, 0x6d, 0x6f, 0x6e, 0x2f, 0x76, 0x31, 0x2f, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2e, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x2e, 0x6f, 0x70, 0x65, 0x6e, 0x74, 0x65, 0x6c, 0x65, 0x6d, 0x65, - 0x74, 0x72, 0x79, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, - 0x63, 0x65, 0x2f, 0x76, 0x31, 0x2f, 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x2e, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xd5, 0x01, 0x0a, 0x0d, 0x52, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, - 0x65, 0x53, 0x70, 0x61, 0x6e, 0x73, 0x12, 0x45, 0x0a, 0x08, 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, - 0x63, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x29, 0x2e, 0x6f, 0x70, 0x65, 0x6e, 0x74, - 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x74, 0x72, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x72, - 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x52, 0x65, 0x73, 0x6f, 0x75, - 0x72, 0x63, 0x65, 0x52, 0x08, 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x12, 0x7d, 0x0a, - 0x1d, 0x69, 0x6e, 0x73, 0x74, 0x72, 0x75, 0x6d, 0x65, 0x6e, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, - 0x5f, 0x6c, 0x69, 0x62, 0x72, 0x61, 0x72, 0x79, 0x5f, 0x73, 0x70, 0x61, 0x6e, 0x73, 0x18, 0x02, - 0x20, 0x03, 0x28, 0x0b, 0x32, 0x39, 0x2e, 0x6f, 0x70, 0x65, 0x6e, 0x74, 0x65, 0x6c, 0x65, 0x6d, - 0x65, 0x74, 0x72, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x74, 0x72, 0x61, 0x63, 0x65, - 0x2e, 0x76, 0x31, 0x2e, 0x49, 0x6e, 0x73, 0x74, 0x72, 0x75, 0x6d, 0x65, 0x6e, 0x74, 0x61, 0x74, - 0x69, 0x6f, 0x6e, 0x4c, 0x69, 0x62, 0x72, 0x61, 0x72, 0x79, 0x53, 0x70, 0x61, 0x6e, 0x73, 0x52, - 0x1b, 0x69, 0x6e, 0x73, 0x74, 0x72, 0x75, 0x6d, 0x65, 0x6e, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, - 0x4c, 0x69, 0x62, 0x72, 0x61, 0x72, 0x79, 0x53, 0x70, 0x61, 0x6e, 0x73, 0x22, 0xc7, 0x01, 0x0a, - 0x1b, 0x49, 0x6e, 0x73, 0x74, 0x72, 0x75, 0x6d, 0x65, 0x6e, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, - 0x4c, 0x69, 0x62, 0x72, 0x61, 0x72, 0x79, 0x53, 0x70, 0x61, 0x6e, 0x73, 0x12, 0x6e, 0x0a, 0x17, - 0x69, 0x6e, 0x73, 0x74, 0x72, 0x75, 0x6d, 0x65, 0x6e, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x5f, - 0x6c, 0x69, 0x62, 0x72, 0x61, 0x72, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x35, 0x2e, - 0x6f, 0x70, 0x65, 0x6e, 0x74, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x74, 0x72, 0x79, 0x2e, 0x70, 0x72, - 0x6f, 0x74, 0x6f, 0x2e, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2e, 0x76, 0x31, 0x2e, 0x49, 0x6e, - 0x73, 0x74, 0x72, 0x75, 0x6d, 0x65, 0x6e, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x4c, 0x69, 0x62, - 0x72, 0x61, 0x72, 0x79, 0x52, 0x16, 0x69, 0x6e, 0x73, 0x74, 0x72, 0x75, 0x6d, 0x65, 0x6e, 0x74, - 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x4c, 0x69, 0x62, 0x72, 0x61, 0x72, 0x79, 0x12, 0x38, 0x0a, 0x05, - 0x73, 0x70, 0x61, 0x6e, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x22, 0x2e, 0x6f, 0x70, - 0x65, 0x6e, 0x74, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x74, 0x72, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, - 0x6f, 0x2e, 0x74, 0x72, 0x61, 0x63, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x70, 0x61, 0x6e, 0x52, - 0x05, 0x73, 0x70, 0x61, 0x6e, 0x73, 0x22, 0x9c, 0x0a, 0x0a, 0x04, 0x53, 0x70, 0x61, 0x6e, 0x12, - 0x19, 0x0a, 0x08, 0x74, 0x72, 0x61, 0x63, 0x65, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, - 0x0c, 0x52, 0x07, 0x74, 0x72, 0x61, 0x63, 0x65, 0x49, 0x64, 0x12, 0x17, 0x0a, 0x07, 0x73, 0x70, - 0x61, 0x6e, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x06, 0x73, 0x70, 0x61, - 0x6e, 0x49, 0x64, 0x12, 0x1f, 0x0a, 0x0b, 0x74, 0x72, 0x61, 0x63, 0x65, 0x5f, 0x73, 0x74, 0x61, - 0x74, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x74, 0x72, 0x61, 0x63, 0x65, 0x53, - 0x74, 0x61, 0x74, 0x65, 0x12, 0x24, 0x0a, 0x0e, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x5f, 0x73, - 0x70, 0x61, 0x6e, 0x5f, 0x69, 0x64, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0c, 0x70, 0x61, - 0x72, 0x65, 0x6e, 0x74, 0x53, 0x70, 0x61, 0x6e, 0x49, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, - 0x6d, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x3f, - 0x0a, 0x04, 0x6b, 0x69, 0x6e, 0x64, 0x18, 0x06, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x2b, 0x2e, 0x6f, - 0x70, 0x65, 0x6e, 0x74, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x74, 0x72, 0x79, 0x2e, 0x70, 0x72, 0x6f, - 0x74, 0x6f, 0x2e, 0x74, 0x72, 0x61, 0x63, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x70, 0x61, 0x6e, - 0x2e, 0x53, 0x70, 0x61, 0x6e, 0x4b, 0x69, 0x6e, 0x64, 0x52, 0x04, 0x6b, 0x69, 0x6e, 0x64, 0x12, - 0x2f, 0x0a, 0x14, 0x73, 0x74, 0x61, 0x72, 0x74, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x5f, 0x75, 0x6e, - 0x69, 0x78, 0x5f, 0x6e, 0x61, 0x6e, 0x6f, 0x18, 0x07, 0x20, 0x01, 0x28, 0x06, 0x52, 0x11, 0x73, - 0x74, 0x61, 0x72, 0x74, 0x54, 0x69, 0x6d, 0x65, 0x55, 0x6e, 0x69, 0x78, 0x4e, 0x61, 0x6e, 0x6f, - 0x12, 0x2b, 0x0a, 0x12, 0x65, 0x6e, 0x64, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x5f, 0x75, 0x6e, 0x69, - 0x78, 0x5f, 0x6e, 0x61, 0x6e, 0x6f, 0x18, 0x08, 0x20, 0x01, 0x28, 0x06, 0x52, 0x0f, 0x65, 0x6e, - 0x64, 0x54, 0x69, 0x6d, 0x65, 0x55, 0x6e, 0x69, 0x78, 0x4e, 0x61, 0x6e, 0x6f, 0x12, 0x47, 0x0a, - 0x0a, 0x61, 0x74, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x73, 0x18, 0x09, 0x20, 0x03, 0x28, - 0x0b, 0x32, 0x27, 0x2e, 0x6f, 0x70, 0x65, 0x6e, 0x74, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x74, 0x72, - 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2e, 0x76, - 0x31, 0x2e, 0x4b, 0x65, 0x79, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x52, 0x0a, 0x61, 0x74, 0x74, 0x72, - 0x69, 0x62, 0x75, 0x74, 0x65, 0x73, 0x12, 0x38, 0x0a, 0x18, 0x64, 0x72, 0x6f, 0x70, 0x70, 0x65, - 0x64, 0x5f, 0x61, 0x74, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x73, 0x5f, 0x63, 0x6f, 0x75, - 0x6e, 0x74, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x16, 0x64, 0x72, 0x6f, 0x70, 0x70, 0x65, - 0x64, 0x41, 0x74, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x73, 0x43, 0x6f, 0x75, 0x6e, 0x74, - 0x12, 0x40, 0x0a, 0x06, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x73, 0x18, 0x0b, 0x20, 0x03, 0x28, 0x0b, - 0x32, 0x28, 0x2e, 0x6f, 0x70, 0x65, 0x6e, 0x74, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x74, 0x72, 0x79, - 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x74, 0x72, 0x61, 0x63, 0x65, 0x2e, 0x76, 0x31, 0x2e, - 0x53, 0x70, 0x61, 0x6e, 0x2e, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x52, 0x06, 0x65, 0x76, 0x65, 0x6e, - 0x74, 0x73, 0x12, 0x30, 0x0a, 0x14, 0x64, 0x72, 0x6f, 0x70, 0x70, 0x65, 0x64, 0x5f, 0x65, 0x76, - 0x65, 0x6e, 0x74, 0x73, 0x5f, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x0c, 0x20, 0x01, 0x28, 0x0d, - 0x52, 0x12, 0x64, 0x72, 0x6f, 0x70, 0x70, 0x65, 0x64, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x73, 0x43, - 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x3d, 0x0a, 0x05, 0x6c, 0x69, 0x6e, 0x6b, 0x73, 0x18, 0x0d, 0x20, - 0x03, 0x28, 0x0b, 0x32, 0x27, 0x2e, 0x6f, 0x70, 0x65, 0x6e, 0x74, 0x65, 0x6c, 0x65, 0x6d, 0x65, - 0x74, 0x72, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x74, 0x72, 0x61, 0x63, 0x65, 0x2e, - 0x76, 0x31, 0x2e, 0x53, 0x70, 0x61, 0x6e, 0x2e, 0x4c, 0x69, 0x6e, 0x6b, 0x52, 0x05, 0x6c, 0x69, - 0x6e, 0x6b, 0x73, 0x12, 0x2e, 0x0a, 0x13, 0x64, 0x72, 0x6f, 0x70, 0x70, 0x65, 0x64, 0x5f, 0x6c, - 0x69, 0x6e, 0x6b, 0x73, 0x5f, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x0e, 0x20, 0x01, 0x28, 0x0d, - 0x52, 0x11, 0x64, 0x72, 0x6f, 0x70, 0x70, 0x65, 0x64, 0x4c, 0x69, 0x6e, 0x6b, 0x73, 0x43, 0x6f, - 0x75, 0x6e, 0x74, 0x12, 0x3c, 0x0a, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x0f, 0x20, - 0x01, 0x28, 0x0b, 0x32, 0x24, 0x2e, 0x6f, 0x70, 0x65, 0x6e, 0x74, 0x65, 0x6c, 0x65, 0x6d, 0x65, - 0x74, 0x72, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x74, 0x72, 0x61, 0x63, 0x65, 0x2e, - 0x76, 0x31, 0x2e, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, - 0x73, 0x1a, 0xc4, 0x01, 0x0a, 0x05, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x12, 0x24, 0x0a, 0x0e, 0x74, - 0x69, 0x6d, 0x65, 0x5f, 0x75, 0x6e, 0x69, 0x78, 0x5f, 0x6e, 0x61, 0x6e, 0x6f, 0x18, 0x01, 0x20, - 0x01, 0x28, 0x06, 0x52, 0x0c, 0x74, 0x69, 0x6d, 0x65, 0x55, 0x6e, 0x69, 0x78, 0x4e, 0x61, 0x6e, - 0x6f, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, - 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x47, 0x0a, 0x0a, 0x61, 0x74, 0x74, 0x72, 0x69, 0x62, 0x75, - 0x74, 0x65, 0x73, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x27, 0x2e, 0x6f, 0x70, 0x65, 0x6e, - 0x74, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x74, 0x72, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, - 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2e, 0x76, 0x31, 0x2e, 0x4b, 0x65, 0x79, 0x56, 0x61, 0x6c, - 0x75, 0x65, 0x52, 0x0a, 0x61, 0x74, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x73, 0x12, 0x38, - 0x0a, 0x18, 0x64, 0x72, 0x6f, 0x70, 0x70, 0x65, 0x64, 0x5f, 0x61, 0x74, 0x74, 0x72, 0x69, 0x62, - 0x75, 0x74, 0x65, 0x73, 0x5f, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0d, - 0x52, 0x16, 0x64, 0x72, 0x6f, 0x70, 0x70, 0x65, 0x64, 0x41, 0x74, 0x74, 0x72, 0x69, 0x62, 0x75, - 0x74, 0x65, 0x73, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x1a, 0xde, 0x01, 0x0a, 0x04, 0x4c, 0x69, 0x6e, - 0x6b, 0x12, 0x19, 0x0a, 0x08, 0x74, 0x72, 0x61, 0x63, 0x65, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, - 0x01, 0x28, 0x0c, 0x52, 0x07, 0x74, 0x72, 0x61, 0x63, 0x65, 0x49, 0x64, 0x12, 0x17, 0x0a, 0x07, - 0x73, 0x70, 0x61, 0x6e, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x06, 0x73, - 0x70, 0x61, 0x6e, 0x49, 0x64, 0x12, 0x1f, 0x0a, 0x0b, 0x74, 0x72, 0x61, 0x63, 0x65, 0x5f, 0x73, - 0x74, 0x61, 0x74, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x74, 0x72, 0x61, 0x63, - 0x65, 0x53, 0x74, 0x61, 0x74, 0x65, 0x12, 0x47, 0x0a, 0x0a, 0x61, 0x74, 0x74, 0x72, 0x69, 0x62, - 0x75, 0x74, 0x65, 0x73, 0x18, 0x04, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x27, 0x2e, 0x6f, 0x70, 0x65, - 0x6e, 0x74, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x74, 0x72, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x2e, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2e, 0x76, 0x31, 0x2e, 0x4b, 0x65, 0x79, 0x56, 0x61, - 0x6c, 0x75, 0x65, 0x52, 0x0a, 0x61, 0x74, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x73, 0x12, - 0x38, 0x0a, 0x18, 0x64, 0x72, 0x6f, 0x70, 0x70, 0x65, 0x64, 0x5f, 0x61, 0x74, 0x74, 0x72, 0x69, - 0x62, 0x75, 0x74, 0x65, 0x73, 0x5f, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x05, 0x20, 0x01, 0x28, - 0x0d, 0x52, 0x16, 0x64, 0x72, 0x6f, 0x70, 0x70, 0x65, 0x64, 0x41, 0x74, 0x74, 0x72, 0x69, 0x62, - 0x75, 0x74, 0x65, 0x73, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x22, 0x99, 0x01, 0x0a, 0x08, 0x53, 0x70, - 0x61, 0x6e, 0x4b, 0x69, 0x6e, 0x64, 0x12, 0x19, 0x0a, 0x15, 0x53, 0x50, 0x41, 0x4e, 0x5f, 0x4b, - 0x49, 0x4e, 0x44, 0x5f, 0x55, 0x4e, 0x53, 0x50, 0x45, 0x43, 0x49, 0x46, 0x49, 0x45, 0x44, 0x10, - 0x00, 0x12, 0x16, 0x0a, 0x12, 0x53, 0x50, 0x41, 0x4e, 0x5f, 0x4b, 0x49, 0x4e, 0x44, 0x5f, 0x49, - 0x4e, 0x54, 0x45, 0x52, 0x4e, 0x41, 0x4c, 0x10, 0x01, 0x12, 0x14, 0x0a, 0x10, 0x53, 0x50, 0x41, - 0x4e, 0x5f, 0x4b, 0x49, 0x4e, 0x44, 0x5f, 0x53, 0x45, 0x52, 0x56, 0x45, 0x52, 0x10, 0x02, 0x12, - 0x14, 0x0a, 0x10, 0x53, 0x50, 0x41, 0x4e, 0x5f, 0x4b, 0x49, 0x4e, 0x44, 0x5f, 0x43, 0x4c, 0x49, - 0x45, 0x4e, 0x54, 0x10, 0x03, 0x12, 0x16, 0x0a, 0x12, 0x53, 0x50, 0x41, 0x4e, 0x5f, 0x4b, 0x49, - 0x4e, 0x44, 0x5f, 0x50, 0x52, 0x4f, 0x44, 0x55, 0x43, 0x45, 0x52, 0x10, 0x04, 0x12, 0x16, 0x0a, - 0x12, 0x53, 0x50, 0x41, 0x4e, 0x5f, 0x4b, 0x49, 0x4e, 0x44, 0x5f, 0x43, 0x4f, 0x4e, 0x53, 0x55, - 0x4d, 0x45, 0x52, 0x10, 0x05, 0x22, 0xfc, 0x07, 0x0a, 0x06, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, - 0x12, 0x66, 0x0a, 0x0f, 0x64, 0x65, 0x70, 0x72, 0x65, 0x63, 0x61, 0x74, 0x65, 0x64, 0x5f, 0x63, - 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x39, 0x2e, 0x6f, 0x70, 0x65, 0x6e, - 0x74, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x74, 0x72, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, - 0x74, 0x72, 0x61, 0x63, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x2e, - 0x44, 0x65, 0x70, 0x72, 0x65, 0x63, 0x61, 0x74, 0x65, 0x64, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, - 0x43, 0x6f, 0x64, 0x65, 0x42, 0x02, 0x18, 0x01, 0x52, 0x0e, 0x64, 0x65, 0x70, 0x72, 0x65, 0x63, - 0x61, 0x74, 0x65, 0x64, 0x43, 0x6f, 0x64, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, - 0x61, 0x67, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, - 0x67, 0x65, 0x12, 0x43, 0x0a, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0e, - 0x32, 0x2f, 0x2e, 0x6f, 0x70, 0x65, 0x6e, 0x74, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x74, 0x72, 0x79, - 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x74, 0x72, 0x61, 0x63, 0x65, 0x2e, 0x76, 0x31, 0x2e, - 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x2e, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x43, 0x6f, 0x64, - 0x65, 0x52, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x22, 0xda, 0x05, 0x0a, 0x14, 0x44, 0x65, 0x70, 0x72, - 0x65, 0x63, 0x61, 0x74, 0x65, 0x64, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x43, 0x6f, 0x64, 0x65, - 0x12, 0x1d, 0x0a, 0x19, 0x44, 0x45, 0x50, 0x52, 0x45, 0x43, 0x41, 0x54, 0x45, 0x44, 0x5f, 0x53, - 0x54, 0x41, 0x54, 0x55, 0x53, 0x5f, 0x43, 0x4f, 0x44, 0x45, 0x5f, 0x4f, 0x4b, 0x10, 0x00, 0x12, - 0x24, 0x0a, 0x20, 0x44, 0x45, 0x50, 0x52, 0x45, 0x43, 0x41, 0x54, 0x45, 0x44, 0x5f, 0x53, 0x54, - 0x41, 0x54, 0x55, 0x53, 0x5f, 0x43, 0x4f, 0x44, 0x45, 0x5f, 0x43, 0x41, 0x4e, 0x43, 0x45, 0x4c, - 0x4c, 0x45, 0x44, 0x10, 0x01, 0x12, 0x28, 0x0a, 0x24, 0x44, 0x45, 0x50, 0x52, 0x45, 0x43, 0x41, - 0x54, 0x45, 0x44, 0x5f, 0x53, 0x54, 0x41, 0x54, 0x55, 0x53, 0x5f, 0x43, 0x4f, 0x44, 0x45, 0x5f, - 0x55, 0x4e, 0x4b, 0x4e, 0x4f, 0x57, 0x4e, 0x5f, 0x45, 0x52, 0x52, 0x4f, 0x52, 0x10, 0x02, 0x12, - 0x2b, 0x0a, 0x27, 0x44, 0x45, 0x50, 0x52, 0x45, 0x43, 0x41, 0x54, 0x45, 0x44, 0x5f, 0x53, 0x54, - 0x41, 0x54, 0x55, 0x53, 0x5f, 0x43, 0x4f, 0x44, 0x45, 0x5f, 0x49, 0x4e, 0x56, 0x41, 0x4c, 0x49, - 0x44, 0x5f, 0x41, 0x52, 0x47, 0x55, 0x4d, 0x45, 0x4e, 0x54, 0x10, 0x03, 0x12, 0x2c, 0x0a, 0x28, - 0x44, 0x45, 0x50, 0x52, 0x45, 0x43, 0x41, 0x54, 0x45, 0x44, 0x5f, 0x53, 0x54, 0x41, 0x54, 0x55, - 0x53, 0x5f, 0x43, 0x4f, 0x44, 0x45, 0x5f, 0x44, 0x45, 0x41, 0x44, 0x4c, 0x49, 0x4e, 0x45, 0x5f, - 0x45, 0x58, 0x43, 0x45, 0x45, 0x44, 0x45, 0x44, 0x10, 0x04, 0x12, 0x24, 0x0a, 0x20, 0x44, 0x45, - 0x50, 0x52, 0x45, 0x43, 0x41, 0x54, 0x45, 0x44, 0x5f, 0x53, 0x54, 0x41, 0x54, 0x55, 0x53, 0x5f, - 0x43, 0x4f, 0x44, 0x45, 0x5f, 0x4e, 0x4f, 0x54, 0x5f, 0x46, 0x4f, 0x55, 0x4e, 0x44, 0x10, 0x05, - 0x12, 0x29, 0x0a, 0x25, 0x44, 0x45, 0x50, 0x52, 0x45, 0x43, 0x41, 0x54, 0x45, 0x44, 0x5f, 0x53, - 0x54, 0x41, 0x54, 0x55, 0x53, 0x5f, 0x43, 0x4f, 0x44, 0x45, 0x5f, 0x41, 0x4c, 0x52, 0x45, 0x41, - 0x44, 0x59, 0x5f, 0x45, 0x58, 0x49, 0x53, 0x54, 0x53, 0x10, 0x06, 0x12, 0x2c, 0x0a, 0x28, 0x44, - 0x45, 0x50, 0x52, 0x45, 0x43, 0x41, 0x54, 0x45, 0x44, 0x5f, 0x53, 0x54, 0x41, 0x54, 0x55, 0x53, - 0x5f, 0x43, 0x4f, 0x44, 0x45, 0x5f, 0x50, 0x45, 0x52, 0x4d, 0x49, 0x53, 0x53, 0x49, 0x4f, 0x4e, - 0x5f, 0x44, 0x45, 0x4e, 0x49, 0x45, 0x44, 0x10, 0x07, 0x12, 0x2d, 0x0a, 0x29, 0x44, 0x45, 0x50, - 0x52, 0x45, 0x43, 0x41, 0x54, 0x45, 0x44, 0x5f, 0x53, 0x54, 0x41, 0x54, 0x55, 0x53, 0x5f, 0x43, - 0x4f, 0x44, 0x45, 0x5f, 0x52, 0x45, 0x53, 0x4f, 0x55, 0x52, 0x43, 0x45, 0x5f, 0x45, 0x58, 0x48, - 0x41, 0x55, 0x53, 0x54, 0x45, 0x44, 0x10, 0x08, 0x12, 0x2e, 0x0a, 0x2a, 0x44, 0x45, 0x50, 0x52, - 0x45, 0x43, 0x41, 0x54, 0x45, 0x44, 0x5f, 0x53, 0x54, 0x41, 0x54, 0x55, 0x53, 0x5f, 0x43, 0x4f, - 0x44, 0x45, 0x5f, 0x46, 0x41, 0x49, 0x4c, 0x45, 0x44, 0x5f, 0x50, 0x52, 0x45, 0x43, 0x4f, 0x4e, - 0x44, 0x49, 0x54, 0x49, 0x4f, 0x4e, 0x10, 0x09, 0x12, 0x22, 0x0a, 0x1e, 0x44, 0x45, 0x50, 0x52, - 0x45, 0x43, 0x41, 0x54, 0x45, 0x44, 0x5f, 0x53, 0x54, 0x41, 0x54, 0x55, 0x53, 0x5f, 0x43, 0x4f, - 0x44, 0x45, 0x5f, 0x41, 0x42, 0x4f, 0x52, 0x54, 0x45, 0x44, 0x10, 0x0a, 0x12, 0x27, 0x0a, 0x23, - 0x44, 0x45, 0x50, 0x52, 0x45, 0x43, 0x41, 0x54, 0x45, 0x44, 0x5f, 0x53, 0x54, 0x41, 0x54, 0x55, - 0x53, 0x5f, 0x43, 0x4f, 0x44, 0x45, 0x5f, 0x4f, 0x55, 0x54, 0x5f, 0x4f, 0x46, 0x5f, 0x52, 0x41, - 0x4e, 0x47, 0x45, 0x10, 0x0b, 0x12, 0x28, 0x0a, 0x24, 0x44, 0x45, 0x50, 0x52, 0x45, 0x43, 0x41, - 0x54, 0x45, 0x44, 0x5f, 0x53, 0x54, 0x41, 0x54, 0x55, 0x53, 0x5f, 0x43, 0x4f, 0x44, 0x45, 0x5f, - 0x55, 0x4e, 0x49, 0x4d, 0x50, 0x4c, 0x45, 0x4d, 0x45, 0x4e, 0x54, 0x45, 0x44, 0x10, 0x0c, 0x12, - 0x29, 0x0a, 0x25, 0x44, 0x45, 0x50, 0x52, 0x45, 0x43, 0x41, 0x54, 0x45, 0x44, 0x5f, 0x53, 0x54, - 0x41, 0x54, 0x55, 0x53, 0x5f, 0x43, 0x4f, 0x44, 0x45, 0x5f, 0x49, 0x4e, 0x54, 0x45, 0x52, 0x4e, - 0x41, 0x4c, 0x5f, 0x45, 0x52, 0x52, 0x4f, 0x52, 0x10, 0x0d, 0x12, 0x26, 0x0a, 0x22, 0x44, 0x45, - 0x50, 0x52, 0x45, 0x43, 0x41, 0x54, 0x45, 0x44, 0x5f, 0x53, 0x54, 0x41, 0x54, 0x55, 0x53, 0x5f, - 0x43, 0x4f, 0x44, 0x45, 0x5f, 0x55, 0x4e, 0x41, 0x56, 0x41, 0x49, 0x4c, 0x41, 0x42, 0x4c, 0x45, - 0x10, 0x0e, 0x12, 0x24, 0x0a, 0x20, 0x44, 0x45, 0x50, 0x52, 0x45, 0x43, 0x41, 0x54, 0x45, 0x44, - 0x5f, 0x53, 0x54, 0x41, 0x54, 0x55, 0x53, 0x5f, 0x43, 0x4f, 0x44, 0x45, 0x5f, 0x44, 0x41, 0x54, - 0x41, 0x5f, 0x4c, 0x4f, 0x53, 0x53, 0x10, 0x0f, 0x12, 0x2a, 0x0a, 0x26, 0x44, 0x45, 0x50, 0x52, - 0x45, 0x43, 0x41, 0x54, 0x45, 0x44, 0x5f, 0x53, 0x54, 0x41, 0x54, 0x55, 0x53, 0x5f, 0x43, 0x4f, - 0x44, 0x45, 0x5f, 0x55, 0x4e, 0x41, 0x55, 0x54, 0x48, 0x45, 0x4e, 0x54, 0x49, 0x43, 0x41, 0x54, - 0x45, 0x44, 0x10, 0x10, 0x22, 0x4e, 0x0a, 0x0a, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x43, 0x6f, - 0x64, 0x65, 0x12, 0x15, 0x0a, 0x11, 0x53, 0x54, 0x41, 0x54, 0x55, 0x53, 0x5f, 0x43, 0x4f, 0x44, - 0x45, 0x5f, 0x55, 0x4e, 0x53, 0x45, 0x54, 0x10, 0x00, 0x12, 0x12, 0x0a, 0x0e, 0x53, 0x54, 0x41, - 0x54, 0x55, 0x53, 0x5f, 0x43, 0x4f, 0x44, 0x45, 0x5f, 0x4f, 0x4b, 0x10, 0x01, 0x12, 0x15, 0x0a, - 0x11, 0x53, 0x54, 0x41, 0x54, 0x55, 0x53, 0x5f, 0x43, 0x4f, 0x44, 0x45, 0x5f, 0x45, 0x52, 0x52, - 0x4f, 0x52, 0x10, 0x02, 0x42, 0x58, 0x0a, 0x1f, 0x69, 0x6f, 0x2e, 0x6f, 0x70, 0x65, 0x6e, 0x74, - 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x74, 0x72, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x74, - 0x72, 0x61, 0x63, 0x65, 0x2e, 0x76, 0x31, 0x42, 0x0a, 0x54, 0x72, 0x61, 0x63, 0x65, 0x50, 0x72, - 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x27, 0x67, 0x6f, 0x2e, 0x6f, 0x70, 0x65, 0x6e, 0x74, 0x65, - 0x6c, 0x65, 0x6d, 0x65, 0x74, 0x72, 0x79, 0x2e, 0x69, 0x6f, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x2f, 0x6f, 0x74, 0x6c, 0x70, 0x2f, 0x74, 0x72, 0x61, 0x63, 0x65, 0x2f, 0x76, 0x31, 0x62, 0x06, - 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, -} - -var ( - file_opentelemetry_proto_trace_v1_trace_proto_rawDescOnce sync.Once - file_opentelemetry_proto_trace_v1_trace_proto_rawDescData = file_opentelemetry_proto_trace_v1_trace_proto_rawDesc -) - -func file_opentelemetry_proto_trace_v1_trace_proto_rawDescGZIP() []byte { - file_opentelemetry_proto_trace_v1_trace_proto_rawDescOnce.Do(func() { - file_opentelemetry_proto_trace_v1_trace_proto_rawDescData = protoimpl.X.CompressGZIP(file_opentelemetry_proto_trace_v1_trace_proto_rawDescData) - }) - return file_opentelemetry_proto_trace_v1_trace_proto_rawDescData -} - -var file_opentelemetry_proto_trace_v1_trace_proto_enumTypes = make([]protoimpl.EnumInfo, 3) -var file_opentelemetry_proto_trace_v1_trace_proto_msgTypes = make([]protoimpl.MessageInfo, 6) -var file_opentelemetry_proto_trace_v1_trace_proto_goTypes = []interface{}{ - (Span_SpanKind)(0), // 0: opentelemetry.proto.trace.v1.Span.SpanKind - (Status_DeprecatedStatusCode)(0), // 1: opentelemetry.proto.trace.v1.Status.DeprecatedStatusCode - (Status_StatusCode)(0), // 2: opentelemetry.proto.trace.v1.Status.StatusCode - (*ResourceSpans)(nil), // 3: opentelemetry.proto.trace.v1.ResourceSpans - (*InstrumentationLibrarySpans)(nil), // 4: opentelemetry.proto.trace.v1.InstrumentationLibrarySpans - (*Span)(nil), // 5: opentelemetry.proto.trace.v1.Span - (*Status)(nil), // 6: opentelemetry.proto.trace.v1.Status - (*Span_Event)(nil), // 7: opentelemetry.proto.trace.v1.Span.Event - (*Span_Link)(nil), // 8: opentelemetry.proto.trace.v1.Span.Link - (*v1.Resource)(nil), // 9: opentelemetry.proto.resource.v1.Resource - (*v11.InstrumentationLibrary)(nil), // 10: opentelemetry.proto.common.v1.InstrumentationLibrary - (*v11.KeyValue)(nil), // 11: opentelemetry.proto.common.v1.KeyValue -} -var file_opentelemetry_proto_trace_v1_trace_proto_depIdxs = []int32{ - 9, // 0: opentelemetry.proto.trace.v1.ResourceSpans.resource:type_name -> opentelemetry.proto.resource.v1.Resource - 4, // 1: opentelemetry.proto.trace.v1.ResourceSpans.instrumentation_library_spans:type_name -> opentelemetry.proto.trace.v1.InstrumentationLibrarySpans - 10, // 2: opentelemetry.proto.trace.v1.InstrumentationLibrarySpans.instrumentation_library:type_name -> opentelemetry.proto.common.v1.InstrumentationLibrary - 5, // 3: opentelemetry.proto.trace.v1.InstrumentationLibrarySpans.spans:type_name -> opentelemetry.proto.trace.v1.Span - 0, // 4: opentelemetry.proto.trace.v1.Span.kind:type_name -> opentelemetry.proto.trace.v1.Span.SpanKind - 11, // 5: opentelemetry.proto.trace.v1.Span.attributes:type_name -> opentelemetry.proto.common.v1.KeyValue - 7, // 6: opentelemetry.proto.trace.v1.Span.events:type_name -> opentelemetry.proto.trace.v1.Span.Event - 8, // 7: opentelemetry.proto.trace.v1.Span.links:type_name -> opentelemetry.proto.trace.v1.Span.Link - 6, // 8: opentelemetry.proto.trace.v1.Span.status:type_name -> opentelemetry.proto.trace.v1.Status - 1, // 9: opentelemetry.proto.trace.v1.Status.deprecated_code:type_name -> opentelemetry.proto.trace.v1.Status.DeprecatedStatusCode - 2, // 10: opentelemetry.proto.trace.v1.Status.code:type_name -> opentelemetry.proto.trace.v1.Status.StatusCode - 11, // 11: opentelemetry.proto.trace.v1.Span.Event.attributes:type_name -> opentelemetry.proto.common.v1.KeyValue - 11, // 12: opentelemetry.proto.trace.v1.Span.Link.attributes:type_name -> opentelemetry.proto.common.v1.KeyValue - 13, // [13:13] is the sub-list for method output_type - 13, // [13:13] is the sub-list for method input_type - 13, // [13:13] is the sub-list for extension type_name - 13, // [13:13] is the sub-list for extension extendee - 0, // [0:13] is the sub-list for field type_name -} - -func init() { file_opentelemetry_proto_trace_v1_trace_proto_init() } -func file_opentelemetry_proto_trace_v1_trace_proto_init() { - if File_opentelemetry_proto_trace_v1_trace_proto != nil { - return - } - if !protoimpl.UnsafeEnabled { - file_opentelemetry_proto_trace_v1_trace_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*ResourceSpans); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_opentelemetry_proto_trace_v1_trace_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*InstrumentationLibrarySpans); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_opentelemetry_proto_trace_v1_trace_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*Span); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_opentelemetry_proto_trace_v1_trace_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*Status); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_opentelemetry_proto_trace_v1_trace_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*Span_Event); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_opentelemetry_proto_trace_v1_trace_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*Span_Link); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - } - type x struct{} - out := protoimpl.TypeBuilder{ - File: protoimpl.DescBuilder{ - GoPackagePath: reflect.TypeOf(x{}).PkgPath(), - RawDescriptor: file_opentelemetry_proto_trace_v1_trace_proto_rawDesc, - NumEnums: 3, - NumMessages: 6, - NumExtensions: 0, - NumServices: 0, - }, - GoTypes: file_opentelemetry_proto_trace_v1_trace_proto_goTypes, - DependencyIndexes: file_opentelemetry_proto_trace_v1_trace_proto_depIdxs, - EnumInfos: file_opentelemetry_proto_trace_v1_trace_proto_enumTypes, - MessageInfos: file_opentelemetry_proto_trace_v1_trace_proto_msgTypes, - }.Build() - File_opentelemetry_proto_trace_v1_trace_proto = out.File - file_opentelemetry_proto_trace_v1_trace_proto_rawDesc = nil - file_opentelemetry_proto_trace_v1_trace_proto_goTypes = nil - file_opentelemetry_proto_trace_v1_trace_proto_depIdxs = nil -} diff --git a/vendor/google.golang.org/genproto/googleapis/api/httpbody/httpbody.pb.go b/vendor/google.golang.org/genproto/googleapis/api/httpbody/httpbody.pb.go deleted file mode 100644 index b47efe82b2..0000000000 --- a/vendor/google.golang.org/genproto/googleapis/api/httpbody/httpbody.pb.go +++ /dev/null @@ -1,232 +0,0 @@ -// Copyright 2015 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Code generated by protoc-gen-go. DO NOT EDIT. -// versions: -// protoc-gen-go v1.26.0 -// protoc v3.12.2 -// source: google/api/httpbody.proto - -package httpbody - -import ( - reflect "reflect" - sync "sync" - - protoreflect "google.golang.org/protobuf/reflect/protoreflect" - protoimpl "google.golang.org/protobuf/runtime/protoimpl" - anypb "google.golang.org/protobuf/types/known/anypb" -) - -const ( - // Verify that this generated code is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) - // Verify that runtime/protoimpl is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) -) - -// Message that represents an arbitrary HTTP body. It should only be used for -// payload formats that can't be represented as JSON, such as raw binary or -// an HTML page. -// -// -// This message can be used both in streaming and non-streaming API methods in -// the request as well as the response. -// -// It can be used as a top-level request field, which is convenient if one -// wants to extract parameters from either the URL or HTTP template into the -// request fields and also want access to the raw HTTP body. -// -// Example: -// -// message GetResourceRequest { -// // A unique request id. -// string request_id = 1; -// -// // The raw HTTP body is bound to this field. -// google.api.HttpBody http_body = 2; -// } -// -// service ResourceService { -// rpc GetResource(GetResourceRequest) returns (google.api.HttpBody); -// rpc UpdateResource(google.api.HttpBody) returns -// (google.protobuf.Empty); -// } -// -// Example with streaming methods: -// -// service CaldavService { -// rpc GetCalendar(stream google.api.HttpBody) -// returns (stream google.api.HttpBody); -// rpc UpdateCalendar(stream google.api.HttpBody) -// returns (stream google.api.HttpBody); -// } -// -// Use of this type only changes how the request and response bodies are -// handled, all other features will continue to work unchanged. -type HttpBody struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - // The HTTP Content-Type header value specifying the content type of the body. - ContentType string `protobuf:"bytes,1,opt,name=content_type,json=contentType,proto3" json:"content_type,omitempty"` - // The HTTP request/response body as raw binary. - Data []byte `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"` - // Application specific response metadata. Must be set in the first response - // for streaming APIs. - Extensions []*anypb.Any `protobuf:"bytes,3,rep,name=extensions,proto3" json:"extensions,omitempty"` -} - -func (x *HttpBody) Reset() { - *x = HttpBody{} - if protoimpl.UnsafeEnabled { - mi := &file_google_api_httpbody_proto_msgTypes[0] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *HttpBody) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*HttpBody) ProtoMessage() {} - -func (x *HttpBody) ProtoReflect() protoreflect.Message { - mi := &file_google_api_httpbody_proto_msgTypes[0] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use HttpBody.ProtoReflect.Descriptor instead. -func (*HttpBody) Descriptor() ([]byte, []int) { - return file_google_api_httpbody_proto_rawDescGZIP(), []int{0} -} - -func (x *HttpBody) GetContentType() string { - if x != nil { - return x.ContentType - } - return "" -} - -func (x *HttpBody) GetData() []byte { - if x != nil { - return x.Data - } - return nil -} - -func (x *HttpBody) GetExtensions() []*anypb.Any { - if x != nil { - return x.Extensions - } - return nil -} - -var File_google_api_httpbody_proto protoreflect.FileDescriptor - -var file_google_api_httpbody_proto_rawDesc = []byte{ - 0x0a, 0x19, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x68, 0x74, 0x74, - 0x70, 0x62, 0x6f, 0x64, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0a, 0x67, 0x6f, 0x6f, - 0x67, 0x6c, 0x65, 0x2e, 0x61, 0x70, 0x69, 0x1a, 0x19, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, - 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x61, 0x6e, 0x79, 0x2e, 0x70, 0x72, 0x6f, - 0x74, 0x6f, 0x22, 0x77, 0x0a, 0x08, 0x48, 0x74, 0x74, 0x70, 0x42, 0x6f, 0x64, 0x79, 0x12, 0x21, - 0x0a, 0x0c, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x18, 0x01, - 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x54, 0x79, 0x70, - 0x65, 0x12, 0x12, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, - 0x04, 0x64, 0x61, 0x74, 0x61, 0x12, 0x34, 0x0a, 0x0a, 0x65, 0x78, 0x74, 0x65, 0x6e, 0x73, 0x69, - 0x6f, 0x6e, 0x73, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x14, 0x2e, 0x67, 0x6f, 0x6f, 0x67, - 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x41, 0x6e, 0x79, 0x52, - 0x0a, 0x65, 0x78, 0x74, 0x65, 0x6e, 0x73, 0x69, 0x6f, 0x6e, 0x73, 0x42, 0x68, 0x0a, 0x0e, 0x63, - 0x6f, 0x6d, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x61, 0x70, 0x69, 0x42, 0x0d, 0x48, - 0x74, 0x74, 0x70, 0x42, 0x6f, 0x64, 0x79, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x3b, - 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x67, 0x6f, 0x6c, 0x61, 0x6e, 0x67, 0x2e, 0x6f, 0x72, - 0x67, 0x2f, 0x67, 0x65, 0x6e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x67, 0x6f, 0x6f, 0x67, 0x6c, - 0x65, 0x61, 0x70, 0x69, 0x73, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x68, 0x74, 0x74, 0x70, 0x62, 0x6f, - 0x64, 0x79, 0x3b, 0x68, 0x74, 0x74, 0x70, 0x62, 0x6f, 0x64, 0x79, 0xf8, 0x01, 0x01, 0xa2, 0x02, - 0x04, 0x47, 0x41, 0x50, 0x49, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, -} - -var ( - file_google_api_httpbody_proto_rawDescOnce sync.Once - file_google_api_httpbody_proto_rawDescData = file_google_api_httpbody_proto_rawDesc -) - -func file_google_api_httpbody_proto_rawDescGZIP() []byte { - file_google_api_httpbody_proto_rawDescOnce.Do(func() { - file_google_api_httpbody_proto_rawDescData = protoimpl.X.CompressGZIP(file_google_api_httpbody_proto_rawDescData) - }) - return file_google_api_httpbody_proto_rawDescData -} - -var file_google_api_httpbody_proto_msgTypes = make([]protoimpl.MessageInfo, 1) -var file_google_api_httpbody_proto_goTypes = []interface{}{ - (*HttpBody)(nil), // 0: google.api.HttpBody - (*anypb.Any)(nil), // 1: google.protobuf.Any -} -var file_google_api_httpbody_proto_depIdxs = []int32{ - 1, // 0: google.api.HttpBody.extensions:type_name -> google.protobuf.Any - 1, // [1:1] is the sub-list for method output_type - 1, // [1:1] is the sub-list for method input_type - 1, // [1:1] is the sub-list for extension type_name - 1, // [1:1] is the sub-list for extension extendee - 0, // [0:1] is the sub-list for field type_name -} - -func init() { file_google_api_httpbody_proto_init() } -func file_google_api_httpbody_proto_init() { - if File_google_api_httpbody_proto != nil { - return - } - if !protoimpl.UnsafeEnabled { - file_google_api_httpbody_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*HttpBody); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - } - type x struct{} - out := protoimpl.TypeBuilder{ - File: protoimpl.DescBuilder{ - GoPackagePath: reflect.TypeOf(x{}).PkgPath(), - RawDescriptor: file_google_api_httpbody_proto_rawDesc, - NumEnums: 0, - NumMessages: 1, - NumExtensions: 0, - NumServices: 0, - }, - GoTypes: file_google_api_httpbody_proto_goTypes, - DependencyIndexes: file_google_api_httpbody_proto_depIdxs, - MessageInfos: file_google_api_httpbody_proto_msgTypes, - }.Build() - File_google_api_httpbody_proto = out.File - file_google_api_httpbody_proto_rawDesc = nil - file_google_api_httpbody_proto_goTypes = nil - file_google_api_httpbody_proto_depIdxs = nil -} diff --git a/vendor/google.golang.org/grpc/health/client.go b/vendor/google.golang.org/grpc/health/client.go deleted file mode 100644 index b5bee48380..0000000000 --- a/vendor/google.golang.org/grpc/health/client.go +++ /dev/null @@ -1,117 +0,0 @@ -/* - * - * Copyright 2018 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package health - -import ( - "context" - "fmt" - "io" - "time" - - "google.golang.org/grpc" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/connectivity" - healthpb "google.golang.org/grpc/health/grpc_health_v1" - "google.golang.org/grpc/internal" - "google.golang.org/grpc/internal/backoff" - "google.golang.org/grpc/status" -) - -var ( - backoffStrategy = backoff.DefaultExponential - backoffFunc = func(ctx context.Context, retries int) bool { - d := backoffStrategy.Backoff(retries) - timer := time.NewTimer(d) - select { - case <-timer.C: - return true - case <-ctx.Done(): - timer.Stop() - return false - } - } -) - -func init() { - internal.HealthCheckFunc = clientHealthCheck -} - -const healthCheckMethod = "/grpc.health.v1.Health/Watch" - -// This function implements the protocol defined at: -// https://github.com/grpc/grpc/blob/master/doc/health-checking.md -func clientHealthCheck(ctx context.Context, newStream func(string) (interface{}, error), setConnectivityState func(connectivity.State, error), service string) error { - tryCnt := 0 - -retryConnection: - for { - // Backs off if the connection has failed in some way without receiving a message in the previous retry. - if tryCnt > 0 && !backoffFunc(ctx, tryCnt-1) { - return nil - } - tryCnt++ - - if ctx.Err() != nil { - return nil - } - setConnectivityState(connectivity.Connecting, nil) - rawS, err := newStream(healthCheckMethod) - if err != nil { - continue retryConnection - } - - s, ok := rawS.(grpc.ClientStream) - // Ideally, this should never happen. But if it happens, the server is marked as healthy for LBing purposes. - if !ok { - setConnectivityState(connectivity.Ready, nil) - return fmt.Errorf("newStream returned %v (type %T); want grpc.ClientStream", rawS, rawS) - } - - if err = s.SendMsg(&healthpb.HealthCheckRequest{Service: service}); err != nil && err != io.EOF { - // Stream should have been closed, so we can safely continue to create a new stream. - continue retryConnection - } - s.CloseSend() - - resp := new(healthpb.HealthCheckResponse) - for { - err = s.RecvMsg(resp) - - // Reports healthy for the LBing purposes if health check is not implemented in the server. - if status.Code(err) == codes.Unimplemented { - setConnectivityState(connectivity.Ready, nil) - return err - } - - // Reports unhealthy if server's Watch method gives an error other than UNIMPLEMENTED. - if err != nil { - setConnectivityState(connectivity.TransientFailure, fmt.Errorf("connection active but received health check RPC error: %v", err)) - continue retryConnection - } - - // As a message has been received, removes the need for backoff for the next retry by resetting the try count. - tryCnt = 0 - if resp.Status == healthpb.HealthCheckResponse_SERVING { - setConnectivityState(connectivity.Ready, nil) - } else { - setConnectivityState(connectivity.TransientFailure, fmt.Errorf("connection active but health check failed. status=%s", resp.Status)) - } - } - } -} diff --git a/vendor/google.golang.org/grpc/health/logging.go b/vendor/google.golang.org/grpc/health/logging.go deleted file mode 100644 index 83c6acf55e..0000000000 --- a/vendor/google.golang.org/grpc/health/logging.go +++ /dev/null @@ -1,23 +0,0 @@ -/* - * - * Copyright 2020 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package health - -import "google.golang.org/grpc/grpclog" - -var logger = grpclog.Component("health_service") diff --git a/vendor/google.golang.org/grpc/health/server.go b/vendor/google.golang.org/grpc/health/server.go deleted file mode 100644 index cce6312d77..0000000000 --- a/vendor/google.golang.org/grpc/health/server.go +++ /dev/null @@ -1,163 +0,0 @@ -/* - * - * Copyright 2017 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -// Package health provides a service that exposes server's health and it must be -// imported to enable support for client-side health checks. -package health - -import ( - "context" - "sync" - - "google.golang.org/grpc/codes" - healthgrpc "google.golang.org/grpc/health/grpc_health_v1" - healthpb "google.golang.org/grpc/health/grpc_health_v1" - "google.golang.org/grpc/status" -) - -// Server implements `service Health`. -type Server struct { - healthgrpc.UnimplementedHealthServer - mu sync.RWMutex - // If shutdown is true, it's expected all serving status is NOT_SERVING, and - // will stay in NOT_SERVING. - shutdown bool - // statusMap stores the serving status of the services this Server monitors. - statusMap map[string]healthpb.HealthCheckResponse_ServingStatus - updates map[string]map[healthgrpc.Health_WatchServer]chan healthpb.HealthCheckResponse_ServingStatus -} - -// NewServer returns a new Server. -func NewServer() *Server { - return &Server{ - statusMap: map[string]healthpb.HealthCheckResponse_ServingStatus{"": healthpb.HealthCheckResponse_SERVING}, - updates: make(map[string]map[healthgrpc.Health_WatchServer]chan healthpb.HealthCheckResponse_ServingStatus), - } -} - -// Check implements `service Health`. -func (s *Server) Check(ctx context.Context, in *healthpb.HealthCheckRequest) (*healthpb.HealthCheckResponse, error) { - s.mu.RLock() - defer s.mu.RUnlock() - if servingStatus, ok := s.statusMap[in.Service]; ok { - return &healthpb.HealthCheckResponse{ - Status: servingStatus, - }, nil - } - return nil, status.Error(codes.NotFound, "unknown service") -} - -// Watch implements `service Health`. -func (s *Server) Watch(in *healthpb.HealthCheckRequest, stream healthgrpc.Health_WatchServer) error { - service := in.Service - // update channel is used for getting service status updates. - update := make(chan healthpb.HealthCheckResponse_ServingStatus, 1) - s.mu.Lock() - // Puts the initial status to the channel. - if servingStatus, ok := s.statusMap[service]; ok { - update <- servingStatus - } else { - update <- healthpb.HealthCheckResponse_SERVICE_UNKNOWN - } - - // Registers the update channel to the correct place in the updates map. - if _, ok := s.updates[service]; !ok { - s.updates[service] = make(map[healthgrpc.Health_WatchServer]chan healthpb.HealthCheckResponse_ServingStatus) - } - s.updates[service][stream] = update - defer func() { - s.mu.Lock() - delete(s.updates[service], stream) - s.mu.Unlock() - }() - s.mu.Unlock() - - var lastSentStatus healthpb.HealthCheckResponse_ServingStatus = -1 - for { - select { - // Status updated. Sends the up-to-date status to the client. - case servingStatus := <-update: - if lastSentStatus == servingStatus { - continue - } - lastSentStatus = servingStatus - err := stream.Send(&healthpb.HealthCheckResponse{Status: servingStatus}) - if err != nil { - return status.Error(codes.Canceled, "Stream has ended.") - } - // Context done. Removes the update channel from the updates map. - case <-stream.Context().Done(): - return status.Error(codes.Canceled, "Stream has ended.") - } - } -} - -// SetServingStatus is called when need to reset the serving status of a service -// or insert a new service entry into the statusMap. -func (s *Server) SetServingStatus(service string, servingStatus healthpb.HealthCheckResponse_ServingStatus) { - s.mu.Lock() - defer s.mu.Unlock() - if s.shutdown { - logger.Infof("health: status changing for %s to %v is ignored because health service is shutdown", service, servingStatus) - return - } - - s.setServingStatusLocked(service, servingStatus) -} - -func (s *Server) setServingStatusLocked(service string, servingStatus healthpb.HealthCheckResponse_ServingStatus) { - s.statusMap[service] = servingStatus - for _, update := range s.updates[service] { - // Clears previous updates, that are not sent to the client, from the channel. - // This can happen if the client is not reading and the server gets flow control limited. - select { - case <-update: - default: - } - // Puts the most recent update to the channel. - update <- servingStatus - } -} - -// Shutdown sets all serving status to NOT_SERVING, and configures the server to -// ignore all future status changes. -// -// This changes serving status for all services. To set status for a particular -// services, call SetServingStatus(). -func (s *Server) Shutdown() { - s.mu.Lock() - defer s.mu.Unlock() - s.shutdown = true - for service := range s.statusMap { - s.setServingStatusLocked(service, healthpb.HealthCheckResponse_NOT_SERVING) - } -} - -// Resume sets all serving status to SERVING, and configures the server to -// accept all future status changes. -// -// This changes serving status for all services. To set status for a particular -// services, call SetServingStatus(). -func (s *Server) Resume() { - s.mu.Lock() - defer s.mu.Unlock() - s.shutdown = false - for service := range s.statusMap { - s.setServingStatusLocked(service, healthpb.HealthCheckResponse_SERVING) - } -} diff --git a/vendor/gopkg.in/natefinch/lumberjack.v2/.gitignore b/vendor/gopkg.in/natefinch/lumberjack.v2/.gitignore deleted file mode 100644 index 836562412f..0000000000 --- a/vendor/gopkg.in/natefinch/lumberjack.v2/.gitignore +++ /dev/null @@ -1,23 +0,0 @@ -# Compiled Object files, Static and Dynamic libs (Shared Objects) -*.o -*.a -*.so - -# Folders -_obj -_test - -# Architecture specific extensions/prefixes -*.[568vq] -[568vq].out - -*.cgo1.go -*.cgo2.c -_cgo_defun.c -_cgo_gotypes.go -_cgo_export.* - -_testmain.go - -*.exe -*.test diff --git a/vendor/gopkg.in/natefinch/lumberjack.v2/.travis.yml b/vendor/gopkg.in/natefinch/lumberjack.v2/.travis.yml deleted file mode 100644 index 65dcbc56dc..0000000000 --- a/vendor/gopkg.in/natefinch/lumberjack.v2/.travis.yml +++ /dev/null @@ -1,6 +0,0 @@ -language: go - -go: - - 1.8 - - 1.7 - - 1.6 \ No newline at end of file diff --git a/vendor/gopkg.in/natefinch/lumberjack.v2/LICENSE b/vendor/gopkg.in/natefinch/lumberjack.v2/LICENSE deleted file mode 100644 index c3d4cc307d..0000000000 --- a/vendor/gopkg.in/natefinch/lumberjack.v2/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -The MIT License (MIT) - -Copyright (c) 2014 Nate Finch - -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: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -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. \ No newline at end of file diff --git a/vendor/gopkg.in/natefinch/lumberjack.v2/README.md b/vendor/gopkg.in/natefinch/lumberjack.v2/README.md deleted file mode 100644 index 060eae52a2..0000000000 --- a/vendor/gopkg.in/natefinch/lumberjack.v2/README.md +++ /dev/null @@ -1,179 +0,0 @@ -# lumberjack [![GoDoc](https://godoc.org/gopkg.in/natefinch/lumberjack.v2?status.png)](https://godoc.org/gopkg.in/natefinch/lumberjack.v2) [![Build Status](https://travis-ci.org/natefinch/lumberjack.svg?branch=v2.0)](https://travis-ci.org/natefinch/lumberjack) [![Build status](https://ci.appveyor.com/api/projects/status/00gchpxtg4gkrt5d)](https://ci.appveyor.com/project/natefinch/lumberjack) [![Coverage Status](https://coveralls.io/repos/natefinch/lumberjack/badge.svg?branch=v2.0)](https://coveralls.io/r/natefinch/lumberjack?branch=v2.0) - -### Lumberjack is a Go package for writing logs to rolling files. - -Package lumberjack provides a rolling logger. - -Note that this is v2.0 of lumberjack, and should be imported using gopkg.in -thusly: - - import "gopkg.in/natefinch/lumberjack.v2" - -The package name remains simply lumberjack, and the code resides at -https://github.com/natefinch/lumberjack under the v2.0 branch. - -Lumberjack is intended to be one part of a logging infrastructure. -It is not an all-in-one solution, but instead is a pluggable -component at the bottom of the logging stack that simply controls the files -to which logs are written. - -Lumberjack plays well with any logging package that can write to an -io.Writer, including the standard library's log package. - -Lumberjack assumes that only one process is writing to the output files. -Using the same lumberjack configuration from multiple processes on the same -machine will result in improper behavior. - - -**Example** - -To use lumberjack with the standard library's log package, just pass it into the SetOutput function when your application starts. - -Code: - -```go -log.SetOutput(&lumberjack.Logger{ - Filename: "/var/log/myapp/foo.log", - MaxSize: 500, // megabytes - MaxBackups: 3, - MaxAge: 28, //days - Compress: true, // disabled by default -}) -``` - - - -## type Logger -``` go -type Logger struct { - // Filename is the file to write logs to. Backup log files will be retained - // in the same directory. It uses -lumberjack.log in - // os.TempDir() if empty. - Filename string `json:"filename" yaml:"filename"` - - // MaxSize is the maximum size in megabytes of the log file before it gets - // rotated. It defaults to 100 megabytes. - MaxSize int `json:"maxsize" yaml:"maxsize"` - - // MaxAge is the maximum number of days to retain old log files based on the - // timestamp encoded in their filename. Note that a day is defined as 24 - // hours and may not exactly correspond to calendar days due to daylight - // savings, leap seconds, etc. The default is not to remove old log files - // based on age. - MaxAge int `json:"maxage" yaml:"maxage"` - - // MaxBackups is the maximum number of old log files to retain. The default - // is to retain all old log files (though MaxAge may still cause them to get - // deleted.) - MaxBackups int `json:"maxbackups" yaml:"maxbackups"` - - // LocalTime determines if the time used for formatting the timestamps in - // backup files is the computer's local time. The default is to use UTC - // time. - LocalTime bool `json:"localtime" yaml:"localtime"` - - // Compress determines if the rotated log files should be compressed - // using gzip. The default is not to perform compression. - Compress bool `json:"compress" yaml:"compress"` - // contains filtered or unexported fields -} -``` -Logger is an io.WriteCloser that writes to the specified filename. - -Logger opens or creates the logfile on first Write. If the file exists and -is less than MaxSize megabytes, lumberjack will open and append to that file. -If the file exists and its size is >= MaxSize megabytes, the file is renamed -by putting the current time in a timestamp in the name immediately before the -file's extension (or the end of the filename if there's no extension). A new -log file is then created using original filename. - -Whenever a write would cause the current log file exceed MaxSize megabytes, -the current file is closed, renamed, and a new log file created with the -original name. Thus, the filename you give Logger is always the "current" log -file. - -Backups use the log file name given to Logger, in the form `name-timestamp.ext` -where name is the filename without the extension, timestamp is the time at which -the log was rotated formatted with the time.Time format of -`2006-01-02T15-04-05.000` and the extension is the original extension. For -example, if your Logger.Filename is `/var/log/foo/server.log`, a backup created -at 6:30pm on Nov 11 2016 would use the filename -`/var/log/foo/server-2016-11-04T18-30-00.000.log` - -### Cleaning Up Old Log Files -Whenever a new logfile gets created, old log files may be deleted. The most -recent files according to the encoded timestamp will be retained, up to a -number equal to MaxBackups (or all of them if MaxBackups is 0). Any files -with an encoded timestamp older than MaxAge days are deleted, regardless of -MaxBackups. Note that the time encoded in the timestamp is the rotation -time, which may differ from the last time that file was written to. - -If MaxBackups and MaxAge are both 0, no old log files will be deleted. - - - - - - - - - - - -### func (\*Logger) Close -``` go -func (l *Logger) Close() error -``` -Close implements io.Closer, and closes the current logfile. - - - -### func (\*Logger) Rotate -``` go -func (l *Logger) Rotate() error -``` -Rotate causes Logger to close the existing log file and immediately create a -new one. This is a helper function for applications that want to initiate -rotations outside of the normal rotation rules, such as in response to -SIGHUP. After rotating, this initiates a cleanup of old log files according -to the normal rules. - -**Example** - -Example of how to rotate in response to SIGHUP. - -Code: - -```go -l := &lumberjack.Logger{} -log.SetOutput(l) -c := make(chan os.Signal, 1) -signal.Notify(c, syscall.SIGHUP) - -go func() { - for { - <-c - l.Rotate() - } -}() -``` - -### func (\*Logger) Write -``` go -func (l *Logger) Write(p []byte) (n int, err error) -``` -Write implements io.Writer. If a write would cause the log file to be larger -than MaxSize, the file is closed, renamed to include a timestamp of the -current time, and a new log file is created using the original log file name. -If the length of the write is greater than MaxSize, an error is returned. - - - - - - - - - -- - - -Generated by [godoc2md](http://godoc.org/github.com/davecheney/godoc2md) diff --git a/vendor/gopkg.in/natefinch/lumberjack.v2/chown.go b/vendor/gopkg.in/natefinch/lumberjack.v2/chown.go deleted file mode 100644 index 11d0669723..0000000000 --- a/vendor/gopkg.in/natefinch/lumberjack.v2/chown.go +++ /dev/null @@ -1,11 +0,0 @@ -// +build !linux - -package lumberjack - -import ( - "os" -) - -func chown(_ string, _ os.FileInfo) error { - return nil -} diff --git a/vendor/gopkg.in/natefinch/lumberjack.v2/chown_linux.go b/vendor/gopkg.in/natefinch/lumberjack.v2/chown_linux.go deleted file mode 100644 index 2758ec9ced..0000000000 --- a/vendor/gopkg.in/natefinch/lumberjack.v2/chown_linux.go +++ /dev/null @@ -1,19 +0,0 @@ -package lumberjack - -import ( - "os" - "syscall" -) - -// os_Chown is a var so we can mock it out during tests. -var os_Chown = os.Chown - -func chown(name string, info os.FileInfo) error { - f, err := os.OpenFile(name, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, info.Mode()) - if err != nil { - return err - } - f.Close() - stat := info.Sys().(*syscall.Stat_t) - return os_Chown(name, int(stat.Uid), int(stat.Gid)) -} diff --git a/vendor/gopkg.in/natefinch/lumberjack.v2/lumberjack.go b/vendor/gopkg.in/natefinch/lumberjack.v2/lumberjack.go deleted file mode 100644 index 46d97c5531..0000000000 --- a/vendor/gopkg.in/natefinch/lumberjack.v2/lumberjack.go +++ /dev/null @@ -1,541 +0,0 @@ -// Package lumberjack provides a rolling logger. -// -// Note that this is v2.0 of lumberjack, and should be imported using gopkg.in -// thusly: -// -// import "gopkg.in/natefinch/lumberjack.v2" -// -// The package name remains simply lumberjack, and the code resides at -// https://github.com/natefinch/lumberjack under the v2.0 branch. -// -// Lumberjack is intended to be one part of a logging infrastructure. -// It is not an all-in-one solution, but instead is a pluggable -// component at the bottom of the logging stack that simply controls the files -// to which logs are written. -// -// Lumberjack plays well with any logging package that can write to an -// io.Writer, including the standard library's log package. -// -// Lumberjack assumes that only one process is writing to the output files. -// Using the same lumberjack configuration from multiple processes on the same -// machine will result in improper behavior. -package lumberjack - -import ( - "compress/gzip" - "errors" - "fmt" - "io" - "io/ioutil" - "os" - "path/filepath" - "sort" - "strings" - "sync" - "time" -) - -const ( - backupTimeFormat = "2006-01-02T15-04-05.000" - compressSuffix = ".gz" - defaultMaxSize = 100 -) - -// ensure we always implement io.WriteCloser -var _ io.WriteCloser = (*Logger)(nil) - -// Logger is an io.WriteCloser that writes to the specified filename. -// -// Logger opens or creates the logfile on first Write. If the file exists and -// is less than MaxSize megabytes, lumberjack will open and append to that file. -// If the file exists and its size is >= MaxSize megabytes, the file is renamed -// by putting the current time in a timestamp in the name immediately before the -// file's extension (or the end of the filename if there's no extension). A new -// log file is then created using original filename. -// -// Whenever a write would cause the current log file exceed MaxSize megabytes, -// the current file is closed, renamed, and a new log file created with the -// original name. Thus, the filename you give Logger is always the "current" log -// file. -// -// Backups use the log file name given to Logger, in the form -// `name-timestamp.ext` where name is the filename without the extension, -// timestamp is the time at which the log was rotated formatted with the -// time.Time format of `2006-01-02T15-04-05.000` and the extension is the -// original extension. For example, if your Logger.Filename is -// `/var/log/foo/server.log`, a backup created at 6:30pm on Nov 11 2016 would -// use the filename `/var/log/foo/server-2016-11-04T18-30-00.000.log` -// -// Cleaning Up Old Log Files -// -// Whenever a new logfile gets created, old log files may be deleted. The most -// recent files according to the encoded timestamp will be retained, up to a -// number equal to MaxBackups (or all of them if MaxBackups is 0). Any files -// with an encoded timestamp older than MaxAge days are deleted, regardless of -// MaxBackups. Note that the time encoded in the timestamp is the rotation -// time, which may differ from the last time that file was written to. -// -// If MaxBackups and MaxAge are both 0, no old log files will be deleted. -type Logger struct { - // Filename is the file to write logs to. Backup log files will be retained - // in the same directory. It uses -lumberjack.log in - // os.TempDir() if empty. - Filename string `json:"filename" yaml:"filename"` - - // MaxSize is the maximum size in megabytes of the log file before it gets - // rotated. It defaults to 100 megabytes. - MaxSize int `json:"maxsize" yaml:"maxsize"` - - // MaxAge is the maximum number of days to retain old log files based on the - // timestamp encoded in their filename. Note that a day is defined as 24 - // hours and may not exactly correspond to calendar days due to daylight - // savings, leap seconds, etc. The default is not to remove old log files - // based on age. - MaxAge int `json:"maxage" yaml:"maxage"` - - // MaxBackups is the maximum number of old log files to retain. The default - // is to retain all old log files (though MaxAge may still cause them to get - // deleted.) - MaxBackups int `json:"maxbackups" yaml:"maxbackups"` - - // LocalTime determines if the time used for formatting the timestamps in - // backup files is the computer's local time. The default is to use UTC - // time. - LocalTime bool `json:"localtime" yaml:"localtime"` - - // Compress determines if the rotated log files should be compressed - // using gzip. The default is not to perform compression. - Compress bool `json:"compress" yaml:"compress"` - - size int64 - file *os.File - mu sync.Mutex - - millCh chan bool - startMill sync.Once -} - -var ( - // currentTime exists so it can be mocked out by tests. - currentTime = time.Now - - // os_Stat exists so it can be mocked out by tests. - os_Stat = os.Stat - - // megabyte is the conversion factor between MaxSize and bytes. It is a - // variable so tests can mock it out and not need to write megabytes of data - // to disk. - megabyte = 1024 * 1024 -) - -// Write implements io.Writer. If a write would cause the log file to be larger -// than MaxSize, the file is closed, renamed to include a timestamp of the -// current time, and a new log file is created using the original log file name. -// If the length of the write is greater than MaxSize, an error is returned. -func (l *Logger) Write(p []byte) (n int, err error) { - l.mu.Lock() - defer l.mu.Unlock() - - writeLen := int64(len(p)) - if writeLen > l.max() { - return 0, fmt.Errorf( - "write length %d exceeds maximum file size %d", writeLen, l.max(), - ) - } - - if l.file == nil { - if err = l.openExistingOrNew(len(p)); err != nil { - return 0, err - } - } - - if l.size+writeLen > l.max() { - if err := l.rotate(); err != nil { - return 0, err - } - } - - n, err = l.file.Write(p) - l.size += int64(n) - - return n, err -} - -// Close implements io.Closer, and closes the current logfile. -func (l *Logger) Close() error { - l.mu.Lock() - defer l.mu.Unlock() - return l.close() -} - -// close closes the file if it is open. -func (l *Logger) close() error { - if l.file == nil { - return nil - } - err := l.file.Close() - l.file = nil - return err -} - -// Rotate causes Logger to close the existing log file and immediately create a -// new one. This is a helper function for applications that want to initiate -// rotations outside of the normal rotation rules, such as in response to -// SIGHUP. After rotating, this initiates compression and removal of old log -// files according to the configuration. -func (l *Logger) Rotate() error { - l.mu.Lock() - defer l.mu.Unlock() - return l.rotate() -} - -// rotate closes the current file, moves it aside with a timestamp in the name, -// (if it exists), opens a new file with the original filename, and then runs -// post-rotation processing and removal. -func (l *Logger) rotate() error { - if err := l.close(); err != nil { - return err - } - if err := l.openNew(); err != nil { - return err - } - l.mill() - return nil -} - -// openNew opens a new log file for writing, moving any old log file out of the -// way. This methods assumes the file has already been closed. -func (l *Logger) openNew() error { - err := os.MkdirAll(l.dir(), 0744) - if err != nil { - return fmt.Errorf("can't make directories for new logfile: %s", err) - } - - name := l.filename() - mode := os.FileMode(0644) - info, err := os_Stat(name) - if err == nil { - // Copy the mode off the old logfile. - mode = info.Mode() - // move the existing file - newname := backupName(name, l.LocalTime) - if err := os.Rename(name, newname); err != nil { - return fmt.Errorf("can't rename log file: %s", err) - } - - // this is a no-op anywhere but linux - if err := chown(name, info); err != nil { - return err - } - } - - // we use truncate here because this should only get called when we've moved - // the file ourselves. if someone else creates the file in the meantime, - // just wipe out the contents. - f, err := os.OpenFile(name, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, mode) - if err != nil { - return fmt.Errorf("can't open new logfile: %s", err) - } - l.file = f - l.size = 0 - return nil -} - -// backupName creates a new filename from the given name, inserting a timestamp -// between the filename and the extension, using the local time if requested -// (otherwise UTC). -func backupName(name string, local bool) string { - dir := filepath.Dir(name) - filename := filepath.Base(name) - ext := filepath.Ext(filename) - prefix := filename[:len(filename)-len(ext)] - t := currentTime() - if !local { - t = t.UTC() - } - - timestamp := t.Format(backupTimeFormat) - return filepath.Join(dir, fmt.Sprintf("%s-%s%s", prefix, timestamp, ext)) -} - -// openExistingOrNew opens the logfile if it exists and if the current write -// would not put it over MaxSize. If there is no such file or the write would -// put it over the MaxSize, a new file is created. -func (l *Logger) openExistingOrNew(writeLen int) error { - l.mill() - - filename := l.filename() - info, err := os_Stat(filename) - if os.IsNotExist(err) { - return l.openNew() - } - if err != nil { - return fmt.Errorf("error getting log file info: %s", err) - } - - if info.Size()+int64(writeLen) >= l.max() { - return l.rotate() - } - - file, err := os.OpenFile(filename, os.O_APPEND|os.O_WRONLY, 0644) - if err != nil { - // if we fail to open the old log file for some reason, just ignore - // it and open a new log file. - return l.openNew() - } - l.file = file - l.size = info.Size() - return nil -} - -// genFilename generates the name of the logfile from the current time. -func (l *Logger) filename() string { - if l.Filename != "" { - return l.Filename - } - name := filepath.Base(os.Args[0]) + "-lumberjack.log" - return filepath.Join(os.TempDir(), name) -} - -// millRunOnce performs compression and removal of stale log files. -// Log files are compressed if enabled via configuration and old log -// files are removed, keeping at most l.MaxBackups files, as long as -// none of them are older than MaxAge. -func (l *Logger) millRunOnce() error { - if l.MaxBackups == 0 && l.MaxAge == 0 && !l.Compress { - return nil - } - - files, err := l.oldLogFiles() - if err != nil { - return err - } - - var compress, remove []logInfo - - if l.MaxBackups > 0 && l.MaxBackups < len(files) { - preserved := make(map[string]bool) - var remaining []logInfo - for _, f := range files { - // Only count the uncompressed log file or the - // compressed log file, not both. - fn := f.Name() - if strings.HasSuffix(fn, compressSuffix) { - fn = fn[:len(fn)-len(compressSuffix)] - } - preserved[fn] = true - - if len(preserved) > l.MaxBackups { - remove = append(remove, f) - } else { - remaining = append(remaining, f) - } - } - files = remaining - } - if l.MaxAge > 0 { - diff := time.Duration(int64(24*time.Hour) * int64(l.MaxAge)) - cutoff := currentTime().Add(-1 * diff) - - var remaining []logInfo - for _, f := range files { - if f.timestamp.Before(cutoff) { - remove = append(remove, f) - } else { - remaining = append(remaining, f) - } - } - files = remaining - } - - if l.Compress { - for _, f := range files { - if !strings.HasSuffix(f.Name(), compressSuffix) { - compress = append(compress, f) - } - } - } - - for _, f := range remove { - errRemove := os.Remove(filepath.Join(l.dir(), f.Name())) - if err == nil && errRemove != nil { - err = errRemove - } - } - for _, f := range compress { - fn := filepath.Join(l.dir(), f.Name()) - errCompress := compressLogFile(fn, fn+compressSuffix) - if err == nil && errCompress != nil { - err = errCompress - } - } - - return err -} - -// millRun runs in a goroutine to manage post-rotation compression and removal -// of old log files. -func (l *Logger) millRun() { - for _ = range l.millCh { - // what am I going to do, log this? - _ = l.millRunOnce() - } -} - -// mill performs post-rotation compression and removal of stale log files, -// starting the mill goroutine if necessary. -func (l *Logger) mill() { - l.startMill.Do(func() { - l.millCh = make(chan bool, 1) - go l.millRun() - }) - select { - case l.millCh <- true: - default: - } -} - -// oldLogFiles returns the list of backup log files stored in the same -// directory as the current log file, sorted by ModTime -func (l *Logger) oldLogFiles() ([]logInfo, error) { - files, err := ioutil.ReadDir(l.dir()) - if err != nil { - return nil, fmt.Errorf("can't read log file directory: %s", err) - } - logFiles := []logInfo{} - - prefix, ext := l.prefixAndExt() - - for _, f := range files { - if f.IsDir() { - continue - } - if t, err := l.timeFromName(f.Name(), prefix, ext); err == nil { - logFiles = append(logFiles, logInfo{t, f}) - continue - } - if t, err := l.timeFromName(f.Name(), prefix, ext+compressSuffix); err == nil { - logFiles = append(logFiles, logInfo{t, f}) - continue - } - // error parsing means that the suffix at the end was not generated - // by lumberjack, and therefore it's not a backup file. - } - - sort.Sort(byFormatTime(logFiles)) - - return logFiles, nil -} - -// timeFromName extracts the formatted time from the filename by stripping off -// the filename's prefix and extension. This prevents someone's filename from -// confusing time.parse. -func (l *Logger) timeFromName(filename, prefix, ext string) (time.Time, error) { - if !strings.HasPrefix(filename, prefix) { - return time.Time{}, errors.New("mismatched prefix") - } - if !strings.HasSuffix(filename, ext) { - return time.Time{}, errors.New("mismatched extension") - } - ts := filename[len(prefix) : len(filename)-len(ext)] - return time.Parse(backupTimeFormat, ts) -} - -// max returns the maximum size in bytes of log files before rolling. -func (l *Logger) max() int64 { - if l.MaxSize == 0 { - return int64(defaultMaxSize * megabyte) - } - return int64(l.MaxSize) * int64(megabyte) -} - -// dir returns the directory for the current filename. -func (l *Logger) dir() string { - return filepath.Dir(l.filename()) -} - -// prefixAndExt returns the filename part and extension part from the Logger's -// filename. -func (l *Logger) prefixAndExt() (prefix, ext string) { - filename := filepath.Base(l.filename()) - ext = filepath.Ext(filename) - prefix = filename[:len(filename)-len(ext)] + "-" - return prefix, ext -} - -// compressLogFile compresses the given log file, removing the -// uncompressed log file if successful. -func compressLogFile(src, dst string) (err error) { - f, err := os.Open(src) - if err != nil { - return fmt.Errorf("failed to open log file: %v", err) - } - defer f.Close() - - fi, err := os_Stat(src) - if err != nil { - return fmt.Errorf("failed to stat log file: %v", err) - } - - if err := chown(dst, fi); err != nil { - return fmt.Errorf("failed to chown compressed log file: %v", err) - } - - // If this file already exists, we presume it was created by - // a previous attempt to compress the log file. - gzf, err := os.OpenFile(dst, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, fi.Mode()) - if err != nil { - return fmt.Errorf("failed to open compressed log file: %v", err) - } - defer gzf.Close() - - gz := gzip.NewWriter(gzf) - - defer func() { - if err != nil { - os.Remove(dst) - err = fmt.Errorf("failed to compress log file: %v", err) - } - }() - - if _, err := io.Copy(gz, f); err != nil { - return err - } - if err := gz.Close(); err != nil { - return err - } - if err := gzf.Close(); err != nil { - return err - } - - if err := f.Close(); err != nil { - return err - } - if err := os.Remove(src); err != nil { - return err - } - - return nil -} - -// logInfo is a convenience struct to return the filename and its embedded -// timestamp. -type logInfo struct { - timestamp time.Time - os.FileInfo -} - -// byFormatTime sorts by newest time formatted in the name. -type byFormatTime []logInfo - -func (b byFormatTime) Less(i, j int) bool { - return b[i].timestamp.After(b[j].timestamp) -} - -func (b byFormatTime) Swap(i, j int) { - b[i], b[j] = b[j], b[i] -} - -func (b byFormatTime) Len() int { - return len(b) -} diff --git a/vendor/modules.txt b/vendor/modules.txt index bc78ee5c09..fa6b960e1c 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -137,7 +137,7 @@ github.com/cenkalti/backoff/v4 github.com/cespare/xxhash # github.com/cespare/xxhash/v2 v2.1.2 github.com/cespare/xxhash/v2 -# github.com/coreos/etcd v3.3.13+incompatible +# github.com/coreos/etcd v3.3.25+incompatible github.com/coreos/etcd/pkg/fileutil github.com/coreos/etcd/pkg/tlsutil # github.com/coreos/go-semver v0.3.0 @@ -173,8 +173,6 @@ github.com/fatih/color github.com/felixge/fgprof # github.com/felixge/httpsnoop v1.0.1 github.com/felixge/httpsnoop -# github.com/form3tech-oss/jwt-go v3.2.3+incompatible -github.com/form3tech-oss/jwt-go # github.com/fsouza/fake-gcs-server v1.7.0 ## explicit github.com/fsouza/fake-gcs-server/fakestorage @@ -266,10 +264,7 @@ github.com/golang/groupcache/lru github.com/golang/groupcache/singleflight # github.com/golang/protobuf v1.5.2 ## explicit -github.com/golang/protobuf/descriptor -github.com/golang/protobuf/jsonpb github.com/golang/protobuf/proto -github.com/golang/protobuf/protoc-gen-go/descriptor github.com/golang/protobuf/ptypes github.com/golang/protobuf/ptypes/any github.com/golang/protobuf/ptypes/duration @@ -298,24 +293,25 @@ github.com/googleapis/gax-go/v2/apierror/internal/proto # github.com/gorilla/mux v1.8.0 ## explicit github.com/gorilla/mux -# github.com/gorilla/websocket v1.4.2 -github.com/gorilla/websocket -# github.com/grafana/dskit v0.0.0-20210908150159-fcf48cb19aa4 +# github.com/grafana/dskit v0.0.0-20211007183133-4c566019f311 ## explicit github.com/grafana/dskit/backoff github.com/grafana/dskit/closer +github.com/grafana/dskit/crypto/tls github.com/grafana/dskit/flagext +github.com/grafana/dskit/grpcclient +github.com/grafana/dskit/grpcencoding/snappy +github.com/grafana/dskit/grpcutil github.com/grafana/dskit/kv github.com/grafana/dskit/kv/codec github.com/grafana/dskit/kv/consul github.com/grafana/dskit/kv/etcd -github.com/grafana/dskit/kv/kvtls github.com/grafana/dskit/kv/memberlist +github.com/grafana/dskit/middleware github.com/grafana/dskit/modules github.com/grafana/dskit/runtimeconfig github.com/grafana/dskit/services # github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 -## explicit github.com/grpc-ecosystem/go-grpc-middleware # github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.0.0-rc.2.0.20201207153454-9f6bf00c00a7 github.com/grpc-ecosystem/go-grpc-middleware/v2 @@ -323,12 +319,6 @@ github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors/tags github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors/tracing github.com/grpc-ecosystem/go-grpc-middleware/v2/util/metautils -# github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 -github.com/grpc-ecosystem/go-grpc-prometheus -# github.com/grpc-ecosystem/grpc-gateway v1.16.0 -github.com/grpc-ecosystem/grpc-gateway/internal -github.com/grpc-ecosystem/grpc-gateway/runtime -github.com/grpc-ecosystem/grpc-gateway/utilities # github.com/hailocab/go-hostpool v0.0.0-20160125115350-e80d13ce29ed github.com/hailocab/go-hostpool # github.com/hashicorp/consul/api v1.10.1 @@ -360,8 +350,6 @@ github.com/hashicorp/serf/coordinate github.com/jessevdk/go-flags # github.com/jmespath/go-jmespath v0.4.0 github.com/jmespath/go-jmespath -# github.com/jonboulle/clockwork v0.2.2 -github.com/jonboulle/clockwork # github.com/josharian/intern v1.0.0 github.com/josharian/intern # github.com/jpillora/backoff v1.0.0 @@ -591,8 +579,6 @@ github.com/shurcooL/httpfs/vfsutil github.com/shurcooL/vfsgen # github.com/sirupsen/logrus v1.8.1 github.com/sirupsen/logrus -# github.com/soheilhy/cmux v0.1.5 -github.com/soheilhy/cmux # github.com/sony/gobreaker v0.4.1 ## explicit github.com/sony/gobreaker @@ -600,8 +586,6 @@ github.com/sony/gobreaker ## explicit github.com/spf13/afero github.com/spf13/afero/mem -# github.com/spf13/pflag v1.0.5 -github.com/spf13/pflag # github.com/stretchr/objx v0.2.0 github.com/stretchr/objx # github.com/stretchr/testify v1.7.0 @@ -653,8 +637,6 @@ github.com/thanos-io/thanos/pkg/strutil github.com/thanos-io/thanos/pkg/targets/targetspb github.com/thanos-io/thanos/pkg/testutil github.com/thanos-io/thanos/pkg/tracing -# github.com/tmc/grpc-websocket-proxy v0.0.0-20201229170055-e5319fda7802 -github.com/tmc/grpc-websocket-proxy/wsproxy # github.com/uber/jaeger-client-go v2.29.1+incompatible ## explicit github.com/uber/jaeger-client-go @@ -678,7 +660,7 @@ github.com/uber/jaeger-client-go/utils # github.com/uber/jaeger-lib v2.4.1+incompatible github.com/uber/jaeger-lib/metrics github.com/uber/jaeger-lib/metrics/prometheus -# github.com/weaveworks/common v0.0.0-20210901124008-1fa3f9fa874c +# github.com/weaveworks/common v0.0.0-20210913144402-035033b78a78 ## explicit github.com/weaveworks/common/aws github.com/weaveworks/common/errors @@ -696,8 +678,6 @@ github.com/weaveworks/common/tracing github.com/weaveworks/common/user # github.com/weaveworks/promrus v1.2.0 github.com/weaveworks/promrus -# github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2 -github.com/xiang90/probing # github.com/yuin/gopher-lua v0.0.0-20200816102855-ee81675732da github.com/yuin/gopher-lua github.com/yuin/gopher-lua/ast @@ -711,91 +691,19 @@ go.etcd.io/etcd/pkg/transport # go.etcd.io/etcd/api/v3 v3.5.0 go.etcd.io/etcd/api/v3/authpb go.etcd.io/etcd/api/v3/etcdserverpb -go.etcd.io/etcd/api/v3/etcdserverpb/gw go.etcd.io/etcd/api/v3/membershippb go.etcd.io/etcd/api/v3/mvccpb go.etcd.io/etcd/api/v3/v3rpc/rpctypes go.etcd.io/etcd/api/v3/version # go.etcd.io/etcd/client/pkg/v3 v3.5.0 -go.etcd.io/etcd/client/pkg/v3/fileutil go.etcd.io/etcd/client/pkg/v3/logutil -go.etcd.io/etcd/client/pkg/v3/pathutil -go.etcd.io/etcd/client/pkg/v3/srv go.etcd.io/etcd/client/pkg/v3/systemd -go.etcd.io/etcd/client/pkg/v3/tlsutil -go.etcd.io/etcd/client/pkg/v3/transport go.etcd.io/etcd/client/pkg/v3/types -# go.etcd.io/etcd/client/v2 v2.305.0 -go.etcd.io/etcd/client/v2 # go.etcd.io/etcd/client/v3 v3.5.0 go.etcd.io/etcd/client/v3 -go.etcd.io/etcd/client/v3/concurrency go.etcd.io/etcd/client/v3/credentials go.etcd.io/etcd/client/v3/internal/endpoint go.etcd.io/etcd/client/v3/internal/resolver -# go.etcd.io/etcd/pkg/v3 v3.5.0 -go.etcd.io/etcd/pkg/v3/adt -go.etcd.io/etcd/pkg/v3/contention -go.etcd.io/etcd/pkg/v3/cpuutil -go.etcd.io/etcd/pkg/v3/crc -go.etcd.io/etcd/pkg/v3/debugutil -go.etcd.io/etcd/pkg/v3/flags -go.etcd.io/etcd/pkg/v3/httputil -go.etcd.io/etcd/pkg/v3/idutil -go.etcd.io/etcd/pkg/v3/ioutil -go.etcd.io/etcd/pkg/v3/netutil -go.etcd.io/etcd/pkg/v3/pbutil -go.etcd.io/etcd/pkg/v3/runtime -go.etcd.io/etcd/pkg/v3/schedule -go.etcd.io/etcd/pkg/v3/traceutil -go.etcd.io/etcd/pkg/v3/wait -# go.etcd.io/etcd/raft/v3 v3.5.0 -go.etcd.io/etcd/raft/v3 -go.etcd.io/etcd/raft/v3/confchange -go.etcd.io/etcd/raft/v3/quorum -go.etcd.io/etcd/raft/v3/raftpb -go.etcd.io/etcd/raft/v3/tracker -# go.etcd.io/etcd/server/v3 v3.5.0 -go.etcd.io/etcd/server/v3/auth -go.etcd.io/etcd/server/v3/config -go.etcd.io/etcd/server/v3/datadir -go.etcd.io/etcd/server/v3/embed -go.etcd.io/etcd/server/v3/etcdserver -go.etcd.io/etcd/server/v3/etcdserver/api -go.etcd.io/etcd/server/v3/etcdserver/api/etcdhttp -go.etcd.io/etcd/server/v3/etcdserver/api/membership -go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp -go.etcd.io/etcd/server/v3/etcdserver/api/snap -go.etcd.io/etcd/server/v3/etcdserver/api/snap/snappb -go.etcd.io/etcd/server/v3/etcdserver/api/v2auth -go.etcd.io/etcd/server/v3/etcdserver/api/v2discovery -go.etcd.io/etcd/server/v3/etcdserver/api/v2error -go.etcd.io/etcd/server/v3/etcdserver/api/v2http -go.etcd.io/etcd/server/v3/etcdserver/api/v2http/httptypes -go.etcd.io/etcd/server/v3/etcdserver/api/v2stats -go.etcd.io/etcd/server/v3/etcdserver/api/v2store -go.etcd.io/etcd/server/v3/etcdserver/api/v2v3 -go.etcd.io/etcd/server/v3/etcdserver/api/v3alarm -go.etcd.io/etcd/server/v3/etcdserver/api/v3client -go.etcd.io/etcd/server/v3/etcdserver/api/v3compactor -go.etcd.io/etcd/server/v3/etcdserver/api/v3election -go.etcd.io/etcd/server/v3/etcdserver/api/v3election/v3electionpb -go.etcd.io/etcd/server/v3/etcdserver/api/v3election/v3electionpb/gw -go.etcd.io/etcd/server/v3/etcdserver/api/v3lock -go.etcd.io/etcd/server/v3/etcdserver/api/v3lock/v3lockpb -go.etcd.io/etcd/server/v3/etcdserver/api/v3lock/v3lockpb/gw -go.etcd.io/etcd/server/v3/etcdserver/api/v3rpc -go.etcd.io/etcd/server/v3/etcdserver/cindex -go.etcd.io/etcd/server/v3/lease -go.etcd.io/etcd/server/v3/lease/leasehttp -go.etcd.io/etcd/server/v3/lease/leasepb -go.etcd.io/etcd/server/v3/mvcc -go.etcd.io/etcd/server/v3/mvcc/backend -go.etcd.io/etcd/server/v3/mvcc/buckets -go.etcd.io/etcd/server/v3/proxy/grpcproxy/adapter -go.etcd.io/etcd/server/v3/verify -go.etcd.io/etcd/server/v3/wal -go.etcd.io/etcd/server/v3/wal/walpb # go.mongodb.org/mongo-driver v1.5.1 go.mongodb.org/mongo-driver/bson go.mongodb.org/mongo-driver/bson/bsoncodec @@ -822,61 +730,6 @@ go.opencensus.io/trace go.opencensus.io/trace/internal go.opencensus.io/trace/propagation go.opencensus.io/trace/tracestate -# go.opentelemetry.io/contrib v0.20.0 -go.opentelemetry.io/contrib -# go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.20.0 -go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc -# go.opentelemetry.io/otel v0.20.0 -go.opentelemetry.io/otel -go.opentelemetry.io/otel/attribute -go.opentelemetry.io/otel/baggage -go.opentelemetry.io/otel/codes -go.opentelemetry.io/otel/internal -go.opentelemetry.io/otel/internal/baggage -go.opentelemetry.io/otel/internal/global -go.opentelemetry.io/otel/internal/metric -go.opentelemetry.io/otel/internal/trace/noop -go.opentelemetry.io/otel/propagation -go.opentelemetry.io/otel/semconv -go.opentelemetry.io/otel/unit -# go.opentelemetry.io/otel/exporters/otlp v0.20.0 -go.opentelemetry.io/otel/exporters/otlp -go.opentelemetry.io/otel/exporters/otlp/internal/otlpconfig -go.opentelemetry.io/otel/exporters/otlp/internal/transform -go.opentelemetry.io/otel/exporters/otlp/otlpgrpc -# go.opentelemetry.io/otel/metric v0.20.0 -go.opentelemetry.io/otel/metric -go.opentelemetry.io/otel/metric/number -go.opentelemetry.io/otel/metric/registry -# go.opentelemetry.io/otel/sdk v0.20.0 -go.opentelemetry.io/otel/sdk/instrumentation -go.opentelemetry.io/otel/sdk/internal -go.opentelemetry.io/otel/sdk/resource -go.opentelemetry.io/otel/sdk/trace -# go.opentelemetry.io/otel/sdk/export/metric v0.20.0 -go.opentelemetry.io/otel/sdk/export/metric -go.opentelemetry.io/otel/sdk/export/metric/aggregation -# go.opentelemetry.io/otel/sdk/metric v0.20.0 -go.opentelemetry.io/otel/sdk/metric -go.opentelemetry.io/otel/sdk/metric/aggregator -go.opentelemetry.io/otel/sdk/metric/aggregator/exact -go.opentelemetry.io/otel/sdk/metric/aggregator/histogram -go.opentelemetry.io/otel/sdk/metric/aggregator/lastvalue -go.opentelemetry.io/otel/sdk/metric/aggregator/minmaxsumcount -go.opentelemetry.io/otel/sdk/metric/aggregator/sum -go.opentelemetry.io/otel/sdk/metric/controller/basic -go.opentelemetry.io/otel/sdk/metric/controller/time -go.opentelemetry.io/otel/sdk/metric/processor/basic -go.opentelemetry.io/otel/sdk/metric/selector/simple -# go.opentelemetry.io/otel/trace v0.20.0 -go.opentelemetry.io/otel/trace -# go.opentelemetry.io/proto/otlp v0.7.0 -go.opentelemetry.io/proto/otlp/collector/metrics/v1 -go.opentelemetry.io/proto/otlp/collector/trace/v1 -go.opentelemetry.io/proto/otlp/common/v1 -go.opentelemetry.io/proto/otlp/metrics/v1 -go.opentelemetry.io/proto/otlp/resource/v1 -go.opentelemetry.io/proto/otlp/trace/v1 # go.uber.org/atomic v1.9.0 ## explicit go.uber.org/atomic @@ -987,7 +840,6 @@ google.golang.org/appengine/socket google.golang.org/appengine/urlfetch # google.golang.org/genproto v0.0.0-20210903162649-d08c68adba83 google.golang.org/genproto/googleapis/api/annotations -google.golang.org/genproto/googleapis/api/httpbody google.golang.org/genproto/googleapis/bigtable/admin/v2 google.golang.org/genproto/googleapis/bigtable/v2 google.golang.org/genproto/googleapis/iam/v1 @@ -1025,7 +877,6 @@ google.golang.org/grpc/encoding google.golang.org/grpc/encoding/gzip google.golang.org/grpc/encoding/proto google.golang.org/grpc/grpclog -google.golang.org/grpc/health google.golang.org/grpc/health/grpc_health_v1 google.golang.org/grpc/internal google.golang.org/grpc/internal/backoff @@ -1104,8 +955,6 @@ gopkg.in/fsnotify/fsnotify.v1 gopkg.in/inf.v0 # gopkg.in/ini.v1 v1.57.0 gopkg.in/ini.v1 -# gopkg.in/natefinch/lumberjack.v2 v2.0.0 -gopkg.in/natefinch/lumberjack.v2 # gopkg.in/yaml.v2 v2.4.0 ## explicit gopkg.in/yaml.v2